-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOwnableWithGuardian.t.sol
56 lines (44 loc) · 1.63 KB
/
OwnableWithGuardian.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import 'forge-std/Test.sol';
import {OwnableWithGuardian} from '../src/contracts/access-control/OwnableWithGuardian.sol';
contract ImplOwnableWithGuardian is OwnableWithGuardian {
function mock_onlyGuardian() external onlyGuardian {}
function mock_onlyOwnerOrGuardian() external onlyOwnerOrGuardian {}
}
contract TestOfOwnableWithGuardian is Test {
ImplOwnableWithGuardian public withGuardian;
address owner = makeAddr('owner');
address guardian = makeAddr('guardian');
function setUp() public {
withGuardian = new ImplOwnableWithGuardian();
assertEq(withGuardian.owner(), address(this));
assertEq(withGuardian.guardian(), address(this));
withGuardian.transferOwnership(owner);
withGuardian.updateGuardian(guardian);
}
function testConstructorLogic() external view {
assertEq(withGuardian.owner(), owner);
assertEq(withGuardian.guardian(), guardian);
}
function testGuardianUpdateViaGuardian(address newGuardian) external {
vm.startPrank(guardian);
withGuardian.updateGuardian(newGuardian);
}
function testGuardianUpdateViaOwner(address newGuardian) external {
vm.prank(owner);
withGuardian.updateGuardian(newGuardian);
}
function testGuardianUpdateNoAccess() external {
vm.expectRevert('ONLY_BY_OWNER_OR_GUARDIAN');
withGuardian.updateGuardian(guardian);
}
function test_onlyGuardianGuard() external {
vm.prank(guardian);
withGuardian.mock_onlyGuardian();
}
function test_onlyGuardianGuard_shouldRevert() external {
vm.expectRevert('ONLY_BY_GUARDIAN');
withGuardian.mock_onlyGuardian();
}
}