diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 941fa4a3e..a7d6b2c9d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -317,6 +317,15 @@ jobs: if ! cargo make --version 2>/dev/null; then cargo install cargo-make --force fi + + # Some integration tests use midenup to compile the example projects + - name: Install midenup + run: | + if ! miden help 2>/dev/null; then + cargo install --git https://github.com/0xMiden/midenup + midenup init + fi + - name: Test run: | cargo make test -E 'package(midenc-integration-network-tests)' diff --git a/Cargo.lock b/Cargo.lock index 6f165f8a2..fab5d2b67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2178,8 +2178,7 @@ dependencies = [ [[package]] name = "miden-agglayer" version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21a867217bab689c0539f6b4797cb452f0932de6904479a38f1322e045b9383b" +source = "git+https://github.com/lambdaclass/miden-base.git?branch=fabrizioorsi%2Fmiden-testing-compiler-backport#b4852646e9508c4df51d9e62e00cb8b1fe99317e" dependencies = [ "fs-err", "miden-assembly", @@ -2280,8 +2279,7 @@ dependencies = [ [[package]] name = "miden-block-prover" version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e92a0ddae8d0983e37bc636edba741947b1e3dc63baed2ad85921342080154a" +source = "git+https://github.com/lambdaclass/miden-base.git?branch=fabrizioorsi%2Fmiden-testing-compiler-backport#b4852646e9508c4df51d9e62e00cb8b1fe99317e" dependencies = [ "miden-protocol", "thiserror", @@ -2289,9 +2287,8 @@ dependencies = [ [[package]] name = "miden-client" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b256399e6f0d7ae53a592b771a1286c46ca6b45397d1c5fda6d83dbd222357" +version = "0.13.2" +source = "git+https://github.com/lambdaclass/miden-client.git?branch=fabrizioorsi%2Fmiden-testing-compiler-backport#67e8cd003f6f5dba22c8fc3dc54fcd6b51798d4d" dependencies = [ "anyhow", "async-trait", @@ -2643,8 +2640,7 @@ dependencies = [ [[package]] name = "miden-protocol" version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "785be319a826c9cb43d2e1a41a1fb1eee3f2baafe360e0d743690641f7c93ad5" +source = "git+https://github.com/lambdaclass/miden-base.git?branch=fabrizioorsi%2Fmiden-testing-compiler-backport#b4852646e9508c4df51d9e62e00cb8b1fe99317e" dependencies = [ "bech32", "fs-err", @@ -2674,8 +2670,7 @@ dependencies = [ [[package]] name = "miden-protocol-macros" version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2dc854c1b9e49e82d3f39c5710345226e0b2a62ec0ea220c616f1f3a099cfb3" +source = "git+https://github.com/lambdaclass/miden-base.git?branch=fabrizioorsi%2Fmiden-testing-compiler-backport#b4852646e9508c4df51d9e62e00cb8b1fe99317e" dependencies = [ "proc-macro2", "quote", @@ -2724,8 +2719,7 @@ version = "0.10.0" [[package]] name = "miden-standards" version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98e33771fc35e1e640582bcd26c88b2ab449dd3a70888b315546d0d3447f4bb3" +source = "git+https://github.com/lambdaclass/miden-base.git?branch=fabrizioorsi%2Fmiden-testing-compiler-backport#b4852646e9508c4df51d9e62e00cb8b1fe99317e" dependencies = [ "fs-err", "miden-assembly", @@ -2773,8 +2767,7 @@ dependencies = [ [[package]] name = "miden-testing" version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae5d41a888d1a5e520a9312a170975d0fbadefb1b9200543cebdf54dd0960310" +source = "git+https://github.com/lambdaclass/miden-base.git?branch=fabrizioorsi%2Fmiden-testing-compiler-backport#b4852646e9508c4df51d9e62e00cb8b1fe99317e" dependencies = [ "anyhow", "itertools 0.14.0", @@ -2815,8 +2808,7 @@ dependencies = [ [[package]] name = "miden-tx" version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "430e4ee02b5efb71b104926e229441e0071a93a259a70740bf8c436495caa64f" +source = "git+https://github.com/lambdaclass/miden-base.git?branch=fabrizioorsi%2Fmiden-testing-compiler-backport#b4852646e9508c4df51d9e62e00cb8b1fe99317e" dependencies = [ "miden-processor", "miden-protocol", @@ -2829,8 +2821,7 @@ dependencies = [ [[package]] name = "miden-tx-batch-prover" version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03bc209b6487ebac0de230461e229a99d17ed73596c7d99fc59eea47a28a89cc" +source = "git+https://github.com/lambdaclass/miden-base.git?branch=fabrizioorsi%2Fmiden-testing-compiler-backport#b4852646e9508c4df51d9e62e00cb8b1fe99317e" dependencies = [ "miden-protocol", "miden-tx", diff --git a/Cargo.toml b/Cargo.toml index 544c54632..bdecfceee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -171,6 +171,12 @@ miden-test-harness-macros = { path = "test-harness/test-harness-macros" } #miden-processor = { path = "../miden-vm/processor" } #miden-mast-package = { git = "https://github.com/0xMiden/miden-vm", rev = "614cd7f9b52f45238b0ab59c71ebb49325051e5d" } #miden-mast-package = { path = "../miden-vm/package" } +miden-protocol = { git = "https://github.com/lambdaclass/miden-base.git", branch = "fabrizioorsi/miden-testing-compiler-backport" } +miden-standards = { git = "https://github.com/lambdaclass/miden-base.git", branch = "fabrizioorsi/miden-testing-compiler-backport" } +miden-testing = { git = "https://github.com/lambdaclass/miden-base.git", branch = "fabrizioorsi/miden-testing-compiler-backport" } +miden-tx = { git = "https://github.com/lambdaclass/miden-base.git", branch = "fabrizioorsi/miden-testing-compiler-backport" } +miden-block-prover = { git = "https://github.com/lambdaclass/miden-base.git", branch = "fabrizioorsi/miden-testing-compiler-backport" } +miden-tx-batch-prover = { git = "https://github.com/lambdaclass/miden-base.git", branch = "fabrizioorsi/miden-testing-compiler-backport" } [profile.dev] diff --git a/tests/integration-network/Cargo.toml b/tests/integration-network/Cargo.toml index 5fbc77baf..9b7eae9ce 100644 --- a/tests/integration-network/Cargo.toml +++ b/tests/integration-network/Cargo.toml @@ -12,7 +12,7 @@ edition.workspace = true publish = false [dependencies] -miden-client = { version = "0.13", features = ["std", "tonic", "testing"] } +miden-client = { branch = "fabrizioorsi/miden-testing-compiler-backport", git = "https://github.com/lambdaclass/miden-client.git", features = ["std", "tonic", "testing"] } miden-core.workspace = true miden-protocol = { workspace = true, features = ["std"] } miden-standards = { workspace = true, features = ["std"] } diff --git a/tests/integration-network/src/mockchain/basic_wallet.rs b/tests/integration-network/src/mockchain/basic_wallet.rs index 2365b8051..44b35f4d1 100644 --- a/tests/integration-network/src/mockchain/basic_wallet.rs +++ b/tests/integration-network/src/mockchain/basic_wallet.rs @@ -1,21 +1,21 @@ //! Basic wallet test module use miden_client::{ + account::component::{BasicWallet, InitStorageData}, asset::FungibleAsset, crypto::RpoRandomCoin, - note::NoteAssets, - testing::{AccountState, Auth, MockChain}, + testing::{Auth, MockChain, NoteBuilder}, transaction::OutputNote, }; use miden_core::Felt; +use miden_protocol::{account::AccountComponent, asset::Asset}; use midenc_expect_test::expect; use super::{ cycle_helpers::{note_cycles, prologue_cycles, tx_script_processing_cycles}, helpers::{ - NoteCreationConfig, assert_account_has_fungible_asset, build_asset_transfer_tx, - build_existing_basic_wallet_account_builder, build_send_notes_script, compile_rust_package, - create_note_from_package, execute_tx, to_core_felts, + assert_account_has_fungible_asset, build_asset_transfer_tx, build_send_notes_script, + compile_rust_package, execute_tx, to_core_felts, }, }; @@ -27,6 +27,9 @@ pub fn test_basic_wallet_p2id() { let note_package = compile_rust_package("../../examples/p2id-note", true); let tx_script_package = compile_rust_package("../../examples/basic-wallet-tx-script", true); + let wallet_component = + AccountComponent::from_package(&wallet_package, &InitStorageData::default()).unwrap(); + let mut builder = MockChain::builder(); let max_supply = 1_000_000_000u64; let faucet_account = builder @@ -35,20 +38,12 @@ pub fn test_basic_wallet_p2id() { let faucet_id = faucet_account.id(); let alice_account = builder - .add_account_from_builder( - Auth::BasicAuth, - build_existing_basic_wallet_account_builder(wallet_package.clone(), false, [1_u8; 32]), - AccountState::Exists, - ) + .add_existing_account_from_components(Auth::BasicAuth, [wallet_component.clone()]) .unwrap(); let alice_id = alice_account.id(); let bob_account = builder - .add_account_from_builder( - Auth::BasicAuth, - build_existing_basic_wallet_account_builder(wallet_package, false, [2_u8; 32]), - AccountState::Exists, - ) + .add_existing_account_from_components(Auth::BasicAuth, [wallet_component]) .unwrap(); let bob_id = bob_account.id(); @@ -61,16 +56,13 @@ pub fn test_basic_wallet_p2id() { let mint_asset = FungibleAsset::new(faucet_id, mint_amount).unwrap(); let mut note_rng = RpoRandomCoin::new(note_package.unwrap_program().hash()); - let p2id_note_mint = create_note_from_package( - note_package.clone(), - faucet_id, - NoteCreationConfig { - assets: NoteAssets::new(vec![mint_asset.into()]).unwrap(), - inputs: to_core_felts(&alice_id), - ..Default::default() - }, - &mut note_rng, - ); + let p2id_note_mint = NoteBuilder::new(faucet_id, &mut note_rng) + .package((*note_package).clone()) + .add_assets([Asset::from(mint_asset)]) + .note_inputs(to_core_felts(&alice_id)) + .unwrap() + .build() + .unwrap(); let faucet_account = chain.committed_account(faucet_id).unwrap().clone(); let mint_tx_script = @@ -136,6 +128,9 @@ pub fn test_basic_wallet_p2ide() { let p2id_note_package = compile_rust_package("../../examples/p2id-note", true); let p2ide_note_package = compile_rust_package("../../examples/p2ide-note", true); + let wallet_component = + AccountComponent::from_package(&wallet_package, &InitStorageData::default()).unwrap(); + let mut builder = MockChain::builder(); let max_supply = 1_000_000_000u64; let faucet_account = builder @@ -144,20 +139,15 @@ pub fn test_basic_wallet_p2ide() { let faucet_id = faucet_account.id(); let alice_account = builder - .add_account_from_builder( + .add_existing_account_from_components( Auth::BasicAuth, - build_existing_basic_wallet_account_builder(wallet_package.clone(), true, [3_u8; 32]), - AccountState::Exists, + [wallet_component.clone(), BasicWallet.into()], ) .unwrap(); let alice_id = alice_account.id(); let bob_account = builder - .add_account_from_builder( - Auth::BasicAuth, - build_existing_basic_wallet_account_builder(wallet_package, false, [4_u8; 32]), - AccountState::Exists, - ) + .add_existing_account_from_components(Auth::BasicAuth, [wallet_component]) .unwrap(); let bob_id = bob_account.id(); @@ -169,17 +159,14 @@ pub fn test_basic_wallet_p2ide() { let mint_amount = 100_000u64; let mint_asset = FungibleAsset::new(faucet_id, mint_amount).unwrap(); - let mut p2id_rng = RpoRandomCoin::new(p2id_note_package.unwrap_program().hash()); - let p2id_note_mint = create_note_from_package( - p2id_note_package.clone(), - faucet_id, - NoteCreationConfig { - assets: NoteAssets::new(vec![mint_asset.into()]).unwrap(), - inputs: to_core_felts(&alice_id), - ..Default::default() - }, - &mut p2id_rng, - ); + let p2id_rng = RpoRandomCoin::new(p2id_note_package.unwrap_program().hash()); + let p2id_note_mint = NoteBuilder::new(faucet_id, p2id_rng) + .package((*p2id_note_package).clone()) + .add_assets([Asset::from(mint_asset)]) + .note_inputs(to_core_felts(&alice_id)) + .unwrap() + .build() + .unwrap(); let faucet_account = chain.committed_account(faucet_id).unwrap().clone(); let mint_tx_script = @@ -205,21 +192,18 @@ pub fn test_basic_wallet_p2ide() { let timelock_height = Felt::new(0); let reclaim_height = Felt::new(0); - let mut p2ide_rng = RpoRandomCoin::new(p2ide_note_package.unwrap_program().hash()); - let p2ide_note = create_note_from_package( - p2ide_note_package, - alice_id, - NoteCreationConfig { - assets: NoteAssets::new(vec![transfer_asset.into()]).unwrap(), - inputs: { - let mut inputs = to_core_felts(&bob_id); - inputs.extend([timelock_height, reclaim_height]); - inputs - }, - ..Default::default() - }, - &mut p2ide_rng, - ); + let p2ide_rng = RpoRandomCoin::new(p2ide_note_package.unwrap_program().hash()); + let p2ide_note = NoteBuilder::new(alice_id, p2ide_rng) + .package((*p2ide_note_package).clone()) + .add_assets([Asset::from(transfer_asset)]) + .note_inputs({ + let mut inputs = to_core_felts(&bob_id); + inputs.extend([timelock_height, reclaim_height]); + inputs + }) + .unwrap() + .build() + .unwrap(); let alice_account = chain.committed_account(alice_id).unwrap().clone(); let transfer_tx_script = @@ -266,21 +250,19 @@ pub fn test_basic_wallet_p2ide_reclaim() { .unwrap(); let faucet_id = faucet_account.id(); + let wallet_component = + AccountComponent::from_package(&wallet_package, &InitStorageData::default()).unwrap(); + let alice_account = builder - .add_account_from_builder( + .add_existing_account_from_components( Auth::BasicAuth, - build_existing_basic_wallet_account_builder(wallet_package.clone(), true, [5_u8; 32]), - AccountState::Exists, + [wallet_component.clone(), BasicWallet.into()], ) .unwrap(); let alice_id = alice_account.id(); let bob_account = builder - .add_account_from_builder( - Auth::BasicAuth, - build_existing_basic_wallet_account_builder(wallet_package, false, [6_u8; 32]), - AccountState::Exists, - ) + .add_existing_account_from_components(Auth::BasicAuth, [wallet_component]) .unwrap(); let bob_id = bob_account.id(); @@ -292,17 +274,14 @@ pub fn test_basic_wallet_p2ide_reclaim() { let mint_amount = 100_000u64; let mint_asset = FungibleAsset::new(faucet_id, mint_amount).unwrap(); - let mut p2id_rng = RpoRandomCoin::new(p2id_note_package.unwrap_program().hash()); - let p2id_note_mint = create_note_from_package( - p2id_note_package.clone(), - faucet_id, - NoteCreationConfig { - assets: NoteAssets::new(vec![mint_asset.into()]).unwrap(), - inputs: to_core_felts(&alice_id), - ..Default::default() - }, - &mut p2id_rng, - ); + let p2id_rng = RpoRandomCoin::new(p2id_note_package.unwrap_program().hash()); + let p2id_note_mint = NoteBuilder::new(faucet_id, p2id_rng) + .package((*p2id_note_package).clone()) + .add_assets([Asset::from(mint_asset)]) + .note_inputs(to_core_felts(&alice_id)) + .unwrap() + .build() + .unwrap(); let faucet_account = chain.committed_account(faucet_id).unwrap().clone(); let mint_tx_script = @@ -328,21 +307,18 @@ pub fn test_basic_wallet_p2ide_reclaim() { let timelock_height = Felt::new(0); let reclaim_height = Felt::new(1000); - let mut p2ide_rng = RpoRandomCoin::new(p2ide_note_package.unwrap_program().hash()); - let p2ide_note = create_note_from_package( - p2ide_note_package, - alice_id, - NoteCreationConfig { - assets: NoteAssets::new(vec![transfer_asset.into()]).unwrap(), - inputs: { - let mut inputs = to_core_felts(&bob_id); - inputs.extend([timelock_height, reclaim_height]); - inputs - }, - ..Default::default() - }, - &mut p2ide_rng, - ); + let p2ide_rng = RpoRandomCoin::new(p2ide_note_package.unwrap_program().hash()); + let p2ide_note = NoteBuilder::new(alice_id, p2ide_rng) + .package((*p2ide_note_package).clone()) + .add_assets([Asset::from(transfer_asset)]) + .note_inputs({ + let mut inputs = to_core_felts(&bob_id); + inputs.extend([timelock_height, reclaim_height]); + inputs + }) + .unwrap() + .build() + .unwrap(); let alice_account = chain.committed_account(alice_id).unwrap().clone(); let transfer_tx_script = diff --git a/tests/integration-network/src/mockchain/counter_contract.rs b/tests/integration-network/src/mockchain/counter_contract.rs index 2060a4079..20bccbb7a 100644 --- a/tests/integration-network/src/mockchain/counter_contract.rs +++ b/tests/integration-network/src/mockchain/counter_contract.rs @@ -2,24 +2,20 @@ use miden_client::{ Word, - account::component::BasicWallet, + account::{ + AccountComponent, StorageSlotName, + component::{BasicWallet, InitStorageData}, + }, crypto::RpoRandomCoin, - note::NoteTag, - testing::{AccountState, Auth, MockChain}, + testing::{Auth, MockChain, NoteBuilder}, transaction::OutputNote, }; use miden_core::{Felt, FieldElement}; -use miden_protocol::account::{ - AccountBuilder, AccountStorageMode, AccountType, StorageMap, StorageSlot, StorageSlotName, -}; use midenc_expect_test::expect; use super::{ cycle_helpers::note_cycles, - helpers::{ - NoteCreationConfig, account_component_from_package, assert_counter_storage, - compile_rust_package, create_note_from_package, execute_tx, - }, + helpers::{assert_counter_storage, compile_rust_package, execute_tx}, }; /// Tests the counter contract deployment and note consumption workflow on a mock chain. @@ -33,33 +29,27 @@ pub fn test_counter_contract() { let value = Word::from([Felt::ZERO, Felt::ZERO, Felt::ZERO, Felt::ONE]); let counter_storage_slot = StorageSlotName::new("miden::component::miden_counter_contract::count_map").unwrap(); - let storage_slots = vec![StorageSlot::with_map( - counter_storage_slot.clone(), - StorageMap::with_entries([(key, value)]).unwrap(), - )]; - let counter_component = account_component_from_package(contract_package, storage_slots); - let counter_account_builder = AccountBuilder::new([0_u8; 32]) - .account_type(AccountType::RegularAccountUpdatableCode) - .storage_mode(AccountStorageMode::Public) - .with_component(BasicWallet) - .with_component(counter_component); + let mut init_storage_data = InitStorageData::default(); + init_storage_data + .insert_map_entry(counter_storage_slot.clone(), key, value) + .unwrap(); + let contract_package = AccountComponent::from_package(&contract_package, &init_storage_data) + .expect("Failed to build account component from counter project"); let mut builder = MockChain::builder(); let counter_account = builder - .add_account_from_builder(Auth::BasicAuth, counter_account_builder, AccountState::Exists) - .expect("failed to add counter account to mock chain builder"); + .add_existing_account_from_components( + Auth::BasicAuth, + [BasicWallet.into(), contract_package], + ) + .unwrap(); let mut rng = RpoRandomCoin::new(note_package.clone().unwrap_program().hash()); - let counter_note = create_note_from_package( - note_package, - counter_account.id(), - NoteCreationConfig { - tag: NoteTag::with_account_target(counter_account.id()), - ..Default::default() - }, - &mut rng, - ); + let counter_note = NoteBuilder::new(counter_account.id(), &mut rng) + .package((*note_package).clone()) + .build() + .unwrap(); builder.add_output_note(OutputNote::Full(counter_note.clone())); let mut chain = builder.build().expect("failed to build mock chain"); diff --git a/tests/integration-network/src/mockchain/counter_contract_no_auth.rs b/tests/integration-network/src/mockchain/counter_contract_no_auth.rs index b66039cd2..e1f9aa5b7 100644 --- a/tests/integration-network/src/mockchain/counter_contract_no_auth.rs +++ b/tests/integration-network/src/mockchain/counter_contract_no_auth.rs @@ -2,24 +2,29 @@ use miden_client::{ Word, - account::component::BasicWallet, + account::{ + AccountComponent, + component::{BasicWallet, InitStorageData}, + }, crypto::RpoRandomCoin, note::NoteTag, - testing::{AccountState, Auth, MockChain}, + testing::{AccountState, Auth, MockChain, NoteBuilder}, transaction::OutputNote, }; use miden_core::{Felt, FieldElement}; -use miden_protocol::account::{ - AccountBuilder, AccountStorageMode, AccountType, StorageMap, StorageSlot, StorageSlotName, -}; +use miden_protocol::account::{AccountBuilder, AccountStorageMode, AccountType, StorageSlotName}; +// use super::helpers::{ +// assert_counter_storage, build_existing_counter_account_builder_with_auth_package, execute_tx, +// use miden_protocol::account::{ +// AccountBuilder, AccountStorageMode, AccountType, StorageMap, StorageSlot, StorageSlotName, +// }; use midenc_expect_test::expect; use super::{ cycle_helpers::{auth_procedure_cycles, note_cycles}, helpers::{ - NoteCreationConfig, assert_counter_storage, - build_existing_counter_account_builder_with_auth_package, compile_rust_package, - create_note_from_package, execute_tx, + assert_counter_storage, build_existing_counter_account_builder_with_auth_package, + compile_rust_package, execute_tx, }, }; @@ -33,7 +38,7 @@ use super::{ #[test] pub fn test_counter_contract_no_auth() { // Compile the contracts first (before creating any runtime) - let contract_package = compile_rust_package("../../examples/counter-contract", true); + let counter_package = compile_rust_package("../../examples/counter-contract", true); let note_package = compile_rust_package("../../examples/counter-note", true); let no_auth_auth_component = compile_rust_package("../../examples/auth-component-no-auth", true); @@ -42,18 +47,24 @@ pub fn test_counter_contract_no_auth() { let value = Word::from([Felt::ZERO, Felt::ZERO, Felt::ZERO, Felt::ONE]); let counter_storage_slot = StorageSlotName::new("miden::component::miden_counter_contract::count_map").unwrap(); - let counter_storage_slots = vec![StorageSlot::with_map( - counter_storage_slot.clone(), - StorageMap::with_entries([(key, value)]).unwrap(), - )]; - let mut builder = MockChain::builder(); + let counter_component = { + let mut init_storage_data = InitStorageData::default(); + init_storage_data + .insert_map_entry(counter_storage_slot.clone(), key, value) + .unwrap(); + AccountComponent::from_package(&counter_package, &init_storage_data).unwrap() + }; + + let mut counter_init_storage_data = InitStorageData::default(); + counter_init_storage_data + .insert_map_entry(counter_storage_slot.clone(), key, value) + .expect("failed to insert counter map entry"); let counter_account = build_existing_counter_account_builder_with_auth_package( - contract_package, + counter_component, no_auth_auth_component, vec![], - counter_storage_slots, [0_u8; 32], ) .build_existing() @@ -75,16 +86,13 @@ pub fn test_counter_contract_no_auth() { eprintln!("Sender account ID: {:?}", sender_account.id().to_hex()); // Sender creates the counter note (note script increments counter's storage on consumption) - let mut rng = RpoRandomCoin::new(note_package.unwrap_program().hash()); - let counter_note = create_note_from_package( - note_package.clone(), - sender_account.id(), - NoteCreationConfig { - tag: NoteTag::with_account_target(counter_account.id()), - ..Default::default() - }, - &mut rng, - ); + let rng = RpoRandomCoin::new(note_package.unwrap_program().hash()); + let counter_note = NoteBuilder::new(sender_account.id(), rng) + .package((*note_package).clone()) + .tag(NoteTag::with_account_target(counter_account.id()).into()) + .build() + .unwrap(); + eprintln!("Counter note hash: {:?}", counter_note.id().to_hex()); builder.add_output_note(OutputNote::Full(counter_note.clone())); diff --git a/tests/integration-network/src/mockchain/counter_contract_rust_auth.rs b/tests/integration-network/src/mockchain/counter_contract_rust_auth.rs index 5cdff8289..7cc3691ff 100644 --- a/tests/integration-network/src/mockchain/counter_contract_rust_auth.rs +++ b/tests/integration-network/src/mockchain/counter_contract_rust_auth.rs @@ -5,7 +5,10 @@ //! contract account that uses the Rust-compiled auth component. use miden_client::{ - auth::BasicAuthenticator, crypto::RpoRandomCoin, note::NoteTag, testing::MockChain, + auth::BasicAuthenticator, + crypto::RpoRandomCoin, + note::NoteTag, + testing::{MockChain, NoteBuilder}, transaction::OutputNote, }; use miden_protocol::account::StorageSlotName; @@ -14,9 +17,8 @@ use midenc_expect_test::expect; use super::{ cycle_helpers::auth_procedure_cycles, helpers::{ - NoteCreationConfig, assert_counter_storage, block_on, - build_counter_account_with_rust_rpo_auth, build_send_notes_script, compile_rust_package, - create_note_from_package, + assert_counter_storage, block_on, build_counter_account_with_rust_rpo_auth, + build_send_notes_script, compile_rust_package, }, }; @@ -57,16 +59,12 @@ pub fn test_counter_contract_rust_auth_blocks_unauthorized_note_creation() { ); // Positive check: original client (with the key) can create a note - let mut rng = RpoRandomCoin::new(note_package.unwrap_program().hash()); - let own_note = create_note_from_package( - note_package.clone(), - counter_account.id(), - NoteCreationConfig { - tag: NoteTag::with_account_target(counter_account.id()), - ..Default::default() - }, - &mut rng, - ); + let rng = RpoRandomCoin::new(note_package.unwrap_program().hash()); + let own_note = NoteBuilder::new(counter_account.id(), rng) + .package((*note_package).clone()) + .tag(NoteTag::with_account_target(counter_account.id()).into()) + .build() + .expect("failed to build own_note"); let tx_script = build_send_notes_script(&counter_account, std::slice::from_ref(&own_note)); let authenticator = BasicAuthenticator::new(std::slice::from_ref(&secret_key)); @@ -88,15 +86,12 @@ pub fn test_counter_contract_rust_auth_blocks_unauthorized_note_creation() { // Negative check: without the RPO-Falcon512 key, creating output notes should fail. let counter_account = chain.committed_account(counter_account_id).unwrap().clone(); - let forged_note = create_note_from_package( - note_package, - counter_account.id(), - NoteCreationConfig { - tag: NoteTag::with_account_target(counter_account.id()), - ..Default::default() - }, - &mut rng, - ); + let rng = RpoRandomCoin::new(note_package.unwrap_program().hash()); + let forged_note = NoteBuilder::new(counter_account.id(), rng) + .package((*note_package).clone()) + .tag(NoteTag::with_account_target(counter_account.id()).into()) + .build() + .expect("failed to build forged_note"); let tx_script = build_send_notes_script(&counter_account, std::slice::from_ref(&forged_note)); let tx_context_builder = chain diff --git a/tests/integration-network/src/mockchain/helpers.rs b/tests/integration-network/src/mockchain/helpers.rs index 6cf420314..844a09837 100644 --- a/tests/integration-network/src/mockchain/helpers.rs +++ b/tests/integration-network/src/mockchain/helpers.rs @@ -4,14 +4,15 @@ use std::{collections::BTreeSet, future::Future, sync::Arc}; use miden_client::{ Word, - account::component::BasicWallet, + account::{ + AccountStorage, StorageSlotName, + component::{BasicWallet, InitStorageData}, + }, asset::FungibleAsset, auth::AuthSecretKey, crypto::FeltRng, - note::{ - Note, NoteAssets, NoteInputs, NoteMetadata, NoteRecipient, NoteScript, NoteTag, NoteType, - }, - testing::{MockChain, TransactionContextBuilder}, + note::{Note, NoteType}, + testing::{MockChain, NoteBuilder, TransactionContextBuilder}, transaction::OutputNote, }; use miden_core::{Felt, FieldElement, crypto::hash::Rpo256}; @@ -19,8 +20,8 @@ use miden_integration_tests::CompilerTestBuilder; use miden_mast_package::Package; use miden_protocol::{ account::{ - Account, AccountBuilder, AccountComponent, AccountComponentMetadata, AccountId, - AccountStorage, AccountStorageMode, AccountType, StorageMap, StorageSlot, StorageSlotName, + Account, AccountBuilder, AccountComponent, AccountId, AccountStorageMode, AccountType, + StorageSlot, }, asset::Asset, note::PartialNote, @@ -51,10 +52,9 @@ pub(super) fn block_on(future: F) -> F::Output { // COMPILATION // ================================================================================================ -/// Helper to compile a Rust package to a Miden `Package`. -pub(super) fn compile_rust_package(package_path: &str, release: bool) -> Arc { +pub(super) fn compile_rust_package(project_path: &str, release: bool) -> Arc { let config = WasmTranslationConfig::default(); - let mut builder = CompilerTestBuilder::rust_source_cargo_miden(package_path, config, []); + let mut builder = CompilerTestBuilder::rust_source_cargo_miden(project_path, config, []); if release { builder.with_release(true); @@ -67,89 +67,9 @@ pub(super) fn compile_rust_package(package_path: &str, release: bool) -> Arc, -} - -impl Default for NoteCreationConfig { - fn default() -> Self { - Self { - note_type: NoteType::Public, - tag: NoteTag::new(0), - assets: Default::default(), - inputs: Default::default(), - } - } -} - -/// Creates a note from a compiled note package without requiring a `miden_client::Client`. -pub(super) fn create_note_from_package( - package: Arc, - sender_id: AccountId, - config: NoteCreationConfig, - rng: &mut impl FeltRng, -) -> Note { - let note_program = package.unwrap_program(); - let note_script = - NoteScript::from_parts(note_program.mast_forest().clone(), note_program.entrypoint()); - - let serial_num = rng.draw_word(); - let note_inputs = NoteInputs::new(config.inputs).unwrap(); - let recipient = NoteRecipient::new(serial_num, note_script, note_inputs); - - let metadata = NoteMetadata::new(sender_id, config.note_type, config.tag); - - Note::new(config.assets, metadata, recipient) -} - // ACCOUNT COMPONENT HELPERS // ================================================================================================ -/// Creates an account component from a compiled package's component metadata. -pub(super) fn account_component_from_package( - package: Arc, - storage_slots: Vec, -) -> AccountComponent { - let metadata = AccountComponentMetadata::try_from(package.as_ref()) - .expect("no account component metadata present"); - AccountComponent::new(package.unwrap_library().as_ref().clone(), storage_slots) - .unwrap() - .with_metadata(metadata) -} - -// BASIC WALLET HELPERS -// ================================================================================================ - -/// Builds an account builder for an existing basic-wallet account based on the provided component -/// package. -pub(super) fn build_existing_basic_wallet_account_builder( - wallet_package: Arc, - with_std_basic_wallet: bool, - seed: [u8; 32], -) -> AccountBuilder { - let wallet_component = account_component_from_package(wallet_package, vec![]); - - let mut builder = AccountBuilder::new(seed) - .account_type(AccountType::RegularAccountUpdatableCode) - .storage_mode(AccountStorageMode::Public) - .with_component(wallet_component); - - if with_std_basic_wallet { - builder = builder.with_component(BasicWallet); - } - - builder -} - /// Asserts that the account vault contains a fungible asset from the expected faucet with the /// expected total amount. pub(super) fn assert_account_has_fungible_asset( @@ -223,10 +143,6 @@ pub(super) fn build_asset_transfer_tx( tx_script_package: Arc, rng: &mut impl FeltRng, ) -> (TransactionContextBuilder, Note) { - let note_program = p2id_note_package.unwrap_program(); - let note_script = - NoteScript::from_parts(note_program.mast_forest().clone(), note_program.entrypoint()); - let tx_script_program = tx_script_package.unwrap_program(); let tx_script = TransactionScript::from_parts( tx_script_program.mast_forest().clone(), @@ -234,20 +150,27 @@ pub(super) fn build_asset_transfer_tx( ); let serial_num = rng.draw_word(); - let inputs = NoteInputs::new(to_core_felts(&recipient_id)).unwrap(); - let note_recipient = NoteRecipient::new(serial_num, note_script, inputs); - let config = NoteCreationConfig { - assets: NoteAssets::new(vec![asset.into()]).unwrap(), - ..Default::default() - }; - let metadata = NoteMetadata::new(sender_id, config.note_type, config.tag); - let output_note = Note::new(config.assets, metadata, note_recipient.clone()); + let asset: Asset = asset.into(); + let output_note = NoteBuilder::new(sender_id, rng) + .serial_number(serial_num) + .package((*p2id_note_package).clone()) + .note_inputs(to_core_felts(&recipient_id)) + .unwrap() + .add_assets([asset]) + .tag(0) + .build() + .unwrap(); // Prepare commitment data // This must match the input layout expected by `examples/basic-wallet-tx-script`. - let mut commitment_input: Vec = vec![config.tag.into(), Felt::from(config.note_type)]; - let recipient_digest: [Felt; 4] = note_recipient.digest().into(); + let mut commitment_input: Vec = vec![ + // The output's note tag + Felt::new(0u64), + // The output's note type + Felt::from(NoteType::Public), + ]; + let recipient_digest: [Felt; 4] = output_note.recipient().digest().into(); commitment_input.extend(recipient_digest); let asset_arr: Word = asset.into(); @@ -312,10 +235,9 @@ pub(super) fn assert_counter_storage( /// Builds an account builder for an existing public counter account containing the counter /// contract component and a custom authentication component compiled as a package library. pub(super) fn build_existing_counter_account_builder_with_auth_package( - contract_package: Arc, + counter_component: AccountComponent, auth_component_package: Arc, auth_storage_slots: Vec, - counter_storage_slots: Vec, seed: [u8; 32], ) -> AccountBuilder { let supported_types = BTreeSet::from_iter([AccountType::RegularAccountUpdatableCode]); @@ -325,7 +247,6 @@ pub(super) fn build_existing_counter_account_builder_with_auth_package( ) .unwrap() .with_supported_types(supported_types); - let counter_component = account_component_from_package(contract_package, counter_storage_slots); AccountBuilder::new(seed) .account_type(AccountType::RegularAccountUpdatableCode) @@ -346,10 +267,13 @@ pub(super) fn build_counter_account_with_rust_rpo_auth( ) -> (Account, AuthSecretKey) { let key = Word::from([Felt::ZERO, Felt::ZERO, Felt::ZERO, Felt::ONE]); let value = Word::from([Felt::ZERO, Felt::ZERO, Felt::ZERO, Felt::ONE]); - let counter_storage_slots = vec![StorageSlot::with_map( - counter_storage_slot_name(), - StorageMap::with_entries([(key, value)]).unwrap(), - )]; + let mut counter_init_storage_data = InitStorageData::default(); + counter_init_storage_data + .insert_map_entry(counter_storage_slot_name(), key, value) + .expect("failed to insert counter map entry"); + + let counter_component = + AccountComponent::from_package(&component_package, &counter_init_storage_data).unwrap(); let mut rng = StdRng::seed_from_u64(1); let secret_key = AuthSecretKey::new_falcon512_rpo_with_rng(&mut rng); @@ -359,10 +283,9 @@ pub(super) fn build_counter_account_with_rust_rpo_auth( vec![StorageSlot::with_value(auth_public_key_slot_name(), pk_commitment)]; let account = build_existing_counter_account_builder_with_auth_package( - component_package, + counter_component, auth_component_package, auth_storage_slots, - counter_storage_slots, seed, ) .build_existing()