@@ -301,7 +301,47 @@ func Test_MerkleDB_Invalidate_Siblings_On_Commit(t *testing.T) {
301
301
require .False (viewToCommit .(* trieView ).isInvalid ())
302
302
}
303
303
304
- func Test_MerkleDB_Commit_Proof_To_Empty_Trie (t * testing.T ) {
304
+ func Test_MerkleDB_CommitRangeProof_DeletesValuesInRange (t * testing.T ) {
305
+ require := require .New (t )
306
+
307
+ db , err := getBasicDB ()
308
+ require .NoError (err )
309
+
310
+ // value that shouldn't be deleted
311
+ require .NoError (db .Put ([]byte ("key6" ), []byte ("3" )))
312
+
313
+ startRoot , err := db .GetMerkleRoot (context .Background ())
314
+ require .NoError (err )
315
+
316
+ // Get an empty proof
317
+ proof , err := db .GetRangeProof (
318
+ context .Background (),
319
+ maybe .Nothing [[]byte ](),
320
+ maybe .Some ([]byte ("key3" )),
321
+ 10 ,
322
+ )
323
+ require .NoError (err )
324
+
325
+ // confirm there are no key.values in the proof
326
+ require .Empty (proof .KeyValues )
327
+
328
+ // add values to be deleted by proof commit
329
+ batch := db .NewBatch ()
330
+ require .NoError (batch .Put ([]byte ("key1" ), []byte ("1" )))
331
+ require .NoError (batch .Put ([]byte ("key2" ), []byte ("2" )))
332
+ require .NoError (batch .Put ([]byte ("key3" ), []byte ("3" )))
333
+ require .NoError (batch .Write ())
334
+
335
+ // despite having no key/values in it, committing this proof should delete key1-key3.
336
+ require .NoError (db .CommitRangeProof (context .Background (), maybe .Nothing [[]byte ](), maybe .Some ([]byte ("key3" )), proof ))
337
+
338
+ afterCommitRoot , err := db .GetMerkleRoot (context .Background ())
339
+ require .NoError (err )
340
+
341
+ require .Equal (startRoot , afterCommitRoot )
342
+ }
343
+
344
+ func Test_MerkleDB_CommitRangeProof_EmptyTrie (t * testing.T ) {
305
345
require := require .New (t )
306
346
307
347
// Populate [db1] with 3 key-value pairs.
@@ -326,7 +366,7 @@ func Test_MerkleDB_Commit_Proof_To_Empty_Trie(t *testing.T) {
326
366
db2 , err := getBasicDB ()
327
367
require .NoError (err )
328
368
329
- require .NoError (db2 .CommitRangeProof (context .Background (), maybe .Some ([]byte ("key1" )), proof ))
369
+ require .NoError (db2 .CommitRangeProof (context .Background (), maybe .Some ([]byte ("key1" )), maybe . Some ([] byte ( "key3" )), proof ))
330
370
331
371
// [db2] should have the same key-value pairs as [db1].
332
372
db2Root , err := db2 .GetMerkleRoot (context .Background ())
@@ -338,7 +378,7 @@ func Test_MerkleDB_Commit_Proof_To_Empty_Trie(t *testing.T) {
338
378
require .Equal (db1Root , db2Root )
339
379
}
340
380
341
- func Test_MerkleDB_Commit_Proof_To_Filled_Trie (t * testing.T ) {
381
+ func Test_MerkleDB_CommitRangeProof_TrieWithInitialValues (t * testing.T ) {
342
382
require := require .New (t )
343
383
344
384
// Populate [db1] with 3 key-value pairs.
@@ -374,6 +414,7 @@ func Test_MerkleDB_Commit_Proof_To_Filled_Trie(t *testing.T) {
374
414
require .NoError (db2 .CommitRangeProof (
375
415
context .Background (),
376
416
maybe .Some ([]byte ("key1" )),
417
+ maybe .Some ([]byte ("key3" )),
377
418
proof ,
378
419
))
379
420
0 commit comments