Skip to content

Commit

Permalink
test: Remove mock crate
Browse files Browse the repository at this point in the history
  • Loading branch information
igamigo committed May 29, 2024
1 parent 74a5371 commit 3730e4b
Show file tree
Hide file tree
Showing 60 changed files with 924 additions and 1,464 deletions.
271 changes: 3 additions & 268 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ members = [
"bench-tx",
"miden-lib",
"miden-tx",
"mock",
"objects",
]

Expand Down
3 changes: 1 addition & 2 deletions bench-tx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ path = "src/main.rs"
[dependencies]
miden-lib = { path = "../miden-lib", version = "0.4" }
miden-objects = { path = "../objects", version = "0.4" }
miden-tx = { path = "../miden-tx", version = "0.4" }
mock = { package = "miden-mock", path = "../mock" }
miden-tx = { path = "../miden-tx", version = "0.4", features = ["testing"] }
rand = { workspace = true }
serde = { package = "serde", version = "1.0" }
serde_json = { package = "serde_json", version = "1.0", features = ["preserve_order"] }
Expand Down
9 changes: 4 additions & 5 deletions bench-tx/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use std::{
rc::Rc,
};

use miden_lib::{
notes::create_p2id_note, transaction::ToTransactionKernelInputs, utils::Serializable,
};
use miden_lib::{notes::create_p2id_note, transaction::ToTransactionKernelInputs};
use miden_objects::{
accounts::{AccountId, AuthSecretKey},
assembly::ProgramAst,
Expand All @@ -19,14 +17,15 @@ use miden_objects::{
Felt,
};
use miden_tx::{
host::BasicAuthenticator, TransactionExecutor, TransactionHost, TransactionProgress,
host::BasicAuthenticator, utils::Serializable, MockDataStore, TransactionExecutor,
TransactionHost, TransactionProgress,
};
use rand::rngs::StdRng;
use vm_processor::{ExecutionOptions, RecAdviceProvider, Word};

mod utils;
use utils::{
get_account_with_default_account_code, write_bench_results_to_json, MockDataStore,
get_account_with_default_account_code, write_bench_results_to_json,
ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN, ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN,
ACCOUNT_ID_SENDER, DEFAULT_AUTH_SCRIPT,
};
Expand Down
114 changes: 2 additions & 112 deletions bench-tx/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,9 @@ use miden_objects::{
accounts::{Account, AccountCode, AccountId, AccountStorage, SlotItem, StorageSlot},
assembly::ModuleAst,
assets::{Asset, AssetVault},
notes::{Note, NoteId},
transaction::{ChainMmr, InputNote, InputNotes, OutputNote, TransactionArgs},
BlockHeader, Felt, Word,
};
use miden_tx::{DataStore, DataStoreError, TransactionInputs, TransactionProgress};
use mock::mock::{
account::MockAccountType,
notes::AssetPreservationStatus,
transaction::{mock_inputs, mock_inputs_with_existing},
Felt, Word,
};
use miden_tx::TransactionProgress;
use serde::Serialize;
use serde_json::{from_str, to_string_pretty, Value};

Expand Down Expand Up @@ -45,109 +38,6 @@ pub const DEFAULT_ACCOUNT_CODE: &str = "
export.basic_eoa::auth_tx_rpo_falcon512
";

// MOCK DATA STORE
// ================================================================================================

#[derive(Clone)]
pub struct MockDataStore {
pub account: Account,
pub block_header: BlockHeader,
pub block_chain: ChainMmr,
pub notes: Vec<InputNote>,
pub tx_args: TransactionArgs,
}

impl MockDataStore {
pub fn new(asset_preservation: AssetPreservationStatus) -> Self {
let (tx_inputs, tx_args) =
mock_inputs(MockAccountType::StandardExisting, asset_preservation);
let (account, _, block_header, block_chain, notes) = tx_inputs.into_parts();

Self {
account,
block_header,
block_chain,
notes: notes.into_vec(),
tx_args,
}
}

pub fn with_existing(account: Option<Account>, input_notes: Option<Vec<Note>>) -> Self {
let (
account,
block_header,
block_chain,
consumed_notes,
_auxiliary_data_inputs,
created_notes,
) = mock_inputs_with_existing(
MockAccountType::StandardExisting,
AssetPreservationStatus::Preserved,
account,
input_notes,
);
let output_notes = created_notes.into_iter().filter_map(|note| match note {
OutputNote::Full(note) => Some(note),
OutputNote::Partial(_) => None,
OutputNote::Header(_) => None,
});
let mut tx_args = TransactionArgs::default();
tx_args.extend_expected_output_notes(output_notes);

Self {
account,
block_header,
block_chain,
notes: consumed_notes,
tx_args,
}
}

pub fn tx_args(&self) -> &TransactionArgs {
&self.tx_args
}
}

impl Default for MockDataStore {
fn default() -> Self {
Self::new(AssetPreservationStatus::Preserved)
}
}

impl DataStore for MockDataStore {
fn get_transaction_inputs(
&self,
account_id: AccountId,
block_num: u32,
notes: &[NoteId],
) -> Result<TransactionInputs, DataStoreError> {
assert_eq!(account_id, self.account.id());
assert_eq!(block_num, self.block_header.block_num());
assert_eq!(notes.len(), self.notes.len());

let notes = self
.notes
.iter()
.filter(|note| notes.contains(&note.id()))
.cloned()
.collect::<Vec<_>>();

Ok(TransactionInputs::new(
self.account.clone(),
None,
self.block_header,
self.block_chain.clone(),
InputNotes::new(notes).unwrap(),
)
.unwrap())
}

fn get_account_code(&self, account_id: AccountId) -> Result<ModuleAst, DataStoreError> {
assert_eq!(account_id, self.account.id());
Ok(self.account.code().module().clone())
}
}

// TRANSACTION BENCHMARK
// ================================================================================================

Expand Down
6 changes: 4 additions & 2 deletions miden-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ edition.workspace = true
[features]
concurrent = ["miden-objects/concurrent", "std"]
default = ["std"]
std = ["assembly/std", "miden-objects/std", "miden-stdlib/std", "vm-processor/std", "mock/std"]
std = ["assembly/std", "miden-objects/std", "miden-stdlib/std", "vm-processor/std"]
# the testing feature is required to enable the account creation pow patch
testing = ["miden-objects/testing"]

Expand All @@ -29,7 +29,9 @@ miden-stdlib = { workspace = true }
miden-objects = { path = "../objects", version = "0.4", default-features = false, features = [
"testing",
] }
mock = { package = "miden-mock", path = "../mock", default-features = false }
miden-tx = { path = "../miden-tx", version = "0.4", default-features = false, features = [
"testing",
] }
vm-processor = { workspace = true, features = ["internals"] }

[build-dependencies]
Expand Down
93 changes: 60 additions & 33 deletions miden-lib/src/tests/test_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,40 @@ use miden_objects::{
ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN,
ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN,
},
testing::{
prepare_word, storage_item_0, storage_item_1, storage_item_2, storage_map_2,
transaction::{mock_executed_tx, mock_inputs, notes::AssetPreservationStatus},
MockAccountType, STORAGE_LEAVES_2,
},
AccountId, AccountType, StorageSlotType,
},
crypto::{hash::rpo::RpoDigest, merkle::LeafIndex},
};
use mock::{
mock::{
account::{
storage_item_0, storage_item_1, storage_item_2, storage_map_2, MockAccountType,
STORAGE_LEAVES_2,
},
host::MockHost,
notes::AssetPreservationStatus,
transaction::{mock_executed_tx, mock_inputs},
},
prepare_transaction,
procedures::{output_notes_data_procedure, prepare_word},
run_tx, run_within_host, run_within_tx_kernel,
use miden_tx::host::testing::{
procedures::output_notes_data_procedure,
utils::{prepare_transaction, run_tx, run_within_host, run_within_tx_kernel},
MockHost,
};

use super::{
super::transaction::ToTransactionKernelInputs, ContextId, Felt, MemAdviceProvider,
ProcessState, StackInputs, Word, ONE, ZERO,
};
use crate::transaction::memory::{ACCT_CODE_ROOT_PTR, ACCT_NEW_CODE_ROOT_PTR};
use crate::transaction::{
memory::{ACCT_CODE_ROOT_PTR, ACCT_NEW_CODE_ROOT_PTR},
TransactionKernel,
};

// ACCOUNT CODE TESTS
// ================================================================================================

#[test]
pub fn test_set_code_is_not_immediate() {
let (tx_inputs, tx_args) =
mock_inputs(MockAccountType::StandardExisting, AssetPreservationStatus::Preserved);
let (tx_inputs, tx_args) = mock_inputs(
MockAccountType::StandardExisting,
AssetPreservationStatus::Preserved,
&TransactionKernel::assembler(),
);

let code = "
use.miden::kernels::tx::prologue
Expand Down Expand Up @@ -67,7 +69,8 @@ pub fn test_set_code_is_not_immediate() {

#[test]
pub fn test_set_code_succeeds() {
let executed_transaction = mock_executed_tx(AssetPreservationStatus::Preserved);
let executed_transaction =
mock_executed_tx(AssetPreservationStatus::Preserved, &TransactionKernel::assembler());

let output_notes_data_procedure =
output_notes_data_procedure(executed_transaction.output_notes());
Expand Down Expand Up @@ -244,8 +247,11 @@ fn test_is_faucet_procedure() {
#[test]
fn test_get_item() {
for storage_item in [storage_item_0(), storage_item_1()] {
let (tx_inputs, tx_args) =
mock_inputs(MockAccountType::StandardExisting, AssetPreservationStatus::Preserved);
let (tx_inputs, tx_args) = mock_inputs(
MockAccountType::StandardExisting,
AssetPreservationStatus::Preserved,
&TransactionKernel::assembler(),
);

let code = format!(
"
Expand Down Expand Up @@ -278,8 +284,11 @@ fn test_get_item() {

#[test]
fn test_set_item() {
let (tx_inputs, tx_args) =
mock_inputs(MockAccountType::StandardExisting, AssetPreservationStatus::Preserved);
let (tx_inputs, tx_args) = mock_inputs(
MockAccountType::StandardExisting,
AssetPreservationStatus::Preserved,
&TransactionKernel::assembler(),
);

// copy the initial account slots (SMT)
let mut account_smt = tx_inputs.account().storage().slots().clone();
Expand Down Expand Up @@ -333,8 +342,11 @@ fn test_set_item() {
#[test]
fn test_get_storage_data_type() {
for storage_item in [storage_item_0(), storage_item_1(), storage_item_2()] {
let (tx_inputs, tx_args) =
mock_inputs(MockAccountType::StandardExisting, AssetPreservationStatus::Preserved);
let (tx_inputs, tx_args) = mock_inputs(
MockAccountType::StandardExisting,
AssetPreservationStatus::Preserved,
&TransactionKernel::assembler(),
);

let code = format!(
"
Expand Down Expand Up @@ -379,8 +391,11 @@ fn test_get_storage_data_type() {

#[test]
fn test_get_map_item() {
let (tx_inputs, tx_args) =
mock_inputs(MockAccountType::StandardExisting, AssetPreservationStatus::Preserved);
let (tx_inputs, tx_args) = mock_inputs(
MockAccountType::StandardExisting,
AssetPreservationStatus::Preserved,
&TransactionKernel::assembler(),
);

let storage_item = storage_item_2();
for (key, value) in STORAGE_LEAVES_2 {
Expand Down Expand Up @@ -427,8 +442,11 @@ fn test_set_map_item() {
[Felt::new(9_u64), Felt::new(10_u64), Felt::new(11_u64), Felt::new(12_u64)],
);

let (tx_inputs, tx_args) =
mock_inputs(MockAccountType::StandardExisting, AssetPreservationStatus::Preserved);
let (tx_inputs, tx_args) = mock_inputs(
MockAccountType::StandardExisting,
AssetPreservationStatus::Preserved,
&TransactionKernel::assembler(),
);

let storage_item = storage_item_2();

Expand Down Expand Up @@ -482,8 +500,11 @@ fn test_set_map_item() {

#[test]
fn test_get_vault_commitment() {
let (tx_inputs, tx_args) =
mock_inputs(MockAccountType::StandardExisting, AssetPreservationStatus::Preserved);
let (tx_inputs, tx_args) = mock_inputs(
MockAccountType::StandardExisting,
AssetPreservationStatus::Preserved,
&TransactionKernel::assembler(),
);

let account = tx_inputs.account();
let code = format!(
Expand Down Expand Up @@ -513,8 +534,11 @@ fn test_get_vault_commitment() {

#[test]
fn test_authenticate_procedure() {
let (tx_inputs, _tx_args) =
mock_inputs(MockAccountType::StandardExisting, AssetPreservationStatus::Preserved);
let (tx_inputs, _tx_args) = mock_inputs(
MockAccountType::StandardExisting,
AssetPreservationStatus::Preserved,
&TransactionKernel::assembler(),
);
let account = tx_inputs.account();

let proc0_index = LeafIndex::new(0).unwrap();
Expand All @@ -527,8 +551,11 @@ fn test_authenticate_procedure() {
];

for (root, valid) in test_cases.into_iter() {
let (tx_inputs, tx_args) =
mock_inputs(MockAccountType::StandardExisting, AssetPreservationStatus::Preserved);
let (tx_inputs, tx_args) = mock_inputs(
MockAccountType::StandardExisting,
AssetPreservationStatus::Preserved,
&TransactionKernel::assembler(),
);

let code = format!(
"\
Expand Down
Loading

0 comments on commit 3730e4b

Please sign in to comment.