Files
2024-01-03 09:44:09 +01:00

120 lines
4.3 KiB
Go

// (c) 2021-2024, Lux Partners Limited. All rights reserved.
// See the file LICENSE for licensing terms.
package nativeminter
import (
"testing"
"github.com/luxdefi/evm/precompile/allowlist"
"github.com/luxdefi/evm/precompile/precompileconfig"
"github.com/luxdefi/evm/precompile/testutils"
"github.com/luxdefi/evm/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"go.uber.org/mock/gomock"
)
func TestVerify(t *testing.T) {
admins := []common.Address{allowlist.TestAdminAddr}
enableds := []common.Address{allowlist.TestEnabledAddr}
managers := []common.Address{allowlist.TestManagerAddr}
tests := map[string]testutils.ConfigVerifyTest{
"valid config": {
Config: NewConfig(utils.NewUint64(3), admins, enableds, managers, nil),
ChainConfig: func() precompileconfig.ChainConfig {
config := precompileconfig.NewMockChainConfig(gomock.NewController(t))
config.EXPECT().IsDUpgrade(gomock.Any()).Return(true).AnyTimes()
return config
}(),
ExpectedError: "",
},
"invalid allow list config in native minter allowlist": {
Config: NewConfig(utils.NewUint64(3), admins, admins, nil, nil),
ExpectedError: "cannot set address",
},
"duplicate admins in config in native minter allowlist": {
Config: NewConfig(utils.NewUint64(3), append(admins, admins[0]), enableds, managers, nil),
ExpectedError: "duplicate address",
},
"duplicate enableds in config in native minter allowlist": {
Config: NewConfig(utils.NewUint64(3), admins, append(enableds, enableds[0]), managers, nil),
ExpectedError: "duplicate address",
},
"nil amount in native minter config": {
Config: NewConfig(utils.NewUint64(3), admins, nil, nil,
map[common.Address]*math.HexOrDecimal256{
common.HexToAddress("0x01"): math.NewHexOrDecimal256(123),
common.HexToAddress("0x02"): nil,
}),
ExpectedError: "initial mint cannot contain nil",
},
"negative amount in native minter config": {
Config: NewConfig(utils.NewUint64(3), admins, nil, nil,
map[common.Address]*math.HexOrDecimal256{
common.HexToAddress("0x01"): math.NewHexOrDecimal256(123),
common.HexToAddress("0x02"): math.NewHexOrDecimal256(-1),
}),
ExpectedError: "initial mint cannot contain invalid amount",
},
}
allowlist.VerifyPrecompileWithAllowListTests(t, Module, tests)
}
func TestEqual(t *testing.T) {
admins := []common.Address{allowlist.TestAdminAddr}
enableds := []common.Address{allowlist.TestEnabledAddr}
managers := []common.Address{allowlist.TestManagerAddr}
tests := map[string]testutils.ConfigEqualTest{
"non-nil config and nil other": {
Config: NewConfig(utils.NewUint64(3), admins, enableds, managers, nil),
Other: nil,
Expected: false,
},
"different type": {
Config: NewConfig(utils.NewUint64(3), admins, enableds, managers, nil),
Other: precompileconfig.NewMockConfig(gomock.NewController(t)),
Expected: false,
},
"different timestamp": {
Config: NewConfig(utils.NewUint64(3), admins, nil, nil, nil),
Other: NewConfig(utils.NewUint64(4), admins, nil, nil, nil),
Expected: false,
},
"different initial mint amounts": {
Config: NewConfig(utils.NewUint64(3), admins, nil, nil,
map[common.Address]*math.HexOrDecimal256{
common.HexToAddress("0x01"): math.NewHexOrDecimal256(1),
}),
Other: NewConfig(utils.NewUint64(3), admins, nil, nil,
map[common.Address]*math.HexOrDecimal256{
common.HexToAddress("0x01"): math.NewHexOrDecimal256(2),
}),
Expected: false,
},
"different initial mint addresses": {
Config: NewConfig(utils.NewUint64(3), admins, nil, nil,
map[common.Address]*math.HexOrDecimal256{
common.HexToAddress("0x01"): math.NewHexOrDecimal256(1),
}),
Other: NewConfig(utils.NewUint64(3), admins, nil, nil,
map[common.Address]*math.HexOrDecimal256{
common.HexToAddress("0x02"): math.NewHexOrDecimal256(1),
}),
Expected: false,
},
"same config": {
Config: NewConfig(utils.NewUint64(3), admins, nil, nil,
map[common.Address]*math.HexOrDecimal256{
common.HexToAddress("0x01"): math.NewHexOrDecimal256(1),
}),
Other: NewConfig(utils.NewUint64(3), admins, nil, nil,
map[common.Address]*math.HexOrDecimal256{
common.HexToAddress("0x01"): math.NewHexOrDecimal256(1),
}),
Expected: true,
},
}
allowlist.EqualPrecompileWithAllowListTests(t, Module, tests)
}