-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(evm): evmante increment_sender_seq, validate_basic, gas_consume,…
… reject_msgs, can_transfer
- Loading branch information
1 parent
ec4dfca
commit fde2383
Showing
11 changed files
with
384 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,109 @@ | ||
package app_test | ||
|
||
import ( | ||
"math/big" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/NibiruChain/nibiru/app" | ||
"github.com/NibiruChain/nibiru/eth" | ||
"github.com/NibiruChain/nibiru/x/evm/evmtest" | ||
"github.com/NibiruChain/nibiru/x/evm/statedb" | ||
) | ||
|
||
func (s *TestSuite) TestNewDynamicFeeChecker() { | ||
func (s *TestSuite) TestCanTransferDecorator() { | ||
testCases := []struct { | ||
name string | ||
txSetup func(deps *evmtest.TestDeps) sdk.FeeTx | ||
ctxSetup func(deps *evmtest.TestDeps) | ||
wantErr string | ||
wantFee int64 | ||
wantPriority int64 | ||
name string | ||
txSetup func(deps *evmtest.TestDeps) sdk.FeeTx | ||
ctxSetup func(deps *evmtest.TestDeps) | ||
beforeTxSetup func(deps *evmtest.TestDeps, sdb *statedb.StateDB) | ||
wantErr string | ||
}{ | ||
{ | ||
name: "happy: genesis tx with sufficient fee", | ||
ctxSetup: func(deps *evmtest.TestDeps) { | ||
gasPrice := sdk.NewInt64Coin("unibi", 1) | ||
deps.Ctx = deps.Ctx. | ||
WithBlockHeight(0). | ||
WithMinGasPrices( | ||
sdk.NewDecCoins(sdk.NewDecCoinFromCoin(gasPrice)), | ||
). | ||
WithIsCheckTx(true) | ||
name: "happy: signed tx, sufficient funds", | ||
beforeTxSetup: func(deps *evmtest.TestDeps, sdb *statedb.StateDB) { | ||
sdb.AddBalance(deps.Sender.EthAddr, big.NewInt(100)) | ||
}, | ||
txSetup: func(deps *evmtest.TestDeps) sdk.FeeTx { | ||
txMsg := happyCreateContractTx(deps) | ||
txMsg := happyTransfertTx(deps, 0) | ||
txBuilder := deps.EncCfg.TxConfig.NewTxBuilder() | ||
|
||
gethSigner := deps.Sender.GethSigner(deps.Chain.EvmKeeper.EthChainID(deps.Ctx)) | ||
keyringSigner := deps.Sender.KeyringSigner | ||
err := txMsg.Sign(gethSigner, keyringSigner) | ||
s.Require().NoError(err) | ||
|
||
tx, err := txMsg.BuildTx(txBuilder, eth.EthBaseDenom) | ||
s.Require().NoError(err) | ||
|
||
return tx | ||
}, | ||
wantErr: "", | ||
wantFee: gasLimitCreateContract().Int64(), | ||
wantPriority: 0, | ||
wantErr: "", | ||
}, | ||
{ | ||
name: "sad: genesis tx insufficient fee", | ||
ctxSetup: func(deps *evmtest.TestDeps) { | ||
gasPrice := sdk.NewInt64Coin("unibi", 2) | ||
deps.Ctx = deps.Ctx. | ||
WithBlockHeight(0). | ||
WithMinGasPrices( | ||
sdk.NewDecCoins(sdk.NewDecCoinFromCoin(gasPrice)), | ||
). | ||
WithIsCheckTx(true) | ||
}, | ||
name: "sad: signed tx, insufficient funds", | ||
txSetup: func(deps *evmtest.TestDeps) sdk.FeeTx { | ||
txMsg := happyCreateContractTx(deps) | ||
txMsg := happyTransfertTx(deps, 0) | ||
txBuilder := deps.EncCfg.TxConfig.NewTxBuilder() | ||
|
||
gethSigner := deps.Sender.GethSigner(deps.Chain.EvmKeeper.EthChainID(deps.Ctx)) | ||
keyringSigner := deps.Sender.KeyringSigner | ||
err := txMsg.Sign(gethSigner, keyringSigner) | ||
s.Require().NoError(err) | ||
|
||
tx, err := txMsg.BuildTx(txBuilder, eth.EthBaseDenom) | ||
s.Require().NoError(err) | ||
|
||
return tx | ||
}, | ||
wantErr: "insufficient fee", | ||
wantErr: "insufficient funds", | ||
}, | ||
{ | ||
name: "happy: tx with sufficient fee", | ||
name: "sad: unsigned tx", | ||
txSetup: func(deps *evmtest.TestDeps) sdk.FeeTx { | ||
txMsg := happyCreateContractTx(deps) | ||
txMsg := happyTransfertTx(deps, 0) | ||
txBuilder := deps.EncCfg.TxConfig.NewTxBuilder() | ||
|
||
tx, err := txMsg.BuildTx(txBuilder, eth.EthBaseDenom) | ||
s.Require().NoError(err) | ||
|
||
return tx | ||
}, | ||
wantErr: "", | ||
wantFee: gasLimitCreateContract().Int64(), | ||
wantPriority: 0, | ||
wantErr: "invalid transaction", | ||
}, | ||
{ | ||
name: "sad: tx with non evm message", | ||
txSetup: func(deps *evmtest.TestDeps) sdk.FeeTx { | ||
return nonEvmMsgTx(deps).(sdk.FeeTx) | ||
}, | ||
wantErr: "invalid message", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
s.Run(tc.name, func() { | ||
deps := evmtest.NewTestDeps() | ||
checker := app.NewDynamicFeeChecker(deps.K) | ||
stateDB := deps.StateDB() | ||
anteDec := app.NewCanTransferDecorator(deps.Chain.AppKeepers) | ||
tx := tc.txSetup(&deps) | ||
|
||
if tc.ctxSetup != nil { | ||
tc.ctxSetup(&deps) | ||
} | ||
if tc.beforeTxSetup != nil { | ||
tc.beforeTxSetup(&deps, stateDB) | ||
err := stateDB.Commit() | ||
s.Require().NoError(err) | ||
} | ||
|
||
fee, priority, err := checker(deps.Ctx, tc.txSetup(&deps)) | ||
|
||
_, err := anteDec.AnteHandle( | ||
deps.Ctx, tx, false, NextNoOpAnteHandler, | ||
) | ||
if tc.wantErr != "" { | ||
s.Require().ErrorContains(err, tc.wantErr) | ||
return | ||
} | ||
s.Require().NoError(err) | ||
s.Require().Equal(tc.wantFee, fee.AmountOf("unibi").Int64()) | ||
s.Require().Equal(tc.wantPriority, priority) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.