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

fix(ton): fix call data parsing #3711

Open
wants to merge 3 commits into from

Conversation

swift1337
Copy link
Contributor

@swift1337 swift1337 commented Mar 13, 2025

ABI-encoded call data was truncated:

invalid output (truncated)

2000000000000000000000000000000000000000000000000000000000000000105a455441204f4e20544f4e2059454148

Now fixed and passed as is:

0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000115a455441204f4e20544f4e205945414833000000000000000000000000000000

Related: #2810

Summary by CodeRabbit

  • Documentation
    • Streamlined release notes by reorganizing sections to clearly present upcoming features and fixes.
  • New Features
    • Updated feature listings now highlight improved caching capabilities.
  • Bug Fixes
    • Addressed an issue that improves the reliability of transaction data parsing.
  • Tests
    • Enhanced validations for deposit and call operations to ensure consistent performance.

@swift1337 swift1337 added the TON_TESTS Runs TON E2E tests label Mar 13, 2025
@swift1337 swift1337 self-assigned this Mar 13, 2025
@swift1337 swift1337 requested a review from a team as a code owner March 13, 2025 21:22
Copy link
Contributor

coderabbitai bot commented Mar 13, 2025

📝 Walkthrough

Walkthrough

The changes reorganize the changelog documentation, update header levels, and remove redundant subsections. A new fixes section is introduced for TON call_data parsing. The test suite has been enhanced with an additional case to validate deposit and call ABI transaction parsing, along with adjustments to snake data tests. A new JSON fixture file for deposit and call transactions is added, and the bit string handling routines in the TLB module have been refactored to streamline marshalling and unmarshalling processes.

Changes

File(s) Change Summary
changelog.md Changed "## Unreleased" to "# UNRELEASED", removed redundant "### Features" subheading, and introduced a new "Fixes" section with an entry for TON call_data parsing.
pkg/contracts/ton/gateway_test.go
pkg/contracts/ton/testdata/.../07-deposit-and-call-abi.json
Added a new test case ("Deposit and call ABI") to validate transaction parsing and updated snake data tests with a helper function for hex-to-byte conversion. A new JSON fixture file for deposit and call transaction is introduced.
pkg/contracts/ton/tlb.go Refactored UnmarshalSnakeCell and MarshalSnakeCell to use new bit string handling routines, removing unnecessary steps and directly processing data via boc.BitString and boc.NewBitString.

Sequence Diagram(s)

sequenceDiagram
    participant TC as Test Case
    participant GC as Gateway Contract
    participant TL as TLB Module

    TC->>GC: Load transaction fixture (JSON data)
    GC->>TL: Parse transaction using UnmarshalSnakeCell
    TL-->>GC: Return parsed transaction details
    GC-->>TC: Provide transaction details
    TC->>TC: Assert expected deposit, recipient, amount, and call data
Loading

Possibly related PRs

Suggested labels

UPGRADE_TESTS, no-changelog

Suggested reviewers

  • kingpinXD
  • lumtis
  • gartnera

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 24290d1 and 8347492.

📒 Files selected for processing (4)
  • changelog.md (1 hunks)
  • pkg/contracts/ton/gateway_test.go (2 hunks)
  • pkg/contracts/ton/testdata/07-deposit-and-call-abi.json (1 hunks)
  • pkg/contracts/ton/tlb.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to ...

**/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

  • pkg/contracts/ton/gateway_test.go
  • pkg/contracts/ton/tlb.go
🪛 markdownlint-cli2 (0.17.2)
changelog.md

5-5: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3

(MD001, heading-increment)

🔇 Additional comments (9)
changelog.md (2)

3-7: Good job on improving the changelog structure!

The reorganization of the changelog with a proper heading level and distinct sections for features and fixes improves readability and follows better Markdown documentation practices.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

5-5: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3

(MD001, heading-increment)


11-12: Clear documentation of the TON call_data parsing fix.

The addition of a dedicated Fixes section with the entry correctly references the PR number and provides a concise description of the fix.

pkg/contracts/ton/testdata/07-deposit-and-call-abi.json (1)

1-8: Well-structured test fixture for TON deposit and call ABI transactions.

This JSON fixture provides the necessary test data for validating the fix to the TON call_data parsing functionality. The file includes all required fields (account, boc, description, hash, logicalTime) and clearly identifies itself as test data.

pkg/contracts/ton/tlb.go (2)

35-38: Improved bit string handling in UnmarshalSnakeCell.

The refactoring from manually processing cell data to directly using BitString's ReadBytes functionality simplifies the code while maintaining functionality. This approach calculates the exact number of bytes to read and leverages the BitString API more effectively.


43-49: Streamlined MarshalSnakeCell implementation.

The refactored code directly creates and writes to a BitString of the appropriate size, removing unnecessary intermediate steps. This approach is more straightforward and likely more efficient.

pkg/contracts/ton/gateway_test.go (4)

165-199: Excellent test coverage for ABI-encoded call data parsing.

The new test case for "Deposit and call ABI" validates the fix for TON call_data parsing by testing a real-world scenario with ABI-encoded payload. The test includes comprehensive assertions for sender, recipient, deposit amount, and the exact call data content.


401-406: Good utility function for hex to byte conversion.

The h2b helper function improves code readability by abstracting the conversion of hexadecimal strings to byte slices, handling the common "0x" prefix case.


408-426: Enhanced test data structure and coverage.

Restructuring the test cases into a named struct with descriptive fields improves test readability and maintainability. The addition of ABI-encoded call data test cases provides excellent coverage for complex scenarios.


437-441: Improved error reporting for test failures.

The enhanced error reporting now provides detailed information about length mismatches, including the actual content and byte comparisons, which will significantly improve the debugging experience when tests fail.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

LGTM but why the DepositAndCall E2E test didn't catch it?

@swift1337
Copy link
Contributor Author

LGTM but why the DepositAndCall E2E test didn't catch it?

because its contract doesn't check for message contents nor tries to decode ABI

lastMessage = message;

@swift1337 swift1337 added this pull request to the merge queue Mar 14, 2025
Any commits made after this event will not be merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TON_TESTS Runs TON E2E tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants