Skip to content

Commit

Permalink
Randomize removed value from collectCom mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Mar 17, 2023
1 parent e2d771c commit ee59ee0
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions hydra-node/test/Hydra/Chain/Direct/Contract/CollectCom.hs
Expand Up @@ -46,7 +46,7 @@ import Hydra.Ledger.Cardano (genAdaOnlyUTxO, genAddressInEra, genTxIn, genVerifi
import Hydra.Party (Party, partyToChain)
import Plutus.Orphans ()
import Plutus.V2.Ledger.Api (toBuiltin, toData)
import Test.QuickCheck (elements, oneof, suchThat)
import Test.QuickCheck (choose, elements, oneof, suchThat)
import Test.QuickCheck.Instances ()
import qualified Prelude

Expand Down Expand Up @@ -200,9 +200,15 @@ genCollectComMutation (tx, _utxo) =
mutatedAddress <- genAddressInEra testNetworkId
pure $ ChangeOutput 0 (modifyTxOutAddress (const mutatedAddress) headTxOut)
, SomeMutation (Just $ toErrorCode NotAllValueCollected) ExtractSomeValue <$> do
-- Remove one lovelace from headOutput, i.e. to "collect dust"
-- TODO: select a random asset and amount
let removedValue = lovelaceToValue 1
-- Remove a random asset and quantity from headOutput
removedValue <- do
let allAssets = valueToList $ txOutValue headTxOut
nonPTs = flip filter allAssets $ \case
(AssetId pid _, _) -> pid /= testPolicyId
_ -> True
(assetId, Quantity n) <- elements nonPTs
q <- Quantity <$> choose (0, n)
pure $ valueFromList [(assetId, q)]
-- Add another output which would extract the 'removedValue'. The ledger
-- would check for this, and this is needed because the way we implement
-- collectCom checks.
Expand Down

0 comments on commit ee59ee0

Please sign in to comment.