github.com/ava-labs/subnet-evm@v0.6.4/accounts/abi/bind/precompilebind/precompile_config_test_template.go (about) 1 // (c) 2019-2022, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 package precompilebind 4 5 // tmplSourcePrecompileConfigGo is the Go precompiled config source template. 6 const tmplSourcePrecompileConfigTestGo = ` 7 // Code generated 8 // This file is a generated precompile config test with the skeleton of test functions. 9 // The file is generated by a template. Please inspect every code and comment in this file before use. 10 11 package {{.Package}} 12 13 import ( 14 "testing" 15 16 "github.com/ava-labs/subnet-evm/precompile/precompileconfig" 17 "github.com/ava-labs/subnet-evm/precompile/testutils" 18 "github.com/ava-labs/subnet-evm/utils" 19 {{- if .Contract.AllowList}} 20 "github.com/ava-labs/subnet-evm/precompile/allowlist" 21 22 "github.com/ethereum/go-ethereum/common" 23 {{- end}} 24 "go.uber.org/mock/gomock" 25 ) 26 27 // TestVerify tests the verification of Config. 28 func TestVerify(t *testing.T) { 29 {{- if .Contract.AllowList}} 30 admins := []common.Address{allowlist.TestAdminAddr} 31 enableds := []common.Address{allowlist.TestEnabledAddr} 32 managers := []common.Address{allowlist.TestManagerAddr} 33 {{- end}} 34 tests := map[string]testutils.ConfigVerifyTest{ 35 "valid config": { 36 Config: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), 37 ChainConfig: func() precompileconfig.ChainConfig { 38 config := precompileconfig.NewMockChainConfig(gomock.NewController(t)) 39 config.EXPECT().IsDurango(gomock.Any()).Return(true).AnyTimes() 40 return config 41 }(), 42 ExpectedError: "", 43 }, 44 // CUSTOM CODE STARTS HERE 45 // Add your own Verify tests here, e.g.: 46 // "your custom test name": { 47 // Config: NewConfig(utils.NewUint64(3), {{- if .Contract.AllowList}} admins, enableds, managers{{- end}}), 48 // ExpectedError: ErrYourCustomError.Error(), 49 // }, 50 } 51 {{- if .Contract.AllowList}} 52 // Verify the precompile with the allowlist. 53 // This adds allowlist verify tests to your custom tests 54 // and runs them all together. 55 // Even if you don't add any custom tests, keep this. This will still 56 // run the default allowlist verify tests. 57 allowlist.VerifyPrecompileWithAllowListTests(t, Module, tests) 58 {{- else}} 59 // Run verify tests. 60 testutils.RunVerifyTests(t, tests) 61 {{- end}} 62 } 63 64 // TestEqual tests the equality of Config with other precompile configs. 65 func TestEqual(t *testing.T) { 66 {{- if .Contract.AllowList}} 67 admins := []common.Address{allowlist.TestAdminAddr} 68 enableds := []common.Address{allowlist.TestEnabledAddr} 69 managers := []common.Address{allowlist.TestManagerAddr} 70 {{- end}} 71 tests := map[string]testutils.ConfigEqualTest{ 72 "non-nil config and nil other": { 73 Config: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds,managers{{- end}}), 74 Other: nil, 75 Expected: false, 76 }, 77 "different type": { 78 Config: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), 79 Other: precompileconfig.NewMockConfig(gomock.NewController(t)), 80 Expected: false, 81 }, 82 "different timestamp": { 83 Config: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), 84 Other: NewConfig(utils.NewUint64(4){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), 85 Expected: false, 86 }, 87 "same config": { 88 Config: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), 89 Other: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), 90 Expected: true, 91 }, 92 // CUSTOM CODE STARTS HERE 93 // Add your own Equal tests here 94 } 95 {{- if .Contract.AllowList}} 96 // Run allow list equal tests. 97 // This adds allowlist equal tests to your custom tests 98 // and runs them all together. 99 // Even if you don't add any custom tests, keep this. This will still 100 // run the default allowlist equal tests. 101 allowlist.EqualPrecompileWithAllowListTests(t, Module, tests) 102 {{- else}} 103 // Run equal tests. 104 testutils.RunEqualTests(t, tests) 105 {{- end}} 106 } 107 `