Add Oracle Aggregator and CCIP Integration
- Introduced Aggregator.sol for Chainlink-compatible oracle functionality, including round-based updates and access control. - Added OracleWithCCIP.sol to extend Aggregator with CCIP cross-chain messaging capabilities. - Created .gitmodules to include OpenZeppelin contracts as a submodule. - Developed a comprehensive deployment guide in NEXT_STEPS_COMPLETE_GUIDE.md for Phase 2 and smart contract deployment. - Implemented Vite configuration for the orchestration portal, supporting both Vue and React frameworks. - Added server-side logic for the Multi-Cloud Orchestration Portal, including API endpoints for environment management and monitoring. - Created scripts for resource import and usage validation across non-US regions. - Added tests for CCIP error handling and integration to ensure robust functionality. - Included various new files and directories for the orchestration portal and deployment scripts.
This commit is contained in:
178
test/CCIPWETH9Bridge.t.sol
Normal file
178
test/CCIPWETH9Bridge.t.sol
Normal file
@@ -0,0 +1,178 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
import {Test, console} from "forge-std/Test.sol";
|
||||
import {CCIPWETH9Bridge} from "../contracts/ccip/CCIPWETH9Bridge.sol";
|
||||
import {WETH} from "../contracts/tokens/WETH.sol";
|
||||
import {IRouterClient} from "../contracts/ccip/IRouterClient.sol";
|
||||
|
||||
interface IERC20 {
|
||||
function approve(address spender, uint256 amount) external returns (bool);
|
||||
function balanceOf(address account) external view returns (uint256);
|
||||
function transfer(address to, uint256 amount) external returns (bool);
|
||||
}
|
||||
|
||||
contract MockCCIPRouter is IRouterClient {
|
||||
mapping(bytes32 => bool) public messages;
|
||||
uint256 public fee = 0.001 ether;
|
||||
|
||||
function ccipSend(
|
||||
uint64 destinationChainSelector,
|
||||
EVM2AnyMessage memory message
|
||||
) external payable override returns (bytes32 messageId, uint256 fees) {
|
||||
messageId = keccak256(abi.encode(block.timestamp, msg.sender, message));
|
||||
messages[messageId] = true;
|
||||
fees = fee;
|
||||
emit MessageSent(
|
||||
messageId,
|
||||
destinationChainSelector,
|
||||
msg.sender,
|
||||
message.receiver,
|
||||
message.data,
|
||||
message.tokenAmounts,
|
||||
message.feeToken,
|
||||
message.extraArgs
|
||||
);
|
||||
}
|
||||
|
||||
function getFee(
|
||||
uint64 destinationChainSelector,
|
||||
EVM2AnyMessage memory message
|
||||
) external view override returns (uint256) {
|
||||
return fee;
|
||||
}
|
||||
|
||||
function getSupportedTokens(
|
||||
uint64 destinationChainSelector
|
||||
) external pure override returns (address[] memory) {
|
||||
return new address[](0);
|
||||
}
|
||||
|
||||
// Note: In real CCIP, tokens are automatically transferred by the router
|
||||
// This mock is simplified for testing
|
||||
}
|
||||
|
||||
contract CCIPWETH9BridgeTest is Test {
|
||||
CCIPWETH9Bridge public bridge;
|
||||
WETH public weth9;
|
||||
MockCCIPRouter public mockRouter;
|
||||
address public feeToken = address(0x123); // Mock LINK token
|
||||
address public user = address(1);
|
||||
address public recipient = address(2);
|
||||
uint64 public destinationChainSelector = 1;
|
||||
|
||||
function setUp() public {
|
||||
// Deploy WETH9
|
||||
weth9 = new WETH();
|
||||
|
||||
// Deploy Mock CCIP Router
|
||||
mockRouter = new MockCCIPRouter();
|
||||
|
||||
// Deploy Bridge
|
||||
bridge = new CCIPWETH9Bridge(
|
||||
address(mockRouter),
|
||||
address(weth9),
|
||||
feeToken
|
||||
);
|
||||
|
||||
// Setup user
|
||||
vm.deal(user, 10 ether);
|
||||
vm.prank(user);
|
||||
weth9.deposit{value: 5 ether}();
|
||||
}
|
||||
|
||||
function testAddDestination() public {
|
||||
address receiverBridge = address(0x456);
|
||||
|
||||
vm.prank(bridge.admin());
|
||||
bridge.addDestination(destinationChainSelector, receiverBridge);
|
||||
|
||||
(uint64 chainSelector, address receiverBridge_, bool enabled) =
|
||||
bridge.destinations(destinationChainSelector);
|
||||
|
||||
assertEq(chainSelector, destinationChainSelector);
|
||||
assertEq(receiverBridge_, receiverBridge);
|
||||
assertTrue(enabled);
|
||||
}
|
||||
|
||||
function testSendCrossChain() public {
|
||||
address receiverBridge = address(0x456);
|
||||
uint256 amount = 1 ether;
|
||||
|
||||
// Add destination
|
||||
vm.prank(bridge.admin());
|
||||
bridge.addDestination(destinationChainSelector, receiverBridge);
|
||||
|
||||
// Approve bridge
|
||||
vm.prank(user);
|
||||
weth9.approve(address(bridge), amount);
|
||||
|
||||
// Approve fee token (mock)
|
||||
deal(feeToken, user, 1 ether);
|
||||
vm.prank(user);
|
||||
IERC20(feeToken).approve(address(bridge), 1 ether);
|
||||
|
||||
// Send cross-chain
|
||||
vm.prank(user);
|
||||
bytes32 messageId = bridge.sendCrossChain(
|
||||
destinationChainSelector,
|
||||
recipient,
|
||||
amount
|
||||
);
|
||||
|
||||
assertTrue(messageId != bytes32(0));
|
||||
assertEq(weth9.balanceOf(user), 4 ether);
|
||||
assertEq(weth9.balanceOf(address(bridge)), amount);
|
||||
}
|
||||
|
||||
function testReceiveCrossChain() public {
|
||||
uint256 amount = 1 ether;
|
||||
address sourceSender = address(0x789);
|
||||
uint64 sourceChainSelector = 2;
|
||||
|
||||
// Deposit WETH9 to bridge for testing (simulating CCIP token transfer)
|
||||
vm.deal(address(this), amount);
|
||||
weth9.deposit{value: amount}();
|
||||
weth9.transfer(address(bridge), amount);
|
||||
|
||||
// Prepare message
|
||||
bytes32 messageId = keccak256("test-message");
|
||||
bytes memory data = abi.encode(recipient, amount, sourceSender, 1);
|
||||
|
||||
IRouterClient.TokenAmount[] memory tokenAmounts = new IRouterClient.TokenAmount[](1);
|
||||
tokenAmounts[0] = IRouterClient.TokenAmount({
|
||||
token: address(weth9),
|
||||
amount: amount,
|
||||
amountType: IRouterClient.TokenAmountType.Fiat
|
||||
});
|
||||
|
||||
// Simulate receive (mock router calls bridge - tokens already transferred)
|
||||
vm.prank(address(mockRouter));
|
||||
bridge.ccipReceive(
|
||||
IRouterClient.Any2EVMMessage({
|
||||
messageId: messageId,
|
||||
sourceChainSelector: sourceChainSelector,
|
||||
sender: abi.encode(sourceSender),
|
||||
data: data,
|
||||
tokenAmounts: tokenAmounts
|
||||
})
|
||||
);
|
||||
|
||||
assertEq(weth9.balanceOf(recipient), amount);
|
||||
assertTrue(bridge.processedTransfers(messageId));
|
||||
}
|
||||
|
||||
function testCalculateFee() public {
|
||||
address receiverBridge = address(0x456);
|
||||
uint256 amount = 1 ether;
|
||||
|
||||
// Add destination
|
||||
vm.prank(bridge.admin());
|
||||
bridge.addDestination(destinationChainSelector, receiverBridge);
|
||||
|
||||
// Calculate fee
|
||||
uint256 fee = bridge.calculateFee(destinationChainSelector, amount);
|
||||
assertEq(fee, mockRouter.fee());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user