-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
check: fee distribution on failed tx #149
Draft
aljo242
wants to merge
9
commits into
main
Choose a base branch
from
check/fee-distribution
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a74335d
added tests for stuck escrow fee
freeelancer 9b9134e
fix to distribute stuck escrowed fees
freeelancer 6fbf825
try to revert
c06077b
repro
d71f3de
mock and format
3676549
remove
901431f
actually test
083bd5d
ok
5609bd6
gosimple
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,122 @@ | ||
package post_test | ||
|
||
import ( | ||
"fmt" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"testing" | ||
|
||
"cosmossdk.io/math" | ||
"github.com/cosmos/cosmos-sdk/testutil/testdata" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/mock" | ||
|
||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
antesuite "github.com/skip-mev/feemarket/x/feemarket/ante/suite" | ||
"github.com/skip-mev/feemarket/x/feemarket/post" | ||
"github.com/skip-mev/feemarket/x/feemarket/types" | ||
) | ||
|
||
func TestPostHandleDistributeFeesMock(t *testing.T) { | ||
// Same data for every test case | ||
const ( | ||
baseDenom = "stake" | ||
resolvableDenom = "atom" | ||
expectedConsumedGas = 11730 | ||
expectedConsumedSimGas = expectedConsumedGas + post.BankSendGasConsumption | ||
gasLimit = expectedConsumedSimGas | ||
) | ||
|
||
validFeeAmount := types.DefaultMinBaseGasPrice.MulInt64(int64(gasLimit)) | ||
validFeeAmountWithTip := validFeeAmount.Add(math.LegacyNewDec(100)) | ||
validFeeWithTip := sdk.NewCoins(sdk.NewCoin(baseDenom, validFeeAmountWithTip.TruncateInt())) | ||
|
||
testCases := []antesuite.TestCase{ | ||
{ | ||
Name: "signer has enough funds, should pass with tip", | ||
Malleate: func(s *antesuite.TestSuite) antesuite.TestCaseArgs { | ||
accs := s.CreateTestAccounts(1) | ||
s.MockBankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].Account.GetAddress(), | ||
types.FeeCollectorName, mock.Anything).Return(nil).Once() | ||
s.MockBankKeeper.On("SendCoinsFromModuleToModule", mock.Anything, types.FeeCollectorName, authtypes.FeeCollectorName, mock.Anything).Return(nil).Once() | ||
s.MockBankKeeper.On("SendCoinsFromModuleToAccount", mock.Anything, types.FeeCollectorName, mock.Anything, mock.Anything).Return(nil).Once() | ||
return antesuite.TestCaseArgs{ | ||
Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())}, | ||
GasLimit: gasLimit, | ||
FeeAmount: validFeeWithTip, | ||
} | ||
}, | ||
RunAnte: true, | ||
RunPost: true, | ||
Simulate: false, | ||
ExpPass: true, | ||
ExpErr: nil, | ||
ExpectConsumedGas: expectedConsumedGas, | ||
Mock: true, | ||
DistributeFees: true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(fmt.Sprintf("Case %s", tc.Name), func(t *testing.T) { | ||
s := antesuite.SetupTestSuite(t, tc.Mock, true) | ||
s.TxBuilder = s.ClientCtx.TxConfig.NewTxBuilder() | ||
args := tc.Malleate(s) | ||
|
||
s.RunTestCase(t, tc, args) | ||
}) | ||
} | ||
} | ||
|
||
func TestPostHandleDistributeFees(t *testing.T) { | ||
// Same data for every test case | ||
const ( | ||
baseDenom = "stake" | ||
resolvableDenom = "atom" | ||
expectedConsumedGas = 65558 | ||
|
||
gasLimit = 100000 | ||
) | ||
|
||
validFeeAmount := types.DefaultMinBaseGasPrice.MulInt64(int64(gasLimit)) | ||
validFeeAmountWithTip := validFeeAmount.Add(math.LegacyNewDec(100)) | ||
validFeeWithTip := sdk.NewCoins(sdk.NewCoin(baseDenom, validFeeAmountWithTip.TruncateInt())) | ||
|
||
testCases := []antesuite.TestCase{ | ||
{ | ||
Name: "signer has enough funds, gaslimit is not enough to complete entire transaction, should pass", | ||
Malleate: func(s *antesuite.TestSuite) antesuite.TestCaseArgs { | ||
accs := s.CreateTestAccounts(1) | ||
|
||
balance := antesuite.TestAccountBalance{ | ||
TestAccount: accs[0], | ||
Coins: validFeeWithTip, | ||
} | ||
s.SetAccountBalances([]antesuite.TestAccountBalance{balance}) | ||
|
||
return antesuite.TestCaseArgs{ | ||
Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())}, | ||
GasLimit: 35188, | ||
FeeAmount: validFeeWithTip, | ||
} | ||
}, | ||
RunAnte: true, | ||
RunPost: true, | ||
Simulate: false, | ||
ExpPass: false, | ||
ExpErr: sdkerrors.ErrOutOfGas, | ||
ExpectConsumedGas: 65558, | ||
Mock: false, | ||
DistributeFees: true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(fmt.Sprintf("Case %s", tc.Name), func(t *testing.T) { | ||
s := antesuite.SetupTestSuite(t, tc.Mock, true) | ||
s.TxBuilder = s.ClientCtx.TxConfig.NewTxBuilder() | ||
args := tc.Malleate(s) | ||
|
||
s.RunTestCase(t, tc, args) | ||
}) | ||
} | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should always run the post handler in these tests even if there is an ante handler error. https://docs.cosmos.network/v0.50/learn/advanced/baseapp#runmsgs