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

feat: support .tg extension for NEAR #1484

Merged
merged 8 commits into from
Nov 7, 2024
Merged

feat: support .tg extension for NEAR #1484

merged 8 commits into from
Nov 7, 2024

Conversation

AdamREQ
Copy link
Contributor

@AdamREQ AdamREQ commented Nov 5, 2024

Description of the changes

Support .tg for NEAR: https://app.asana.com/0/1207673178190193/1208099463835050

Summary by CodeRabbit

  • New Features

    • Enhanced NEAR address validation to accept addresses ending with .tg in addition to .near.
  • Bug Fixes

    • Improved error handling for unsupported networks while validating addresses.
  • Tests

    • Added a new test case to verify functionality with .tg payment addresses in the payment network integration.
    • Introduced validation for a new valid Near account format (testaccount.tg) in the address validation tests.

Copy link
Contributor

coderabbitai bot commented Nov 5, 2024

Walkthrough

The changes involve an update to the isValidNearAddress function in the currency-utils.ts file. The modification enhances the regular expression used for validating NEAR addresses, allowing the function to recognize addresses that end with either .near or .tg. Additionally, new test cases have been introduced in the any-to-near.test.ts file to verify that the createCreationAction method and the applyActionToExtensions method correctly handle payment addresses with the .tg extension. A new valid Near account format, validNearTgAccount, has also been added to the test suite for Near address validation.

Changes

File Path Change Summary
packages/currency/src/currency-utils.ts Updated the regular expression in isValidNearAddress to accept .near and .tg addresses.
packages/advanced-logic/test/extensions/payment-network/any-to-near.test.ts Added new test cases for handling .tg payment addresses in createCreationAction and applyActionToExtensions.
packages/advanced-logic/test/utils/payment-network/any/generator-data-create.ts Added new constant extensionStateWithAnyToNativeTokenPaymentAndRefundTGExtension for testing with .tg payment address.
packages/currency/test/address-validation/near-validation.test.ts Introduced a new valid Near account format validNearTgAccount and added a test case for its validation.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CurrencyUtils

    User->>CurrencyUtils: Validate Address
    CurrencyUtils->>CurrencyUtils: Check format against regex
    alt Valid Address
        CurrencyUtils-->>User: Address is valid
    else Invalid Address
        CurrencyUtils-->>User: Address is invalid
    end
Loading

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>, 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
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: 2

🧹 Outside diff range comments (1)
packages/currency/src/currency-utils.ts (1)

Line range hint 3-6: Update function documentation to include .tg extension support.

The function documentation should be updated to explicitly mention support for both .near and .tg extensions when using the 'near' network.

 /**
  * Checks if a Near address is valid according to a currency network.
+ * For 'near' network, addresses must end with either .near or .tg
  * Returns true if the currency network is not given and the address is correct for any network.
  */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 61b9cc3 and a64e5a8.

📒 Files selected for processing (1)
  • packages/currency/src/currency-utils.ts (1 hunks)
🔇 Additional comments (1)
packages/currency/src/currency-utils.ts (1)

30-30: LGTM! Regex pattern correctly implements .tg support.

The updated regular expression properly validates addresses ending with either .near or .tg while maintaining the existing validation rules.

packages/currency/src/currency-utils.ts Outdated Show resolved Hide resolved
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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between a64e5a8 and 952f107.

📒 Files selected for processing (1)
  • packages/advanced-logic/test/extensions/payment-network/any-to-near.test.ts (1 hunks)

Copy link
Member

@alexandre-abrioux alexandre-abrioux left a comment

Choose a reason for hiding this comment

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

LGTM!

packages/currency/src/currency-utils.ts Outdated Show resolved Hide resolved
@AdamREQ AdamREQ requested review from yomarion and removed request for yomarion November 5, 2024 13:43
@AdamREQ AdamREQ enabled auto-merge (squash) November 7, 2024 12:35
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: 4

🧹 Outside diff range comments (1)
packages/currency/src/currency-utils.ts (1)

Line range hint 1-38: Update documentation to reflect .tg extension support.

Since this is a protocol-level change adding support for .tg extension:

  1. Update the function's JSDoc to mention both .near and .tg support
  2. Consider adding a link to documentation about .tg addresses in the comments

Apply this diff to enhance the documentation:

 /**
  * Checks if a Near address is valid according to a currency network.
  * Returns true if the currency network is not given and the address is correct for any network.
+ * 
+ * Supported formats for mainnet:
+ * - <account>.near
+ * - <account>.tg
+ * 
+ * Supported formats for testnet:
+ * - <account>.testnet
  */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 952f107 and 4d4b7f9.

📒 Files selected for processing (4)
  • packages/advanced-logic/test/extensions/payment-network/any-to-near.test.ts (2 hunks)
  • packages/advanced-logic/test/utils/payment-network/any/generator-data-create.ts (1 hunks)
  • packages/currency/src/currency-utils.ts (1 hunks)
  • packages/currency/test/address-validation/near-validation.test.ts (2 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/advanced-logic/test/extensions/payment-network/any-to-near.test.ts (1)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1484
File: packages/advanced-logic/test/extensions/payment-network/any-to-near.test.ts:0-0
Timestamp: 2024-11-06T14:48:18.698Z
Learning: In `packages/advanced-logic/test/extensions/payment-network/any-to-near.test.ts`, when the existing happy path tests are deemed sufficient, additional test cases may not be necessary.
🔇 Additional comments (4)
packages/currency/test/address-validation/near-validation.test.ts (2)

4-4: LGTM! Constant follows established naming convention.

The new constant validNearTgAccount is well-named and follows the existing pattern for test data.


Line range hint 1-24: Verify NEAR address format requirements.

Let's confirm that the test cases align with NEAR's official address format requirements.

✅ Verification successful

Let me search for the actual NEAR address validation implementation to understand the rules being enforced.


Let me try to find the actual implementation file since we only found test files. Let's search in the src directory.


Test cases correctly align with NEAR's address format requirements

The test cases in near-validation.test.ts accurately reflect NEAR's address format requirements as implemented in isValidNearAddress():

  • Hex format (64 characters): f336b7833496cdcae230463c3daff7b2fe187a93be8df5b1326ce7a595033163
  • Account format with valid TLDs (.near, .tg): testaccount.near, testaccount.tg
  • Invalid cases:
    • Bad TLD: testaccount.badnear
    • Invalid format with hex: f336b7833496cdcae230463c3daff7b2fe187a93be8df5b1326ce7a595033163.badnear

The implementation follows NEAR's specifications from:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for NEAR address format documentation or validation rules in the codebase
rg -i "near.*address.*format|near.*account.*format" --type ts

Length of output: 188


Script:

#!/bin/bash
# Find the implementation of isValidNearAddress function
ast-grep --pattern 'function isValidNearAddress($_) {
  $$$
}'

# Also search for any NEAR-related constants or regex patterns
rg -i "near.*pattern|near.*regex|near.*validation" --type ts

Length of output: 1547


Script:

#!/bin/bash
# Find the implementation file
fd "currency-utils.ts" --type f

# Once found, let's see its content
cat packages/currency/src/currency-utils.ts

Length of output: 2314

packages/advanced-logic/test/extensions/payment-network/any-to-near.test.ts (2)

8-8: LGTM! Import added for .tg extension test data.

The new import provides the necessary test data constant for validating .tg extension support.


312-327: LGTM! Test case correctly validates .tg extension support.

The test case follows the established pattern and effectively verifies that the payment network can handle .tg addresses. The test is focused, has clear assertions, and uses predefined test data for validation.

@AdamREQ AdamREQ merged commit 3df13d5 into master Nov 7, 2024
25 checks passed
@AdamREQ AdamREQ deleted the feat/support-tg-near branch November 7, 2024 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

4 participants