-
Notifications
You must be signed in to change notification settings - Fork 276
feat: Add go test utilities for precompiles and migrate one test (Phase 2) #1830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| } | ||
|
|
||
| // TestAllowListRoles demonstrates role management | ||
| func TestAllowListRoles(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test will fail as libevm's simulated backend has no visibility into subnetevm's precompiles, nor is there anyway to deploy them to libevm's simualted backend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nor is there anyway to deploy them to libevm's simualted backend
Call evm.RegisterAllLibEVMExtras() in TestMain()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This not sufficient - see what I wrote in the original post. If you can get this test to work, I'd love to see it as that would allow us to get rid of the tmpnet stuff entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See this comment to Austin which hopefully provides more context to the original post:
alarso16
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand your logic for eliminating option 2. We already use the custom subnet-evm/ethclient implementation everywhere in the repo because of the genesis differences, so why would you try and import the libevm implementation?
| RewardManagerAddress = common.HexToAddress("0x0200000000000000000000000000000000000004") | ||
| WarpAddress = common.HexToAddress("0x0200000000000000000000000000000000000005") | ||
| ) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(note to self) Review the rest of the file, below this comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we testing against a tmpnet for any of this? The goal is just to confirm that the Solidity and the precompiles work properly together, which should be an integration and not an e2e test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my original PR, post, this comment thread , and my reply to Austin asking the same thing.
In short: personal skill issue. I don't think it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHub insists that I leave a comment ¯\_(ツ)_/¯
libevm's bind.ContractTransactor: subnet-evm's bind.ContractTransactor: subnet-evm/accounts/abi/bind/backend.go Lines 74 to 80 in 65f4d47
In summary:
|
Co-authored-by: Arran Schlosberg <519948+ARR4N@users.noreply.github.com> Signed-off-by: Jonathan Oppenheimer <147infiniti@gmail.com>
Why this should be merged
This is phase 2 of the conversion from a
npm/typescript based testing framework to a go based framework.To start, let me provide some background: there are two basic approaches we could take here in transitioning the framework:
Option A: keep existing tmpnet infrastructure
tests/utils/subnet.goinfrastructureOption B: configure precompiles in
libevm'ssimulated.Backenddirectly and testUpon investigation, I determined that Option B was not possible without modifications to
libevm:The
libevmsimulated backend always boots with the stock dev genesis (params.AllDevChainProtocolChanges) and never passes through any Avalanche-specific extras. You can see the hard-coded setup in libevm/ethclient/simulated/backend.go (NewBackend), where the default Genesis config is created with plain libevm params -- there’s no call into subnet-evm’s extras or precompile registration.Even if we changed that to inject a
subnet-evmChainConfig,libevm’s core genesis logic has no idea what "GenesisPrecompiles" are. The go file inlibevmsimply initializes accounts and code; there’s no hook that walks the config and installs stateful precompiles. Thesubnet-evmtree explicitly does that work (it calls ApplyPrecompileActivations during genesis creation), but that function doesn’t exist in the libevm copy. Without it, the precompile contracts never get written to state, and as a result, every0x0200…address still looks empty and the bindings revert with “no contract code”. I saw this first hand when trying to test it out.In the absence of a better way to test these with libevm's
simulated.Backend,I moved forward with Option A.How this works
tests/precompile/contracttest/helpers.go- Test backend setup, utilitiestests/precompile/contracttest/roles.go- AllowList role management (needs tmpnet for precompiles)tests/precompile/contracttest/tmpnet.go- Tmpnet/RPC backend helpers.tests/precompile/contracttest/example_test.go- Examples (simulated backend)I also migrated a single test
contract_deployer_allow_list_test,as a proof of concept for this approach. I was largely able to match the format of the typescript test. Here is the mapping of tests to show no coverage was lost:test("precompile should see owner address has admin role")step_verifySenderIsAdminginkgo.It("should verify deployer list shows admin has admin role via precompile")test("precompile should see test address has no role")step_newAddressHasNoRoleginkgo.It("should verify new address has no role")test("contract should report test address has no admin role")step_noRoleIsNotAdminginkgo.It("should verify contract correctly reports admin status")(partial)test("contract should report owner address has admin role")step_ownerIsAdminginkgo.It("should verify contract correctly reports admin status")(combined)test("should not let test address deploy")step_noRoleCannotDeployginkgo.It("should not let address with no role deploy contracts")test("should allow admin to add contract as admin")step_adminAddContractAsAdminginkgo.It("should allow admin to add contract as admin via precompile")test("should allow admin to add deployer address as deployer through contract")step_addDeployerThroughContractginkgo.It("should allow admin to add deployer via contract")test("should let deployer address to deploy")step_deployerCanDeployginkgo.It("should allow enabled address to deploy contracts")test("should let admin revoke deployer")step_adminCanRevokeDeployerginkgo.It("should allow admin to revoke deployer role")I have also called out specific things of note via comments below. The next steps are to migrate each of the additional 6 tests, one at a time.
How this was tested
CI. We deliberately kept the Hardhat bridge in place so the TypeScript suites can run beside the new Go tests during migration. The tmpnet-backed Go suites (labeled
Go) now execute via Ginkgo in CI, butRunHardhatTests()and the async TypeScript descriptors remain until Phase 3 completes the rewrites, and in Phase 4, we remove all the npm code in one go.Need to be documented?
No
Need to update RELEASES.md?
No.