Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions accounts/abi/bind/precompilebind/precompile_config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,107 @@ func (c *Config) Equal(s precompileconfig.Config) bool {
return equals
}
`

// tmplSourcePrecompileConfigGo is the Go precompiled config source template.
const tmplSourcePrecompileConfigTestGo = `
// Code generated
// This file is a generated precompile config test with the skeleton of test functions.
// The file is generated by a template. Please inspect every code and comment in this file before use.

package {{.Package}}

import (
"testing"

"github.com/ava-labs/subnet-evm/precompile/precompileconfig"
"github.com/ava-labs/subnet-evm/precompile/precompiletest"
"github.com/ava-labs/subnet-evm/utils"
{{- if .Contract.AllowList}}
"github.com/ava-labs/subnet-evm/precompile/allowlist/allowlisttest"

"github.com/ava-labs/libevm/common"
{{- end}}
"go.uber.org/mock/gomock"
)

// TestVerify tests the verification of Config.
func TestVerify(t *testing.T) {
{{- if .Contract.AllowList}}
admins := []common.Address{allowlisttest.TestAdminAddr}
enableds := []common.Address{allowlisttest.TestEnabledAddr}
managers := []common.Address{allowlisttest.TestManagerAddr}
{{- end}}
tests := map[string]precompiletest.ConfigVerifyTest{
"valid config": {
Config: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}),
ChainConfig: func() precompileconfig.ChainConfig {
config := precompileconfig.NewMockChainConfig(gomock.NewController(t))
config.EXPECT().IsDurango(gomock.Any()).Return(true).AnyTimes()
return config
}(),
ExpectedError: nil,
},
// CUSTOM CODE STARTS HERE
// Add your own Verify tests here, e.g.:
// "your custom test name": {
// Config: NewConfig(utils.NewUint64(3), {{- if .Contract.AllowList}} admins, enableds, managers{{- end}}),
// ExpectedError: ErrYourCustomError,
// },
}
{{- if .Contract.AllowList}}
// Verify the precompile with the allowlist.
// This adds allowlist verify tests to your custom tests
// and runs them all together.
// Even if you don't add any custom tests, keep this. This will still
// run the default allowlist verify tests.
allowlisttest.VerifyPrecompileWithAllowListTests(t, Module, tests)
{{- else}}
// Run verify tests.
precompiletest.RunVerifyTests(t, tests)
{{- end}}
}

// TestEqual tests the equality of Config with other precompile configs.
func TestEqual(t *testing.T) {
{{- if .Contract.AllowList}}
admins := []common.Address{allowlisttest.TestAdminAddr}
enableds := []common.Address{allowlisttest.TestEnabledAddr}
managers := []common.Address{allowlisttest.TestManagerAddr}
{{- end}}
tests := map[string]precompiletest.ConfigEqualTest{
"non-nil config and nil other": {
Config: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds,managers{{- end}}),
Other: nil,
Expected: false,
},
"different type": {
Config: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}),
Other: precompileconfig.NewMockConfig(gomock.NewController(t)),
Expected: false,
},
"different timestamp": {
Config: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}),
Other: NewConfig(utils.NewUint64(4){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}),
Expected: false,
},
"same config": {
Config: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}),
Other: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}),
Expected: true,
},
// CUSTOM CODE STARTS HERE
// Add your own Equal tests here
}
{{- if .Contract.AllowList}}
// Run allow list equal tests.
// This adds allowlist equal tests to your custom tests
// and runs them all together.
// Even if you don't add any custom tests, keep this. This will still
// run the default allowlist equal tests.
allowlisttest.EqualPrecompileWithAllowListTests(t, Module, tests)
{{- else}}
// Run equal tests.
precompiletest.RunEqualTests(t, tests)
{{- end}}
}
`
109 changes: 0 additions & 109 deletions accounts/abi/bind/precompilebind/precompile_config_test_template.go

This file was deleted.

Loading
Loading