Skip to content

Commit

Permalink
test: reuse common tests utils in cli tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasArrachea committed Jan 9, 2025
1 parent 39d6a75 commit 71cf4ce
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 51 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bin/miden-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ required-features = ["testing", "concurrent"]
assert_cmd = { version = "2.0" }
predicates = { version = "3.0" }
uuid = { version = "1.10", features = ["serde", "v4"] }
miden-client-tests = { path = "../../tests", version = "0.6.0"}

[dependencies]
clap = { version = "4.5", features = ["derive"] }
Expand Down
50 changes: 4 additions & 46 deletions bin/miden-cli/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ use miden_client::{
NoteRecipient, NoteTag, NoteType,
},
rpc::TonicRpcClient,
store::{sqlite_store::SqliteStore, NoteFilter, StoreAuthenticator, TransactionFilter},
store::{sqlite_store::SqliteStore, NoteFilter, StoreAuthenticator},
testing::account_id::ACCOUNT_ID_OFF_CHAIN_SENDER,
transactions::{OutputNote, TransactionRequestBuilder},
utils::Serializable,
Client, Felt,
};
use miden_client_tests::common::{execute_tx_and_sync, insert_new_wallet};
use predicates::str::contains;
use rand::Rng;
use uuid::Uuid;
Expand Down Expand Up @@ -664,29 +665,7 @@ async fn debug_mode_outputs_logs() {
// Create a Client and a custom note
let store_path = create_test_store_path();
let mut client = create_test_client_with_store_path(&store_path).await;

// Create the account
let key_pair = SecretKey::with_rng(client.rng());

let mut init_seed = [0u8; 32];
client.rng().fill_bytes(&mut init_seed);

let anchor_block = client.get_latest_epoch_block().await.unwrap();

let (account, seed) = AccountBuilder::new()
.init_seed(init_seed)
.anchor((&anchor_block).try_into().unwrap())
.account_type(AccountType::RegularAccountImmutableCode)
.storage_mode(AccountStorageMode::Private)
.with_component(RpoFalcon512Component::new(key_pair.public_key()))
.with_component(BasicWalletComponent)
.build()
.unwrap();

client
.add_account(&account, Some(seed), &AuthSecretKey::RpoFalcon512(key_pair), false)
.await
.unwrap();
let (account, _) = insert_new_wallet(&mut client, AccountStorageMode::Private).await.unwrap();

// Create the custom note
let note_script = "
Expand Down Expand Up @@ -715,28 +694,7 @@ async fn debug_mode_outputs_logs() {
.with_own_output_notes(vec![OutputNote::Full(note.clone())])
.unwrap()
.build();
let transaction_execution_result =
client.new_transaction(account.id(), transaction_request).await.unwrap();
let transaction_id = transaction_execution_result.executed_transaction().id();
client.submit_transaction(transaction_execution_result).await.unwrap();
loop {
println!("Syncing State...");
client.sync_state().await.unwrap();

// Check if executed transaction got committed by the node
let uncommited_transactions =
client.get_transactions(TransactionFilter::Uncomitted).await.unwrap();
let is_tx_committed = uncommited_transactions
.iter()
.all(|uncommited_tx| uncommited_tx.id != transaction_id);

if is_tx_committed {
break;
}

// 500_000_000 ns = 0.5s
std::thread::sleep(std::time::Duration::new(0, 500_000_000));
}
execute_tx_and_sync(&mut client, account.id(), transaction_request).await;

// Export the note
let note_file: NoteFile = NoteFile::NoteDetails {
Expand Down
15 changes: 10 additions & 5 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,28 @@ repository.workspace = true
rust-version.workspace = true
edition.workspace = true

[dev-dependencies]
async-trait = { version = "0.1" }
[dependencies]
miden-client = { path = "../crates/rust-client", features = [
"concurrent",
"testing",
"std",
"sqlite",
"tonic",
] }
rand = { workspace = true }
uuid = { version = "1.10", features = ["serde", "v4"] }
toml = { version = "0.8" }
miden-objects = { workspace = true, default-features = false, features = ["testing"] }

[dev-dependencies]
async-trait = { version = "0.1" }
miden-lib = { workspace = true, default-features = false, features = ["testing"] }
rand = { workspace = true }
tokio = { workspace = true }
toml = { version = "0.8" }
uuid = { version = "1.10", features = ["serde", "v4"] }
winter-maybe-async = { version = "0.10" }

[[test]]
name = "integration"
path = "integration/main.rs"

[lib]
path = "integration/lib.rs"
1 change: 1 addition & 0 deletions tests/integration/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod common;

0 comments on commit 71cf4ce

Please sign in to comment.