Skip to content

test-setup: deploy SimpleTest at a CREATE2 address so keyed runs stop redeploying it - #520

Open
alexshchur wants to merge 4 commits into
masterfrom
fix/setup-create2-simpletest
Open

alexshchur wants to merge 4 commits into
masterfrom
fix/setup-create2-simpletest

Conversation

@alexshchur

@alexshchur alexshchur commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Goal

A keyed CI run should, on its own: detect that SimpleTest's bytecode changed, deploy it if so, and otherwise reuse the contract already on the chain. No registry to keep in sync, no dependency on who deployed last, nothing a human has to refresh.

Why it didn't

setup.mjs decided "deploy or not" by comparing the compiled bytecode hash with the committed test/setup/src/deployments.json. #390 changed the bytecode and CI never writes that file back, so since then every keyed run redeployed SimpleTest on Ethereum, Arbitrum and Base Sepolia, and on 2026-11-09 one of those deploys failed on Base Sepolia (run 42641443056) before any test ran. The stored values had the same shape: primaryTestChainRegistry.json pinned handles that only the account that ran setup could read, so test-live depended on a human running setup with CI's own key and committing.

Change

The chain is the only source of truth; the committed registries are gone.

  • Deploy. On chains with the deterministic CREATE2 deployer (0x4e59b44847b379578588920cA78FbF26c0B4956C, detected with cast code), SimpleTest lives at an address computed from a fixed salt and its bytecode. Setup skips when that address has code, deploys through the deployer otherwise, and treats a failed send as success when the code is there afterwards (another run got there first). The deployer being msg.sender at construction is harmless: SimpleTest has no constructor and no owner.
  • Hand-off to the tests. Setup writes what it found or deployed to deployments.local.json, gitignored, and tsup inlines it into the bundle of this checkout. A checkout where setup has not run has no addresses and the live suites say so.
  • Stored values. Setup stores storedValue (42) and publicValue (7) as its account and pins the resulting handles in the same local file, read at the block of its own transaction. The decrypt tests use the pinned handles. The fixture is shared and the matrix suites overwrite it, but a handle stays decryptable after the contract moves on, so this is the one thing the tests cannot read live from the chain. Setup skips the step while the TaskManager's ACL still allows the pinned handles for this account, so a developer's checkout stores once; a fresh runner stores on each run (two transactions).
  • Where setup runs in CI. Only in a new Test fixtures job, one leg per testnet. Each leg uploads its deployments.local.json as an artifact; the live suite and the matrix leg of that testnet wait for it and download the file before they build. Setup sends transactions from the test account, and so does the matrix leg, so the fixtures leg sits in the same concurrency group as the matrix leg of its testnet and the two never overlap, within a run or across runs. The live suite only reads, as before this PR. An earlier version of this PR ran setup inside test-live as well; that collided with the Arbitrum matrix leg on the account's nonce (run 43429024574).
  • Chains without the deployer (CoFHE staging, local CoFHE) keep forge create, recorded in the same local file. They reset periodically, so a fresh runner deploys there once per run.

A keyed run, before and after

Before: forge build → hash differs from the committed entry → forge create → address written to the runner only → values stored again → tests. Three deploys per run, and a failed deploy fails the job.

After, in the fixtures job: forge build → the CREATE2 address has code → skip → store the two values and pin their handles → upload the record. Then the test jobs download it and run. The first run after a bytecode change deploys once per chain; every later run only reads the chain, apart from the two value stores on Arbitrum. (This PR's CI runs showed exactly this: the first deployed on all three chains, the next ones logged a skip.)

Gaps that remain

  • Staging and local CoFHE can't reuse across machines: their forge create address lives only in the checkout's local file. Installing the CREATE2 deployer there would fix it, but its presigned legacy transaction may be rejected by those nodes and would have to be redone after every reset. Left as is; those chains are ephemeral.
  • Values are stored per fresh checkout. A fresh CI runner has no pinned handles, so the Arbitrum fixtures leg sends two trivial-encrypt transactions on each run. Reusing across runners would need a shared record again, which is what this PR removes; the cost is small and I'd rather keep the chain as the only state.
  • A first attempt read the handles live from the contract and failed in CI: the Arbitrum matrix job, running at the same time with the same key, had overwritten publicValue. Pinning at store time is the fix; it is also what the old committed registry was doing, minus the commit.
  • simpleTestAbi.ts is still a committed file generated from the contract. Unchanged here.

Notes

  • cd test/setup && pnpm test: 18 tests with stubbed cast/forge, no network, covering both deploy paths, the value store and its ACL-gated reuse, and the address derivation against cast create2.
  • No changeset: @cofhe/test-setup is private.

@changeset-bot

changeset-bot Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 2c88839

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Vercel previews (commit 2c88839)

Project Deployment Updated
docs Visit Preview Nov 18, 2026 06:35 UTC
react Visit Preview Nov 18, 2026 06:33 UTC

…tries

Every keyed CI run redeployed SimpleTest on the three testnets since #390
changed its bytecode: setup.mjs compared the compiled bytecode hash with the
committed deployments.json, CI never wrote the new entry back, and one of the
redeploys failed the Base Sepolia job before any test ran. The committed
registries were a copy of chain state that only a human could refresh.

The chain is now the only source of truth. Where the deterministic CREATE2
deployer has code (the testnets), SimpleTest lives at an address computed from
the bytecode: setup skips when that address has code, deploys otherwise, and a
failed send still counts when the code is there afterwards. Chains without the
deployer (staging, local CoFHE) keep forge create; they reset anyway. Setup
writes what it found or deployed to deployments.local.json, which is not
committed and which tsup inlines for the tests of this checkout.

The values the decrypt tests read follow the same rule. Setup stores them as
its own account and pins the resulting handles in the same local file, read at
the block of its own transaction; it skips while the TaskManager's ACL still
allows the pinned handles for that account. The tests use the pinned handles,
since the fixture is shared and other suites overwrite it while a handle stays
decryptable. primaryTestChainRegistry.json and stagingTestChainRegistry.json go,
along with the coupling to whichever key last ran setup. The test-live jobs run
setup for Arbitrum Sepolia before the tests, like the matrix jobs do.

@architect-dev architect-dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, removing the deployments.json is great (btw .memories/testing.md needs to be updated to prevent drift). One issue is that test-live now runs the setup, which can cause nonce collisions.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments in this file need to be updated (read-only removed etc).

We should extract test-setup out to its own step that is depended on by both test-live and integration / matrix tests. Adding setup to the test-live opens the chance for nonce collision as the test-setup is being run concurrently for the live / integration tests.

…bs read its record

test-live ran setup on Arbitrum Sepolia at the same time as the Arbitrum matrix leg, with
the same key, and failed on a nonce collision. Setup now runs only in the fixtures jobs,
in the concurrency group of the matrix leg of the same testnet, and hands
deployments.local.json to the test jobs as an artifact. test-live is read-only again.

This branch was successfully deployed

2 active deployments
Preview – docs — 2c888398 Deployed Nov 18, 2026 by github-actions[bot]
Preview – react — 2c888398 Deployed Nov 18, 2026 by github-actions[bot]
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