## Description We decided to remove middlewares, and revert to antehandlers (exactly like in v045) for this release. A better middleware solution will be implemented after v046. ref: https://github.com/cosmos/cosmos-sdk/issues/11955 This PR is part 2 of 2: - part 1: Revert baseapp and middlewares to v0.45.4 - part 2: Add posthandler, tips, priority Depends on: - [x] #11979 --- Suggestion for reviewers: - Apart from correctness, I would also like someone to review **exhaustiveness**. I.e. all changes we made in v046 into the [middleware folder](https://github.com/cosmos/cosmos-sdk/tree/v0.46.0-beta2/x/auth/middleware) are reflected in this PR, and that I didn't forget anything. I found the following ones: - add a TxFeeChecker in DeductFee - add a ExtensionChecker in ExtCheckerDecorator - add a TipDecorator --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package ante_test
|
|
|
|
import (
|
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/x/auth/ante"
|
|
"github.com/cosmos/cosmos-sdk/x/auth/tx"
|
|
)
|
|
|
|
func (suite *AnteTestSuite) TestRejectExtensionOptionsDecorator() {
|
|
suite.SetupTest(true) // setup
|
|
|
|
testCases := []struct {
|
|
msg string
|
|
allow bool
|
|
}{
|
|
{"allow extension", true},
|
|
{"reject extension", false},
|
|
}
|
|
for _, tc := range testCases {
|
|
suite.Run(tc.msg, func() {
|
|
txBuilder := suite.clientCtx.TxConfig.NewTxBuilder()
|
|
|
|
reod := ante.NewExtensionOptionsDecorator(func(_ *codectypes.Any) bool {
|
|
return tc.allow
|
|
})
|
|
antehandler := sdk.ChainAnteDecorators(reod)
|
|
|
|
// no extension options should not trigger an error
|
|
theTx := txBuilder.GetTx()
|
|
_, err := antehandler(suite.ctx, theTx, false)
|
|
suite.Require().NoError(err)
|
|
|
|
extOptsTxBldr, ok := txBuilder.(tx.ExtensionOptionsTxBuilder)
|
|
if !ok {
|
|
// if we can't set extension options, this decorator doesn't apply and we're done
|
|
return
|
|
}
|
|
|
|
// set an extension option and check
|
|
any, err := codectypes.NewAnyWithValue(testdata.NewTestMsg())
|
|
suite.Require().NoError(err)
|
|
extOptsTxBldr.SetExtensionOptions(any)
|
|
theTx = txBuilder.GetTx()
|
|
_, err = antehandler(suite.ctx, theTx, false)
|
|
if tc.allow {
|
|
suite.Require().NoError(err)
|
|
} else {
|
|
suite.Require().EqualError(err, "unknown extension options")
|
|
}
|
|
})
|
|
}
|
|
}
|