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

test: add bridge call origin token unit test #941

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

zakir-code
Copy link
Contributor

@zakir-code zakir-code commented Jan 22, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced cross-chain bridge functionality to support value transfers during bridge calls
    • Added support for payable bridge and crosschain transactions in smart contracts
  • Improvements

    • Updated method signatures to include value parameters for more flexible token and Ether transfers
    • Expanded testing capabilities for cross-chain token and value interactions
  • Technical Updates

    • Modified contract methods to handle Ether transactions
    • Updated test suites to accommodate new cross-chain transfer mechanisms

Copy link

coderabbitai bot commented Jan 22, 2025

Walkthrough

The pull request introduces modifications to the cross-chain bridge call functionality across multiple files. The primary change is the addition of a value parameter to bridge call methods, enabling Ether transactions during cross-chain operations. This update affects both the Go implementation and Solidity contract, allowing more flexible token and value transfers across different blockchain networks. The changes span contract implementations, test suites, and helper utilities to support this new functionality.

Changes

File Change Summary
contract/crosschain_precompile.go Updated BridgeCall method signature to include value parameter
precompiles/crosschain/bridge_call_test.go Added new test method TestContract_BridgeCall_OriginToken
precompiles/crosschain/contract_test.go Added methods for ERC20 token handling and bridge fee quoting
precompiles/crosschain/crosschain_test.go Added TestContract_Crosschain_OriginToken test method
solidity/contracts/test/CrosschainTest.sol Made bridgeCall method payable, allowing Ether transactions
tests/contract/crosschain_test.sol.go Updated ABI and method signatures to support payable transactions
testutil/helpers/crosschain_precompile_suite.go Modified BridgeCall and Crosschain method signatures

Sequence Diagram

sequenceDiagram
    participant Sender
    participant CrosschainContract
    participant DestinationChain
    
    Sender->>CrosschainContract: bridgeCall(value, tokens, data)
    CrosschainContract-->>DestinationChain: Transfer tokens + value
    DestinationChain-->>Sender: Confirm transaction
Loading

Possibly related PRs

Poem

🐰 Hopping across the blockchain's wide sea,
With value in paw, our bridge calls run free!
Ether flows smooth, tokens dance with grace,
A rabbit's magic in every trace!
Cross-chain adventures, now more profound! 🌉

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

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.

@fx0x55
Copy link
Contributor

fx0x55 commented Jan 22, 2025

@coderabbitai review

Copy link

coderabbitai bot commented Jan 22, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

🧹 Nitpick comments (3)
precompiles/crosschain/crosschain_test.go (1)

32-73: Consider adding more assertions for comprehensive testing.

The test setup and flow look good, but consider adding assertions for:

  1. The emitted event parameters
  2. The exact contents of the transaction logs
  3. The state of the contract before and after the crosschain operation
precompiles/crosschain/contract_test.go (1)

131-155: Parameterize hardcoded values in quote input.

The function uses hardcoded values that might not be suitable for all test cases:

  • Gas limit of 21000 (Ethereum base transaction cost)
  • Amount of 1
    Consider parameterizing these values to make the function more flexible.

Apply this diff to improve flexibility:

-func (suite *CrosschainPrecompileTestSuite) Quote(denom string) {
+func (suite *CrosschainPrecompileTestSuite) Quote(denom string, gasLimit uint64, amount *big.Int) {
 	quoteQuoteInput := contract.IBridgeFeeQuoteQuoteInput{
 		Cap:       0,
-		GasLimit:  21000,
+		GasLimit:  gasLimit,
 		Expiry:    uint64(time.Now().Add(time.Hour).Unix()),
 		ChainName: contract.MustStrToByte32(suite.chainName),
 		TokenName: contract.MustStrToByte32(denom),
-		Amount:    big.NewInt(1),
+		Amount:    amount,
 	}
precompiles/crosschain/bridge_call_test.go (1)

225-249: Add assertions for transaction logs.

The test verifies the presence of logs but doesn't validate their content. Consider adding assertions to verify the log data matches the expected values.

Example assertion to add:

 	suite.NotNil(txResponse)
 	suite.Len(txResponse.Logs, 1)
+	// Verify log content
+	log := txResponse.Logs[0]
+	suite.Equal(value, log.Amount)
+	suite.Equal(suite.signer.Address(), log.From)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d7a1464 and 58d6627.

📒 Files selected for processing (7)
  • contract/crosschain_precompile.go (1 hunks)
  • precompiles/crosschain/bridge_call_test.go (3 hunks)
  • precompiles/crosschain/contract_test.go (5 hunks)
  • precompiles/crosschain/crosschain_test.go (3 hunks)
  • solidity/contracts/test/CrosschainTest.sol (2 hunks)
  • tests/contract/crosschain_test.sol.go (2 hunks)
  • testutil/helpers/crosschain_precompile_suite.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Summary
🔇 Additional comments (9)
testutil/helpers/crosschain_precompile_suite.go (1)

61-64: LGTM! Test helper methods updated correctly.

The BridgeCall method has been properly updated to include the value parameter and correctly propagates it to the underlying CrosschainPrecompileKeeper.

contract/crosschain_precompile.go (1)

Line range hint 57-66: LGTM! Core implementation updated correctly.

The BridgeCall method has been properly updated to:

  1. Accept the value parameter for Ether transactions
  2. Pass the value to ApplyContract
  3. Maintain proper error handling and return values
precompiles/crosschain/crosschain_test.go (1)

Line range hint 75-95: LGTM! Origin token test case looks good.

The test properly verifies:

  1. Balance changes before and after the operation
  2. Correct module account handling
  3. Transaction response and logs
solidity/contracts/test/CrosschainTest.sol (2)

67-67: LGTM! Function correctly marked as payable.

The bridgeCall function is properly marked as payable to accept Ether transactions.


Line range hint 81-91: Verify value handling in production code.

The implementation correctly forwards the msg.value to the ICrosschain contract. However, ensure that the production contract properly validates the msg.value against expected amounts to prevent accidental value transfers.

precompiles/crosschain/contract_test.go (2)

66-67: Verify the purpose of magic numbers in block height setup.

The values 100 and 10 are used without explanation. Consider using named constants or adding comments to explain their significance in the test setup.


85-87: LGTM!

Clean implementation of the ERC20TokenKeeper getter.

precompiles/crosschain/bridge_call_test.go (1)

183-223: LGTM!

Well-structured test that verifies:

  1. Token setup and minting
  2. Bridge call execution
  3. Balance checks after the operation
tests/contract/crosschain_test.sol.go (1)

331-345: LGTM!

The generated code correctly reflects the contract changes making bridgeCall payable.

precompiles/crosschain/contract_test.go Show resolved Hide resolved
@zakir-code zakir-code merged commit c081999 into main Jan 22, 2025
18 checks passed
@zakir-code zakir-code deleted the zakir/bridge-call-test branch January 22, 2025 10:40
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