Skip to main content
Test at every layer before you deploy: unit-test your Rego rules with opa test, run your WASM oracle in isolation, then simulate the full policy end-to-end against the Newton network. This guide covers all three. For diagnosing failures after deployment, see Testing & Debugging.

Unit-test your Rego with opa test

Rego rules are pure functions of input, data.params, and data.wasm, which makes them easy to unit-test without the network. Write a companion policy_test.rego and mock the data with with. Given a policy like this:
Write policy_test.rego alongside it. Mock data.params and data.wasm with with, and assert on both allow and membership in the deny set:
Run the tests:
Recommended coverage:
  • Happy path — clean data allows.
  • Each deny rule — one test per rule, asserting the expected reason is in deny and allow is false.
  • Param toggles — a deny flag set to false does not deny.
  • Edge valuesnull, empty, and out-of-range fields behave as intended.
  • No fail-open under multiple failures — two deny conditions at once still denies.
  • Multi-oracle — for chained oracles, wrap each fixture under its own pack id ({"vaultsfyi": {...}, "webacy": {...}}) and assert deny rules from each namespace fire independently.

Quick local checks with the CLI

The CLI bundles a Rego engine with Newton’s crypto and identity built-ins. Use it to evaluate a query or validate syntax:
Pass --non-strict for OPA-compatible evaluation. -d (data/policy) can be repeated; -i is the input (intent) file. See the CLI Reference.

Test your WASM oracle

Run the compiled oracle in isolation to confirm it produces the data shape your Rego expects.
For an oracle that needs secrets, test through the Gateway:
See Uploading & Accessing Secrets in Oracles for the secrets lifecycle.

Simulate the full policy

The final step before deploying: evaluate the complete policy (Rego + every oracle + merged data) against a sample intent with newt_simulatePolicy. Pass one entry per oracle in policy_data and namespaced policy_params:
Inspect evaluation_result.policy_params_and_data in the response to confirm the merged data.wasm shape, and evaluation_result.result for the allow/deny decision. For multi-oracle policies, see Chaining Multiple Data Oracles.
  1. opa test your Rego rules.
  2. policy-data simulate each oracle locally.
  3. Upload secrets, then newt_simulatePolicyDataWithClient to verify they resolve.
  4. newt_simulatePolicy for the full end-to-end decision.
  5. Deploy, then submit production tasks.

Next Steps

Testing & Debugging

Diagnose failures after deployment

Chaining Data Oracles

Simulate and test multi-oracle policies

Deployment Checklist

Pre-launch verification steps

Rego Syntax Guide

Rego language reference