0g-chain/x/evmutil/genesis_test.go
Draco Li 2b123bf007
Add EIP712 ante (#1267)
* add eip712 ante

* minor cleanup

* eip712 integration test with bridge conversion

* fix issues

* update bridge module

* merge bridge module convert logic

* update eip712 tests & update deps

* remove v17 migrations

* remove v17 migrations

* fix genesis test

* fix erc20 to coin tx

* remove eth check

* clean up imports

* remove

* fix evmutil cli

* remove bridge comments

* address feedback

* rename mint method

* add transfer checks for locking & unlocking funds

* fix gas

* increase gas even more

* fix amount check

Co-authored-by: Ruaridh <rhuairahrighairidh@users.noreply.github.com>

Co-authored-by: Ruaridh <rhuairahrighairidh@users.noreply.github.com>
2022-08-23 13:04:40 -04:00

91 lines
2.5 KiB
Go

package evmutil_test
import (
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/suite"
"github.com/kava-labs/kava/x/evmutil"
"github.com/kava-labs/kava/x/evmutil/testutil"
"github.com/kava-labs/kava/x/evmutil/types"
)
type genesisTestSuite struct {
testutil.Suite
}
func (suite *genesisTestSuite) SetupTest() {
suite.Suite.SetupTest()
}
func (s *genesisTestSuite) TestInitGenesis_SetAccounts() {
gs := types.NewGenesisState(
[]types.Account{
{Address: s.Addrs[0], Balance: sdk.NewInt(100)},
},
types.DefaultParams(),
)
accounts := s.Keeper.GetAllAccounts(s.Ctx)
s.Require().Len(accounts, 0)
evmutil.InitGenesis(s.Ctx, s.Keeper, gs)
accounts = s.Keeper.GetAllAccounts(s.Ctx)
s.Require().Len(accounts, 1)
account := s.Keeper.GetAccount(s.Ctx, s.Addrs[0])
s.Require().Equal(account.Address, s.Addrs[0])
s.Require().Equal(account.Balance, sdk.NewInt(100))
}
func (s *genesisTestSuite) TestInitGenesis_SetParams() {
params := types.DefaultParams()
conversionPair := types.ConversionPair{
KavaERC20Address: testutil.MustNewInternalEVMAddressFromString("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2").Bytes(),
Denom: "weth",
}
params.EnabledConversionPairs = []types.ConversionPair{conversionPair}
gs := types.NewGenesisState(
[]types.Account{},
params,
)
evmutil.InitGenesis(s.Ctx, s.Keeper, gs)
params = s.Keeper.GetParams(s.Ctx)
s.Require().Len(params.EnabledConversionPairs, 1)
s.Require().Equal(conversionPair, params.EnabledConversionPairs[0])
}
func (s *genesisTestSuite) TestInitGenesis_ValidateFail() {
gs := types.NewGenesisState(
[]types.Account{
{Address: s.Addrs[0], Balance: sdk.NewInt(-100)},
},
types.DefaultParams(),
)
s.Require().Panics(func() {
evmutil.InitGenesis(s.Ctx, s.Keeper, gs)
})
}
func (s *genesisTestSuite) TestExportGenesis() {
accounts := []types.Account{
{Address: s.Addrs[0], Balance: sdk.NewInt(10)},
{Address: s.Addrs[1], Balance: sdk.NewInt(20)},
}
for _, account := range accounts {
s.Keeper.SetAccount(s.Ctx, account)
}
params := types.DefaultParams()
params.EnabledConversionPairs = []types.ConversionPair{
{
KavaERC20Address: testutil.MustNewInternalEVMAddressFromString("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2").Bytes(),
Denom: "weth"},
}
s.Keeper.SetParams(s.Ctx, params)
gs := evmutil.ExportGenesis(s.Ctx, s.Keeper)
s.Require().Equal(gs.Accounts, accounts)
s.Require().Equal(params, gs.Params)
}
func TestGenesisTestSuite(t *testing.T) {
suite.Run(t, new(genesisTestSuite))
}