forked from RareSkills/huff-puzzles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Donations.t.sol
63 lines (56 loc) · 2.05 KB
/
Donations.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
58
59
60
61
62
63
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.19;
import "forge-std/Test.sol";
import {HuffConfig} from "foundry-huff/HuffConfig.sol";
import {HuffDeployer} from "foundry-huff/HuffDeployer.sol";
interface Donations {
function donated(address user) external view returns (uint256);
}
contract DonationsTest is Test {
Donations public donations;
function setUp() public {
donations = Donations(HuffDeployer.config().deploy("Donations"));
}
function testDonations() public {
// first party
vm.deal(address(this), 1 ether);
(bool success, ) = address(donations).call{value: 0.5 ether}("");
require(success, "call failed");
assertEq(
donations.donated(address(this)),
0.5 ether,
"expected donated balance of address(this) to be 0.5 ether"
);
(success, ) = address(donations).call{value: 0.2 ether}("");
require(success, "call failed");
assertEq(
donations.donated(address(this)),
0.7 ether,
"expected donated balance of address(this) to be 0.7 ether"
);
// second party
startHoax(address(0xCAFE), 1 ether);
(success, ) = address(donations).call{value: 0.5 ether}("");
require(success, "call failed");
assertEq(
donations.donated(address(0xCAFE)),
0.5 ether,
"expected donated balance of address(0xCAFE) to be 0.5 ether"
);
(success, ) = address(donations).call{value: 0.3 ether}("");
require(success, "call failed");
assertEq(
donations.donated(address(0xCAFE)),
0.8 ether,
"expected donated balance of address(0xCAFE) to be 0.8 ether"
);
// try send 0
(success, ) = address(donations).call{value: 0 ether}("");
require(success, "call failed");
assertEq(
donations.donated(address(0xCAFE)),
0.8 ether,
"expected donated balance of address(0xCAFE) to be 0.8 ether"
);
}
}