Skip to content

Commit

Permalink
refactor(test): rename test deps Chain to App (#1998)
Browse files Browse the repository at this point in the history
* refactor: rename test deps Chain to App

* fix(e2e): increase localnet timeout because JSON-RPC server takes a little while longer to startup

---------

Co-authored-by: Unique Divine <[email protected]>
  • Loading branch information
k-yang and Unique-Divine authored Aug 12, 2024
1 parent d005d80 commit 53a2d71
Show file tree
Hide file tree
Showing 24 changed files with 92 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e-evm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
- name: "Launch localnet"
run: |
just localnet --no-build &
sleep 6
sleep 10
- name: "Run tests (just test)"
run: just test
Expand Down
8 changes: 4 additions & 4 deletions app/evmante/evmante_can_transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (s *TestSuite) TestCanTransferDecorator() {
beforeTxSetup: func(deps *evmtest.TestDeps, sdb *statedb.StateDB) {
s.NoError(
testapp.FundAccount(
deps.Chain.BankKeeper,
deps.App.BankKeeper,
deps.Ctx,
deps.Sender.NibiruAddr,
sdk.NewCoins(sdk.NewInt64Coin(eth.EthBaseDenom, 100)),
Expand All @@ -34,7 +34,7 @@ func (s *TestSuite) TestCanTransferDecorator() {
txMsg := evmtest.HappyTransferTx(deps, 0)
txBuilder := deps.EncCfg.TxConfig.NewTxBuilder()

gethSigner := deps.Sender.GethSigner(deps.Chain.EvmKeeper.EthChainID(deps.Ctx))
gethSigner := deps.Sender.GethSigner(deps.App.EvmKeeper.EthChainID(deps.Ctx))
keyringSigner := deps.Sender.KeyringSigner
err := txMsg.Sign(gethSigner, keyringSigner)
s.Require().NoError(err)
Expand All @@ -52,7 +52,7 @@ func (s *TestSuite) TestCanTransferDecorator() {
txMsg := evmtest.HappyTransferTx(deps, 0)
txBuilder := deps.EncCfg.TxConfig.NewTxBuilder()

gethSigner := deps.Sender.GethSigner(deps.Chain.EvmKeeper.EthChainID(deps.Ctx))
gethSigner := deps.Sender.GethSigner(deps.App.EvmKeeper.EthChainID(deps.Ctx))
keyringSigner := deps.Sender.KeyringSigner
err := txMsg.Sign(gethSigner, keyringSigner)
s.Require().NoError(err)
Expand Down Expand Up @@ -90,7 +90,7 @@ func (s *TestSuite) TestCanTransferDecorator() {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewCanTransferDecorator(&deps.Chain.AppKeepers.EvmKeeper)
anteDec := evmante.NewCanTransferDecorator(&deps.App.AppKeepers.EvmKeeper)
tx := tc.txSetup(&deps)

if tc.ctxSetup != nil {
Expand Down
2 changes: 1 addition & 1 deletion app/evmante/evmante_emit_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *TestSuite) TestEthEmitEventDecorator() {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewEthEmitEventDecorator(&deps.Chain.AppKeepers.EvmKeeper)
anteDec := evmante.NewEthEmitEventDecorator(&deps.App.AppKeepers.EvmKeeper)

tx := tc.txSetup(&deps)
s.Require().NoError(stateDB.Commit())
Expand Down
2 changes: 1 addition & 1 deletion app/evmante/evmante_gas_consume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (s *TestSuite) TestAnteDecEthGasConsume() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewAnteDecEthGasConsume(
&deps.Chain.AppKeepers.EvmKeeper, tc.maxGasWanted,
&deps.App.AppKeepers.EvmKeeper, tc.maxGasWanted,
)

tc.beforeTxSetup(&deps, stateDB)
Expand Down
12 changes: 6 additions & 6 deletions app/evmante/evmante_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *TestSuite) TestAnteHandlerEVM() {
txMsg := evmtest.HappyTransferTx(deps, 0)
txBuilder := deps.EncCfg.TxConfig.NewTxBuilder()

gethSigner := deps.Sender.GethSigner(deps.Chain.EvmKeeper.EthChainID(deps.Ctx))
gethSigner := deps.Sender.GethSigner(deps.App.EvmKeeper.EthChainID(deps.Ctx))
keyringSigner := deps.Sender.KeyringSigner
err := txMsg.Sign(gethSigner, keyringSigner)
s.Require().NoError(err)
Expand All @@ -74,15 +74,15 @@ func (s *TestSuite) TestAnteHandlerEVM() {
anteHandlerEVM := evmante.NewAnteHandlerEVM(
ante.AnteHandlerOptions{
HandlerOptions: authante.HandlerOptions{
AccountKeeper: deps.Chain.AccountKeeper,
BankKeeper: deps.Chain.BankKeeper,
FeegrantKeeper: deps.Chain.FeeGrantKeeper,
AccountKeeper: deps.App.AccountKeeper,
BankKeeper: deps.App.BankKeeper,
FeegrantKeeper: deps.App.FeeGrantKeeper,
SignModeHandler: deps.EncCfg.TxConfig.SignModeHandler(),
SigGasConsumer: authante.DefaultSigVerificationGasConsumer,
ExtensionOptionChecker: func(*codectypes.Any) bool { return true },
},
EvmKeeper: deps.Chain.EvmKeeper,
AccountKeeper: deps.Chain.AccountKeeper,
EvmKeeper: deps.App.EvmKeeper,
AccountKeeper: deps.App.AccountKeeper,
})

tx := tc.txSetup(&deps)
Expand Down
4 changes: 2 additions & 2 deletions app/evmante/evmante_increment_sender_seq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (s *TestSuite) TestAnteDecEthIncrementSenderSequence() {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewAnteDecEthIncrementSenderSequence(&deps.Chain.EvmKeeper, deps.Chain.AccountKeeper)
anteDec := evmante.NewAnteDecEthIncrementSenderSequence(&deps.App.EvmKeeper, deps.App.AccountKeeper)

if tc.beforeTxSetup != nil {
tc.beforeTxSetup(&deps, stateDB)
Expand All @@ -85,7 +85,7 @@ func (s *TestSuite) TestAnteDecEthIncrementSenderSequence() {
s.Require().NoError(err)

if tc.wantSeq > 0 {
seq := deps.Chain.AccountKeeper.GetAccount(deps.Ctx, deps.Sender.NibiruAddr).GetSequence()
seq := deps.App.AccountKeeper.GetAccount(deps.Ctx, deps.Sender.NibiruAddr).GetSequence()
s.Require().Equal(tc.wantSeq, seq)
}
})
Expand Down
2 changes: 1 addition & 1 deletion app/evmante/evmante_mempool_fees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (s *TestSuite) TestMempoolGasFeeDecorator() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
anteDec := evmante.NewMempoolGasPriceDecorator(&deps.Chain.AppKeepers.EvmKeeper)
anteDec := evmante.NewMempoolGasPriceDecorator(&deps.App.AppKeepers.EvmKeeper)

tx := tc.txSetup(&deps)

Expand Down
6 changes: 3 additions & 3 deletions app/evmante/evmante_setup_ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
func (s *TestSuite) TestEthSetupContextDecorator() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewEthSetUpContextDecorator(&deps.Chain.EvmKeeper)
anteDec := evmante.NewEthSetUpContextDecorator(&deps.App.EvmKeeper)

s.Require().NoError(stateDB.Commit())
tx := evmtest.HappyCreateContractTx(&deps)

// Set block gas used to non 0 to check that handler resets it
deps.Chain.EvmKeeper.EvmState.BlockGasUsed.Set(deps.Ctx, 1000)
deps.App.EvmKeeper.EvmState.BlockGasUsed.Set(deps.Ctx, 1000)

// Ante handler returns new context
newCtx, err := anteDec.AnteHandle(
Expand All @@ -37,7 +37,7 @@ func (s *TestSuite) TestEthSetupContextDecorator() {
s.Require().Equal(defaultGasConfig, newCtx.TransientKVGasConfig())

// Check that block gas used is reset to 0
gas, err := deps.Chain.EvmKeeper.EvmState.BlockGasUsed.Get(newCtx)
gas, err := deps.App.EvmKeeper.EvmState.BlockGasUsed.Get(newCtx)
s.Require().NoError(err)
s.Require().Equal(gas, uint64(0))
}
4 changes: 2 additions & 2 deletions app/evmante/evmante_sigverify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s *TestSuite) TestEthSigVerificationDecorator() {
name: "happy: signed ethereum tx",
txSetup: func(deps *evmtest.TestDeps) sdk.Tx {
tx := evmtest.HappyCreateContractTx(deps)
gethSigner := deps.Sender.GethSigner(deps.Chain.EvmKeeper.EthChainID(deps.Ctx))
gethSigner := deps.Sender.GethSigner(deps.App.EvmKeeper.EthChainID(deps.Ctx))
keyringSigner := deps.Sender.KeyringSigner
err := tx.Sign(gethSigner, keyringSigner)
s.Require().NoError(err)
Expand All @@ -68,7 +68,7 @@ func (s *TestSuite) TestEthSigVerificationDecorator() {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewEthSigVerificationDecorator(&deps.Chain.AppKeepers.EvmKeeper)
anteDec := evmante.NewEthSigVerificationDecorator(&deps.App.AppKeepers.EvmKeeper)

tx := tc.txSetup(&deps)
s.Require().NoError(stateDB.Commit())
Expand Down
12 changes: 6 additions & 6 deletions app/evmante/evmante_validate_basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (s *TestSuite) TestEthValidateBasicDecorator() {
s.Require().NoError(err)
txMsg := evmtest.HappyCreateContractTx(deps)

gethSigner := deps.Sender.GethSigner(deps.Chain.EvmKeeper.EthChainID(deps.Ctx))
gethSigner := deps.Sender.GethSigner(deps.App.EvmKeeper.EthChainID(deps.Ctx))
keyringSigner := deps.Sender.KeyringSigner
err = txMsg.Sign(gethSigner, keyringSigner)
s.Require().NoError(err)
Expand All @@ -127,7 +127,7 @@ func (s *TestSuite) TestEthValidateBasicDecorator() {
{
name: "sad: tx without extension options should fail",
txSetup: func(deps *evmtest.TestDeps) sdk.Tx {
chainID := deps.Chain.EvmKeeper.EthChainID(deps.Ctx)
chainID := deps.App.EvmKeeper.EthChainID(deps.Ctx)
gasLimit := uint64(10)
fees := sdk.NewCoins(sdk.NewInt64Coin("unibi", int64(gasLimit)))
msg := buildEthMsg(chainID, gasLimit, deps.Sender.NibiruAddr.String(), nil)
Expand All @@ -152,7 +152,7 @@ func (s *TestSuite) TestEthValidateBasicDecorator() {
{
name: "sad: tx with from value set should fail",
txSetup: func(deps *evmtest.TestDeps) sdk.Tx {
chainID := deps.Chain.EvmKeeper.EthChainID(deps.Ctx)
chainID := deps.App.EvmKeeper.EthChainID(deps.Ctx)
gasLimit := uint64(10)
fees := sdk.NewCoins(sdk.NewInt64Coin("unibi", int64(gasLimit)))
msg := buildEthMsg(chainID, gasLimit, deps.Sender.NibiruAddr.String(), nil)
Expand All @@ -163,7 +163,7 @@ func (s *TestSuite) TestEthValidateBasicDecorator() {
{
name: "sad: tx with fee <> msg fee",
txSetup: func(deps *evmtest.TestDeps) sdk.Tx {
chainID := deps.Chain.EvmKeeper.EthChainID(deps.Ctx)
chainID := deps.App.EvmKeeper.EthChainID(deps.Ctx)
gasLimit := uint64(10)
fees := sdk.NewCoins(sdk.NewInt64Coin("unibi", 5))
msg := buildEthMsg(chainID, gasLimit, "", nil)
Expand All @@ -174,7 +174,7 @@ func (s *TestSuite) TestEthValidateBasicDecorator() {
{
name: "sad: tx with gas limit <> msg gas limit",
txSetup: func(deps *evmtest.TestDeps) sdk.Tx {
chainID := deps.Chain.EvmKeeper.EthChainID(deps.Ctx)
chainID := deps.App.EvmKeeper.EthChainID(deps.Ctx)
gasLimit := uint64(10)
fees := sdk.NewCoins(sdk.NewInt64Coin("unibi", int64(gasLimit)))
msg := buildEthMsg(chainID, gasLimit, "", nil)
Expand All @@ -188,7 +188,7 @@ func (s *TestSuite) TestEthValidateBasicDecorator() {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewEthValidateBasicDecorator(&deps.Chain.AppKeepers.EvmKeeper)
anteDec := evmante.NewEthValidateBasicDecorator(&deps.App.AppKeepers.EvmKeeper)

tx := tc.txSetup(&deps)
s.Require().NoError(stateDB.Commit())
Expand Down
2 changes: 1 addition & 1 deletion app/evmante/evmante_verify_eth_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (s *TestSuite) TestAnteDecoratorVerifyEthAcc_CheckTx() {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewAnteDecVerifyEthAcc(&deps.Chain.AppKeepers.EvmKeeper, &deps.Chain.AppKeepers.AccountKeeper)
anteDec := evmante.NewAnteDecVerifyEthAcc(&deps.App.AppKeepers.EvmKeeper, &deps.App.AppKeepers.AccountKeeper)

tc.beforeTxSetup(&deps, stateDB)
tx := tc.txSetup(&deps)
Expand Down
1 change: 1 addition & 0 deletions contrib/scripts/localnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ val_address=${val_address:-"nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl"}
$BINARY add-genesis-account $val_address $GENESIS_COINS
# EVM encoded nibi address for the same account
$BINARY add-genesis-account nibi1cr6tg4cjvux00pj6zjqkh6d0jzg7mksaywxyl3 $GENESIS_COINS
$BINARY add-genesis-account nibi1ltez0kkshywzm675rkh8rj2eaf8et78cqjqrhc $GENESIS_COINS
echo_success "Successfully added genesis account: $val_key_name"

# ------------------------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions x/evm/evmmodule/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ func (s *Suite) TestExportInitGenesis() {

// Fund sender's wallet
spendableCoins := sdk.NewCoins(sdk.NewInt64Coin("unibi", totalSupply.Int64()))
err = deps.Chain.BankKeeper.MintCoins(deps.Ctx, evm.ModuleName, spendableCoins)
err = deps.App.BankKeeper.MintCoins(deps.Ctx, evm.ModuleName, spendableCoins)
s.Require().NoError(err)
err = deps.Chain.BankKeeper.SendCoinsFromModuleToAccount(
err = deps.App.BankKeeper.SendCoinsFromModuleToAccount(
deps.Ctx, evm.ModuleName, deps.Sender.NibiruAddr, spendableCoins,
)
s.Require().NoError(err)
Expand All @@ -87,13 +87,13 @@ func (s *Suite) TestExportInitGenesis() {
s.Require().NoError(err)

// Export genesis
evmGenesisState := evmmodule.ExportGenesis(deps.Ctx, &deps.EvmKeeper, deps.Chain.AccountKeeper)
authGenesisState := deps.Chain.AccountKeeper.ExportGenesis(deps.Ctx)
evmGenesisState := evmmodule.ExportGenesis(deps.Ctx, &deps.EvmKeeper, deps.App.AccountKeeper)
authGenesisState := deps.App.AccountKeeper.ExportGenesis(deps.Ctx)

// Init genesis from the exported state
deps = evmtest.NewTestDeps()
deps.Chain.AccountKeeper.InitGenesis(deps.Ctx, *authGenesisState)
evmmodule.InitGenesis(deps.Ctx, &deps.EvmKeeper, deps.Chain.AccountKeeper, *evmGenesisState)
deps.App.AccountKeeper.InitGenesis(deps.Ctx, *authGenesisState)
evmmodule.InitGenesis(deps.Ctx, &deps.EvmKeeper, deps.App.AccountKeeper, *evmGenesisState)

// Verify erc20 balances for users A, B and sender
balance, err := deps.EvmKeeper.ERC20().BalanceOf(erc20Addr, toUserA, deps.Ctx)
Expand Down
6 changes: 3 additions & 3 deletions x/evm/evmtest/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ func CreateFunTokenForBankCoin(
Name: bankDenom,
Symbol: bankDenom,
}
if deps.Chain.BankKeeper.HasDenomMetaData(deps.Ctx, bankDenom) {
if deps.App.BankKeeper.HasDenomMetaData(deps.Ctx, bankDenom) {
s.Failf("setting bank.DenomMetadata would overwrite existing denom \"%s\"", bankDenom)
}
deps.Chain.BankKeeper.SetDenomMetaData(deps.Ctx, bankMetadata)
deps.App.BankKeeper.SetDenomMetaData(deps.Ctx, bankMetadata)

// Give the sender funds for the fee
err := testapp.FundAccount(
deps.Chain.BankKeeper,
deps.App.BankKeeper,
deps.Ctx,
deps.Sender.NibiruAddr,
deps.EvmKeeper.FeeForCreateFunToken(deps.Ctx),
Expand Down
4 changes: 2 additions & 2 deletions x/evm/evmtest/evmante.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var NextNoOpAnteHandler sdk.AnteHandler = func(
func HappyTransferTx(deps *TestDeps, nonce uint64) *evm.MsgEthereumTx {
to := NewEthAccInfo().EthAddr
ethContractCreationTxParams := &evm.EvmTxArgs{
ChainID: deps.Chain.EvmKeeper.EthChainID(deps.Ctx),
ChainID: deps.App.EvmKeeper.EthChainID(deps.Ctx),
Nonce: nonce,
Amount: big.NewInt(10),
GasLimit: GasLimitCreateContract().Uint64(),
Expand Down Expand Up @@ -68,7 +68,7 @@ func buildTx(

func HappyCreateContractTx(deps *TestDeps) *evm.MsgEthereumTx {
ethContractCreationTxParams := &evm.EvmTxArgs{
ChainID: deps.Chain.EvmKeeper.EthChainID(deps.Ctx),
ChainID: deps.App.EvmKeeper.EthChainID(deps.Ctx),
Nonce: 1,
Amount: big.NewInt(10),
GasLimit: GasLimitCreateContract().Uint64(),
Expand Down
12 changes: 6 additions & 6 deletions x/evm/evmtest/test_deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

type TestDeps struct {
Chain *app.NibiruApp
App *app.NibiruApp
Ctx sdk.Context
EncCfg codec.EncodingConfig
EvmKeeper keeper.Keeper
Expand All @@ -36,21 +36,21 @@ func NewTestDeps() TestDeps {
encCfg := app.MakeEncodingConfig()
evm.RegisterInterfaces(encCfg.InterfaceRegistry)
eth.RegisterInterfaces(encCfg.InterfaceRegistry)
chain, ctx := testapp.NewNibiruTestAppAndContext()
app, ctx := testapp.NewNibiruTestAppAndContext()
ctx = ctx.WithChainID(eth.EIP155ChainID_Testnet)
ethAcc := NewEthAccInfo()
return TestDeps{
Chain: chain,
App: app,
Ctx: ctx,
EncCfg: encCfg,
EvmKeeper: chain.EvmKeeper,
EvmKeeper: app.EvmKeeper,
GenState: evm.DefaultGenesisState(),
Sender: ethAcc,
}
}

func (deps TestDeps) StateDB() *statedb.StateDB {
return statedb.New(deps.Ctx, &deps.Chain.EvmKeeper,
return statedb.New(deps.Ctx, &deps.App.EvmKeeper,
statedb.NewEmptyTxConfig(
gethcommon.BytesToHash(deps.Ctx.HeaderHash().Bytes()),
),
Expand All @@ -59,5 +59,5 @@ func (deps TestDeps) StateDB() *statedb.StateDB {

func (deps *TestDeps) GethSigner() gethcore.Signer {
ctx := deps.Ctx
return deps.Sender.GethSigner(deps.Chain.EvmKeeper.EthChainID(ctx))
return deps.Sender.GethSigner(deps.App.EvmKeeper.EthChainID(ctx))
}
Loading

0 comments on commit 53a2d71

Please sign in to comment.