11import { assertEquals } from "https://deno.land/std@0.86.0/testing/asserts.ts"
22import { MerkleTree , Helper } from "../mod.ts"
33
4- const exampleArray = [ "dog" , "horse" , "cow" , "chicken" , "rabbit" , "bird" , "bee" , "me" ]
5-
64Deno . test ( "should return valid as the investigated entry is in array" , async ( ) => {
75
6+ const exampleArray = [ "dog" , "horse" , "cow" , "chicken" , "rabbit" , "bird" , "bee" , "me" ]
7+
88 for ( const investigatedEntry of exampleArray ) {
99 const merkleTree = new MerkleTree ( exampleArray )
1010
@@ -20,6 +20,8 @@ Deno.test("should return valid as the investigated entry is in array", async ()
2020
2121Deno . test ( "should return invalid as the investigated entry is not in array" , async ( ) => {
2222
23+ const exampleArray = [ "dog" , "horse" , "cow" , "chicken" , "rabbit" , "bird" , "bee" , "me" ]
24+
2325 const merkleTree = new MerkleTree ( exampleArray )
2426 const investigatedEntry = "an entry which is not in the array"
2527 const proof = merkleTree . getProofElements ( exampleArray . indexOf ( investigatedEntry ) )
@@ -30,3 +32,25 @@ Deno.test("should return invalid as the investigated entry is not in array", asy
3032 assertEquals ( isValid , false )
3133
3234} )
35+
36+
37+ Deno . test ( "should be able to utilize a custom hash function" , async ( ) => {
38+
39+ const exampleArray = [ 2 , 4 , 8 , 1 ]
40+
41+ const merkleTree = new MerkleTree ( exampleArray , ( x : number ) => x * 2 % 10 )
42+ const rootHash = merkleTree . getRootHash ( )
43+
44+ assertEquals ( rootHash , 8 )
45+
46+ const proof = merkleTree . getProofElements ( exampleArray . indexOf ( 1 ) )
47+ console . log ( proof )
48+
49+ const investigatedEntry = 1
50+ const investigatedEntryHashed = investigatedEntry * 2 % 10
51+ const isValid = merkleTree . verify ( proof , investigatedEntryHashed , rootHash , exampleArray . indexOf ( investigatedEntry ) )
52+
53+ assertEquals ( isValid , true )
54+
55+
56+ } )
0 commit comments