Skip to content

Commit

Permalink
Draft MutateComittedValue mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Jan 26, 2022
1 parent d6270de commit d129d0f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 0 additions & 1 deletion hydra-node/src/Hydra/Chain/Direct/Tx.hs
Expand Up @@ -213,7 +213,6 @@ commitTx networkId party utxo (initialInput, vkh) =
commitDatum =
Api.mkTxOutDatum $ mkCommitDatum party (Head.validatorHash policyId) utxo

-- FIXME: WIP
mkCommitDatum :: Party -> Plutus.ValidatorHash -> Maybe (Api.TxIn, Api.TxOut Api.CtxUTxO Api.Era) -> Plutus.Datum
mkCommitDatum (partyFromVerKey . vkey -> party) headValidatorHash utxo =
Commit.datum (party, headValidatorHash, serializedUtxo)
Expand Down
12 changes: 10 additions & 2 deletions hydra-node/test/Hydra/Chain/Direct/Contract/Commit.hs
Expand Up @@ -8,14 +8,16 @@ import Hydra.Prelude
import Hydra.Chain.Direct.TxSpec ()

import Data.Maybe (fromJust)
import Hydra.Chain.Direct.Contract.Mutation (Mutation (ChangeOutput), SomeMutation (SomeMutation))
import Hydra.Chain.Direct.Contract.Mutation (Mutation (ChangeInput, ChangeOutput), SomeMutation (SomeMutation))
import qualified Hydra.Chain.Direct.Fixture as Fixture
import Hydra.Chain.Direct.Tx (commitTx, mkInitialOutput, pubKeyHash)
import Hydra.Ledger.Cardano (
CardanoTx,
CtxUTxO,
Era,
PaymentKey,
TxBody (..),
TxBodyContent (TxBodyContent, txIns),
TxIn,
TxOut (TxOut),
Utxo,
Expand All @@ -24,6 +26,7 @@ import Hydra.Ledger.Cardano (
genOutput,
genValue,
getOutputs,
getTxBody,
lovelaceToValue,
mkTxOutValue,
modifyTxOutValue,
Expand Down Expand Up @@ -65,7 +68,7 @@ healthyCommitTx =
committedUtxo :: (TxIn, TxOut CtxUTxO Era)
committedUtxo = flip generateWith 42 $ do
txIn <- arbitrary
txOut <- modifyTxOutValue (const $ lovelaceToValue 7_000_000) <$> (genOutput =<< arbitrary)
txOut <- modifyTxOutValue (const $ lovelaceToValue 8_000_000) <$> (genOutput =<< arbitrary)
pure (txIn, txOut)

commitVerificationKey :: VerificationKey PaymentKey
Expand All @@ -76,6 +79,7 @@ healthyCommitTx =

data CommitMutation
= MutateCommitOutputValue
| MutateComittedValue
deriving (Generic, Show, Enum, Bounded)

genCommitMutation :: (CardanoTx, Utxo) -> Gen SomeMutation
Expand All @@ -84,7 +88,11 @@ genCommitMutation (tx, _utxo) =
[ SomeMutation MutateCommitOutputValue . ChangeOutput 0 <$> do
mutatedValue <- (mkTxOutValue <$> genValue) `suchThat` (/= commitOutputValue)
pure $ TxOut commitOutputAddress mutatedValue commitOutputDatum
, SomeMutation MutateComittedValue . ChangeInput comittedTxIn
<$> (genOutput =<< arbitrary)
]
where
TxOut commitOutputAddress commitOutputValue commitOutputDatum =
fromJust $ getOutputs tx !!? 0

comittedTxIn = undefined

0 comments on commit d129d0f

Please sign in to comment.