Skip to content

Commit

Permalink
Introduce datums when constructing AbortTx
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly-iohk committed Sep 23, 2021
1 parent 4d4308c commit 06d20aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
11 changes: 8 additions & 3 deletions hydra-node/src/Hydra/Chain/Direct/Tx.hs
Expand Up @@ -31,7 +31,7 @@ import Hydra.Contract.Head (State (Initial))
import Hydra.Data.ContestationPeriod (contestationPeriodFromDiffTime, contestationPeriodToDiffTime)
import Hydra.Data.Party (partyFromVerKey, partyToVerKey)
import Hydra.Party (anonymousParty, vkey)
import Plutus.V1.Ledger.Api (ValidatorHash (ValidatorHash), fromBuiltin, fromData, toData)
import Plutus.V1.Ledger.Api (PubKeyHash (..), ValidatorHash (ValidatorHash), fromBuiltin, fromData, toData)
import Shelley.Spec.Ledger.API (
Coin (..),
Credential (ScriptHashObj),
Expand All @@ -42,7 +42,6 @@ import Shelley.Spec.Ledger.API (
TxIn,
Wdrl (Wdrl),
)
import Shelley.Spec.Ledger.Tx (hashScript)

-- TODO(SN): parameterize
network :: Network
Expand Down Expand Up @@ -109,7 +108,7 @@ initTx HeadParameters{contestationPeriod, parties} txIn =

abortTx :: TxIn StandardCrypto -> ValidatedTx Era
abortTx txIn =
mkUnsignedTx body mempty redeemers scripts
mkUnsignedTx body dats redeemers scripts
where
body =
TxBody
Expand Down Expand Up @@ -144,6 +143,12 @@ abortTx txIn =

initialScript = PlutusScript . toShort . fromLazy $ serialize Initial.validatorScript

dats = TxDats $ Map.singleton initialDatumHash initialDatum

initialDatumHash = hashData @Era initialDatum

initialDatum = Data . toData $ PubKeyHash "not a PubKeyHash"

--

-- * Observe Hydra Head transactions
Expand Down
7 changes: 4 additions & 3 deletions hydra-node/test/Hydra/Chain/Direct/TxSpec.hs
Expand Up @@ -36,11 +36,12 @@ import Hydra.Data.ContestationPeriod (contestationPeriodFromDiffTime)
import Hydra.Data.Party (partyFromVerKey)
import Hydra.Ledger.Simple (SimpleTx)
import Hydra.Party (vkey)
import Plutus.V1.Ledger.Api (PubKeyHash (PubKeyHash), toBuiltinData, toData)
import Plutus.V1.Ledger.Api (PubKeyHash (PubKeyHash), toBuiltin, toBuiltinData, toData)
import Shelley.Spec.Ledger.API (Coin (Coin), StrictMaybe (SJust), UTxO (UTxO))
import Test.Cardano.Ledger.Alonzo.PlutusScripts (defaultCostModel)
import Test.Cardano.Ledger.Alonzo.Serialisation.Generators ()
import Test.QuickCheck (counterexample, (===), (==>))
import Test.QuickCheck.Instances ()

-- TODO(SN): use real max tx size
maxTxSize :: Int64
Expand Down Expand Up @@ -86,14 +87,14 @@ spec =

-- TODO(SN): this requires the abortTx to include a redeemer, for a TxIn,
-- spending an Initial-validated output
prop "validates against 'initial' script in haskell (unlimited budget)" $ \txIn ->
prop "validates against 'initial' script in haskell (unlimited budget)" $ \txIn pkh ->
let tx = abortTx txIn
-- input governed by initial script and a 'Plutus.PubKeyHash' datum
utxo = UTxO $ Map.singleton txIn txOut
txOut = TxOut initialAddress initialValue (SJust initialDatumHash)
initialAddress = validatorHashToAddr Initial.validatorHash
initialValue = inject (Coin 0)
initialDatumHash = hashData @Era . Data . toData $ PubKeyHash "not a PubKeyHash"
initialDatumHash = hashData @Era . Data . toData $ PubKeyHash $ toBuiltin (pkh :: ByteString)
results = validateTxScriptsUnlimited tx utxo
in 1 == length (rights $ Map.elems results)
& counterexample ("Evaluation results: " <> show results)
Expand Down

0 comments on commit 06d20aa

Please sign in to comment.