-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestTokenWhitelistRegistry.t.sol
129 lines (106 loc) · 4.82 KB
/
TestTokenWhitelistRegistry.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
117
118
119
120
121
122
123
124
125
126
127
128
129
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >=0.8.18;
import {Test} from "@forge-std/Test.sol";
import {TokenWhitelistRegistry} from "@src/base/TokenWhitelistRegistry.sol";
import {ProtocolState} from "@src/base/ProtocolState.sol";
import "@src/base/ProtocolAccessController.sol";
import "@src/base/ProtocolAddressRegistry.sol";
contract TestTokenWhitelistRegistry is Test {
TokenWhitelistRegistry public registry;
IProtocolAddressRegistry public addressRegistry;
ProtocolState public protocolState;
function setUp() public {
ProtocolAccessController accessController = new ProtocolAccessController(address(this));
addressRegistry =
IProtocolAddressRegistry(new ProtocolAddressRegistry(address(accessController)));
protocolState = new ProtocolState(addressRegistry);
registry = new TokenWhitelistRegistry(addressRegistry);
addressRegistry.setProtocolState(address(protocolState));
addressRegistry.setTokenWhitelistRegistry(address(registry));
}
modifier validAddress(address addr) {
vm.assume(addr != address(0));
vm.assume(addr != address(this));
vm.assume(!addressRegistry.isRegistered(addr));
_;
}
function test_whitelist_token(address token, address otherToken, address router)
external
validAddress(token)
validAddress(otherToken)
validAddress(router)
{
vm.assume(router != token);
vm.assume(router != otherToken);
vm.assume(token != otherToken);
registry.whitelistToken(router, token);
assertFalse(registry.isTokenWhitelisted(address(this), router, otherToken));
assertFalse(registry.isTokenWhitelisted(address(this), otherToken, router));
assertFalse(registry.isTokenWhitelisted(address(this), token, router));
assertTrue(registry.isTokenWhitelisted(address(this), router, token));
}
function test_blacklist_token(address token, address otherToken, address router)
external
validAddress(token)
validAddress(otherToken)
validAddress(router)
{
vm.assume(router != token);
vm.assume(router != otherToken);
vm.assume(token != otherToken);
registry.whitelistToken(router, token);
registry.blacklistToken(router, token);
assertFalse(registry.isTokenWhitelisted(address(this), router, token));
assertFalse(registry.isTokenWhitelisted(address(this), router, otherToken));
assertFalse(registry.isTokenWhitelisted(address(this), otherToken, router));
assertFalse(registry.isTokenWhitelisted(address(this), token, router));
}
function test_cannot_whitelist_self_as_token() public {
vm.expectRevert("TokenWhitelistRegistry: sender address");
registry.whitelistToken(address(999), address(this));
}
function test_cannot_whitelist_self_as_router() public {
vm.expectRevert("TokenWhitelistRegistry: sender address");
registry.whitelistToken(address(this), address(999));
}
function test_cannot_whitelist_zero_as_token() public {
vm.expectRevert("TokenWhitelistRegistry: zero address");
registry.whitelistToken(address(999), address(0));
}
function test_cannot_whitelist_zero_as_router() public {
vm.expectRevert("TokenWhitelistRegistry: zero address");
registry.whitelistToken(address(0), address(999));
}
function test_cannot_whitelist_registry_as_token() public {
vm.expectRevert("TokenWhitelistRegistry: self address");
registry.whitelistToken(address(registry), address(999));
}
function test_cannot_whitelist_registry_as_router() public {
vm.expectRevert("TokenWhitelistRegistry: self address");
registry.whitelistToken(address(999), address(registry));
}
function test_cannot_whitelist_reserved_address_as_router() public {
vm.expectRevert("TokenWhitelistRegistry: reserved address");
registry.whitelistToken(address(addressRegistry), address(999));
}
function test_cannot_whitelist_reserved_address_as_token() public {
vm.expectRevert("TokenWhitelistRegistry: reserved address");
registry.whitelistToken(address(999), address(addressRegistry));
}
function test_cannot_whitelist_when_paused() public {
protocolState.pause();
vm.expectRevert("ProtocolState: stopped");
registry.whitelistToken(address(this), address(this));
}
function test_can_blacklist_when_paused(address token, address router)
public
validAddress(token)
validAddress(router)
{
vm.assume(router != token);
registry.whitelistToken(router, token);
protocolState.pause();
registry.blacklistToken(router, token);
assertFalse(registry.isTokenWhitelisted(address(this), router, token));
}
}