# Testing/Debugging code for Calculate and Custom Logic Block using UI

### **1. Overview**

The **customLogicBlock** and **calculateContainerBlock** can be executed in a “dry-run” mode. This feature provides a sandboxed environment for testing the logic of a block independently, helping policy developers validate their implementation with different input scenarios without affecting the main policy.

### **2. Custom Logic Block**

#### **Dry-Run Execution**

The `customLogicBlock` supports isolated dry-run execution. This means it can be tested independently of other blocks in a policy, allowing for detailed debugging and rapid prototyping.

Execution is controlled through a step-by-step interface in the UI, enabling users to define parameters, input data, and immediately inspect the results.

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-933fd8e544708a5a9f976acab52c14a5efe12bb7%2Fimage%20(1)%20(1)%20(2).png?alt=media" alt=""><figcaption></figcaption></figure>

***

### **3. Dry-Run Execution Steps**

#### **Step 1: Configure Block Properties**

Users can adjust various configuration options related to the block directly within the dry-run interface. This avoids the need to navigate back to the main policy editor and streamlines the testing workflow.

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-a502f2fdbb7cc03c0ad245d405a8edb248d76dee%2Fimage%20(2)%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

***

#### **Step 2: Provide Input Data**

The block can be tested using mock input data. Three primary input methods are supported:

**a. Schema-Based Input**

* Select a data schema from a dropdown list.
* A dynamic form is generated based on the schema, allowing users to fill in relevant fields.
* Ideal for users who prefer a structured and guided input interface.

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-9bc4634f45103c869c09d24cc2caa7d4e0b6f324%2Fimage%20(3)%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

**b. JSON Editor**

* Directly input JSON-formatted data using the built-in editor.
* Best suited for advanced users or when precise control over the input format is needed.

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-6ce8b07aaa8e91a82df486f5e6ea81e27db1e374%2Fimage%20(4)%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

**c. File Upload**

* Upload a JSON file containing the test data.
* The file must be well-formed JSON.

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-86c1b95a73c7c8d82d625403cb1f29e49ea23175%2Fimage%20(5)%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

> **Note**: Only valid JSON inputs are accepted. Malformed files will cause parsing errors.

***

#### **Step 3: Use Historical Data**

The **History** tab displays saved input/output pairs from previous executions during dry-run mode. This is helpful when working with complex workflows that generate intermediate data.

To utilize this:

1. Enable **Policy Dry-Run Mode**.
2. Execute the policy workflow normally.
3. Once execution reaches the target block, its context (input/output) will be saved and visible in the history tab.

> **Important Notes:**

* Historical data is only available in dry-run mode and is cleared upon exit.
* Code changes made in dry-run are not persisted. To retain them, re-enter the changes in **Draft Mode** of the policy.

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-8ce412f3955ae5a7a1b44c0244edae5e83b34456%2Fimage%20(6)%20(2).png?alt=media" alt=""><figcaption></figcaption></figure>

***

#### **Step 4: Write and Test Code (customLogicBlock only)**

In the final step:

* Modify the code as needed.
* Press the **Test** button to execute.

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-a07a9b07aec70be7260ce90365e7430b318ac180%2Fimage%20(9).png?alt=media" alt=""><figcaption></figcaption></figure>

**Debugging Tips**

Use the `debug` function to output logs:

```javascript
javascriptCopyEditdebug("Variable Value", variable);
```

* Outputs appear in the **Logs** tab.
* Has no effect (noop) when the policy is in **Published Mode**.

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-88c40c118dd995102349a300d82f62f6ceb6657d%2Fimage%20(8).png?alt=media" alt=""><figcaption></figcaption></figure>

***

### **4. Viewing Test Results**

Upon completion of the dry-run, the results are split into several tabs:

| Tab        | Description                                                     |
| ---------- | --------------------------------------------------------------- |
| **Input**  | Displays the ingress VC (Verifiable Credential) documents used. |
| **Logs**   | Shows output from `debug()` and system logs.                    |
| **Output** | Final result VC document (if execution succeeds).               |
| **Errors** | Any errors encountered during test-run.                         |

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-42e8c24532442ab54510860d62a24e6b9b7d40c6%2Fimage%20(10).png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-c8d0e609c0da518c86005e884f8c6d8e330f9cf9%2Fimage%20(11).png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-59199ceeab50bfca323620154d7ae5845d8c4e17%2Fimage%20(12).png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-0c186963b293980702239e239d42478b60c52368%2Fimage%20(13).png?alt=media" alt=""><figcaption></figcaption></figure>

***

### **5. calculateContainerBlock**

All features described for `customLogicBlock` apply to `calculateContainerBlock`, **except** it does not include a code editor tab. This block is evaluated based on its configured calculation logic rather than custom scripting.

***

### **6. API Support for Dry-Run**

The following API endpoints are available to programmatically interact with the dry-run feature:

#### **Get Block History**

```http
httpCopyEditGET /api/v1/policies/:policyId/dry-run/block/:tagName/history
Permissions: POLICIES_POLICY_UPDATE
```

* Retrieves the list of historical test data for the specified block.

#### **Execute Block Dry-Run**

```http
httpCopyEditPOST /api/v1/policies/:policyId/dry-run/block
Permissions: POLICIES_POLICY_UPDATE
```

* Submits the block for dry-run execution with the specified input.
