package gnarlring import "testing" func TestChildCommitment(t *testing.T) { pk, _ := NTRUKeyGen() cc := NewChildCommitment(5, pk, nil) // nil rng uses crypto/rand via Default if cc.Index != 5 { t.Fatalf("index = %d, want 5", cc.Index) } if !Equal(cc.PubKey, pk.H) { t.Fatal("PubKey mismatch") } if IsZero(cc.W) { t.Fatal("W is zero — unlikely for fresh z") } } func TestAggregatedCommitment(t *testing.T) { pk, _ := NTRUKeyGen() ac := NewAggregatedCommitment() cc := NewChildCommitment(0, pk, nil) if !ac.Add(cc) { t.Fatal("Add failed") } if ac.Count != 1 { t.Fatalf("Count = %d, want 1", ac.Count) } if ac.Add(cc) { t.Fatal("Add should reject duplicate") } ac.Remove(0) if ac.Count != 0 { t.Fatalf("Count after remove = %d, want 0", ac.Count) } } func TestAggregatedTarget(t *testing.T) { pk, _ := NTRUKeyGen() ac := NewAggregatedCommitment() for i := 0; i < N; i++ { cc := NewChildCommitment(i, pk, nil) ac.Add(cc) } target1 := ac.Target([]byte("hello"), 0) target2 := ac.Target([]byte("hello"), 0) if !Equal(target1, target2) { t.Fatal("target not deterministic") } // Different message → different target. target3 := ac.Target([]byte("world"), 0) if Equal(target1, target3) { t.Fatal("different messages give same target") } // Different epoch → different target. target4 := ac.Target([]byte("hello"), 1) if Equal(target1, target4) { t.Fatal("different epochs give same target") } } func TestWCompressed(t *testing.T) { pk, _ := NTRUKeyGen() ac := NewAggregatedCommitment() for i := 0; i < N; i++ { cc := NewChildCommitment(i, pk, nil) ac.Add(cc) } wc1 := ac.WCompressed(0) wc2 := ac.WCompressed(0) if len(wc1) != 27 { t.Fatalf("WCompressed len = %d, want 27", len(wc1)) } if string(wc1) != string(wc2) { t.Fatal("WCompressed not deterministic") } }