diff --git a/app/app.go b/app/app.go index 70051316f8..f91faaf38b 100644 --- a/app/app.go +++ b/app/app.go @@ -1055,25 +1055,24 @@ func New( } app.SetAnteHandler(anteHandler) - // TODO[1760]: fee-handler: Add the msgfeehandler back to the app. - /* - msgFeeHandler, err := piohandlers.NewAdditionalMsgFeeHandler(piohandlers.PioBaseAppKeeperOptions{ - AccountKeeper: app.AccountKeeper, - BankKeeper: app.BankKeeper, - FeegrantKeeper: app.FeeGrantKeeper, - MsgFeesKeeper: app.MsgFeesKeeper, - Decoder: encodingConfig.TxConfig.TxDecoder(), - }) - if err != nil { - panic(err) - } - app.SetFeeHandler(msgFeeHandler) - */ + msgFeeHandler, err := piohandlers.NewAdditionalMsgFeeHandler(piohandlers.PioBaseAppKeeperOptions{ + AccountKeeper: app.AccountKeeper, + BankKeeper: app.BankKeeper, + FeegrantKeeper: app.FeeGrantKeeper, + MsgFeesKeeper: app.MsgFeesKeeper, + Decoder: encodingConfig.TxConfig.TxDecoder(), + }) + + if err != nil { + panic(err) + } + + app.SetFeeHandler(msgFeeHandler) app.SetEndBlocker(app.EndBlocker) - // app.SetAggregateEventsFunc(piohandlers.AggregateEvents) // TODO[1760]: event-history + app.SetAggregateEventsFunc(piohandlers.AggregateEvents) // TODO[1760]: event-history // Add upgrade plans for each release. This must be done before the baseapp seals via LoadLatestVersion() down below. InstallCustomUpgradeHandlers(app) diff --git a/go.mod b/go.mod index 8abf5a1f90..6c62a7ddf7 100644 --- a/go.mod +++ b/go.mod @@ -213,7 +213,7 @@ replace ( // TODO[1760]: wasm: Put this CosmWasm/wasmd replace back with an updated version (or delete it). // github.com/CosmWasm/wasmd => github.com/provenance-io/wasmd v0.30.0-pio-5 // TODO[1760]: sdk: Put this replace back with an updated version of the sdk from our fork. - github.com/cosmos/cosmos-sdk => github.com/provenance-io/cosmos-sdk v0.50.5-nullpointer0x00-msg-router + github.com/cosmos/cosmos-sdk => github.com/provenance-io/cosmos-sdk v0.50.5-nullpointer0x00-msg-based-fee-support // TODO[1760]: ibc: Put this ibc-go replace back with an updated version (or delete it). // github.com/cosmos/ibc-go/v6 => github.com/provenance-io/ibc-go/v6 v6.2.0-pio-1 // dgrijalva/jwt-go is deprecated and doesn't receive security updates. diff --git a/go.sum b/go.sum index 0b93b7b5a7..6822ce461c 100644 --- a/go.sum +++ b/go.sum @@ -905,8 +905,8 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.3.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= -github.com/provenance-io/cosmos-sdk v0.50.5-nullpointer0x00-msg-router h1:DznZMkfRr23Q4CZXR9WBgP8zfn9fQf5xiqK4kaQqZXs= -github.com/provenance-io/cosmos-sdk v0.50.5-nullpointer0x00-msg-router/go.mod h1:UbShFs6P8Ly29xxJvkNGaNaL/UGj5a686NRtb1Cqra0= +github.com/provenance-io/cosmos-sdk v0.50.5-nullpointer0x00-msg-based-fee-support h1:eVD2/kZ4KJN34a+EXZocVmNaROjMVnVE0BAo4rAxRYg= +github.com/provenance-io/cosmos-sdk v0.50.5-nullpointer0x00-msg-based-fee-support/go.mod h1:UbShFs6P8Ly29xxJvkNGaNaL/UGj5a686NRtb1Cqra0= github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ= github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Unghqrcc= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= diff --git a/internal/handlers/msg_fee_handler.go b/internal/handlers/msg_fee_handler.go index 137e5f69ca..d17ac1d139 100644 --- a/internal/handlers/msg_fee_handler.go +++ b/internal/handlers/msg_fee_handler.go @@ -2,6 +2,7 @@ package handlers import ( sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" msgfeestypes "github.com/provenance-io/provenance/x/msgfees/types" @@ -15,8 +16,6 @@ type PioBaseAppKeeperOptions struct { Decoder sdk.TxDecoder } -// TODO[1760]: fee-handler: Uncomment NewAdditionalMsgFeeHandler once the FeeHandler type is back in the SDK. -/* func NewAdditionalMsgFeeHandler(options PioBaseAppKeeperOptions) (sdk.FeeHandler, error) { if options.AccountKeeper == nil { return nil, sdkerrors.ErrLogic.Wrap("account keeper is required for AdditionalMsgFeeHandler builder") @@ -41,4 +40,3 @@ func NewAdditionalMsgFeeHandler(options PioBaseAppKeeperOptions) (sdk.FeeHandler return NewMsgFeeInvoker(options.BankKeeper, options.AccountKeeper, options.FeegrantKeeper, options.MsgFeesKeeper, options.Decoder).Invoke, nil } -*/ diff --git a/internal/handlers/msg_fee_handler_test.go b/internal/handlers/msg_fee_handler_test.go index 034cbd1718..cbd5c8a900 100644 --- a/internal/handlers/msg_fee_handler_test.go +++ b/internal/handlers/msg_fee_handler_test.go @@ -1,7 +1,5 @@ package handlers_test -// TODO[1760]: fee-handler: Uncomment these tests. -/* import ( sdk "github.com/cosmos/cosmos-sdk/types" @@ -69,4 +67,3 @@ func (s *HandlerTestSuite) TestMsgFeeHandlerSetUpIncorrect() { }) s.Require().Error(err) } -*/ diff --git a/internal/handlers/msg_fee_invoker_test.go b/internal/handlers/msg_fee_invoker_test.go index 568f1a031d..928ac9793a 100644 --- a/internal/handlers/msg_fee_invoker_test.go +++ b/internal/handlers/msg_fee_invoker_test.go @@ -22,6 +22,7 @@ import ( simapp "github.com/provenance-io/provenance/app" "github.com/provenance-io/provenance/internal/antewrapper" + piohandlers "github.com/provenance-io/provenance/internal/handlers" "github.com/provenance-io/provenance/internal/pioconfig" msgfeetype "github.com/provenance-io/provenance/x/msgfees/types" ) @@ -47,35 +48,31 @@ func (s *HandlerTestSuite) TestMsgFeeHandlerFeeChargedNoRemainingBaseFee() { feeGasMeter.ConsumeBaseFee(sdk.Coins{sdk.NewInt64Coin("atom", 100_000)}) }, "panicked on adding fees") s.ctx = s.ctx.WithGasMeter(feeGasMeter) - // TODO[1760]: fee-handler: Uncomment all this once the FeeHandler type is back in the SDK. - _ = acct1 - /* - feeChargeFn, err := piohandlers.NewAdditionalMsgFeeHandler(piohandlers.PioBaseAppKeeperOptions{ - AccountKeeper: s.app.AccountKeeper, - BankKeeper: s.app.BankKeeper, - FeegrantKeeper: s.app.FeeGrantKeeper, - MsgFeesKeeper: s.app.MsgFeesKeeper, - Decoder: encodingConfig.TxConfig.TxDecoder(), - }) - s.Require().NoError(err) - coins, _, err := feeChargeFn(s.ctx, false) - - s.Require().ErrorContains(err, "spendable balance 0nhash is smaller than 1000000nhash: insufficient funds", "feeChargeFn 1") - // fee gas meter has nothing to charge, so nothing should have been charged. - s.Require().True(coins.IsZero(), "coins.IsZero() 1") - - s.Require().NoError(testutil.FundAccount(s.ctx, s.app.BankKeeper, acct1.GetAddress(), sdk.NewCoins(sdk.NewInt64Coin(NHash, 900_000))), "fund account") - coins, _, err = feeChargeFn(s.ctx, false) - s.Require().ErrorContains(err, "900000nhash is smaller than 1000000nhash: insufficient funds: insufficient funds", "feeChargeFn 2") - // fee gas meter has nothing to charge, so nothing should have been charged. - s.Require().True(coins.IsZero(), "coins.IsZero() 2") - - s.Require().NoError(testutil.FundAccount(s.ctx, s.app.BankKeeper, acct1.GetAddress(), sdk.NewCoins(sdk.NewInt64Coin(NHash, 100_000))), "fund account again") - coins, _, err = feeChargeFn(s.ctx, false) - s.Require().NoError(err, "feeChargeFn 3") - // fee gas meter has nothing to charge, so nothing should have been charged. - s.Require().True(coins.IsAllGTE(sdk.Coins{sdk.NewInt64Coin(NHash, 1_000_000)}), "coins all gt 1000000nhash") - */ + feeChargeFn, err := piohandlers.NewAdditionalMsgFeeHandler(piohandlers.PioBaseAppKeeperOptions{ + AccountKeeper: s.app.AccountKeeper, + BankKeeper: s.app.BankKeeper, + FeegrantKeeper: s.app.FeeGrantKeeper, + MsgFeesKeeper: s.app.MsgFeesKeeper, + Decoder: encodingConfig.TxConfig.TxDecoder(), + }) + s.Require().NoError(err) + coins, _, err := feeChargeFn(s.ctx, false) + + s.Require().ErrorContains(err, "spendable balance 0nhash is smaller than 1000000nhash: insufficient funds", "feeChargeFn 1") + // fee gas meter has nothing to charge, so nothing should have been charged. + s.Require().True(coins.IsZero(), "coins.IsZero() 1") + + s.Require().NoError(testutil.FundAccount(s.ctx, s.app.BankKeeper, acct1.GetAddress(), sdk.NewCoins(sdk.NewInt64Coin(NHash, 900_000))), "fund account") + coins, _, err = feeChargeFn(s.ctx, false) + s.Require().ErrorContains(err, "900000nhash is smaller than 1000000nhash: insufficient funds: insufficient funds", "feeChargeFn 2") + // fee gas meter has nothing to charge, so nothing should have been charged. + s.Require().True(coins.IsZero(), "coins.IsZero() 2") + + s.Require().NoError(testutil.FundAccount(s.ctx, s.app.BankKeeper, acct1.GetAddress(), sdk.NewCoins(sdk.NewInt64Coin(NHash, 100_000))), "fund account again") + coins, _, err = feeChargeFn(s.ctx, false) + s.Require().NoError(err, "feeChargeFn 3") + // fee gas meter has nothing to charge, so nothing should have been charged. + s.Require().True(coins.IsAllGTE(sdk.Coins{sdk.NewInt64Coin(NHash, 1_000_000)}), "coins all gt 1000000nhash") } func (s *HandlerTestSuite) TestMsgFeeHandlerFeeChargedWithRemainingBaseFee() { @@ -96,32 +93,30 @@ func (s *HandlerTestSuite) TestMsgFeeHandlerFeeChargedWithRemainingBaseFee() { feeGasMeter.ConsumeBaseFee(sdk.Coins{sdk.NewInt64Coin("atom", 100_000)}) // fee consumed at ante handler }, "panicked on adding fees") s.ctx = s.ctx.WithGasMeter(feeGasMeter) - // TODO[1760]: fee-handler: Uncomment all this once the FeeHandler type is back in the SDK. - _ = acct1 - /* - feeChargeFn, err := piohandlers.NewAdditionalMsgFeeHandler(piohandlers.PioBaseAppKeeperOptions{ - AccountKeeper: s.app.AccountKeeper, - BankKeeper: s.app.BankKeeper, - FeegrantKeeper: s.app.FeeGrantKeeper, - MsgFeesKeeper: s.app.MsgFeesKeeper, - Decoder: encodingConfig.TxConfig.TxDecoder(), - }) - s.Require().NoError(err, "NewAdditionalMsgFeeHandler") - - s.Require().NoError(testutil.FundAccount(s.ctx, s.app.BankKeeper, acct1.GetAddress(), sdk.NewCoins(sdk.NewInt64Coin(NHash, 1_000_000))), "funding account") - coins, _, err := feeChargeFn(s.ctx, false) - s.Require().ErrorContains(err, "spendable balance 0atom is smaller than 20000atom: insufficient funds", "feeChargeFn 1") - // fee gas meter has nothing to charge, so nothing should have been charged. - s.Require().True(coins.IsZero(), "coins.IsZero() 1") - - s.Require().NoError(testutil.FundAccount(s.ctx, s.app.BankKeeper, acct1.GetAddress(), sdk.NewCoins(sdk.NewInt64Coin("atom", 20000), sdk.NewInt64Coin(NHash, 1000000))), "funding account again") - coins, _, err = feeChargeFn(s.ctx, false) - s.Require().Nil(err, "Got error when should have successfully paid all msg fees and swept remaining base fees") - s.Require().True(coins.Equal(sdk.Coins{sdk.NewInt64Coin(NHash, 1000000), sdk.NewInt64Coin("atom", 20000)})) - s.Require().NoError(err, "feeChargeFn 2") - expected := sdk.Coins{sdk.NewInt64Coin("atom", 20000), sdk.NewInt64Coin(NHash, 1000000)} - s.Require().Equal(expected, coins, "final coins") - */ + + feeChargeFn, err := piohandlers.NewAdditionalMsgFeeHandler(piohandlers.PioBaseAppKeeperOptions{ + AccountKeeper: s.app.AccountKeeper, + BankKeeper: s.app.BankKeeper, + FeegrantKeeper: s.app.FeeGrantKeeper, + MsgFeesKeeper: s.app.MsgFeesKeeper, + Decoder: encodingConfig.TxConfig.TxDecoder(), + }) + s.Require().NoError(err, "NewAdditionalMsgFeeHandler") + + s.Require().NoError(testutil.FundAccount(s.ctx, s.app.BankKeeper, acct1.GetAddress(), sdk.NewCoins(sdk.NewInt64Coin(NHash, 1_000_000))), "funding account") + coins, _, err := feeChargeFn(s.ctx, false) + s.Require().ErrorContains(err, "spendable balance 0atom is smaller than 20000atom: insufficient funds", "feeChargeFn 1") + // fee gas meter has nothing to charge, so nothing should have been charged. + s.Require().True(coins.IsZero(), "coins.IsZero() 1") + + s.Require().NoError(testutil.FundAccount(s.ctx, s.app.BankKeeper, acct1.GetAddress(), sdk.NewCoins(sdk.NewInt64Coin("atom", 20000), sdk.NewInt64Coin(NHash, 1000000))), "funding account again") + coins, _, err = feeChargeFn(s.ctx, false) + s.Require().Nil(err, "Got error when should have successfully paid all msg fees and swept remaining base fees") + s.Require().True(coins.Equal(sdk.Coins{sdk.NewInt64Coin(NHash, 1000000), sdk.NewInt64Coin("atom", 20000)})) + s.Require().NoError(err, "feeChargeFn 2") + expected := sdk.Coins{sdk.NewInt64Coin("atom", 20000), sdk.NewInt64Coin(NHash, 1000000)} + s.Require().Equal(expected, coins, "final coins") + } func (s *HandlerTestSuite) TestMsgFeeHandlerFeeChargedFeeGranter() { @@ -142,21 +137,20 @@ func (s *HandlerTestSuite) TestMsgFeeHandlerFeeChargedFeeGranter() { feeGasMeter.ConsumeBaseFee(sdk.Coins{sdk.NewInt64Coin("atom", 100_000)}) }, "panicked on adding fees") s.ctx = s.ctx.WithGasMeter(feeGasMeter) - // TODO[1760]: fee-handler: Uncomment all this once the FeeHandler type is back in the SDK. - /* - feeChargeFn, err := piohandlers.NewAdditionalMsgFeeHandler(piohandlers.PioBaseAppKeeperOptions{ - AccountKeeper: s.app.AccountKeeper, - BankKeeper: s.app.BankKeeper, - FeegrantKeeper: s.app.FeeGrantKeeper, - MsgFeesKeeper: s.app.MsgFeesKeeper, - Decoder: encodingConfig.TxConfig.TxDecoder(), - }) - - coins, _, err := feeChargeFn(s.ctx, false) - s.Require().Nil(err, "Got error when should not have.") - // fee gas meter has nothing to charge, so nothing should have been charged. - s.Require().True(coins.IsAllGTE(sdk.Coins{sdk.NewInt64Coin(NHash, 1000000)})) - */ + + feeChargeFn, err := piohandlers.NewAdditionalMsgFeeHandler(piohandlers.PioBaseAppKeeperOptions{ + AccountKeeper: s.app.AccountKeeper, + BankKeeper: s.app.BankKeeper, + FeegrantKeeper: s.app.FeeGrantKeeper, + MsgFeesKeeper: s.app.MsgFeesKeeper, + Decoder: encodingConfig.TxConfig.TxDecoder(), + }) + + coins, _, err := feeChargeFn(s.ctx, false) + s.Require().Nil(err, "Got error when should not have.") + // fee gas meter has nothing to charge, so nothing should have been charged. + s.Require().True(coins.IsAllGTE(sdk.Coins{sdk.NewInt64Coin(NHash, 1000000)})) + } func (s *HandlerTestSuite) TestMsgFeeHandlerBadDecoder() { @@ -172,18 +166,17 @@ func (s *HandlerTestSuite) TestMsgFeeHandlerBadDecoder() { s.ctx = s.ctx.WithTxBytes(bz) feeGasMeter := antewrapper.NewFeeGasMeterWrapper(log.NewTestLogger(s.T()), storetypes.NewGasMeter(100), false).(*antewrapper.FeeGasMeter) s.ctx = s.ctx.WithGasMeter(feeGasMeter) - // TODO[1760]: fee-handler: Uncomment all this once the FeeHandler type is back in the SDK. - /* - feeChargeFn, err := piohandlers.NewAdditionalMsgFeeHandler(piohandlers.PioBaseAppKeeperOptions{ - AccountKeeper: s.app.AccountKeeper, - BankKeeper: s.app.BankKeeper, - FeegrantKeeper: s.app.FeeGrantKeeper, - MsgFeesKeeper: s.app.MsgFeesKeeper, - Decoder: moduletestutil.MakeTestEncodingConfig().TxConfig.TxDecoder(), - }) - s.Require().NoError(err) - s.Require().Panics(func() { feeChargeFn(s.ctx, false) }, "Bad decoder while setting up app.") - */ + + feeChargeFn, err := piohandlers.NewAdditionalMsgFeeHandler(piohandlers.PioBaseAppKeeperOptions{ + AccountKeeper: s.app.AccountKeeper, + BankKeeper: s.app.BankKeeper, + FeegrantKeeper: s.app.FeeGrantKeeper, + MsgFeesKeeper: s.app.MsgFeesKeeper, + Decoder: moduletestutil.MakeTestEncodingConfig().TxConfig.TxDecoder(), + }) + s.Require().NoError(err) + s.Require().Panics(func() { feeChargeFn(s.ctx, false) }, "Bad decoder while setting up app.") + } func setUpApp(s *HandlerTestSuite, additionalFeeCoinDenom string, additionalFeeCoinAmt int64) (moduletestutil.TestEncodingConfig, error) {