-
Notifications
You must be signed in to change notification settings - Fork 403
/
WHypERC4626.t.sol
116 lines (91 loc) · 3.71 KB
/
WHypERC4626.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.13;
import {Test} from "forge-std/Test.sol";
import {MockMailbox} from "../../contracts/mock/MockMailbox.sol";
import {WHypERC4626} from "../../contracts/token/extensions/WHypERC4626.sol";
import {HypERC4626} from "../../contracts/token/extensions/HypERC4626.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MockHypERC4626 is HypERC4626 {
constructor(address _mailbox) HypERC4626(18, _mailbox, 2) {}
function mint(address to, uint256 amount) external {
_mint(to, amount);
}
}
contract WHypERC4626Test is Test {
WHypERC4626 public wHypERC4626;
MockHypERC4626 public underlyingToken;
address public alice = address(0x1);
address public bob = address(0x2);
function setUp() public {
MockMailbox mailbox = new MockMailbox(1);
underlyingToken = new MockHypERC4626(address(mailbox));
wHypERC4626 = new WHypERC4626(
underlyingToken,
"Wrapped Rebasing Token",
"WRT"
);
underlyingToken.mint(alice, 1000 * 10 ** 18);
underlyingToken.mint(bob, 1000 * 10 ** 18);
}
function test_wrap() public {
uint256 amount = 100 * 10 ** 18;
vm.startPrank(alice);
underlyingToken.approve(address(wHypERC4626), amount);
uint256 wrappedAmount = wHypERC4626.wrap(amount);
assertEq(wHypERC4626.balanceOf(alice), wrappedAmount);
assertEq(underlyingToken.balanceOf(alice), 900 * 10 ** 18);
vm.stopPrank();
}
function test_wrap_revertsWhen_zeroAmount() public {
vm.startPrank(alice);
underlyingToken.approve(address(wHypERC4626), 0);
vm.expectRevert("WHypERC4626: wrap amount must be greater than 0");
wHypERC4626.wrap(0);
vm.stopPrank();
}
function test_unwrap() public {
uint256 amount = 100 * 10 ** 18;
vm.startPrank(alice);
underlyingToken.approve(address(wHypERC4626), amount);
uint256 wrappedAmount = wHypERC4626.wrap(amount);
uint256 unwrappedAmount = wHypERC4626.unwrap(wrappedAmount);
assertEq(wHypERC4626.balanceOf(alice), 0);
assertEq(underlyingToken.balanceOf(alice), 1000 * 10 ** 18);
assertEq(unwrappedAmount, amount);
vm.stopPrank();
}
function test_unwrap_revertsWhen_zeroAmount() public {
vm.startPrank(alice);
vm.expectRevert("WHypERC4626: unwrap amount must be greater than 0");
wHypERC4626.unwrap(0);
vm.stopPrank();
}
function test_getWrappedAmount() public view {
uint256 amount = 100 * 10 ** 18;
uint256 wrappedAmount = wHypERC4626.getWrappedAmount(amount);
assertEq(wrappedAmount, underlyingToken.assetsToShares(amount));
}
function test_getUnderlyingAmount() public view {
uint256 amount = 100 * 10 ** 18;
uint256 underlyingAmount = wHypERC4626.getUnderlyingAmount(amount);
assertEq(underlyingAmount, underlyingToken.sharesToAssets(amount));
}
function test_wrappedPerUnderlying() public view {
uint256 wrappedPerUnderlying = wHypERC4626.wrappedPerUnderlying();
assertEq(
wrappedPerUnderlying,
underlyingToken.assetsToShares(1 * 10 ** underlyingToken.decimals())
);
}
function test_underlyingPerWrapped() public view {
uint256 underlyingPerWrapped = wHypERC4626.underlyingPerWrapped();
assertEq(
underlyingPerWrapped,
underlyingToken.sharesToAssets(1 * 10 ** underlyingToken.decimals())
);
}
function test_decimals() public view {
uint8 decimals = wHypERC4626.decimals();
assertEq(decimals, underlyingToken.decimals());
}
}