forked from foundry-rs/foundry
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStore.t.sol
More file actions
46 lines (36 loc) · 1.58 KB
/
Copy pathStore.t.sol
File metadata and controls
46 lines (36 loc) · 1.58 KB
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
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.18;
import "ds-test/test.sol";
import "cheats/Vm.sol";
contract Storage {
uint256 public slot0 = 10;
uint256 public slot1 = 20;
}
contract StoreTest is DSTest {
Vm constant vm = Vm(HEVM_ADDRESS);
Storage store;
function setUp() public {
store = new Storage();
}
function testStore() public {
assertEq(store.slot0(), 10, "initial value for slot 0 is incorrect");
assertEq(store.slot1(), 20, "initial value for slot 1 is incorrect");
vm.store(address(store), bytes32(0), bytes32(uint256(1)));
assertEq(store.slot0(), 1, "store failed");
assertEq(store.slot1(), 20, "store failed");
}
function testStoreNotAvailableOnPrecompiles() public {
assertEq(store.slot0(), 10, "initial value for slot 0 is incorrect");
assertEq(store.slot1(), 20, "initial value for slot 1 is incorrect");
vm._expectCheatcodeRevert("cannot use precompile 0x0000000000000000000000000000000000000001 as an argument");
vm.store(address(1), bytes32(0), bytes32(uint256(1)));
}
function testStoreFuzzed(uint256 slot0, uint256 slot1) public {
assertEq(store.slot0(), 10, "initial value for slot 0 is incorrect");
assertEq(store.slot1(), 20, "initial value for slot 1 is incorrect");
vm.store(address(store), bytes32(0), bytes32(slot0));
vm.store(address(store), bytes32(uint256(1)), bytes32(slot1));
assertEq(store.slot0(), slot0, "store failed");
assertEq(store.slot1(), slot1, "store failed");
}
}