Commit 5b39256b authored by smartcontracts's avatar smartcontracts Committed by GitHub

feat(ctb): add basic weth tests (#10235)

parent b35e82b5
...@@ -4,16 +4,31 @@ import { Test } from "forge-std/Test.sol"; ...@@ -4,16 +4,31 @@ import { Test } from "forge-std/Test.sol";
import { WETH98 } from "src/dispute/weth/WETH98.sol"; import { WETH98 } from "src/dispute/weth/WETH98.sol";
contract WETH98_Test is Test { contract WETH98_Test is Test {
event Approval(address indexed src, address indexed guy, uint256 wad);
event Transfer(address indexed src, address indexed dst, uint256 wad);
event Deposit(address indexed dst, uint256 wad);
event Withdrawal(address indexed src, uint256 wad);
WETH98 public weth; WETH98 public weth;
address alice; address alice;
address bob;
function setUp() public { function setUp() public {
weth = new WETH98(); weth = new WETH98();
alice = makeAddr("alice"); alice = makeAddr("alice");
bob = makeAddr("bob");
deal(alice, 1 ether); deal(alice, 1 ether);
} }
function test_getName_succeeds() public view {
assertEq(weth.name(), "Wrapped Ether");
assertEq(weth.symbol(), "WETH");
assertEq(weth.decimals(), 18);
}
function test_receive_succeeds() public { function test_receive_succeeds() public {
vm.expectEmit(address(weth));
emit Deposit(alice, 1 ether);
vm.prank(alice); vm.prank(alice);
(bool success,) = address(weth).call{ value: 1 ether }(""); (bool success,) = address(weth).call{ value: 1 ether }("");
assertTrue(success); assertTrue(success);
...@@ -21,15 +36,107 @@ contract WETH98_Test is Test { ...@@ -21,15 +36,107 @@ contract WETH98_Test is Test {
} }
function test_fallback_succeeds() public { function test_fallback_succeeds() public {
vm.expectEmit(address(weth));
emit Deposit(alice, 1 ether);
vm.prank(alice); vm.prank(alice);
(bool success,) = address(weth).call{ value: 1 ether }(hex"1234"); (bool success,) = address(weth).call{ value: 1 ether }(hex"1234");
assertTrue(success); assertTrue(success);
assertEq(weth.balanceOf(alice), 1 ether); assertEq(weth.balanceOf(alice), 1 ether);
} }
function test_getName_succeeds() public view { function test_deposit_succeeds() public {
assertEq(weth.name(), "Wrapped Ether"); vm.expectEmit(address(weth));
assertEq(weth.symbol(), "WETH"); emit Deposit(alice, 1 ether);
assertEq(weth.decimals(), 18); vm.prank(alice);
weth.deposit{ value: 1 ether }();
assertEq(weth.balanceOf(alice), 1 ether);
}
function test_withdraw_succeeds() public {
vm.prank(alice);
weth.deposit{ value: 1 ether }();
vm.expectEmit(address(weth));
emit Withdrawal(alice, 1 ether);
vm.prank(alice);
weth.withdraw(1 ether);
assertEq(weth.balanceOf(alice), 0);
}
function test_withdraw_partialWithdrawal_succeeds() public {
vm.prank(alice);
weth.deposit{ value: 1 ether }();
vm.expectEmit(address(weth));
emit Withdrawal(alice, 1 ether / 2);
vm.prank(alice);
weth.withdraw(1 ether / 2);
assertEq(weth.balanceOf(alice), 1 ether / 2);
}
function test_withdraw_tooLargeWithdrawal_fails() public {
vm.prank(alice);
weth.deposit{ value: 1 ether }();
vm.expectRevert();
vm.prank(alice);
weth.withdraw(1 ether + 1);
}
function test_transfer_succeeds() public {
vm.prank(alice);
weth.deposit{ value: 1 ether }();
vm.expectEmit(address(weth));
emit Transfer(alice, bob, 1 ether);
vm.prank(alice);
weth.transfer(bob, 1 ether);
assertEq(weth.balanceOf(alice), 0);
assertEq(weth.balanceOf(bob), 1 ether);
}
function test_transfer_tooLarge_fails() public {
vm.prank(alice);
weth.deposit{ value: 1 ether }();
vm.expectRevert();
vm.prank(alice);
weth.transfer(bob, 1 ether + 1);
}
function test_approve_succeeds() public {
vm.prank(alice);
vm.expectEmit(address(weth));
emit Approval(alice, bob, 1 ether);
weth.approve(bob, 1 ether);
assertEq(weth.allowance(alice, bob), 1 ether);
}
function test_transferFrom_succeeds() public {
vm.prank(alice);
weth.deposit{ value: 1 ether }();
vm.prank(alice);
weth.approve(bob, 1 ether);
vm.expectEmit(address(weth));
emit Transfer(alice, bob, 1 ether);
vm.prank(bob);
weth.transferFrom(alice, bob, 1 ether);
assertEq(weth.balanceOf(alice), 0);
assertEq(weth.balanceOf(bob), 1 ether);
}
function test_transferFrom_tooLittleApproval_fails() public {
vm.prank(alice);
weth.deposit{ value: 1 ether }();
vm.prank(alice);
weth.approve(bob, 1 ether);
vm.expectRevert();
vm.prank(bob);
weth.transferFrom(alice, bob, 1 ether + 1);
}
function test_transferFrom_tooLittleBalance_fails() public {
vm.prank(alice);
weth.deposit{ value: 1 ether }();
vm.prank(alice);
weth.approve(bob, 2 ether);
vm.expectRevert();
vm.prank(bob);
weth.transferFrom(alice, bob, 1 ether + 1);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment