Skip to main content
Test that a guarded operation succeeds after a marker in the same block, rejects an unmarked block, and becomes available after the configured block-gap threshold.

Prerequisites

  • Access to credible-registry, with its submodules checked out
  • anvil, cast, forge, and jq on your PATH
  • A free local port 8545, or another port selected with RPC_PORT
The guard and test harness live in credible-registry, not credible-std. These commands use revision 8804c9e:

Run the Fixture

From the Registry repository root, run:
The script starts a fresh Anvil chain, deploys the Registry, marks an initial block, and deploys GuardedCounter. The initial marker is required by the guard constructor. This tests the fixture, not your protocol’s upgrade. To use another port:
The fixture uses a fixed threshold of 10 blocks. FAIL_OPEN_THRESHOLD and --expected-threshold change the runner’s expectation, not the deployed contract. Use a custom target to test a different threshold.

Test Your Contract

The runner cannot reuse a live-network address or another Anvil instance. Supply deployment commands that run after its local chain starts:
  1. Deploy a Registry with MARKER_ADDRESS authorized as a builder. Print the Registry address as the command’s final output line.
  2. Deploy or upgrade your target with REGISTRY_ADDRESS. Set up balances, roles, and approvals, then print the target or proxy address as the final line.
  3. Specify the guarded call, a state-reading call, and the expected state before and after success.
This runnable example uses the repository’s GuardedName contract:
Replace the target deployment and call details with your protocol’s equivalents. Pass each function argument with a separate --guarded-call-arg; use --state-read-call-arg for getter arguments. String state values must include the quotes returned by cast call, as above. Commands receive RPC_URL, REPO_ROOT, REGISTRY_ADDRESS, and EXPECTED_THRESHOLD, plus local test keys and addresses. The runner marks the Registry before invoking the target command. Use these keys only on the local test chain. The runner checks credibleRegistry()(address) and failOpenBlockThreshold()(uint256) by default. For different getters, use --registry-read-call and --threshold-read-call. For targets without getters, supply --config-assert-command; it must exit successfully only when both settings match.

Verify the Results

The harness disables automining for the ordering test. Sending both transactions with automining enabled would put them in different blocks. The fixture and example above report the following summary. Require zero failures and a zero exit status; a custom configuration check changes the check count.

Test Simulation Separately

The Registry accepts zero-gas-price calls in nonzero blocks without a marker. The harness uses --gas-price 1gwei for its rejection probe so it tests paid-call behavior. In Foundry tests, set a nonzero vm.txGasPrice when testing guard rejection. A successful wallet simulation is not proof of production protection. Monitor lastCredibleBlock() or marker events for actual marker activity. See zero-gas-price calls. The harness does not test the Credible RPC, real builder enforcement, assertion activation, Safe modules, or storage-layout compatibility. Complete those checks in your integration test plan.