Skip to content
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

Add two unit tests for ProcessRewards #806

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

teddyding
Copy link
Contributor

@teddyding teddyding commented Nov 27, 2023

Changelist

Added two unit tests:

  • 3 accounts, treasury balance has remaining balance at the end of block, fee_multiplier=0.99
  • 3 accounts, treasury balance has remaining balance at the end of block, fee_multiplier=0.33 (value suggested by governance in initial rewards distribution period)

Test Plan

[Describe how this PR was tested (if applicable)]

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Copy link
Contributor

coderabbitai bot commented Nov 27, 2023

Walkthrough

The changes involve updates to a test suite for the TestProcessRewardsForBlock function. These updates add various test scenarios to evaluate the rewards distribution mechanism. The scenarios test the system's behavior with different reward shares, treasury balances, token prices, and fee multipliers. The tests ensure that the rewards are calculated correctly, considering factors like sufficient treasury funds, the impact of different fee multipliers, and the proper handling of reward rounding.

Changes

File Path Change Summary
.../x/rewards/keeper/keeper_test.go Added test cases to TestProcessRewardsForBlock for evaluating reward distribution with varying reward shares, treasury balances, token prices, and fee multipliers.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 37e5119 and 8e6fbb5.
Files selected for processing (1)
  • protocol/x/rewards/keeper/keeper_test.go (1 hunks)

Comment on lines +669 to +672
Address: authtypes.NewModuleAddress(types.TreasuryAccountName).String(),
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(14_282_714), // 200 - 105.34 - 79.955 - 0.419 ~= 14.28 full coins
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the test case "three reward shares, enough treasury balance, $1.18 token price, 0.99 fee multiplier", the treasury account address is retrieved using authtypes.NewModuleAddress(types.TreasuryAccountName).String(). This is inconsistent with the rest of the test cases, which use types.TreasuryModuleAddress.String(). To maintain consistency and avoid potential issues, the same method should be used throughout the test cases.

Comment on lines +718 to +721
Address: authtypes.NewModuleAddress(types.TreasuryAccountName).String(),
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(138_094_240), // 200 - 105.34 - 79.955 - 0.419 ~= 138.094 full coins
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the test case "three reward shares, enough treasury balance, $1.18 token price, 0.33 fee multiplier", the treasury account address is retrieved using authtypes.NewModuleAddress(types.TreasuryAccountName).String(). This is inconsistent with the rest of the test cases, which use types.TreasuryModuleAddress.String(). To maintain consistency and avoid potential issues, the same method should be used throughout the test cases.

},
tokenPrice: tokenPrice1_18Usdc,
treasuryAccountBalance: sdkmath.NewInt(200_000_000), // 200 full coins
feeMultiplierPpm: 330_000, // 99%
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment for the feeMultiplierPpm in the test case "three reward shares, enough treasury balance, $1.18 token price, 0.33 fee multiplier" states "99%" which is incorrect. The actual value used in the test case is 330_000, which corresponds to "33%". The comment should be updated to reflect the correct fee multiplier percentage to avoid confusion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Fix this comment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roy-dydx I've corrected the comment to accurately reflect the fee multiplier percentage:

- feeMultiplierPpm:       330_000,                     // 99%
+ feeMultiplierPpm:       330_000,                     // 33%

This change ensures that the comment now matches the actual value used in the test case.

}},
},
{
Address: authtypes.NewModuleAddress(types.TreasuryAccountName).String(),
Copy link
Contributor

@clemire clemire Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coderabbit made a good comment, so I'm calling it out (I personally ignore code rabbit these days): please use types.TreasuryModuleAddress.String() here and below instead? (This was a recentish code change, maybe 3 weeks ago.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants