Skip to content

Instantly share code, notes, and snippets.

@saurfang
Created April 15, 2018 01:59
Show Gist options
  • Save saurfang/a0a985bf1f44faa119477f7db51bf16b to your computer and use it in GitHub Desktop.
Save saurfang/a0a985bf1f44faa119477f7db51bf16b to your computer and use it in GitHub Desktop.
const GuessTheNewNumberChallenge = artifacts.require('GuessTheNewNumberChallenge');
const GuessTheNewNumberSolver = artifacts.require('GuessTheNewNumberSolver');
contract('GuessTheNewNumberSolver', ([account]) => {
it('should solve the challenge', async () => {
let challenge = await GuessTheNewNumberChallenge.new({value: web3.toWei(1, 'ether')});
let solver = await GuessTheNewNumberSolver.new();
await solver.guess(challenge.address, {value: web3.toWei(1, 'ether')});
assert(
await challenge.isComplete() === true,
'Challenge has not been completed!'
);
});
});
pragma solidity ^0.4.21;
import "./GuessTheNewNumberChallenge.sol";
contract GuessTheNewNumberSolver {
function guess(address _challenge)
public
payable {
require(msg.value == 1 ether);
uint8 answer = uint8(keccak256(block.blockhash(block.number - 1), now));
GuessTheNewNumberChallenge challenge = GuessTheNewNumberChallenge(_challenge);
challenge.guess.value(msg.value)(answer);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment