Files
smom-dbis-138/docs/ccip-integration/chain138/TESTING.md

195 lines
3.6 KiB
Markdown

# CCIP Testing Guide for ChainID 138
**Date**: 2025-01-27
**Network**: ChainID 138 (DeFi Oracle Meta Mainnet)
---
## Overview
This guide provides testing procedures and examples for CCIP infrastructure on ChainID 138.
---
## Test Categories
### 1. Unit Tests
Test individual contract functions in isolation.
**Files**:
- `test/CCIPWETH9Bridge.t.sol`
- `test/CCIPWETH10Bridge.t.sol`
- `test/ccip/CCIPIntegration.t.sol`
- `test/ccip/CCIPErrorHandling.t.sol`
- `test/ccip/CCIPFees.t.sol`
### 2. Integration Tests
Test end-to-end cross-chain flows.
**Files**:
- `test/ccip/CCIPIntegration.t.sol`
### 3. Functional Tests
Test real-world usage scenarios.
---
## Running Tests
### Run All CCIP Tests
```bash
forge test --match-path "test/ccip/**" -vvv
forge test --match-path "test/CCIP*.t.sol" -vvv
```
### Run Specific Test File
```bash
forge test --match-path "test/CCIPWETH9Bridge.t.sol" -vvv
```
### Run Specific Test Function
```bash
forge test --match-test "testSendCrossChain" -vvv
```
---
## Test Scenarios
### Router Tests
```solidity
function testRouterMessageSending() public {
// Test sending message via router
IRouterClient.EVM2AnyMessage memory message = ...;
(bytes32 messageId, uint256 fee) = router.ccipSend(destinationSelector, message);
assertTrue(messageId != bytes32(0));
}
function testRouterFeeCalculation() public {
// Test fee calculation
uint256 fee = router.getFee(destinationSelector, message);
assertTrue(fee > 0);
}
```
### Bridge Tests
```solidity
function testBridgeTransfer() public {
// Approve bridge
weth9.approve(address(bridge), amount);
// Send cross-chain
bytes32 messageId = bridge.sendCrossChain(destinationSelector, recipient, amount);
// Verify
assertTrue(messageId != bytes32(0));
}
function testBridgeFeeCalculation() public {
uint256 fee = bridge.calculateFee(destinationSelector, amount);
assertTrue(fee > 0);
}
```
### Integration Tests
```solidity
function testEndToEndTransfer() public {
// 1. Lock tokens on source chain
// 2. Send cross-chain message
// 3. Verify unlock on destination chain
// 4. Verify balances
}
```
---
## Test Data
### Test Addresses
```solidity
address constant TEST_USER = address(0x1111);
address constant TEST_RECIPIENT = address(0x2222);
address constant TEST_ADMIN = address(0x3333);
```
### Test Amounts
```solidity
uint256 constant TEST_AMOUNT = 1 ether;
uint256 constant TEST_FEE = 0.001 ether;
```
### Test Chain Selectors
```solidity
uint64 constant CHAIN138_SELECTOR = 138;
uint64 constant ETH_MAINNET_SELECTOR = 5009297550715157269;
```
---
## Mock Contracts
For testing without actual cross-chain connectivity:
```solidity
contract MockRouter is IRouterClient {
function ccipSend(...) external payable returns (bytes32, uint256) {
// Mock implementation
}
function getFee(...) external view returns (uint256) {
// Mock fee calculation
}
}
```
---
## Test Coverage Goals
- **Unit Tests**: >90% coverage
- **Integration Tests**: All critical paths
- **Error Handling**: All error cases
- **Edge Cases**: Boundary conditions
---
## Continuous Integration
### GitHub Actions Example
```yaml
name: CCIP Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: foundry-actions/setup-foundry@v1
- run: forge test --match-path "test/ccip/**"
```
---
## Related Documentation
- [Deployment Guide](DEPLOYMENT_GUIDE_CHAIN138.md)
- [Developer Integration Guide](../developer-guides/CCIP_INTEGRATION_GUIDE.md)
---
**Last Updated**: 2025-01-27