Skip to content

Commit 7640ce3

Browse files
committed
tx-submission: fixed 'all transactions' test
The property is only satisfied if there are no transaction which advertise wrong size.
1 parent 32d7ad2 commit 7640ce3

File tree

2 files changed

+34
-12
lines changed
  • ouroboros-network-testing/src/Test/Ouroboros/Network
  • ouroboros-network/testlib/Test/Ouroboros/Network/Diffusion/Testnet

2 files changed

+34
-12
lines changed

ouroboros-network-testing/src/Test/Ouroboros/Network/Utils.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ data WithName name event = WithName {
178178
deriving Functor
179179

180180
instance (Show name, Show event) => Show (WithName name event) where
181-
show (WithName name ev) = "#" <> show name <> " %" <> show ev
181+
show (WithName name ev) = "#" <> show name <> " % " <> show ev
182182

183183
data WithTime event = WithTime {
184184
wtTime :: Time,
@@ -187,7 +187,7 @@ data WithTime event = WithTime {
187187
deriving Functor
188188

189189
instance Show event => Show (WithTime event) where
190-
show (WithTime t ev) = "@" <> show t <> " " <> show ev
190+
show (WithTime (Time t) ev) = show t <> " @ " <> show ev
191191

192192
tracerWithName :: name -> Tracer m (WithName name a) -> Tracer m a
193193
tracerWithName name = contramap (WithName name)

ouroboros-network/testlib/Test/Ouroboros/Network/Diffusion/Testnet/Cardano.hs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ tests =
253253
[ testProperty "no protocol errors"
254254
prop_no_txSubmission_error_iosim
255255
, testProperty "all transactions"
256-
unit_txSubmission_allTransactions
256+
prop_txSubmission_allTransactions
257257
, testProperty "inflight coverage"
258258
prop_check_inflight_ratio
259259
]
@@ -848,16 +848,34 @@ prop_no_txSubmission_error_iosim
848848
= testWithIOSim prop_no_txSubmission_error long_trace
849849

850850

851+
newtype WellSizedTx = WellSizedTx { getTx :: Tx TxId }
852+
deriving Show
853+
854+
fixupWellSizedTx :: Tx TxId -> Tx TxId
855+
fixupWellSizedTx tx@Tx { getTxSize } = tx { getTxAdvSize = getTxSize }
856+
857+
instance Arbitrary WellSizedTx where
858+
arbitrary = WellSizedTx
859+
. fixupWellSizedTx
860+
<$> arbitrary
861+
shrink = map (WellSizedTx . fixupWellSizedTx)
862+
. shrink
863+
. getTx
864+
865+
851866
-- | This test checks that even in a scenario where nodes keep disconnecting,
852867
-- but eventually stay online. We manage to get all transactions.
853868
--
854-
unit_txSubmission_allTransactions :: ArbTxDecisionPolicy
855-
-> NonEmptyList (Tx TxId)
856-
-> NonEmptyList (Tx TxId)
869+
-- We exclude txs which are not advertise the right size, since they disconnect
870+
-- the nodes, and as a result not all tx-s might transfer.
871+
--
872+
prop_txSubmission_allTransactions :: ArbTxDecisionPolicy
873+
-> NonEmptyList WellSizedTx
874+
-> NonEmptyList WellSizedTx
857875
-> Property
858-
unit_txSubmission_allTransactions (ArbTxDecisionPolicy decisionPolicy)
859-
(NonEmpty txsA)
860-
(NonEmpty txsB) =
876+
prop_txSubmission_allTransactions (ArbTxDecisionPolicy decisionPolicy)
877+
(NonEmpty txsA')
878+
(NonEmpty txsB') =
861879
let localRootConfig = LocalRootConfig
862880
DoNotAdvertisePeer
863881
InitiatorAndResponderDiffusionMode
@@ -933,6 +951,9 @@ unit_txSubmission_allTransactions (ArbTxDecisionPolicy decisionPolicy)
933951
)
934952
500_000 -- ^ Running for 500k might not be enough.
935953
where
954+
txsA = getTx <$> txsA'
955+
txsB = getTx <$> txsB'
956+
936957
-- We need to make sure the transactions are unique, this simplifies
937958
-- things.
938959
--
@@ -982,11 +1003,12 @@ unit_txSubmission_allTransactions (ArbTxDecisionPolicy decisionPolicy)
9821003
(validSortedTxidsA, validSortedTxidsB) =
9831004
let f = sort
9841005
. map (\Tx {getTxId} -> getTxId)
985-
. filter (\Tx {getTxValid} -> getTxValid)
1006+
. filter (\Tx {getTxSize, getTxAdvSize, getTxValid} -> getTxSize == getTxAdvSize
1007+
&& getTxValid)
9861008
in bimap f f (uniqueTxsA, uniqueTxsB)
9871009

988-
in -- counterexample (intercalate "\n" $ map show $ Trace.toList events)
989-
counterexample (Trace.ppTrace show (ppSimEvent 0 0 0) trace)
1010+
in counterexample (intercalate "\n" $ map show $ Trace.toList events)
1011+
-- counterexample (Trace.ppTrace show (ppSimEvent 0 0 0) trace)
9901012
$ counterexample ("accepted txids map: " ++ show sortedAcceptedTxidsMap)
9911013
$ counterexample ("A: unique txs: " ++ show uniqueTxsA)
9921014
$ counterexample ("A: valid transactions that should be accepted: " ++ show validSortedTxidsA)

0 commit comments

Comments
 (0)