mirror of
https://github.com/luxfi/evm.git
synced 2026-09-24 00:27:44 +00:00
108 lines
3.9 KiB
Go
108 lines
3.9 KiB
Go
// (c) 2020-2022, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
package precompilebind
|
|
|
|
// 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/luxfi/evm/precompile/precompileconfig"
|
|
"github.com/luxfi/evm/precompile/testutils"
|
|
"github.com/luxfi/evm/utils"
|
|
{{- if .Contract.AllowList}}
|
|
"github.com/luxfi/evm/precompile/allowlist"
|
|
|
|
"github.com/luxfi/geth/common"
|
|
{{- end}}
|
|
"go.uber.org/mock/gomock"
|
|
)
|
|
|
|
// TestVerify tests the verification of Config.
|
|
func TestVerify(t *testing.T) {
|
|
{{- if .Contract.AllowList}}
|
|
admins := []common.Address{allowlist.TestAdminAddr}
|
|
enableds := []common.Address{allowlist.TestEnabledAddr}
|
|
managers := []common.Address{allowlist.TestManagerAddr}
|
|
{{- end}}
|
|
tests := map[string]testutils.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: "",
|
|
},
|
|
// 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.Error(),
|
|
// },
|
|
}
|
|
{{- 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.
|
|
allowlist.VerifyPrecompileWithAllowListTests(t, Module, tests)
|
|
{{- else}}
|
|
// Run verify tests.
|
|
testutils.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{allowlist.TestAdminAddr}
|
|
enableds := []common.Address{allowlist.TestEnabledAddr}
|
|
managers := []common.Address{allowlist.TestManagerAddr}
|
|
{{- end}}
|
|
tests := map[string]testutils.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.
|
|
allowlist.EqualPrecompileWithAllowListTests(t, Module, tests)
|
|
{{- else}}
|
|
// Run equal tests.
|
|
testutils.RunEqualTests(t, tests)
|
|
{{- end}}
|
|
}
|
|
`
|