Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
163 changes: 71 additions & 92 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ miden-field = { version = "0.22" }
# miden-standards = { git = "https://github.com/0xMiden/protocol", rev = "a53bbe2209f506df87876c8b9c9a1730214f456b" }
# miden-tx = { tag = "v0.14.0-beta.4", git = "https://github.com/0xMiden/miden-base" }



[profile.dev]
lto = false
# Needed for 'inventory' to work
Expand Down
2 changes: 1 addition & 1 deletion tests/integration-network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ publish = false

[dependencies]
# miden-client = { version = "0.14", features = ["std", "tonic", "testing"] }
miden-client = { git = "https://github.com/0xMiden/miden-client", branch = "release/v0.14.0-beta" }
miden-client = { git = "https://github.com/0xMiden/miden-client", branch = "release/v0.14.0-beta", features = ["std", "testing"] }
miden-core.workspace = true
miden-protocol = { workspace = true, features = ["std", "testing"] }
miden-standards = { workspace = true, features = ["std"] }
Expand Down
150 changes: 71 additions & 79 deletions tests/integration-network/src/mockchain/basic_wallet.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
//! Basic wallet test module

use miden_client::{
asset::FungibleAsset, crypto::RandomCoin, note::NoteAssets, transaction::RawOutputNote,
account::{
AccountComponent, AccountId,
component::{BasicWallet, InitStorageData},
},
asset::{Asset, FungibleAsset},
transaction::RawOutputNote,
};
use miden_core::Felt;
use miden_protocol::account::{AccountId, auth::AuthScheme};
use miden_testing::{AccountState, Auth, MockChain};
use miden_protocol::{account::auth::AuthScheme, crypto::rand::RandomCoin};
use miden_standards::testing::note::NoteBuilder;
use miden_testing::{Auth, MockChain};
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,
},
};

/// Converts the P2IDE note payload into protocol storage order for the basic-wallet tests.
fn to_p2ide_storage_felts(
target: &AccountId,
Expand All @@ -34,6 +38,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
Expand All @@ -49,23 +56,21 @@ pub fn test_basic_wallet_p2id() {
let faucet_id = faucet_account.id();

let alice_account = builder
.add_account_from_builder(
.add_existing_account_from_components(
Auth::BasicAuth {
auth_scheme: AuthScheme::Falcon512Poseidon2,
},
build_existing_basic_wallet_account_builder(wallet_package.clone(), false, [1_u8; 32]),
AccountState::Exists,
[wallet_component.clone()],
)
.unwrap();
let alice_id = alice_account.id();

let bob_account = builder
.add_account_from_builder(
.add_existing_account_from_components(
Auth::BasicAuth {
auth_scheme: AuthScheme::Falcon512Poseidon2,
},
build_existing_basic_wallet_account_builder(wallet_package, false, [2_u8; 32]),
AccountState::Exists,
[wallet_component],
)
.unwrap();
let bob_id = bob_account.id();
Expand All @@ -79,16 +84,13 @@ pub fn test_basic_wallet_p2id() {
let mint_asset = FungibleAsset::new(faucet_id, mint_amount).unwrap();

let mut note_rng = RandomCoin::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_storage(to_core_felts(&alice_id))
.unwrap()
.build()
.unwrap();

let faucet_account = chain.committed_account(faucet_id).unwrap().clone();
let mint_tx_script =
Expand Down Expand Up @@ -154,6 +156,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
Expand All @@ -169,23 +174,21 @@ 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 {
auth_scheme: AuthScheme::Falcon512Poseidon2,
},
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(
.add_existing_account_from_components(
Auth::BasicAuth {
auth_scheme: AuthScheme::Falcon512Poseidon2,
},
build_existing_basic_wallet_account_builder(wallet_package, false, [4_u8; 32]),
AccountState::Exists,
[wallet_component],
)
.unwrap();
let bob_id = bob_account.id();
Expand All @@ -198,17 +201,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 = RandomCoin::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 = RandomCoin::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_storage(to_core_felts(&alice_id))
.unwrap()
.build()
.unwrap();

let faucet_account = chain.committed_account(faucet_id).unwrap().clone();
let mint_tx_script =
Expand All @@ -234,17 +234,14 @@ pub fn test_basic_wallet_p2ide() {
let timelock_height = Felt::new(0);
let reclaim_height = Felt::new(0);

let mut p2ide_rng = RandomCoin::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: to_p2ide_storage_felts(&bob_id, reclaim_height, timelock_height),
..Default::default()
},
&mut p2ide_rng,
);
let p2ide_rng = RandomCoin::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_storage(to_p2ide_storage_felts(&bob_id, reclaim_height, timelock_height))
.unwrap()
.build()
.unwrap();

let alice_account = chain.committed_account(alice_id).unwrap().clone();
let transfer_tx_script =
Expand Down Expand Up @@ -298,24 +295,25 @@ 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 {
auth_scheme: AuthScheme::Falcon512Poseidon2,
},
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(
.add_existing_account_from_components(
Auth::BasicAuth {
auth_scheme: AuthScheme::Falcon512Poseidon2,
},
build_existing_basic_wallet_account_builder(wallet_package, false, [6_u8; 32]),
AccountState::Exists,
[wallet_component],
)
.unwrap();
let bob_id = bob_account.id();
Expand All @@ -328,17 +326,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 = RandomCoin::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 = RandomCoin::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_storage(to_core_felts(&alice_id))
.unwrap()
.build()
.unwrap();

let faucet_account = chain.committed_account(faucet_id).unwrap().clone();
let mint_tx_script =
Expand All @@ -364,17 +359,14 @@ pub fn test_basic_wallet_p2ide_reclaim() {
let timelock_height = Felt::new(0);
let reclaim_height = Felt::new(1);

let mut p2ide_rng = RandomCoin::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: to_p2ide_storage_felts(&bob_id, reclaim_height, timelock_height),
..Default::default()
},
&mut p2ide_rng,
);
let p2ide_rng = RandomCoin::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_storage(to_p2ide_storage_felts(&bob_id, reclaim_height, timelock_height))
.unwrap()
.build()
.unwrap();

let alice_account = chain.committed_account(alice_id).unwrap().clone();
let transfer_tx_script =
Expand Down
53 changes: 20 additions & 33 deletions tests/integration-network/src/mockchain/counter_contract.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
//! Counter contract test module

use miden_client::{
Word, account::component::BasicWallet, crypto::RandomCoin, note::NoteTag,
Word,
account::{AccountComponent, component::InitStorageData},
transaction::RawOutputNote,
};
use miden_core::Felt;
use miden_protocol::account::{
AccountBuilder, AccountStorageMode, AccountType, StorageMap, StorageMapKey, StorageSlot,
auth::AuthScheme,
};
use miden_testing::{AccountState, Auth, MockChain};
use miden_protocol::{account::auth::AuthScheme, crypto::rand::RandomCoin};
use miden_standards::testing::note::NoteBuilder;
use miden_testing::{Auth, MockChain};
use midenc_expect_test::expect;

use super::{
cycle_helpers::note_cycles,
helpers::{
NoteCreationConfig, account_component_from_package, assert_counter_storage,
compile_rust_package, counter_storage_slot_name, create_note_from_package, execute_tx,
COUNTER_CONTRACT_STORAGE_KEY, assert_counter_storage, compile_rust_package,
counter_storage_slot_name, execute_tx,
},
};
use crate::mockchain::helpers::COUNTER_CONTRACT_STORAGE_KEY;

/// Tests the counter contract deployment and note consumption workflow on a mock chain.
#[test]
Expand All @@ -30,40 +28,29 @@ pub fn test_counter_contract() {

let value = Word::from([Felt::ZERO, Felt::ZERO, Felt::ZERO, Felt::ONE]);
let counter_storage_slot = counter_storage_slot_name();
let storage_slots = vec![StorageSlot::with_map(
counter_storage_slot.clone(),
StorageMap::with_entries([(StorageMapKey::new(COUNTER_CONTRACT_STORAGE_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(), COUNTER_CONTRACT_STORAGE_KEY, value)
.unwrap();
let contract_component = 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(
.add_existing_account_from_components(
Auth::BasicAuth {
auth_scheme: AuthScheme::Falcon512Poseidon2,
},
counter_account_builder,
AccountState::Exists,
[contract_component],
)
.expect("failed to add counter account to mock chain builder");
.unwrap();

let mut rng = RandomCoin::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(RawOutputNote::Full(counter_note.clone()));

let mut chain = builder.build().expect("failed to build mock chain");
Expand Down
Loading