Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
5b39256b
Unverified
Commit
5b39256b
authored
Apr 22, 2024
by
smartcontracts
Committed by
GitHub
Apr 22, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(ctb): add basic weth tests (#10235)
parent
b35e82b5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
111 additions
and
4 deletions
+111
-4
WETH98.t.sol
packages/contracts-bedrock/test/dispute/WETH98.t.sol
+111
-4
No files found.
packages/contracts-bedrock/test/dispute/WETH98.t.sol
View file @
5b39256b
...
...
@@ -4,16 +4,31 @@ import { Test } from "forge-std/Test.sol";
import { WETH98 } from "src/dispute/weth/WETH98.sol";
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;
address alice;
address bob;
function setUp() public {
weth = new WETH98();
alice = makeAddr("alice");
bob = makeAddr("bob");
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 {
vm.expectEmit(address(weth));
emit Deposit(alice, 1 ether);
vm.prank(alice);
(bool success,) = address(weth).call{ value: 1 ether }("");
assertTrue(success);
...
...
@@ -21,15 +36,107 @@ contract WETH98_Test is Test {
}
function test_fallback_succeeds() public {
vm.expectEmit(address(weth));
emit Deposit(alice, 1 ether);
vm.prank(alice);
(bool success,) = address(weth).call{ value: 1 ether }(hex"1234");
assertTrue(success);
assertEq(weth.balanceOf(alice), 1 ether);
}
function test_getName_succeeds() public view {
assertEq(weth.name(), "Wrapped Ether");
assertEq(weth.symbol(), "WETH");
assertEq(weth.decimals(), 18);
function test_deposit_succeeds() public {
vm.expectEmit(address(weth));
emit Deposit(alice, 1 ether);
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);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment