Skip to content

Commit e23d763

Browse files
Add UTxO.size
1 parent a15be69 commit e23d763

File tree

9 files changed

+14
-10
lines changed

9 files changed

+14
-10
lines changed

hydra-cardano-api/src/Cardano/Api/UTxO.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ txOutputs = Map.elems . toMap
103103
null :: UTxO -> Bool
104104
null = Map.null . toMap
105105

106+
107+
size :: UTxO -> Int
108+
size = Map.size . toMap
109+
106110
-- * Type Conversions
107111

108112
-- | Transforms a UTxO containing tx outs from any era into Babbage era.

hydra-cluster/test/Test/Hydra/Cluster/FaucetSpec.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ spec =
3434
vk <- generate genVerificationKey
3535
seedFromFaucet node vk 1_000_000 tracer
3636
-- 10 unique outputs
37-
length (UTxO.txOutputs $ fold utxos) `shouldBe` 10
37+
UTxO.size (fold utxos) `shouldBe` 10
3838

3939
describe "returnFundsToFaucet" $ do
4040
it "does nothing if nothing to return" $ \(tracer, node) -> do
@@ -54,7 +54,7 @@ spec =
5454
UTxO.foldMap txOutValue remaining `shouldBe` mempty
5555

5656
-- check the faucet has one utxo extra in the end
57-
length (UTxO.txOutputs finalFaucetFunds) `shouldBe` length (UTxO.txOutputs initialFaucetFunds) + 1
57+
UTxO.size finalFaucetFunds `shouldBe` UTxO.size initialFaucetFunds + 1
5858

5959
let initialFaucetValue = selectLovelace (UTxO.foldMap txOutValue initialFaucetFunds)
6060
let finalFaucetValue = selectLovelace (UTxO.foldMap txOutValue finalFaucetFunds)
@@ -75,4 +75,4 @@ spec =
7575
-- it squashed the UTxO
7676
utxoAfter <- queryUTxOFor networkId nodeSocket QueryTip vk
7777

78-
length (UTxO.txOutputs utxoAfter) `shouldBe` 1
78+
UTxO.size utxoAfter `shouldBe` 1

hydra-node/bench/tx-cost/TxCost.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ computeCommitCost = do
102102
Right tx ->
103103
case checkSizeAndEvaluate tx (utxo <> knownUtxo) of
104104
Just (txSize, memUnit, cpuUnit, minFee) ->
105-
pure $ Just (NumUTxO $ length $ UTxO.txOutputs utxo, txSize, memUnit, cpuUnit, minFee)
105+
pure $ Just (NumUTxO $ UTxO.size utxo, txSize, memUnit, cpuUnit, minFee)
106106
Nothing ->
107107
pure Nothing
108108

hydra-node/test/Hydra/Chain/Direct/StateSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ prop_observeAnyTx =
476476
-- | Given a UTxO with more than one entry, we can split it into two non-empty UTxO.
477477
prop_splitUTxO :: UTxO -> Property
478478
prop_splitUTxO utxo =
479-
(length (UTxO.txOutputs utxo) > 1) ==>
479+
(UTxO.size utxo > 1) ==>
480480
let (inHead, toDecommit) = splitUTxO utxo
481481
in conjoin
482482
[ not (UTxO.null inHead) & counterexample "inHead is empty"

hydra-tx/src/Hydra/Tx/Decrement.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ decrementTx scriptRegistry vk headId headParameters (headInput, headOutput) snap
5555
{ signature = toPlutusSignatures signatures
5656
, snapshotNumber = fromIntegral number
5757
, numberOfDecommitOutputs =
58-
fromIntegral $ length $ maybe [] UTxO.txOutputs utxoToDecommit
58+
fromIntegral $ maybe 0 UTxO.size utxoToDecommit
5959
}
6060

6161
utxoHash = toBuiltin $ hashUTxO @Tx utxo

hydra-tx/src/Hydra/Tx/Fanout.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fanoutTx scriptRegistry utxo utxoToCommit utxoToDecommit (headInput, headOutput)
5252
headRedeemer =
5353
toScriptData $
5454
Head.Fanout
55-
{ numberOfFanoutOutputs = fromIntegral $ length $ UTxO.txOutputs utxo
55+
{ numberOfFanoutOutputs = fromIntegral $ UTxO.size utxo
5656
, numberOfCommitOutputs = fromIntegral $ length orderedTxOutsToCommit
5757
, numberOfDecommitOutputs = fromIntegral $ length orderedTxOutsToDecommit
5858
}

hydra-tx/test/Hydra/Tx/Contract/ContractSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ prop_consistentHashPreSerializedCommits =
227227
prop_hashingCaresAboutOrderingOfTxOuts :: Property
228228
prop_hashingCaresAboutOrderingOfTxOuts =
229229
forAllShrink genUTxOWithSimplifiedAddresses shrinkUTxO $ \(utxo :: UTxO) ->
230-
(length (UTxO.txOutputs utxo) > 1) ==>
230+
(UTxO.size utxo > 1) ==>
231231
let plutusTxOuts =
232232
rights $
233233
zipWith

hydra-tx/test/Hydra/Tx/Contract/Decrement.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ genDecrementMutation (tx, _utxo) =
184184
Head.DecrementRedeemer
185185
{ signature = invalidSignature
186186
, snapshotNumber = fromIntegral healthySnapshotNumber
187-
, numberOfDecommitOutputs = fromIntegral $ maybe 0 (length . UTxO.txOutputs) $ utxoToDecommit healthySnapshot
187+
, numberOfDecommitOutputs = fromIntegral $ maybe 0 UTxO.size $ utxoToDecommit healthySnapshot
188188
}
189189
, -- Spec: Transaction is signed by a participant
190190
SomeMutation (pure $ toErrorCode SignerIsNotAParticipant) AlterRequiredSigner <$> do

hydra-tx/test/Hydra/Tx/Contract/FanOut.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ healthyFanoutTx =
6767

6868
healthyFanoutUTxO :: UTxO
6969
healthyFanoutUTxO =
70-
UTxO.map adaOnly $ generateWith (genUTxOWithSimplifiedAddresses `suchThat` \u -> length (UTxO.txOutputs u) > 1) 42
70+
UTxO.map adaOnly $ generateWith (genUTxOWithSimplifiedAddresses `suchThat` \u -> UTxO.size u > 1) 42
7171

7272
healthySlotNo :: SlotNo
7373
healthySlotNo = arbitrary `generateWith` 42

0 commit comments

Comments
 (0)