github.com/ava-labs/subnet-evm@v0.6.4/tests/precompile/solidity/suites.go (about) 1 // Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 // Implements solidity tests. 5 package solidity 6 7 import ( 8 "context" 9 "fmt" 10 "time" 11 12 "github.com/ava-labs/subnet-evm/tests/utils" 13 ginkgo "github.com/onsi/ginkgo/v2" 14 ) 15 16 // Registers the Asynchronized Precompile Tests 17 // Before running the tests, this function creates all subnets given in the genesis files 18 // and then runs the hardhat tests for each one asynchronously if called with `ginkgo run -procs=`. 19 func RegisterAsyncTests() { 20 // Tests here assumes that the genesis files are in ./tests/precompile/genesis/ 21 // with the name {precompile_name}.json 22 genesisFiles, err := utils.GetFilesAndAliases("./tests/precompile/genesis/*.json") 23 if err != nil { 24 ginkgo.AbortSuite("Failed to get genesis files: " + err.Error()) 25 } 26 if len(genesisFiles) == 0 { 27 ginkgo.AbortSuite("No genesis files found") 28 } 29 subnetsSuite := utils.CreateSubnetsSuite(genesisFiles) 30 31 var _ = ginkgo.Describe("[Asynchronized Precompile Tests]", func() { 32 // Register the ping test first 33 utils.RegisterPingTest() 34 35 // Each ginkgo It node specifies the name of the genesis file (in ./tests/precompile/genesis/) 36 // to use to launch the subnet and the name of the TS test file to run on the subnet (in ./contracts/tests/) 37 ginkgo.It("contract native minter", ginkgo.Label("Precompile"), ginkgo.Label("ContractNativeMinter"), func() { 38 ctx, cancel := context.WithTimeout(context.Background(), time.Minute) 39 defer cancel() 40 41 blockchainID := subnetsSuite.GetBlockchainID("contract_native_minter") 42 runDefaultHardhatTests(ctx, blockchainID, "contract_native_minter") 43 }) 44 45 ginkgo.It("tx allow list", ginkgo.Label("Precompile"), ginkgo.Label("TxAllowList"), func() { 46 ctx, cancel := context.WithTimeout(context.Background(), time.Minute) 47 defer cancel() 48 49 blockchainID := subnetsSuite.GetBlockchainID("tx_allow_list") 50 runDefaultHardhatTests(ctx, blockchainID, "tx_allow_list") 51 }) 52 53 ginkgo.It("contract deployer allow list", ginkgo.Label("Precompile"), ginkgo.Label("ContractDeployerAllowList"), func() { 54 ctx, cancel := context.WithTimeout(context.Background(), time.Minute) 55 defer cancel() 56 57 blockchainID := subnetsSuite.GetBlockchainID("contract_deployer_allow_list") 58 runDefaultHardhatTests(ctx, blockchainID, "contract_deployer_allow_list") 59 }) 60 61 ginkgo.It("fee manager", ginkgo.Label("Precompile"), ginkgo.Label("FeeManager"), func() { 62 ctx, cancel := context.WithTimeout(context.Background(), time.Minute) 63 defer cancel() 64 65 blockchainID := subnetsSuite.GetBlockchainID("fee_manager") 66 runDefaultHardhatTests(ctx, blockchainID, "fee_manager") 67 }) 68 69 ginkgo.It("reward manager", ginkgo.Label("Precompile"), ginkgo.Label("RewardManager"), func() { 70 ctx, cancel := context.WithTimeout(context.Background(), time.Minute) 71 defer cancel() 72 73 blockchainID := subnetsSuite.GetBlockchainID("reward_manager") 74 runDefaultHardhatTests(ctx, blockchainID, "reward_manager") 75 }) 76 77 // ADD YOUR PRECOMPILE HERE 78 /* 79 ginkgo.It("your precompile", ginkgo.Label("Precompile"), ginkgo.Label("YourPrecompile"), func() { 80 ctx, cancel := context.WithTimeout(context.Background(), time.Minute) 81 defer cancel() 82 83 // Specify the name shared by the genesis file in ./tests/precompile/genesis/{your_precompile}.json 84 // and the test file in ./contracts/tests/{your_precompile}.ts 85 // If you want to use a different test command and genesis path than the defaults, you can 86 // use the utils.RunTestCMD. See utils.RunDefaultHardhatTests for an example. 87 subnetsSuite.RunHardhatTests(ctx, "your_precompile") 88 }) 89 */ 90 }) 91 } 92 93 // Default parameters are: 94 // 95 // 1. Hardhat contract environment is located at ./contracts 96 // 2. Hardhat test file is located at ./contracts/test/<test>.ts 97 // 3. npx is available in the ./contracts directory 98 func runDefaultHardhatTests(ctx context.Context, blockchainID, testName string) { 99 cmdPath := "./contracts" 100 // test path is relative to the cmd path 101 testPath := fmt.Sprintf("./test/%s.ts", testName) 102 utils.RunHardhatTests(ctx, blockchainID, cmdPath, testPath) 103 }