-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathWrapStrategy.t.sol
More file actions
118 lines (96 loc) · 3.95 KB
/
WrapStrategy.t.sol
File metadata and controls
118 lines (96 loc) · 3.95 KB
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
117
118
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import { ISuperToken } from "@superfluid-finance/ethereum-contracts/contracts/superfluid/SuperToken.sol";
import { SuperTokenV1Library } from "@superfluid-finance/ethereum-contracts/contracts/apps/SuperTokenV1Library.sol";
import { FoundrySuperfluidTester } from "@superfluid-finance/ethereum-contracts/test/foundry/FoundrySuperfluidTester.t.sol";
import { Manager } from "./../contracts/Manager.sol";
import { WrapStrategy } from "./../contracts/strategies/WrapStrategy.sol";
import { IStrategy } from "./../contracts/interfaces/IStrategy.sol";
import { ISETH } from "@superfluid-finance/ethereum-contracts/contracts/interfaces/tokens/ISETH.sol";
/// @title ManagerTests
contract WrapStrategyTests is FoundrySuperfluidTester {
using SuperTokenV1Library for ISuperToken;
event Wrap(
address indexed user,
address indexed superToken,
uint256 superTokenAmount
);
event ManagerChanged(
address indexed oldManager,
address indexed Manager
);
event EmergencyWithdrawInitiated(
address indexed receiver,
address indexed token,
uint256 amount
);
/// SETUP AND HELPERS
constructor() FoundrySuperfluidTester(3) {}
uint64 MIN_LOWER = 2 days;
uint64 MIN_UPPER = 7 days;
Manager public manager;
WrapStrategy public wrapStrategy;
uint256 internal _expectedTotalSupply;
ISETH nativeSuperToken;
function setUp() override public virtual {
super.setUp();
nativeSuperToken = sfDeployer.deployNativeAssetSuperToken("xFTT", "xFTT");
manager = new Manager(address(sf.cfa), MIN_LOWER, MIN_UPPER);
wrapStrategy = new WrapStrategy(address(manager));
}
function startStream(address sender, address receiver, int96 flowRate) public {
vm.startPrank(sender);
superToken.createFlow(receiver, flowRate);
vm.stopPrank();
}
function stopStream(address sender, address receiver) public {
vm.startPrank(sender);
superToken.deleteFlow(sender, receiver);
vm.stopPrank();
}
/// TESTS
function test_RevertWhen_DeploymentWithoutManager() public {
vm.expectRevert(IStrategy.ZeroAddress.selector);
new WrapStrategy(address(0));
}
function testDeploymentCheckData() public {
WrapStrategy wrap = new WrapStrategy(address(manager));
assertEq(address(manager), wrap.manager(), "manager address not equal");
}
// Manager operations
function testCannotChangeManagerContractIfNotOwner() public {
Manager newManager = new Manager(address(sf.cfa), MIN_LOWER, MIN_UPPER);
vm.prank(admin);
vm.expectRevert(bytes("Ownable: caller is not the owner"));
wrapStrategy.changeManager(address(newManager));
}
function testCannotChangeManagerZeroAddress() public {
vm.expectRevert(IStrategy.ZeroAddress.selector);
wrapStrategy.changeManager(address(0));
}
function testChangeManagerContract() public {
Manager newManager = new Manager(address(sf.cfa), MIN_LOWER, MIN_UPPER);
vm.expectEmit(true, true, true, true);
emit ManagerChanged(address(manager), address(newManager));
wrapStrategy.changeManager(address(newManager));
}
// SuperToken
function testSupportedSuperToken() public {
assertTrue(
wrapStrategy.isSupportedSuperToken(superToken),
"SuperToken should be supported"
);
}
function testCannotNonSupportedSuperToken() public {
assertTrue(
!wrapStrategy.isSupportedSuperToken(nativeSuperToken),
"Native SuperToken shouldn't be supported"
);
}
// Wrap Strategy Operations
function testCannotPerformWrapIfNotManager() public {
vm.prank(alice);
vm.expectRevert(abi.encodeWithSelector(IStrategy.UnauthorizedCaller.selector, alice, address(manager)));
wrapStrategy.wrap(bob, superToken, 1);
}
}