diff --git a/x/auth/middleware/basic_test.go b/x/auth/middleware/basic_test.go index 1c44e292eb93..7bc583ed8d75 100644 --- a/x/auth/middleware/basic_test.go +++ b/x/auth/middleware/basic_test.go @@ -33,22 +33,37 @@ func (s *MWTestSuite) TestValidateBasic() { invalidTx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) s.Require().NoError(err) + // DeliverTx _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: invalidTx}) s.Require().NotNil(err, "Did not error on invalid tx") + // SimulateTx + _, err = txHandler.SimulateTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: invalidTx}) + s.Require().NotNil(err, "Did not error on invalid tx") + privs, accNums, accSeqs = []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0} validTx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) s.Require().NoError(err) + // DeliverTx _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: validTx}) s.Require().Nil(err, "ValidateBasicMiddleware returned error on valid tx. err: %v", err) + // SimulateTx + _, err = txHandler.SimulateTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: validTx}) + s.Require().Nil(err, "ValidateBasicMiddleware returned error on valid tx. err: %v", err) + // test middleware skips on recheck ctx = ctx.WithIsReCheckTx(true) // middleware should skip processing invalidTx on recheck and thus return nil-error + // DeliverTx _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: invalidTx}) s.Require().Nil(err, "ValidateBasicMiddleware ran on ReCheck") + + // SimulateTx + _, err = txHandler.SimulateTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: invalidTx}) + s.Require().Nil(err, "ValidateBasicMiddleware ran on ReCheck") } func (s *MWTestSuite) TestValidateMemo() { @@ -73,8 +88,12 @@ func (s *MWTestSuite) TestValidateMemo() { s.Require().NoError(err) // require that long memos get rejected + // DeliverTx _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: invalidTx}) + s.Require().NotNil(err, "Did not error on tx with high memo") + // SimulateTx + _, err = txHandler.SimulateTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: invalidTx}) s.Require().NotNil(err, "Did not error on tx with high memo") txBuilder.SetMemo(strings.Repeat("01234567890", 10)) @@ -82,8 +101,13 @@ func (s *MWTestSuite) TestValidateMemo() { s.Require().NoError(err) // require small memos pass ValidateMemo middleware + // DeliverTx _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: validTx}) s.Require().Nil(err, "ValidateBasicMiddleware returned error on valid tx. err: %v", err) + + // SimulateTx + _, err = txHandler.SimulateTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: validTx}) + s.Require().Nil(err, "ValidateBasicMiddleware returned error on valid tx. err: %v", err) } func (s *MWTestSuite) TestConsumeGasForTxSize() { @@ -214,8 +238,15 @@ func (s *MWTestSuite) TestTxHeightTimeoutMiddleware() { s.Require().NoError(err) ctx := ctx.WithBlockHeight(tc.height) + + // DeliverTx + _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}) + s.Require().Equal(tc.expectErr, err != nil, err) + + // SimulateTx _, err = txHandler.SimulateTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}) s.Require().Equal(tc.expectErr, err != nil, err) + }) } } diff --git a/x/auth/middleware/fee_test.go b/x/auth/middleware/fee_test.go index 7c1f54463fff..9899e2aa63c3 100644 --- a/x/auth/middleware/fee_test.go +++ b/x/auth/middleware/fee_test.go @@ -100,15 +100,27 @@ func (s *MWTestSuite) TestDeductFees() { err = testutil.FundAccount(s.app.BankKeeper, ctx, addr1, coins) s.Require().NoError(err) + // DeliverTx _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}) - s.Require().NotNil(err, "Tx did not error when fee payer had insufficient funds") + s.Require().NotNil(err, "Tx errored when fee payer had insufficient funds") + + // SimulateTx + _, err = txHandler.SimulateTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}) + s.Require().NotNil(err, "Tx errored when fee payer had insufficient funds") // Set account with sufficient funds s.app.AccountKeeper.SetAccount(ctx, acc) err = testutil.FundAccount(s.app.BankKeeper, ctx, addr1, sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(200)))) s.Require().NoError(err) + // DeliverTx _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}) + s.Require().Nil(err, "Tx did not error after account has been set with sufficient funds") + + err = testutil.FundAccount(s.app.BankKeeper, ctx, addr1, sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(200)))) + s.Require().NoError(err) - s.Require().Nil(err, "Tx errored after account has been set with sufficient funds") + // SimulateTx + _, err = txHandler.SimulateTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}) + s.Require().Nil(err, "Tx did not error after account has been set with sufficient funds") } diff --git a/x/auth/middleware/gas_test.go b/x/auth/middleware/gas_test.go index 78685fa6c766..480077762149 100644 --- a/x/auth/middleware/gas_test.go +++ b/x/auth/middleware/gas_test.go @@ -65,10 +65,13 @@ func (s *MWTestSuite) TestSetup() { for _, tc := range testcases { s.Run(tc.name, func() { res, _, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: tc.tx}, tx.RequestCheckTx{}) + _, simErr := txHandler.SimulateTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: tc.tx}) if tc.expErr { s.Require().EqualError(err, tc.errorStr) + s.Require().EqualError(simErr, tc.errorStr) } else { s.Require().Nil(err, "SetUpContextMiddleware returned error") + s.Require().Nil(simErr, "SetUpContextMiddleware returned error") s.Require().Equal(tc.expGasLimit, uint64(res.GasWanted)) } }) diff --git a/x/auth/middleware/run_msgs_test.go b/x/auth/middleware/run_msgs_test.go index 6278d5c023d2..143a21975380 100644 --- a/x/auth/middleware/run_msgs_test.go +++ b/x/auth/middleware/run_msgs_test.go @@ -28,8 +28,13 @@ func (s *MWTestSuite) TestRunMsgs() { txBytes, err := s.clientCtx.TxConfig.TxEncoder()(testTx) s.Require().NoError(err) + // DeliverTx res, err := txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx, TxBytes: txBytes}) s.Require().NoError(err) s.Require().Len(res.MsgResponses, 1) s.Require().Equal(fmt.Sprintf("/%s", proto.MessageName(&testdata.MsgCreateDogResponse{})), res.MsgResponses[0].TypeUrl) + + // SimulateTx + _, err = txHandler.SimulateTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx, TxBytes: txBytes}) + s.Require().NoError(err) } diff --git a/x/auth/middleware/sigverify_test.go b/x/auth/middleware/sigverify_test.go index a0c68062a968..fd4fc5622041 100644 --- a/x/auth/middleware/sigverify_test.go +++ b/x/auth/middleware/sigverify_test.go @@ -55,6 +55,7 @@ func (s *MWTestSuite) TestSetPubKey() { testTx, _, err := s.createTestTx(txBuilder, privs, accNums, accSeqs, ctx.ChainID()) require.NoError(err) + // DeliverTx _, err = txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}) require.NoError(err) @@ -65,6 +66,10 @@ func (s *MWTestSuite) TestSetPubKey() { require.True(pubs[i].Equals(pk), "Wrong Pubkey retrieved from AccountKeeper, idx=%d\nexpected=%s\n got=%s", i, pubs[i], pk) } + + // SimulateTx + _, err = txHandler.SimulateTx(sdk.WrapSDKContext(ctx), tx.Request{Tx: testTx}) + require.NoError(err) } func (s *MWTestSuite) TestConsumeSignatureVerificationGas() { diff --git a/x/auth/middleware/tx_test.go b/x/auth/middleware/tx_test.go index 8624aadbfea2..9e4ce65ed648 100644 --- a/x/auth/middleware/tx_test.go +++ b/x/auth/middleware/tx_test.go @@ -46,11 +46,18 @@ func (s *MWTestSuite) TestTxDecoderMiddleware() { txReqChecker, middleware.NewTxDecoderMiddleware(s.clientCtx.TxConfig.TxDecoder()), ) + + // DeliverTx _, err := txHandler.DeliverTx(sdk.WrapSDKContext(ctx), tc.req) + + // SimulateTx + _, simErr := txHandler.SimulateTx(sdk.WrapSDKContext(ctx), tc.req) if tc.expErr { require.Error(err) + require.Error(simErr) } else { require.NoError(err) + require.NoError(simErr) } }) }