Skip to content

Commit

Permalink
Fix starting real world utxo to included "A" equivalent
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed May 23, 2024
1 parent 6a1370f commit bd66d18
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions hydra-node/test/Hydra/Chain/Direct/TxTraceSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Data.Time.Clock.POSIX (posixSecondsToUTCTime)
import Hydra.Cardano.Api (
SlotNo (..),
mkTxOutDatumInline,
modifyTxOutValue,
selectLovelace,
throwError,
txOutAddress,
Expand Down Expand Up @@ -493,12 +494,14 @@ allActors = [Alice, Bob, Carol]
-- | A "random" UTxO distribution for a given 'ModelSnapshot'.
generateUTxOFromModelSnapshot :: ModelSnapshot -> (UTxO, UTxO)
generateUTxOFromModelSnapshot snapshot =
( foldMap go (snapshotUTxO snapshot)
, foldMap go (decommitUTxO snapshot)
( foldMap realWorldModelUTxO (snapshotUTxO snapshot)
, foldMap realWorldModelUTxO (decommitUTxO snapshot)
)
where
go modelUTxO =
(`generateWith` fromEnum modelUTxO) $ genUTxO1 genTxOut

-- | Map a 'ModelUTxO' to a real-world 'UTxO'.
realWorldModelUTxO :: ModelUTxO -> UTxO
realWorldModelUTxO modelUTxO =
(`generateWith` fromEnum modelUTxO) $ genUTxO1 genTxOut

-- TODO: dry with signedSnapshot
decommitSnapshot :: ModelSnapshot -> (Snapshot Tx, MultiSignature (Snapshot Tx))
Expand Down Expand Up @@ -559,16 +562,20 @@ openHeadUTxO =
openHeadTxOut =
mkHeadOutput Fixture.testNetworkId Fixture.testPolicyId openHeadDatum
& addParticipationTokens [Fixture.alicePVk, Fixture.bobPVk, Fixture.carolPVk]
& modifyTxOutValue (<> foldMap txOutValue inHeadUTxO)

openHeadDatum =
mkTxOutDatumInline
Head.Open
{ parties = partyToChain <$> [Fixture.alice, Fixture.bob, Fixture.carol]
, utxoHash = toBuiltin $ hashUTxO @Tx $ fst $ generateUTxOFromModelSnapshot (ModelSnapshot 0 (fromList [A]) (fromList []))
, utxoHash = toBuiltin $ hashUTxO inHeadUTxO
, contestationPeriod = CP.toChain Fixture.cperiod
, headId = headIdToCurrencySymbol $ mkHeadId Fixture.testPolicyId
, snapshotNumber = 0
}

inHeadUTxO = foldMap realWorldModelUTxO (utxoInHead initialState)

-- | Creates a decrement transaction using given utxo and given snapshot.
newDecrementTx :: Actor -> (Snapshot Tx, MultiSignature (Snapshot Tx)) -> AppM (Either DecrementTxError Tx)
newDecrementTx actor (snapshot, signatures) = do
Expand Down Expand Up @@ -700,12 +707,12 @@ expectValid TxResult{observation} fn = do
expectInvalid :: Monad m => TxResult -> PostconditionM' m ()
expectInvalid = \case
TxResult{validationError = Nothing, constructedTx, spendableUTxO} -> do
counterexample' "Expected to fail validation"
counterexample' "Expected tx to fail validation"
case constructedTx of
Left err -> counterexample' $ "But construction failed with:" <> err
Right tx -> do
counterexample' $ renderTxWithUTxO spendableUTxO tx
fail ""
fail "But it did not fail"
_ -> pure ()

-- | Generate sometimes a value with given generator, bur more often just use
Expand Down

0 comments on commit bd66d18

Please sign in to comment.