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 Solana wallet address in zetacore for SOL withdrawals #2518

Merged
merged 5 commits into from
Jul 22, 2024

Conversation

ws4charlie
Copy link
Contributor

@ws4charlie ws4charlie commented Jul 19, 2024

Description

  • Add support for Solana address in zetacored

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

  • New Features
    • Added support for Solana addresses, enhancing interoperability with the Solana blockchain.
    • Introduced a new function for decoding Solana wallet addresses.
  • Bug Fixes
    • Improved error handling for invalid Solana addresses.
  • Tests
    • Added extensive test cases for decoding and validating Solana wallet addresses.
    • Updated existing tests for better clarity and maintainability.
  • Chores
    • Updated changelog to reflect the new features and improvements.

Copy link
Contributor

coderabbitai bot commented Jul 19, 2024

Walkthrough

This update enhances the Zetacore by adding support for Solana wallet addresses, improving interoperability with the Solana blockchain. Key changes include new decoding functions, expanded test coverage, and refined handling of blockchain consensus types. These updates strengthen the system's capabilities and ensure robust address validation across various blockchain platforms.

Changes

Files Change Summary
changelog.md New entry for PR 2518 documenting support for Solana addresses in Zetacore.
pkg/chains/address.go Added DecodeSolanaWalletAddress function for decoding Solana wallet addresses from Base58 strings.
pkg/chains/address_test.go Introduced Test_DecodeSolanaWalletAddress with various test cases for validating address decoding.
pkg/chains/chain.go Modified EncodeAddress method for new consensus type Consensus_solana_consensus and improved error handling; changed IsBitcoinChain to use network-based checks.
pkg/chains/chain_test.go Updated test setup using constants for chains and added tests for validating Solana addresses.
x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go Added Network field to Chain struct in the TestKeeper_CheckMigration function for clarity.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Chain
    participant AddressDecoder

    User->>Chain: Request address encoding
    Chain->>AddressDecoder: Decode address
    AddressDecoder-->>Chain: Return decoded public key
    Chain-->>User: Return encoded address or error
Loading

🐰 In the Zeta fields I hop and play,
With Solana's friends, we'll pave the way!
New addresses decoded with glee,
A blockchain world, so wild and free!
Hoppin' and boppin' through code so bright,
Celebrating changes that feel just right!
🌟


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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 129c99b and 0a6d047.

Files selected for processing (5)
  • changelog.md (1 hunks)
  • pkg/chains/address.go (2 hunks)
  • pkg/chains/address_test.go (1 hunks)
  • pkg/chains/chain.go (3 hunks)
  • pkg/chains/chain_test.go (3 hunks)
Additional context used
Path-based instructions (4)
pkg/chains/address.go (1)

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

pkg/chains/chain.go (1)

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

pkg/chains/chain_test.go (1)

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

pkg/chains/address_test.go (1)

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

Additional comments not posted (10)
pkg/chains/address.go (1)

91-105: LGTM! Ensure robust error handling.

The function DecodeSolanaWalletAddress is well-implemented with proper error handling for invalid Base58 encoding and checks for the Ed25519 curve.

However, ensure that all potential edge cases are covered in the tests.

pkg/chains/chain.go (2)

Line range hint 55-83:
LGTM! Verify the correctness of the new case.

The new case for Consensus_solana_consensus in the EncodeAddress method is well-implemented and improves readability and maintainability.

However, ensure that the new case is thoroughly tested to verify its correctness.


122-122: LGTM! Verify the correctness of the updated logic.

The update to use ChainListByNetwork in the IsBitcoinChain function aligns the logic with the new network-based approach and improves the structure and clarity of the code.

However, ensure that the updated logic is thoroughly tested to verify its correctness.

pkg/chains/chain_test.go (5)

150-176: LGTM! Verify the correctness and coverage of the new test cases for Solana addresses.

The new test cases for Solana addresses in the EncodeAddress method are well-implemented and improve the clarity and specificity of the tests.

However, ensure that the new test cases cover all potential edge cases and verify the correctness of the implementation.


298-303: LGTM! Verify the correctness and coverage of the new test cases for Solana addresses.

The new test cases for Solana addresses in the DecodeAddressFromChainID method are well-implemented and improve the clarity and specificity of the tests.

However, ensure that the new test cases cover all potential edge cases and verify the correctness of the implementation.


Line range hint 250-263:
LGTM! Verify the correctness and coverage of the new test cases for Ethereum networks.

The new test cases for Ethereum networks in the IsEVMChain method are well-implemented and improve the clarity and specificity of the tests.

However, ensure that the new test cases cover all potential edge cases and verify the correctness of the implementation.


Line range hint 270-283:
LGTM! Verify the correctness and coverage of the new test cases for Bitcoin networks.

The new test cases for Bitcoin networks in the IsBitcoinChain method are well-implemented and improve the clarity and specificity of the tests.

However, ensure that the new test cases cover all potential edge cases and verify the correctness of the implementation.


Line range hint 290-303:
LGTM! Verify the correctness and coverage of the new test cases for ZetaChain networks.

The new test cases for ZetaChain networks in the IsZetaChain method are well-implemented and improve the clarity and specificity of the tests.

However, ensure that the new test cases cover all potential edge cases and verify the correctness of the implementation.

pkg/chains/address_test.go (1)

101-151: LGTM! Ensure DecodeSolanaWalletAddress function is implemented correctly.

The new test function Test_DecodeSolanaWalletAddress is well-structured and covers various scenarios for decoding Solana wallet addresses.

However, ensure that the DecodeSolanaWalletAddress function is correctly implemented and handles all edge cases.

Verification successful

The DecodeSolanaWalletAddress function is implemented correctly.

The function decodes a Base58 encoded address and checks if it is on the ed25519 curve, handling all the edge cases mentioned in the test cases. The implementation aligns with the test scenarios provided in the Test_DecodeSolanaWalletAddress function.

  • pkg/chains/address.go: DecodeSolanaWalletAddress
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `DecodeSolanaWalletAddress` function.

# Test: Search for the function implementation. Expect: Correct handling of all edge cases.
ast-grep --lang go --pattern $'func DecodeSolanaWalletAddress($_) ($_, error) {
  $$$
}'

Length of output: 89


Script:

#!/bin/bash
# Description: Search for the function name `DecodeSolanaWalletAddress` in the codebase to locate its implementation.

# Search for the function definition
rg "func DecodeSolanaWalletAddress" -A 10

Length of output: 838


Script:

#!/bin/bash
# Description: Retrieve the complete implementation of `DecodeSolanaWalletAddress` function.

# Search for the complete function implementation
rg "func DecodeSolanaWalletAddress" -A 20

Length of output: 1285

changelog.md (1)

35-35: Changelog entry is accurate and complete.

The new entry for pull request 2518 accurately describes the addition of support for Solana addresses in the Zetacore.

@lumtis
Copy link
Member

lumtis commented Jul 22, 2024

@ws4charlie looks like there is a failure in unit tests

Copy link
Contributor

@swift1337 swift1337 left a comment

Choose a reason for hiding this comment

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

LGTM. left some minor comments.

pkg/chains/address.go Show resolved Hide resolved
pkg/chains/address.go Outdated Show resolved Hide resolved
pkg/chains/address_test.go Outdated Show resolved Hide resolved
pkg/chains/chain.go 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: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0a6d047 and 7800034.

Files selected for processing (3)
  • pkg/chains/address.go (2 hunks)
  • pkg/chains/address_test.go (1 hunks)
  • pkg/chains/chain.go (3 hunks)
Files skipped from review as they are similar to previous changes (3)
  • pkg/chains/address.go
  • pkg/chains/address_test.go
  • pkg/chains/chain.go

Copy link

codecov bot commented Jul 22, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.

Project coverage is 46.53%. Comparing base (129c99b) to head (32ac60a).
Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2518      +/-   ##
===========================================
+ Coverage    46.50%   46.53%   +0.02%     
===========================================
  Files          456      456              
  Lines        30282    30296      +14     
===========================================
+ Hits         14083    14098      +15     
+ Misses       15372    15371       -1     
  Partials       827      827              
Files Coverage Δ
pkg/chains/address.go 94.33% <100.00%> (+0.86%) ⬆️
pkg/chains/chain.go 94.00% <81.81%> (+1.52%) ⬆️

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.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7800034 and 32ac60a.

Files selected for processing (1)
  • x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go (1 hunks)
Additional context used
Path-based instructions (1)
x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go (1)

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

Additional comments not posted (15)
x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go (15)

Line range hint 12-56:
LGTM!

The test case "successfully validate inbound" is well-structured and correctly sets up mock data, configures mocks, and verifies the expected outcomes.


Line range hint 58-86:
LGTM!

The test case "fail if tss not found" is well-structured and correctly sets up mock data, configures mocks, and verifies the expected outcomes.


Line range hint 88-118:
LGTM!

The test case "fail if InitiateOutbound fails" is well-structured and correctly sets up mock data, configures mocks, and verifies the expected outcomes.


Line range hint 120-151:
LGTM!

The test case "does not set cctx if SetCctxAndNonceToCctxAndInboundHashToCctx fails" is well-structured and correctly sets up mock data, configures mocks, and verifies the expected outcomes.


Line range hint 153-183:
LGTM!

The test case "fail if inbound is disabled" is well-structured and correctly sets up mock data, configures mocks, and verifies the expected outcomes.


Line range hint 185-216:
LGTM!

The test case "fails when CheckIfTSSMigrationTransfer fails" is well-structured and correctly sets up mock data, configures mocks, and verifies the expected outcomes.


Line range hint 218-239:
LGTM!

The test case "Do not return error if sender is not a TSS address for evm chain" is well-structured and correctly sets up mock data, configures mocks, and verifies the expected outcomes.


Line range hint 241-262:
LGTM!

The test case "Do not return error if sender is not a TSS address for btc chain" is well-structured and correctly sets up mock data, configures mocks, and verifies the expected outcomes.


Line range hint 264-285:
LGTM!

The test case "fails when chain is not supported" is well-structured and correctly sets up mock data, configures mocks, and verifies the expected outcomes.


Line range hint 287-308:
LGTM!

The test case "skips check when an older tss address is invalid for bitcoin chain" is well-structured and correctly sets up mock data, configures mocks, and verifies the expected outcomes.


Line range hint 310-331:
LGTM!

The test case "skips check when an older tss address is invalid for evm chain" is well-structured and correctly sets up mock data, configures mocks, and verifies the expected outcomes.


Line range hint 333-359:
LGTM!

The test case "fails when sender is a TSS address for evm chain for evm chain" is well-structured and correctly sets up mock data, configures mocks, and verifies the expected outcomes.


Line range hint 361-391:
LGTM!

The test case "fails when sender is a TSS address for btc chain for btc chain" is well-structured and correctly sets up mock data, configures mocks, and verifies the expected outcomes.


Line range hint 393-414:
LGTM!

The test case "fails if bitcoin network params not found for BTC chain" is well-structured and correctly sets up mock data, configures mocks, and verifies the expected outcomes. The addition of the Network field to the Chain struct instantiation is appropriate and enhances the test case.

Also applies to: 626-633


Line range hint 635-655:
LGTM!

The test case "fails if gateway is not observer" is well-structured and correctly sets up mock data, configures mocks, and verifies the expected outcomes.

@lumtis lumtis added this pull request to the merge queue Jul 22, 2024
Merged via the queue into develop with commit e730d3a Jul 22, 2024
30 checks passed
@lumtis lumtis deleted the zetacore-change-for-solana branch July 22, 2024 17:16
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.

3 participants