-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestRouterWhitelistRegistry.t.sol
94 lines (76 loc) · 3.29 KB
/
TestRouterWhitelistRegistry.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
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >=0.8.18;
import {Test, console2} from "@forge-std/Test.sol";
import {RouterWhitelistRegistry} from "@src/base/RouterWhitelistRegistry.sol";
import {ProtocolState} from "@src/base/ProtocolState.sol";
import "@src/base/ProtocolAccessController.sol";
import "@src/base/ProtocolAddressRegistry.sol";
contract TestRouterWhitelistRegistry is Test {
RouterWhitelistRegistry 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 RouterWhitelistRegistry(addressRegistry);
addressRegistry.setProtocolState(address(protocolState));
addressRegistry.setRouterWhitelistRegistry(address(registry));
}
modifier validAddress(address router) {
vm.assume(router != address(0));
vm.assume(router != address(this));
vm.assume(router != address(registry));
vm.assume(!addressRegistry.isRegistered(router));
_;
}
function test_whitelist_router(address router, address otherRouter)
external
validAddress(router)
validAddress(otherRouter)
{
vm.assume(router != otherRouter);
registry.whitelistRouter(router);
assertFalse(registry.isRouterWhitelisted(address(this), otherRouter));
assertTrue(registry.isRouterWhitelisted(address(this), router));
}
function test_blacklist_router(address router, address otherRouter)
external
validAddress(router)
validAddress(otherRouter)
{
vm.assume(router != otherRouter);
registry.whitelistRouter(router);
registry.blacklistRouter(router);
assertFalse(registry.isRouterWhitelisted(address(this), router));
assertFalse(registry.isRouterWhitelisted(address(this), otherRouter));
}
function test_cannot_whitelist_self() public {
vm.expectRevert("RouterWhitelistRegistry: sender address");
registry.whitelistRouter(address(this));
}
function test_cannot_whitelist_zero() public {
vm.expectRevert("RouterWhitelistRegistry: zero address");
registry.whitelistRouter(address(0));
}
function test_cannot_whitelist_registry() public {
vm.expectRevert("RouterWhitelistRegistry: self address");
registry.whitelistRouter(address(registry));
}
function test_cannot_whitelist_reserved_address() public {
vm.expectRevert("RouterWhitelistRegistry: reserved address");
registry.whitelistRouter(address(addressRegistry));
}
function test_cannot_whitelist_when_paused() public {
protocolState.pause();
vm.expectRevert("ProtocolState: stopped");
registry.whitelistRouter(address(this));
}
function test_can_blacklist_when_paused(address router) public validAddress(router) {
registry.whitelistRouter(router);
protocolState.pause();
registry.blacklistRouter(router);
assertFalse(registry.isRouterWhitelisted(address(this), router));
}
}