fix merkle tree tool to latest web3

This commit is contained in:
Ricardo Guilherme Schmidt 2018-08-27 09:43:29 -03:00 committed by Barry G
parent 725b68a69e
commit d8a60a8201
2 changed files with 12 additions and 14 deletions

View File

@ -23,12 +23,10 @@ contract('MerkleProof', function () {
const proof = merkleTree.getHexProof(elements[0]); const proof = merkleTree.getHexProof(elements[0]);
const leaf = bufferToHex(sha3(elements[0])); const leaf = bufferToHex(sha3(elements[0]));
console.log(root);
console.log(proof); const result = await MerkleProofWrapper.methods.verifyProof(proof, root, leaf).call();
console.log(leaf);
var result = await MerkleProofWrapper.methods.verifyProof(proof, root, leaf).call(); assert(result);
console.log(result);
//assert(result, true);
}); });
it('should return false for an invalid Merkle proof', async function () { it('should return false for an invalid Merkle proof', async function () {
@ -44,9 +42,9 @@ contract('MerkleProof', function () {
const badProof = badMerkleTree.getHexProof(badElements[0]); const badProof = badMerkleTree.getHexProof(badElements[0]);
var result = await MerkleProofWrapper.methods.verifyProof(badProof, correctRoot, correctLeaf).call(); const result = await MerkleProofWrapper.methods.verifyProof(badProof, correctRoot, correctLeaf).call();
console.log(result);
//assert(result, false); assert(!result);
}); });
it('should return false for a Merkle proof of invalid length', async function () { 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])); const leaf = bufferToHex(sha3(elements[0]));
var result = await MerkleProofWrapper.methods.verifyProof(badProof, root, leaf).call() const result = await MerkleProofWrapper.methods.verifyProof(badProof, root, leaf).call()
console.log(result);
//assert(result, false); assert(!result);
}); });
}); });
}); });

View File

@ -122,7 +122,7 @@ class MerkleTree {
throw new Error("Array is not an array of buffers"); 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) { sortAndConcat(...args) {