aboutsummaryrefslogtreecommitdiff
path: root/internal/merkle/tree_test.go
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-26 15:41:45 -0800
committerFuwn <[email protected]>2026-02-26 15:41:45 -0800
commitfec9114caaa7d274e524793d5eb0cf2ef2c5af11 (patch)
tree0897394ccdfaf6633e1a4ca8eb02bff49bb93c00 /internal/merkle/tree_test.go
parentfeat: add read-only PLC API compatibility endpoints (diff)
downloadplutia-test-fec9114caaa7d274e524793d5eb0cf2ef2c5af11.tar.xz
plutia-test-fec9114caaa7d274e524793d5eb0cf2ef2c5af11.zip
feat: Apply Iku formatting
Diffstat (limited to 'internal/merkle/tree_test.go')
-rw-r--r--internal/merkle/tree_test.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/internal/merkle/tree_test.go b/internal/merkle/tree_test.go
index 9fa791d..b2546a8 100644
--- a/internal/merkle/tree_test.go
+++ b/internal/merkle/tree_test.go
@@ -9,12 +9,14 @@ import (
func TestRootAndProof(t *testing.T) {
inputs := [][]byte{HashLeaf([]byte("a")), HashLeaf([]byte("b")), HashLeaf([]byte("c"))}
root := Root(inputs)
+
if len(root) == 0 {
t.Fatalf("expected root")
}
for i := range inputs {
proof := BuildProof(inputs, i)
+
if !VerifyProof(inputs[i], proof, root) {
t.Fatalf("proof verification failed for index %d", i)
}
@@ -23,6 +25,7 @@ func TestRootAndProof(t *testing.T) {
func TestRootEmpty(t *testing.T) {
r := Root(nil)
+
if got := hex.EncodeToString(r); got != "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" {
t.Fatalf("unexpected empty root: %s", got)
}
@@ -32,13 +35,17 @@ func TestAccumulatorRootMatchesRoot(t *testing.T) {
for n := 1; n <= 128; n++ {
leaves := make([][]byte, 0, n)
acc := NewAccumulator()
+
for i := 0; i < n; i++ {
leaf := HashLeaf([]byte(fmt.Sprintf("leaf-%d", i)))
leaves = append(leaves, leaf)
+
acc.AddLeafHash(leaf)
}
+
want := hex.EncodeToString(Root(leaves))
got := hex.EncodeToString(acc.RootDuplicateLast())
+
if got != want {
t.Fatalf("root mismatch n=%d got=%s want=%s", n, got, want)
}