@@ -20,6 +20,7 @@ import Data.Time.Clock.POSIX (posixSecondsToUTCTime)
20
20
import Hydra.Cardano.Api (
21
21
SlotNo (.. ),
22
22
mkTxOutDatumInline ,
23
+ renderUTxO ,
23
24
selectLovelace ,
24
25
throwError ,
25
26
txOutAddress ,
@@ -39,7 +40,7 @@ import Hydra.Ledger (hashUTxO, utxoFromTx)
39
40
import Hydra.Ledger.Cardano (Tx , adjustUTxO , genTxOut , genUTxO1 )
40
41
import Hydra.Ledger.Cardano.Evaluate (evaluateTx )
41
42
import Hydra.Party (partyToChain )
42
- import Hydra.Snapshot (ConfirmedSnapshot (.. ), Snapshot (.. ), SnapshotNumber (.. ), number )
43
+ import Hydra.Snapshot (ConfirmedSnapshot (.. ), Snapshot (.. ), SnapshotNumber (.. ), getSnapshot , number )
43
44
import PlutusTx.Builtins (toBuiltin )
44
45
import Test.Hydra.Fixture qualified as Fixture
45
46
import Test.QuickCheck (Property , Smart (.. ), checkCoverage , cover , elements , forAll , frequency , ioProperty , oneof )
@@ -376,7 +377,7 @@ instance RunModel Model AppM where
376
377
let fannedOut = utxoFromTx tx
377
378
-- counterexamplePost ("Fanned out UTxO does not match: " <> renderUTxO fannedOut)
378
379
-- counterexamplePost ("SnapshotUTxO: " <> renderUTxO (snapshotUTxO snapshot))
379
- guard $ sorted fannedOut == sorted (generateUTxOFromModelSnapshot snapshot)
380
+ guard $ sorted fannedOut == sorted (fst $ generateUTxOFromModelSnapshot snapshot)
380
381
381
382
expectValid result $ \ case
382
383
Tx. Fanout {} -> pure ()
@@ -436,10 +437,11 @@ allActors :: [Actor]
436
437
allActors = [Alice , Bob , Carol ]
437
438
438
439
-- | A "random" UTxO distribution for a given 'ModelSnapshot'.
439
- generateUTxOFromModelSnapshot :: ModelSnapshot -> UTxO
440
+ generateUTxOFromModelSnapshot :: ModelSnapshot -> ( UTxO , UTxO )
440
441
generateUTxOFromModelSnapshot snapshot =
441
- foldMap go (snapshotUTxO snapshot)
442
- <> foldMap go (decommitUTxO snapshot)
442
+ ( foldMap go (snapshotUTxO snapshot)
443
+ , foldMap go (decommitUTxO snapshot)
444
+ )
443
445
where
444
446
go modelUTxO =
445
447
(`generateWith` fromEnum modelUTxO) $ genUTxO1 genTxOut
@@ -449,8 +451,7 @@ decommitSnapshot :: ModelSnapshot -> (Snapshot Tx, MultiSignature (Snapshot Tx))
449
451
decommitSnapshot ms =
450
452
(snapshot, signatures)
451
453
where
452
- utxo = generateUTxOFromModelSnapshot ms{decommitUTxO = mempty }
453
- toDecommit = generateUTxOFromModelSnapshot ms{snapshotUTxO = mempty }
454
+ (utxo, toDecommit) = generateUTxOFromModelSnapshot ms{snapshotUTxO = mempty }
454
455
snapshot =
455
456
Snapshot
456
457
{ headId = mkHeadId Fixture. testPolicyId
@@ -472,7 +473,7 @@ signedSnapshot ms =
472
473
{ headId = mkHeadId Fixture. testPolicyId
473
474
, number = snapshotNumber ms
474
475
, confirmed = []
475
- , utxo = generateUTxOFromModelSnapshot ms
476
+ , utxo = fst $ generateUTxOFromModelSnapshot ms
476
477
, utxoToDecommit = Nothing
477
478
}
478
479
signatures = aggregate [sign sk snapshot | sk <- [Fixture. aliceSk, Fixture. bobSk, Fixture. carolSk]]
@@ -487,7 +488,7 @@ confirmedSnapshot modelSnapshot@ModelSnapshot{snapshotNumber} =
487
488
{ -- -- NOTE: The close validator would not check headId on close with
488
489
-- initial snapshot, but we need to provide it still.
489
490
headId = mkHeadId Fixture. testPolicyId
490
- , initialUTxO = generateUTxOFromModelSnapshot (ModelSnapshot 0 (fromList [A ]) (fromList [] ))
491
+ , initialUTxO = fst $ generateUTxOFromModelSnapshot (ModelSnapshot 0 (fromList [A ]) (fromList [] ))
491
492
}
492
493
_ -> ConfirmedSnapshot {snapshot, signatures}
493
494
where
@@ -508,7 +509,7 @@ openHeadUTxO =
508
509
mkTxOutDatumInline
509
510
Head. Open
510
511
{ parties = partyToChain <$> [Fixture. alice, Fixture. bob, Fixture. carol]
511
- , utxoHash = toBuiltin $ hashUTxO @ Tx $ generateUTxOFromModelSnapshot (ModelSnapshot 0 (fromList [A ]) (fromList [] ))
512
+ , utxoHash = toBuiltin $ hashUTxO @ Tx $ fst $ generateUTxOFromModelSnapshot (ModelSnapshot 0 (fromList [A ]) (fromList [] ))
512
513
, contestationPeriod = CP. toChain Fixture. cperiod
513
514
, headId = headIdToCurrencySymbol $ mkHeadId Fixture. testPolicyId
514
515
, snapshotNumber = 0
@@ -534,15 +535,17 @@ newDecrementTx actor (snapshot, signatures) = do
534
535
newCloseTx :: HasCallStack => Actor -> ConfirmedSnapshot Tx -> AppM Tx
535
536
newCloseTx actor snapshot = do
536
537
spendableUTxO <- get
537
- either (failure . show ) pure $
538
- close
539
- (actorChainContext actor)
540
- spendableUTxO
541
- (mkHeadId Fixture. testPolicyId)
542
- Fixture. testHeadParameters
543
- snapshot
544
- lowerBound
545
- upperBound
538
+ traceShow " close utxo" $
539
+ traceShow (renderUTxO $ utxo $ getSnapshot snapshot) $
540
+ either (failure . show ) pure $
541
+ close
542
+ (actorChainContext actor)
543
+ spendableUTxO
544
+ (mkHeadId Fixture. testPolicyId)
545
+ Fixture. testHeadParameters
546
+ snapshot
547
+ lowerBound
548
+ upperBound
546
549
where
547
550
lowerBound = 0
548
551
@@ -554,14 +557,16 @@ newCloseTx actor snapshot = do
554
557
newContestTx :: HasCallStack => Actor -> ConfirmedSnapshot Tx -> AppM Tx
555
558
newContestTx actor snapshot = do
556
559
spendableUTxO <- get
557
- either (failure . show ) pure $
558
- contest
559
- (actorChainContext actor)
560
- spendableUTxO
561
- (mkHeadId Fixture. testPolicyId)
562
- Fixture. cperiod
563
- snapshot
564
- currentTime
560
+ traceShow " contest utxo" $
561
+ traceShow (renderUTxO $ utxo $ getSnapshot snapshot) $
562
+ either (failure . show ) pure $
563
+ contest
564
+ (actorChainContext actor)
565
+ spendableUTxO
566
+ (mkHeadId Fixture. testPolicyId)
567
+ Fixture. cperiod
568
+ snapshot
569
+ currentTime
565
570
where
566
571
currentTime = (0 , posixSecondsToUTCTime 0 )
567
572
@@ -572,14 +577,16 @@ newFanoutTx :: Actor -> ModelSnapshot -> AppM (Either FanoutTxError Tx)
572
577
newFanoutTx actor snapshot = do
573
578
spendableUTxO <- get
574
579
let (snapshot', _) = signedSnapshot snapshot
575
- pure $
576
- fanout
577
- (actorChainContext actor)
578
- spendableUTxO
579
- Fixture. testSeedInput
580
- (utxo snapshot')
581
- (utxoToDecommit snapshot')
582
- deadline
580
+ traceShow " fanout utxo" $
581
+ traceShow (renderUTxO $ utxo snapshot') $
582
+ pure $
583
+ fanout
584
+ (actorChainContext actor)
585
+ spendableUTxO
586
+ Fixture. testSeedInput
587
+ (utxo snapshot')
588
+ (utxoToDecommit snapshot')
589
+ deadline
583
590
where
584
591
CP. UnsafeContestationPeriod contestationPeriod = Fixture. cperiod
585
592
deadline = SlotNo $ fromIntegral contestationPeriod * fromIntegral (length allActors)
0 commit comments