Commit 50bfcebc authored by George Hotz's avatar George Hotz

get challenge id

parent bc1822e7
...@@ -55,6 +55,7 @@ contract Challenge { ...@@ -55,6 +55,7 @@ contract Challenge {
// create challenge // create challenge
uint256 public lastChallengeId = 0; uint256 public lastChallengeId = 0;
event ChallengeCreate(uint256 challengeId);
function newChallengeTrusted(bytes32 startState, bytes32 finalSystemState, uint256 stepCount) internal returns (uint256) { function newChallengeTrusted(bytes32 startState, bytes32 finalSystemState, uint256 stepCount) internal returns (uint256) {
uint256 challengeId = lastChallengeId; uint256 challengeId = lastChallengeId;
Chal storage c = challenges[challengeId]; Chal storage c = challenges[challengeId];
...@@ -73,6 +74,7 @@ contract Challenge { ...@@ -73,6 +74,7 @@ contract Challenge {
c.R = stepCount; c.R = stepCount;
// find me later // find me later
emit ChallengeCreate(challengeId);
return challengeId; return challengeId;
} }
......
...@@ -30,7 +30,7 @@ describe("Challenge contract", function () { ...@@ -30,7 +30,7 @@ describe("Challenge contract", function () {
let preimages = Object.assign({}, startTrie['preimages'], finalTrie['preimages']); let preimages = Object.assign({}, startTrie['preimages'], finalTrie['preimages']);
const finalSystemState = finalTrie['root'] const finalSystemState = finalTrie['root']
let args = [blockNumberN, blockNp1Rlp, assertionRoot, finalSystemState, 1] let args = [blockNumberN, blockNp1Rlp, assertionRoot, finalSystemState, finalTrie['step']]
let cdat = c.interface.encodeFunctionData("InitiateChallenge", args) let cdat = c.interface.encodeFunctionData("InitiateChallenge", args)
let nodes = await getTrieNodesForCall(c, cdat, preimages) let nodes = await getTrieNodesForCall(c, cdat, preimages)
...@@ -39,6 +39,9 @@ describe("Challenge contract", function () { ...@@ -39,6 +39,9 @@ describe("Challenge contract", function () {
await mm.AddTrieNode(n) await mm.AddTrieNode(n)
} }
let ret = await c.InitiateChallenge(...args) let ret = await c.InitiateChallenge(...args)
console.log(await ret.wait()) let receipt = await ret.wait()
// ChallengeCreate event
let challengeId = receipt.events[0].args['challengeId'].toNumber()
console.log("new challenge with id", challengeId)
}).timeout(60000) }).timeout(60000)
}) })
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment