Skip to content

Commit c17ea26

Browse files
committed
fix kv store tests
1 parent 429e205 commit c17ea26

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

state/protocol/protocol_state/kvstore/kvstore_storage_test.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ func TestProtocolKVStore_StoreTx(t *testing.T) {
2929
// On the happy path, where the input `kvState` encodes its state successfully, the wrapped store
3030
// should be called to persist the version-encoded snapshot.
3131
t.Run("happy path", func(t *testing.T) {
32-
lockManager := storage.NewTestingLockManager()
3332
expectedVersion := uint64(13)
3433
encData := unittest.RandomBytes(117)
3534
versionedSnapshot := &flow.PSKeyValueStoreData{
@@ -38,32 +37,26 @@ func TestProtocolKVStore_StoreTx(t *testing.T) {
3837
}
3938
kvState.On("VersionedEncode").Return(expectedVersion, encData, nil).Once()
4039

41-
err := unittest.WithLock(t, lockManager, storage.LockInsertBlock, func(lctx lockctx.Context) error {
42-
rw := storagemock.NewReaderBatchWriter(t)
43-
llStorage.On("BatchStore", lctx, rw, kvStateID, versionedSnapshot).Return(nil).Once()
40+
rw := storagemock.NewReaderBatchWriter(t)
41+
llStorage.On("BatchStore", rw, kvStateID, versionedSnapshot).Return(nil).Once()
4442

45-
// TODO: potentially update - we might be bringing back a functor here, because we acquire a lock as explained in slack thread https://flow-foundation.slack.com/archives/C071612SJJE/p1754600182033289?thread_ts=1752912083.194619&cid=C071612SJJE
46-
// Calling `BatchStore` should return the output of the wrapped low-level storage, which is a deferred database
47-
// update. Conceptually, it is possible that `ProtocolKVStore` wraps the deferred database operation in faulty
48-
// code, such that it cannot be executed. Therefore, we execute the top-level deferred database update below
49-
// and verify that the deferred database operation returned by the lower-level is actually reached.
50-
return store.BatchStore(lctx, rw, kvStateID, kvState)
51-
})
43+
// Calling `BatchStore` should return the output of the wrapped low-level storage, which is a deferred database
44+
// update. Conceptually, it is possible that `ProtocolKVStore` wraps the deferred database operation in faulty
45+
// code, such that it cannot be executed. Therefore, we execute the top-level deferred database update below
46+
// and verify that the deferred database operation returned by the lower-level is actually reached.
47+
err := store.BatchStore(rw, kvStateID, kvState)
5248
require.NoError(t, err)
5349
})
5450

5551
// On the unhappy path, i.e. when the encoding of input `kvState` failed, `ProtocolKVStore` should produce
5652
// a deferred database update that always returns the encoding error.
5753
t.Run("encoding fails", func(t *testing.T) {
58-
lockManager := storage.NewTestingLockManager()
5954
encodingError := errors.New("encoding error")
6055

6156
kvState.On("VersionedEncode").Return(uint64(0), nil, encodingError).Once()
6257

63-
err := unittest.WithLock(t, lockManager, storage.LockInsertBlock, func(lctx lockctx.Context) error {
64-
rw := storagemock.NewReaderBatchWriter(t)
65-
return store.BatchStore(lctx, rw, kvStateID, kvState)
66-
})
58+
rw := storagemock.NewReaderBatchWriter(t)
59+
err := store.BatchStore(rw, kvStateID, kvState)
6760
require.ErrorIs(t, err, encodingError)
6861
})
6962
}

0 commit comments

Comments
 (0)