-
Notifications
You must be signed in to change notification settings - Fork 21
/
CoinFlip.t.sol
34 lines (25 loc) · 951 Bytes
/
CoinFlip.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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "forge-std/Test.sol";
import "./CoinFlipFactory.sol";
contract CoinFlipTest is Test {
CoinFlipFactory factory;
uint256 FACTOR = 57896044618658097711785492504343953926634992332820282019728792003956564819968;
function setUp() public {
factory = new CoinFlipFactory();
}
function flip() internal view returns (bool) {
uint256 blockValue = uint256(blockhash(block.number - 1));
uint256 coinFlip = blockValue / FACTOR;
bool side = coinFlip == 1 ? true : false;
return side;
}
function testCoinFlip() public {
address coinFlip = factory.createInstance(address(this));
for (uint256 i = 0; i < 10; i++) {
CoinFlip(coinFlip).flip(flip());
vm.roll(block.number + 1);
}
assertTrue(factory.validateInstance(payable(address(coinFlip)), address(this)));
}
}