> For the complete documentation index, see [llms.txt](https://docs.guardianservice.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.guardianservice.app/technical-information/users/standard-registry-users-schemas-and-policies/policies/testing-debugging-code/testing-debugging-code-for-calculate-and-custom-logic-block-using-ui.md).

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

## **1. Overview** <a href="#id-1.-overview" id="id-1.-overview"></a>

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** <a href="#id-2.-custom-logic-block" id="id-2.-custom-logic-block"></a>

### **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://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FiFxRRcFoTgB4FgFMC3if%2Fimage.png?alt=media&amp;token=7b91b997-5faf-465b-bc51-ab8e65e2daab" alt=""><figcaption></figcaption></figure>

## **3. Dry-Run Execution Steps** <a href="#id-3.-dry-run-execution-steps" id="id-3.-dry-run-execution-steps"></a>

### **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://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FH0de0vq3DK74WbsJzcpv%2Fimage.png?alt=media&amp;token=a473c59a-9b58-41ba-94e8-89e7186a9b87" 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://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FkrTPCDoMeOL7wXeM2Px1%2Fimage.png?alt=media&amp;token=5735ed3c-5b59-4cdc-9045-f6b1784ee175" 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://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FZDqmxMfbmgDwfOZowQhL%2Fimage.png?alt=media&amp;token=30841b3a-5081-4a21-a37e-77c5bf0fc0bb" 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://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FVglMOXchXyZntCd7ReEG%2Fimage.png?alt=media&amp;token=56f3656c-b373-45ba-ab7a-8290eee0250a" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Note**: Only valid JSON inputs are accepted. Malformed files will cause parsing errors.
{% endhint %}

### **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.

{% hint style="info" %}
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.
  {% endhint %}

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FQyYhyvGSto2JuNJ6skpv%2Fimage.png?alt=media&amp;token=7eea3108-e3db-4307-b547-76faf1d7770e" 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://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FWRlDyTcZvISCmQAPk8wf%2Fimage.png?alt=media&amp;token=9fddeaa6-ee2c-4fc1-b638-91863ef4f403" alt=""><figcaption></figcaption></figure>

**Debugging Tips**

Use the `debug` function to output logs:

```json5
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://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FKbdNHwYfaD9cfdeq6O1K%2Fimage.png?alt=media&amp;token=7bb22818-5ade-47e1-b4e9-5f9e0c807e03" alt=""><figcaption></figcaption></figure>

## **4. Viewing Test Results** <a href="#id-4.-viewing-test-results" id="id-4.-viewing-test-results"></a>

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://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FeZLMiyoAuSX6EKpVlTIO%2Fimage.png?alt=media&amp;token=26dd2dcf-048c-4bb7-8a41-0cf4a03869bb" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FB8EUBUsOu0wM8AqqKNVO%2Fimage.png?alt=media&amp;token=1268b290-33ad-45f4-a9bc-539befae68bc" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FUnoBnSgs1c8r982recVO%2Fimage.png?alt=media&amp;token=a77a24be-f83f-44a3-91cc-878ea4ad2855" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FsQV9vyfHn5BZOdAsCPaw%2Fimage.png?alt=media&amp;token=a01ee745-239b-4bb0-b86b-b53768062491" alt=""><figcaption></figcaption></figure>

## **5. calculateContainerBlock** <a href="#id-5.-calculatecontainerblock" id="id-5.-calculatecontainerblock"></a>

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.
