-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow feegrants from marker accounts again. (#2111)
* Write a unit test (that currently fails) that attempts to use a feegrant for a MsgSend. * In the antehandler stuff, if a feegrant is looked for and used, make note of that in the context where we're collecting fees. Then, in the marker send restriction, if coming from a marker, check for that feegrant flag to bypass checking that there's a transfer agent with withdraw permissions. * Unit tests on the new context helpers. * Add some test cases to the SendRestrictionFn tests to hit the scenario where there's a feegrant in use. * Put a better comment on the feegrant bypass. * Fix imports in the send_restrictions. * Delete an unused constant: AddressHasAccessKey = "address_has_access" * Final touches on that updated comment. * Add changelog entry. * Update the flowchart that covers this bug. * Remove the entry from CHANGELOG.md and add a new unreleased entry (the new way).
- Loading branch information
1 parent
247be8e
commit 954a6d6
Showing
9 changed files
with
253 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Allow marker funds to be used via feegrant again [#2110](https://github.com/provenance-io/provenance/issues/2110). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package sdk | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
var ( | ||
feeGranteeKey = "pio-feegrant-in-use" | ||
) | ||
|
||
// WithFeeGrantInUse returns a new context that will indicate that a feegrant is being used. | ||
func WithFeeGrantInUse[C context.Context](ctx C) C { | ||
sdkCtx := sdk.UnwrapSDKContext(ctx) | ||
sdkCtx = sdkCtx.WithValue(feeGranteeKey, true) | ||
return context.Context(sdkCtx).(C) | ||
} | ||
|
||
// WithoutFeeGrantInUse returns a new context that will indicate that a feegrant is NOT being used. | ||
func WithoutFeeGrantInUse[C context.Context](ctx C) C { | ||
sdkCtx := sdk.UnwrapSDKContext(ctx) | ||
sdkCtx = sdkCtx.WithValue(feeGranteeKey, false) | ||
return context.Context(sdkCtx).(C) | ||
} | ||
|
||
// HasFeeGrantInUse checks the context to see if the a feegrant is being used. | ||
func HasFeeGrantInUse[C context.Context](ctx C) bool { | ||
sdkCtx := sdk.UnwrapSDKContext(ctx) | ||
bypassValue := sdkCtx.Value(feeGranteeKey) | ||
if bypassValue == nil { | ||
return false | ||
} | ||
bypass, isBool := bypassValue.(bool) | ||
return isBool && bypass | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package sdk | ||
|
||
import ( | ||
"testing" | ||
|
||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" | ||
"github.com/stretchr/testify/assert" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func TestFeeGrantContextFuncs(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
ctx sdk.Context | ||
exp bool | ||
}{ | ||
{ | ||
name: "brand new mostly empty context", | ||
ctx: sdk.NewContext(nil, cmtproto.Header{}, false, nil), | ||
exp: false, | ||
}, | ||
{ | ||
name: "context with fee grant in use", | ||
ctx: WithFeeGrantInUse(sdk.NewContext(nil, cmtproto.Header{}, false, nil)), | ||
exp: true, | ||
}, | ||
{ | ||
name: "context with fee grant in use on one that originally was without it", | ||
ctx: WithFeeGrantInUse(WithoutFeeGrantInUse(sdk.NewContext(nil, cmtproto.Header{}, false, nil))), | ||
exp: true, | ||
}, | ||
{ | ||
name: "context with fee grant in use twice", | ||
ctx: WithFeeGrantInUse(WithFeeGrantInUse(sdk.NewContext(nil, cmtproto.Header{}, false, nil))), | ||
exp: true, | ||
}, | ||
{ | ||
name: "context without fee grant in use", | ||
ctx: WithoutFeeGrantInUse(sdk.NewContext(nil, cmtproto.Header{}, false, nil)), | ||
exp: false, | ||
}, | ||
{ | ||
name: "context without fee grant in use on one that originally had it", | ||
ctx: WithoutFeeGrantInUse(WithFeeGrantInUse(sdk.NewContext(nil, cmtproto.Header{}, false, nil))), | ||
exp: false, | ||
}, | ||
{ | ||
name: "context without fee grant in use twice", | ||
ctx: WithoutFeeGrantInUse(WithoutFeeGrantInUse(sdk.NewContext(nil, cmtproto.Header{}, false, nil))), | ||
exp: false, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
actual := HasFeeGrantInUse(tc.ctx) | ||
assert.Equal(t, tc.exp, actual, "HasFeeGrantInUse") | ||
}) | ||
} | ||
} | ||
|
||
func TestFeeGrantInUseFuncsDoNotModifyProvided(t *testing.T) { | ||
origCtx := sdk.NewContext(nil, cmtproto.Header{}, false, nil) | ||
assert.False(t, HasFeeGrantInUse(origCtx), "HasFeeGrantInUse(origCtx)") | ||
afterWith := WithFeeGrantInUse(origCtx) | ||
assert.True(t, HasFeeGrantInUse(afterWith), "HasFeeGrantInUse(afterWith)") | ||
assert.False(t, HasFeeGrantInUse(origCtx), "HasFeeGrantInUse(origCtx) after giving it to WithFeeGrantInUse") | ||
afterWithout := WithoutFeeGrantInUse(afterWith) | ||
assert.False(t, HasFeeGrantInUse(afterWithout), "HasFeeGrantInUse(afterWithout)") | ||
assert.True(t, HasFeeGrantInUse(afterWith), "HasFeeGrantInUse(afterWith) after giving it to WithoutFeeGrantInUse") | ||
assert.False(t, HasFeeGrantInUse(origCtx), "HasFeeGrantInUse(origCtx) after giving afterWith to WithoutFeeGrantInUse") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.