-
Notifications
You must be signed in to change notification settings - Fork 21
/
Switch.t.sol
51 lines (44 loc) · 2.47 KB
/
Switch.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "forge-std/Test.sol";
import "./SwitchFactory.sol";
contract SwitchTest is Test {
SwitchFactory factory;
address switchInstance;
function setUp() public {
factory = new SwitchFactory();
switchInstance = factory.createInstance(address(this));
}
function testSwitch() public {
bytes memory data = abi.encodeWithSelector(
bytes4(keccak256("flipSwitch(bytes)")), abi.encodeWithSelector(bytes4(keccak256("turnSwitchOff()")))
);
/**
* 0x30c13ade // selector of flipSwitch(bytes)
* 0000000000000000000000000000000000000000000000000000000000000020 // offset of _data
* 0000000000000000000000000000000000000000000000000000000000000004 // length of _data
* 20606e1500000000000000000000000000000000000000000000000000000000 // selector of turnSwitchOff()
*/
(bool success, bytes memory err) = switchInstance.call(data);
if (!success) {
console.logBytes(err);
}
assertTrue(!Switch(switchInstance).switchOn());
/**
* 0x30c13ade // selector of flipSwitch(bytes)
* 0000000000000000000000000000000000000000000000000000000000000060 // offset of _data
* ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff // placeholder, content doesn't matter, length is 32 bytes
* 20606e1500000000000000000000000000000000000000000000000000000000 // selector of turnSwitchOff()
* 0000000000000000000000000000000000000000000000000000000000000004 // length of _data
* 76227e1200000000000000000000000000000000000000000000000000000000 // selector of turnSwitchOn()
*/
data =
hex"30c13ade0000000000000000000000000000000000000000000000000000000000000060ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff20606e1500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000476227e1200000000000000000000000000000000000000000000000000000000";
(success, err) = switchInstance.call(data);
if (!success) {
console.logBytes(err);
}
assertTrue(Switch(switchInstance).switchOn());
assertTrue(factory.validateInstance(payable(switchInstance), address(this)));
}
}