-
Notifications
You must be signed in to change notification settings - Fork 7
/
AccessControl.t.sol
36 lines (29 loc) · 1.22 KB
/
AccessControl.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
pragma solidity 0.8.20;
import "forge-std/Test.sol";
import {AccessControl} from "../../src/accesscontrol/AccessControl.sol";
import {RewardsBox} from "../../src/accesscontrol/RewardsBox.sol";
import {Attack} from "./Attack.sol";
import {ERC20} from "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
contract AccessControlTest is Test {
ERC20 public reward;
RewardsBox public rewardsBox;
uint256 public rewardAmount = 1e18;
function setUp() public {
reward = new ERC20("Wrapped Ether", "WETH");
rewardsBox = new RewardsBox(address(reward), address(new AccessControl()));
deal(address(reward), address(rewardsBox), rewardAmount);
}
function testFail_claim() public {
AccessControl accessController = new AccessControl();
rewardsBox.claim(address(accessController), 1);
}
function test_codeHash() public {
AccessControl accessController = new AccessControl();
require(address(accessController).codehash == rewardsBox.accessControlHash());
}
function test_attackSuccess() public {
Attack attack = new Attack();
attack.pwn(address(rewardsBox), address(reward));
require(reward.balanceOf(address(this)) == 1e18);
}
}