Co-authored-by: Julián Toledano <JulianToledano@users.noreply.github.com>
This commit is contained in:
parent
cb1b2841c1
commit
8fb1a8c7bf
@ -28,7 +28,6 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codecaddress "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/runtime"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/configurator"
|
||||
@ -101,9 +100,8 @@ func (suite *SimTestSuite) TestWeightedOperations() {
|
||||
appParams := make(simtypes.AppParams)
|
||||
|
||||
weightedOps := simulation.WeightedOperations(
|
||||
suite.interfaceRegistry,
|
||||
appParams, suite.cdc, suite.txConfig, suite.accountKeeper,
|
||||
suite.bankKeeper, suite.feegrantKeeper, codecaddress.NewBech32Codec("cosmos"),
|
||||
appParams, suite.txConfig, suite.accountKeeper,
|
||||
suite.bankKeeper, suite.feegrantKeeper,
|
||||
)
|
||||
|
||||
s := rand.NewSource(1)
|
||||
@ -153,7 +151,7 @@ func (suite *SimTestSuite) TestSimulateMsgGrantAllowance() {
|
||||
require.NoError(err)
|
||||
|
||||
// execute operation
|
||||
op := simulation.SimulateMsgGrantAllowance(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.feegrantKeeper)
|
||||
op := simulation.SimulateMsgGrantAllowance(suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.feegrantKeeper)
|
||||
operationMsg, futureOperations, err := op(r, app.BaseApp, ctx.WithHeaderInfo(header.Info{Time: time.Now()}), accounts, "")
|
||||
require.NoError(err)
|
||||
|
||||
@ -197,7 +195,7 @@ func (suite *SimTestSuite) TestSimulateMsgRevokeAllowance() {
|
||||
require.NoError(err)
|
||||
|
||||
// execute operation
|
||||
op := simulation.SimulateMsgRevokeAllowance(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.feegrantKeeper)
|
||||
op := simulation.SimulateMsgRevokeAllowance(suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.feegrantKeeper)
|
||||
operationMsg, futureOperations, err := op(r, app.BaseApp, ctx, accounts, "")
|
||||
require.NoError(err)
|
||||
|
||||
|
||||
@ -31,12 +31,15 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### API Breaking Changes
|
||||
|
||||
* [#21377](https://github.com/cosmos/cosmos-sdk/pull/21377) Simulation API breaking changes:
|
||||
* `SimulateMsgGrantAllowance` and `SimulateMsgRevokeAllowance` no longer require a `ProtoCodec` parameter.
|
||||
* `WeightedOperations` functions no longer require `ProtoCodec`, `JSONCodec`, or `address.Codec` parameters.
|
||||
* [#20529](https://github.com/cosmos/cosmos-sdk/pull/20529) `Accept` on the `FeeAllowanceI` interface now expects the feegrant environment in the `context.Context`.
|
||||
* [#19450](https://github.com/cosmos/cosmos-sdk/pull/19450) Migrate module to use `appmodule.Environment` instead of passing individual services.
|
||||
|
||||
### Consensus Breaking Changes
|
||||
|
||||
* [#19188](https://github.com/cosmos/cosmos-sdk/pull/19188) Remove creation of `BaseAccount` when sending a message to an account that does not exist
|
||||
* [#19188](https://github.com/cosmos/cosmos-sdk/pull/19188) Remove creation of `BaseAccount` when sending a message to an account that does not exist.
|
||||
|
||||
## [v0.1.1](https://github.com/cosmos/cosmos-sdk/releases/tag/x/feegrant/v0.1.1) - 2024-04-22
|
||||
|
||||
|
||||
@ -72,4 +72,4 @@ func (a BasicAllowance) ExpiresAt() (*time.Time, error) {
|
||||
}
|
||||
|
||||
// UpdatePeriodReset BasicAllowance does not update "PeriodReset"
|
||||
func (a BasicAllowance) UpdatePeriodReset(validTime time.Time) error { return nil }
|
||||
func (a BasicAllowance) UpdatePeriodReset(_ time.Time) error { return nil }
|
||||
|
||||
@ -130,8 +130,7 @@ func TestBasicFeeValidAllow(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
for name, stc := range cases {
|
||||
tc := stc // to make scopelint happy
|
||||
for name, tc := range cases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
err := tc.allowance.UpdatePeriodReset(tc.blockTime)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -446,7 +446,7 @@ func (s *CLITestSuite) TestTxWithFeeGrant() {
|
||||
granterAddr, err := s.baseCtx.AddressCodec.BytesToString(granter)
|
||||
s.Require().NoError(err)
|
||||
|
||||
// creating an account manually (This account won't be exist in state)
|
||||
// creating an account manually (This account won't exist in state)
|
||||
k, _, err := s.baseCtx.Keyring.NewMnemonic("grantee", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
|
||||
s.Require().NoError(err)
|
||||
pub, err := k.GetPubKey()
|
||||
|
||||
@ -19,7 +19,7 @@ type FeeAllowanceI interface {
|
||||
// and will be saved again after an acceptance.
|
||||
//
|
||||
// If remove is true (regardless of the error), the FeeAllowance will be deleted from storage
|
||||
// (eg. when it is used up). (See call to RevokeAllowance in Keeper.UseGrantedFees)
|
||||
// (e.g. when it is used up). (See call to RevokeAllowance in Keeper.UseGrantedFees)
|
||||
Accept(ctx context.Context, fee sdk.Coins, msgs []sdk.Msg) (remove bool, err error)
|
||||
|
||||
// ValidateBasic should evaluate this FeeAllowance for internal consistency.
|
||||
|
||||
@ -63,12 +63,13 @@ func (a *AllowedMsgAllowance) GetAllowance() (FeeAllowanceI, error) {
|
||||
|
||||
// SetAllowance sets allowed fee allowance.
|
||||
func (a *AllowedMsgAllowance) SetAllowance(allowance FeeAllowanceI) error {
|
||||
var err error
|
||||
a.Allowance, err = types.NewAnyWithValue(allowance.(proto.Message))
|
||||
newAllowance, err := types.NewAnyWithValue(allowance.(proto.Message))
|
||||
if err != nil {
|
||||
return errorsmod.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", allowance)
|
||||
}
|
||||
|
||||
a.Allowance = newAllowance
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -96,8 +97,8 @@ func (a *AllowedMsgAllowance) Accept(ctx context.Context, fee sdk.Coins, msgs []
|
||||
return remove, err
|
||||
}
|
||||
|
||||
func (a *AllowedMsgAllowance) allowedMsgsToMap(ctx context.Context) (map[string]bool, error) {
|
||||
msgsMap := make(map[string]bool, len(a.AllowedMessages))
|
||||
func (a *AllowedMsgAllowance) allowedMsgsToMap(ctx context.Context) (map[string]struct{}, error) {
|
||||
msgsMap := make(map[string]struct{}, len(a.AllowedMessages))
|
||||
environment, ok := ctx.Value(corecontext.EnvironmentContextKey).(appmodule.Environment)
|
||||
if !ok {
|
||||
return nil, errors.New("environment not set")
|
||||
@ -107,7 +108,7 @@ func (a *AllowedMsgAllowance) allowedMsgsToMap(ctx context.Context) (map[string]
|
||||
if err := gasMeter.Consume(gasCostPerIteration, "check msg"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
msgsMap[msg] = true
|
||||
msgsMap[msg] = struct{}{}
|
||||
}
|
||||
|
||||
return msgsMap, nil
|
||||
@ -127,7 +128,7 @@ func (a *AllowedMsgAllowance) allMsgTypesAllowed(ctx context.Context, msgs []sdk
|
||||
if err := gasMeter.Consume(gasCostPerIteration, "check msg"); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if !msgsMap[sdk.MsgTypeURL(msg)] {
|
||||
if _, allowed := msgsMap[sdk.MsgTypeURL(msg)]; !allowed {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,8 +141,7 @@ func TestFilteredFeeValidAllow(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
for name, stc := range cases {
|
||||
tc := stc // to make scopelint happy
|
||||
for name, tc := range cases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
err := tc.allowance.ValidateBasic()
|
||||
require.NoError(t, err)
|
||||
@ -150,7 +149,7 @@ func TestFilteredFeeValidAllow(t *testing.T) {
|
||||
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: tc.blockTime})
|
||||
|
||||
// create grant
|
||||
var granter, grantee sdk.AccAddress
|
||||
granter, grantee := sdk.AccAddress("granter"), sdk.AccAddress("grantee")
|
||||
allowance, err := feegrant.NewAllowedMsgAllowance(tc.allowance, tc.msgs)
|
||||
require.NoError(t, err)
|
||||
granterStr, err := ac.BytesToString(granter)
|
||||
|
||||
@ -190,7 +190,7 @@ func (k Keeper) revokeAllowance(ctx context.Context, granter, grantee sdk.AccAdd
|
||||
}
|
||||
|
||||
// GetAllowance returns the allowance between the granter and grantee.
|
||||
// If there is none, it returns nil, nil.
|
||||
// If there is none, it returns nil, collections.ErrNotFound.
|
||||
// Returns an error on parsing issues
|
||||
func (k Keeper) GetAllowance(ctx context.Context, granter, grantee sdk.AccAddress) (feegrant.FeeAllowanceI, error) {
|
||||
grant, err := k.FeeAllowance.Get(ctx, collections.Join(grantee, granter))
|
||||
|
||||
@ -167,7 +167,6 @@ func (suite *KeeperTestSuite) TestKeeperCrud() {
|
||||
}
|
||||
|
||||
for name, tc := range cases {
|
||||
tc := tc
|
||||
suite.Run(name, func() {
|
||||
allow, _ := suite.feegrantKeeper.GetAllowance(suite.ctx, tc.granter, tc.grantee)
|
||||
|
||||
@ -261,7 +260,6 @@ func (suite *KeeperTestSuite) TestUseGrantedFee() {
|
||||
}
|
||||
|
||||
for name, tc := range cases {
|
||||
tc := tc
|
||||
suite.Run(name, func() {
|
||||
err := suite.feegrantKeeper.GrantAllowance(suite.ctx, tc.granter, tc.grantee, future)
|
||||
suite.Require().NoError(err)
|
||||
@ -298,9 +296,9 @@ func (suite *KeeperTestSuite) TestUseGrantedFee() {
|
||||
suite.Contains(err.Error(), "fee allowance expired")
|
||||
|
||||
// verify: feegrant is not revoked
|
||||
// Because using the past feegrant will return err, data will be rolled back in actual scenarios.
|
||||
// Only when the feegrant allowance used up in a certain transaction feegrant will revoked success due to err is nil
|
||||
// abci's EndBlocker will remove the expired feegrant.
|
||||
// The expired feegrant is not automatically revoked when attempting to use it.
|
||||
// This is because the transaction using an expired feegrant would fail and be rolled back.
|
||||
// Expired feegrants are typically cleaned up by the ABCI EndBlocker, not by failed usage attempts.
|
||||
_, err = suite.feegrantKeeper.GetAllowance(ctx, suite.addrs[0], suite.addrs[2])
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
@ -344,8 +342,6 @@ func (suite *KeeperTestSuite) TestPruneGrants() {
|
||||
grantee sdk.AccAddress
|
||||
allowance feegrant.FeeAllowanceI
|
||||
expErrMsg string
|
||||
preRun func()
|
||||
postRun func()
|
||||
}{
|
||||
{
|
||||
name: "grant pruned from state after a block: error",
|
||||
@ -412,11 +408,7 @@ func (suite *KeeperTestSuite) TestPruneGrants() {
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
suite.Run(tc.name, func() {
|
||||
if tc.preRun != nil {
|
||||
tc.preRun()
|
||||
}
|
||||
err := suite.feegrantKeeper.GrantAllowance(suite.ctx, tc.granter, tc.grantee, tc.allowance)
|
||||
suite.NoError(err)
|
||||
err = suite.feegrantKeeper.RemoveExpiredAllowances(tc.ctx, 5)
|
||||
@ -430,10 +422,6 @@ func (suite *KeeperTestSuite) TestPruneGrants() {
|
||||
suite.NoError(err)
|
||||
suite.NotNil(grant)
|
||||
}
|
||||
|
||||
if tc.postRun != nil {
|
||||
tc.postRun()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,8 +29,8 @@ func (suite *KeeperTestSuite) TestGrantAllowance() {
|
||||
errMsg string
|
||||
}{
|
||||
{
|
||||
"invalid granter address",
|
||||
func() *feegrant.MsgGrantAllowance {
|
||||
name: "invalid granter address",
|
||||
req: func() *feegrant.MsgGrantAllowance {
|
||||
any, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{})
|
||||
suite.Require().NoError(err)
|
||||
invalid := "invalid-granter"
|
||||
@ -40,12 +40,12 @@ func (suite *KeeperTestSuite) TestGrantAllowance() {
|
||||
Allowance: any,
|
||||
}
|
||||
},
|
||||
true,
|
||||
"decoding bech32 failed",
|
||||
expectErr: true,
|
||||
errMsg: "decoding bech32 failed",
|
||||
},
|
||||
{
|
||||
"invalid grantee address",
|
||||
func() *feegrant.MsgGrantAllowance {
|
||||
name: "invalid grantee address",
|
||||
req: func() *feegrant.MsgGrantAllowance {
|
||||
any, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{})
|
||||
suite.Require().NoError(err)
|
||||
invalid := "invalid-grantee"
|
||||
@ -55,12 +55,12 @@ func (suite *KeeperTestSuite) TestGrantAllowance() {
|
||||
Allowance: any,
|
||||
}
|
||||
},
|
||||
true,
|
||||
"decoding bech32 failed",
|
||||
expectErr: true,
|
||||
errMsg: "decoding bech32 failed",
|
||||
},
|
||||
{
|
||||
"valid: grantee account doesn't exist",
|
||||
func() *feegrant.MsgGrantAllowance {
|
||||
name: "valid: grantee account doesn't exist",
|
||||
req: func() *feegrant.MsgGrantAllowance {
|
||||
grantee := "cosmos139f7kncmglres2nf3h4hc4tade85ekfr8sulz5"
|
||||
granteeAccAddr, err := addressCodec.StringToBytes(grantee)
|
||||
suite.Require().NoError(err)
|
||||
@ -85,12 +85,12 @@ func (suite *KeeperTestSuite) TestGrantAllowance() {
|
||||
Allowance: any,
|
||||
}
|
||||
},
|
||||
false,
|
||||
"",
|
||||
expectErr: false,
|
||||
errMsg: "",
|
||||
},
|
||||
{
|
||||
"invalid: past expiry",
|
||||
func() *feegrant.MsgGrantAllowance {
|
||||
name: "invalid: past expiry",
|
||||
req: func() *feegrant.MsgGrantAllowance {
|
||||
any, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{
|
||||
SpendLimit: suite.atom,
|
||||
Expiration: &yesterday,
|
||||
@ -102,12 +102,12 @@ func (suite *KeeperTestSuite) TestGrantAllowance() {
|
||||
Allowance: any,
|
||||
}
|
||||
},
|
||||
true,
|
||||
"expiration is before current block time",
|
||||
expectErr: true,
|
||||
errMsg: "expiration is before current block time",
|
||||
},
|
||||
{
|
||||
"valid: basic fee allowance",
|
||||
func() *feegrant.MsgGrantAllowance {
|
||||
name: "valid: basic fee allowance",
|
||||
req: func() *feegrant.MsgGrantAllowance {
|
||||
any, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{
|
||||
SpendLimit: suite.atom,
|
||||
Expiration: &oneYear,
|
||||
@ -119,12 +119,12 @@ func (suite *KeeperTestSuite) TestGrantAllowance() {
|
||||
Allowance: any,
|
||||
}
|
||||
},
|
||||
false,
|
||||
"",
|
||||
expectErr: false,
|
||||
errMsg: "",
|
||||
},
|
||||
{
|
||||
"fail: fee allowance exists",
|
||||
func() *feegrant.MsgGrantAllowance {
|
||||
name: "fail: fee allowance exists",
|
||||
req: func() *feegrant.MsgGrantAllowance {
|
||||
any, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{
|
||||
SpendLimit: suite.atom,
|
||||
Expiration: &oneYear,
|
||||
@ -136,12 +136,12 @@ func (suite *KeeperTestSuite) TestGrantAllowance() {
|
||||
Allowance: any,
|
||||
}
|
||||
},
|
||||
true,
|
||||
"fee allowance already exists",
|
||||
expectErr: true,
|
||||
errMsg: "fee allowance already exists",
|
||||
},
|
||||
{
|
||||
"valid: periodic fee allowance",
|
||||
func() *feegrant.MsgGrantAllowance {
|
||||
name: "valid: periodic fee allowance",
|
||||
req: func() *feegrant.MsgGrantAllowance {
|
||||
any, err := codectypes.NewAnyWithValue(&feegrant.PeriodicAllowance{
|
||||
Basic: feegrant.BasicAllowance{
|
||||
SpendLimit: suite.atom,
|
||||
@ -156,12 +156,12 @@ func (suite *KeeperTestSuite) TestGrantAllowance() {
|
||||
Allowance: any,
|
||||
}
|
||||
},
|
||||
false,
|
||||
"",
|
||||
expectErr: false,
|
||||
errMsg: "",
|
||||
},
|
||||
{
|
||||
"valid: with period reset",
|
||||
func() *feegrant.MsgGrantAllowance {
|
||||
name: "valid: with period reset",
|
||||
req: func() *feegrant.MsgGrantAllowance {
|
||||
any, err := codectypes.NewAnyWithValue(&feegrant.PeriodicAllowance{
|
||||
Basic: feegrant.BasicAllowance{
|
||||
SpendLimit: suite.atom,
|
||||
@ -178,12 +178,12 @@ func (suite *KeeperTestSuite) TestGrantAllowance() {
|
||||
Allowance: any,
|
||||
}
|
||||
},
|
||||
false,
|
||||
"",
|
||||
expectErr: false,
|
||||
errMsg: "",
|
||||
},
|
||||
{
|
||||
"error: fee allowance exists",
|
||||
func() *feegrant.MsgGrantAllowance {
|
||||
name: "error: fee allowance exists",
|
||||
req: func() *feegrant.MsgGrantAllowance {
|
||||
any, err := codectypes.NewAnyWithValue(&feegrant.PeriodicAllowance{
|
||||
Basic: feegrant.BasicAllowance{
|
||||
SpendLimit: suite.atom,
|
||||
@ -198,8 +198,8 @@ func (suite *KeeperTestSuite) TestGrantAllowance() {
|
||||
Allowance: any,
|
||||
}
|
||||
},
|
||||
true,
|
||||
"fee allowance already exists",
|
||||
expectErr: true,
|
||||
errMsg: "fee allowance already exists",
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
@ -225,42 +225,42 @@ func (suite *KeeperTestSuite) TestRevokeAllowance() {
|
||||
errMsg string
|
||||
}{
|
||||
{
|
||||
"error: invalid granter",
|
||||
&feegrant.MsgRevokeAllowance{
|
||||
name: "error: invalid granter",
|
||||
request: &feegrant.MsgRevokeAllowance{
|
||||
Granter: invalidGranter,
|
||||
Grantee: suite.encodedAddrs[1],
|
||||
},
|
||||
func() {},
|
||||
true,
|
||||
"decoding bech32 failed",
|
||||
preRun: func() {},
|
||||
expectErr: true,
|
||||
errMsg: "decoding bech32 failed",
|
||||
},
|
||||
{
|
||||
"error: invalid grantee",
|
||||
&feegrant.MsgRevokeAllowance{
|
||||
name: "error: invalid grantee",
|
||||
request: &feegrant.MsgRevokeAllowance{
|
||||
Granter: suite.encodedAddrs[0],
|
||||
Grantee: invalidGrantee,
|
||||
},
|
||||
func() {},
|
||||
true,
|
||||
"decoding bech32 failed",
|
||||
preRun: func() {},
|
||||
expectErr: true,
|
||||
errMsg: "decoding bech32 failed",
|
||||
},
|
||||
{
|
||||
"error: fee allowance not found",
|
||||
&feegrant.MsgRevokeAllowance{
|
||||
name: "error: fee allowance not found",
|
||||
request: &feegrant.MsgRevokeAllowance{
|
||||
Granter: suite.encodedAddrs[0],
|
||||
Grantee: suite.encodedAddrs[1],
|
||||
},
|
||||
func() {},
|
||||
true,
|
||||
"not found",
|
||||
preRun: func() {},
|
||||
expectErr: true,
|
||||
errMsg: "not found",
|
||||
},
|
||||
{
|
||||
"success: revoke fee allowance",
|
||||
&feegrant.MsgRevokeAllowance{
|
||||
name: "success: revoke fee allowance",
|
||||
request: &feegrant.MsgRevokeAllowance{
|
||||
Granter: suite.encodedAddrs[0],
|
||||
Grantee: suite.encodedAddrs[1],
|
||||
},
|
||||
func() {
|
||||
preRun: func() {
|
||||
// removing fee allowance from previous tests if exists
|
||||
_, err := suite.msgSrvr.RevokeAllowance(suite.ctx, &feegrant.MsgRevokeAllowance{
|
||||
Granter: suite.encodedAddrs[0],
|
||||
@ -283,18 +283,18 @@ func (suite *KeeperTestSuite) TestRevokeAllowance() {
|
||||
_, err = suite.msgSrvr.GrantAllowance(suite.ctx, req)
|
||||
suite.Require().NoError(err)
|
||||
},
|
||||
false,
|
||||
"",
|
||||
expectErr: false,
|
||||
errMsg: "",
|
||||
},
|
||||
{
|
||||
"error: check fee allowance revoked",
|
||||
&feegrant.MsgRevokeAllowance{
|
||||
name: "error: check fee allowance revoked",
|
||||
request: &feegrant.MsgRevokeAllowance{
|
||||
Granter: suite.encodedAddrs[0],
|
||||
Grantee: suite.encodedAddrs[1],
|
||||
},
|
||||
func() {},
|
||||
true,
|
||||
"not found",
|
||||
preRun: func() {},
|
||||
expectErr: true,
|
||||
errMsg: "not found",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -19,8 +19,7 @@ func addAllowancesByExpTimeQueue(ctx context.Context, env appmodule.Environment,
|
||||
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
var grant feegrant.Grant
|
||||
bz := iterator.Value()
|
||||
if err := cdc.Unmarshal(bz, &grant); err != nil {
|
||||
if err := cdc.Unmarshal(iterator.Value(), &grant); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -41,8 +40,7 @@ func addAllowancesByExpTimeQueue(ctx context.Context, env appmodule.Environment,
|
||||
prefixStore.Delete(key)
|
||||
} else {
|
||||
grantByExpTimeQueueKey := FeeAllowancePrefixQueue(exp, key)
|
||||
err = store.Set(grantByExpTimeQueueKey, []byte{})
|
||||
if err != nil {
|
||||
if err := store.Set(grantByExpTimeQueueKey, []byte{}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ type mockGasService struct {
|
||||
coregas.Service
|
||||
}
|
||||
|
||||
func (m mockGasService) GasMeter(ctx context.Context) coregas.Meter {
|
||||
func (m mockGasService) GasMeter(_ context.Context) coregas.Meter {
|
||||
return mockGasMeter{}
|
||||
}
|
||||
|
||||
@ -27,6 +27,6 @@ type mockGasMeter struct {
|
||||
coregas.Meter
|
||||
}
|
||||
|
||||
func (m mockGasMeter) Consume(amount coregas.Gas, descriptor string) error {
|
||||
func (m mockGasMeter) Consume(_ coregas.Gas, _ string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -87,13 +87,20 @@ func TestFeegrantPruning(t *testing.T) {
|
||||
feegrant.RegisterQueryServer(queryHelper, feegrantKeeper)
|
||||
queryClient := feegrant.NewQueryClient(queryHelper)
|
||||
|
||||
require.NoError(t, module.EndBlocker(testCtx.Ctx, feegrantKeeper))
|
||||
|
||||
granteeStr, err := ac.BytesToString(grantee)
|
||||
require.NoError(t, err)
|
||||
res, err := queryClient.Allowances(testCtx.Ctx.Context(), &feegrant.QueryAllowancesRequest{
|
||||
queryRequest := &feegrant.QueryAllowancesRequest{
|
||||
Grantee: granteeStr,
|
||||
})
|
||||
}
|
||||
|
||||
res, err := queryClient.Allowances(testCtx.Ctx.Context(), queryRequest)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, res)
|
||||
require.Len(t, res.Allowances, 3)
|
||||
|
||||
require.NoError(t, module.EndBlocker(testCtx.Ctx, feegrantKeeper))
|
||||
|
||||
res, err = queryClient.Allowances(testCtx.Ctx.Context(), queryRequest)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, res)
|
||||
require.Len(t, res.Allowances, 2)
|
||||
@ -101,9 +108,7 @@ func TestFeegrantPruning(t *testing.T) {
|
||||
testCtx.Ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Time: now.AddDate(0, 0, 2)})
|
||||
require.NoError(t, module.EndBlocker(testCtx.Ctx, feegrantKeeper))
|
||||
|
||||
res, err = queryClient.Allowances(testCtx.Ctx.Context(), &feegrant.QueryAllowancesRequest{
|
||||
Grantee: granteeStr,
|
||||
})
|
||||
res, err = queryClient.Allowances(testCtx.Ctx.Context(), queryRequest)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, res)
|
||||
require.Len(t, res.Allowances, 1)
|
||||
|
||||
@ -170,7 +170,7 @@ func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) {
|
||||
// WeightedOperations returns all the feegrant module operations with their respective weights.
|
||||
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
|
||||
return simulation.WeightedOperations(
|
||||
am.registry, simState.AppParams, simState.Cdc, simState.TxConfig,
|
||||
am.accountKeeper, am.bankKeeper, am.keeper, am.accountKeeper.AddressCodec(),
|
||||
simState.AppParams, simState.TxConfig,
|
||||
am.accountKeeper, am.bankKeeper, am.keeper,
|
||||
)
|
||||
}
|
||||
|
||||
@ -3,13 +3,10 @@ package simulation
|
||||
import (
|
||||
"math/rand"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/x/feegrant"
|
||||
"cosmossdk.io/x/feegrant/keeper"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/simulation"
|
||||
@ -29,14 +26,11 @@ var (
|
||||
)
|
||||
|
||||
func WeightedOperations(
|
||||
registry codectypes.InterfaceRegistry,
|
||||
appParams simtypes.AppParams,
|
||||
cdc codec.JSONCodec,
|
||||
txConfig client.TxConfig,
|
||||
ak feegrant.AccountKeeper,
|
||||
bk feegrant.BankKeeper,
|
||||
k keeper.Keeper,
|
||||
ac address.Codec,
|
||||
) simulation.WeightedOperations {
|
||||
var (
|
||||
weightMsgGrantAllowance int
|
||||
@ -55,23 +49,20 @@ func WeightedOperations(
|
||||
},
|
||||
)
|
||||
|
||||
pCdc := codec.NewProtoCodec(registry)
|
||||
|
||||
return simulation.WeightedOperations{
|
||||
simulation.NewWeightedOperation(
|
||||
weightMsgGrantAllowance,
|
||||
SimulateMsgGrantAllowance(pCdc, txConfig, ak, bk, k),
|
||||
SimulateMsgGrantAllowance(txConfig, ak, bk, k),
|
||||
),
|
||||
simulation.NewWeightedOperation(
|
||||
weightMsgRevokeAllowance,
|
||||
SimulateMsgRevokeAllowance(pCdc, txConfig, ak, bk, k),
|
||||
SimulateMsgRevokeAllowance(txConfig, ak, bk, k),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// SimulateMsgGrantAllowance generates MsgGrantAllowance with random values.
|
||||
func SimulateMsgGrantAllowance(
|
||||
cdc *codec.ProtoCodec,
|
||||
txConfig client.TxConfig,
|
||||
ak feegrant.AccountKeeper,
|
||||
bk feegrant.BankKeeper,
|
||||
@ -135,7 +126,6 @@ func SimulateMsgGrantAllowance(
|
||||
|
||||
// SimulateMsgRevokeAllowance generates a MsgRevokeAllowance with random values.
|
||||
func SimulateMsgRevokeAllowance(
|
||||
cdc *codec.ProtoCodec,
|
||||
txConfig client.TxConfig,
|
||||
ak feegrant.AccountKeeper,
|
||||
bk feegrant.BankKeeper,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user