* WIP: middleware refactor * refactor `tx.Request` * Add MsgResponses any in sdk.Result * add helper functions in abci * refactor tips * review changes * Fix mock tests * Update baseapp/abci.go * Update baseapp/abci.go * Update types/tx/middleware.go * Update types/tx/middleware.go * tx.Response to abci conversion * refactor makeABCIData * Add comments * Fix build * fix build error * fix tests * fix test * fix tests * Fix TestSimulateTx * fix tests * fix test * Fix build * Simplify code * fix test build * Use repeated bytes in txMsgData * Fix grpc-gateway test * Make proto-gen * Automagically register MsgResponse * review changes * Use froydi's trick * Use Any in TxMsgData * Finally remove API breaking change * Revert unnecessary stuff * refactor: Move TxDecoder into its own middleware * Add test for txDecoderMiddleware * Fix some baseapp tests * Fix some more tests * Fix mock tests * Fix middleware tests * Add cl * Fix tests * Update types/tx/middleware.go Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com> Co-authored-by: atheesh <atheesh@vitwit.com> Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com>
37 lines
1.3 KiB
Go
37 lines
1.3 KiB
Go
package middleware_test
|
|
|
|
import (
|
|
"github.com/cosmos/cosmos-sdk/codec/types"
|
|
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
typestx "github.com/cosmos/cosmos-sdk/types/tx"
|
|
"github.com/cosmos/cosmos-sdk/x/auth/middleware"
|
|
"github.com/cosmos/cosmos-sdk/x/auth/tx"
|
|
)
|
|
|
|
func (s *MWTestSuite) TestRejectExtensionOptionsMiddleware() {
|
|
ctx := s.SetupTest(true) // setup
|
|
txBuilder := s.clientCtx.TxConfig.NewTxBuilder()
|
|
|
|
txHandler := middleware.ComposeMiddlewares(noopTxHandler, middleware.RejectExtensionOptionsMiddleware)
|
|
|
|
// no extension options should not trigger an error
|
|
theTx := txBuilder.GetTx()
|
|
_, _, err := txHandler.CheckTx(sdk.WrapSDKContext(ctx), typestx.Request{Tx: theTx}, typestx.RequestCheckTx{})
|
|
s.Require().NoError(err)
|
|
|
|
extOptsTxBldr, ok := txBuilder.(tx.ExtensionOptionsTxBuilder)
|
|
if !ok {
|
|
// if we can't set extension options, this middleware doesn't apply and we're done
|
|
return
|
|
}
|
|
|
|
// setting any extension option should cause an error
|
|
any, err := types.NewAnyWithValue(testdata.NewTestMsg())
|
|
s.Require().NoError(err)
|
|
extOptsTxBldr.SetExtensionOptions(any)
|
|
theTx = txBuilder.GetTx()
|
|
_, _, err = txHandler.CheckTx(sdk.WrapSDKContext(ctx), typestx.Request{Tx: theTx}, typestx.RequestCheckTx{})
|
|
s.Require().EqualError(err, "unknown extension options")
|
|
}
|