Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Remove basic wallets from genesis #541

Open
wants to merge 4 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 18 additions & 96 deletions bin/miden-cli/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use miden_client::{
sqlite_store::{config::SqliteStoreConfig, SqliteStore},
NoteFilter,
},
testing::ACCOUNT_ID_OFF_CHAIN_SENDER,
Client, Felt,
};
use rand::Rng;
Expand Down Expand Up @@ -149,19 +150,14 @@ fn test_mint_with_untracked_account() {
// IMPORT TESTS
// ================================================================================================

// Accounts 0 and 1 should be basic wallets and account2 should be a fungible faucet
const GENESIS_ACCOUNTS_FILENAMES: [&str; 3] = ["account0.mac", "account1.mac", "account2.mac"];
// Only one faucet is being created on the genesis block
const GENESIS_ACCOUNTS_FILENAMES: [&str; 1] = ["account0.mac"];

// This tests that it's possible to import the genesis accounts and interact with them. To do so it:
//
// 1. Creates a new client
// 2. Imports all 3 genesis accounts
// 3. Runs a mint tx, syncs and consumes the created note with none of the regular accounts
// 4. Runs a P2ID tx from the account that just received the asset to the remaining basic account
// 5. Syncs and consumes the P2ID note with the other account
//
// Since it uses the genesis accounts generated by the node, this test should be kept updated
// against possible changes in the node that would affect the resulting account IDs.
// 2. Imports the genesis account
// 3. Runs a mint tx and syncs until the transaction and note are committed
tomyrd marked this conversation as resolved.
Show resolved Hide resolved
#[test]
#[ignore = "import genesis test gets ignored by default so integration tests can be ran with dockerized and remote nodes where we might not have the genesis data"]
fn test_import_genesis_accounts_can_be_used_for_transactions() {
Expand Down Expand Up @@ -199,83 +195,41 @@ fn test_import_genesis_accounts_can_be_used_for_transactions() {

sync_cli(&temp_dir);

let (first_basic_account_id, second_basic_account_id, fungible_faucet_account_id) = {
let fungible_faucet_account_id = {
let client = create_test_client_with_store_path(&store_path);
let accounts = client.get_account_headers().unwrap();

let account_ids = accounts.iter().map(|(acc, _seed)| acc.id()).collect::<Vec<_>>();
let regular_accounts = account_ids.iter().filter(|id| !id.is_faucet()).collect::<Vec<_>>();
let faucet_accounts = account_ids.iter().filter(|id| id.is_faucet()).collect::<Vec<_>>();

assert_eq!(regular_accounts.len(), 2);
assert_eq!(faucet_accounts.len(), 1);

(
regular_accounts[0].to_hex(),
regular_accounts[1].to_hex(),
faucet_accounts[0].to_hex(),
)
faucet_accounts[0].to_hex()
};

// Ensure they've been importing by showing them
// TODO: Once show is fixed for faucet account do the full iteration without skipping the
// faucet
tomyrd marked this conversation as resolved.
Show resolved Hide resolved
for account_id in [&first_basic_account_id, &second_basic_account_id] {
let args = vec!["account", "--show", account_id];
let mut show_cmd = Command::cargo_bin("miden").unwrap();
show_cmd.args(&args);
show_cmd.current_dir(&temp_dir).assert().success();
}

// Let's try and mint
mint_cli(&temp_dir, &first_basic_account_id[..8], &fungible_faucet_account_id);

// Wait until the note is committed on the node
sync_until_no_notes(&store_path, &temp_dir, NoteFilter::Expected);

// Consume the note
let note_to_consume_id = {
let client = create_test_client_with_store_path(&store_path);
let notes = client.get_input_notes(NoteFilter::Committed).unwrap();
let args = vec!["account", "--show", &fungible_faucet_account_id];
let mut show_cmd = Command::cargo_bin("miden").unwrap();
show_cmd.args(&args);
show_cmd.current_dir(&temp_dir).assert().success();

notes.first().unwrap().id().to_hex()
};

consume_note_cli(&temp_dir, &first_basic_account_id, &[&note_to_consume_id]);

// Wait until the note is consumed on the node
sync_until_no_notes(&store_path, &temp_dir, NoteFilter::Processing);
// Create wallet account
let mut create_wallet_cmd = Command::cargo_bin("miden").unwrap();
create_wallet_cmd.args(["new-wallet", "-s", "private"]);
create_wallet_cmd.current_dir(&temp_dir).assert().success();

// Send assets to second account
send_cli(
// Let's try and mint
mint_cli(
&temp_dir,
&first_basic_account_id,
&second_basic_account_id,
&AccountId::try_from(ACCOUNT_ID_OFF_CHAIN_SENDER).unwrap().to_hex(),
&fungible_faucet_account_id,
);

// Using the full note id should find it.
show_note_cli(&temp_dir, &note_to_consume_id, false);
// Querying a non existant note id should fail.
show_note_cli(&temp_dir, "0x1234567890", true);
// Querying a note id hex that matches many should fail.
show_note_cli(&temp_dir, "0x", true);

// Wait until the note is committed on the node
sync_until_no_notes(&store_path, &temp_dir, NoteFilter::Expected);

// Consume note for second account
let note_to_consume_id = {
let client = create_test_client_with_store_path(&store_path);
let notes = client.get_input_notes(NoteFilter::Committed).unwrap();

notes.first().unwrap().id().to_hex()
};

consume_note_cli(&temp_dir, &second_basic_account_id, &[&note_to_consume_id]);

// Wait until the note is consumed on the node
sync_until_no_notes(&store_path, &temp_dir, NoteFilter::Processing);
}
tomyrd marked this conversation as resolved.
Show resolved Hide resolved

// This tests that it's possible to export and import notes into other CLIs. To do so it:
Expand Down Expand Up @@ -504,19 +458,6 @@ fn sync_cli(cli_path: &Path) {
}
}

/// Shows note details using the cli and checks that the command runs
/// successfully given account using the CLI given by `cli_path`.
fn show_note_cli(cli_path: &Path, note_id: &str, should_fail: bool) {
let mut show_note_cmd = Command::cargo_bin("miden").unwrap();
show_note_cmd.args(["notes", "--show", note_id]);

if should_fail {
show_note_cmd.current_dir(cli_path).assert().failure();
} else {
show_note_cmd.current_dir(cli_path).assert().success();
}
}

/// Mints 100 units of the corresponding faucet using the cli and checks that the command runs
/// successfully given account using the CLI given by `cli_path`.
fn mint_cli(cli_path: &Path, target_account_id: &str, faucet_id: &str) {
Expand All @@ -534,25 +475,6 @@ fn mint_cli(cli_path: &Path, target_account_id: &str, faucet_id: &str) {
mint_cmd.current_dir(cli_path).assert().success();
}

/// Sends 25 units of the corresponding faucet and checks that the command runs successfully given
/// account using the CLI given by `cli_path`.
fn send_cli(cli_path: &Path, from_account_id: &str, to_account_id: &str, faucet_id: &str) {
let mut send_cmd = Command::cargo_bin("miden").unwrap();
send_cmd.args([
"send",
"--sender",
&from_account_id[0..8],
"--target",
&to_account_id[0..8],
"--asset",
&format!("25::{faucet_id}"),
"-n",
"private",
"--force",
]);
send_cmd.current_dir(cli_path).assert().success();
}

/// Syncs until there are no input notes satisfying the provided filter
fn sync_until_no_notes(store_path: &Path, cli_path: &Path, filter: NoteFilter) {
let client = create_test_client_with_store_path(store_path);
Expand Down
14 changes: 0 additions & 14 deletions tests/config/genesis.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
version = 1
timestamp = 1672531200

[[accounts]]
type = "BasicWallet"
init_seed = "0xa123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
auth_scheme = "RpoFalcon512"
auth_seed = "0xb123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
storage_mode = "private"

[[accounts]]
type = "BasicWallet"
init_seed = "0xa123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdea"
auth_scheme = "RpoFalcon512"
auth_seed = "0xb123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdea"
storage_mode = "private"

[[accounts]]
type = "BasicFungibleFaucet"
init_seed = "0xc123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
Expand Down
3 changes: 3 additions & 0 deletions tests/config/miden-node.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Configuration settings for running integration tests.
# Adjust these values to modify how the tests are executed, such as using a remote RPC endpoint instead of a local one.

[block_producer]
# port defined as: sum(ord(c)**p for (p, c) in enumerate('miden-block-producer', 1)) % 2**16
endpoint = { host = "localhost", port = 48046 }
Expand Down
Loading