Skip to content

Commit

Permalink
test(embedded/tbtree): validate appended data inclusion
Browse files Browse the repository at this point in the history
Signed-off-by: Jeronimo Irazabal <jeronimo.irazabal@gmail.com>
  • Loading branch information
jeroiraz committed Apr 28, 2021
1 parent 5c0345b commit 69280e5
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions embedded/ahtree/ahtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,42 @@ func TestAppend(t *testing.T) {
require.NoError(t, err)
}

func TestIntegrity(t *testing.T) {
tree, err := Open("ahtree_test", DefaultOptions().WithSynced(false))
require.NoError(t, err)
defer os.RemoveAll("ahtree_test")

N := 1024

for i := 1; i <= N; i++ {
_, _, err := tree.Append([]byte{byte(i)})
require.NoError(t, err)
}

n, _, err := tree.Root()
require.NoError(t, err)

for i := uint64(1); i <= n; i++ {
r, err := tree.RootAt(i)
require.NoError(t, err)

for j := uint64(1); j <= i; j++ {
iproof, err := tree.InclusionProof(j, i)
require.NoError(t, err)

d, err := tree.DataAt(j)
require.NoError(t, err)

pd := make([]byte, 1+len(d))
pd[0] = LeafPrefix
copy(pd[1:], d)

verifies := VerifyInclusion(iproof, j, i, sha256.Sum256(pd), r)
require.True(t, verifies)
}
}
}

func TestInclusionAndConsistencyProofs(t *testing.T) {
tree, err := Open("ahtree_test", DefaultOptions().WithSynced(false))
require.NoError(t, err)
Expand Down

0 comments on commit 69280e5

Please sign in to comment.