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

[CORE-619] add e2e tests for subaccount transfers #800

Merged
merged 2 commits into from
Nov 29, 2023
Merged

[CORE-619] add e2e tests for subaccount transfers #800

merged 2 commits into from
Nov 29, 2023

Conversation

tqin7
Copy link
Contributor

@tqin7 tqin7 commented Nov 22, 2023

Changelist

add e2e tests for MsgCreateTransfer, which transfers between subaccounts

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 22, 2023

Walkthrough

The changes involve the addition of a new test function TestMsgCreateTransfer in the app_test.go file of a Go package, which is designed to test the transfer message handling logic within a protocol. This function includes various test scenarios to ensure the correct behavior of transfers between subaccounts, handling of non-USDC assets, zero amount transfers, and self-transfers. The updates include new imports and enhanced test cases to validate successful operations and expected failures.

Changes

File Change Summary
.../x/sending/app_test.go The provided diff contains the addition of a new test function TestMsgCreateTransfer to the source code. This test function is responsible for testing the message handling logic related to creating transfers between subaccounts. It includes test cases for successful transfers between different subaccounts, as well as failure cases such as transferring non-USDC assets, zero amounts, and transferring from a subaccount to itself. Each test case sets up the necessary context, constructs the transfer message, invokes CheckTx, and then verifies the expected behavior of the transfer, including subaccount balances and indexer events.
.../x/sending/app_test.go The provided diff shows changes to a Go package related to testing transfer functionality. The changes include the addition of imports, new test cases for the TestMsgCreateTransfer function, and modifications to the test setup and assertions within the test function. Specifically, the test cases cover various scenarios such as successful transfers, failed transfers due to insufficient balance, transfers of non-USDC assets, zero amount transfers, and transfers from a subaccount to itself. The test setup involves creating test application instances, constructing messages, invoking CheckTx, and validating the results.
.../x/sending/app_test.go The diff includes the following changes: 1. Added import statement for the "bytes" package and the "github.com/cometbft/cometbft/types" package. 2. Added a new test function TestMsgCreateTransfer to test the message for creating a transfer. 3. The new test function includes test cases for successful and failed transfers, including scenarios for transferring between subaccounts, transferring to a non-existent subaccount, transferring non-USDC assets, transferring zero amounts, and transferring from a subaccount to itself.

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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2c64cf6 and 4541828.
Files selected for processing (1)
  • protocol/x/sending/app_test.go (1 hunks)
Additional comments: 1
protocol/x/sending/app_test.go (1)
  • 30-96: The test cases in TestMsgCreateTransfer are well-structured and cover a variety of scenarios. However, there are a few points to consider:
  • The test case "Success: transfer from Alice subaccount to non-existent subaccount" assumes that transferring to a non-existent subaccount will create it. This behavior should be explicitly documented in the system's design or API documentation, as it could have security implications.
  • The test case "Failure: transfer a non-USDC asset" uses a string "Non-USDC asset transfer not implemented" to check for an error condition. It's important to ensure that this string is consistent with the actual error message returned by the system.
  • The test case "Failure: transfer zero amount" and "Failure: transfer from a subaccount to itself" are good checks for input validation. Ensure that these checks are also performed at the API level and not just in the tests to prevent these operations from occurring in a production environment.

Overall, the tests seem to be comprehensive, but it's crucial to ensure that the assumptions made in the tests align with the actual system behavior and that all error conditions are handled consistently across the application.

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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2c64cf6 and 529524b.
Files selected for processing (1)
  • protocol/x/sending/app_test.go (2 hunks)
Additional comments: 2
protocol/x/sending/app_test.go (2)
  • 3-11: The import block has been updated to include necessary packages for the test cases. Ensure that all new imports are used within the test file to avoid including unnecessary dependencies.

  • 32-307: The TestMsgCreateTransfer function has been added to test various scenarios for transferring assets between subaccounts. The test cases are well-structured and cover a range of expected behaviors. However, there are a few points to consider:

  • Ensure that the senderInitialBalance is set up correctly in the genesis state for each test case to reflect the initial conditions accurately.
  • Verify that the checkTxResponseContains string is correctly asserted in the test cases that expect a specific error message.
  • Confirm that the CheckTx and DeliverTx methods are being called with the correct parameters and that their responses are being handled as expected.
  • Check that the balance assertions after the transfer (senderQuantumsAfterTransfer and recipientQuantumsAfterTransfer) are correctly calculated and that the test fails if the balances do not match the expected values.
  • Ensure that the indexer events are being checked correctly and that the expected events match the actual events emitted during the test.

Overall, the test function appears to be comprehensive and should provide good coverage for the transfer functionality. It is important to run the tests and verify that they pass and that they are correctly testing the intended behavior.

amount: 7_654_321,
},
// Transfer to a non-existent subaccount will create that subaccount and succeed.
"Success: transfer from Alice subaccount to non-existent subaccount": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Bob's account already exists on the chain, though, yes? Asking b/c I'm not sure - does it make sense to run a test case with an unused account id to create a subaccount? Are there any owner checks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh actually I overrode genesis state with just 1 subaccount (sender subaccount) so all test cases actually send to a subaccount that doesn't exist yet. Let me update the PR!

Copy link
Contributor

Choose a reason for hiding this comment

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

ICICIC. Thanks for explaining!

}
require.Conditionf(t, checkTxResp.IsOK, "Expected CheckTx to succeed. Response: %+v", checkTxResp)

// Check that no indexer events are emitted so far.
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 TY for the comments!

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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 529524b and d651b44.
Files selected for processing (1)
  • protocol/x/sending/app_test.go (2 hunks)
Additional comments: 6
protocol/x/sending/app_test.go (6)
  • 3-9: The addition of import statements for "bytes" and "github.com/cometbft/cometbft/types" is consistent with the summary and necessary for the new tests.

  • 32-329: The new test function TestMsgCreateTransfer is well-structured and covers a comprehensive set of scenarios for asset transfers between subaccounts, including success and failure cases.

  • 63-120: The test cases within TestMsgCreateTransfer correctly implement the scenarios described in the summary, such as transfers between subaccounts, to non-existent subaccounts, non-USDC assets, zero amounts, and transfers from a subaccount to itself.

  • 123-328: The test setup and assertions in TestMsgCreateTransfer are thorough, checking not only for the correct transaction execution but also for the proper state updates and event generation.

  • 63-120: The use of constants for asset IDs and subaccount IDs in the test cases enhances maintainability and readability.

  • 214-326: The test function TestMsgCreateTransfer correctly checks for the presence of indexer events, ensuring that the system's indexing functionality is working as expected.

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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 529524b and 74e2020.
Files selected for processing (1)
  • protocol/x/sending/app_test.go (2 hunks)
Additional comments: 4
protocol/x/sending/app_test.go (4)
  • 3-9: The addition of the "bytes" and "github.com/cometbft/cometbft/types" packages is justified as they are used within the new test function TestMsgCreateTransfer.

  • 32-328: The new test function TestMsgCreateTransfer is well-structured, with clear setup and expectations for each test case, covering a variety of scenarios for transfer operations.

  • 123-328: The test function includes thorough setup and assertions, properly validating the expected outcomes after invoking CheckTx and DeliverTx, and checking the state changes for sender and recipient subaccount balances.

  • 29-333: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [3-330]

No breaking changes have been introduced to the existing API, as there are no alterations to the signatures of exported functions, global data structures, global variables, interfaces, return values, or thrown exceptions.

@tqin7 tqin7 merged commit 013aabe into main Nov 29, 2023
15 of 16 checks passed
@tqin7 tqin7 deleted the tq/core-619 branch November 29, 2023 21:52
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.

2 participants