From 66c5c3e592eb81eadee9adb22784e890e50cadcc Mon Sep 17 00:00:00 2001 From: weiihann Date: Tue, 5 Nov 2024 22:06:47 +0800 Subject: [PATCH] add non-membership tests --- core/trie/proof_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/core/trie/proof_test.go b/core/trie/proof_test.go index ae2f68377a..f4133bbf97 100644 --- a/core/trie/proof_test.go +++ b/core/trie/proof_test.go @@ -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) @@ -521,6 +523,8 @@ func TestProve(t *testing.T) { } func TestProveNKeys(t *testing.T) { + t.Parallel() + n := 10000 tempTrie := buildTrieWithNKeys(t, n) @@ -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)