Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a healthyCommitTx and validate it
Factored out 'mkInitialOutput' to be able to use it in the commit unit tests.
- Loading branch information
Showing
4 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
-- | Mutation-based script validator tests for the commit transaction where a | ||
-- 'healthyCommitTx' gets mutated by an arbitrary 'genCommitMutation' | ||
module Hydra.Chain.Direct.Contract.Commit where | ||
|
||
import Hydra.Prelude | ||
|
||
import qualified Hydra.Chain.Direct.Fixture as Fixture | ||
import Hydra.Chain.Direct.Tx (commitTx, mkInitialOutput) | ||
import Hydra.Ledger.Cardano (CardanoTx, CtxUTxO, Era, PaymentKey, TxIn, TxOut, Utxo, VerificationKey, adaOnly, fromLedgerTx, genOutput, singletonUtxo, toCtxUTxOTxOut, toLedgerTxIn) | ||
import Hydra.Party (Party) | ||
|
||
-- Arbitrary VerificationKey instance | ||
import Hydra.Chain.Direct.TxSpec () | ||
|
||
-- | ||
-- CommitTx | ||
-- | ||
|
||
healthyCommitTx :: (CardanoTx, Utxo) | ||
healthyCommitTx = | ||
( fromLedgerTx tx | ||
, lookupUtxo | ||
) | ||
where | ||
lookupUtxo = singletonUtxo (initialInput, toCtxUTxOTxOut initialOutput) | ||
|
||
tx = | ||
commitTx | ||
Fixture.testNetworkId | ||
healthyCommitParty | ||
healthyCommittedUtxo | ||
(toLedgerTxIn initialInput, initialPubKeyHash) | ||
|
||
initialInput = generateWith arbitrary 42 | ||
|
||
initialOutput = mkInitialOutput Fixture.testNetworkId healthyCommitVerificationKey | ||
|
||
initialPubKeyHash = generateWith arbitrary 42 | ||
|
||
-- NOTE: An ada-only output which is currently addressed to some arbitrary | ||
-- public key. | ||
healthyCommittedUtxo :: Maybe (TxIn, TxOut CtxUTxO Era) | ||
healthyCommittedUtxo = flip generateWith 42 $ do | ||
txIn <- arbitrary | ||
txOut <- adaOnly <$> (genOutput =<< arbitrary) | ||
pure $ Just (txIn, txOut) | ||
|
||
healthyCommitVerificationKey :: VerificationKey PaymentKey | ||
healthyCommitVerificationKey = generateWith arbitrary 42 | ||
|
||
healthyCommitParty :: Party | ||
healthyCommitParty = generateWith arbitrary 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters