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
//SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
/* Testing utilities */
import { Test } from "forge-std/Test.sol";
import { CallRecorder } from "../testing/helpers/CallRecorder.sol";
import { Reverter } from "../testing/helpers/Reverter.sol";
import { Transactor } from "../universal/Transactor.sol";
contract Transactor_Initializer is Test {
address alice = address(128);
address bob = address(256);
Transactor transactor;
Reverter reverter;
CallRecorder callRecorded;
function setUp() public {
// Deploy Reverter and CallRecorder helper contracts
reverter = new Reverter();
callRecorded = new CallRecorder();
// Deploy Transactor contract
transactor = new Transactor(address(alice));
vm.label(address(transactor), "Transactor");
// Give alice and bob some ETH
vm.deal(alice, 1 ether);
vm.deal(bob, 1 ether);
vm.label(alice, "alice");
vm.label(bob, "bob");
}
}
contract TransactorTest is Transactor_Initializer {
// Tests if the owner was set correctly during deploy
function test_constructor() external {
assertEq(address(alice), transactor.owner());
}
// Tests CALL, should do a call to target
function test_CALL() external {
// Initialize call data
bytes memory data = abi.encodeWithSelector(callRecorded.record.selector);
// Run CALL
vm.prank(alice);
vm.expectCall(address(callRecorded), 200_000 wei, data);
transactor.CALL(address(callRecorded), data, 200_000 wei);
}
// It should revert if called by non-owner
function testFail_CALL() external {
// Initialize call data
bytes memory data = abi.encodeWithSelector(callRecorded.record.selector);
// Run CALL
vm.prank(bob);
transactor.CALL(address(callRecorded), data, 200_000 wei);
vm.expectRevert("UNAUTHORIZED");
}
function test_DELEGATECALL() external {
// Initialize call data
bytes memory data = abi.encodeWithSelector(reverter.doRevert.selector);
// Run CALL
vm.prank(alice);
vm.expectCall(address(reverter), data);
transactor.DELEGATECALL(address(reverter), data);
}
// It should revert if called by non-owner
function testFail_DELEGATECALLL() external {
// Initialize call data
bytes memory data = abi.encodeWithSelector(reverter.doRevert.selector);
// Run CALL
vm.prank(bob);
transactor.DELEGATECALL(address(reverter), data);
vm.expectRevert("UNAUTHORIZED");
}
}