Skip to content

Commit

Permalink
finalize bank keeper changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Unique-Divine committed Oct 28, 2024
1 parent 7f904a0 commit efbd52e
Show file tree
Hide file tree
Showing 37 changed files with 124 additions and 224 deletions.
2 changes: 1 addition & 1 deletion app/ante/gas_wanted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (s *AnteTestSuite) TestGasWantedDecorator() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
stateDB := deps.NewStateDB()
anteDec := ante.AnteDecoratorGasWanted{}

tx := tc.txSetup(&deps)
Expand Down
2 changes: 1 addition & 1 deletion app/ante/handler_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type AnteHandlerOptions struct {
IBCKeeper *ibckeeper.Keeper
DevGasKeeper *devgaskeeper.Keeper
DevGasBankKeeper devgasante.BankKeeper
EvmKeeper evmkeeper.Keeper
EvmKeeper *evmkeeper.Keeper
AccountKeeper authkeeper.AccountKeeper

TxCounterStoreKey types.StoreKey
Expand Down
4 changes: 2 additions & 2 deletions app/evmante/evmante_can_transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func (s *TestSuite) TestCanTransferDecorator() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.CanTransferDecorator{&deps.App.AppKeepers.EvmKeeper}
stateDB := deps.NewStateDB()
anteDec := evmante.CanTransferDecorator{deps.App.AppKeepers.EvmKeeper}
tx := tc.txSetup(&deps)

if tc.ctxSetup != nil {
Expand Down
4 changes: 2 additions & 2 deletions app/evmante/evmante_emit_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func (s *TestSuite) TestEthEmitEventDecorator() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewEthEmitEventDecorator(&deps.App.AppKeepers.EvmKeeper)
stateDB := deps.NewStateDB()
anteDec := evmante.NewEthEmitEventDecorator(deps.App.AppKeepers.EvmKeeper)

tx := tc.txSetup(&deps)
s.Require().NoError(stateDB.Commit())
Expand Down
4 changes: 2 additions & 2 deletions app/evmante/evmante_gas_consume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ func (s *TestSuite) TestAnteDecEthGasConsume() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
stateDB := deps.NewStateDB()
anteDec := evmante.NewAnteDecEthGasConsume(
&deps.App.AppKeepers.EvmKeeper, tc.maxGasWanted,
deps.App.AppKeepers.EvmKeeper, tc.maxGasWanted,
)

tc.beforeTxSetup(&deps, stateDB)
Expand Down
18 changes: 9 additions & 9 deletions app/evmante/evmante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ func NewAnteHandlerEVM(
) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
// outermost AnteDecorator. SetUpContext must be called first
NewEthSetUpContextDecorator(&options.EvmKeeper),
NewMempoolGasPriceDecorator(&options.EvmKeeper),
NewEthValidateBasicDecorator(&options.EvmKeeper),
NewEthSigVerificationDecorator(&options.EvmKeeper),
NewAnteDecVerifyEthAcc(&options.EvmKeeper, options.AccountKeeper),
CanTransferDecorator{&options.EvmKeeper},
NewAnteDecEthGasConsume(&options.EvmKeeper, options.MaxTxGasWanted),
NewAnteDecEthIncrementSenderSequence(&options.EvmKeeper, options.AccountKeeper),
NewEthSetUpContextDecorator(options.EvmKeeper),
NewMempoolGasPriceDecorator(options.EvmKeeper),
NewEthValidateBasicDecorator(options.EvmKeeper),
NewEthSigVerificationDecorator(options.EvmKeeper),
NewAnteDecVerifyEthAcc(options.EvmKeeper, options.AccountKeeper),
CanTransferDecorator{options.EvmKeeper},
NewAnteDecEthGasConsume(options.EvmKeeper, options.MaxTxGasWanted),
NewAnteDecEthIncrementSenderSequence(options.EvmKeeper, options.AccountKeeper),
ante.AnteDecoratorGasWanted{},
// emit eth tx hash and index at the very last ante handler.
NewEthEmitEventDecorator(&options.EvmKeeper),
NewEthEmitEventDecorator(options.EvmKeeper),
)
}
2 changes: 1 addition & 1 deletion app/evmante/evmante_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (s *TestSuite) TestAnteHandlerEVM() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
stateDB := deps.NewStateDB()

anteHandlerEVM := evmante.NewAnteHandlerEVM(
ante.AnteHandlerOptions{
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 @@ -66,8 +66,8 @@ func (s *TestSuite) TestAnteDecEthIncrementSenderSequence() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewAnteDecEthIncrementSenderSequence(&deps.App.EvmKeeper, deps.App.AccountKeeper)
stateDB := deps.NewStateDB()
anteDec := evmante.NewAnteDecEthIncrementSenderSequence(deps.App.EvmKeeper, deps.App.AccountKeeper)

if tc.beforeTxSetup != nil {
tc.beforeTxSetup(&deps, stateDB)
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.App.AppKeepers.EvmKeeper)
anteDec := evmante.NewMempoolGasPriceDecorator(deps.App.AppKeepers.EvmKeeper)

tx := tc.txSetup(&deps)

Expand Down
4 changes: 2 additions & 2 deletions app/evmante/evmante_setup_ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

func (s *TestSuite) TestEthSetupContextDecorator() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewEthSetUpContextDecorator(&deps.App.EvmKeeper)
stateDB := deps.NewStateDB()
anteDec := evmante.NewEthSetUpContextDecorator(deps.App.EvmKeeper)

s.Require().NoError(stateDB.Commit())
tx := evmtest.HappyCreateContractTx(&deps)
Expand Down
4 changes: 2 additions & 2 deletions app/evmante/evmante_sigverify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func (s *TestSuite) TestEthSigVerificationDecorator() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewEthSigVerificationDecorator(&deps.App.AppKeepers.EvmKeeper)
stateDB := deps.NewStateDB()
anteDec := evmante.NewEthSigVerificationDecorator(deps.App.AppKeepers.EvmKeeper)

tx := tc.txSetup(&deps)
s.Require().NoError(stateDB.Commit())
Expand Down
4 changes: 2 additions & 2 deletions app/evmante/evmante_validate_basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ func (s *TestSuite) TestEthValidateBasicDecorator() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewEthValidateBasicDecorator(&deps.App.AppKeepers.EvmKeeper)
stateDB := deps.NewStateDB()
anteDec := evmante.NewEthValidateBasicDecorator(deps.App.AppKeepers.EvmKeeper)

tx := tc.txSetup(&deps)
s.Require().NoError(stateDB.Commit())
Expand Down
4 changes: 2 additions & 2 deletions app/evmante/evmante_verify_eth_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func (s *TestSuite) TestAnteDecoratorVerifyEthAcc_CheckTx() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewAnteDecVerifyEthAcc(&deps.App.AppKeepers.EvmKeeper, &deps.App.AppKeepers.AccountKeeper)
stateDB := deps.NewStateDB()
anteDec := evmante.NewAnteDecVerifyEthAcc(deps.App.AppKeepers.EvmKeeper, &deps.App.AppKeepers.AccountKeeper)

tc.beforeTxSetup(&deps, stateDB)
tx := tc.txSetup(&deps)
Expand Down
5 changes: 3 additions & 2 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func (app *NibiruApp) InitKeepers(
),
)

app.EvmKeeper = evmkeeper.NewKeeper(
evmKeeper := evmkeeper.NewKeeper(
appCodec,
keys[evm.StoreKey],
tkeys[evm.TransientKey],
Expand All @@ -388,6 +388,7 @@ func (app *NibiruApp) InitKeepers(
app.StakingKeeper,
cast.ToString(appOpts.Get("evm.tracer")),
)
app.EvmKeeper = &evmKeeper

// ---------------------------------- IBC keepers

Expand Down Expand Up @@ -644,7 +645,7 @@ func (app *NibiruApp) initAppModules(
ibcfee.NewAppModule(app.ibcFeeKeeper),
ica.NewAppModule(&app.icaControllerKeeper, &app.icaHostKeeper),

evmmodule.NewAppModule(&app.EvmKeeper, app.AccountKeeper),
evmmodule.NewAppModule(app.EvmKeeper, app.AccountKeeper),

// wasm
wasm.NewAppModule(
Expand Down
2 changes: 1 addition & 1 deletion app/keepers/all_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type PublicKeepers struct {
SudoKeeper keeper.Keeper
DevGasKeeper devgaskeeper.Keeper
TokenFactoryKeeper tokenfactorykeeper.Keeper
EvmKeeper evmkeeper.Keeper
EvmKeeper *evmkeeper.Keeper

// WASM keepers
WasmKeeper wasmkeeper.Keeper
Expand Down
4 changes: 2 additions & 2 deletions x/evm/evmmodule/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ func (s *Suite) TestExportInitGenesis() {
s.Require().NoError(err)

// Export genesis
evmGenesisState := evmmodule.ExportGenesis(deps.Ctx, &deps.EvmKeeper, deps.App.AccountKeeper)
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.App.AccountKeeper.InitGenesis(deps.Ctx, *authGenesisState)
evmmodule.InitGenesis(deps.Ctx, &deps.EvmKeeper, deps.App.AccountKeeper, *evmGenesisState)
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
4 changes: 2 additions & 2 deletions x/evm/evmtest/smart_contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (s *Suite) TestCreateContractTxMsg() {
EthAcc: ethAcc,
EthChainIDInt: deps.EvmKeeper.EthChainID(deps.Ctx),
GasPrice: big.NewInt(1),
Nonce: deps.StateDB().GetNonce(ethAcc.EthAddr),
Nonce: deps.NewStateDB().GetNonce(ethAcc.EthAddr),
}

ethTxMsg, err := evmtest.CreateContractMsgEthereumTx(args)
Expand All @@ -33,7 +33,7 @@ func (s *Suite) TestExecuteContractTxMsg() {
EthAcc: ethAcc,
EthChainIDInt: deps.EvmKeeper.EthChainID(deps.Ctx),
GasPrice: big.NewInt(1),
Nonce: deps.StateDB().GetNonce(ethAcc.EthAddr),
Nonce: deps.NewStateDB().GetNonce(ethAcc.EthAddr),
ContractAddress: &contractAddress,
Data: nil,
}
Expand Down
4 changes: 2 additions & 2 deletions x/evm/evmtest/test_deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type TestDeps struct {
App *app.NibiruApp
Ctx sdk.Context
EncCfg codec.EncodingConfig
EvmKeeper keeper.Keeper
EvmKeeper *keeper.Keeper
GenState *evm.GenesisState
Sender EthPrivKeyAcc
}
Expand All @@ -45,7 +45,7 @@ func NewTestDeps() TestDeps {
}
}

func (deps TestDeps) StateDB() *statedb.StateDB {
func (deps TestDeps) NewStateDB() *statedb.StateDB {
return deps.EvmKeeper.NewStateDB(
deps.Ctx,
statedb.NewEmptyTxConfig(
Expand Down
62 changes: 7 additions & 55 deletions x/evm/evmtest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"math/big"
"testing"

sdkmath "cosmossdk.io/math"

"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
gethcommon "github.com/ethereum/go-ethereum/common"
Expand All @@ -28,37 +26,6 @@ import (

type GethTxType = uint8

func TxTemplateAccessListTx() *gethcore.AccessListTx {
return &gethcore.AccessListTx{
GasPrice: big.NewInt(1),
Gas: gethparams.TxGas,
To: &gethcommon.Address{},
Value: big.NewInt(0),
Data: []byte{},
}
}

func TxTemplateLegacyTx() *gethcore.LegacyTx {
return &gethcore.LegacyTx{
GasPrice: big.NewInt(1),
Gas: gethparams.TxGas,
To: &gethcommon.Address{},
Value: big.NewInt(0),
Data: []byte{},
}
}

func TxTemplateDynamicFeeTx() *gethcore.DynamicFeeTx {
return &gethcore.DynamicFeeTx{
GasFeeCap: big.NewInt(10),
GasTipCap: big.NewInt(2),
Gas: gethparams.TxGas,
To: &gethcommon.Address{},
Value: big.NewInt(0),
Data: []byte{},
}
}

func NewEthTxMsgFromTxData(
deps *TestDeps,
txType GethTxType,
Expand Down Expand Up @@ -117,7 +84,7 @@ func NewEthTxMsgFromTxData(

// ExecuteNibiTransfer executes nibi transfer
func ExecuteNibiTransfer(deps *TestDeps, t *testing.T) *evm.MsgEthereumTx {
nonce := deps.StateDB().GetNonce(deps.Sender.EthAddr)
nonce := deps.NewStateDB().GetNonce(deps.Sender.EthAddr)
recipient := NewEthPrivAcc().EthAddr

txArgs := evm.JsonTxArgs{
Expand Down Expand Up @@ -156,7 +123,7 @@ func DeployContract(
}
bytecodeForCall := append(contract.Bytecode, packedArgs...)

nonce := deps.StateDB().GetNonce(deps.Sender.EthAddr)
nonce := deps.NewStateDB().GetNonce(deps.Sender.EthAddr)
ethTxMsg, gethSigner, krSigner, err := GenerateEthTxMsgAndSigner(
evm.JsonTxArgs{
Nonce: (*hexutil.Uint64)(&nonce),
Expand Down Expand Up @@ -213,7 +180,7 @@ func DeployAndExecuteERC20Transfer(
"transfer", NewEthPrivAcc().EthAddr, new(big.Int).SetUint64(1000),
)
require.NoError(t, err)
nonce = deps.StateDB().GetNonce(deps.Sender.EthAddr)
nonce = deps.NewStateDB().GetNonce(deps.Sender.EthAddr)
txArgs := evm.JsonTxArgs{
From: &deps.Sender.EthAddr,
To: &contractAddr,
Expand All @@ -238,7 +205,7 @@ func CallContractTx(
input []byte,
sender EthPrivKeyAcc,
) (ethTxMsg *evm.MsgEthereumTx, resp *evm.MsgEthereumTxResponse, err error) {
nonce := deps.StateDB().GetNonce(sender.EthAddr)
nonce := deps.NewStateDB().GetNonce(sender.EthAddr)
ethTxMsg, gethSigner, krSigner, err := GenerateEthTxMsgAndSigner(evm.JsonTxArgs{
From: &sender.EthAddr,
To: &contractAddr,
Expand All @@ -260,6 +227,8 @@ func CallContractTx(
return ethTxMsg, resp, err
}

var DefaultEthCallGasLimit = srvconfig.DefaultEthCallGasLimit

// GenerateEthTxMsgAndSigner estimates gas, sets gas limit and returns signer for
// the tx.
//
Expand Down Expand Up @@ -309,7 +278,7 @@ func TransferWei(
deps,
gethcore.LegacyTxType,
innerTxData,
deps.StateDB().GetNonce(ethAcc.EthAddr),
deps.NewStateDB().GetNonce(ethAcc.EthAddr),
&to,
amountWei,
gethparams.TxGas,
Expand All @@ -325,20 +294,3 @@ func TransferWei(
}
return err
}

// ValidLegacyTx: Useful initial condition for tests
// Exported only for use in tests.
func ValidLegacyTx() *evm.LegacyTx {
sdkInt := sdkmath.NewIntFromBigInt(evm.NativeToWei(big.NewInt(420)))
return &evm.LegacyTx{
Nonce: 24,
GasLimit: 50_000,
To: gethcommon.HexToAddress("0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed").Hex(),
GasPrice: &sdkInt,
Amount: &sdkInt,
Data: []byte{},
V: []byte{},
R: []byte{},
S: []byte{},
}
}
Loading

0 comments on commit efbd52e

Please sign in to comment.