@@ -125,6 +125,12 @@ module Test.Gen.Cardano.Api.Typed
125
125
, genLedgerValueForTxOut
126
126
, genLedgerMultiAssetValue
127
127
, genWitnesses
128
+ , genScriptWitnessedTxIn
129
+ , genScriptWitnessedTxMintValue
130
+ , genScriptWitnessedTxCertificates
131
+ , genScriptWitnessedTxProposals
132
+ , genScriptWitnessedTxWithdrawals
133
+ , genScriptWitnesssedTxVotingProcedures
128
134
, genWitnessNetworkIdOrByronAddress
129
135
, genRational
130
136
, genGovernancePoll
@@ -742,6 +748,17 @@ genTxWithdrawals =
742
748
]
743
749
)
744
750
751
+ genScriptWitnessedTxWithdrawals :: Exp. Era era -> Gen (TxWithdrawals BuildTx era )
752
+ genScriptWitnessedTxWithdrawals era = do
753
+ num <- Gen. integral (Range. constant 0 3 )
754
+ sAddrs <- Gen. list (Range. singleton num) genStakeAddress
755
+ coins <- Gen. list (Range. singleton num) genPositiveLovelace
756
+ sWits <-
757
+ Gen. list (Range. singleton num) $
758
+ ScriptWitness ScriptWitnessForStakeAddr <$> genApiPlutusScriptWitness WitCtxStake era
759
+ let withdrawals = zipWith3 (\ addr c wit -> (addr, c, BuildTxWith wit)) sAddrs coins sWits
760
+ return $ TxWithdrawals (convert era) withdrawals
761
+
745
762
genTxCertificates :: Typeable era => CardanoEra era -> Gen (TxCertificates BuildTx era )
746
763
genTxCertificates =
747
764
inEonForEra
@@ -755,6 +772,20 @@ genTxCertificates =
755
772
]
756
773
)
757
774
775
+ genScriptWitnessedTxCertificates :: Typeable era => Exp. Era era -> Gen (TxCertificates BuildTx era )
776
+ genScriptWitnessedTxCertificates era = do
777
+ let w = convert era
778
+ num <- Gen. integral (Range. linear 0 3 )
779
+ certs <- Gen. list (Range. singleton num) $ genCertificate w
780
+ plutusScriptWits <- Gen. list (Range. singleton num) $ genApiPlutusScriptWitness WitCtxStake era
781
+ let certsAndWits =
782
+ zipWith
783
+ (\ c p -> (c, Just p))
784
+ certs
785
+ plutusScriptWits
786
+
787
+ pure $ mkTxCertificates (convert era) certsAndWits
788
+
758
789
genCertificate :: forall era . Typeable era => ShelleyBasedEra era -> Gen (Certificate era )
759
790
genCertificate sbe =
760
791
Gen. choice $
@@ -1388,6 +1419,17 @@ genProposals w = conwayEraOnwardsConstraints w $ do
1388
1419
(proposal,) <$> Gen. maybe (genScriptWitnessForStake sbe)
1389
1420
pure $ mkTxProposalProcedures proposalsWithMaybeWitnesses
1390
1421
1422
+ genScriptWitnessedTxProposals
1423
+ :: Exp. Era era
1424
+ -> Gen (TxProposalProcedures BuildTx era )
1425
+ genScriptWitnessedTxProposals era = do
1426
+ let w = convert era
1427
+ num <- Gen. integral (Range. linear 0 3 )
1428
+ proposals <- Gen. list (Range. singleton num) (genProposal w)
1429
+ sWits <- Gen. list (Range. singleton num) $ genApiPlutusScriptWitness WitCtxStake era
1430
+ let proposalsWithMaybeWitnesses = zipWith (\ p wit -> (p, Just wit)) proposals sWits
1431
+ pure $ Exp. obtainCommonConstraints era $ mkTxProposalProcedures proposalsWithMaybeWitnesses
1432
+
1391
1433
genProposal :: ConwayEraOnwards era -> Gen (L. ProposalProcedure (ShelleyLedgerEra era ))
1392
1434
genProposal w =
1393
1435
conwayEraOnwardsTestConstraints w Q. arbitrary
@@ -1405,6 +1447,18 @@ genVotingProcedures w = conwayEraOnwardsConstraints w $ do
1405
1447
<$> Q. arbitrary
1406
1448
<*> pure (pure votersWithWitnesses)
1407
1449
1450
+ genScriptWitnesssedTxVotingProcedures
1451
+ :: Exp. Era era
1452
+ -> Gen (Api. TxVotingProcedures BuildTx era )
1453
+ genScriptWitnesssedTxVotingProcedures era = do
1454
+ num <- Gen. integral (Range. linear 0 3 )
1455
+ voters <- Gen. list (Range. singleton num) Q. arbitrary
1456
+ plutusScriptWits <- Gen. list (Range. singleton num) $ genApiPlutusScriptWitness WitCtxStake era
1457
+ let votersWithWitnesses = fromList $ zip voters plutusScriptWits
1458
+ Api. TxVotingProcedures
1459
+ <$> Exp. obtainCommonConstraints era Q. arbitrary
1460
+ <*> pure (pure votersWithWitnesses)
1461
+
1408
1462
genCurrentTreasuryValue :: ConwayEraOnwards era -> Gen L. Coin
1409
1463
genCurrentTreasuryValue _era = Q. arbitrary
1410
1464
@@ -1447,8 +1501,38 @@ genPlutusScriptWitness = do
1447
1501
genPlutusScriptDatum :: Gen (Exp. PlutusScriptDatum lang purpose )
1448
1502
genPlutusScriptDatum = return Exp. NoScriptDatum
1449
1503
1504
+ genScriptWitnessedTxIn
1505
+ :: Exp. Era era -> Gen [(TxIn , BuildTxWith BuildTx (Witness WitCtxTxIn era ))]
1506
+ genScriptWitnessedTxIn era = do
1507
+ num <- Gen. integral (Range. linear 0 3 )
1508
+ sWits <-
1509
+ map (ScriptWitness ScriptWitnessForSpending )
1510
+ <$> Gen. list (Range. singleton num) (genApiPlutusScriptWitness WitCtxTxIn era)
1511
+ txIns <- Gen. list (Range. singleton num) genTxIn
1512
+ pure $ zip txIns (BuildTxWith <$> sWits)
1513
+
1514
+ genScriptWitnessedTxMintValue
1515
+ :: Exp. Era era -> Gen (TxMintValue BuildTx era )
1516
+ genScriptWitnessedTxMintValue era = do
1517
+ let w = convert era
1518
+ num <- Gen. integral (Range. linear 0 3 )
1519
+ sWits <-
1520
+ Gen. list (Range. singleton num) (genApiPlutusScriptWitness WitCtxMint era)
1521
+
1522
+ policies <- Gen. list (Range. singleton num) genPolicyId
1523
+ mintValues <- Gen. list (Range. singleton num) genPolicyAssets
1524
+ let assets =
1525
+ [ (p, mintValue, BuildTxWith s)
1526
+ | p <- policies
1527
+ , s <- sWits
1528
+ , mintValue <- mintValues
1529
+ ]
1530
+
1531
+ pure $ mkTxMintValue w assets
1532
+
1450
1533
-- | This generator does not generate a valid witness - just a random one.
1451
- genScriptWitnessForStake :: ShelleyBasedEra era -> Gen (Api. ScriptWitness WitCtxStake era )
1534
+ genScriptWitnessForStake
1535
+ :: ShelleyBasedEra era -> Gen (Api. ScriptWitness WitCtxStake era )
1452
1536
genScriptWitnessForStake sbe = do
1453
1537
ScriptInEra scriptLangInEra script' <- genScriptInEra sbe
1454
1538
case script' of
@@ -1474,6 +1558,50 @@ genScriptWitnessForStake sbe = do
1474
1558
scriptRedeemer
1475
1559
<$> genExecutionUnits
1476
1560
1561
+ genAnyPlutusScriptVersion :: Gen AnyPlutusScriptVersion
1562
+ genAnyPlutusScriptVersion = do
1563
+ Gen. element [minBound .. maxBound ]
1564
+
1565
+ plutusScriptLangaugeInEra
1566
+ :: Exp. Era era -> PlutusScriptVersion lang -> ScriptLanguageInEra lang era
1567
+ plutusScriptLangaugeInEra Exp. ConwayEra l =
1568
+ case l of
1569
+ PlutusScriptV1 -> PlutusScriptV1InConway
1570
+ PlutusScriptV2 -> PlutusScriptV2InConway
1571
+ PlutusScriptV3 -> PlutusScriptV3InConway
1572
+
1573
+ genApiPlutusScriptWitness
1574
+ :: WitCtx witctx -> Exp. Era era -> Gen (Api. ScriptWitness witctx era )
1575
+ genApiPlutusScriptWitness witCtx era = do
1576
+ dat <- case witCtx of
1577
+ WitCtxTxIn -> do
1578
+ datum <- Gen. maybe genHashableScriptData
1579
+
1580
+ Gen. element [ScriptDatumForTxIn datum, InlineScriptDatum ]
1581
+ WitCtxMint -> do
1582
+ pure NoScriptDatumForMint
1583
+ WitCtxStake -> do
1584
+ pure NoScriptDatumForStake
1585
+
1586
+ AnyPlutusScriptVersion lang <- genAnyPlutusScriptVersion
1587
+ PlutusScript plutusScriptVersion' plutusScript <-
1588
+ PlutusScript lang <$> genValidPlutusScript lang
1589
+
1590
+ plutusScriptOrReferenceInput <-
1591
+ Gen. choice
1592
+ [ pure $ PScript plutusScript
1593
+ , PReferenceScript <$> genTxIn
1594
+ ]
1595
+
1596
+ scriptRedeemer <- genHashableScriptData
1597
+ PlutusScriptWitness
1598
+ (plutusScriptLangaugeInEra era lang)
1599
+ plutusScriptVersion'
1600
+ plutusScriptOrReferenceInput
1601
+ dat
1602
+ scriptRedeemer
1603
+ <$> genExecutionUnits
1604
+
1477
1605
genScriptWitnessForMint :: ShelleyBasedEra era -> Gen (Api. ScriptWitness WitCtxMint era )
1478
1606
genScriptWitnessForMint sbe = do
1479
1607
ScriptInEra scriptLangInEra script' <- genScriptInEra sbe
0 commit comments