[Flow EVM] Add bootstrap option to enable the EVM testing helpers#8487
[Flow EVM] Add bootstrap option to enable the EVM testing helpers#8487
EVM testing helpers#8487Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
📝 WalkthroughWalkthroughThis PR introduces configuration-driven EVM test helper injection by adding an explicit Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can scan for known vulnerabilities in your dependencies using OSV Scanner.OSV Scanner will automatically detect and report security vulnerabilities in your project's dependencies. No additional configuration is required. |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
fvm/evm/stdlib/contract_test.go (1)
354-359: Consider adding one complementaryevmTestHelpersEnabled=falsedeployment case.Line 358 now always enables helpers in the shared deploy path. A focused disabled-path test would keep toggle behavior fully covered.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@fvm/evm/stdlib/contract_test.go` around lines 354 - 359, The shared deploy path currently always enables helpers by calling stdlib.ContractCode(..., true); add a complementary test case that deploys the same contract using evmTestHelpersEnabled=false to exercise the disabled helpers path. Locate the test that builds/deploys via stdlib.ContractCode (the call with the three contractsAddress args) and add a parallel subtest or table entry that passes false instead of true, ensuring the deployment, assertions, and teardown mirror the existing enabled case so toggle behavior is fully covered.fvm/evm/evm_test.go (1)
312-313: Add a forked-network regression case.These new helper-gating checks still bootstrap
flow.Emulator.Chain(), so they never exercise the path that was previously broken on forked networks. A singleflow.Testnet.Chain()orflow.Mainnet.Chain()case withWithEVMTestHelpersEnabled(cadence.NewBool(true))would lock down the actual fix instead of only re-testing emulator behavior.Also applies to: 316-387, 484-486, 489-648
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@fvm/evm/evm_test.go` around lines 312 - 313, The tests currently only exercise the emulator chain; add at least one forked-network regression case that uses flow.Testnet.Chain() or flow.Mainnet.Chain() together with the existing helper flag (WithEVMTestHelpersEnabled(cadence.NewBool(true))) to ensure the broken path on forked networks is covered; update the test table/cases around the EVM test helper sections (the blocks invoking flow.Emulator.Chain() and the test entries at the ranges mentioned) to include a parallel case that swaps Chain() to flow.Testnet.Chain() (or flow.Mainnet.Chain()) while keeping the same setup and assertions so the fix is validated on a forked network.fvm/evm/handler/handler_test.go (1)
1300-1304: Propagate this chain fix intoSetupHandlertoo.These tests now align
NewBlockStore(flow.Emulator, ...)withNewContractHandler(flow.Emulator, ...), butSetupHandlerat Line 1415 still hard-codesdefaultChainID. That leaves most of the integrated tests in this file on the old mixed emulator/testnet setup and can hide block-store regressions.♻️ Suggested follow-up
func SetupHandler(t testing.TB, backend types.Backend, rootAddr flow.Address) *handler.ContractHandler { return handler.NewContractHandler( flow.Emulator, rootAddr, flowTokenAddress, rootAddr, - handler.NewBlockStore(defaultChainID, backend, rootAddr), + handler.NewBlockStore(flow.Emulator, backend, rootAddr), handler.NewAddressAllocator(), backend, emulator.NewEmulator(backend, rootAddr), ) }Also applies to: 1322-1326, 1354-1373
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@fvm/evm/handler/handler_test.go` around lines 1300 - 1304, Tests were updated to construct the block store and contract handler with flow.Emulator (handler.NewBlockStore(flow.Emulator, ...) and handler.NewContractHandler(flow.Emulator, ...)) but SetupHandler still hard-codes defaultChainID, leaving tests using a mixed chain; update SetupHandler to accept or derive the chain parameter and pass flow.Emulator into the same calls (use handler.NewBlockStore(chain, ...) and handler.NewContractHandler(chain, ...)) instead of defaultChainID so the handler setup matches the test constructors (search for SetupHandler, defaultChainID, NewBlockStore and NewContractHandler to locate the spots to change).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@fvm/bootstrap.go`:
- Line 89: Add unit tests that cover the new evmTestHelpersEnabled bootstrap
flag: write one test that constructs the bootstrap with default options and
asserts evmTestHelpersEnabled is false, and a second test that passes the
explicit option/enabler (the same option used where evmTestHelpersEnabled is
set) and asserts it becomes true; locate the code paths around the
evmTestHelpersEnabled field and the bootstrap constructor/option function (the
option setter used in the diff) and exercise both branches (default and explicit
true) to ensure patch coverage for the flag.
In `@utils/unittest/execution_state.go`:
- Line 95: Add a unit test that exercises the fallback branch of the function
that returns the default commitment (the branch that currently returns
"6f96de6f0bc152c1d03383f220b62c0c0edc1aa11da57b6db3d62807a0bdde0d"): call that
function with a chain ID that is not Mainnet, Testnet, or Sandboxnet (an “other”
chain ID) and assert the returned string equals the hex literal; place the test
alongside existing execution_state tests in the same package and use the same
test helpers/setup so this branch is covered by patch-level unit tests.
---
Nitpick comments:
In `@fvm/evm/evm_test.go`:
- Around line 312-313: The tests currently only exercise the emulator chain; add
at least one forked-network regression case that uses flow.Testnet.Chain() or
flow.Mainnet.Chain() together with the existing helper flag
(WithEVMTestHelpersEnabled(cadence.NewBool(true))) to ensure the broken path on
forked networks is covered; update the test table/cases around the EVM test
helper sections (the blocks invoking flow.Emulator.Chain() and the test entries
at the ranges mentioned) to include a parallel case that swaps Chain() to
flow.Testnet.Chain() (or flow.Mainnet.Chain()) while keeping the same setup and
assertions so the fix is validated on a forked network.
In `@fvm/evm/handler/handler_test.go`:
- Around line 1300-1304: Tests were updated to construct the block store and
contract handler with flow.Emulator (handler.NewBlockStore(flow.Emulator, ...)
and handler.NewContractHandler(flow.Emulator, ...)) but SetupHandler still
hard-codes defaultChainID, leaving tests using a mixed chain; update
SetupHandler to accept or derive the chain parameter and pass flow.Emulator into
the same calls (use handler.NewBlockStore(chain, ...) and
handler.NewContractHandler(chain, ...)) instead of defaultChainID so the handler
setup matches the test constructors (search for SetupHandler, defaultChainID,
NewBlockStore and NewContractHandler to locate the spots to change).
In `@fvm/evm/stdlib/contract_test.go`:
- Around line 354-359: The shared deploy path currently always enables helpers
by calling stdlib.ContractCode(..., true); add a complementary test case that
deploys the same contract using evmTestHelpersEnabled=false to exercise the
disabled helpers path. Locate the test that builds/deploys via
stdlib.ContractCode (the call with the three contractsAddress args) and add a
parallel subtest or table entry that passes false instead of true, ensuring the
deployment, assertions, and teardown mirror the existing enabled case so toggle
behavior is fully covered.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0b52bba4-9d52-472e-8132-1ab2a2ce48cc
📒 Files selected for processing (9)
fvm/bootstrap.gofvm/evm/evm_test.gofvm/evm/handler/handler.gofvm/evm/handler/handler_test.gofvm/evm/stdlib/contract.gofvm/evm/stdlib/contract_test.gofvm/evm/stdlib/type.gofvm/evm/types/errors.goutils/unittest/execution_state.go
💤 Files with no reviewable changes (2)
- fvm/evm/types/errors.go
- fvm/evm/handler/handler.go
|
It worked for me with a local CLI build, added |
Follow up to #8391
The current way of injecting the
EVMtesting helpers, works when the Cadence testing framework is run with Flow Emulator, but not against forked networks (testnet/mainnet). That's because these forked networks are bootstrapped with their appropriate chain ID, and this makes the existing defensive check to fail.To overcome that, a new
BootstrapProcedureOptionis added, namelyWithEVMTestHelpersEnabled. This achieves the same defensive check, and allows 3rd party tools to control whether theEVMtesting helpers should be enabled or not.Summary by CodeRabbit
New Features
Bug Fixes