@@ -7,13 +7,15 @@ use crate::plutus_data::PlutusData;
7
7
use crate :: v1:: address:: {
8
8
Address , CertificateIndex , ChainPointer , Credential , Slot , StakingCredential , TransactionIndex ,
9
9
} ;
10
- use crate :: v1:: crypto:: { Ed25519PubKeyHash , LedgerBytes } ;
10
+ use crate :: v1:: assoc_map:: AssocMap ;
11
+ use crate :: v1:: crypto:: { Ed25519PubKeyHash , LedgerBytes , PaymentPubKeyHash } ;
11
12
use crate :: v1:: datum:: { Datum , DatumHash } ;
12
13
use crate :: v1:: interval:: { Extended , LowerBound , PlutusInterval , UpperBound } ;
13
14
use crate :: v1:: redeemer:: { Redeemer , RedeemerHash } ;
14
15
use crate :: v1:: script:: { MintingPolicyHash , ScriptHash , ValidatorHash } ;
15
16
use crate :: v1:: transaction:: {
16
- POSIXTime , TransactionHash , TransactionInput , TransactionOutput , TxInInfo ,
17
+ DCert , POSIXTime , ScriptContext , ScriptPurpose , TransactionHash , TransactionInfo ,
18
+ TransactionInput , TransactionOutput , TxInInfo ,
17
19
} ;
18
20
use crate :: v2:: value:: { AssetClass , CurrencySymbol , TokenName , Value } ;
19
21
use num_bigint:: BigInt ;
@@ -243,7 +245,7 @@ pub fn arb_transaction_index() -> impl Strategy<Value = TransactionIndex> {
243
245
arb_integer ( ) . prop_map ( TransactionIndex )
244
246
}
245
247
246
- /// Strategy to generate a certificate index
248
+ /// Strategy to generate a certificate index.
247
249
pub fn arb_certificate_index ( ) -> impl Strategy < Value = CertificateIndex > {
248
250
arb_integer ( ) . prop_map ( CertificateIndex )
249
251
}
@@ -293,3 +295,80 @@ pub fn arb_tx_in_info() -> impl Strategy<Value = TxInInfo> {
293
295
( arb_transaction_input ( ) , arb_transaction_output ( ) )
294
296
. prop_map ( |( reference, output) | TxInInfo { reference, output } )
295
297
}
298
+
299
+ /// Strategy to generate an AssocMap, given the strategies to generate keys and values
300
+ pub fn arb_assoc_map < K : std:: fmt:: Debug , V : std:: fmt:: Debug > (
301
+ arb_k : impl Strategy < Value = K > ,
302
+ arb_v : impl Strategy < Value = V > ,
303
+ ) -> impl Strategy < Value = AssocMap < K , V > > {
304
+ vec ( ( arb_k, arb_v) , 10 ) . prop_map ( AssocMap )
305
+ }
306
+
307
+ /// Strategy to generate a PaymentPubKeyHash
308
+ pub fn arb_payment_pub_key_hash ( ) -> impl Strategy < Value = PaymentPubKeyHash > {
309
+ arb_ed25519_pub_key_hash ( ) . prop_map ( PaymentPubKeyHash )
310
+ }
311
+
312
+ /// Strategy to generate a DCert
313
+ pub fn arb_d_cert ( ) -> impl Strategy < Value = DCert > {
314
+ prop_oneof ! [
315
+ arb_staking_credential( ) . prop_map( DCert :: DelegKey ) ,
316
+ arb_staking_credential( ) . prop_map( DCert :: DelegDeregKey ) ,
317
+ ( arb_staking_credential( ) , arb_payment_pub_key_hash( ) )
318
+ . prop_map( |( sc, pkh) | DCert :: DelegDelegate ( sc, pkh) ) ,
319
+ ( arb_payment_pub_key_hash( ) , arb_payment_pub_key_hash( ) )
320
+ . prop_map( |( p1, p2) | DCert :: PoolRegister ( p1, p2) ) ,
321
+ ( arb_payment_pub_key_hash( ) , arb_integer( ) ) . prop_map( |( pkh, i) | DCert :: PoolRetire ( pkh, i) ) ,
322
+ Just ( DCert :: Genesis ) ,
323
+ Just ( DCert :: Mir )
324
+ ]
325
+ }
326
+
327
+ /// Strategy to generate a ScriptPurpose
328
+ pub fn arb_script_purpose ( ) -> impl Strategy < Value = ScriptPurpose > {
329
+ prop_oneof ! [
330
+ arb_currency_symbol( ) . prop_map( ScriptPurpose :: Minting ) ,
331
+ arb_transaction_input( ) . prop_map( ScriptPurpose :: Spending ) ,
332
+ arb_staking_credential( ) . prop_map( ScriptPurpose :: Rewarding ) ,
333
+ arb_d_cert( ) . prop_map( ScriptPurpose :: Certifying )
334
+ ]
335
+ }
336
+
337
+ /// Strategy to generate a TransactionInfo. Note that its inputs, outputs, d_cert,
338
+ /// signatories and datums field will each have a length of 0 to 5
339
+ pub fn arb_transaction_info ( ) -> impl Strategy < Value = TransactionInfo > {
340
+ (
341
+ vec ( arb_tx_in_info ( ) , 5 ) ,
342
+ vec ( arb_transaction_output ( ) , 5 ) ,
343
+ arb_value ( ) ,
344
+ arb_value ( ) ,
345
+ vec ( arb_d_cert ( ) , 5 ) ,
346
+ vec ( ( arb_staking_credential ( ) , arb_integer ( ) ) , 5 ) ,
347
+ arb_plutus_interval_posix_time ( ) ,
348
+ vec ( arb_payment_pub_key_hash ( ) , 5 ) ,
349
+ vec ( ( arb_datum_hash ( ) , arb_datum ( ) ) , 5 ) ,
350
+ arb_transaction_hash ( ) ,
351
+ )
352
+ . prop_map (
353
+ |( inputs, outputs, fee, mint, d_cert, wdrl, valid_range, signatories, datums, id) | {
354
+ TransactionInfo {
355
+ inputs,
356
+ outputs,
357
+ fee,
358
+ mint,
359
+ d_cert,
360
+ wdrl,
361
+ valid_range,
362
+ signatories,
363
+ datums,
364
+ id,
365
+ }
366
+ } ,
367
+ )
368
+ }
369
+
370
+ /// Strategy to generate a ScriptContext
371
+ pub fn arb_script_context ( ) -> impl Strategy < Value = ScriptContext > {
372
+ ( arb_script_purpose ( ) , arb_transaction_info ( ) )
373
+ . prop_map ( |( purpose, tx_info) | ScriptContext { purpose, tx_info } )
374
+ }
0 commit comments