plutus_ledger_api/goldens/
v1.rs1use crate::{
3 plutus_data::PlutusData,
4 v1::{
5 address::{Address, Credential, StakingCredential},
6 crypto::{Ed25519PubKeyHash, LedgerBytes, PaymentPubKeyHash},
7 datum::{Datum, DatumHash},
8 interval::{Interval, PlutusInterval},
9 redeemer::{Redeemer, RedeemerHash},
10 script::{MintingPolicyHash, ScriptHash, ValidatorHash},
11 transaction::{
12 DCert, POSIXTime, ScriptContext, ScriptPurpose, TransactionHash, TransactionInfo,
13 TransactionInput, TransactionOutput, TxInInfo,
14 },
15 value::{AssetClass, CurrencySymbol, TokenName, Value},
16 },
17 v2::address::{CertificateIndex, ChainPointer, Slot, TransactionIndex},
18};
19use num_bigint::BigInt;
20
21pub fn sample_script_hash() -> ScriptHash {
22 ScriptHash(LedgerBytes([1].repeat(28).to_vec()))
23}
24
25pub fn sample_currency_symbol() -> CurrencySymbol {
26 CurrencySymbol::NativeToken(MintingPolicyHash(sample_script_hash()))
27}
28
29pub fn sample_token_name() -> TokenName {
30 TokenName::from_string("Something").unwrap()
31}
32
33pub fn sample_asset_class() -> AssetClass {
34 AssetClass {
35 currency_symbol: sample_currency_symbol(),
36 token_name: sample_token_name(),
37 }
38}
39
40pub fn sample_value() -> Value {
41 Value::token_value(
42 &sample_currency_symbol(),
43 &sample_token_name(),
44 &BigInt::from(123),
45 ) + Value::ada_value(&BigInt::from(234))
46}
47
48pub fn sample_plutus_interval() -> PlutusInterval<POSIXTime> {
49 PlutusInterval::from(Interval::StartAt(POSIXTime(BigInt::from(1723106785))))
50}
51
52pub fn sample_ed25519_pub_key_hash() -> Ed25519PubKeyHash {
53 Ed25519PubKeyHash(LedgerBytes([0].repeat(28).to_vec()))
54}
55
56pub fn sample_credential() -> Credential {
57 Credential::Script(ValidatorHash(sample_script_hash()))
58}
59
60pub fn sample_staking_credential() -> StakingCredential {
61 StakingCredential::Hash(sample_credential())
62}
63
64pub fn sample_chain_pointer() -> ChainPointer {
65 ChainPointer {
66 slot_number: Slot(134561.into()),
67 transaction_index: TransactionIndex(4.into()),
68 certificate_index: CertificateIndex(10.into()),
69 }
70}
71
72pub fn sample_address() -> Address {
73 Address {
74 credential: Credential::PubKey(sample_ed25519_pub_key_hash()),
75 staking_credential: Some(sample_staking_credential()),
76 }
77}
78
79pub fn sample_transaction_hash() -> TransactionHash {
80 TransactionHash(LedgerBytes([0].repeat(32).to_vec()))
81}
82
83pub fn sample_transaction_input() -> TransactionInput {
84 TransactionInput {
85 transaction_id: sample_transaction_hash(),
86 index: BigInt::from(3),
87 }
88}
89
90pub fn sample_datum_hash() -> DatumHash {
91 DatumHash(LedgerBytes([0].repeat(32).to_vec()))
92}
93
94pub fn sample_plutus_data() -> PlutusData {
95 PlutusData::constr(1, vec![PlutusData::bytes("Something".as_bytes().to_vec())])
96}
97
98pub fn sample_datum() -> Datum {
99 Datum(sample_plutus_data())
100}
101
102pub fn sample_redeemer_hash() -> RedeemerHash {
103 RedeemerHash(LedgerBytes([0].repeat(32).to_vec()))
104}
105
106pub fn sample_redeemer() -> Redeemer {
107 Redeemer(PlutusData::Integer(BigInt::from(144)))
108}
109
110pub fn sample_tx_in_info() -> TxInInfo {
111 TxInInfo {
112 reference: sample_transaction_input(),
113 output: sample_transaction_output(),
114 }
115}
116
117pub fn sample_transaction_output() -> TransactionOutput {
118 TransactionOutput {
119 address: sample_address(),
120 value: sample_value(),
121 datum_hash: Some(sample_datum_hash()),
122 }
123}
124
125pub fn sample_payment_pub_key_hash() -> PaymentPubKeyHash {
126 PaymentPubKeyHash(sample_ed25519_pub_key_hash())
127}
128
129pub fn sample_script_purpose() -> ScriptPurpose {
130 ScriptPurpose::Minting(sample_currency_symbol())
131}
132
133pub fn sample_dcert() -> DCert {
134 DCert::DelegDelegate(sample_staking_credential(), sample_payment_pub_key_hash())
135}
136
137pub fn sample_transaction_info() -> TransactionInfo {
138 TransactionInfo {
139 inputs: vec![sample_tx_in_info()],
140 outputs: vec![sample_transaction_output()],
141 fee: sample_value(),
142 mint: sample_value(),
143 d_cert: vec![sample_dcert()],
144 wdrl: vec![(sample_staking_credential(), BigInt::from(12))],
145 valid_range: sample_plutus_interval(),
146 signatories: vec![sample_payment_pub_key_hash()],
147 datums: vec![(sample_datum_hash(), sample_datum())],
148 id: sample_transaction_hash(),
149 }
150}
151
152pub fn sample_script_context() -> ScriptContext {
153 ScriptContext {
154 tx_info: sample_transaction_info(),
155 purpose: sample_script_purpose(),
156 }
157}