@@ -71,9 +71,9 @@ func TestBlockIndexByHeightAndRetrieve(t *testing.T) {
7171 })
7272
7373 // Now index the block by height (requires LockFinalizeBlock)
74- unittest .WithLock (t , lockManager , storage .LockFinalizeBlock , func (lctx2 lockctx.Context ) error {
74+ unittest .WithLock (t , lockManager , storage .LockFinalizeBlock , func (lctx lockctx.Context ) error {
7575 return db .WithReaderBatchWriter (func (rw storage.ReaderBatchWriter ) error {
76- return operation .IndexFinalizedBlockByHeight (lctx2 , rw , block .Height , block .ID ())
76+ return operation .IndexFinalizedBlockByHeight (lctx , rw , block .Height , block .ID ())
7777 })
7878 })
7979
@@ -88,15 +88,13 @@ func TestBlockIndexByHeightAndRetrieve(t *testing.T) {
8888 require .Equal (t , * prop , * retrievedProposalByHeight )
8989
9090 // Test that indexing the same height again returns ErrAlreadyExists
91- lctx3 := lockManager . NewContext ()
92- err = lctx3 . AcquireLock ( storage .LockFinalizeBlock )
93- require . NoError ( t , err )
94-
95- err = db . WithReaderBatchWriter ( func ( rw storage.ReaderBatchWriter ) error {
96- return operation . IndexFinalizedBlockByHeight ( lctx3 , rw , block . Height , block . ID ())
91+ unittest . WithLock ( t , lockManager , storage . LockFinalizeBlock , func ( lctx lockctx. Context ) error {
92+ err := db . WithReaderBatchWriter ( func ( rw storage.ReaderBatchWriter ) error {
93+ return operation . IndexFinalizedBlockByHeight ( lctx , rw , block . Height , block . ID () )
94+ })
95+ require . ErrorIs ( t , err , storage .ErrAlreadyExists )
96+ return nil
9797 })
98- require .ErrorIs (t , err , storage .ErrAlreadyExists )
99- lctx3 .Release ()
10098
10199 // Test that retrieving by non-existent height returns ErrNotFound
102100 _ , err = blocks .ByHeight (block .Height + 1000 )
0 commit comments