Skip to content

Commit

Permalink
extra test
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
jsign committed Oct 4, 2023
1 parent 6907863 commit a50c940
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ func TestProofOfAbsenceBorderCase(t *testing.T) {
key2, _ := hex.DecodeString("0001000000000000000000000000000000000000000000000000000000000001")

// Insert an arbitrary value at key 0000000000000000000000000000000000000000000000000000000000000001
root.Insert(oneKeyTest, fourtyKeyTest, nil)
root.Insert(key1, fourtyKeyTest, nil)

// Generate a proof for the following keys:
// - key1, which is present.
Expand Down Expand Up @@ -940,3 +940,38 @@ func TestProofOfAbsenceBorderCase(t *testing.T) {
t.Fatal("differing commitment for child #0")
}
}

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

key1, _ := hex.DecodeString("00000000000000000000000000000000000000000000000000000000000000fe")
key2, _ := hex.DecodeString("01000000000000000000000000000000000000000000000000000000000000fe")

root.Insert(key1, fourtyKeyTest, nil)
root.Insert(key2, fourtyKeyTest, nil)

proof, _, _, _, _ := MakeVerkleMultiProof(root, keylist{key1, key2})

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 := TreeFromProof(dproof, root.Commit())
if err != nil {
t.Fatal(err)
}

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

if !Equal(droot.(*InternalNode).children[0].Commit(), root.(*InternalNode).children[0].Commit()) {
t.Fatal("differing commitment for child #0")
}
}

0 comments on commit a50c940

Please sign in to comment.