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: precompile bridge call #889

Merged
merged 2 commits into from
Jan 10, 2025
Merged

test: precompile bridge call #889

merged 2 commits into from
Jan 10, 2025

Conversation

zakir-code
Copy link
Contributor

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

Summary by CodeRabbit

  • New Features

    • Enhanced cross-chain bridge call functionality with new test cases and methods
    • Added bridge token registration capabilities
    • Expanded contract interaction methods for cross-chain operations
  • Tests

    • Introduced comprehensive test suite for cross-chain bridge calls
    • Added new test methods to validate bridge token and transaction processes
  • Improvements

    • Updated contract method visibility for external accessibility
    • Simplified test suite initialization processes
    • Improved code structure and method chaining in test utilities

Copy link

coderabbitai bot commented Jan 10, 2025

Walkthrough

This pull request introduces enhancements to the cross-chain bridge call testing infrastructure across multiple files. The changes primarily focus on expanding test capabilities for bridge call functionality, modifying contract interfaces, and updating test suite initialization methods. Key modifications include adding a new test function for bridge calls, changing function visibility in Solidity contracts, updating contract metadata, and streamlining test suite initialization processes.

Changes

File Change Summary
precompiles/crosschain/bridge_call_test.go Added new TestContract_BridgeCall() test function with comprehensive bridge token and transaction testing
precompiles/crosschain/contract_test.go Added new methods: GetSender(), IsCallPrecompile(), AddBridgeToken(). Modified test suite initialization and setup logic
solidity/contracts/test/CrosschainTest.sol Changed bridgeCall function visibility from internal to external
tests/contract/crosschain_test.sol.go Updated ABI and Bin fields, added new BridgeCall methods, deprecated previous ABI/Bin variables
tests/integration/integration_test.go Uncommented three previously disabled test methods in TestRun
testutil/helpers/*_precompile_suite.go Simplified initialization of contractBaseSuite across multiple helper files

Sequence Diagram

sequenceDiagram
    participant Sender
    participant CrosschainContract
    participant BridgeToken
    participant ModuleKeeper

    Sender->>CrosschainContract: Initiate Bridge Call
    CrosschainContract->>BridgeToken: Verify Token
    BridgeToken-->>CrosschainContract: Token Verified
    CrosschainContract->>ModuleKeeper: Mint/Transfer Tokens
    ModuleKeeper-->>CrosschainContract: Token Transaction Complete
    CrosschainContract-->>Sender: Bridge Call Response
Loading

Possibly related PRs

Poem

🐰 Hop, skip, and bridge we'll go!
Cross-chain calls now start to flow
From internal to external light
Our code takes a quantum-like flight
Testing bridges with rabbit might! 🌉

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.

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

🧹 Nitpick comments (2)
precompiles/crosschain/bridge_call_test.go (2)

188-190: Verify block height initialization

Setting last observed block height to 100. Consider parameterizing this value if it's significant for the test.


205-207: Consider adding more balance checks

While the final balance check is good, consider:

  1. Adding initial balance verification before the bridge call
  2. Verifying the module's token balance
 func (suite *CrosschainPrecompileTestSuite) TestContract_BridgeCall() {
     // ... existing setup ...
+    initialBalance, err := erc20TokenKeeper.BalanceOf(suite.Ctx, tokenAddr, suite.GetSender())
+    suite.Require().NoError(err)
+    suite.Require().Equal(big.NewInt(100), initialBalance)
+
     txResponse := suite.BridgeCall(...)
     // ... existing verification ...
+    moduleAddress := common.BytesToAddress(authtypes.NewModuleAddress(erc20types.ModuleName).Bytes())
+    moduleBalance, err := erc20TokenKeeper.BalanceOf(suite.Ctx, tokenAddr, moduleAddress)
+    suite.Require().NoError(err)
+    suite.Require().Equal(big.NewInt(101), moduleBalance) // 100 initial + 1 transferred
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 32b058c and d522d32.

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

21-21: Clean initialization pattern!

Good improvement in combining the ContractBaseSuite creation with WithContract call. This makes the code more concise while maintaining immutability.

testutil/helpers/crosschain_precompile_suite.go (1)

22-22: Consistent initialization pattern applied!

Good to see the same clean initialization pattern being consistently applied across different precompile suites. This maintains code consistency and improves readability across the codebase.

tests/contract/crosschain_test.sol.go (2)

34-35: Verify the updated ABI and binary data

The ABI and Bin fields in CrosschainTestMetaData have been updated to include the new bridgeCall function. Ensure that the generated ABI and binary accurately reflect the changes in the Solidity contract to prevent any mismatches between the contract and its Go bindings.


329-349: New BridgeCall methods added

The BridgeCall methods have been added to the CrosschainTestTransactor, CrosschainTestSession, and CrosschainTestTransactorSession types. The method signatures align with the contract's ABI, and the implementations appear correct.

solidity/contracts/test/CrosschainTest.sol (1)

81-81: ⚠️ Potential issue

Assess the change in function visibility from internal to external

The bridgeCall function's visibility has been changed from internal to external. Exposing this function externally allows it to be called from outside the contract. Ensure this change is intentional and does not introduce security risks. Consider implementing access control modifiers, such as onlyOwner or custom modifiers, to restrict access if necessary.

precompiles/crosschain/contract_test.go (2)

32-34: Initialize test suite with specified crosschainAddr

The test suite is now initialized with an explicit crosschainAddr, improving clarity and consistency in the test setup.


66-76: Enhance code readability with new helper methods

The addition of GetSender() and IsCallPrecompile() methods encapsulates logic for determining the sender and checking if the call is to a precompile. This improves code readability and maintainability.

tests/integration/integration_test.go (1)

109-111: Verify test dependencies and stability

The previously disabled staking contract tests have been re-enabled. Please ensure:

  1. These tests don't have dependencies on the preceding tests in the execution sequence
  2. The tests are stable and don't introduce flakiness to the test suite

Run this script to check for potential test dependencies and stability issues:

✅ Verification successful

Tests are properly isolated and independent

The re-enabled tests are well-designed with:

  • Independent test state using fresh keys and accounts for each test
  • Proper cleanup of shared resources
  • No dependencies on test execution order
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential test dependencies and stability issues
# Look for shared state setup/teardown and test ordering requirements

# Search for test setup/teardown methods
echo "Checking test setup/teardown methods:"
rg -A 5 "func.*Setup|func.*TearDown" tests/integration/

# Search for potential shared state
echo "Checking for shared state usage:"
rg "suite\.(StakingContractTest|StakingSharesContractTest|StakingPrecompileRedelegateByContractTest)" tests/integration/

Length of output: 1397


Script:

#!/bin/bash
# Check test implementations and state management

# Look for the test implementations
echo "Test implementations:"
rg -B 2 -A 10 "func.*\(suite \*IntegrationTest\) (StakingContractTest|StakingSharesContractTest|StakingPrecompileRedelegateByContractTest)" tests/integration/

# Check for shared state variables
echo -e "\nShared state variables:"
rg "suite\." --context 2 tests/integration/integration_test.go | grep -v "func"

# Check for network state modifications
echo -e "\nNetwork state modifications:"
rg "suite\.network\." tests/integration/integration_test.go

Length of output: 7226

precompiles/crosschain/bridge_call_test.go (3)

8-18: LGTM! Dependencies are properly organized.

The new imports are correctly added and organized by their respective domains (SDK, Ethereum, and internal packages).


191-204: LGTM! Bridge call test is well structured.

The test properly:

  1. Sets up the test scenario with necessary parameters
  2. Executes the bridge call
  3. Verifies the transaction response and logs

180-187: Verify token minting behavior

The test mints tokens both via ERC20TokenKeeper and MintTokenToModule. Please ensure:

  1. Both minting operations are necessary
  2. The amounts (100 units) are sufficient for the test scenarios
✅ Verification successful

Both minting operations are necessary and amounts are appropriate

The dual minting is correct as it maintains parity between ERC20 tokens and native coins, which is essential for bridge operations. The 100-unit amount provides sufficient balance for the test's bridge call that transfers 1 unit, with adequate buffer for potential additional test scenarios.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check token minting patterns across tests
# Look for similar dual minting patterns that might indicate redundancy

# Search for similar minting patterns
echo "Checking minting patterns:"
rg "MintTokenToModule.*NewCoin.*usdt" precompiles/
rg "erc20TokenKeeper.*Mint" precompiles/

Length of output: 433


Script:

#!/bin/bash
# Get broader context of the test function
echo "=== Test function context ==="
rg -B 10 -A 20 "MintTokenToModule.*NewCoin.*usdt" precompiles/crosschain/bridge_call_test.go

echo -e "\n=== Other bridge tests with similar patterns ==="
# Look for bridge-related test files
fd "bridge.*test" precompiles/ --exec rg -l "MintTokenToModule|erc20TokenKeeper.*Mint" {}

Length of output: 1633

precompiles/crosschain/contract_test.go Show resolved Hide resolved
precompiles/crosschain/contract_test.go Show resolved Hide resolved
@nulnut nulnut merged commit c944d46 into main Jan 10, 2025
16 checks passed
@nulnut nulnut deleted the zakir/test-bridge-call branch January 10, 2025 07:42
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