Skip to content

Commit

Permalink
fix: clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbinth committed Dec 25, 2023
1 parent 7f15edd commit 84811c7
Show file tree
Hide file tree
Showing 23 changed files with 98 additions and 134 deletions.
14 changes: 7 additions & 7 deletions miden-lib/src/tests/test_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub fn test_account_type() {
("is_immutable_account", AccountType::RegularAccountImmutableCode),
];

let test_cases = vec![
let test_cases = [
ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN,
ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN,
ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN,
Expand Down Expand Up @@ -233,7 +233,7 @@ fn test_get_item() {

let _process = run_tx(
transaction.tx_program().clone(),
StackInputs::from(transaction.stack_inputs()),
transaction.stack_inputs(),
MemAdviceProvider::from(transaction.advice_provider_inputs()),
)
.unwrap();
Expand Down Expand Up @@ -288,7 +288,7 @@ fn test_get_child_tree_item() {

let _process = run_tx(
transaction.tx_program().clone(),
StackInputs::from(transaction.stack_inputs()),
transaction.stack_inputs(),
MemAdviceProvider::from(transaction.advice_provider_inputs()),
)
.unwrap();
Expand Down Expand Up @@ -357,15 +357,15 @@ fn test_set_item() {

let _process = run_tx(
transaction.tx_program().clone(),
StackInputs::from(transaction.stack_inputs()),
transaction.stack_inputs(),
MemAdviceProvider::from(transaction.advice_provider_inputs()),
)
.unwrap();
}

#[test]
fn test_is_faucet_procedure() {
let test_cases = vec![
let test_cases = [
ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN,
ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN,
ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN,
Expand Down Expand Up @@ -455,7 +455,7 @@ fn test_authenticate_procedure() {

let process = run_tx(
transaction.tx_program().clone(),
StackInputs::from(transaction.stack_inputs()),
transaction.stack_inputs(),
MemAdviceProvider::from(transaction.advice_provider_inputs()),
);

Expand Down Expand Up @@ -504,7 +504,7 @@ fn test_get_vault_commitment() {

let _process = run_tx(
transaction.tx_program().clone(),
StackInputs::from(transaction.stack_inputs()),
transaction.stack_inputs(),
MemAdviceProvider::from(transaction.advice_provider_inputs()),
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion miden-lib/src/tests/test_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn test_create_non_fungible_asset_succeeds() {
assert_eqw
end
",
non_fungible_asset_data_hash = prepare_word(&*Hasher::hash(&NON_FUNGIBLE_ASSET_DATA)),
non_fungible_asset_data_hash = prepare_word(&Hasher::hash(&NON_FUNGIBLE_ASSET_DATA)),
expected_non_fungible_asset = prepare_word(&Word::from(non_fungible_asset))
);

Expand Down
2 changes: 1 addition & 1 deletion miden-lib/src/tests/test_epilogue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn test_epilogue() {
executed_transaction
.tx_script()
.as_ref()
.map_or_else(|| Word::default(), |s| **s.hash())
.map_or_else(Word::default, |s| **s.hash())
);

// assert created notes commitment is correct
Expand Down
14 changes: 7 additions & 7 deletions miden-lib/src/tests/test_note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn test_get_sender_no_sender() {
notes,
None,
auxiliary_data,
&code,
code,
"",
None,
);
Expand Down Expand Up @@ -83,7 +83,7 @@ fn test_get_sender() {
notes,
None,
auxiliary_data,
&code,
code,
"",
None,
);
Expand Down Expand Up @@ -262,8 +262,8 @@ fn test_get_assets() {
",
note_0_num_assets = notes[0].note().vault().num_assets(),
note_1_num_assets = notes[1].note().vault().num_assets(),
NOTE_0_ASSET_ASSERTIONS = construct_asset_assertions(&notes[0].note()),
NOTE_1_ASSET_ASSERTIONS = construct_asset_assertions(&notes[1].note()),
NOTE_0_ASSET_ASSERTIONS = construct_asset_assertions(notes[0].note()),
NOTE_1_ASSET_ASSERTIONS = construct_asset_assertions(notes[1].note()),
);

let inputs = prepare_transaction(
Expand Down Expand Up @@ -346,7 +346,7 @@ fn test_get_inputs() {
call.process_note_0
end
",
NOTE_1_INPUT_ASSERTIONS = construct_input_assertions(&notes[0].note()),
NOTE_1_INPUT_ASSERTIONS = construct_input_assertions(notes[0].note()),
);

let inputs = prepare_transaction(
Expand Down Expand Up @@ -393,7 +393,7 @@ fn test_note_setup() {
notes,
None,
auxiliary_data,
&code,
code,
"",
None,
);
Expand Down Expand Up @@ -427,6 +427,6 @@ fn note_setup_memory_assertions<A: AdviceProvider>(process: &Process<DefaultHost
// assert that the correct pointer is stored in bookkeeping memory
assert_eq!(
process.get_mem_value(ContextId::root(), CURRENT_CONSUMED_NOTE_PTR).unwrap()[0],
Felt::try_from(consumed_note_data_ptr(0)).unwrap()
Felt::from(consumed_note_data_ptr(0))
);
}
4 changes: 2 additions & 2 deletions miden-lib/src/tests/test_prologue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn test_transaction_prologue() {
notes,
Some(tx_script),
auxiliary_data,
&code,
code,
"",
Some(assembly_file),
);
Expand Down Expand Up @@ -248,7 +248,7 @@ fn account_data_memory_assertions<A: AdviceProvider>(
{
assert_eq!(
process.get_mem_value(ContextId::root(), types_ptr).unwrap(),
Word::try_from(types.into_iter().map(Felt::from).collect::<Vec<_>>()).unwrap()
Word::try_from(types.iter().map(Felt::from).collect::<Vec<_>>()).unwrap()
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions miden-lib/src/tests/test_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ fn test_get_output_notes_hash() {
push.{expected} assert_eqw
end
",
recipient_1 = prepare_word(&*output_note_1.recipient()),
recipient_1 = prepare_word(&output_note_1.recipient()),
tag_1 = output_note_1.metadata().tag(),
asset_1 = prepare_word(&Word::from(
**output_note_1.vault().iter().take(1).collect::<Vec<_>>().first().unwrap()
)),
recipient_2 = prepare_word(&*output_note_2.recipient()),
recipient_2 = prepare_word(&output_note_2.recipient()),
tag_2 = output_note_2.metadata().tag(),
asset_2 = prepare_word(&Word::from(
**output_note_2.vault().iter().take(1).collect::<Vec<_>>().first().unwrap()
Expand Down
16 changes: 6 additions & 10 deletions miden-tx/src/compiler/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ use super::{AccountId, ModuleAst, ProgramAst, ScriptTarget, TransactionCompiler}
// ================================================================================================

// Mast roots of account procedures:
const ACCT_PROC_1: &'static str =
"0x8ef0092134469a1330e3c468f57c7f085ce611645d09cc7516c786fefc71d794";
const ACCT_PROC_2: &'static str =
"0xff06b90f849c4b262cbfbea67042c4ea017ea0e9c558848a951d44b23370bec5";
const ACCOUNT_CODE_MASM: &'static str = "\
const ACCT_PROC_1: &str = "0x8ef0092134469a1330e3c468f57c7f085ce611645d09cc7516c786fefc71d794";
const ACCT_PROC_2: &str = "0xff06b90f849c4b262cbfbea67042c4ea017ea0e9c558848a951d44b23370bec5";
const ACCOUNT_CODE_MASM: &str = "\
export.account_procedure_1
push.1.2
add
Expand All @@ -28,11 +26,9 @@ end
";

// Mast roots of additional procedures:
const ADD_PROC_1: &'static str =
"0x5b6f7afcde4aaf538519c3bf5bb9321fac83cd769a3100c0b1225c9a6d75c9a1";
const ADD_PROC_2: &'static str =
"0xd4b1f9fbad5d0e6d2386509eab6a865298db20095d7315226dfa513ce017c990";
const ADDITIONAL_PROCEDURES: &'static str = "\
const ADD_PROC_1: &str = "0x5b6f7afcde4aaf538519c3bf5bb9321fac83cd769a3100c0b1225c9a6d75c9a1";
const ADD_PROC_2: &str = "0xd4b1f9fbad5d0e6d2386509eab6a865298db20095d7315226dfa513ce017c990";
const ADDITIONAL_PROCEDURES: &str = "\
export.additional_procedure_1
push.3.4
add
Expand Down
9 changes: 4 additions & 5 deletions miden-tx/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ fn test_transaction_result_account_delta() {
end
";
let new_acct_code_ast = ModuleAst::parse(new_acct_code_src).unwrap();
let new_acct_code =
AccountCode::new(new_acct_code_ast.clone(), &mut Assembler::default()).unwrap();
let new_acct_code = AccountCode::new(new_acct_code_ast.clone(), &Assembler::default()).unwrap();

// removed assets
let removed_asset_1 = Asset::Fungible(
Expand All @@ -102,7 +101,7 @@ fn test_transaction_result_account_delta() {
.expect("asset is valid"),
);
let removed_asset_3 = non_fungible_asset(ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN);
let removed_assets = vec![removed_asset_1, removed_asset_2, removed_asset_3];
let removed_assets = [removed_asset_1, removed_asset_2, removed_asset_3];

let account_procedure_incr_nonce_mast_root = to_hex(
&data_store.account.code().procedures()[ACCOUNT_PROCEDURE_INCR_NONCE_PROC_IDX].as_bytes(),
Expand Down Expand Up @@ -212,7 +211,7 @@ fn test_transaction_result_account_delta() {
push.1 exec.incr_nonce
end
",
NEW_ACCOUNT_ROOT = prepare_word(&*new_acct_code.root()),
NEW_ACCOUNT_ROOT = prepare_word(&new_acct_code.root()),
REMOVED_ASSET_1 = prepare_word(&Word::from(removed_asset_1)),
REMOVED_ASSET_2 = prepare_word(&Word::from(removed_asset_2)),
REMOVED_ASSET_3 = prepare_word(&Word::from(removed_asset_3)),
Expand Down Expand Up @@ -240,7 +239,7 @@ fn test_transaction_result_account_delta() {
assert_eq!(transaction_result.account_delta().storage().updated_items.len(), 1);
assert_eq!(
transaction_result.account_delta().storage().updated_items[0].0,
CHILD_ROOT_PARENT_LEAF_INDEX as u8
CHILD_ROOT_PARENT_LEAF_INDEX
);

// vault delta
Expand Down
15 changes: 7 additions & 8 deletions miden-tx/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ pub fn get_account_with_default_account_code(
) -> Account {
let account_code_src = DEFAULT_ACCOUNT_CODE;
let account_code_ast = ModuleAst::parse(account_code_src).unwrap();
let mut account_assembler = assembler();
let account_assembler = assembler();

let account_code = AccountCode::new(account_code_ast.clone(), &mut account_assembler).unwrap();
let account_code = AccountCode::new(account_code_ast.clone(), &account_assembler).unwrap();
let account_storage =
AccountStorage::new(vec![(0, (StorageSlotType::Value { value_arity: 0 }, public_key))])
.unwrap();

let account_vault = match assets {
Some(asset) => AccountVault::new(&vec![asset.into()]).unwrap(),
None => AccountVault::new(&vec![]).unwrap(),
Some(asset) => AccountVault::new(&[asset]).unwrap(),
None => AccountVault::new(&[]).unwrap(),
};

Account::new(account_id, account_vault, account_storage, account_code, Felt::new(1))
Expand All @@ -144,16 +144,15 @@ pub fn get_note_with_fungible_asset_and_script(
fungible_asset: FungibleAsset,
note_script: ProgramAst,
) -> Note {
let mut note_assembler = assembler();

let (note_script, _) = NoteScript::new(note_script, &mut note_assembler).unwrap();
let note_assembler = assembler();
let (note_script, _) = NoteScript::new(note_script, &note_assembler).unwrap();
const SERIAL_NUM: Word = [Felt::new(1), Felt::new(2), Felt::new(3), Felt::new(4)];
let sender_id = AccountId::try_from(ACCOUNT_ID_SENDER).unwrap();

Note::new(
note_script.clone(),
&[],
&vec![fungible_asset.into()],
&[fungible_asset.into()],
SERIAL_NUM,
sender_id,
Felt::new(1),
Expand Down
45 changes: 17 additions & 28 deletions miden-tx/tests/faucet_contract_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn test_faucet_contract_mint_fungible_asset_succeeds() {
fn test_faucet_contract_mint_fungible_asset_fails_exceeds_max_supply() {
let (faucet_pub_key, faucet_keypair_felts) = get_new_key_pair_with_advice_map();
let faucet_account =
get_faucet_account_with_max_supply_and_total_issuance(faucet_pub_key.clone(), 200, None);
get_faucet_account_with_max_supply_and_total_issuance(faucet_pub_key, 200, None);

// CONSTRUCT AND EXECUTE TX (Failure)
// --------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -153,11 +153,8 @@ fn test_faucet_contract_mint_fungible_asset_fails_exceeds_max_supply() {
#[test]
fn test_faucet_contract_burn_fungible_asset_succeeds() {
let (faucet_pub_key, _faucet_keypair_felts) = get_new_key_pair_with_advice_map();
let faucet_account = get_faucet_account_with_max_supply_and_total_issuance(
faucet_pub_key.clone(),
200,
Some(100),
);
let faucet_account =
get_faucet_account_with_max_supply_and_total_issuance(faucet_pub_key, 200, Some(100));

let fungible_asset = FungibleAsset::new(faucet_account.id(), 100).unwrap();

Expand All @@ -173,8 +170,7 @@ fn test_faucet_contract_burn_fungible_asset_succeeds() {

// need to create a note with the fungible asset to be burned
let note_script = ProgramAst::parse(
format!(
"
"
use.miden::faucets::basic_fungible->faucet_contract
use.miden::sat::note
Expand All @@ -185,13 +181,11 @@ fn test_faucet_contract_burn_fungible_asset_succeeds() {
mem_loadw
call.faucet_contract::burn
end
"
)
.as_str(),
",
)
.unwrap();

let note = get_note_with_fungible_asset_and_script(fungible_asset.clone(), note_script);
let note = get_note_with_fungible_asset_and_script(fungible_asset, note_script);

// CONSTRUCT AND EXECUTE TX (Success)
// --------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -220,7 +214,7 @@ fn test_faucet_contract_creation() {
// we need a Falcon Public Key to create the wallet account
let key_pair: KeyPair = KeyPair::new().unwrap();
let pub_key: PublicKey = key_pair.public_key();
let auth_scheme: AuthScheme = AuthScheme::RpoFalcon512 { pub_key: pub_key.into() };
let auth_scheme: AuthScheme = AuthScheme::RpoFalcon512 { pub_key };

// we need to use an initial seed to create the wallet account
let init_seed: [u8; 32] = [
Expand All @@ -233,30 +227,25 @@ fn test_faucet_contract_creation() {
let token_symbol = TokenSymbol::try_from(token_symbol_string).unwrap();
let decimals = 2u8;

let (faucet_account, _) = create_basic_fungible_faucet(
init_seed,
token_symbol.clone(),
decimals,
max_supply,
auth_scheme,
)
.unwrap();
let (faucet_account, _) =
create_basic_fungible_faucet(init_seed, token_symbol, decimals, max_supply, auth_scheme)
.unwrap();

// check that max_supply (slot 1) is 123
assert_eq!(
faucet_account.storage().get_item(1),
[Felt::new(123), Felt::new(2), TokenSymbol::from(token_symbol).into(), ZERO].into()
[Felt::new(123), Felt::new(2), token_symbol.into(), ZERO].into()
);

assert_eq!(faucet_account.is_faucet(), true);
assert!(faucet_account.is_faucet());

let exp_faucet_account_code_src =
include_str!("../../miden-lib/asm/miden/faucets/basic_fungible.masm");
let exp_faucet_account_code_ast = ModuleAst::parse(exp_faucet_account_code_src).unwrap();
let mut account_assembler = assembler();
let account_assembler = assembler();

let exp_faucet_account_code =
AccountCode::new(exp_faucet_account_code_ast.clone(), &mut account_assembler).unwrap();
AccountCode::new(exp_faucet_account_code_ast.clone(), &account_assembler).unwrap();

assert_eq!(faucet_account.code(), &exp_faucet_account_code);
}
Expand All @@ -270,10 +259,10 @@ fn get_faucet_account_with_max_supply_and_total_issuance(
let faucet_account_code_src =
include_str!("../../miden-lib/asm/miden/faucets/basic_fungible.masm");
let faucet_account_code_ast = ModuleAst::parse(faucet_account_code_src).unwrap();
let mut account_assembler = assembler();
let account_assembler = assembler();

let faucet_account_code =
AccountCode::new(faucet_account_code_ast.clone(), &mut account_assembler).unwrap();
AccountCode::new(faucet_account_code_ast.clone(), &account_assembler).unwrap();

let faucet_storage_slot_1 = [Felt::new(max_supply), Felt::new(0), Felt::new(0), Felt::new(0)];
let mut faucet_account_storage = AccountStorage::new(vec![
Expand All @@ -290,7 +279,7 @@ fn get_faucet_account_with_max_supply_and_total_issuance(

Account::new(
faucet_account_id,
AccountVault::new(&vec![]).unwrap(),
AccountVault::new(&[]).unwrap(),
faucet_account_storage.clone(),
faucet_account_code.clone(),
Felt::new(1),
Expand Down
Loading

0 comments on commit 84811c7

Please sign in to comment.