To run our e2e contract tests, we will need to create an Avalanche L1 that has the Hello World precompile activated, so we will copy and paste the below genesis file into: /tests/precompile/genesis/hello_world.json.
Note: it's important that this has the same name as the HardHat test file we created previously.
Adding this to our genesis enables our HelloWorld precompile at the genesis block (0th block), with 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC as the admin address.
Now that we have declared the HardHat test and corresponding genesis.json file. The last step to running the e2e test is to declare the new test in /tests/precompile/solidity/suites.go.
At the bottom of the file you will see the following code commented out:
runDefaultHardhatTests will run the default Hardhat test command and use the default genesis path. If you want to use a different test command and genesis path than the defaults, you can use the utils.CreateSubnet and utils.RunTestCMD. See how they were used with default params here
You should copy and paste the ginkgo It node and update from {your_precompile} to hello_world. The string passed in to utils.RunDefaultHardhatTests(ctx, "your_precompile") will be used to find both the HardHat test file to execute and the genesis file, which is why you need to use the same name for both.
After modifying the It node, it should look like the following (you can copy and paste this directly if you prefer):
Now that we've set up the new ginkgo test, we can run the ginkgo test that we want by using the GINKGO_LABEL_FILTER. This environment variable is passed as a flag to Ginkgo in ./scripts/run_ginkgo.sh and restricts what tests will run to only the tests with a matching label.
Before we start testing, we will need to build the AvalancheGo binary and the custom Subnet-EVM binary.
Precompile-EVM bundles Subnet-EVM and runs it under the hood in the plugins/main.go. Meaning that Precompile-EVM binary works the same way as Subnet-EVM binary. Precompile-EVM repo has also same scripts and the build process as Subnet-EVM. Following steps also apply to Precompile-EVM.
You should have cloned AvalancheGo within your $GOPATH in the Background and Requirements section, so you can build AvalancheGo with the following command:
Once you've built AvalancheGo, you can confirm that it was successful by printing the version:
This should print something like the following (if you are running AvalancheGo v1.9.7):
This path will be used later as the environment variable AVALANCHEGO_EXEC_PATH in the network runner.
Please note that the RPCChainVM version of AvalancheGo and Subnet-EVM must match.
Once we've built AvalancheGo, we can navigate back to the repo and build the binary:
This will build the Subnet-EVM binary and place it in AvalancheGo's build/plugins directory by default at the file path: $GOPATH/src/github.com/ava-labs/avalanchego/build/plugins/srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy
To confirm that the Subnet-EVM binary is compatible with AvalancheGo, you can run the same version command and confirm the RPCChainVM version matches:
This should give similar output:
If the RPCChainVM Protocol version printed out does not match the one used in AvalancheGo then Subnet-EVM will not be able to talk to AvalancheGo and the blockchain will not start. You can find the compatibility table for AvalancheGo and Subnet-EVM here.
The build/plugins directory will later be used as the AVALANCHEGO_PLUGIN_PATH.
To run ONLY the HelloWorld precompile test, run the command:
use GINKGO_LABEL_FILTER env var to filter the test:
You will first see the node starting up in the BeforeSuite section of the precompile test:
After the BeforeSuite completes successfully, it will skip all but the HelloWorld labeled precompile test:
Finally, you will see the load test being skipped as well:
Looks like the tests are passing!
Note
If your tests failed, please retrace your steps. Most likely the error is that the precompile was not enabled and some code is missing. Try running npm install in the contracts directory to ensure that hardhat and other packages are installed.