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 additional v2 test cases to callbacks #6403

Merged

Conversation

chatton
Copy link
Contributor

@chatton chatton commented May 28, 2024

Description

NOTE: converting to draft until token structure refactor is complete as this effects the tests.

No test logic has changed in this PR. The existing tests have all been updated to add v2 packet data test cases which do the same checks as the v1 tests.

I opted to not use the conversion fn and to explicitly declare v2 packet data types so as to not maintain a dependency on the v1 type in those tests.

closes: #6356


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to GitHub issue with discussion and accepted design, OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

Summary by CodeRabbit

  • New Features

    • Enhanced callback functionality with support for new packet data structures and configurations.
  • Bug Fixes

    • Improved validation for callback addresses and memo fields.
  • Refactor

    • Simplified Denom structure in packet transfer tests, improving code readability and maintainability.

Copy link
Contributor

coderabbitai bot commented May 28, 2024

Walkthrough

The changes involve enhancing the test cases for handling callback data in packet transfers by incorporating the FungibleTokenPacketDataV2 structure. This includes setting gas limits, defining callback addresses, and validating memo fields. Additionally, the Denom structure within transfertypes.Token has been simplified in the ibc_middleware_test.go file to improve readability and maintainability.

Changes

Files Change Summary
callbacks_test.go Expanded test cases to include FungibleTokenPacketDataV2, added scenarios for gas limits, callback addresses, and memo validation.
ibc_middleware_test.go Simplified the structure of Denom within transfertypes.Token by directly assigning values to fields.

Sequence Diagram(s) (Beta)

N/A

Assessment against linked issues

Objective Addressed Explanation
Amend test cases to use FungibleTokenPacketDataV2 (#6356)
Combine functions TestGetSourceCallbackDataTransfer and TestGetDestCallbackDataTransfer (#6358) The functions TestGetSourceCallbackDataTransfer and TestGetDestCallbackDataTransfer have not been combined into a single function.

Possibly related issues


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.

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.

Actionable comments posted: 0

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between e07599e and b5aafc1.
Files selected for processing (1)
  • modules/apps/callbacks/types/callbacks_test.go (7 hunks)
Additional Context Used
Path-based Instructions (1)
modules/apps/callbacks/types/callbacks_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Additional comments not posted (5)
modules/apps/callbacks/types/callbacks_test.go (5)

16-16: The import of ibcexported is correctly added to support the new test cases involving FungibleTokenPacketDataV2.


573-596: The addition of v2 test cases in TestGetSourceCallbackDataTransfer is correctly implemented, ensuring that both v1 and v2 functionalities are tested. This is crucial for backward compatibility and future-proofing the code.


660-683: The implementation of v2 test cases in TestGetDestCallbackDataTransfer is thorough, covering the necessary scenarios to ensure the new data format is handled correctly.
[APROVED]


814-932: The expanded test cases in TestGetCallbackAddress for FungibleTokenPacketDataV2 are comprehensive, covering various memo formats and ensuring robustness in callback address extraction.


298-322: The new test cases for FungibleTokenPacketDataV2 are well-structured and cover a variety of scenarios including edge cases for gas limits and memo formatting. Ensure that these tests are integrated into the continuous integration pipeline to verify their execution in the automated test environment.

Also applies to: 324-346, 348-370, 372-394, 396-420, 422-444, 455-471, 473-489, 491-507

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.

Actionable comments posted: 0

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between b5aafc1 and a5f6cff.
Files selected for processing (1)
  • modules/apps/callbacks/ibc_middleware_test.go (6 hunks)
Additional Context Used
Path-based Instructions (1)
modules/apps/callbacks/ibc_middleware_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Additional comments not posted (6)
modules/apps/callbacks/ibc_middleware_test.go (6)

170-171: Ensure the Denom and Trace fields are correctly assigned in FungibleTokenPacketDataV2.

This change aligns with the PR's objective to use FungibleTokenPacketDataV2 instead of the older version, enhancing clarity and maintainability.


312-313: Verify the correct assignment of Denom and Trace fields in FungibleTokenPacketDataV2.

The update is consistent with the PR's goal to transition to FungibleTokenPacketDataV2 and simplifies the data structure.


645-646: Check the assignment of Denom and Trace fields in FungibleTokenPacketDataV2.

This change is part of the PR's broader effort to update the packet data format, which should help in reducing dependencies on the older data format.


777-778: Confirm the correct handling of Denom and Trace fields in FungibleTokenPacketDataV2.

The modifications are consistent with the PR's objectives to use the new packet data format, which improves the clarity and maintainability of the code.


1001-1002: Ensure the Denom and Trace fields are correctly assigned in FungibleTokenPacketDataV2.

This change is part of the PR's broader effort to update the packet data format, which should help in reducing dependencies on the older data format.


1035-1036: Check the assignment of Denom and Trace fields in FungibleTokenPacketDataV2.

The update is consistent with the PR's goal to transition to FungibleTokenPacketDataV2 and simplifies the data structure.

@chatton chatton marked this pull request as draft May 29, 2024 08:34
Copy link

sonarcloud bot commented May 29, 2024

Quality Gate Passed Quality Gate passed for 'ibc-go'

Issues
11 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@chatton chatton marked this pull request as ready for review May 29, 2024 14:51
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.

Actionable comments posted: 0

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between a5f6cff and 2247204.
Files selected for processing (2)
  • modules/apps/callbacks/ibc_middleware_test.go (2 hunks)
  • modules/apps/callbacks/types/callbacks_test.go (19 hunks)
Files skipped from review as they are similar to previous changes (1)
  • modules/apps/callbacks/ibc_middleware_test.go
Additional Context Used
Path-based Instructions (1)
modules/apps/callbacks/types/callbacks_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Additional comments not posted (6)
modules/apps/callbacks/types/callbacks_test.go (6)

16-16: Added import for ibcexported is appropriate for the new test cases involving FungibleTokenPacketDataV2.


Line range hint 748-965: Updates to TestGetCallbackAddress include handling of new packet formats and various memo configurations. It's important to ensure that the address extraction from memos is robust against malformed or incorrect data, especially with the new packet format.

Verification successful

The test cases in modules/apps/callbacks/types/callbacks_test.go cover a wide range of scenarios for memo handling, including valid and invalid JSON strings, empty memos, and various structures within the memo. This indicates a robust approach to address extraction from memos, ensuring that the code can handle malformed or incorrect data effectively.

  • Instances of memo handling include different formats and potential edge cases.
  • The test cases ensure robustness against malformed or incorrect data.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Ensure robustness of address extraction from memos.

# Test: Search for memo handling in the test file. Expect: Robust handling of malformed or incorrect data.
rg --type go $'Memo' modules/apps/callbacks/types/callbacks_test.go

Length of output: 3626


255-463: The addition of test cases for FungibleTokenPacketDataV2 in the TestGetCallbackData function is well-aligned with the PR objectives to support both v1 and v2 data formats. Ensure that all edge cases and potential error scenarios are covered for the new data structure.

Verification successful

The test cases for FungibleTokenPacketDataV2 in callbacks_test.go cover a comprehensive range of scenarios, including various success conditions, edge cases, and potential error scenarios. This ensures robust testing of the new data structure.

  • Success scenarios with different gas limits and callback configurations.
  • Failure scenarios with empty memos, invalid addresses, and malformed JSON.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all edge cases and error scenarios are covered for FungibleTokenPacketDataV2.

# Test: Search for test cases related to FungibleTokenPacketDataV2. Expect: Comprehensive coverage.
rg --type go $'FungibleTokenPacketDataV2' modules/apps/callbacks/types/callbacks_test.go

Length of output: 1445



Script:

#!/bin/bash
# Description: List all test cases involving FungibleTokenPacketDataV2 and review their content for edge cases and error scenarios.

# Step 1: List all test cases involving FungibleTokenPacketDataV2.
rg --type go --context 10 'FungibleTokenPacketDataV2' modules/apps/callbacks/types/callbacks_test.go

Length of output: 11678


661-744: The TestGetDestCallbackDataTransfer function updates are consistent with the changes in TestGetSourceCallbackDataTransfer, adding support for v2 packet data. This consistency is good for maintainability. Ensure that the packet data handling and callback mechanisms are thoroughly tested.

Verification successful

The search results indicate that GetDestCallbackData is used in multiple test cases across different files, ensuring that various scenarios are covered. This demonstrates thorough testing of packet data handling and callback mechanisms.

  • modules/apps/callbacks/types/callbacks_test.go: Contains the TestGetDestCallbackDataTransfer function.
  • modules/apps/callbacks/callbacks_test.go: Contains additional test cases involving GetDestCallbackData.

These findings confirm that the packet data handling and callback mechanisms are thoroughly tested.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify packet data handling and callback mechanisms are thoroughly tested.

# Test: Search for packet data handling and callback mechanism tests. Expect: Thorough testing.
rg --type go $'GetDestCallbackData' modules/apps/callbacks/types/callbacks_test.go

Length of output: 244



Script:

#!/bin/bash
# Description: Verify packet data handling and callback mechanisms are thoroughly tested across all test files.

# Test: Search for packet data handling and callback mechanism tests across all Go test files.
rg --type go 'GetDestCallbackData' --glob '*_test.go'

Length of output: 451



Script:

#!/bin/bash
# Description: Extract and review test cases involving GetDestCallbackData in modules/apps/callbacks/callbacks_test.go.

# Extract lines containing GetDestCallbackData and surrounding context for review.
rg --type go -A 10 -B 10 'GetDestCallbackData' modules/apps/callbacks/callbacks_test.go

Length of output: 984


567-654: The TestGetSourceCallbackDataTransfer function has been updated to include test cases for both v1 and v2 packet data. This is crucial for ensuring backward compatibility and the correct handling of new packet formats. It's important to verify that the setup and teardown methods are correctly handling the new test cases.


Line range hint 979-1225: The TestUserDefinedGasLimit function correctly handles user-defined gas limits in both v1 and v2 packet data formats. This is crucial for ensuring that gas limits are respected and correctly applied. Verify that the gas limit extraction logic is correctly implemented and does not allow for unintended behaviors.

Verification successful

The getUserDefinedGasLimit function correctly handles user-defined gas limits by ensuring the gas limit is specified as a string and not a JSON number. It returns 0 if the gas limit is improperly formatted or not specified. The test cases in callbacks_test.go cover various scenarios, including valid and invalid gas limits.

  • The function ensures the gas limit is a string.
  • It parses the string to a uint64 and returns 0 if parsing fails.

This implementation appears robust and correctly handles the intended scenarios.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify correct implementation of gas limit extraction logic.

# Test: Search for gas limit extraction logic in the test file. Expect: Correct implementation and no unintended behaviors.
rg --type go $'GetUserDefinedGasLimit' modules/apps/callbacks/types/callbacks_test.go

Length of output: 173



Script:

#!/bin/bash
# Description: Locate the definition and implementation of GetUserDefinedGasLimit.

# Search for the definition of GetUserDefinedGasLimit in the codebase.
rg --type go 'func GetUserDefinedGasLimit' 

Length of output: 162



Script:

#!/bin/bash
# Description: Extract the implementation of GetUserDefinedGasLimit.

# Extract the implementation of GetUserDefinedGasLimit from the specified file.
rg --type go --context 10 'func GetUserDefinedGasLimit' modules/apps/callbacks/types/export_test.go

Length of output: 685



Script:

#!/bin/bash
# Description: Locate the definition and implementation of getUserDefinedGasLimit.

# Search for the definition of getUserDefinedGasLimit in the codebase.
rg --type go 'func getUserDefinedGasLimit' 

Length of output: 160



Script:

#!/bin/bash
# Description: Extract the implementation of getUserDefinedGasLimit.

# Extract the implementation of getUserDefinedGasLimit from the specified file.
rg --type go --context 20 'func getUserDefinedGasLimit' modules/apps/callbacks/types/callbacks.go

Length of output: 1658

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

Woo! Nice work!!

@colin-axner colin-axner added the priority PRs that need prompt reviews label May 29, 2024
Copy link
Contributor

@DimitrisJim DimitrisJim left a comment

Choose a reason for hiding this comment

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

🚀

@chatton chatton merged commit 370cfb9 into main May 29, 2024
72 of 75 checks passed
@chatton chatton deleted the cian/issue#6356-amend-test-cases-to-use-fungibletokenpacketdatav2 branch May 29, 2024 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority PRs that need prompt reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Amend test cases to use FungibleTokenPacketDataV2
3 participants