| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Test.Ouroboros.Storage.LeiosDB
Description
Tests for the Ouroboros.Consensus.Storage.LeiosDB interface.
These tests verify the semantics of the LeiosDbHandle operations for both InMemory and SQLite implementations. Each test case uses a fresh database to ensure isolation and serve as an (too optimistic) performance baseline.
Synopsis
- assertOfferBlock ∷ LeiosPoint → LeiosEbNotification → IO ()
- assertOfferBlockTxs ∷ LeiosPoint → LeiosEbNotification → IO ()
- forEachImplementation ∷ (DbImpl → [TestTree]) → [TestTree]
- genEb ∷ Int → Gen LeiosEb
- genEbHash ∷ Gen EbHash
- genPoint ∷ Gen LeiosPoint
- genPointAndEb ∷ Int → Gen (LeiosPoint, LeiosEb)
- genRbHash ∷ Gen RbHash
- genSlotNo ∷ Gen SlotNo
- genTxBytes ∷ Gen ByteString
- genTxHash ∷ Gen TxHash
- magnitudeBucket ∷ (Num a, Ord a) ⇒ a → String
- maxTxBytesZero ∷ ByteString
- micro ∷ Integer → DiffTime
- milli ∷ Integer → DiffTime
- mkTestEb ∷ Int → LeiosEb
- mkTestEbHash ∷ Word → EbHash
- mkTestGroups ∷ DbImpl → [TestTree]
- mkTestPoint ∷ SlotNo → Word → LeiosPoint
- mkTestTxHash ∷ Word → TxHash
- prop_completedEbComplete ∷ DbImpl → Property
- prop_completedEbMissingTxs ∷ DbImpl → Property
- prop_completedEbNoBody ∷ DbImpl → Property
- prop_completedEbPartialTxs ∷ DbImpl → Property
- prop_ebsInsertThenLookup ∷ DbImpl → Property
- prop_ebsLookupMissing ∷ DbImpl → Property
- prop_pointsAccumulate ∷ DbImpl → Property
- prop_pointsInsertThenScan ∷ DbImpl → Property
- prop_txsInsertThenRetrieve ∷ DbImpl → Property
- prop_txsRetrieveMissing ∷ DbImpl → Property
- rwBatchRetrieveTxs ∷ RW → EbHash → [Int] → IO [(Int, TxHash, Maybe ByteString)]
- rwInsertEbBody ∷ RW → LeiosPoint → LeiosEb → IO CompletedEbs
- rwInsertEbPoint ∷ RW → LeiosPoint → BytesSize → IO ()
- rwInsertTxs ∷ RW → [(TxHash, ByteString)] → IO CompletedEbs
- rwLookupEbBody ∷ RW → EbHash → IO [(TxHash, BytesSize)]
- rwLookupEbClosure ∷ RW → EbHash → IO (Maybe [(TxHash, ByteString)])
- rwScanEbPoints ∷ RW → IO [(SlotNo, EbHash)]
- schemaObjects ∷ FilePath → IO [String]
- showTime ∷ DiffTime → String
- testRbHash ∷ RbHash
- test_correctData ∷ LeiosDbHandle IO → IO ()
- test_deleteDanglingTxs ∷ FilePath → FilePath → LeiosDbHandle IO → IO ()
- test_lateSubscriber ∷ LeiosDbHandle IO → IO ()
- test_multipleNotifications ∷ LeiosDbHandle IO → IO ()
- test_multipleSlotsSameHash ∷ LeiosDbHandle IO → IO ()
- test_multipleSubscribers ∷ LeiosDbHandle IO → IO ()
- test_noOfferBlockTxsBeforeComplete ∷ LeiosDbHandle IO → IO ()
- test_noReNotifyCompletedEbs ∷ LeiosDbHandle IO → IO ()
- test_noReNotifyOnRelatedTxReinsert ∷ LeiosDbHandle IO → IO ()
- test_offerBlockTxs ∷ LeiosDbHandle IO → IO ()
- test_reopenKeepsData ∷ FilePath → FilePath → IO ()
- test_schemaAtHandleCreation ∷ FilePath → FilePath → IO ()
- test_singleSubscriber ∷ LeiosDbHandle IO → IO ()
- test_truncateDropsEbsAfterSlot ∷ FilePath → FilePath → LeiosDbHandle IO → IO ()
- test_truncateImmutablePartition ∷ FilePath → FilePath → IO ()
- test_zeroByteFilesGetSchema ∷ FilePath → FilePath → IO ()
- tests ∷ TestTree
- timeBucket ∷ DiffTime → String
- timed ∷ IO a → IO (a, DiffTime)
- withFreshDb ∷ DbImpl → (LeiosDbHandle IO → IO a) → IO a
- withFreshSQLiteDb ∷ (LeiosDbHandle IO → IO a) → IO a
- withFreshSQLiteFile ∷ (FilePath → FilePath → LeiosDbHandle IO → IO a) → IO a
- withRW ∷ LeiosDbHandle IO → (RW → IO a) → IO a
- withTempLeiosDbPaths ∷ (FilePath → FilePath → IO a) → IO a
- data DbImpl
- data RW = RW {}
Documentation
assertOfferBlock ∷ LeiosPoint → LeiosEbNotification → IO () Source #
Assert that a notification is AcquiredEb with the expected point.
assertOfferBlockTxs ∷ LeiosPoint → LeiosEbNotification → IO () Source #
Assert that a notification is AcquiredEbTxs with the expected point.
forEachImplementation ∷ (DbImpl → [TestTree]) → [TestTree] Source #
Run tests for each database implementation.
genEbHash ∷ Gen EbHash Source #
Generate a random EbHash (32 random bytes). With 256 bits of randomness, collisions are practically impossible.
genPoint ∷ Gen LeiosPoint Source #
Generate a random LeiosPoint.
genPointAndEb ∷ Int → Gen (LeiosPoint, LeiosEb) Source #
Generate a LeiosPoint and LeiosEb together with the given number of transactions.
genRbHash ∷ Gen RbHash Source #
Generate a random RbHash (32 random bytes). With 256 bits of randomness, collisions are practically impossible.
genTxBytes ∷ Gen ByteString Source #
Generate random max sized tx (16k).
maxTxBytesZero ∷ ByteString Source #
Max sized tx (16k) with all zeros.
mkTestEbHash ∷ Word → EbHash Source #
Create a simple test EbHash from a seed byte.
mkTestGroups ∷ DbImpl → [TestTree] Source #
Create the test groups for a given database implementation.
mkTestPoint ∷ SlotNo → Word → LeiosPoint Source #
Create a test LeiosPoint.
mkTestTxHash ∷ Word → TxHash Source #
Create a simple test TxHash from a seed byte.
prop_completedEbComplete ∷ DbImpl → Property Source #
Property: complete EB (all txs inserted) returns Just with correct tx data.
prop_completedEbMissingTxs ∷ DbImpl → Property Source #
Property: EB with body but no txs returns Nothing.
prop_completedEbNoBody ∷ DbImpl → Property Source #
Property: EB with only a point announced (no body) returns Nothing.
prop_completedEbPartialTxs ∷ DbImpl → Property Source #
Property: EB with partial txs (at least one missing) returns Nothing.
prop_ebsInsertThenLookup ∷ DbImpl → Property Source #
Property: inserting an EB body and looking it up returns the correct txs.
prop_ebsLookupMissing ∷ DbImpl → Property Source #
Property: looking up a non-existent EB returns empty list.
prop_pointsAccumulate ∷ DbImpl → Property Source #
Property: multiple inserted points all appear in scan results.
prop_pointsInsertThenScan ∷ DbImpl → Property Source #
Property: inserting a point and then scanning should return it.
prop_txsInsertThenRetrieve ∷ DbImpl → Property Source #
Property: inserting tx bytes and retrieving them returns the correct data.
With the normalized schema, txs are inserted into a global txs table by TxHash,
and retrieval JOINs with that table.
prop_txsRetrieveMissing ∷ DbImpl → Property Source #
Property: retrieving from non-existent EB returns empty list.
rwInsertEbBody ∷ RW → LeiosPoint → LeiosEb → IO CompletedEbs Source #
rwInsertEbPoint ∷ RW → LeiosPoint → BytesSize → IO () Source #
rwInsertTxs ∷ RW → [(TxHash, ByteString)] → IO CompletedEbs Source #
rwLookupEbClosure ∷ RW → EbHash → IO (Maybe [(TxHash, ByteString)]) Source #
A dummy announcing RB hash for DB tests that don't care about its value.
test_correctData ∷ LeiosDbHandle IO → IO () Source #
Test that the notification contains the correct AcquiredEb data.
test_deleteDanglingTxs ∷ FilePath → FilePath → LeiosDbHandle IO → IO () Source #
test_lateSubscriber ∷ LeiosDbHandle IO → IO () Source #
Test that a subscriber who subscribes after an insertion does not receive the past notification.
test_multipleNotifications ∷ LeiosDbHandle IO → IO () Source #
Test that multiple insertions yield multiple notifications in order.
test_multipleSlotsSameHash ∷ LeiosDbHandle IO → IO () Source #
The same EB content can be forged at multiple slots; the DB must
track each LeiosPoint independently and emit one AcquiredEbTxs
per (slot, hash) when the closure completes, regardless of how many
slots reference the same hash. Conflating the slots loses a
notification.
test_multipleSubscribers ∷ LeiosDbHandle IO → IO () Source #
Test that multiple subscribers each receive the notification.
test_noOfferBlockTxsBeforeComplete ∷ LeiosDbHandle IO → IO () Source #
Test that no AcquiredEbTxs notification is produced when only some transactions have been inserted via rwInsertTxs.
test_noReNotifyCompletedEbs ∷ LeiosDbHandle IO → IO () Source #
Test that completed EBs are not re-notified when subsequent unrelated transactions are inserted.
test_noReNotifyOnRelatedTxReinsert ∷ LeiosDbHandle IO → IO () Source #
Re-inserting a tx that is _referenced_ by an already-completed EB
must not re-fire AcquiredEbTxs. This is the practical case where
the previous 'no re-notification' check (which only used an unrelated
tx) lets a bug through: the completion predicate
any (\e -> eteTxHash e `elem` insertedTxHashes) matches again on
any subsequent batch containing an EB-referenced tx, since the
'all txs present' clause remains true once the EB is complete.
The voting layer treats the duplicate AcquiredEbTxs as a fatal
AlreadyKnown from addVote.
test_offerBlockTxs ∷ LeiosDbHandle IO → IO () Source #
Test that a AcquiredEbTxs notification is produced when all transactions are inserted via rwInsertTxs.
test_singleSubscriber ∷ LeiosDbHandle IO → IO () Source #
Test that a single subscriber receives a notification when rwInsertEbBody is called.
test_truncateDropsEbsAfterSlot ∷ FilePath → FilePath → LeiosDbHandle IO → IO () Source #
test_truncateImmutablePartition ∷ FilePath → FilePath → IO () Source #
The immutable schema lacks the volatile-only tables; the tooling that DBTruncater runs on both files must still work on it.
test_zeroByteFilesGetSchema ∷ FilePath → FilePath → IO () Source #
A file that exists without a schema, as a crash between creating the file and applying the schema leaves it.
timed ∷ IO a → IO (a, DiffTime) Source #
Measure the time of an IO action and return the result with DiffTime.
withFreshDb ∷ DbImpl → (LeiosDbHandle IO → IO a) → IO a Source #
Create a fresh database and run an action with it. Ensures proper cleanup for SQLite databases.
withFreshSQLiteDb ∷ (LeiosDbHandle IO → IO a) → IO a Source #
withFreshSQLiteFile ∷ (FilePath → FilePath → LeiosDbHandle IO → IO a) → IO a Source #
Create a fresh SQLite database and hand its paths to the action, which
truncateLeiosDbAfterSlot needs. The database is torn down -- writes
flushed, threads stopped, connections closed -- before the directory is
removed; a still-open connection makes the removal flaky (a hard failure
on Windows, where deleting an open WAL is a sharing violation).
withTempLeiosDbPaths ∷ (FilePath → FilePath → IO a) → IO a Source #
Paths for both partition files in a fresh temporary directory, which is removed afterwards. Nothing is created at the paths.
Database creation strategy for different implementations.
A reader and a writer onto the same database -- what every caller outside these tests now holds, since reads and writes no longer share a connection.
Constructors
| RW | |
Fields | |