Skip to content

Commit

Permalink
Add property `prop_multiple_putPoolRegistration_single_readPoolRegist…
Browse files Browse the repository at this point in the history
…ration`.
  • Loading branch information
jonathanknowles committed Jul 7, 2020
1 parent 5ab78c7 commit a8cab3e
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions lib/core/test/unit/Cardano/Pool/DB/Properties.hs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ properties = do
(property . prop_poolRegistration)
it "putPoolRetirement then readPoolRetirement yields expected result"
(property . prop_poolRetirement)
it "prop_multiple_putPoolRegistration_single_readPoolRegistration"
(property .
prop_multiple_putPoolRegistration_single_readPoolRegistration)
it "readPoolRegistrationStatus should respect registration order"
(property . prop_readPoolRegistrationStatus)
it "rollback of PoolRegistration"
Expand Down Expand Up @@ -473,6 +476,56 @@ prop_poolRetirement DBLayer {..} entries =
]
assert (entriesIn == entriesOut)

-- | For the same pool, write multiple pool registration certificates to the
-- database and then read back the current registration certificate.
--
prop_multiple_putPoolRegistration_single_readPoolRegistration
:: DBLayer IO
-> PoolId
-> [PoolRegistrationCertificate]
-> Property
prop_multiple_putPoolRegistration_single_readPoolRegistration
DBLayer {..} sharedPoolId certificatesManyPoolIds =
monadicIO (setup >> prop)
where
setup = run $ atomically cleanDB

prop = do
run $ atomically $
mapM_ (uncurry putPoolRegistration) certificatePublications
mRetrievedCertificatePublication <-
run $ atomically $ readPoolRegistration sharedPoolId
monitor $ counterexample $ unlines
[ "\nExpected certificate publication: "
, show mExpectedCertificatePublication
, "\nRetrieved certificate publication: "
, show mRetrievedCertificatePublication
, "\nNumber of certificate publications: "
, show (length certificatePublications)
, "\nAll certificate publications: "
, unlines (("\n" <>) . show <$> certificatePublications)
]
assert $ (==)
mRetrievedCertificatePublication
mExpectedCertificatePublication

certificatePublications
:: [(CertificatePublicationTime, PoolRegistrationCertificate)]
certificatePublications = publicationTimes `zip` certificates

mExpectedCertificatePublication = certificatePublications
& reverse
& listToMaybe

publicationTimes =
[(SlotId en sn, SlotInternalIndex ii)
| en <- [0 ..]
, sn <- [0 .. 3]
, ii <- [0 .. 3]
]

certificates = set #poolId sharedPoolId <$> certificatesManyPoolIds

prop_readPoolRegistrationStatus
:: DBLayer IO
-> PoolId
Expand Down

0 comments on commit a8cab3e

Please sign in to comment.