-
Notifications
You must be signed in to change notification settings - Fork 591
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
[Incentives Module][bugfix] Scale gas costs by denoms in gauge #4830
Changes from 4 commits
46fda09
d52a66a
b582f2d
3d33969
8138436
97837cb
bd93b46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -332,3 +332,98 @@ func (suite *KeeperTestSuite) TestChargeFeeIfSufficientFeeDenomBalance() { | |
}) | ||
} | ||
} | ||
|
||
func (suite *KeeperTestSuite) TestAddToGaugeRewards() { | ||
testCases := []struct { | ||
name string | ||
owner sdk.AccAddress | ||
coinsToAdd sdk.Coins | ||
gaugeId uint64 | ||
minimumGasConsumed uint64 | ||
|
||
expectErr bool | ||
}{ | ||
{ | ||
name: "valid case: valid gauge", | ||
owner: suite.TestAccs[0], | ||
coinsToAdd: sdk.NewCoins( | ||
sdk.NewCoin("uosmo", sdk.NewInt(100000)), | ||
sdk.NewCoin("atom", sdk.NewInt(99999)), | ||
), | ||
gaugeId: 1, | ||
minimumGasConsumed: uint64(2 * types.BaseGasFeeForAddRewardToGauge), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the base gas cost for txns like these are usually in the 10k-20k gas range, we should add a test case with many denoms (>4) to ensure that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good added! for 8 tokens it looks like this;
|
||
|
||
expectErr: false, | ||
}, | ||
{ | ||
name: "valid case: valid gauge with >4 denoms", | ||
owner: suite.TestAccs[0], | ||
coinsToAdd: sdk.NewCoins( | ||
sdk.NewCoin("uosmo", sdk.NewInt(100000)), | ||
sdk.NewCoin("atom", sdk.NewInt(99999)), | ||
sdk.NewCoin("mars", sdk.NewInt(88888)), | ||
sdk.NewCoin("akash", sdk.NewInt(77777)), | ||
sdk.NewCoin("eth", sdk.NewInt(6666)), | ||
sdk.NewCoin("usdc", sdk.NewInt(555)), | ||
sdk.NewCoin("dai", sdk.NewInt(4444)), | ||
sdk.NewCoin("ust", sdk.NewInt(3333)), | ||
), | ||
gaugeId: 1, | ||
minimumGasConsumed: uint64(8 * types.BaseGasFeeForAddRewardToGauge), | ||
|
||
expectErr: false, | ||
}, | ||
{ | ||
name: "invalid case: gauge Id is not valid", | ||
owner: suite.TestAccs[0], | ||
coinsToAdd: sdk.NewCoins( | ||
sdk.NewCoin("uosmo", sdk.NewInt(100000)), | ||
sdk.NewCoin("atom", sdk.NewInt(99999)), | ||
), | ||
gaugeId: 0, | ||
minimumGasConsumed: uint64(0), | ||
|
||
expectErr: true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
suite.Run(tc.name, func() { | ||
suite.SetupTest() | ||
_, _, existingGaugeCoins, _ := suite.SetupNewGauge(true, sdk.Coins{sdk.NewInt64Coin("stake", 12)}) | ||
|
||
suite.FundAcc(tc.owner, tc.coinsToAdd) | ||
|
||
existingGasConsumed := suite.Ctx.GasMeter().GasConsumed() | ||
|
||
err := suite.App.IncentivesKeeper.AddToGaugeRewards(suite.Ctx, tc.owner, tc.coinsToAdd, tc.gaugeId) | ||
if tc.expectErr { | ||
suite.Require().Error(err) | ||
|
||
// balance shouldn't change in the module | ||
balance := suite.App.BankKeeper.GetAllBalances(suite.Ctx, suite.App.AccountKeeper.GetModuleAddress(types.ModuleName)) | ||
suite.Require().Equal(existingGaugeCoins, balance) | ||
|
||
} else { | ||
suite.Require().NoError(err) | ||
|
||
// Ensure that at least the minimum amount of gas was charged (based on number of additional gauge coins) | ||
gasConsumed := suite.Ctx.GasMeter().GasConsumed() - existingGasConsumed | ||
suite.Require().True(gasConsumed >= tc.minimumGasConsumed) | ||
|
||
// existing coins gets added to the module when we create gauge and add to gauge | ||
expectedCoins := existingGaugeCoins.Add(tc.coinsToAdd...) | ||
|
||
// check module account balance, should go up | ||
balance := suite.App.BankKeeper.GetAllBalances(suite.Ctx, suite.App.AccountKeeper.GetModuleAddress(types.ModuleName)) | ||
suite.Require().Equal(expectedCoins, balance) | ||
|
||
// check gauge coins should go up | ||
gauge, err := suite.App.IncentivesKeeper.GetGaugeByID(suite.Ctx, tc.gaugeId) | ||
suite.Require().NoError(err) | ||
|
||
suite.Require().Equal(expectedCoins, gauge.Coins) | ||
} | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package types | ||
|
||
var ( | ||
BaseGasFeeForAddRewardToGauge = 10_000 | ||
) |
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.
Just realized that this should actually be charging
baseAmount * (len(gauge.Coins) + len(coins))
since we allow for adding multiple coins at once here. The current implementation only scales by the number of coins being added, not the ones that already exist.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.
i see, i originally thought it was just for new denoms. I'll change it to accomodate existing denoms