-
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 tests for can_transfer, fee_checker, gas_comsume
- Loading branch information
1 parent
89cc591
commit ec4dfca
Showing
2 changed files
with
203 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package app_test | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/NibiruChain/nibiru/app" | ||
"github.com/NibiruChain/nibiru/eth" | ||
"github.com/NibiruChain/nibiru/x/evm/evmtest" | ||
) | ||
|
||
func (s *TestSuite) TestNewDynamicFeeChecker() { | ||
testCases := []struct { | ||
name string | ||
txSetup func(deps *evmtest.TestDeps) sdk.FeeTx | ||
ctxSetup func(deps *evmtest.TestDeps) | ||
wantErr string | ||
wantFee int64 | ||
wantPriority int64 | ||
}{ | ||
{ | ||
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) | ||
}, | ||
txSetup: func(deps *evmtest.TestDeps) sdk.FeeTx { | ||
txMsg := happyCreateContractTx(deps) | ||
txBuilder := deps.EncCfg.TxConfig.NewTxBuilder() | ||
tx, err := txMsg.BuildTx(txBuilder, eth.EthBaseDenom) | ||
s.Require().NoError(err) | ||
return tx | ||
}, | ||
wantErr: "", | ||
wantFee: gasLimitCreateContract().Int64(), | ||
wantPriority: 0, | ||
}, | ||
{ | ||
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) | ||
}, | ||
txSetup: func(deps *evmtest.TestDeps) sdk.FeeTx { | ||
txMsg := happyCreateContractTx(deps) | ||
txBuilder := deps.EncCfg.TxConfig.NewTxBuilder() | ||
tx, err := txMsg.BuildTx(txBuilder, eth.EthBaseDenom) | ||
s.Require().NoError(err) | ||
return tx | ||
}, | ||
wantErr: "insufficient fee", | ||
}, | ||
{ | ||
name: "happy: tx with sufficient fee", | ||
txSetup: func(deps *evmtest.TestDeps) sdk.FeeTx { | ||
txMsg := happyCreateContractTx(deps) | ||
txBuilder := deps.EncCfg.TxConfig.NewTxBuilder() | ||
tx, err := txMsg.BuildTx(txBuilder, eth.EthBaseDenom) | ||
s.Require().NoError(err) | ||
return tx | ||
}, | ||
wantErr: "", | ||
wantFee: gasLimitCreateContract().Int64(), | ||
wantPriority: 0, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
s.Run(tc.name, func() { | ||
deps := evmtest.NewTestDeps() | ||
checker := app.NewDynamicFeeChecker(deps.K) | ||
|
||
if tc.ctxSetup != nil { | ||
tc.ctxSetup(&deps) | ||
} | ||
|
||
fee, priority, err := checker(deps.Ctx, tc.txSetup(&deps)) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package app_test | ||
|
||
import ( | ||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" | ||
|
||
"github.com/NibiruChain/nibiru/app" | ||
"github.com/NibiruChain/nibiru/x/evm/evmtest" | ||
) | ||
|
||
func (s *TestSuite) TestGasWantedDecorator() { | ||
testCases := []struct { | ||
name string | ||
ctxSetup func(deps *evmtest.TestDeps) | ||
txSetup func(deps *evmtest.TestDeps) sdk.Tx | ||
wantErr string | ||
}{ | ||
{ | ||
name: "happy: non fee tx type", | ||
txSetup: func(deps *evmtest.TestDeps) sdk.Tx { | ||
return happyCreateContractTx(deps) | ||
}, | ||
wantErr: "", | ||
}, | ||
{ | ||
name: "happy: tx without gas, block gas limit 1000", | ||
ctxSetup: func(deps *evmtest.TestDeps) { | ||
cp := &tmproto.ConsensusParams{ | ||
Block: &tmproto.BlockParams{MaxGas: 1000}, | ||
} | ||
deps.Ctx = deps.Ctx.WithConsensusParams(cp) | ||
}, | ||
txSetup: func(deps *evmtest.TestDeps) sdk.Tx { | ||
return legacytx.StdTx{ | ||
Msgs: []sdk.Msg{ | ||
happyCreateContractTx(deps), | ||
}, | ||
} | ||
}, | ||
wantErr: "", | ||
}, | ||
{ | ||
name: "happy: tx with gas wanted 500, block gas limit 1000", | ||
ctxSetup: func(deps *evmtest.TestDeps) { | ||
cp := &tmproto.ConsensusParams{ | ||
Block: &tmproto.BlockParams{MaxGas: 1000}, | ||
} | ||
deps.Ctx = deps.Ctx.WithConsensusParams(cp) | ||
}, | ||
txSetup: func(deps *evmtest.TestDeps) sdk.Tx { | ||
return legacytx.StdTx{ | ||
Msgs: []sdk.Msg{ | ||
happyCreateContractTx(deps), | ||
}, | ||
Fee: legacytx.StdFee{Gas: 500}, | ||
} | ||
}, | ||
wantErr: "", | ||
}, | ||
{ | ||
name: "sad: tx with gas wanted 1000, block gas limit 500", | ||
ctxSetup: func(deps *evmtest.TestDeps) { | ||
cp := &tmproto.ConsensusParams{ | ||
Block: &tmproto.BlockParams{ | ||
MaxGas: 500, | ||
}, | ||
} | ||
deps.Ctx = deps.Ctx.WithConsensusParams(cp) | ||
}, | ||
txSetup: func(deps *evmtest.TestDeps) sdk.Tx { | ||
return legacytx.StdTx{ | ||
Msgs: []sdk.Msg{ | ||
happyCreateContractTx(deps), | ||
}, | ||
Fee: legacytx.StdFee{Gas: 1000}, | ||
} | ||
}, | ||
wantErr: "exceeds block gas limit", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
s.Run(tc.name, func() { | ||
deps := evmtest.NewTestDeps() | ||
stateDB := deps.StateDB() | ||
anteDec := app.AnteDecoratorGasWanted{} | ||
|
||
tx := tc.txSetup(&deps) | ||
s.Require().NoError(stateDB.Commit()) | ||
|
||
deps.Ctx = deps.Ctx.WithIsCheckTx(true) | ||
if tc.ctxSetup != nil { | ||
tc.ctxSetup(&deps) | ||
} | ||
_, err := anteDec.AnteHandle( | ||
deps.Ctx, tx, false, NextNoOpAnteHandler, | ||
) | ||
if tc.wantErr != "" { | ||
s.Require().ErrorContains(err, tc.wantErr) | ||
return | ||
} | ||
s.Require().NoError(err) | ||
}) | ||
} | ||
} |