-
Notifications
You must be signed in to change notification settings - Fork 0
/
Greeter.t.sol
42 lines (32 loc) · 1.26 KB
/
Greeter.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
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.15;
import "forge-std/Test.sol";
import {Greeter} from "src/Greeter.sol";
contract GreeterTest is Test {
using stdStorage for StdStorage;
Greeter greeter;
event GMEverybodyGM();
function setUp() external {
greeter = new Greeter("gm");
}
// VM Cheatcodes can be found in ./lib/forge-std/src/Vm.sol
// Or at https://github.com/foundry-rs/forge-std
function testSetGm() external {
// slither-disable-next-line reentrancy-events,reentrancy-benign
greeter.setGreeting("gm gm");
// Expect the GMEverybodyGM event to be fired
vm.expectEmit(true, true, true, true);
emit GMEverybodyGM();
// slither-disable-next-line unused-return
greeter.gm("gm gm");
// Expect the gm() call to revert
vm.expectRevert(abi.encodeWithSignature("BadGm()"));
// slither-disable-next-line unused-return
greeter.gm("gm");
// We can read slots directly
uint256 slot = stdstore.target(address(greeter)).sig(greeter.owner.selector).find();
assertEq(slot, 1);
bytes32 owner = vm.load(address(greeter), bytes32(slot));
assertEq(address(this), address(uint160(uint256(owner))));
}
}