Skip to content

Commit

Permalink
refactor: tests cleanup (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
hackaugusto authored and bobbinth committed Jul 4, 2024
1 parent ee5e938 commit bf38e8a
Show file tree
Hide file tree
Showing 29 changed files with 1,413 additions and 1,485 deletions.
37 changes: 22 additions & 15 deletions bench-tx/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ use miden_objects::{
assets::{Asset, FungibleAsset},
crypto::{dsa::rpo_falcon512::SecretKey, rand::RpoRandomCoin},
notes::NoteType,
testing::notes::AssetPreservationStatus,
transaction::TransactionArgs,
Felt,
};
use miden_tx::{
auth::BasicAuthenticator, testing::data_store::MockDataStore, utils::Serializable,
auth::BasicAuthenticator, testing::TransactionContextBuilder, utils::Serializable,
TransactionExecutor, TransactionHost, TransactionProgress,
};
use rand::rngs::StdRng;
use vm_processor::{ExecutionOptions, RecAdviceProvider, Word};
use vm_processor::{ExecutionOptions, RecAdviceProvider, Word, ONE};

mod utils;
use utils::{
Expand Down Expand Up @@ -66,23 +67,28 @@ fn main() -> Result<(), String> {

/// Runs the default transaction with empty transaction script and two default notes.
pub fn benchmark_default_tx() -> Result<TransactionProgress, String> {
let data_store = MockDataStore::default();
let tx_context = TransactionContextBuilder::with_standard_account(
ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN,
ONE,
)
.with_mock_notes(AssetPreservationStatus::Preserved)
.build();
let mut executor: TransactionExecutor<_, ()> =
TransactionExecutor::new(data_store.clone(), None).with_tracing();
TransactionExecutor::new(tx_context.clone(), None).with_tracing();

let account_id = data_store.account().id();
let account_id = tx_context.account().id();
executor.load_account(account_id).map_err(|e| e.to_string())?;

let block_ref = data_store.block_header().block_num();
let note_ids = data_store
.tx_inputs
let block_ref = tx_context.tx_inputs().block_header().block_num();
let note_ids = tx_context
.tx_inputs()
.input_notes()
.iter()
.map(|note| note.id())
.collect::<Vec<_>>();

let transaction = executor
.prepare_transaction(account_id, block_ref, &note_ids, data_store.tx_args.clone())
.prepare_transaction(account_id, block_ref, &note_ids, tx_context.tx_args().clone())
.map_err(|e| e.to_string())?;

let (stack_inputs, advice_inputs) = transaction.get_kernel_inputs();
Expand Down Expand Up @@ -132,16 +138,17 @@ pub fn benchmark_p2id() -> Result<TransactionProgress, String> {
)
.unwrap();

let data_store =
MockDataStore::with_existing(Some(target_account.clone()), Some(vec![note.clone()]));
let tx_context = TransactionContextBuilder::new(target_account.clone())
.input_notes(vec![note.clone()])
.build();

let mut executor: TransactionExecutor<_, ()> =
TransactionExecutor::new(data_store.clone(), None).with_tracing();
TransactionExecutor::new(tx_context.clone(), None).with_tracing();
executor.load_account(target_account_id).unwrap();

let block_ref = data_store.block_header().block_num();
let note_ids = data_store
.tx_inputs
let block_ref = tx_context.tx_inputs().block_header().block_num();
let note_ids = tx_context
.tx_inputs()
.input_notes()
.iter()
.map(|note| note.id())
Expand Down
7 changes: 3 additions & 4 deletions miden-tx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ async = ["winter-maybe-async/async"]
concurrent = ["miden-lib/concurrent", "miden-objects/concurrent", "miden-prover/concurrent", "std"]
default = ["std"]
std = ["miden-lib/std", "miden-objects/std", "miden-prover/std", "miden-verifier/std", "vm-processor/std"]
testing = ["miden-objects/testing", "miden-lib/testing", "vm-processor/internals"]
async = ["winter-maybe-async/async"]
testing = ["miden-objects/testing", "miden-lib/testing", "vm-processor/internals", "dep:rand_chacha"]

[dependencies]
miden-lib = { path = "../miden-lib", version = "0.4", default-features = false }
miden-objects = { path = "../objects", version = "0.4", default-features = false }
miden-prover = { workspace = true }
miden-verifier = { workspace = true }
rand = { workspace = true }
winter-maybe-async = "0.10.0"
rand_chacha = { version = "0.3", default-features = false, optional = true }
vm-processor = { workspace = true }
winter-maybe-async = { version = "0.10.0" }
winter-maybe-async = { version = "0.10" }

[dev-dependencies]
rand_chacha = { version = "0.3", default-features = false }
Expand Down
79 changes: 0 additions & 79 deletions miden-tx/src/testing/chain_data.rs

This file was deleted.

91 changes: 0 additions & 91 deletions miden-tx/src/testing/data_store.rs

This file was deleted.

8 changes: 3 additions & 5 deletions miden-tx/src/testing/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
use miden_lib::transaction::TransactionKernel;
#[cfg(feature = "std")]
use vm_processor::{
AdviceInputs, AdviceProvider, DefaultHost, ExecutionError, ExecutionOptions, Host, Process,
Program, StackInputs,
AdviceInputs, AdviceProvider, DefaultHost, ExecutionError, Host, Process, Program, StackInputs,
};

// MOCK CODE EXECUTOR
Expand Down Expand Up @@ -43,18 +42,17 @@ impl<H: Host> CodeExecutor<H> {
/// `code` before execution.
/// Otherwise, `self.imports` and `code` will be concatenated and the result will be executed.
pub fn run(self, code: &str) -> Result<Process<H>, ExecutionError> {
let assembler = TransactionKernel::assembler();
let assembler = TransactionKernel::assembler().with_debug_mode(true);

let program = assembler.compile(code).unwrap();
self.execute_program(program)
}

pub fn execute_program(self, program: Program) -> Result<Process<H>, ExecutionError> {
let mut process = Process::new(
let mut process = Process::new_debug(
program.kernel().clone(),
self.stack_inputs.unwrap_or_default(),
self.host,
ExecutionOptions::default(),
);
process.execute(&program)?;

Expand Down
1 change: 0 additions & 1 deletion miden-tx/src/testing/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod account_procs;
pub mod data_store;
pub mod executor;

pub use mock_host::MockHost;
Expand Down
Loading

0 comments on commit bf38e8a

Please sign in to comment.