Skip to content

Commit

Permalink
add extra border case test
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
jsign committed Nov 3, 2023
1 parent 09c9c79 commit 156d92b
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1217,3 +1217,49 @@ func TestDoubleProofOfAbsence(t *testing.T) {
t.Fatalf("invalid number of proof-of-absence stems: %d", len(proof.PoaStems))
}
}

func TestProveAbsenceInEmptyHalf(t *testing.T) {
root := New()

key1, _ := hex.DecodeString("00000000000000000000000000000000000000000000000000000000000000FF")

if err := root.Insert(key1, fourtyKeyTest, nil); err != nil {
t.Fatalf("could not insert key: %v", err)
}
if err := root.Insert(key1, fourtyKeyTest, nil); err != nil {
t.Fatalf("could not insert key: %v", err)
}

key2, _ := hex.DecodeString("0000000000000000000000000000000000000000000000000000000000000000")
proof, _, _, _, _ := MakeVerkleMultiProof(root, nil, keylist{key2}, nil)

serialized, statediff, err := SerializeProof(proof)
if err != nil {
t.Fatalf("could not serialize proof: %v", err)
}

dproof, err := DeserializeProof(serialized, statediff)
if err != nil {
t.Fatalf("error deserializing proof: %v", err)
}

droot, err := PreStateTreeFromProof(dproof, root.Commit())
if err != nil {
t.Fatal(err)
}

if !droot.Commit().Equal(root.Commit()) {
t.Fatal("differing root commitments")
}

// Depite we have two proof of absences for different steams, we should only have one
// stem in `others`. i.e: we only need one for both steams.
if len(proof.PoaStems) != 1 {
t.Fatalf("invalid number of proof-of-absence stems: %d", len(proof.PoaStems))
}

// We need one extension status for each stem.
if len(proof.ExtStatus) != 2 {
t.Fatalf("invalid number of proof-of-absence stems: %d", len(proof.PoaStems))
}
}

0 comments on commit 156d92b

Please sign in to comment.