Skip to content

Commit

Permalink
Ensure fixture parties are sorted as expected
Browse files Browse the repository at this point in the history
We want to ensure alice, bob, carol as Party reflect the sorting
of their identifiers
  • Loading branch information
abailly committed Sep 20, 2023
1 parent d18d539 commit 291aaa5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 5 additions & 5 deletions hydra-node/test/Hydra/Network/ReliabilitySpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ spec = parallel $ do
captureIncoming receivedMessages msg =
atomically $ modifyTVar' receivedMessages (`snoc` msg)

let msg' = 42 :: Int
msg <- Data "node-1" <$> runIO (generate @String arbitrary)

it "forward received messages" $ do
Expand Down Expand Up @@ -74,7 +75,7 @@ spec = parallel $ do
action (Network{broadcast = const $ pure ()})

withReliability nullTracer alice [bob] aliceNetwork (const $ pure ()) $ \Network{broadcast} ->
withReliability nullTracer bob [bob] bobNetwork (captureIncoming receivedMessages) $ \_ -> do
withReliability nullTracer bob [alice] bobNetwork (captureIncoming receivedMessages) $ \_ -> do
broadcast (Data "node-1" msg)
threadDelay 1

Expand Down Expand Up @@ -114,21 +115,20 @@ spec = parallel $ do
alice
[bob, carol]
( \incoming _ -> do
incoming (Authenticated (ReliableMsg (fromList [0, 1, 0]) (Data "node-2" msg)) bob)
incoming (Authenticated (ReliableMsg (fromList [0, 0, 1]) (Data "node-3" msg)) carol)
incoming (Authenticated (ReliableMsg (fromList [0, 1, 0]) (Data "node-2" msg')) bob)
incoming (Authenticated (ReliableMsg (fromList [0, 0, 1]) (Data "node-3" msg')) carol)
)
(captureIncoming receivedMessages)
$ \_ ->
pure ()

toList <$> readTVarIO receivedMessages

receivedMsgs `shouldBe` [Authenticated (Data "node-2" msg) bob, Authenticated (Data "node-3" msg) carol]
receivedMsgs `shouldBe` [Authenticated (Data "node-2" msg') bob, Authenticated (Data "node-3" msg') carol]

prop "retransmits unacknowledged messages given peer index does not change" $ \(Positive lastMessageKnownToBob) ->
forAll (arbitrary `suchThat` (> lastMessageKnownToBob)) $ \totalNumberOfMessages ->
let messagesList = Data "node-1" <$> [1 .. totalNumberOfMessages]
msg' = 42
sentMsgs = runSimOrThrow $ do
sentMessages <- newTVarIO empty

Expand Down
4 changes: 4 additions & 0 deletions hydra-node/test/Hydra/PartySpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Test.Hydra.Prelude

import Hydra.Party (Party (..))
import Test.Aeson.GenericSpecs (roundtripAndGoldenSpecs)
import Test.Hydra.Fixture (alice, bob, carol)
import Test.QuickCheck ((==>))

spec :: Spec
Expand All @@ -23,3 +24,6 @@ spec = do
(compare x y == EQ) == (x == y)

roundtripAndGoldenSpecs (Proxy @Party)

it "has alice, bob, carol sorted" $
sort [alice, bob, carol] `shouldBe` [alice, bob, carol]
2 changes: 1 addition & 1 deletion hydra-node/test/Test/Hydra/Fixture.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ carol = deriveParty carolSk
aliceSk, bobSk, carolSk :: SigningKey HydraKey
aliceSk = generateSigningKey "alice"
bobSk = generateSigningKey "bob"
carolSk = generateSigningKey "carol"
carolSk = generateSigningKey "zcarol"

aliceVk, bobVk, carolVk :: VerificationKey HydraKey
aliceVk = getVerificationKey aliceSk
Expand Down

0 comments on commit 291aaa5

Please sign in to comment.