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

[Testing] add account balance coverage to account settlement #670

Merged
merged 3 commits into from
Jul 15, 2024

Conversation

bryanchriswhite
Copy link
Contributor

@bryanchriswhite bryanchriswhite commented Jul 10, 2024

Summary

Add coverage for the following balances to the account settlement tests:

  • Application/supplier account
  • Application/supplier module account
  • Application/supplier stake

Issue

Type of change

Select one or more:

  • New feature, functionality or library
  • Bug fix
  • Code health or cleanup
  • Documentation
  • Other (specify)

Testing

Documentation changes (only if making doc changes)

  • make docusaurus_start; only needed if you make doc changes

Local Testing (only if making code changes)

  • Unit Tests: make go_develop_and_test
  • LocalNet E2E Tests: make test_e2e
  • See quickstart guide for instructions

PR Testing (only if making code changes)

  • DevNet E2E Tests: Add the devnet-test-e2e label to the PR.
    • THIS IS VERY EXPENSIVE, so only do it after all the reviews are complete.
    • Optionally run make trigger_ci if you want to re-trigger tests without any code changes
    • If tests fail, try re-running failed tests only using the GitHub UI as shown here

Sanity Checklist

  • I have tested my changes using the available tooling
  • I have commented my code
  • I have performed a self-review of my own code; both comments & source code
  • I create and reference any new tickets, if applicable
  • I have left TODOs throughout the codebase, if applicable

Summary by CodeRabbit

  • New Features

    • Introduced new SupplierKeeper to manage supplier interactions within the tokenomics module.
  • Tests

    • Enhanced test cases to include new balance checks and validations.
    • Added new function getBalance for retrieving account balances in tests.
    • Updated test logic to handle various accounting scenarios, including debt and low app stake.

@bryanchriswhite bryanchriswhite added testing Test (or test utils) additions, fixes, improvements or other tokenomics Token Economics - what else do you need? labels Jul 10, 2024
@bryanchriswhite bryanchriswhite self-assigned this Jul 10, 2024
Copy link

coderabbitai bot commented Jul 10, 2024

Walkthrough

The recent changes introduce a SupplierKeeper to the TokenomicsModuleKeepers struct, update test files in the x/tokenomics/keeper package to reflect new logic and imports, and modify the BankKeeper interface in x/tokenomics/types by adding a Balance method and a new SupplierKeeper interface. These updates enhance the functionality and testing of the tokenomics module.

Changes

File Path Change Summary
testutil/keeper/tokenomics.go Added SupplierKeeper to TokenomicsModuleKeepers struct and initialized it in NewTokenomicsModuleKeepers.
x/tokenomics/keeper/settle_session_accounting_test.go Updated imports, added getBalance function, and enhanced test functions with new assertions and validations.
x/tokenomics/types/expected_keepers.go Added banktypes import, modified BankKeeper interface, and introduced a new SupplierKeeper interface.

Poem

In code's vast garden, changes bloom anew,
A SupplierKeeper now joins the crew.
Tests enhanced with balance checks so true,
Tokenomics thrive, with each line we pursue.
🐇✨ CodeRabbit hops, to bring this view!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

// Assert that `suppliertypes.ModuleName` account module balance is *unchanged*
// Assert that `supplierAddress` account balance has *increased* by the appropriate amount
// Assert that `supplierAddress` staked balance is *unchanged*
// Assert that `apptypes.ModuleName` account module balance is *unchanged*
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Reviewer, this assertion seems to be incorrect to me. My understanding is that the account module balance MUST decrease as a result of the burn. I assumed this is copy-pasta and have the test making the modified assertion.

@bryanchriswhite bryanchriswhite force-pushed the issues/584/test/settlement-balances branch from 988dc63 to 1ee53df Compare July 10, 2024 10:30
@bryanchriswhite bryanchriswhite marked this pull request as ready for review July 10, 2024 10:31
Copy link

@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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bdbc365 and 1ee53df.

Files selected for processing (3)
  • testutil/keeper/tokenomics.go (2 hunks)
  • x/tokenomics/keeper/settle_session_accounting_test.go (4 hunks)
  • x/tokenomics/types/expected_keepers.go (3 hunks)
Additional comments not posted (15)
x/tokenomics/types/expected_keepers.go (3)

9-9: Import Statement Added

The import statement for banktypes has been added correctly and is necessary for the new method in the BankKeeper interface.


58-62: New SupplierKeeper Interface

The SupplierKeeper interface has been introduced with GetSupplier and SetSupplier methods. This addition appears correct and aligns with the PR's objective to add coverage for supplier account balances.


30-30: New Method in BankKeeper Interface

The Balance method has been added to the BankKeeper interface. Ensure the implementation of this method aligns with the expected functionality and handles errors appropriately.

testutil/keeper/tokenomics.go (2)

60-60: SupplierKeeper Added to TokenomicsModuleKeepers

The SupplierKeeper field is correctly added to the TokenomicsModuleKeepers struct.


344-344: SupplierKeeper Initialization

The SupplierKeeper is correctly initialized in the NewTokenomicsModuleKeepers function.

x/tokenomics/keeper/settle_session_accounting_test.go (10)

5-12: Import Statements Added

The new import statements for context, authtypes, and banktypes are necessary for the updated test logic and are correctly added.


24-24: Import Statement for suppliertypes

The import statement for suppliertypes is necessary for the updated test logic and is correctly added.


29-29: TODO_MAINNET: Add Coverage

The TODO comment indicates that test coverage for handling app debt scenarios needs to be added. This is a reminder and does not affect the current functionality.


34-47: Adding Application and Supplier for Test

The code correctly sets up a new application and supplier with their respective stakes for the test scenario.


70-109: Test for Valid Accounting

The test function correctly sets up the context and initial conditions for testing valid accounting scenarios. The balance queries before accounting are appropriately done.


110-124: Claim Setup for Test

The code correctly sets up a claim with the necessary session header and root hash for the test scenario.


126-127: Error Handling in Test

The test correctly checks for no errors in the SettleSessionAccounting function call.


130-156: Assertions for Valid Accounting

The assertions in the test function correctly verify the expected balances and stakes after the accounting process.


160-248: Test for Low App Stake

The test function correctly sets up the context and initial conditions for testing scenarios where the application stake is too low. The balance queries and assertions are appropriately done.


456-474: New getBalance Function

The getBalance function is introduced to retrieve account balances for testing. Ensure that this function is used consistently across all relevant test cases.

@bryanchriswhite bryanchriswhite linked an issue Jul 10, 2024 that may be closed by this pull request
15 tasks
@bryanchriswhite bryanchriswhite changed the title [Testing add account balance coverage to account settlement [Testing] add account balance coverage to account settlement Jul 10, 2024
Copy link
Contributor

@red-0ne red-0ne left a comment

Choose a reason for hiding this comment

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

Left a few comments but this reflects well how it works.


// Add a new application
appStake := cosmostypes.NewCoin("upokt", math.NewInt(1000000))
expectedAppEndStakeAmount := cosmostypes.NewCoin("upokt", math.NewInt(420))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we calculate this value or explain how we came up with it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just an arbitrary amount which the expectedAppBurn is defined in terms of. The idea is to ensure a non-zero stake balance that can be asserted at the end of the test. Defining this value first lets us define expectedAppBurn in terms of it and appStake, which I figured would be the simplest way to set things up.

require.True(t, appIsFound)
require.Equal(t, &expectedAppEndStakeAmount, app.GetStake())

// Assert that `apptypes.ModuleName` account module balance is *decreased* by the appropriate amount
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a comment on why app module balance decreases and not supplier module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

	// Assert that `apptypes.ModuleName` account module balance is *decreased* by the appropriate amount
	// NB: The application module account burns the amount of uPOKT that was held in escrow
	// on behalf of the applications which were serviced in a given session.
	// Assert that `suppliertypes.ModuleName` account module balance is *unchanged*
	// NB: Supplier rewards are minted to the supplier module account but then immediately
	// distributed to the supplier accounts which provided service in a given session.

x/tokenomics/keeper/settle_session_accounting_test.go Outdated Show resolved Hide resolved
…ent-balances

* pokt/main:
  [TODOs] refactor: proof path calculation (#659)
  [Dependencies] bump go-getter and ibc-go (#691)
  [Relayminer] refactor: `relayerSessionsManager#waitForBlock()` (#648)
  [Observables] chore: add `ReplayObservable#SubscribeFromLatestBufferedOffset()` (#647)
  [Observability] Add claim relays counter (#644)
  [Code Health] chore: log unused error when updating relay mining difficulty (#683)
  [Testing] chore: uncomment proof CLI query tests (#668)
  build(deps): bump ws from 7.5.9 to 7.5.10 in /docusaurus (#686)
  build(deps): bump webpack-dev-middleware from 5.3.3 to 5.3.4 in /docusaurus (#688)
  build(deps): bump express from 4.18.2 to 4.19.2 in /docusaurus (#687)
  build(deps): bump follow-redirects from 1.15.3 to 1.15.6 in /docusaurus (#685)
  build(deps): bump braces from 3.0.2 to 3.0.3 in /docusaurus (#689)
  [CosmosSDK] Bump to v0.50.7 (#682)
Copy link

@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.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1ee53df and 43e8ed1.

Files selected for processing (1)
  • x/tokenomics/keeper/settle_session_accounting_test.go (4 hunks)
Additional comments not posted (7)
x/tokenomics/keeper/settle_session_accounting_test.go (7)

29-47: LGTM!

The setup and assertions for the test look correct.


70-161: LGTM!

The setup and assertions for the test look correct. The function comprehensively tests the valid accounting scenarios.


165-253: LGTM!

The setup and assertions for the test look correct. The function comprehensively tests the scenario where the application stake is too low.


Line range hint 255-267:
LGTM!

The setup and assertions for the test look correct. The function comprehensively tests the scenario where the application is not found.


Line range hint 269-331:
LGTM!

The setup and assertions for the test look correct. The function comprehensively tests various scenarios with invalid root hashes.


Line range hint 333-413:
LGTM!

The setup and assertions for the test look correct. The function comprehensively tests various scenarios with invalid claims.


462-479: LGTM!

The helper function looks correct and is useful for the test cases.

tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types"
)

func TestSettleSessionAccounting_HandleAppGoingIntoDebt(t *testing.T) {
t.Skip("TODO_MAINNET: Add coverage of the design choice made for how to handle this scenario.")
Copy link

Choose a reason for hiding this comment

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

Reminder: Add coverage for the design choice.

The test is currently skipped with a TODO comment. Ensure to add the necessary test coverage for the design choice made for handling this scenario.

Do you want me to help with adding the test coverage or open a GitHub issue to track this task?

Copy link
Contributor

@red-0ne red-0ne left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@bryanchriswhite bryanchriswhite merged commit cd183ed into main Jul 15, 2024
10 checks passed
@bryanchriswhite bryanchriswhite deleted the issues/584/test/settlement-balances branch July 15, 2024 17:58
bryanchriswhite added a commit that referenced this pull request Jul 16, 2024
…ation-overserviced

* pokt/main:
  [TODO] Blockers @okdas (#674)
  [TODO_BLOCKER] chore: Remove stale TODO_BLOCKERs (#694)
  [TODO] refactor: query expiring claims w/ index (#671)
  [TODOs] `grace_period_end_offset_blocks` validation & cleanup (#667)
  [Testing] add account balance coverage to account settlement (#670)
  [Application] Auto-undelegation of unstaked gateways (#692)
  [RelayMiner] Fix LeanClient mutiple suppliers support (#662)
bryanchriswhite added a commit that referenced this pull request Jul 16, 2024
…-root

* pokt/main:
  [TODO] Blockers @okdas (#674)
  [TODO_BLOCKER] chore: Remove stale TODO_BLOCKERs (#694)
  [TODO] refactor: query expiring claims w/ index (#671)
  [TODOs] `grace_period_end_offset_blocks` validation & cleanup (#667)
  [Testing] add account balance coverage to account settlement (#670)
  [Application] Auto-undelegation of unstaked gateways (#692)
  [RelayMiner] Fix LeanClient mutiple suppliers support (#662)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Test (or test utils) additions, fixes, improvements or other tokenomics Token Economics - what else do you need?
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[TODO] @Olshansk's (and now @Bryan's) Blocker TODOs
2 participants