From d8a60a82014f615b471035ef25b49c574ab42faa Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Mon, 27 Aug 2018 09:43:29 -0300 Subject: [PATCH] fix merkle tree tool to latest web3 --- test/merkleproof.spec.js | 22 ++++++++++------------ utils/merkleTree.js | 4 ++-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/test/merkleproof.spec.js b/test/merkleproof.spec.js index 504a71c..6094faa 100644 --- a/test/merkleproof.spec.js +++ b/test/merkleproof.spec.js @@ -23,12 +23,10 @@ contract('MerkleProof', function () { const proof = merkleTree.getHexProof(elements[0]); const leaf = bufferToHex(sha3(elements[0])); - console.log(root); - console.log(proof); - console.log(leaf); - var result = await MerkleProofWrapper.methods.verifyProof(proof, root, leaf).call(); - console.log(result); - //assert(result, true); + + const result = await MerkleProofWrapper.methods.verifyProof(proof, root, leaf).call(); + + assert(result); }); it('should return false for an invalid Merkle proof', async function () { @@ -44,9 +42,9 @@ contract('MerkleProof', function () { const badProof = badMerkleTree.getHexProof(badElements[0]); - var result = await MerkleProofWrapper.methods.verifyProof(badProof, correctRoot, correctLeaf).call(); - console.log(result); - //assert(result, false); + const result = await MerkleProofWrapper.methods.verifyProof(badProof, correctRoot, correctLeaf).call(); + + assert(!result); }); it('should return false for a Merkle proof of invalid length', async function () { @@ -60,9 +58,9 @@ contract('MerkleProof', function () { const leaf = bufferToHex(sha3(elements[0])); - var result = await MerkleProofWrapper.methods.verifyProof(badProof, root, leaf).call() - console.log(result); - //assert(result, false); + const result = await MerkleProofWrapper.methods.verifyProof(badProof, root, leaf).call() + + assert(!result); }); }); }); diff --git a/utils/merkleTree.js b/utils/merkleTree.js index a8f4b7c..bdc7e80 100644 --- a/utils/merkleTree.js +++ b/utils/merkleTree.js @@ -121,8 +121,8 @@ class MerkleTree { if (arr.some(el => !Buffer.isBuffer(el))) { throw new Error("Array is not an array of buffers"); } - - return "0x" + arr.map(el => el.toString("hex")).join(""); + + return arr.map(el => '0x' + el.toString('hex')); } sortAndConcat(...args) {