mirror of
https://github.com/luxfi/evm.git
synced 2026-09-24 00:27:44 +00:00
64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
// (c) 2023-2024, Lux Partners Limited. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package testutils
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/luxdefi/evm/commontype"
|
|
"github.com/luxdefi/evm/precompile/precompileconfig"
|
|
"github.com/stretchr/testify/require"
|
|
"go.uber.org/mock/gomock"
|
|
)
|
|
|
|
// ConfigVerifyTest is a test case for verifying a config
|
|
type ConfigVerifyTest struct {
|
|
Config precompileconfig.Config
|
|
ChainConfig precompileconfig.ChainConfig
|
|
ExpectedError string
|
|
}
|
|
|
|
// ConfigEqualTest is a test case for comparing two configs
|
|
type ConfigEqualTest struct {
|
|
Config precompileconfig.Config
|
|
Other precompileconfig.Config
|
|
Expected bool
|
|
}
|
|
|
|
func RunVerifyTests(t *testing.T, tests map[string]ConfigVerifyTest) {
|
|
for name, test := range tests {
|
|
t.Run(name, func(t *testing.T) {
|
|
t.Helper()
|
|
require := require.New(t)
|
|
|
|
chainConfig := test.ChainConfig
|
|
if chainConfig == nil {
|
|
ctrl := gomock.NewController(t)
|
|
mockChainConfig := precompileconfig.NewMockChainConfig(ctrl)
|
|
mockChainConfig.EXPECT().GetFeeConfig().AnyTimes().Return(commontype.ValidTestFeeConfig)
|
|
mockChainConfig.EXPECT().AllowedFeeRecipients().AnyTimes().Return(false)
|
|
mockChainConfig.EXPECT().IsDUpgrade(gomock.Any()).AnyTimes().Return(true)
|
|
chainConfig = mockChainConfig
|
|
}
|
|
err := test.Config.Verify(chainConfig)
|
|
if test.ExpectedError == "" {
|
|
require.NoError(err)
|
|
} else {
|
|
require.ErrorContains(err, test.ExpectedError)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func RunEqualTests(t *testing.T, tests map[string]ConfigEqualTest) {
|
|
for name, test := range tests {
|
|
t.Run(name, func(t *testing.T) {
|
|
t.Helper()
|
|
require := require.New(t)
|
|
|
|
require.Equal(test.Expected, test.Config.Equal(test.Other))
|
|
})
|
|
}
|
|
}
|