Skip to content

Commit

Permalink
add non-membership tests
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann committed Nov 5, 2024
1 parent b511c95 commit 66c5c3e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions core/trie/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ func newBinaryProofNode() *trie.Binary {
}

func TestProve(t *testing.T) {
t.Parallel()

t.Run("simple binary", func(t *testing.T) {
tempTrie := buildSimpleTrie(t)

Expand Down Expand Up @@ -521,6 +523,8 @@ func TestProve(t *testing.T) {
}

func TestProveNKeys(t *testing.T) {
t.Parallel()

n := 10000
tempTrie := buildTrieWithNKeys(t, n)

Expand All @@ -543,6 +547,31 @@ func TestProveNKeys(t *testing.T) {
}
}

func TestProveNKeysWithNonExistentKeys(t *testing.T) {
t.Parallel()

n := 10000
tempTrie := buildTrieWithNKeys(t, n)

for i := 1; i < n+1; i++ {
keyFelt := new(felt.Felt).SetUint64(uint64(i + n))
key := tempTrie.FeltToKey(keyFelt)

proofSet := trie.NewProofSet()
err := tempTrie.Prove(keyFelt, proofSet)
require.NoError(t, err)

root, err := tempTrie.Root()
require.NoError(t, err)

val, err := trie.VerifyProof(root, &key, proofSet, crypto.Pedersen)
if err != nil {
t.Fatalf("failed for key %s", key.String())
}
require.Equal(t, &felt.Zero, val)
}
}

func TestProveRandomTrie(t *testing.T) {
n := 1000
tempTrie, keys := buildRandomTrie(t, n)
Expand Down

0 comments on commit 66c5c3e

Please sign in to comment.