Skip to content

Commit 10979ae

Browse files
committed
add TestIndexGuaranteeDataMismatch
1 parent 7315ee4 commit 10979ae

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

storage/operation/guarantees_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,36 @@ func TestIndexGuaranteedCollectionByBlockHashMultipleBlocks(t *testing.T) {
140140
})
141141
})
142142
}
143+
144+
func TestIndexGuaranteeDataMismatch(t *testing.T) {
145+
dbtest.RunWithDB(t, func(t *testing.T, db storage.DB) {
146+
collectionID := flow.Identifier{0x01}
147+
guaranteeID1 := flow.Identifier{0x10}
148+
guaranteeID2 := flow.Identifier{0x20}
149+
150+
lockManager := storage.NewTestingLockManager()
151+
152+
// First, index a guarantee for the collection
153+
unittest.WithLock(t, lockManager, storage.LockInsertBlock, func(lctx lockctx.Context) error {
154+
return db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
155+
return operation.IndexGuarantee(lctx, rw, collectionID, guaranteeID1)
156+
})
157+
})
158+
159+
// Now try to index a different guarantee ID for the same collection
160+
// This should return storage.ErrDataMismatch
161+
unittest.WithLock(t, lockManager, storage.LockInsertBlock, func(lctx lockctx.Context) error {
162+
return db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
163+
err := operation.IndexGuarantee(lctx, rw, collectionID, guaranteeID2)
164+
require.ErrorIs(t, err, storage.ErrDataMismatch)
165+
return nil // Always return nil to satisfy WithLock, we'll check the error outside
166+
})
167+
})
168+
169+
// Verify that the original guarantee ID is still stored
170+
var retrievedGuaranteeID flow.Identifier
171+
err := operation.LookupGuarantee(db.Reader(), collectionID, &retrievedGuaranteeID)
172+
require.NoError(t, err)
173+
assert.Equal(t, guaranteeID1, retrievedGuaranteeID)
174+
})
175+
}

0 commit comments

Comments
 (0)