Skip to content

test: add E2E tests for Sui fungible token withdrawAndCall#3831

Merged
ws4charlie merged 7 commits intodevelopfrom
e2e-sui-token-withdraw-and-call
Apr 28, 2025
Merged

test: add E2E tests for Sui fungible token withdrawAndCall#3831
ws4charlie merged 7 commits intodevelopfrom
e2e-sui-token-withdraw-and-call

Conversation

@ws4charlie
Copy link
Contributor

@ws4charlie ws4charlie commented Apr 25, 2025

Description

Added E2E tests:

  • sui_token_withdraw_and_call
  • sui_token_withdraw_and_call_revert_with_call

Closes: #3742

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 end-to-end tests for withdrawing fungible tokens on Sui and invoking contract calls, including scenarios where the call reverts and triggers a revert handler.
  • Bug Fixes
    • Improved handling of pool object types in Sui deployment and contract interactions to prevent type mismatches.
  • Tests
    • Introduced new test cases for Sui token withdraw-and-call operations, including revert scenarios, to enhance test coverage and reliability.
  • Documentation
    • Updated changelog to reflect new test coverage for Sui fungible token withdraw and call functionality.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 25, 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 update introduces comprehensive end-to-end (E2E) tests for the Sui blockchain's withdraw-and-call functionality, covering both native SUI and fungible token scenarios, including revert handling. The changes add new E2E test cases, supporting test logic, and utility methods for payload construction and transaction execution. Adjustments are made to the Move contract to work around type mismatches, and related configuration and deployment scripts are updated to reflect the removal of the pool object. The test runner is enhanced to support the new test flows, and documentation is updated to reflect the additions.

Changes

File(s) Change Summary
e2e/e2etests/test_sui_token_withdraw_and_call.go,
e2e/e2etests/test_sui_token_withdraw_and_call_revert_with_call.go
Added two new E2E test functions: one for Sui fungible token withdraw-and-call, and one for handling revert scenarios with a callback.
e2e/e2etests/e2etests.go,
cmd/zetae2e/local/local.go
Registered the new test cases and updated the list/order of Sui-related E2E tests. Added constants for new test names and included them in the test suite.
e2e/runner/sui.go Introduced two new methods: one to execute withdraw-and-call for fungible tokens, and another to generate the required call payload for the example contract.
e2e/e2etests/test_sui_withdraw_and_call.go,
e2e/e2etests/test_sui_withdraw_and_call_revert_with_call.go
Refactored payload construction to use the new utility method; simplified and clarified test logic. Removed manual payload assembly and hardcoded addresses.
e2e/contracts/sui/example/sources/example.move Modified the on_call function by removing the generic TARGET_COIN parameter and commenting out the pool parameter to address type mismatch issues, allowing tests to proceed.
e2e/config/config.go,
e2e/runner/setup_sui.go
Removed the PoolID field from the Sui example configuration and deployment logic; eliminated handling of the pool object type.
e2e/contracts/sui/example/Makefile Changed the destination of built bytecode module files to one directory up, aligning with updated deployment or testing requirements.
changelog.md Added an entry documenting the addition of E2E tests for Sui fungible token withdraw-and-call functionality.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner as E2ERunner
    participant SuiGateway as GatewayZEVM
    participant SuiContract as ExampleContract
    participant ZEVM as ZEVM

    TestRunner->>SuiGateway: SuiWithdrawAndCallFungibleToken(receiver, amount, payload, revertOptions)
    SuiGateway->>SuiContract: withdraw_and_call(payload)
    alt Success
        SuiContract-->>SuiGateway: on_call executed
        SuiGateway-->>TestRunner: Transaction receipt (mined)
        TestRunner->>ZEVM: Verify balance and call count
    else Revert
        SuiGateway-->>ZEVM: onRevert callback (with revert payload)
        ZEVM-->>TestRunner: Verify revert, refund, and callback
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Implement Sui contract with on_call (inspired by suizeta.move) and add E2E tests for:
- SUI withdrawAndCall
- SUI withdrawAndCallRevert
- Sui fungible token withdrawAndCall
- Sui fungible token withdrawAndCallRevert (#3742)

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@github-actions
Copy link

!!!WARNING!!!
nosec detected in the following files: e2e/e2etests/e2etests.go

Be very careful about using #nosec in code. It can be a quick way to suppress security warnings and move forward with development, it should be employed with caution. Suppressing warnings with #nosec can hide potentially serious vulnerabilities. Only use #nosec when you're absolutely certain that the security issue is either a false positive or has been mitigated in another way.

Only suppress a single rule (or a specific set of rules) within a section of code, while continuing to scan for other problems. To do this, you can list the rule(s) to be suppressed within the #nosec annotation, e.g: /* #nosec G401 */ or //#nosec G201 G202 G203
Broad #nosec annotations should be avoided, as they can hide other vulnerabilities. The CI will block you from merging this PR until you remove #nosec annotations that do not target specific rules.

Pay extra attention to the way #nosec is being used in the files listed above.

@github-actions github-actions bot added the nosec label Apr 25, 2025
@ws4charlie ws4charlie marked this pull request as ready for review April 25, 2025 22:55
@ws4charlie ws4charlie requested a review from a team as a code owner April 25, 2025 22:55
@ws4charlie ws4charlie added test Tests related SUI_TESTS Run make start-sui-tests chain:sui zetaclient Issues related to ZetaClient labels Apr 25, 2025
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

🧹 Nitpick comments (3)
e2e/contracts/sui/example/sources/example.move (1)

46-57: Appropriate function signature simplification

The removal of the TARGET_COIN generic parameter and the commented pool parameter is a suitable approach to resolve type mismatches during testing. The added comments provide good context for future maintainers.

However, consider adding a TODO to restore this functionality in production code if this is a temporary test-only workaround.

// Note: this pool type is hardcoded as <SUI, TOKEN> and therefore causes type mismatch error in the
// fungible token withdrawAndCall test, where the SOURCE_COIN type is FAKE_USDC instead of TOKEN.
// Disabling the pool object for now is the easiest solution to allow the E2E tests to go through.
+// TODO: Consider a more robust solution for production code that supports different coin types.
// _pool: &mut Pool<SOURCE_COIN, TARGET_COIN>,
e2e/runner/sui.go (1)

241-259: Well-designed payload creation helper

The implementation centralizes payload creation logic, which improves maintainability. The method handles the hex decoding of addresses properly and follows a clear error handling pattern.

Consider adding a validation check for the suiAddress parameter to ensure it starts with "0x" before attempting to remove the prefix.

// SuiCreateExampleWACPayload creates a payload for on_call function in Sui the example package
// The example on_call function will just forward the withdrawn token to given 'suiAddress'
func (r *E2ERunner) SuiCreateExampleWACPayload(suiAddress string) (sui.CallPayload, error) {
+	// Validate the address format
+	if !strings.HasPrefix(suiAddress, "0x") {
+		return sui.CallPayload{}, fmt.Errorf("invalid Sui address format: missing 0x prefix")
+	}

	// only the CCTX's coinType is needed, no additional arguments
	argumentTypes := []string{}
	objects := []string{
		r.SuiExample.GlobalConfigID.String(),
		r.SuiExample.PartnerID.String(),
		r.SuiExample.ClockID.String(),
	}

	// create the payload message from the sui address
	message, err := hex.DecodeString(suiAddress[2:]) // remove 0x prefix
	if err != nil {
		return sui.CallPayload{}, err
	}

	return sui.NewCallPayload(argumentTypes, objects, message), nil
}
e2e/e2etests/test_sui_token_withdraw_and_call_revert_with_call.go (1)

27-29: Consider making the invalid address generation more explicit.

The hardcoded invalid address works for the test, but it might be clearer to use a function or constant with a more descriptive name to indicate why this address is invalid (e.g., too short, invalid format).

-	invalidAddress := "8f569597ebca884b784d32678a6f"
+	// Use an address that's too short to be valid in Sui
+	invalidAddress := "8f569597ebca884b784d32678a6f" // Invalid: insufficient length
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 835341d and f629d8a.

⛔ Files ignored due to path filters (1)
  • e2e/contracts/sui/example/Move.lock is excluded by !**/*.lock
📒 Files selected for processing (12)
  • changelog.md (1 hunks)
  • cmd/zetae2e/local/local.go (1 hunks)
  • e2e/config/config.go (0 hunks)
  • e2e/contracts/sui/example/Makefile (1 hunks)
  • e2e/contracts/sui/example/sources/example.move (1 hunks)
  • e2e/e2etests/e2etests.go (2 hunks)
  • e2e/e2etests/test_sui_token_withdraw_and_call.go (1 hunks)
  • e2e/e2etests/test_sui_token_withdraw_and_call_revert_with_call.go (1 hunks)
  • e2e/e2etests/test_sui_withdraw_and_call.go (2 hunks)
  • e2e/e2etests/test_sui_withdraw_and_call_revert_with_call.go (2 hunks)
  • e2e/runner/setup_sui.go (1 hunks)
  • e2e/runner/sui.go (2 hunks)
💤 Files with no reviewable changes (1)
  • e2e/config/config.go
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

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

  • e2e/runner/setup_sui.go
  • cmd/zetae2e/local/local.go
  • e2e/e2etests/test_sui_withdraw_and_call.go
  • e2e/e2etests/test_sui_withdraw_and_call_revert_with_call.go
  • e2e/e2etests/test_sui_token_withdraw_and_call_revert_with_call.go
  • e2e/e2etests/test_sui_token_withdraw_and_call.go
  • e2e/runner/sui.go
  • e2e/e2etests/e2etests.go
🧬 Code Graph Analysis (2)
cmd/zetae2e/local/local.go (1)
e2e/e2etests/e2etests.go (5)
  • TestSuiWithdrawRevertWithCallName (109-109)
  • TestSuiWithdrawAndCallRevertWithCallName (110-110)
  • TestSuiTokenWithdrawName (105-105)
  • TestSuiTokenWithdrawAndCallName (106-106)
  • TestSuiTokenWithdrawAndCallRevertWithCallName (107-107)
e2e/e2etests/e2etests.go (3)
e2e/runner/e2etest.go (3)
  • NewE2ETest (30-47)
  • ArgDefinition (50-53)
  • WithMinimumVersion (13-17)
e2e/e2etests/test_sui_token_withdraw_and_call.go (1)
  • TestSuiTokenWithdrawAndCall (14-62)
e2e/e2etests/test_sui_token_withdraw_and_call_revert_with_call.go (1)
  • TestSuiTokenWithdrawAndCallRevertWithCall (18-80)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: start-e2e-test / e2e
🔇 Additional comments (15)
changelog.md (1)

43-44: Documentation update for PR #3831 looks good.

The addition to the changelog properly documents the new E2E tests for Sui fungible token withdraw and call functionality, providing clear information about what was added.

e2e/contracts/sui/example/Makefile (1)

13-14: Build output destination path modified appropriately.

The destination paths for bytecode modules have been changed to copy files one directory up (../) instead of the current directory. This change aligns with the new test structure and ensures the compiled modules are accessible where needed by the Sui fungible token tests.

e2e/runner/setup_sui.go (2)

152-152: Removed pool parameter to simplify test structure.

The removal of the pool filter from objectTypeFilters aligns with the modifications to the Move contract where the pool parameter was commented out in the on_call function. This simplification helps avoid type mismatches in tests and streamlines the test setup.


168-174: Properly updated SuiExample struct initialization.

The PoolID field has been removed from the SuiExample struct initialization, maintaining consistency with the changes to the Move contract and the corresponding removal in e2e/config/config.go. This ensures a cohesive implementation across the codebase.

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

525-529: Test order rearranged and new tests added for Sui fungible token.

The changes accomplish two things:

  1. Reorder existing Sui tests for better logical flow
  2. Add the new tests for Sui fungible token withdraw-and-call functionality:
    • TestSuiTokenWithdrawAndCallName
    • TestSuiTokenWithdrawAndCallRevertWithCallName

These additions complete the test coverage for Sui fungible token operations, ensuring both success and revert cases are properly tested.

e2e/e2etests/test_sui_withdraw_and_call_revert_with_call.go (2)

15-15: LGTM: Clear test documentation added

The added comment clearly explains the purpose of this test function, which enhances code readability and maintenance.


26-28: Improved code maintainability

Good refactoring to use the centralized helper method for payload creation rather than manual construction. This promotes code reuse and consistency across tests.

e2e/e2etests/test_sui_withdraw_and_call.go (2)

22-26: Improved test robustness with dynamic address retrieval

Excellent change to use a dynamically retrieved signer address instead of hardcoded values. This approach is more flexible and prevents potential issues if the test environment changes.


31-33: Enhanced maintainability with shared payload creation logic

Good use of the helper method for payload creation. This promotes consistency and reduces code duplication across tests.

e2e/runner/sui.go (1)

120-148: Well-implemented fungible token withdraw-and-call operation

This implementation properly parallels the existing SUI token functionality but for fungible tokens. The method follows the established pattern with consistent error handling and validation.

e2e/e2etests/test_sui_token_withdraw_and_call.go (1)

1-62: Test logic is well-structured and follows best practices.

The end-to-end test for Sui fungible token withdraw-and-call functionality follows a clear arrange-act-assert pattern, with appropriate error handling and comprehensive assertions. The test properly verifies both the transaction status and side effects (balance change and call count increment).

e2e/e2etests/test_sui_token_withdraw_and_call_revert_with_call.go (2)

15-18: Good documentation of test purpose and behavior.

The comment clearly explains the test's purpose and expected behavior, which enhances maintainability.


18-80: Test comprehensively verifies revert behavior and token refund.

The test thoroughly checks all aspects of the revert flow: transaction status, callback execution, sender verification, and token refund to the dApp address.

e2e/e2etests/e2etests.go (2)

106-107: New test constants follow consistent naming convention.

The test constants for Sui fungible token withdraw-and-call functionality follow the established naming pattern in the codebase.


907-924: New test registrations are properly configured.

The test registrations include appropriate descriptions, argument definitions, and version requirements (v30.0.0) consistent with other tests in the suite.

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!

@ws4charlie ws4charlie enabled auto-merge April 28, 2025 21:04
Copy link
Member

@kingpinXD kingpinXD left a comment

Choose a reason for hiding this comment

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

Lgtm

@ws4charlie ws4charlie added this pull request to the merge queue Apr 28, 2025
@ws4charlie ws4charlie removed this pull request from the merge queue due to a manual request Apr 28, 2025
@ws4charlie ws4charlie enabled auto-merge April 28, 2025 21:34
@ws4charlie ws4charlie added this pull request to the merge queue Apr 28, 2025
Merged via the queue into develop with commit 4c51775 Apr 28, 2025
47 checks passed
@ws4charlie ws4charlie deleted the e2e-sui-token-withdraw-and-call branch April 28, 2025 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking:cli chain:sui nosec SUI_TESTS Run make start-sui-tests test Tests related zetaclient Issues related to ZetaClient

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sui withdrawAndCall E2E tests

3 participants