2020-04-01 18:49:21 +00:00
|
|
|
package keeper_test
|
2019-09-26 15:54:23 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-04-01 18:49:21 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
2019-09-26 15:54:23 +00:00
|
|
|
|
2021-05-17 10:13:08 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
2019-09-26 15:54:23 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2021-04-17 10:00:07 +00:00
|
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
2019-09-26 15:54:23 +00:00
|
|
|
|
2020-04-01 18:49:21 +00:00
|
|
|
"github.com/cosmos/ethermint/app"
|
2020-08-23 21:41:54 +00:00
|
|
|
ethermint "github.com/cosmos/ethermint/types"
|
2020-09-02 19:41:05 +00:00
|
|
|
"github.com/cosmos/ethermint/x/evm/types"
|
2019-09-26 15:54:23 +00:00
|
|
|
|
|
|
|
ethcmn "github.com/ethereum/go-ethereum/common"
|
2020-08-23 21:41:54 +00:00
|
|
|
ethcrypto "github.com/ethereum/go-ethereum/crypto"
|
2019-09-26 15:54:23 +00:00
|
|
|
|
2021-04-17 10:00:07 +00:00
|
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
2019-09-26 15:54:23 +00:00
|
|
|
)
|
|
|
|
|
2020-04-23 15:49:25 +00:00
|
|
|
const addrHex = "0x756F45E3FA69347A9A973A725E3C98bC4db0b4c1"
|
2020-07-15 10:36:55 +00:00
|
|
|
const hex = "0x0d87a3a5f73140f46aac1bf419263e4e94e87c292f25007700ab7f2060e2af68"
|
2020-04-23 15:49:25 +00:00
|
|
|
|
2020-05-03 01:56:18 +00:00
|
|
|
var (
|
2020-07-15 10:36:55 +00:00
|
|
|
hash = ethcmn.FromHex(hex)
|
2020-05-03 01:56:18 +00:00
|
|
|
)
|
2019-09-26 15:54:23 +00:00
|
|
|
|
2020-04-01 18:49:21 +00:00
|
|
|
type KeeperTestSuite struct {
|
|
|
|
suite.Suite
|
2019-09-26 15:54:23 +00:00
|
|
|
|
2021-05-17 10:13:08 +00:00
|
|
|
ctx sdk.Context
|
|
|
|
app *app.EthermintApp
|
|
|
|
queryClient types.QueryClient
|
|
|
|
address ethcmn.Address
|
2020-04-01 18:49:21 +00:00
|
|
|
}
|
2019-09-26 15:54:23 +00:00
|
|
|
|
2020-04-01 18:49:21 +00:00
|
|
|
func (suite *KeeperTestSuite) SetupTest() {
|
|
|
|
checkTx := false
|
2019-09-26 15:54:23 +00:00
|
|
|
|
2020-04-01 18:49:21 +00:00
|
|
|
suite.app = app.Setup(checkTx)
|
2021-05-31 09:05:32 +00:00
|
|
|
suite.ctx = suite.app.BaseApp.NewContext(checkTx, tmproto.Header{Height: 1, ChainID: "ethermint-1", Time: time.Now().UTC()})
|
2021-06-02 08:06:12 +00:00
|
|
|
suite.app.EvmKeeper.WithContext(suite.ctx)
|
2021-05-25 12:56:36 +00:00
|
|
|
|
2020-07-15 10:36:55 +00:00
|
|
|
suite.address = ethcmn.HexToAddress(addrHex)
|
2020-08-23 21:41:54 +00:00
|
|
|
|
2021-05-17 10:13:08 +00:00
|
|
|
queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry())
|
|
|
|
types.RegisterQueryServer(queryHelper, suite.app.EvmKeeper)
|
|
|
|
suite.queryClient = types.NewQueryClient(queryHelper)
|
|
|
|
|
2021-04-18 16:39:15 +00:00
|
|
|
balance := ethermint.NewPhotonCoin(sdk.ZeroInt())
|
2020-08-23 21:41:54 +00:00
|
|
|
acc := ðermint.EthAccount{
|
2021-04-17 10:00:07 +00:00
|
|
|
BaseAccount: authtypes.NewBaseAccount(sdk.AccAddress(suite.address.Bytes()), nil, 0, 0),
|
2020-08-23 21:41:54 +00:00
|
|
|
CodeHash: ethcrypto.Keccak256(nil),
|
|
|
|
}
|
|
|
|
|
|
|
|
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
|
2021-04-17 10:00:07 +00:00
|
|
|
suite.app.BankKeeper.SetBalance(suite.ctx, acc.GetAddress(), balance)
|
2019-09-26 15:54:23 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 18:49:21 +00:00
|
|
|
func TestKeeperTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(KeeperTestSuite))
|
|
|
|
}
|
2019-09-26 15:54:23 +00:00
|
|
|
|
2020-09-02 19:41:05 +00:00
|
|
|
func (suite *KeeperTestSuite) TestChainConfig() {
|
|
|
|
config, found := suite.app.EvmKeeper.GetChainConfig(suite.ctx)
|
|
|
|
suite.Require().True(found)
|
|
|
|
suite.Require().Equal(types.DefaultChainConfig(), config)
|
|
|
|
|
|
|
|
config.EIP150Block = sdk.NewInt(100)
|
|
|
|
suite.app.EvmKeeper.SetChainConfig(suite.ctx, config)
|
|
|
|
newConfig, found := suite.app.EvmKeeper.GetChainConfig(suite.ctx)
|
|
|
|
suite.Require().True(found)
|
|
|
|
suite.Require().Equal(config, newConfig)
|
|
|
|
}
|