Skip to content

test(credible-block): live-anvil scripts for credible block guard upgrades - #94

Merged
makemake-kbo merged 3 commits into
masterfrom
makemake/eng-4069-featstd-create-test-scripts-for-testing-contract-updates
Jul 27, 2026
Merged

test(credible-block): live-anvil scripts for credible block guard upgrades#94
makemake-kbo merged 3 commits into
masterfrom
makemake/eng-4069-featstd-create-test-scripts-for-testing-contract-updates

Conversation

@makemake-kbo

Copy link
Copy Markdown
Contributor

What

Adds an examples/credible-block project with scripts to test Credible Layer contract upgrades against a live anvil node.

The existing forge unit tests fake block state with vm.roll/vm.prank. That covers the guard's decision logic but cannot reproduce the one thing that only exists on a real chain: a builder's credible-block marker transaction and a guarded transaction landing in the same block (a bundle). These scripts seed a real node and drive mining manually to test exactly that.

Contents

  • src/CredibleRegistry.sol — minimal ICredibleRegistry: a single immutable builder (set at construction) can mark the current block credible. Trimmed to the least required to exercise the guard; the production registry additionally has a timelocked admin, builder whitelist, and timestamp slot-binding.
  • src/GuardedCounter.sol — a concrete CredibleBlockGuard consumer standing in for an upgraded credible-layer contract (bump() is onlyCredibleBlock).
  • script/test-credible-upgrades.sh — boots anvil (fifo mempool ordering), deploys the registry + a builder we control + the guard, then verifies three cases.
  • foundry.toml — new [profile.credible-block].

Cases verified (all pass)

  1. Credible block — bundle [markCurrentBlockCredible, bump] into one block (automine off + cast send --async + single evm_mine); both succeed, counter increments.
  2. Non-credible blockbump() with no marker reverts with NonCredibleBlock(); counter unchanged.
  3. Fail-open — after the builder stays silent for > failOpenBlockThreshold blocks, bump() passes again (and still reverts at the boundary, gap == threshold).

Running

./examples/credible-block/script/test-credible-upgrades.sh

Requires anvil, cast, forge, jq. Exits non-zero on any failed check. See examples/credible-block/README.md for details.

…rades

Add an examples/credible-block project that exercises CredibleBlockGuard's
onlyCredibleBlock modifier against a live anvil node, covering the one thing the
vm.roll/vm.prank unit tests cannot: a builder's credible-block marker tx and a
guarded tx landing in the same block (a bundle).

- CredibleRegistry.sol: minimal ICredibleRegistry with a single immutable builder
- GuardedCounter.sol: concrete guard consumer standing in for an upgraded contract
- test-credible-upgrades.sh: seeds anvil + a builder, then verifies
    1) credible block  - bundled [marker, guarded] both succeed
    2) non-credible     - guarded tx alone reverts (NonCredibleBlock)
    3) fail-open        - guarded tx passes only once the builder set is silent
                          past failOpenBlockThreshold
- foundry.toml: add [profile.credible-block]
@linear-code

linear-code Bot commented Jul 24, 2026

Copy link
Copy Markdown

ENG-4069

Comment thread examples/credible-block/script/test-credible-upgrades.sh
Refuse to run if the RPC port is already answering before launch, and
fail fast if the anvil child exits before becoming ready, instead of
adopting (and snapshotting/reverting/disabling automine on) another node.
Comment thread examples/credible-block/script/test-credible-upgrades.sh
Comment thread examples/credible-block/script/test-credible-upgrades.sh Outdated
Comment thread examples/credible-block/README.md Outdated
…lock in Case 2

Address review on PR #94:
- fix stale script header claiming the registry has an admin/whitelist; it
  takes one immutable builder in the constructor
- seed a credible block before Case 2's non-credible check so a small
  FAIL_OPEN_THRESHOLD override cannot trip fail-open (lastCredibleBlock==0)
  and report a false failure
- use the absolute GitHub URL for the production credible-registry link
@makemake-kbo
makemake-kbo merged commit e1da827 into master Jul 27, 2026
9 checks passed
@makemake-kbo
makemake-kbo deleted the makemake/eng-4069-featstd-create-test-scripts-for-testing-contract-updates branch July 27, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants