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: use base64 encode instead of utf8 in cString #24

Merged
merged 4 commits into from
Dec 6, 2024

Conversation

djm07073
Copy link
Contributor

@djm07073 djm07073 commented Dec 6, 2024

Fix

  • Resolve existing bug: Issue #99.
  • Fix compatibility issue caused by Buffer.to_string and Buffer.from_string handling of UTF-8.

Test

  • Add test cases to ensure full coverage of the changes.

Summary by CodeRabbit

  • New Features

    • Enhanced workflow with a new step for setting up Node.js, ensuring a consistent environment for builds and tests.
    • Added a new test case for decoding module bytes for a new entity, improving test coverage.
  • Bug Fixes

    • Updated address in the test suite to ensure accurate testing of functionalities.
  • Tests

    • Improved clarity in test variable names and expanded test cases for better validation of module information.

@djm07073 djm07073 requested a review from a team as a code owner December 6, 2024 08:12
Copy link

coderabbitai bot commented Dec 6, 2024

Warning

Rate limit exceeded

@djm07073 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 35 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 431a8f1 and 983fe76.

Walkthrough

The changes in this pull request include updates to the GitHub Actions workflow for setting up Node.js, modifications to the MoveBuilder class in src/builder.ts for encoding byte data using base64, and enhancements to the test suite in test/build.spec.ts for improved clarity and coverage. The workflow now includes a step to set up Node.js version 20 with caching for npm dependencies. The MoveBuilder class has updated methods for consistent byte data encoding, and the tests have been refined to replace certain variables and include new test cases.

Changes

File Change Summary
.github/workflows/test.yml Added a new step "Setup Node.js" using actions/setup-node@v3 to specify Node.js version '20' and enable caching for npm dependencies. Existing steps remain unchanged.
src/builder.ts Modified MoveBuilder class to encode compilerPayloadBytes and testOptBytes to base64 instead of UTF-8. Updated static methods to handle Buffer inputs as base64.
test/build.spec.ts Updated addtionalNamedAddresses with a new address for test2, replaced binary with dummy for clarity in tests, added a new test case for hihi, and duplicated a test for module info validation.

Poem

In the garden where bytes play,
A rabbit hops, brightening the day.
With Node.js set, the tests now gleam,
Base64 bytes flow like a dream.
New addresses hop, old ones take flight,
In the world of code, all feels just right! 🐇✨


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

CodeRabbit Configuration 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

@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

🧹 Outside diff range and nitpick comments (1)
test/build.spec.ts (1)

Line range hint 111-126: Remove duplicate test case

This test case is a duplicate of the previous 'reads module info correctly' test (lines 100-108). Consider removing this duplicate or renaming it if it serves a different purpose.

-  it('reads module info correctly', async () => {
-    const binary = await builder.get('dummy')
-    const moduleInfo = await MoveBuilder.read_module_info(binary)
-    const expectedModuleInfo = JSON.stringify({
-      address: [
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 4,
-      ],
-      name: 'dummy',
-    })
-
-    expect(moduleInfo).toEqual(expectedModuleInfo)
-  })
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3537ae2 and 431a8f1.

📒 Files selected for processing (3)
  • .github/workflows/test.yml (1 hunks)
  • src/builder.ts (2 hunks)
  • test/build.spec.ts (2 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/test.yml

35-35: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🔇 Additional comments (4)
src/builder.ts (3)

74-75: LGTM: Appropriate use of base64 encoding for binary data

The switch from UTF-8 to base64 encoding for compiler payload bytes is correct, as base64 is designed for encoding binary data without data loss.


209-209: LGTM: Consistent encoding approach

The test options bytes are now correctly encoded using base64, maintaining consistency with the encoding approach used in other methods.


Line range hint 1-300: Verify comprehensive encoding updates

Let's ensure all binary data handling methods have been updated to use base64 encoding consistently.

✅ Verification successful

Based on the search results, I can now generate the final response:

Binary data handling is correctly implemented

The codebase shows consistent encoding practices:

  • Base64 encoding is correctly used for all binary data transfers (compilerPayloadBytes, testOptBytes, moduleBytes, scriptBytes, compiledBinary)
  • UTF-8 encoding is only used for text data (package names, version strings) and reading text files (Move.toml)
  • No instances of ASCII encoding were found
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining UTF-8 encoding usage in binary data handling
rg -i "toString\('utf-?8'\)" --type ts

# Search for base64 encoding usage to verify consistency
rg -i "toString\('base64'\)" --type ts

# Look for potential Buffer.from operations that might need updating
rg "Buffer\.from\([^,]+,\s*['\"](utf-?8|ascii)['\"]" --type ts

Length of output: 912

test/build.spec.ts (1)

38-96: LGTM: Comprehensive test coverage for base64 encoding

The test cases properly validate the module bytes decoding with both 'dummy' and 'hihi' modules, ensuring the base64 encoding changes work correctly.

.github/workflows/test.yml Outdated Show resolved Hide resolved
@SeUkKim SeUkKim merged commit 2f690dd into main Dec 6, 2024
2 checks passed
@SeUkKim SeUkKim deleted the fix/bug-additionalNamedAddresses branch December 6, 2024 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants