Skip to content

Commit

Permalink
Realize that we need to keep track of PubKeyHash for abortTx
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo authored and abailly-iohk committed Sep 23, 2021
1 parent 06d20aa commit 934ba43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 8 additions & 4 deletions hydra-node/src/Hydra/Chain/Direct/Tx.hs
Expand Up @@ -58,7 +58,7 @@ type Era = AlonzoEra StandardCrypto
constructTx :: TxIn StandardCrypto -> PostChainTx tx -> ValidatedTx Era
constructTx txIn = \case
InitTx p -> initTx p txIn
AbortTx _utxo -> abortTx txIn
AbortTx _utxo -> abortTx (txIn, error "where is this coming from?")
_ -> error "not implemented"

-- | Create the init transaction from some 'HeadParameters' and a single TxIn
Expand Down Expand Up @@ -106,8 +106,12 @@ initTx HeadParameters{contestationPeriod, parties} txIn =
(contestationPeriodFromDiffTime contestationPeriod)
(map (partyFromVerKey . vkey) parties)

abortTx :: TxIn StandardCrypto -> ValidatedTx Era
abortTx txIn =
-- | Create transaction which aborts by spending one input. This is currently
-- only possible if this is governed by the initial script and only for a single
-- input. Of course, the Head protocol specifies we need to spend ALL the Utxo
-- containing PTs.
abortTx :: (TxIn StandardCrypto, PubKeyHash) -> ValidatedTx Era
abortTx (txIn, pkh) =
mkUnsignedTx body dats redeemers scripts
where
body =
Expand Down Expand Up @@ -147,7 +151,7 @@ abortTx txIn =

initialDatumHash = hashData @Era initialDatum

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

--

Expand Down
12 changes: 7 additions & 5 deletions hydra-node/test/Hydra/Chain/Direct/TxSpec.hs
Expand Up @@ -77,8 +77,9 @@ spec =
in Map.elems (unTxDats dats) === [Data . toData $ toBuiltinData datum]

describe "abortTx" $ do
prop "transaction size below limit" $ \txIn ->
let tx = abortTx txIn
prop "transaction size below limit" $ \txIn bytes ->
let tx = abortTx (txIn, pkh)
pkh = PubKeyHash $ toBuiltin (bytes :: ByteString)
cbor = serialize tx
len = LBS.length cbor
in counterexample ("Tx: " <> show tx) $
Expand All @@ -87,14 +88,15 @@ 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 pkh ->
let tx = abortTx txIn
prop "validates against 'initial' script in haskell (unlimited budget)" $ \txIn bytes ->
let tx = abortTx (txIn, pkh)
pkh = PubKeyHash $ toBuiltin (bytes :: ByteString)
-- 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 $ toBuiltin (pkh :: ByteString)
initialDatumHash = hashData @Era . Data $ toData pkh
results = validateTxScriptsUnlimited tx utxo
in 1 == length (rights $ Map.elems results)
& counterexample ("Evaluation results: " <> show results)
Expand Down

0 comments on commit 934ba43

Please sign in to comment.