github.com/MetalBlockchain/subnet-evm@v0.6.3/core/rawdb/accessors_state_sync_test.go (about)

     1  // (c) 2023, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package rawdb
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/ethereum/go-ethereum/common"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestClearPrefix(t *testing.T) {
    14  	require := require.New(t)
    15  	db := NewMemoryDatabase()
    16  	// add a key that should be cleared
    17  	require.NoError(WriteSyncSegment(db, common.Hash{1}, common.Hash{}.Bytes()))
    18  
    19  	// add a key that should not be cleared
    20  	key := append(syncSegmentsPrefix, []byte("foo")...)
    21  	require.NoError(db.Put(key, []byte("bar")))
    22  
    23  	require.NoError(ClearAllSyncSegments(db))
    24  
    25  	count := 0
    26  	it := db.NewIterator(syncSegmentsPrefix, nil)
    27  	defer it.Release()
    28  	for it.Next() {
    29  		count++
    30  	}
    31  	require.NoError(it.Error())
    32  	require.Equal(1, count)
    33  }