snarkvm_ledger_test_helpers/
lib.rs

1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use algorithms::snark::varuna::VarunaVersion;
17use console::{
18    account::{Address, PrivateKey},
19    prelude::*,
20    program::{Ciphertext, Literal, Plaintext, ProgramOwner, Record, Value},
21    types::Field,
22};
23use ledger_block::{
24    Block,
25    ConfirmedTransaction,
26    Deployment,
27    Execution,
28    Fee,
29    Header,
30    Input,
31    Output,
32    Ratifications,
33    Rejected,
34    Transaction,
35    Transactions,
36    Transition,
37};
38use ledger_query::Query;
39use ledger_store::{BlockStore, helpers::memory::BlockMemory};
40use synthesizer_process::Process;
41use synthesizer_program::Program;
42
43use aleo_std::StorageMode;
44use once_cell::sync::OnceCell;
45
46type CurrentNetwork = console::network::MainnetV0;
47type CurrentAleo = circuit::network::AleoV0;
48
49/****************************************** Transition ********************************************/
50
51/// Samples a random transition.
52pub fn sample_transition(rng: &mut TestRng) -> Transition<CurrentNetwork> {
53    crate::sample_execution(rng).into_transitions().next().unwrap()
54}
55
56/// Sample the transition inputs.
57pub fn sample_inputs() -> Vec<(<CurrentNetwork as Network>::TransitionID, Input<CurrentNetwork>)> {
58    let rng = &mut TestRng::default();
59
60    // Sample a transition.
61    let transaction = crate::sample_execution_transaction_with_fee(true, rng);
62    let transition = transaction.transitions().next().unwrap();
63
64    // Retrieve the transition ID and input.
65    let transition_id = *transition.id();
66    let input = transition.inputs().iter().next().unwrap().clone();
67
68    // Sample a random plaintext.
69    let plaintext = Plaintext::Literal(Literal::Field(Uniform::rand(rng)), Default::default());
70    let plaintext_hash = CurrentNetwork::hash_bhp1024(&plaintext.to_bits_le()).unwrap();
71    // Sample a random ciphertext.
72    let fields: Vec<_> = (0..10).map(|_| Uniform::rand(rng)).collect();
73    let ciphertext = Ciphertext::from_fields(&fields).unwrap();
74    let ciphertext_hash = CurrentNetwork::hash_bhp1024(&ciphertext.to_bits_le()).unwrap();
75
76    vec![
77        (transition_id, input),
78        (Uniform::rand(rng), Input::Constant(Uniform::rand(rng), None)),
79        (Uniform::rand(rng), Input::Constant(plaintext_hash, Some(plaintext.clone()))),
80        (Uniform::rand(rng), Input::Public(Uniform::rand(rng), None)),
81        (Uniform::rand(rng), Input::Public(plaintext_hash, Some(plaintext))),
82        (Uniform::rand(rng), Input::Private(Uniform::rand(rng), None)),
83        (Uniform::rand(rng), Input::Private(ciphertext_hash, Some(ciphertext))),
84        (Uniform::rand(rng), Input::Record(Uniform::rand(rng), Uniform::rand(rng))),
85        (Uniform::rand(rng), Input::ExternalRecord(Uniform::rand(rng))),
86    ]
87}
88
89/// Sample the transition outputs.
90pub fn sample_outputs() -> Vec<(<CurrentNetwork as Network>::TransitionID, Output<CurrentNetwork>)> {
91    let rng = &mut TestRng::default();
92
93    // Sample a transition.
94    let transaction = crate::sample_execution_transaction_with_fee(true, rng);
95    let transition = transaction.transitions().next().unwrap();
96
97    // Retrieve the transition ID and input.
98    let transition_id = *transition.id();
99    let input = transition.outputs().iter().next().unwrap().clone();
100
101    // Sample a random plaintext.
102    let plaintext = Plaintext::Literal(Literal::Field(Uniform::rand(rng)), Default::default());
103    let plaintext_hash = CurrentNetwork::hash_bhp1024(&plaintext.to_bits_le()).unwrap();
104    // Sample a random ciphertext.
105    let fields: Vec<_> = (0..10).map(|_| Uniform::rand(rng)).collect();
106    let ciphertext = Ciphertext::from_fields(&fields).unwrap();
107    let ciphertext_hash = CurrentNetwork::hash_bhp1024(&ciphertext.to_bits_le()).unwrap();
108    // Sample a random record.
109    let randomizer = Uniform::rand(rng);
110    let nonce = CurrentNetwork::g_scalar_multiply(&randomizer);
111    let record = Record::<CurrentNetwork, Plaintext<CurrentNetwork>>::from_str(
112        &format!("{{ owner: aleo1d5hg2z3ma00382pngntdp68e74zv54jdxy249qhaujhks9c72yrs33ddah.private, token_amount: 100u64.private, _nonce: {nonce}.public }}"),
113    ).unwrap();
114    let record_ciphertext = record.encrypt(randomizer).unwrap();
115    let record_checksum = CurrentNetwork::hash_bhp1024(&record_ciphertext.to_bits_le()).unwrap();
116    // Sample a sender ciphertext.
117    let sender_ciphertext = match record_ciphertext.version().is_zero() {
118        true => None,
119        false => Some(Uniform::rand(rng)),
120    };
121
122    vec![
123        (transition_id, input),
124        (Uniform::rand(rng), Output::Constant(Uniform::rand(rng), None)),
125        (Uniform::rand(rng), Output::Constant(plaintext_hash, Some(plaintext.clone()))),
126        (Uniform::rand(rng), Output::Public(Uniform::rand(rng), None)),
127        (Uniform::rand(rng), Output::Public(plaintext_hash, Some(plaintext))),
128        (Uniform::rand(rng), Output::Private(Uniform::rand(rng), None)),
129        (Uniform::rand(rng), Output::Private(ciphertext_hash, Some(ciphertext))),
130        (Uniform::rand(rng), Output::Record(Uniform::rand(rng), Uniform::rand(rng), None, sender_ciphertext)),
131        (
132            Uniform::rand(rng),
133            Output::Record(Uniform::rand(rng), record_checksum, Some(record_ciphertext), sender_ciphertext),
134        ),
135        (Uniform::rand(rng), Output::ExternalRecord(Uniform::rand(rng))),
136    ]
137}
138
139/******************************************* Deployment *******************************************/
140
141pub fn sample_deployment(rng: &mut TestRng) -> Deployment<CurrentNetwork> {
142    static INSTANCE: OnceCell<Deployment<CurrentNetwork>> = OnceCell::new();
143    INSTANCE
144        .get_or_init(|| {
145            // Initialize a new program.
146            let (string, program) = Program::<CurrentNetwork>::parse(
147                r"
148program testing.aleo;
149
150mapping store:
151    key as u32.public;
152    value as u32.public;
153
154function compute:
155    input r0 as u32.private;
156    add r0 r0 into r1;
157    output r1 as u32.public;",
158            )
159            .unwrap();
160            assert!(string.is_empty(), "Parser did not consume all of the string: '{string}'");
161
162            // Construct the process.
163            let process = Process::load().unwrap();
164            // Compute the deployment.
165            let deployment = process.deploy::<CurrentAleo, _>(&program, rng).unwrap();
166            // Return the deployment.
167            // Note: This is a testing-only hack to adhere to Rust's dependency cycle rules.
168            Deployment::from_str(&deployment.to_string()).unwrap()
169        })
170        .clone()
171}
172
173/// Samples a rejected deployment.
174pub fn sample_rejected_deployment(edition: u16, is_fee_private: bool, rng: &mut TestRng) -> Rejected<CurrentNetwork> {
175    // Sample a deploy transaction.
176    let deployment = match crate::sample_deployment_transaction(edition, is_fee_private, rng) {
177        Transaction::Deploy(_, _, _, deployment, _) => (*deployment).clone(),
178        _ => unreachable!(),
179    };
180
181    // Sample a new program owner.
182    let private_key = PrivateKey::new(rng).unwrap();
183    let deployment_id = deployment.to_deployment_id().unwrap();
184    let program_owner = ProgramOwner::new(&private_key, deployment_id, rng).unwrap();
185
186    // Return the rejected deployment.
187    Rejected::new_deployment(program_owner, deployment)
188}
189
190/******************************************* Execution ********************************************/
191
192/// Samples a random execution.
193pub fn sample_execution(rng: &mut TestRng) -> Execution<CurrentNetwork> {
194    // Sample the genesis block.
195    let block = crate::sample_genesis_block(rng);
196    // Retrieve a transaction.
197    let transaction = block.transactions().iter().next().unwrap().deref().clone();
198    // Retrieve the execution.
199    if let Transaction::Execute(_, _, execution, _) = transaction { *execution } else { unreachable!() }
200}
201
202/// Samples a rejected execution.
203pub fn sample_rejected_execution(is_fee_private: bool, rng: &mut TestRng) -> Rejected<CurrentNetwork> {
204    // Sample an execute transaction.
205    let execution = match crate::sample_execution_transaction_with_fee(is_fee_private, rng) {
206        Transaction::Execute(_, _, execution, _) => execution,
207        _ => unreachable!(),
208    };
209
210    // Return the rejected execution.
211    Rejected::new_execution(*execution)
212}
213
214/********************************************** Fee ***********************************************/
215
216/// Samples a random hardcoded private fee.
217pub fn sample_fee_private_hardcoded(rng: &mut TestRng) -> Fee<CurrentNetwork> {
218    static INSTANCE: OnceCell<Fee<CurrentNetwork>> = OnceCell::new();
219    INSTANCE
220        .get_or_init(|| {
221            // Sample a deployment or execution ID.
222            let deployment_or_execution_id = Field::rand(rng);
223            // Sample a fee.
224            sample_fee_private(deployment_or_execution_id, rng)
225        })
226        .clone()
227}
228
229/// Samples a random private fee.
230pub fn sample_fee_private(deployment_or_execution_id: Field<CurrentNetwork>, rng: &mut TestRng) -> Fee<CurrentNetwork> {
231    // Sample the genesis block, transaction, and private key.
232    let (block, transaction, private_key) = crate::sample_genesis_block_and_components(rng);
233    // Retrieve a credits record.
234    let credits = transaction.records().next().unwrap().1.clone();
235    // Decrypt the record.
236    let credits = credits.decrypt(&private_key.try_into().unwrap()).unwrap();
237    // Sample a base fee in microcredits.
238    let base_fee_in_microcredits = 10_000_000;
239    // Sample a priority fee in microcredits.
240    let priority_fee_in_microcredits = 1_000;
241
242    // Initialize the process.
243    let process = Process::load().unwrap();
244    // Authorize the fee.
245    let authorization = process
246        .authorize_fee_private::<CurrentAleo, _>(
247            &private_key,
248            credits,
249            base_fee_in_microcredits,
250            priority_fee_in_microcredits,
251            deployment_or_execution_id,
252            rng,
253        )
254        .unwrap();
255    // Construct the fee trace.
256    let (_, mut trace) = process.execute::<CurrentAleo, _>(authorization, rng).unwrap();
257
258    // Initialize a new block store.
259    let block_store = BlockStore::<CurrentNetwork, BlockMemory<_>>::open(StorageMode::new_test(None)).unwrap();
260    // Insert the block into the block store.
261    // Note: This is a testing-only hack to adhere to Rust's dependency cycle rules.
262    block_store.insert(&FromStr::from_str(&block.to_string()).unwrap()).unwrap();
263
264    // Prepare the assignments.
265    trace.prepare(&Query::from(block_store)).unwrap();
266    // Compute the proof and construct the fee.
267    let fee = trace.prove_fee::<CurrentAleo, _>(VarunaVersion::V1, rng).unwrap();
268
269    // Convert the fee.
270    // Note: This is a testing-only hack to adhere to Rust's dependency cycle rules.
271    Fee::from_str(&fee.to_string()).unwrap()
272}
273
274/// Samples a random hardcoded public fee.
275pub fn sample_fee_public_hardcoded(rng: &mut TestRng) -> Fee<CurrentNetwork> {
276    static INSTANCE: OnceCell<Fee<CurrentNetwork>> = OnceCell::new();
277    INSTANCE
278        .get_or_init(|| {
279            // Sample a deployment or execution ID.
280            let deployment_or_execution_id = Field::rand(rng);
281            // Sample a fee.
282            sample_fee_public(deployment_or_execution_id, rng)
283        })
284        .clone()
285}
286
287/// Samples a random public fee.
288pub fn sample_fee_public(deployment_or_execution_id: Field<CurrentNetwork>, rng: &mut TestRng) -> Fee<CurrentNetwork> {
289    // Sample the genesis block, transaction, and private key.
290    let (block, _, private_key) = crate::sample_genesis_block_and_components(rng);
291    // Sample a base fee in microcredits.
292    let base_fee_in_microcredits = 10_000_000;
293    // Sample a priority fee in microcredits.
294    let priority_fee_in_microcredits = 1_000;
295
296    // Initialize the process.
297    let process = Process::load().unwrap();
298    // Authorize the fee.
299    let authorization = process
300        .authorize_fee_public::<CurrentAleo, _>(
301            &private_key,
302            base_fee_in_microcredits,
303            priority_fee_in_microcredits,
304            deployment_or_execution_id,
305            rng,
306        )
307        .unwrap();
308    // Construct the fee trace.
309    let (_, mut trace) = process.execute::<CurrentAleo, _>(authorization, rng).unwrap();
310
311    // Initialize a new block store.
312    let block_store = BlockStore::<CurrentNetwork, BlockMemory<_>>::open(StorageMode::new_test(None)).unwrap();
313    // Insert the block into the block store.
314    // Note: This is a testing-only hack to adhere to Rust's dependency cycle rules.
315    block_store.insert(&FromStr::from_str(&block.to_string()).unwrap()).unwrap();
316
317    // Prepare the assignments.
318    trace.prepare(&Query::from(block_store)).unwrap();
319    // Compute the proof and construct the fee.
320    let fee = trace.prove_fee::<CurrentAleo, _>(VarunaVersion::V1, rng).unwrap();
321
322    // Convert the fee.
323    // Note: This is a testing-only hack to adhere to Rust's dependency cycle rules.
324    Fee::from_str(&fee.to_string()).unwrap()
325}
326
327/******************************************** Program *********************************************/
328
329/// Deploy a program that produces large transactions under the maximum transaction size.
330pub fn small_transaction_program() -> Program<CurrentNetwork> {
331    Program::from_str(
332        r"
333program testing_small.aleo;
334function small_transaction:
335    cast 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field into r0 as [field; 32u32];
336    cast r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 into r1 as [[field; 32u32]; 32u32];
337    cast r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 into r2 as [[field; 32u32]; 32u32];
338    cast r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 into r3 as [[field; 32u32]; 32u32];
339    output r1 as [[field; 32u32]; 32u32].public;
340    output r2 as [[field; 32u32]; 32u32].public;
341    output r3 as [[field; 32u32]; 32u32].public;").unwrap()
342}
343
344/// Deploy a program that produces large transactions above the maximum transaction size.
345pub fn large_transaction_program() -> Program<CurrentNetwork> {
346    Program::from_str(
347        r"
348program testing_large.aleo;
349function large_transaction:
350    cast 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field 0field into r0 as [field; 32u32];
351    cast r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 into r1 as [[field; 32u32]; 27u32];
352    cast r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 into r2 as [[field; 32u32]; 27u32];
353    cast r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 into r3 as [[field; 32u32]; 27u32];
354    cast r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 r0 into r4 as [[field; 32u32]; 27u32];
355    output r1 as [[field; 32u32]; 27u32].public;
356    output r2 as [[field; 32u32]; 27u32].public;
357    output r3 as [[field; 32u32]; 27u32].public;
358    output r4 as [[field; 32u32]; 27u32].public;").unwrap()
359}
360
361/****************************************** Transaction *******************************************/
362
363/// Samples a random deployment transaction with a private or public fee.
364pub fn sample_deployment_transaction(
365    edition: u16,
366    is_fee_private: bool,
367    rng: &mut TestRng,
368) -> Transaction<CurrentNetwork> {
369    // Sample a private key.
370    let private_key = PrivateKey::new(rng).unwrap();
371    // Sample a deployment.
372    let deployment = crate::sample_deployment(rng);
373    // Create a new deployment with the desired edition.
374    let deployment =
375        Deployment::<CurrentNetwork>::new(edition, deployment.program().clone(), deployment.verifying_keys().clone())
376            .unwrap();
377
378    // Compute the deployment ID.
379    let deployment_id = deployment.to_deployment_id().unwrap();
380    // Construct a program owner.
381    let owner = ProgramOwner::new(&private_key, deployment_id, rng).unwrap();
382
383    // Sample the fee.
384    let fee = match is_fee_private {
385        true => crate::sample_fee_private(deployment_id, rng),
386        false => crate::sample_fee_public(deployment_id, rng),
387    };
388
389    // Construct a deployment transaction.
390    Transaction::from_deployment(owner, deployment, fee).unwrap()
391}
392
393/// Samples a random execution transaction with a private or public fee.
394pub fn sample_execution_transaction_with_fee(is_fee_private: bool, rng: &mut TestRng) -> Transaction<CurrentNetwork> {
395    // Sample an execution.
396    let execution = crate::sample_execution(rng);
397    // Compute the execution ID.
398    let execution_id = execution.to_execution_id().unwrap();
399
400    // Sample the fee.
401    let fee = match is_fee_private {
402        true => crate::sample_fee_private(execution_id, rng),
403        false => crate::sample_fee_public(execution_id, rng),
404    };
405
406    // Construct an execution transaction.
407    Transaction::from_execution(execution, Some(fee)).unwrap()
408}
409
410/// Samples a large transaction.
411pub fn sample_large_execution_transaction(rng: &mut TestRng) -> Transaction<CurrentNetwork> {
412    static INSTANCE: once_cell::sync::OnceCell<Execution<CurrentNetwork>> = once_cell::sync::OnceCell::new();
413
414    let execution = INSTANCE
415        .get_or_init(|| {
416            // Initialize a program that produces large transactions.
417            let program = large_transaction_program();
418
419            // Construct the process.
420            let mut process = synthesizer_process::Process::load().unwrap();
421            // Add the program.
422            process.add_program(&program).unwrap();
423
424            // Initialize a private key.
425            let private_key = PrivateKey::new(rng).unwrap();
426
427            // Authorize the function.
428            let authorization = process
429                .authorize::<CurrentAleo, _>(
430                    &private_key,
431                    "testing_large.aleo",
432                    "large_transaction",
433                    Vec::<Value<CurrentNetwork>>::new().iter(),
434                    rng,
435                )
436                .unwrap();
437            // Execute the function.
438            let (_, mut trace) = process.execute::<CurrentAleo, _>(authorization, rng).unwrap();
439
440            // Initialize a new block store.
441            let block_store =
442                ledger_store::BlockStore::<CurrentNetwork, ledger_store::helpers::memory::BlockMemory<_>>::open(
443                    StorageMode::new_test(None),
444                )
445                .unwrap();
446
447            // Prepare the assignments.
448            trace.prepare(&ledger_query::Query::from(block_store)).unwrap();
449            // Compute the proof and construct the execution.
450            let execution = trace.prove_execution::<CurrentAleo, _>("testing.aleo", VarunaVersion::V1, rng).unwrap();
451            // Reconstruct the execution from bytes.
452            // This is a hack to get around Rust dependency resolution.
453            Execution::from_bytes_le(&execution.to_bytes_le().unwrap()).unwrap()
454        })
455        .clone();
456
457    // Compute the execution ID.
458    let execution_id = execution.to_execution_id().unwrap();
459
460    // Sample the fee.
461    let fee = crate::sample_fee_public(execution_id, rng);
462
463    // Construct an execution transaction.
464    Transaction::from_execution(execution, Some(fee)).unwrap()
465}
466
467/// Samples a random private fee transaction.
468pub fn sample_fee_private_transaction(rng: &mut TestRng) -> Transaction<CurrentNetwork> {
469    // Sample a private fee.
470    let fee = crate::sample_fee_private_hardcoded(rng);
471    // Construct a fee transaction.
472    Transaction::from_fee(fee).unwrap()
473}
474
475/// Samples a random public fee transaction.
476pub fn sample_fee_public_transaction(rng: &mut TestRng) -> Transaction<CurrentNetwork> {
477    // Sample a public fee.
478    let fee = crate::sample_fee_public_hardcoded(rng);
479    // Construct a fee transaction.
480    Transaction::from_fee(fee).unwrap()
481}
482
483/****************************************** Transactions ******************************************/
484
485/// Samples a block transactions.
486pub fn sample_block_transactions(rng: &mut TestRng) -> Transactions<CurrentNetwork> {
487    crate::sample_genesis_block(rng).transactions().clone()
488}
489
490/********************************************* Block **********************************************/
491
492/// Samples a random genesis block.
493pub fn sample_genesis_block(rng: &mut TestRng) -> Block<CurrentNetwork> {
494    // Sample the genesis block and components.
495    let (block, _, _) = crate::sample_genesis_block_and_components(rng);
496    // Return the block.
497    block
498}
499
500/// Samples a random genesis block and the transaction from the genesis block.
501pub fn sample_genesis_block_and_transaction(rng: &mut TestRng) -> (Block<CurrentNetwork>, Transaction<CurrentNetwork>) {
502    // Sample the genesis block and components.
503    let (block, transaction, _) = crate::sample_genesis_block_and_components(rng);
504    // Return the block and transaction.
505    (block, transaction)
506}
507
508/// Samples a random genesis block, the transaction from the genesis block, and the genesis private key.
509pub fn sample_genesis_block_and_components(
510    rng: &mut TestRng,
511) -> (Block<CurrentNetwork>, Transaction<CurrentNetwork>, PrivateKey<CurrentNetwork>) {
512    static INSTANCE: OnceCell<(Block<CurrentNetwork>, Transaction<CurrentNetwork>, PrivateKey<CurrentNetwork>)> =
513        OnceCell::new();
514    INSTANCE.get_or_init(|| crate::sample_genesis_block_and_components_raw(rng)).clone()
515}
516
517pub fn sample_genesis_private_key(rng: &mut TestRng) -> PrivateKey<CurrentNetwork> {
518    static INSTANCE: OnceCell<PrivateKey<CurrentNetwork>> = OnceCell::new();
519    *INSTANCE.get_or_init(|| {
520        // Initialize a new caller.
521        PrivateKey::<CurrentNetwork>::new(rng).unwrap()
522    })
523}
524
525/// Samples a random genesis block, the transaction from the genesis block, and the genesis private key.
526fn sample_genesis_block_and_components_raw(
527    rng: &mut TestRng,
528) -> (Block<CurrentNetwork>, Transaction<CurrentNetwork>, PrivateKey<CurrentNetwork>) {
529    // Sample the genesis private key.
530    let private_key = sample_genesis_private_key(rng);
531    let address = Address::<CurrentNetwork>::try_from(private_key).unwrap();
532
533    // Prepare the locator.
534    let locator = ("credits.aleo", "transfer_public_to_private");
535    // Prepare the amount for each call to the function.
536    let amount = 100_000_000u64;
537    // Prepare the function inputs.
538    let inputs = [address.to_string(), format!("{amount}_u64")];
539
540    // Initialize the process.
541    let process = Process::load().unwrap();
542    // Authorize the function.
543    let authorization =
544        process.authorize::<CurrentAleo, _>(&private_key, locator.0, locator.1, inputs.iter(), rng).unwrap();
545    // Execute the function.
546    let (_, mut trace) = process.execute::<CurrentAleo, _>(authorization, rng).unwrap();
547
548    // Initialize a new block store.
549    let block_store = BlockStore::<CurrentNetwork, BlockMemory<_>>::open(StorageMode::new_test(None)).unwrap();
550
551    // Prepare the assignments.
552    trace.prepare(&Query::from(block_store)).unwrap();
553    // Compute the proof and construct the execution.
554    let execution = trace.prove_execution::<CurrentAleo, _>(locator.0, VarunaVersion::V1, rng).unwrap();
555    // Convert the execution.
556    // Note: This is a testing-only hack to adhere to Rust's dependency cycle rules.
557    let execution = Execution::from_str(&execution.to_string()).unwrap();
558
559    // Construct the transaction.
560    let transaction = Transaction::from_execution(execution, None).unwrap();
561    // Prepare the confirmed transaction.
562    let confirmed = ConfirmedTransaction::accepted_execute(0, transaction.clone(), vec![]).unwrap();
563    // Prepare the transactions.
564    let transactions = Transactions::from_iter([confirmed]);
565
566    // Construct the ratifications.
567    let ratifications = Ratifications::try_from(vec![]).unwrap();
568
569    // Prepare the block header.
570    let header = Header::genesis(&ratifications, &transactions, vec![]).unwrap();
571    // Prepare the previous block hash.
572    let previous_hash = <CurrentNetwork as Network>::BlockHash::default();
573
574    // Construct the block.
575    let block = Block::new_beacon(
576        &private_key,
577        previous_hash,
578        header,
579        ratifications,
580        None.into(),
581        vec![],
582        transactions,
583        vec![],
584        rng,
585    )
586    .unwrap();
587    assert!(block.header().is_genesis(), "Failed to initialize a genesis block");
588    // Return the block, transaction, and private key.
589    (block, transaction, private_key)
590}