fix: improve ante basic test accuracy and readability (#25034)
Co-authored-by: Alex | Interchain Labs <alex@interchainlabs.io>
This commit is contained in:
parent
f08a14e98a
commit
399cc759a9
@ -48,7 +48,7 @@ func TestValidateBasic(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = antehandler(suite.ctx, validTx, false)
|
||||
require.Nil(t, err, "ValidateBasicDecorator returned error on valid tx. err: %v", err)
|
||||
require.NoError(t, err, "ValidateBasicDecorator returned error on valid tx. err: %v", err)
|
||||
|
||||
// test decorator skips on recheck
|
||||
suite.ctx = suite.ctx.WithIsReCheckTx(true)
|
||||
@ -56,7 +56,7 @@ func TestValidateBasic(t *testing.T) {
|
||||
// decorator should skip processing invalidTx on recheck and thus return nil-error
|
||||
_, err = antehandler(suite.ctx, invalidTx, false)
|
||||
|
||||
require.Nil(t, err, "ValidateBasicDecorator ran on ReCheck")
|
||||
require.NoError(t, err, "ValidateBasicDecorator ran on ReCheck")
|
||||
}
|
||||
|
||||
func TestValidateMemo(t *testing.T) {
|
||||
@ -92,7 +92,7 @@ func TestValidateMemo(t *testing.T) {
|
||||
|
||||
// require small memos pass ValidateMemo Decorator
|
||||
_, err = antehandler(suite.ctx, validTx, false)
|
||||
require.Nil(t, err, "ValidateBasicDecorator returned error on valid tx. err: %v", err)
|
||||
require.NoError(t, err, "ValidateMemoDecorator returned error on valid tx. err: %v", err)
|
||||
}
|
||||
|
||||
func TestConsumeGasForTxSize(t *testing.T) {
|
||||
@ -130,7 +130,7 @@ func TestConsumeGasForTxSize(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
txBytes, err := suite.clientCtx.TxConfig.TxJSONEncoder()(tx)
|
||||
require.Nil(t, err, "Cannot marshal tx: %v", err)
|
||||
require.NoError(t, err, "Cannot marshal tx: %v", err)
|
||||
|
||||
params := suite.accountKeeper.GetParams(suite.ctx)
|
||||
expectedGas := storetypes.Gas(len(txBytes)) * params.TxSizeCostPerByte
|
||||
@ -146,7 +146,7 @@ func TestConsumeGasForTxSize(t *testing.T) {
|
||||
|
||||
beforeGas = suite.ctx.GasMeter().GasConsumed()
|
||||
suite.ctx, err = antehandler(suite.ctx, tx, false)
|
||||
require.Nil(t, err, "ConsumeTxSizeGasDecorator returned error: %v", err)
|
||||
require.NoError(t, err, "ConsumeTxSizeGasDecorator returned error: %v", err)
|
||||
|
||||
// require that decorator consumes expected amount of gas
|
||||
consumedGas := suite.ctx.GasMeter().GasConsumed() - beforeGas
|
||||
@ -159,7 +159,7 @@ func TestConsumeGasForTxSize(t *testing.T) {
|
||||
tx = txBuilder.GetTx()
|
||||
|
||||
simTxBytes, err := suite.clientCtx.TxConfig.TxJSONEncoder()(tx)
|
||||
require.Nil(t, err, "Cannot marshal tx: %v", err)
|
||||
require.NoError(t, err, "Cannot marshal tx: %v", err)
|
||||
// require that simulated tx is smaller than tx with signatures
|
||||
require.True(t, len(simTxBytes) < len(txBytes), "simulated tx still has signatures")
|
||||
|
||||
@ -173,13 +173,13 @@ func TestConsumeGasForTxSize(t *testing.T) {
|
||||
consumedSimGas := suite.ctx.GasMeter().GasConsumed() - beforeSimGas
|
||||
|
||||
// require that antehandler passes and does not underestimate decorator cost
|
||||
require.Nil(t, err, "ConsumeTxSizeGasDecorator returned error: %v", err)
|
||||
require.NoError(t, err, "ConsumeTxSizeGasDecorator returned error: %v", err)
|
||||
require.True(t, consumedSimGas >= expectedGas, "Simulate mode underestimates gas on AnteDecorator. Simulated cost: %d, expected cost: %d", consumedSimGas, expectedGas)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTxHeightTimeoutDecorator(t *testing.T) {
|
||||
func TestTxTimeoutHeightDecorator(t *testing.T) {
|
||||
suite := SetupTestSuite(t, true)
|
||||
|
||||
antehandler := sdk.ChainAnteDecorators(ante.NewTxTimeoutHeightDecorator())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user