@@ -24,10 +24,8 @@ func TestInsertProtocolKVStore(t *testing.T) {
2424 }
2525
2626 kvStoreStateID := unittest .IdentifierFixture ()
27- err := unittest .WithLock (t , lockManager , storage .LockInsertBlock , func (lctx lockctx.Context ) error {
28- return db .WithReaderBatchWriter (func (rw storage.ReaderBatchWriter ) error {
29- return operation .InsertProtocolKVStore (lctx , rw , kvStoreStateID , expected )
30- })
27+ err := db .WithReaderBatchWriter (func (rw storage.ReaderBatchWriter ) error {
28+ return operation .InsertProtocolKVStore (rw , kvStoreStateID , expected )
3129 })
3230 require .NoError (t , err )
3331
@@ -53,47 +51,6 @@ func TestInsertProtocolKVStore(t *testing.T) {
5351 })
5452}
5553
56- // TestInsertProtocolKVStore_ErrAlreadyExists tests that InsertProtocolKVStore returns ErrAlreadyExists
57- // when attempting to insert a protocol KV store that already exists.
58- func TestInsertProtocolKVStore_ErrAlreadyExists (t * testing.T ) {
59- dbtest .RunWithDB (t , func (t * testing.T , db storage.DB ) {
60- lockManager := storage .NewTestingLockManager ()
61- expected := & flow.PSKeyValueStoreData {
62- Version : 2 ,
63- Data : unittest .RandomBytes (32 ),
64- }
65-
66- kvStoreStateID := unittest .IdentifierFixture ()
67-
68- // First insertion should succeed
69- err := unittest .WithLock (t , lockManager , storage .LockInsertBlock , func (lctx lockctx.Context ) error {
70- return db .WithReaderBatchWriter (func (rw storage.ReaderBatchWriter ) error {
71- return operation .InsertProtocolKVStore (lctx , rw , kvStoreStateID , expected )
72- })
73- })
74- require .NoError (t , err )
75-
76- // Second insertion with same ID should fail with ErrAlreadyExists
77- differentData := & flow.PSKeyValueStoreData {
78- Version : 3 ,
79- Data : unittest .RandomBytes (32 ),
80- }
81- err = unittest .WithLock (t , lockManager , storage .LockInsertBlock , func (lctx lockctx.Context ) error {
82- return db .WithReaderBatchWriter (func (rw storage.ReaderBatchWriter ) error {
83- return operation .InsertProtocolKVStore (lctx , rw , kvStoreStateID , differentData )
84- })
85- })
86- require .Error (t , err )
87- require .ErrorIs (t , err , storage .ErrAlreadyExists )
88-
89- // Verify original data is still there and unchanged
90- var actual flow.PSKeyValueStoreData
91- err = operation .RetrieveProtocolKVStore (db .Reader (), kvStoreStateID , & actual )
92- require .NoError (t , err )
93- assert .Equal (t , expected , & actual )
94- })
95- }
96-
9754// TestIndexProtocolKVStore_ErrAlreadyExists tests that IndexProtocolKVStore returns ErrAlreadyExists
9855// when attempting to index a protocol KV store for a block ID that already has an index.
9956func TestIndexProtocolKVStore_ErrAlreadyExists (t * testing.T ) {
@@ -108,10 +65,8 @@ func TestIndexProtocolKVStore_ErrAlreadyExists(t *testing.T) {
10865 blockID := unittest .IdentifierFixture ()
10966
11067 // Insert the protocol KV store first
111- err := unittest .WithLock (t , lockManager , storage .LockInsertBlock , func (lctx lockctx.Context ) error {
112- return db .WithReaderBatchWriter (func (rw storage.ReaderBatchWriter ) error {
113- return operation .InsertProtocolKVStore (lctx , rw , kvStoreStateID , expected )
114- })
68+ err := db .WithReaderBatchWriter (func (rw storage.ReaderBatchWriter ) error {
69+ return operation .InsertProtocolKVStore (rw , kvStoreStateID , expected )
11570 })
11671 require .NoError (t , err )
11772
@@ -141,29 +96,6 @@ func TestIndexProtocolKVStore_ErrAlreadyExists(t *testing.T) {
14196 })
14297}
14398
144- // TestInsertProtocolKVStore_MissingLock tests that InsertProtocolKVStore requires LockInsertBlock.
145- func TestInsertProtocolKVStore_MissingLock (t * testing.T ) {
146- dbtest .RunWithDB (t , func (t * testing.T , db storage.DB ) {
147- lockManager := storage .NewTestingLockManager ()
148- expected := & flow.PSKeyValueStoreData {
149- Version : 2 ,
150- Data : unittest .RandomBytes (32 ),
151- }
152-
153- kvStoreStateID := unittest .IdentifierFixture ()
154-
155- // Attempt to insert without holding the required lock
156- lctx := lockManager .NewContext ()
157- defer lctx .Release ()
158-
159- err := db .WithReaderBatchWriter (func (rw storage.ReaderBatchWriter ) error {
160- return operation .InsertProtocolKVStore (lctx , rw , kvStoreStateID , expected )
161- })
162- require .Error (t , err )
163- require .Contains (t , err .Error (), storage .LockInsertBlock )
164- })
165- }
166-
16799// TestIndexProtocolKVStore_MissingLock tests that IndexProtocolKVStore requires LockInsertBlock.
168100func TestIndexProtocolKVStore_MissingLock (t * testing.T ) {
169101 dbtest .RunWithDB (t , func (t * testing.T , db storage.DB ) {
@@ -183,28 +115,6 @@ func TestIndexProtocolKVStore_MissingLock(t *testing.T) {
183115 })
184116}
185117
186- // TestInsertProtocolKVStore_WrongLock tests that InsertProtocolKVStore fails when holding wrong locks.
187- func TestInsertProtocolKVStore_WrongLock (t * testing.T ) {
188- dbtest .RunWithDB (t , func (t * testing.T , db storage.DB ) {
189- lockManager := storage .NewTestingLockManager ()
190- expected := & flow.PSKeyValueStoreData {
191- Version : 2 ,
192- Data : unittest .RandomBytes (32 ),
193- }
194-
195- kvStoreStateID := unittest .IdentifierFixture ()
196-
197- // Test with LockFinalizeBlock (wrong lock)
198- err := unittest .WithLock (t , lockManager , storage .LockFinalizeBlock , func (lctx lockctx.Context ) error {
199- return db .WithReaderBatchWriter (func (rw storage.ReaderBatchWriter ) error {
200- return operation .InsertProtocolKVStore (lctx , rw , kvStoreStateID , expected )
201- })
202- })
203- require .Error (t , err )
204- require .Contains (t , err .Error (), storage .LockInsertBlock )
205- })
206- }
207-
208118// TestIndexProtocolKVStore_WrongLock tests that IndexProtocolKVStore fails when holding wrong locks.
209119func TestIndexProtocolKVStore_WrongLock (t * testing.T ) {
210120 dbtest .RunWithDB (t , func (t * testing.T , db storage.DB ) {
0 commit comments