Skip to content

Commit aea74d4

Browse files
committed
add a test to check the corner case of the stateless root (#160)
1 parent 60e681e commit aea74d4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

stateless_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,25 @@ func TestStatelessGet(t *testing.T) {
195195
}
196196
}
197197

198+
func TestStatelessComputeCommitmentEmptyRoot(t *testing.T) {
199+
root := &StatelessNode{}
200+
root.ComputeCommitment()
201+
if !Equal(root.hash, &FrZero) {
202+
t.Fatal("invalid commitment for the empty root")
203+
}
204+
205+
root.depth = 10
206+
root.hash = nil
207+
defer func() {
208+
if err := recover(); err == nil {
209+
t.Fatal("should have caught the computation of an invalid node")
210+
}
211+
}()
212+
root.ComputeCommitment()
213+
214+
t.Fatal("should have panicked before")
215+
}
216+
198217
func TestStatelessToDot(t *testing.T) {
199218
key1, _ := hex.DecodeString("0000100000000000000000000000000000000000000000000000000000000000")
200219
root := NewStateless()

0 commit comments

Comments
 (0)