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"
|
2021-06-29 10:54:29 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
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"
|
2021-06-22 10:14:40 +00:00
|
|
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
2019-09-26 15:54:23 +00:00
|
|
|
|
2021-06-22 10:49:18 +00:00
|
|
|
"github.com/tharsis/ethermint/app"
|
2021-06-29 10:54:29 +00:00
|
|
|
"github.com/tharsis/ethermint/crypto/ethsecp256k1"
|
|
|
|
"github.com/tharsis/ethermint/encoding"
|
2021-06-22 10:49:18 +00:00
|
|
|
ethermint "github.com/tharsis/ethermint/types"
|
|
|
|
"github.com/tharsis/ethermint/x/evm/types"
|
2019-09-26 15:54:23 +00:00
|
|
|
|
2021-06-29 17:02:21 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2019-09-26 15:54:23 +00:00
|
|
|
ethcmn "github.com/ethereum/go-ethereum/common"
|
2021-06-29 10:54:29 +00:00
|
|
|
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
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
|
2021-06-22 10:14:40 +00:00
|
|
|
consAddress sdk.ConsAddress
|
2021-06-29 10:54:29 +00:00
|
|
|
|
|
|
|
// for generate test tx
|
|
|
|
clientCtx client.Context
|
|
|
|
ethSigner ethtypes.Signer
|
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)
|
|
|
|
|
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),
|
2021-06-29 17:02:21 +00:00
|
|
|
CodeHash: common.BytesToHash(ethcrypto.Keccak256(nil)).String(),
|
2020-08-23 21:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
|
2021-06-22 10:14:40 +00:00
|
|
|
|
|
|
|
priv, err := ethsecp256k1.GenerateKey()
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
valAddr := sdk.ValAddress(suite.address.Bytes())
|
|
|
|
validator, err := stakingtypes.NewValidator(valAddr, priv.PubKey(), stakingtypes.Description{})
|
|
|
|
suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator)
|
|
|
|
suite.app.StakingKeeper.SetValidator(suite.ctx, validator)
|
|
|
|
suite.consAddress = sdk.ConsAddress(priv.PubKey().Address())
|
2021-06-29 10:54:29 +00:00
|
|
|
|
|
|
|
encodingConfig := encoding.MakeConfig(app.ModuleBasics)
|
|
|
|
suite.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig)
|
|
|
|
suite.ethSigner = ethtypes.LatestSignerForChainID(suite.app.EvmKeeper.ChainID())
|
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))
|
|
|
|
}
|