Created
April 15, 2018 07:13
-
-
Save saurfang/76f46eeecb8b6eefe3e2518b0b0404e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.21; | |
contract Miner { | |
uint public blockNumber; | |
uint public blocks; | |
function Miner() public { | |
reset(); | |
} | |
function reset() public { | |
blockNumber = block.number; | |
blocks = 0; | |
} | |
function mine() public { | |
blocks = block.number - blockNumber; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const PredictTheBlockHashChallenge = artifacts.require('PredictTheBlockHashChallenge'); | |
const Miner = artifacts.require('Miner'); | |
contract('PredictTheBlockHashChallenge', ([account]) => { | |
it('can be solved', async () => { | |
let challenge = await PredictTheBlockHashChallenge.new({value: web3.toWei(1, 'ether')}); | |
let miner = await Miner.new(); | |
// guess with '0x' | |
await challenge.lockInGuess('', {value: web3.toWei(1, 'ether')}); | |
// call miner for 256 blocks | |
await miner.reset(); | |
while (await miner.blocks() < 256) { | |
await miner.mine(); | |
} | |
challenge.settle(); | |
assert( | |
await challenge.isComplete() === true, | |
'Challenge has not been completed!' | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment