Created
August 29, 2022 06:41
-
-
Save kcalvinalvin/b3df7fca74f38555228e07b29e2bf47d to your computer and use it in GitHub Desktop.
Test function to verify that the code is incorrect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package patriciaaccumulator | |
import ( | |
"encoding/hex" | |
"fmt" | |
"os" | |
"path/filepath" | |
"testing" | |
) | |
func TestVerify(t *testing.T) { | |
path := "./utree/forestdata/" | |
err := os.MkdirAll(path, os.ModePerm) | |
defer os.RemoveAll(path) | |
defer os.RemoveAll("./utree") | |
if err != nil { | |
t.Fatal(err) | |
} | |
_, err = os.Create(filepath.Join(path, "forestfile0.dat")) | |
if err != nil { | |
t.Fatal(err) | |
} | |
f := NewForest(nil, false) | |
var leaves []Leaf | |
numLeaves := uint8(8) | |
for i := uint8(0); i < numLeaves; i++ { | |
hash := Hash{} | |
hash[0] = i + 1 | |
leaves = append(leaves, Leaf{Hash: hash}) | |
} | |
_, err = f.Modify(leaves, nil) | |
if err != nil { | |
t.Fatal(err) | |
} | |
proveHashes := []Hash{leaves[2].Hash, leaves[7].Hash} | |
bp, err := f.ProveBatch(proveHashes) | |
if err != nil { | |
t.Fatal(err) | |
} | |
fmt.Printf("Proof hash count: %d\n", len(bp.hashes)) | |
for _, hash := range bp.hashes { | |
fmt.Printf("proofhash: %s\n", hex.EncodeToString(hash[:])) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment