ouroboros-consensus
Safe HaskellNone
LanguageHaskell2010

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

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.

genEb ∷ Int → Gen LeiosEb Source #

Generate a LeiosEb with the given number of transactions.

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.

genSlotNo ∷ Gen SlotNo Source #

Generate a random SlotNo.

genTxBytes ∷ Gen ByteString Source #

Generate random max sized tx (16k).

genTxHash ∷ Gen TxHash Source #

Generate a random TxHash (32 random bytes).

magnitudeBucket ∷ (Num a, Ord a) ⇒ a → String Source #

maxTxBytesZero ∷ ByteString Source #

Max sized tx (16k) with all zeros.

mkTestEb ∷ Int → LeiosEb Source #

Create a test LeiosEb with the given number of transactions.

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.

schemaObjects ∷ FilePath → IO [String] Source #

Names of the tables and indexes in a database file.

testRbHash ∷ RbHash 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_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_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.

timeBucket ∷ DiffTime → String Source #

Convert DiffTime to a bucket label.

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.

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).

withRW ∷ LeiosDbHandle IO → (RW → IO a) → IO a Source #

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.

data DbImpl Source #

Database creation strategy for different implementations.

Constructors

InMemory 
SQLite 

data RW Source #

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