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(e2e): setup sui #3485

Merged
merged 9 commits into from
Feb 7, 2025
Merged

feat(e2e): setup sui #3485

merged 9 commits into from
Feb 7, 2025

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Feb 5, 2025

TODO:

  • add make target and e2e job in matrix
  • fund deployer account via faucet
  • connect to sui local validator in e2e tests
  • deploy contract from e2e side
  • store contract address in config

This can be merged if/when someone else want's to take over this process. Just let me know and I'll hand it over.

Signer and publish logic derived from protocol-contracts-sui with some refactoring and improved test coverage.

Update: I think this is a good start and first PR, I think we should do the rest in separate PRs

Notes:

  • There aren't any good Sui golang client libraries that fully support secp256k1, so you have to do the work yourself :/

Related to #3318 and #3474 and #3465

Summary by CodeRabbit

  • New Features

    • Integrated Sui blockchain support with conditional test execution based on pull request labels and event types.
    • Introduced a new command-line flag and Makefile target to initiate Sui-specific tests and setup, streamlining local testing workflows.
    • Enabled Sui gateway deployment with encoded binary assets for smoother operations.
  • Tests

    • Added tests to validate Sui cryptographic functions and address generation, ensuring reliable integration.
  • Chores

    • Updated dependencies to include the Sui SDK and related libraries.

@gartnera gartnera added no-changelog Skip changelog CI check SUI_TESTS Run make start-sui-tests labels Feb 5, 2025
Copy link
Contributor

coderabbitai bot commented Feb 5, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This pull request integrates SUI blockchain testing into the end-to-end test framework. It updates the GitHub workflow by adding a new output variable (SUI_TESTS) and conditional logic, and extends the Makefile with a new start-sui-test target. Configuration files and client initialization are updated to include SUI endpoints and clients. Additionally, new command-line flags, cryptographic utilities (including a Sui signer), gateway deployment functionality, and corresponding tests are introduced. The module file is also updated with relevant dependencies, ensuring that SUI-specific tests are executed conditionally based on PR labels and configuration settings.

Changes

File(s) Change Summary
.github/workflows/e2e.yml, Makefile Introduced new output variable SUI_TESTS in the e2e workflow and added the start-sui-test make target to trigger SUI tests conditionally.
cmd/zetae2e/config/clients.go, cmd/zetae2e/config/localnet.yml, cmd/zetae2e/local/local.go Added SUI client initialization, new configuration entries for SUI RPC endpoints, and a CLI flag (flagTestSui) to control SUI test execution.
e2e/config/config.go, e2e/runner/clients.go, e2e/runner/setup_sui.go Extended configuration and runner modules with SUI-specific methods and fields, including a new SetupSui method for deploying the SUI gateway.
e2e/utils/sui/gateway.go, e2e/utils/sui/signer.go, e2e/utils/sui/signer_test.go Introduced a new SUI package comprising utilities for embedding and encoding the gateway binary, a Secp256k1 signer implementation for SUI, and tests validating the signer functionality.
go.mod Added new dependencies (sui-go-sdk and several Go Playground libraries) and updated the secp256k1 dependency from an indirect to a direct requirement.

Sequence Diagram(s)

sequenceDiagram
    participant GH as GitHub Actions
    participant MF as Makefile (start-sui-test)
    participant Runner as E2E Runner
    participant Setup as SetupSui
    participant SuiNet as Sui Network

    GH->>GH: Evaluate PR labels (SUI_TESTS)
    GH->>MF: Trigger start-sui-test target
    MF->>Runner: Execute SUI test command
    Runner->>Setup: Call SetupSui(faucetURL)
    Setup->>Setup: Retrieve deployer signer & prepare transaction
    Setup->>SuiNet: Request SUI tokens and publish gateway module
    SuiNet-->>Setup: Return transaction response
    Setup-->>Runner: Complete SUI gateway setup
Loading

Possibly related PRs

Suggested labels

SOLANA_TESTS, UPGRADE_TESTS

Suggested reviewers

  • fbac
  • kingpinXD
  • ws4charlie
  • lumtis
  • skosito
  • swift1337

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@github-actions github-actions bot added the ci Changes to CI pipeline or github actions label Feb 5, 2025
Copy link

codecov bot commented Feb 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.42%. Comparing base (5cda985) to head (ad29cdf).
Report is 8 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3485      +/-   ##
===========================================
+ Coverage    65.29%   65.42%   +0.13%     
===========================================
  Files          441      442       +1     
  Lines        30425    30525     +100     
===========================================
+ Hits         19865    19970     +105     
+ Misses        9704     9700       -4     
+ Partials       856      855       -1     

see 7 files with indirect coverage changes

@gartnera gartnera marked this pull request as ready for review February 6, 2025 16:04
@gartnera gartnera requested review from a team as code owners February 6, 2025 16:04
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: 6

🧹 Nitpick comments (3)
e2e/utils/sui/signer.go (1)

61-79: Simplify public key retrieval using built-in serialization methods

The GetPublicKey method manually constructs the compressed public key. Utilize the SerializeCompressed method provided by the secp256k1 library for cleaner and more reliable code.

Refactor the method as follows:

 func (s *SignerSecp256k1) GetPublicKey() []byte {
-    pub := s.privkey.Public().(*ecdsa.PublicKey)
-
-    // Create compressed public key format:
-    // 0x02/0x03 | x-coordinate (32 bytes)
-    x := pub.X.Bytes()
-
-    // Ensure x coordinate is 32 bytes with leading zeros if needed
-    paddedX := make([]byte, 32)
-    copy(paddedX[32-len(x):], x)
-
-    // Prefix with 0x02 for even Y or 0x03 for odd Y
-    prefix := byte(0x02)
-    if pub.Y.Bit(0) == 1 {
-        prefix = 0x03
-    }
-
-    return append([]byte{prefix}, paddedX...)
+    secpPubKey := secp256k1.PublicKey{
+        Curve: secp256k1.S256(),
+        X:     s.privkey.PublicKey.X,
+        Y:     s.privkey.PublicKey.Y,
+    }
+    return secpPubKey.SerializeCompressed()
 }
e2e/utils/sui/signer_test.go (1)

51-54: Consider extracting test vector to a constant.

The base64-encoded public key string should be declared as a constant with the other test vectors at the top of the file.

e2e/config/config.go (1)

405-413: Improve method documentation and error handling.

The SuiSigner method could benefit from better documentation and error handling:

Apply this diff to enhance the implementation:

-// SuiAddress derives the blake2b hash from the private key
+// SuiSigner creates a new Sui signer from the account's private key.
+// Returns a SignerSecp256k1 instance that can be used for Sui blockchain operations.
 func (a Account) SuiSigner() (*sui_utils.SignerSecp256k1, error) {
 	privateKeyBytes, err := hex.DecodeString(a.RawPrivateKey.String())
 	if err != nil {
-		return nil, fmt.Errorf("decode private key: %w", err)
+		return nil, fmt.Errorf("failed to decode Sui private key from hex: %w", err)
 	}
 	signer := sui_utils.NewSignerSecp256k1FromSecretKey(privateKeyBytes)
 	return signer, nil
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 304c4d7 and 47aa5b4.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (12)
  • .github/workflows/e2e.yml (6 hunks)
  • Makefile (1 hunks)
  • cmd/zetae2e/config/clients.go (3 hunks)
  • cmd/zetae2e/config/localnet.yml (1 hunks)
  • cmd/zetae2e/local/local.go (4 hunks)
  • e2e/config/config.go (4 hunks)
  • e2e/runner/clients.go (2 hunks)
  • e2e/runner/setup_sui.go (1 hunks)
  • e2e/utils/sui/gateway.go (1 hunks)
  • e2e/utils/sui/signer.go (1 hunks)
  • e2e/utils/sui/signer_test.go (1 hunks)
  • go.mod (4 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.

  • e2e/runner/clients.go
  • e2e/utils/sui/gateway.go
  • cmd/zetae2e/config/clients.go
  • cmd/zetae2e/local/local.go
  • e2e/runner/setup_sui.go
  • e2e/config/config.go
  • e2e/utils/sui/signer.go
  • e2e/utils/sui/signer_test.go
🔇 Additional comments (17)
e2e/utils/sui/gateway.go (1)

1-15: Confirm appropriate use of embedded binary for contract deployment

Embedding the gateway.mv binary directly in the code is acceptable for small binaries, but it can increase the binary size and complicate version management. Consider whether this approach aligns with your deployment and maintenance strategies.

Ensure that embedding the binary is the optimal solution. Alternatively, you might load the binary from an external file or use a build process to manage it.

e2e/runner/clients.go (1)

7-7: LGTM! Clean integration of Sui client.

The addition of the Sui client interface is well-structured and follows the existing pattern in the Clients struct.

Also applies to: 29-29

cmd/zetae2e/config/clients.go (1)

55-58: LGTM! Well-structured client initialization.

The Sui client initialization follows the established pattern and properly handles the optional nature of the Sui RPC configuration.

Also applies to: 75-75

e2e/config/config.go (1)

105-106: LGTM! Well-structured RPC configuration.

The addition of Sui RPC fields follows the existing pattern and maintains consistency with other chain configurations.

cmd/zetae2e/local/local.go (3)

39-39: LGTM!

The flag declaration follows the established pattern and naming convention.


109-109: LGTM!

The flag retrieval is consistent with other test flags and uses the must helper correctly.


200-202: LGTM!

The Sui setup logic is correctly guarded by the test flag and skip condition, following the established pattern for blockchain setups.

cmd/zetae2e/config/localnet.yml (1)

108-109: LGTM!

The Sui RPC endpoints are correctly configured using Docker service names and standard ports.

.github/workflows/e2e.yml (4)

124-124: LGTM!

The SUI_TESTS output variable follows the established pattern for test outputs.


158-158: LGTM!

The Sui test label handling is consistent with other test labels.


190-190: LGTM!

The Sui test handling for release branches follows the established pattern.


273-275: LGTM!

The matrix entry for Sui tests is correctly configured and follows the established pattern.

Makefile (1)

315-318: LGTM!

The Sui test target is correctly configured:

  • Follows the established pattern of other test targets
  • Sets appropriate E2E_ARGS
  • Uses the correct Docker Compose profile
go.mod (4)

122-122: Direct Dependency Activation for secp256k1/v4
The update on this line converts github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 from an indirect to a direct dependency. This change makes the version explicit, which aids in troubleshooting and ensures version stability for cryptographic operations.


307-307: New Sui SDK Dependency Addition
The inclusion of github.com/block-vision/sui-go-sdk v1.0.6 supports the PR’s objective to integrate Sui blockchain testing into the e2e framework. Please ensure that its initialization and associated configurations are properly integrated in the relevant client and configuration modules.


337-339: Introduction of Go-Playground Libraries for Validation and Translation
The addition of github.com/go-playground/locales v0.14.1, github.com/go-playground/universal-translator v0.18.1, and github.com/go-playground/validator/v10 v10.12.0 expands the module's capability for advanced data validation and localization. Verify that these dependencies are consistently used throughout the configuration or input handling logic to meet the PR’s end-to-end testing requirements.


351-351: Addition of go-urn Library
The new dependency github.com/leodido/go-urn v1.2.2 is introduced to support URN parsing or manipulation functionalities. Please confirm that this package is utilized where required in the Sui integration or other related areas.

Copy link
Contributor

@ws4charlie ws4charlie left a comment

Choose a reason for hiding this comment

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

looks good overall.

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.

utACK

@gartnera gartnera added this pull request to the merge queue Feb 7, 2025
Merged via the queue into develop with commit 97c82cc Feb 7, 2025
45 checks passed
@gartnera gartnera deleted the sui-e2e branch February 7, 2025 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking:cli ci Changes to CI pipeline or github actions no-changelog Skip changelog CI check SUI_TESTS Run make start-sui-tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants