Skip to content

Instantly share code, notes, and snippets.

@kcalvinalvin
Created August 29, 2022 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kcalvinalvin/b3df7fca74f38555228e07b29e2bf47d to your computer and use it in GitHub Desktop.
Save kcalvinalvin/b3df7fca74f38555228e07b29e2bf47d to your computer and use it in GitHub Desktop.
Test function to verify that the code is incorrect
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