Files
smom-dbis-138/test/WETH10.t.sol
defiQUG 1fb7266469 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.
2025-12-12 14:57:48 -08:00

134 lines
3.8 KiB
Solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import {Test, console} from "forge-std/Test.sol";
import {WETH10, IERC3156FlashBorrower} from "../contracts/tokens/WETH10.sol";
contract WETH10Test is Test {
WETH10 public weth10;
address public user = address(1);
address public recipient = address(2);
function setUp() public {
weth10 = new WETH10();
vm.deal(user, 10 ether);
}
function testDeposit() public {
vm.prank(user);
weth10.deposit{value: 1 ether}();
assertEq(weth10.balanceOf(user), 1 ether);
assertEq(weth10.totalSupply(), 1 ether);
}
function testWithdraw() public {
vm.prank(user);
weth10.deposit{value: 1 ether}();
uint256 balanceBefore = user.balance;
vm.prank(user);
weth10.withdraw(1 ether);
assertEq(weth10.balanceOf(user), 0);
assertEq(user.balance, balanceBefore + 1 ether);
}
function testTransfer() public {
vm.prank(user);
weth10.deposit{value: 1 ether}();
vm.prank(user);
weth10.transfer(recipient, 0.5 ether);
assertEq(weth10.balanceOf(user), 0.5 ether);
assertEq(weth10.balanceOf(recipient), 0.5 ether);
}
function testApprove() public {
address spender = address(2);
vm.prank(user);
weth10.deposit{value: 1 ether}();
vm.prank(user);
weth10.approve(spender, 0.5 ether);
assertEq(weth10.allowance(user, spender), 0.5 ether);
}
function testReceive() public {
vm.prank(user);
(bool success, ) = address(weth10).call{value: 1 ether}("");
require(success, "Transfer failed");
assertEq(weth10.balanceOf(user), 1 ether);
}
function testMaxFlashLoan() public {
vm.prank(user);
weth10.deposit{value: 5 ether}();
uint256 maxLoan = weth10.maxFlashLoan(address(weth10));
assertEq(maxLoan, 5 ether);
uint256 maxLoanOther = weth10.maxFlashLoan(address(0));
assertEq(maxLoanOther, 0);
}
function testFlashFee() public {
uint256 fee = weth10.flashFee(address(weth10), 1 ether);
assertEq(fee, 0); // WETH10 has no flash loan fee
}
function testFlashLoan() public {
vm.prank(user);
weth10.deposit{value: 10 ether}();
FlashLoanReceiver receiver = new FlashLoanReceiver(weth10);
vm.prank(user);
weth10.approve(address(receiver), type(uint256).max);
uint256 amount = 5 ether;
bytes memory data = "";
vm.prank(user);
bool success = weth10.flashLoan(receiver, address(weth10), amount, data);
assertTrue(success);
}
}
contract FlashLoanReceiver is IERC3156FlashBorrower {
WETH10 public weth10;
bytes32 public constant CALLBACK_SUCCESS = keccak256("ERC3156FlashBorrower.onFlashLoan");
constructor(WETH10 _weth10) {
weth10 = _weth10;
}
function onFlashLoan(
address initiator,
address token,
uint256 amount,
uint256 fee,
bytes calldata data
) external override returns (bytes32) {
require(msg.sender == address(weth10), "FlashLoanReceiver: invalid sender");
require(token == address(weth10), "FlashLoanReceiver: invalid token");
// Use the flash loan (e.g., arbitrage, liquidate, etc.)
// For testing, we just repay immediately
// Repay flash loan
weth10.transfer(address(weth10), amount + fee);
return CALLBACK_SUCCESS;
}
function executeFlashLoan(uint256 amount) external {
bytes memory data = "";
weth10.flashLoan(this, address(weth10), amount, data);
}
}