laconicd/x/evm/types/params_test.go
Thomas Nguy 75d553674c
evm, rpc: disable BaseFee for non London block (#662)
* disable basefee if not london block

* add london block check in state transition

* fix linter

* add unit test

* clean code

* add changelog
2021-10-13 15:39:47 +02:00

138 lines
2.4 KiB
Go

package types
import (
"testing"
"github.com/ethereum/go-ethereum/params"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/stretchr/testify/require"
)
func TestParamKeyTable(t *testing.T) {
require.IsType(t, paramtypes.KeyTable{}, ParamKeyTable())
}
func TestParamsValidate(t *testing.T) {
testCases := []struct {
name string
params Params
expError bool
}{
{"default", DefaultParams(), false},
{
"valid",
NewParams("ara", true, true, DefaultChainConfig(), 2929, 1884, 1344),
false,
},
{
"empty",
Params{},
true,
},
{
"invalid evm denom",
Params{
EvmDenom: "@!#!@$!@5^32",
},
true,
},
{
"invalid eip",
Params{
EvmDenom: "stake",
ExtraEIPs: []int64{1},
},
true,
},
{
"invalid chain config",
NewParams("ara", true, true, ChainConfig{}, 2929, 1884, 1344),
false,
},
}
for _, tc := range testCases {
err := tc.params.Validate()
if tc.expError {
require.Error(t, err, tc.name)
} else {
require.NoError(t, err, tc.name)
}
}
}
func TestParamsEIPs(t *testing.T) {
params := NewParams("ara", true, true, DefaultChainConfig(), 2929, 1884, 1344)
actual := params.EIPs()
require.Equal(t, []int([]int{2929, 1884, 1344}), actual)
}
func TestParamsValidatePriv(t *testing.T) {
require.Error(t, validateEVMDenom(false))
require.NoError(t, validateEVMDenom("inj"))
require.Error(t, validateBool(""))
require.NoError(t, validateBool(true))
require.Error(t, validateEIPs(""))
require.NoError(t, validateEIPs([]int64{1884}))
}
func TestValidateChainConfig(t *testing.T) {
testCases := []struct {
name string
i interface{}
expError bool
}{
{
"invalid chain config type",
"string",
true,
},
{
"valid chain config type",
DefaultChainConfig(),
false,
},
}
for _, tc := range testCases {
err := validateChainConfig(tc.i)
if tc.expError {
require.Error(t, err, tc.name)
} else {
require.NoError(t, err, tc.name)
}
}
}
func TestIsLondon(t *testing.T) {
testCases := []struct {
name string
height int64
result bool
}{
{
"Before london block",
5,
false,
},
{
"After london block",
12_965_001,
true,
},
{
"london block",
12_965_000,
true,
},
}
for _, tc := range testCases {
ethConfig := params.MainnetChainConfig
require.Equal(t, IsLondon(ethConfig, tc.height), tc.result)
}
}