Skip to content

Commit

Permalink
more wrap EVMTestApp in a func
Browse files Browse the repository at this point in the history
  • Loading branch information
jewei1997 committed Sep 6, 2024
1 parent 95b9555 commit d689de4
Show file tree
Hide file tree
Showing 33 changed files with 255 additions and 282 deletions.
18 changes: 9 additions & 9 deletions app/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (suite *AnteTestSuite) TestValidateDepedencies() {
}

func TestEvmAnteErrorHandler(t *testing.T) {
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx([]byte{})
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx([]byte{})
privKey := testkeeper.MockPrivateKey()
testPrivHex := hex.EncodeToString(privKey.Bytes())
key, _ := crypto.HexToECDSA(testPrivHex)
Expand All @@ -234,7 +234,7 @@ func TestEvmAnteErrorHandler(t *testing.T) {
Data: []byte{},
Nonce: 1, // will cause ante error
}
chainID := testkeeper.EVMTestApp.EvmKeeper.ChainID(ctx)
chainID := testkeeper.EVMTestApp().EvmKeeper.ChainID(ctx)
chainCfg := evmtypes.DefaultChainConfig()
ethCfg := chainCfg.EthereumConfig(chainID)
blockNum := big.NewInt(ctx.BlockHeight())
Expand All @@ -245,22 +245,22 @@ func TestEvmAnteErrorHandler(t *testing.T) {
require.Nil(t, err)
req, err := types.NewMsgEVMTransaction(txwrapper)
require.Nil(t, err)
builder := testkeeper.EVMTestApp.GetTxConfig().NewTxBuilder()
builder := testkeeper.EVMTestApp().GetTxConfig().NewTxBuilder()
builder.SetMsgs(req)
txToSend := builder.GetTx()
encodedTx, err := testkeeper.EVMTestApp.GetTxConfig().TxEncoder()(txToSend)
encodedTx, err := testkeeper.EVMTestApp().GetTxConfig().TxEncoder()(txToSend)
require.Nil(t, err)

addr, _ := testkeeper.PrivateKeyToAddresses(privKey)
testkeeper.EVMTestApp.BankKeeper.AddCoins(ctx, addr, sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(100000000000))), true)
res := testkeeper.EVMTestApp.DeliverTx(ctx, abci.RequestDeliverTx{Tx: encodedTx}, txToSend, sha256.Sum256(encodedTx))
testkeeper.EVMTestApp().BankKeeper.AddCoins(ctx, addr, sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(100000000000))), true)
res := testkeeper.EVMTestApp().DeliverTx(ctx, abci.RequestDeliverTx{Tx: encodedTx}, txToSend, sha256.Sum256(encodedTx))
require.NotEqual(t, 0, res.Code)
testkeeper.EVMTestApp.EvmKeeper.SetTxResults([]*abci.ExecTxResult{{
testkeeper.EVMTestApp().EvmKeeper.SetTxResults([]*abci.ExecTxResult{{
Code: res.Code,
Log: "nonce too high",
}})
testkeeper.EVMTestApp.EvmKeeper.SetMsgs([]*evmtypes.MsgEVMTransaction{req})
deferredInfo := testkeeper.EVMTestApp.EvmKeeper.GetAllEVMTxDeferredInfo(ctx)
testkeeper.EVMTestApp().EvmKeeper.SetMsgs([]*evmtypes.MsgEVMTransaction{req})
deferredInfo := testkeeper.EVMTestApp().EvmKeeper.GetAllEVMTxDeferredInfo(ctx)
require.Equal(t, 1, len(deferredInfo))
require.Contains(t, deferredInfo[0].Error, "nonce too high")
}
114 changes: 57 additions & 57 deletions app/receipt_test.go

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions evmrpc/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ func verifyBlockResult(t *testing.T, resObj map[string]interface{}) {
}

func TestEncodeTmBlock_EmptyTransactions(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
block := &coretypes.ResultBlock{
BlockID: MockBlockID,
Block: &tmtypes.Block{
Expand Down Expand Up @@ -182,8 +182,8 @@ func TestEncodeTmBlock_EmptyTransactions(t *testing.T) {
}

func TestEncodeBankMsg(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
fromSeiAddr, _ := testkeeper.MockAddressPair()
toSeiAddr, _ := testkeeper.MockAddressPair()
b := TxConfig.NewTxBuilder()
Expand Down Expand Up @@ -227,8 +227,8 @@ func TestEncodeBankMsg(t *testing.T) {
}

func TestEncodeWasmExecuteMsg(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx(nil)
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx(nil)
fromSeiAddr, fromEvmAddr := testkeeper.MockAddressPair()
toSeiAddr, _ := testkeeper.MockAddressPair()
b := TxConfig.NewTxBuilder()
Expand Down
1 change: 0 additions & 1 deletion evmrpc/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package evmrpc_test

import (
"errors"
"fmt"
"math/big"
"testing"

Expand Down
8 changes: 4 additions & 4 deletions precompiles/bank/bank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ func TestSendForUnlinkedReceiver(t *testing.T) {
}

func TestMetadata(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
k.BankKeeper().SetDenomMetaData(ctx, banktypes.Metadata{Name: "SEI", Symbol: "usei", Base: "usei"})
p, err := bank.NewPrecompile(k.BankKeeper(), k, k.AccountKeeper())
require.Nil(t, err)
Expand Down Expand Up @@ -381,7 +381,7 @@ func TestMetadata(t *testing.T) {
}

func TestRequiredGas(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
k := &testkeeper.EVMTestApp().EvmKeeper
p, err := bank.NewPrecompile(k.BankKeeper(), k, k.AccountKeeper())
require.Nil(t, err)
balanceRequiredGas := p.RequiredGas(p.GetExecutor().(*bank.PrecompileExecutor).BalanceID)
Expand All @@ -391,7 +391,7 @@ func TestRequiredGas(t *testing.T) {
}

func TestAddress(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
k := &testkeeper.EVMTestApp().EvmKeeper
p, err := bank.NewPrecompile(k.BankKeeper(), k, k.AccountKeeper())
require.Nil(t, err)
require.Equal(t, common.HexToAddress(bank.BankAddress), p.Address())
Expand Down
12 changes: 6 additions & 6 deletions precompiles/common/precompiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func TestValidteNonPayable(t *testing.T) {

func TestHandlePrecompileError(t *testing.T) {
_, evmAddr := testkeeper.MockAddressPair()
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx(nil)
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx(nil)
stateDB := state.NewDBImpl(ctx, k, false)
evm := &vm.EVM{StateDB: stateDB}

Expand All @@ -67,8 +67,8 @@ func (e *MockPrecompileExecutor) Execute(ctx sdk.Context, method *abi.Method, ca
}

func TestPrecompileRun(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx(nil)
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx(nil)
abiBz, err := os.ReadFile("erc20_abi.json")
require.Nil(t, err)
newAbi, err := abi.JSON(bytes.NewReader(abiBz))
Expand Down Expand Up @@ -108,8 +108,8 @@ func (e *MockDynamicGasPrecompileExecutor) EVMKeeper() common.EVMKeeper {
}

func TestDynamicGasPrecompileRun(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx(nil)
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx(nil)
abiBz, err := os.ReadFile("erc20_abi.json")
require.Nil(t, err)
newAbi, err := abi.JSON(bytes.NewReader(abiBz))
Expand Down
4 changes: 2 additions & 2 deletions precompiles/pointerview/pointerview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
)

func TestPointerView(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
p, err := pointerview.NewPrecompile(k)
require.Nil(t, err)
_, pointer := testkeeper.MockAddressPair()
Expand Down
6 changes: 3 additions & 3 deletions testutil/keeper/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func MockEVMKeeperWithPrecompiles() (*evmkeeper.Keeper, sdk.Context) {
return &k, ctx
}

func MockEVMKeeper() (*evmkeeper.Keeper, sdk.Context) {
testApp := app.Setup(false, false)
func MockEVMKeeper() (*evmkeeper.Keeper, sdk.Context, *app.App) {
testApp := app.Setup(false, true)
ctx := testApp.GetContextForDeliverTx([]byte{}).WithBlockHeight(8).WithBlockTime(time.Now())
k := testApp.EvmKeeper
k.InitGenesis(ctx, *evmtypes.DefaultGenesis())
Expand All @@ -77,7 +77,7 @@ func MockEVMKeeper() (*evmkeeper.Keeper, sdk.Context) {
if err != nil {
panic(err)
}
return &k, ctx
return &k, ctx, testApp
}

func MockAddressPair() (sdk.AccAddress, common.Address) {
Expand Down
4 changes: 2 additions & 2 deletions x/evm/ante/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
)

func TestBasicDecorator(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
a := ante.NewBasicDecorator(k)
msg, _ := types.NewMsgEVMTransaction(&ethtx.LegacyTx{})
ctx, err := a.AnteHandle(ctx, &mockTx{msgs: []sdk.Msg{msg}}, false, func(ctx sdk.Context, _ sdk.Tx, _ bool) (sdk.Context, error) {
Expand Down
8 changes: 4 additions & 4 deletions x/evm/ante/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
)

func TestEVMFeeCheckDecorator(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
handler := ante.NewEVMFeeCheckDecorator(k)
privKey := testkeeper.MockPrivateKey()
testPrivHex := hex.EncodeToString(privKey.Bytes())
Expand Down Expand Up @@ -115,8 +115,8 @@ func TestEVMFeeCheckDecorator(t *testing.T) {
}

func TestCalculatePriorityScenarios(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
decorator := ante.NewEVMFeeCheckDecorator(k)

_1gwei := big.NewInt(100000000000)
Expand Down
4 changes: 2 additions & 2 deletions x/evm/ante/gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
)

func TestGasLimitDecorator(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
a := ante.NewGasLimitDecorator(k)
limitMsg, _ := types.NewMsgEVMTransaction(&ethtx.LegacyTx{GasLimit: 100})
ctx, err := a.AnteHandle(ctx, &mockTx{msgs: []sdk.Msg{limitMsg}}, false, func(ctx sdk.Context, _ sdk.Tx, _ bool) (sdk.Context, error) {
Expand Down
34 changes: 17 additions & 17 deletions x/evm/ante/preprocess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
)

func TestPreprocessAnteHandler(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx(nil)
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx(nil)
handler := ante.NewEVMPreprocessDecorator(k, k.AccountKeeper())
privKey := testkeeper.MockPrivateKey()
seiAddr, evmAddr := testkeeper.PrivateKeyToAddresses(privKey)
Expand Down Expand Up @@ -71,8 +71,8 @@ func TestPreprocessAnteHandler(t *testing.T) {
}

func TestPreprocessAnteHandlerUnprotected(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx(nil)
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx(nil)
handler := ante.NewEVMPreprocessDecorator(k, k.AccountKeeper())
gasPrice := sdk.NewInt(73141930316)
amt := sdk.NewInt(270000000000000000)
Expand Down Expand Up @@ -100,8 +100,8 @@ func TestPreprocessAnteHandlerUnprotected(t *testing.T) {
}

func TestPreprocessAssociateTx(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx(nil)
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx(nil)
handler := ante.NewEVMPreprocessDecorator(k, k.AccountKeeper())
privKey := testkeeper.MockPrivateKey()
testPrivHex := hex.EncodeToString(privKey.Bytes())
Expand Down Expand Up @@ -144,8 +144,8 @@ func TestPreprocessAssociateTx(t *testing.T) {
}

func TestPreprocessAssociateTxWithWeiBalance(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx(nil)
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx(nil)
handler := ante.NewEVMPreprocessDecorator(k, k.AccountKeeper())
privKey := testkeeper.MockPrivateKey()
testPrivHex := hex.EncodeToString(privKey.Bytes())
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestGetVersion(t *testing.T) {
}

func TestAnteDeps(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
k := &testkeeper.EVMTestApp().EvmKeeper
handler := ante.NewEVMPreprocessDecorator(k, k.AccountKeeper())
msg, _ := types.NewMsgEVMTransaction(&ethtx.LegacyTx{GasLimit: 100})
msg.Derived = &derived.Derived{
Expand All @@ -208,8 +208,8 @@ func TestAnteDeps(t *testing.T) {
}

func TestEVMAddressDecorator(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx(nil)
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx(nil)
privKey := testkeeper.MockPrivateKey()
sender, evmAddr := testkeeper.PrivateKeyToAddresses(privKey)
recipient, _ := testkeeper.MockAddressPair()
Expand All @@ -226,8 +226,8 @@ func TestEVMAddressDecorator(t *testing.T) {
}

func TestIsAccountBalancePositive(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx(nil)
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx(nil)
s1, e1 := testkeeper.MockAddressPair()
s2, e2 := testkeeper.MockAddressPair()
s3, e3 := testkeeper.MockAddressPair()
Expand Down Expand Up @@ -259,8 +259,8 @@ func (m MockTxIncompatible) ValidateBasic() error {
}

func TestEVMAddressDecoratorContinueDespiteErrors(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx(nil)
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx(nil)
handler := ante.NewEVMAddressDecorator(k, k.AccountKeeper())

_, err := handler.AnteHandle(ctx, MockTxIncompatible{}, false, func(ctx sdk.Context, _ sdk.Tx, _ bool) (sdk.Context, error) {
Expand Down Expand Up @@ -301,8 +301,8 @@ func TestEVMAddressDecoratorContinueDespiteErrors(t *testing.T) {
}

func TestMigrateBalance(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx(nil)
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx(nil)
admin, _ := testkeeper.MockAddressPair()
seiAddr, evmAddr := testkeeper.MockAddressPair()
k.BankKeeper().AddCoins(ctx, sdk.AccAddress(evmAddr[:]), sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(2))), false)
Expand Down
8 changes: 4 additions & 4 deletions x/evm/ante/sig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
)

func TestEVMSigVerifyDecorator(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
handler := ante.NewEVMSigVerifyDecorator(k, func() sdk.Context { return ctx })
privKey := testkeeper.MockPrivateKey()
testPrivHex := hex.EncodeToString(privKey.Bytes())
Expand Down Expand Up @@ -101,8 +101,8 @@ func TestEVMSigVerifyDecorator(t *testing.T) {
}

func TestSigVerifyPendingTransaction(t *testing.T) {
k := &testkeeper.EVMTestApp.EvmKeeper
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
k := &testkeeper.EVMTestApp().EvmKeeper
ctx := testkeeper.EVMTestApp().GetContextForDeliverTx([]byte{}).WithBlockTime(time.Now())
ctx = ctx.WithIsCheckTx(true)
handler := ante.NewEVMSigVerifyDecorator(k, func() sdk.Context { return ctx })
privKey := testkeeper.MockPrivateKey()
Expand Down
Loading

0 comments on commit d689de4

Please sign in to comment.