From 87e289c56c0e9ecaa91bb8ed803d946ff8de1d04 Mon Sep 17 00:00:00 2001 From: /alex/ Date: Mon, 24 Jun 2024 08:46:38 +0200 Subject: [PATCH 01/19] ... --- .../examples/snapshot_test_outputs.rs | 8 ++++---- .../iota-genesis-builder/src/stardust/test_outputs/mod.rs | 7 ++----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/crates/iota-genesis-builder/examples/snapshot_test_outputs.rs b/crates/iota-genesis-builder/examples/snapshot_test_outputs.rs index 2a0ef37afba..b1d0a13e839 100644 --- a/crates/iota-genesis-builder/examples/snapshot_test_outputs.rs +++ b/crates/iota-genesis-builder/examples/snapshot_test_outputs.rs @@ -9,7 +9,7 @@ use iota_genesis_builder::stardust::{ parse::FullSnapshotParser, test_outputs::add_snapshot_test_outputs, }; -fn parse_snapshot>(path: P) -> anyhow::Result<()> { +fn parse_snapshot(path: impl AsRef) -> anyhow::Result<()> { let file = File::open(path)?; let parser = FullSnapshotParser::new(file)?; @@ -31,11 +31,11 @@ fn main() -> anyhow::Result<()> { let Some(current_path) = std::env::args().nth(1) else { anyhow::bail!("please provide path to the full-snapshot file"); }; - let mut new_path = String::from("test-"); - new_path.push_str(¤t_path); - parse_snapshot(¤t_path)?; + let new_path = format!("test-{current_path}"); + println!("{new_path}"); + add_snapshot_test_outputs(¤t_path, &new_path)?; parse_snapshot(&new_path)?; diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs index ee459700249..f9e700d49a4 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs @@ -23,11 +23,8 @@ pub fn add_snapshot_test_outputs + core::fmt::Debug>( new_path: P, ) -> anyhow::Result<()> { let current_file = File::open(current_path)?; - let new_file = OpenOptions::new() - .write(true) - .create(true) - .truncate(true) - .open(new_path)?; + let new_file = File::create(new_path)?; + let mut writer = IoPacker::new(BufWriter::new(new_file)); let mut parser = FullSnapshotParser::new(current_file)?; From 9a1b4a42626d6103c07d94ef4e2235c8b8367bda Mon Sep 17 00:00:00 2001 From: /alex/ Date: Mon, 24 Jun 2024 10:14:27 +0200 Subject: [PATCH 02/19] add owned test outputs --- .../stardust/test_outputs/alias_ownership.rs | 96 +++++++++++++++++++ .../src/stardust/test_outputs/mod.rs | 19 ++-- 2 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs new file mode 100644 index 00000000000..816c6bb9aa8 --- /dev/null +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs @@ -0,0 +1,96 @@ +// Copyright (c) 2024 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +use iota_sdk::types::block::{ + address::{AliasAddress, Ed25519Address}, + output::{ + feature::{Irc27Metadata, IssuerFeature, MetadataFeature}, + unlock_condition::{AddressUnlockCondition, ImmutableAliasAddressUnlockCondition}, + AliasId, AliasOutputBuilder, BasicOutputBuilder, Feature, FoundryOutputBuilder, NftId, + NftOutputBuilder, Output, SimpleTokenScheme, UnlockCondition, + }, +}; + +use crate::stardust::{test_outputs::random_output_header, types::output_header::OutputHeader}; + +pub(crate) fn outputs() -> Vec<(OutputHeader, Output)> { + let alias_output_header = random_output_header(); + let alias_owner = Ed25519Address::from(rand::random::<[u8; Ed25519Address::LENGTH]>()); + + let alias_output = AliasOutputBuilder::new_with_amount(1_000_000, AliasId::new(rand::random())) + .add_unlock_condition(AddressUnlockCondition::new(alias_owner)) + .finish() + .unwrap(); + let alias_address = alias_output.alias_address(&alias_output_header.output_id()); + + let mut outputs = Vec::new(); + + outputs.push((alias_output_header, Output::from(alias_output))); + outputs.push(owns_random_basic_output(alias_address)); + outputs.push(owns_random_nft_output(alias_address)); + outputs.push(owns_random_alias_output(alias_address)); + outputs.push(owns_random_foundry_output(alias_address)); + outputs +} + +fn owns_random_basic_output(owner: AliasAddress) -> (OutputHeader, Output) { + let basic_output_header = random_output_header(); + + let basic_output = BasicOutputBuilder::new_with_amount(1_000_000) + .add_unlock_condition(AddressUnlockCondition::new(owner)) + .finish() + .unwrap(); + + (basic_output_header, Output::from(basic_output)) +} + +fn owns_random_nft_output(owner: AliasAddress) -> (OutputHeader, Output) { + let nft_output_header = random_output_header(); + let nft_metadata = Irc27Metadata::new( + "image/png", + "https://nft.org/nft.png".parse().unwrap(), + "NFT", + ) + .with_issuer_name("issuer_name") + .with_collection_name("collection_name") + .with_description("description"); + + let nft_output = NftOutputBuilder::new_with_amount(1_000_000, NftId::new(rand::random())) + .add_unlock_condition(AddressUnlockCondition::new(owner)) + .with_immutable_features(vec![ + Feature::Metadata( + MetadataFeature::new(serde_json::to_vec(&nft_metadata).unwrap()).unwrap(), + ), + Feature::Issuer(IssuerFeature::new(owner)), + ]) + .finish() + .unwrap(); + + (nft_output_header, Output::from(nft_output)) +} + +fn owns_random_alias_output(owner: AliasAddress) -> (OutputHeader, Output) { + let alias_output_header = random_output_header(); + + let alias_output = AliasOutputBuilder::new_with_amount(1_000_000, AliasId::null()) + .add_unlock_condition(AddressUnlockCondition::new(owner)) + .finish() + .unwrap(); + + (alias_output_header, Output::from(alias_output)) +} + +fn owns_random_foundry_output(owner: AliasAddress) -> (OutputHeader, Output) { + let foundry_output_header = random_output_header(); + + let supply = 1_000_000; + let token_scheme = SimpleTokenScheme::new(supply, 0, supply).unwrap(); + let foundry_output = FoundryOutputBuilder::new_with_amount(1_000_000, 1, token_scheme.into()) + .with_unlock_conditions([UnlockCondition::from( + ImmutableAliasAddressUnlockCondition::new(owner), + )]) + .finish_with_params(supply) + .unwrap(); + + (foundry_output_header, Output::from(foundry_output)) +} diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs index f9e700d49a4..7457e9fd7c9 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs @@ -1,13 +1,10 @@ // Copyright (c) 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +mod alias_ownership; mod dummy; -use std::{ - fs::{File, OpenOptions}, - io::BufWriter, - path::Path, -}; +use std::{fs::File, io::BufWriter, path::Path}; use iota_sdk::types::block::{ payload::milestone::{MilestoneOption, ParametersMilestoneOption}, @@ -15,7 +12,7 @@ use iota_sdk::types::block::{ }; use packable::{packer::IoPacker, Packable, PackableExt}; -use crate::stardust::parse::FullSnapshotParser; +use crate::stardust::{parse::FullSnapshotParser, types::output_header::OutputHeader}; /// Adds outputs to test specific and intricate scenario in the full snapshot. pub fn add_snapshot_test_outputs + core::fmt::Debug>( @@ -69,3 +66,13 @@ pub fn add_snapshot_test_outputs + core::fmt::Debug>( Ok(()) } + +// TODO: find a good place for it so we can use it here and in migration/tests +pub(crate) fn random_output_header() -> OutputHeader { + OutputHeader::new_testing( + rand::random(), + rand::random(), + rand::random(), + rand::random(), + ) +} From 64acc223d00b76fa1ad2c38f871466d762d4cdcf Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Thu, 27 Jun 2024 15:29:33 +0200 Subject: [PATCH 03/19] add test outputs owned by alias --- crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs index 87e59a3b5f2..b713d04f027 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs @@ -73,6 +73,7 @@ pub async fn add_snapshot_test_outputs + core::fmt::Debug>( let new_outputs = [ vesting_schedule_entity::outputs(&mut vested_index).await?, vesting_schedule_iota_airdrop::outputs(&mut vested_index).await?, + alias_ownership::outputs(), ] .concat(); let new_amount = new_outputs.iter().map(|o| o.1.amount()).sum::(); From 087547625975e72f5342478241454ca7f8635adb Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Thu, 27 Jun 2024 20:16:56 +0200 Subject: [PATCH 04/19] fix alias unlock --- .../src/stardust/test_outputs/alias_ownership.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs index 816c6bb9aa8..0ff063acce0 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs @@ -5,7 +5,10 @@ use iota_sdk::types::block::{ address::{AliasAddress, Ed25519Address}, output::{ feature::{Irc27Metadata, IssuerFeature, MetadataFeature}, - unlock_condition::{AddressUnlockCondition, ImmutableAliasAddressUnlockCondition}, + unlock_condition::{ + AddressUnlockCondition, GovernorAddressUnlockCondition, + ImmutableAliasAddressUnlockCondition, + }, AliasId, AliasOutputBuilder, BasicOutputBuilder, Feature, FoundryOutputBuilder, NftId, NftOutputBuilder, Output, SimpleTokenScheme, UnlockCondition, }, @@ -18,7 +21,7 @@ pub(crate) fn outputs() -> Vec<(OutputHeader, Output)> { let alias_owner = Ed25519Address::from(rand::random::<[u8; Ed25519Address::LENGTH]>()); let alias_output = AliasOutputBuilder::new_with_amount(1_000_000, AliasId::new(rand::random())) - .add_unlock_condition(AddressUnlockCondition::new(alias_owner)) + .add_unlock_condition(GovernorAddressUnlockCondition::new(alias_owner)) .finish() .unwrap(); let alias_address = alias_output.alias_address(&alias_output_header.output_id()); @@ -73,7 +76,7 @@ fn owns_random_alias_output(owner: AliasAddress) -> (OutputHeader, Output) { let alias_output_header = random_output_header(); let alias_output = AliasOutputBuilder::new_with_amount(1_000_000, AliasId::null()) - .add_unlock_condition(AddressUnlockCondition::new(owner)) + .add_unlock_condition(GovernorAddressUnlockCondition::new(owner)) .finish() .unwrap(); From bcec772aba43d0a098aa793664d4c72d377cf2e4 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Fri, 28 Jun 2024 11:17:05 +0200 Subject: [PATCH 05/19] randomized ownership dependency tree --- .../stardust/test_outputs/alias_ownership.rs | 102 +++++++++++++----- 1 file changed, 76 insertions(+), 26 deletions(-) diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs index 0ff063acce0..8b98ca050d4 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs @@ -1,42 +1,91 @@ // Copyright (c) 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +use std::collections::VecDeque; + use iota_sdk::types::block::{ - address::{AliasAddress, Ed25519Address}, + address::{Address, AliasAddress, Ed25519Address}, output::{ feature::{Irc27Metadata, IssuerFeature, MetadataFeature}, unlock_condition::{ AddressUnlockCondition, GovernorAddressUnlockCondition, ImmutableAliasAddressUnlockCondition, }, - AliasId, AliasOutputBuilder, BasicOutputBuilder, Feature, FoundryOutputBuilder, NftId, - NftOutputBuilder, Output, SimpleTokenScheme, UnlockCondition, + AliasId, AliasOutput, AliasOutputBuilder, BasicOutput, BasicOutputBuilder, Feature, + FoundryOutput, FoundryOutputBuilder, NftId, NftOutput, NftOutputBuilder, Output, + SimpleTokenScheme, UnlockCondition, }, }; +use rand::{rngs::StdRng, Rng, SeedableRng}; use crate::stardust::{test_outputs::random_output_header, types::output_header::OutputHeader}; pub(crate) fn outputs() -> Vec<(OutputHeader, Output)> { - let alias_output_header = random_output_header(); - let alias_owner = Ed25519Address::from(rand::random::<[u8; Ed25519Address::LENGTH]>()); - - let alias_output = AliasOutputBuilder::new_with_amount(1_000_000, AliasId::new(rand::random())) - .add_unlock_condition(GovernorAddressUnlockCondition::new(alias_owner)) - .finish() - .unwrap(); - let alias_address = alias_output.alias_address(&alias_output_header.output_id()); - let mut outputs = Vec::new(); - outputs.push((alias_output_header, Output::from(alias_output))); - outputs.push(owns_random_basic_output(alias_address)); - outputs.push(owns_random_nft_output(alias_address)); - outputs.push(owns_random_alias_output(alias_address)); - outputs.push(owns_random_foundry_output(alias_address)); + // create a randomized ownership dependency tree + let randomness_seed = rand::random(); + let mut rng = StdRng::seed_from_u64(randomness_seed); + println!("alias ownership randomness seed: {randomness_seed}"); + + // create 10 different alias outputs with each owning various other assets + for _ in 0..10 { + let alias_output_header = random_output_header(); + let alias_owner = Ed25519Address::from(rand::random::<[u8; Ed25519Address::LENGTH]>()); + let alias_output = + AliasOutputBuilder::new_with_amount(1_000_000, AliasId::new(rand::random())) + .add_unlock_condition(GovernorAddressUnlockCondition::new(alias_owner)) + .finish() + .unwrap(); + let alias_address = alias_output.alias_address(&alias_output_header.output_id()); + + // let this alias own various other assets, that may themselves own other assets + let max_depth = rng.gen_range(1usize..5); + let mut n = 0; + let mut owning_addresses: VecDeque
= vec![alias_address.into()].into(); + + while let Some(owner) = owning_addresses.pop_front() { + // let each alias or nft own some variable amount of other outputs + let owned_assets_count = rng.gen_range(1usize..=5); + + for _ in 0..owned_assets_count { + match rng.gen_range(0u8..=3) { + 0 /* alias */ => { + let (output_header, output) = random_alias_output(owner); + owning_addresses + .push_back(output.alias_address(&output_header.output_id()).into()); + outputs.push((output_header, output.into())); + } + 1 /* nft */ => { + let (output_header, output) = random_nft_output(owner); + owning_addresses + .push_back(output.nft_address(&output_header.output_id()).into()); + outputs.push((output_header, output.into())); + } + 2 /* basic */ => { + let (output_header, output) = random_basic_output(owner); + outputs.push((output_header, output.into())); + } + 3 /* foundry */=> { + if let Address::Alias(owner) = owner { + let (output_header, output) = random_foundry_output(owner); + outputs.push((output_header, output.into())); + } + } + _ => unreachable!(), + } + } + if n < max_depth { + n += 1; + } else { + break; + } + } + } outputs } -fn owns_random_basic_output(owner: AliasAddress) -> (OutputHeader, Output) { +fn random_basic_output(owner: impl Into
) -> (OutputHeader, BasicOutput) { let basic_output_header = random_output_header(); let basic_output = BasicOutputBuilder::new_with_amount(1_000_000) @@ -44,10 +93,11 @@ fn owns_random_basic_output(owner: AliasAddress) -> (OutputHeader, Output) { .finish() .unwrap(); - (basic_output_header, Output::from(basic_output)) + (basic_output_header, basic_output) } -fn owns_random_nft_output(owner: AliasAddress) -> (OutputHeader, Output) { +fn random_nft_output(owner: impl Into
) -> (OutputHeader, NftOutput) { + let owner = owner.into(); let nft_output_header = random_output_header(); let nft_metadata = Irc27Metadata::new( "image/png", @@ -59,7 +109,7 @@ fn owns_random_nft_output(owner: AliasAddress) -> (OutputHeader, Output) { .with_description("description"); let nft_output = NftOutputBuilder::new_with_amount(1_000_000, NftId::new(rand::random())) - .add_unlock_condition(AddressUnlockCondition::new(owner)) + .add_unlock_condition(AddressUnlockCondition::new(owner.clone())) .with_immutable_features(vec![ Feature::Metadata( MetadataFeature::new(serde_json::to_vec(&nft_metadata).unwrap()).unwrap(), @@ -69,10 +119,10 @@ fn owns_random_nft_output(owner: AliasAddress) -> (OutputHeader, Output) { .finish() .unwrap(); - (nft_output_header, Output::from(nft_output)) + (nft_output_header, nft_output) } -fn owns_random_alias_output(owner: AliasAddress) -> (OutputHeader, Output) { +fn random_alias_output(owner: impl Into
) -> (OutputHeader, AliasOutput) { let alias_output_header = random_output_header(); let alias_output = AliasOutputBuilder::new_with_amount(1_000_000, AliasId::null()) @@ -80,10 +130,10 @@ fn owns_random_alias_output(owner: AliasAddress) -> (OutputHeader, Output) { .finish() .unwrap(); - (alias_output_header, Output::from(alias_output)) + (alias_output_header, alias_output) } -fn owns_random_foundry_output(owner: AliasAddress) -> (OutputHeader, Output) { +fn random_foundry_output(owner: impl Into) -> (OutputHeader, FoundryOutput) { let foundry_output_header = random_output_header(); let supply = 1_000_000; @@ -95,5 +145,5 @@ fn owns_random_foundry_output(owner: AliasAddress) -> (OutputHeader, Output) { .finish_with_params(supply) .unwrap(); - (foundry_output_header, Output::from(foundry_output)) + (foundry_output_header, foundry_output) } From 10ddbef86ffc256596a8a2e80b1432d627c547e0 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Fri, 28 Jun 2024 11:28:41 +0200 Subject: [PATCH 06/19] clean up --- .../src/stardust/test_outputs/alias_ownership.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs index 8b98ca050d4..1186fd043eb 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs @@ -45,10 +45,9 @@ pub(crate) fn outputs() -> Vec<(OutputHeader, Output)> { let mut owning_addresses: VecDeque
= vec![alias_address.into()].into(); while let Some(owner) = owning_addresses.pop_front() { - // let each alias or nft own some variable amount of other outputs - let owned_assets_count = rng.gen_range(1usize..=5); - - for _ in 0..owned_assets_count { + // randomly choose the number of owned assets + for _ in 0..rng.gen_range(1usize..=5) { + // randomly choose the type of asset match rng.gen_range(0u8..=3) { 0 /* alias */ => { let (output_header, output) = random_alias_output(owner); From 3918c843d4a093513ce05c0419a182ac1b3282b4 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Mon, 1 Jul 2024 14:51:33 +0200 Subject: [PATCH 07/19] fix algo --- .../stardust/test_outputs/alias_ownership.rs | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs index 1186fd043eb..0be5ba52df6 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs @@ -41,44 +41,41 @@ pub(crate) fn outputs() -> Vec<(OutputHeader, Output)> { // let this alias own various other assets, that may themselves own other assets let max_depth = rng.gen_range(1usize..5); - let mut n = 0; - let mut owning_addresses: VecDeque
= vec![alias_address.into()].into(); + let mut owning_addresses: VecDeque<(usize, Address)> = + vec![(0, alias_address.into())].into(); - while let Some(owner) = owning_addresses.pop_front() { - // randomly choose the number of owned assets + while let Some((depth, owning_addr)) = owning_addresses.pop_front() { + if depth > max_depth { + continue; + } + // create a random number of random assets for _ in 0..rng.gen_range(1usize..=5) { - // randomly choose the type of asset match rng.gen_range(0u8..=3) { 0 /* alias */ => { - let (output_header, output) = random_alias_output(owner); + let (output_header, alias) = random_alias_output(owning_addr); owning_addresses - .push_back(output.alias_address(&output_header.output_id()).into()); - outputs.push((output_header, output.into())); + .push_back((depth + 1, alias.alias_address(&output_header.output_id()).into())); + outputs.push((output_header, alias.into())); } 1 /* nft */ => { - let (output_header, output) = random_nft_output(owner); + let (output_header, nft) = random_nft_output(owning_addr); owning_addresses - .push_back(output.nft_address(&output_header.output_id()).into()); - outputs.push((output_header, output.into())); + .push_back((depth + 1, nft.nft_address(&output_header.output_id()).into())); + outputs.push((output_header, nft.into())); } 2 /* basic */ => { - let (output_header, output) = random_basic_output(owner); - outputs.push((output_header, output.into())); + let (output_header, basic) = random_basic_output(owning_addr); + outputs.push((output_header, basic.into())); } 3 /* foundry */=> { - if let Address::Alias(owner) = owner { - let (output_header, output) = random_foundry_output(owner); - outputs.push((output_header, output.into())); + if let Address::Alias(child) = owning_addr { + let (output_header, foundry) = random_foundry_output(child); + outputs.push((output_header, foundry.into())); } } _ => unreachable!(), } } - if n < max_depth { - n += 1; - } else { - break; - } } } outputs From d1973e7b441393c2486b53116417ff7b6891bb4b Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Mon, 8 Jul 2024 09:57:20 +0200 Subject: [PATCH 08/19] fix format --- .../stardust/test_outputs/alias_ownership.rs | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs index 0be5ba52df6..80764a276cd 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs @@ -48,28 +48,38 @@ pub(crate) fn outputs() -> Vec<(OutputHeader, Output)> { if depth > max_depth { continue; } + let mut serial_number = 1; // create a random number of random assets - for _ in 0..rng.gen_range(1usize..=5) { - match rng.gen_range(0u8..=3) { - 0 /* alias */ => { - let (output_header, alias) = random_alias_output(owning_addr); - owning_addresses - .push_back((depth + 1, alias.alias_address(&output_header.output_id()).into())); + for _ in 0usize..rng.gen_range(1..=5) { + match rng.gen_range(0..=3) { + 0 => { + // alias + let (output_header, alias) = random_alias_output(&mut rng, owning_addr); + owning_addresses.push_back(( + depth + 1, + alias.alias_address(&output_header.output_id()).into(), + )); outputs.push((output_header, alias.into())); } - 1 /* nft */ => { - let (output_header, nft) = random_nft_output(owning_addr); - owning_addresses - .push_back((depth + 1, nft.nft_address(&output_header.output_id()).into())); + 1 => { + // nft + let (output_header, nft) = random_nft_output(&mut rng, owning_addr); + owning_addresses.push_back(( + depth + 1, + nft.nft_address(&output_header.output_id()).into(), + )); outputs.push((output_header, nft.into())); } - 2 /* basic */ => { - let (output_header, basic) = random_basic_output(owning_addr); + 2 => { + // basic + let (output_header, basic) = random_basic_output(&mut rng, owning_addr); outputs.push((output_header, basic.into())); } - 3 /* foundry */=> { - if let Address::Alias(child) = owning_addr { - let (output_header, foundry) = random_foundry_output(child); + 3 => { + // foundry + if let Address::Alias(owning_addr) = owning_addr { + let (output_header, foundry) = + random_foundry_output(&mut rng, &mut serial_number, owning_addr); outputs.push((output_header, foundry.into())); } } From a5638e66d417cd29961cdab9e5f31e36c4b53978 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Mon, 8 Jul 2024 09:58:29 +0200 Subject: [PATCH 09/19] state controller uc --- .../src/stardust/parse.rs | 2 +- .../stardust/test_outputs/alias_ownership.rs | 26 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/crates/iota-genesis-builder/src/stardust/parse.rs b/crates/iota-genesis-builder/src/stardust/parse.rs index fac8dab5d86..92bb7b9443e 100644 --- a/crates/iota-genesis-builder/src/stardust/parse.rs +++ b/crates/iota-genesis-builder/src/stardust/parse.rs @@ -27,7 +27,7 @@ impl HornetGenesisSnapshotParser { pub fn new(reader: R) -> Result { let mut reader = IoUnpacker::new(std::io::BufReader::new(reader)); // `true` ensures that only genesis snapshots unpack successfully - let header = FullSnapshotHeader::unpack::<_, true>(&mut reader, &())?; + let header = FullSnapshotHeader::unpack::<_, false>(&mut reader, &())?; Ok(Self { reader, header }) } diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs index 80764a276cd..8699467ee3b 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs @@ -9,7 +9,7 @@ use iota_sdk::types::block::{ feature::{Irc27Metadata, IssuerFeature, MetadataFeature}, unlock_condition::{ AddressUnlockCondition, GovernorAddressUnlockCondition, - ImmutableAliasAddressUnlockCondition, + ImmutableAliasAddressUnlockCondition, StateControllerAddressUnlockCondition, }, AliasId, AliasOutput, AliasOutputBuilder, BasicOutput, BasicOutputBuilder, Feature, FoundryOutput, FoundryOutputBuilder, NftId, NftOutput, NftOutputBuilder, Output, @@ -30,13 +30,13 @@ pub(crate) fn outputs() -> Vec<(OutputHeader, Output)> { // create 10 different alias outputs with each owning various other assets for _ in 0..10 { - let alias_output_header = random_output_header(); - let alias_owner = Ed25519Address::from(rand::random::<[u8; Ed25519Address::LENGTH]>()); - let alias_output = - AliasOutputBuilder::new_with_amount(1_000_000, AliasId::new(rand::random())) - .add_unlock_condition(GovernorAddressUnlockCondition::new(alias_owner)) - .finish() - .unwrap(); + let alias_output_header = random_output_header(&mut rng); + let alias_owner = Ed25519Address::from(rng.gen::<[u8; Ed25519Address::LENGTH]>()); + let alias_output = AliasOutputBuilder::new_with_amount(1_000_000, AliasId::new(rng.gen())) + .add_unlock_condition(GovernorAddressUnlockCondition::new(alias_owner)) + .add_unlock_condition(StateControllerAddressUnlockCondition::new(alias_owner)) + .finish() + .unwrap(); let alias_address = alias_output.alias_address(&alias_output_header.output_id()); // let this alias own various other assets, that may themselves own other assets @@ -128,11 +128,13 @@ fn random_nft_output(owner: impl Into
) -> (OutputHeader, NftOutput) { (nft_output_header, nft_output) } -fn random_alias_output(owner: impl Into
) -> (OutputHeader, AliasOutput) { - let alias_output_header = random_output_header(); +fn random_alias_output(rng: &mut StdRng, owner: impl Into
) -> (OutputHeader, AliasOutput) { + let owner = owner.into(); + let alias_output_header = random_output_header(rng); - let alias_output = AliasOutputBuilder::new_with_amount(1_000_000, AliasId::null()) - .add_unlock_condition(GovernorAddressUnlockCondition::new(owner)) + let alias_output = AliasOutputBuilder::new_with_amount(1_000_000, AliasId::new(rng.gen())) + .add_unlock_condition(GovernorAddressUnlockCondition::new(owner.clone())) + .add_unlock_condition(StateControllerAddressUnlockCondition::new(owner)) .finish() .unwrap(); From 4973f3ad8a2e16f638dc0b4abf32a3c1a0caf55a Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Mon, 8 Jul 2024 09:59:33 +0200 Subject: [PATCH 10/19] generate actual addresses --- .../stardust/test_outputs/alias_ownership.rs | 84 +++++++++++++------ .../src/stardust/test_outputs/mod.rs | 2 +- 2 files changed, 60 insertions(+), 26 deletions(-) diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs index 8699467ee3b..a82080a40dc 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs @@ -3,35 +3,51 @@ use std::collections::VecDeque; -use iota_sdk::types::block::{ - address::{Address, AliasAddress, Ed25519Address}, - output::{ - feature::{Irc27Metadata, IssuerFeature, MetadataFeature}, - unlock_condition::{ - AddressUnlockCondition, GovernorAddressUnlockCondition, - ImmutableAliasAddressUnlockCondition, StateControllerAddressUnlockCondition, +use iota_sdk::{ + client::secret::{mnemonic::MnemonicSecretManager, SecretManage}, + types::block::{ + address::{Address, AliasAddress}, + output::{ + feature::{Irc27Metadata, IssuerFeature, MetadataFeature}, + unlock_condition::{ + AddressUnlockCondition, GovernorAddressUnlockCondition, + ImmutableAliasAddressUnlockCondition, StateControllerAddressUnlockCondition, + }, + AliasId, AliasOutput, AliasOutputBuilder, BasicOutput, BasicOutputBuilder, Feature, + FoundryOutput, FoundryOutputBuilder, NftId, NftOutput, NftOutputBuilder, Output, + SimpleTokenScheme, UnlockCondition, OUTPUT_INDEX_RANGE, }, - AliasId, AliasOutput, AliasOutputBuilder, BasicOutput, BasicOutputBuilder, Feature, - FoundryOutput, FoundryOutputBuilder, NftId, NftOutput, NftOutputBuilder, Output, - SimpleTokenScheme, UnlockCondition, }, }; use rand::{rngs::StdRng, Rng, SeedableRng}; -use crate::stardust::{test_outputs::random_output_header, types::output_header::OutputHeader}; +use crate::stardust::{ + test_outputs::{MERGE_MILESTONE_INDEX, MERGE_TIMESTAMP_SECS}, + types::{output_header::OutputHeader, output_index::OutputIndex}, +}; + +// TODO: use different one +const MNEMONIC: &str = "giant dynamic museum toddler six deny defense ostrich bomb access mercy blood explain muscle shoot shallow glad autumn author calm heavy hawk abuse rally"; +const COIN_TYPE: u32 = 4218; +const OWNING_ALIAS_COUNT: u32 = 10; -pub(crate) fn outputs() -> Vec<(OutputHeader, Output)> { +pub(crate) async fn outputs() -> anyhow::Result> { let mut outputs = Vec::new(); + let secret_manager = MnemonicSecretManager::try_from_mnemonic(MNEMONIC)?; // create a randomized ownership dependency tree let randomness_seed = rand::random(); let mut rng = StdRng::seed_from_u64(randomness_seed); println!("alias ownership randomness seed: {randomness_seed}"); + let alias_owners = secret_manager + .generate_ed25519_addresses(COIN_TYPE, 0, 0..OWNING_ALIAS_COUNT, None) + .await?; + // create 10 different alias outputs with each owning various other assets - for _ in 0..10 { + for alias_owner in alias_owners { let alias_output_header = random_output_header(&mut rng); - let alias_owner = Ed25519Address::from(rng.gen::<[u8; Ed25519Address::LENGTH]>()); + let alias_output = AliasOutputBuilder::new_with_amount(1_000_000, AliasId::new(rng.gen())) .add_unlock_condition(GovernorAddressUnlockCondition::new(alias_owner)) .add_unlock_condition(StateControllerAddressUnlockCondition::new(alias_owner)) @@ -88,13 +104,14 @@ pub(crate) fn outputs() -> Vec<(OutputHeader, Output)> { } } } - outputs + Ok(outputs) } fn random_basic_output(owner: impl Into
) -> (OutputHeader, BasicOutput) { let basic_output_header = random_output_header(); - let basic_output = BasicOutputBuilder::new_with_amount(1_000_000) + let amount = rng.gen_range(1_000_000..10_000_000); + let basic_output = BasicOutputBuilder::new_with_amount(amount) .add_unlock_condition(AddressUnlockCondition::new(owner)) .finish() .unwrap(); @@ -114,7 +131,8 @@ fn random_nft_output(owner: impl Into
) -> (OutputHeader, NftOutput) { .with_collection_name("collection_name") .with_description("description"); - let nft_output = NftOutputBuilder::new_with_amount(1_000_000, NftId::new(rand::random())) + let amount = rng.gen_range(1_000_000..10_000_000); + let nft_output = NftOutputBuilder::new_with_amount(amount, NftId::new(rng.gen())) .add_unlock_condition(AddressUnlockCondition::new(owner.clone())) .with_immutable_features(vec![ Feature::Metadata( @@ -132,7 +150,8 @@ fn random_alias_output(rng: &mut StdRng, owner: impl Into
) -> (OutputHe let owner = owner.into(); let alias_output_header = random_output_header(rng); - let alias_output = AliasOutputBuilder::new_with_amount(1_000_000, AliasId::new(rng.gen())) + let amount = rng.gen_range(1_000_000..10_000_000); + let alias_output = AliasOutputBuilder::new_with_amount(amount, AliasId::new(rng.gen())) .add_unlock_condition(GovernorAddressUnlockCondition::new(owner.clone())) .add_unlock_condition(StateControllerAddressUnlockCondition::new(owner)) .finish() @@ -144,14 +163,29 @@ fn random_alias_output(rng: &mut StdRng, owner: impl Into
) -> (OutputHe fn random_foundry_output(owner: impl Into) -> (OutputHeader, FoundryOutput) { let foundry_output_header = random_output_header(); - let supply = 1_000_000; + let amount = rng.gen_range(1_000_000..10_000_000); + let supply = rng.gen_range(1_000_000..100_000_000); let token_scheme = SimpleTokenScheme::new(supply, 0, supply).unwrap(); - let foundry_output = FoundryOutputBuilder::new_with_amount(1_000_000, 1, token_scheme.into()) - .with_unlock_conditions([UnlockCondition::from( - ImmutableAliasAddressUnlockCondition::new(owner), - )]) - .finish_with_params(supply) - .unwrap(); + let foundry_output = + FoundryOutputBuilder::new_with_amount(amount, *serial_number, token_scheme.into()) + .with_unlock_conditions([UnlockCondition::from( + ImmutableAliasAddressUnlockCondition::new(owner), + )]) + .finish_with_params(supply) + .unwrap(); + + *serial_number += 1; (foundry_output_header, foundry_output) } + +fn random_output_header(rng: &mut StdRng) -> OutputHeader { + OutputHeader::new_testing( + rng.gen(), + OutputIndex::new(rng.gen_range(OUTPUT_INDEX_RANGE)) + .expect("range is guaranteed to be valid"), + rng.gen(), + MERGE_MILESTONE_INDEX, + MERGE_TIMESTAMP_SECS, + ) +} diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs index 41c62a45acf..6409b014749 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs @@ -78,7 +78,7 @@ pub async fn add_snapshot_test_outputs + core::fmt::Debug>( stardust_mix::outputs(&mut vested_index).await?, vesting_schedule_entity::outputs(&mut vested_index).await?, vesting_schedule_iota_airdrop::outputs(&mut vested_index).await?, - alias_ownership::outputs(), + alias_ownership::outputs().await?, ] .concat(); let new_amount = new_outputs.iter().map(|o| o.1.amount()).sum::(); From 26152311d8f0a4af545ce31ecfcf13b794761ac7 Mon Sep 17 00:00:00 2001 From: /alex/ Date: Tue, 2 Jul 2024 13:37:19 +0200 Subject: [PATCH 11/19] change mnemonic Co-authored-by: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> --- .../src/stardust/test_outputs/alias_ownership.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs index a82080a40dc..c6214c6a82c 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs @@ -26,8 +26,7 @@ use crate::stardust::{ types::{output_header::OutputHeader, output_index::OutputIndex}, }; -// TODO: use different one -const MNEMONIC: &str = "giant dynamic museum toddler six deny defense ostrich bomb access mercy blood explain muscle shoot shallow glad autumn author calm heavy hawk abuse rally"; +const MNEMONIC: &str = "few hood high omit camp keep burger give happy iron evolve draft few dawn pulp jazz box dash load snake gown bag draft car"; const COIN_TYPE: u32 = 4218; const OWNING_ALIAS_COUNT: u32 = 10; From 7a8303ba6fe153b7b2aef264224fd3506eccf322 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Tue, 2 Jul 2024 17:11:36 +0200 Subject: [PATCH 12/19] min amount fix for foundries --- .../src/stardust/test_outputs/alias_ownership.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs index c6214c6a82c..5b3130346ba 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs @@ -162,8 +162,8 @@ fn random_alias_output(rng: &mut StdRng, owner: impl Into
) -> (OutputHe fn random_foundry_output(owner: impl Into) -> (OutputHeader, FoundryOutput) { let foundry_output_header = random_output_header(); - let amount = rng.gen_range(1_000_000..10_000_000); let supply = rng.gen_range(1_000_000..100_000_000); + let amount = rng.gen_range(1_000_000..10_000_000).min(supply); let token_scheme = SimpleTokenScheme::new(supply, 0, supply).unwrap(); let foundry_output = FoundryOutputBuilder::new_with_amount(amount, *serial_number, token_scheme.into()) From 9bb2d50c8af272aac0a1fa05cdfa5b21e8052338 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Tue, 2 Jul 2024 19:56:38 +0200 Subject: [PATCH 13/19] rm supply check --- .../src/stardust/migration/tests/executor.rs | 2 +- .../src/stardust/test_outputs/alias_ownership.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/iota-genesis-builder/src/stardust/migration/tests/executor.rs b/crates/iota-genesis-builder/src/stardust/migration/tests/executor.rs index a5eb345425f..ebf913a48e7 100644 --- a/crates/iota-genesis-builder/src/stardust/migration/tests/executor.rs +++ b/crates/iota-genesis-builder/src/stardust/migration/tests/executor.rs @@ -38,7 +38,7 @@ fn create_bag_with_pt() { .with_unlock_conditions([UnlockCondition::from( ImmutableAliasAddressUnlockCondition::new(owner), )]) - .finish_with_params(supply) + .finish() .unwrap(); let foundry_id = foundry.id(); let foundry_package_data = NativeTokenPackageData::new( diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs index 5b3130346ba..87caed30482 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs @@ -162,15 +162,15 @@ fn random_alias_output(rng: &mut StdRng, owner: impl Into
) -> (OutputHe fn random_foundry_output(owner: impl Into) -> (OutputHeader, FoundryOutput) { let foundry_output_header = random_output_header(); + let amount = rng.gen_range(1_000_000..10_000_000); let supply = rng.gen_range(1_000_000..100_000_000); - let amount = rng.gen_range(1_000_000..10_000_000).min(supply); let token_scheme = SimpleTokenScheme::new(supply, 0, supply).unwrap(); let foundry_output = FoundryOutputBuilder::new_with_amount(amount, *serial_number, token_scheme.into()) .with_unlock_conditions([UnlockCondition::from( ImmutableAliasAddressUnlockCondition::new(owner), )]) - .finish_with_params(supply) + .finish() .unwrap(); *serial_number += 1; From 7ae679f0e2e930f6e2ec43dcd8d592fa82d4bb35 Mon Sep 17 00:00:00 2001 From: /alex/ Date: Wed, 3 Jul 2024 11:20:46 +0200 Subject: [PATCH 14/19] align! Co-authored-by: Thibault Martinez --- .../src/stardust/test_outputs/alias_ownership.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs index 87caed30482..1177badd5fd 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs @@ -37,7 +37,7 @@ pub(crate) async fn outputs() -> anyhow::Result> { // create a randomized ownership dependency tree let randomness_seed = rand::random(); let mut rng = StdRng::seed_from_u64(randomness_seed); - println!("alias ownership randomness seed: {randomness_seed}"); + println!("alias_ownership randomness seed: {randomness_seed}"); let alias_owners = secret_manager .generate_ed25519_addresses(COIN_TYPE, 0, 0..OWNING_ALIAS_COUNT, None) From 32be6b9bafe249a05d0a3e5bd79b60f9d491024e Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 3 Jul 2024 15:15:27 +0200 Subject: [PATCH 15/19] review --- .../stardust/test_outputs/alias_ownership.rs | 21 ++++++++++--------- .../src/stardust/test_outputs/mod.rs | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs index 1177badd5fd..c9ad4b4af93 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs @@ -47,12 +47,15 @@ pub(crate) async fn outputs() -> anyhow::Result> { for alias_owner in alias_owners { let alias_output_header = random_output_header(&mut rng); - let alias_output = AliasOutputBuilder::new_with_amount(1_000_000, AliasId::new(rng.gen())) - .add_unlock_condition(GovernorAddressUnlockCondition::new(alias_owner)) - .add_unlock_condition(StateControllerAddressUnlockCondition::new(alias_owner)) - .finish() - .unwrap(); - let alias_address = alias_output.alias_address(&alias_output_header.output_id()); + let alias_output = AliasOutputBuilder::new_with_amount( + 1_000_000, + (&alias_output_header.output_id()).into(), + ) + .add_unlock_condition(GovernorAddressUnlockCondition::new(alias_owner)) + .add_unlock_condition(StateControllerAddressUnlockCondition::new(alias_owner)) + .finish() + .unwrap(); + let alias_address = AliasAddress::new(*alias_output.alias_id()); // let this alias own various other assets, that may themselves own other assets let max_depth = rng.gen_range(1usize..5); @@ -70,10 +73,8 @@ pub(crate) async fn outputs() -> anyhow::Result> { 0 => { // alias let (output_header, alias) = random_alias_output(&mut rng, owning_addr); - owning_addresses.push_back(( - depth + 1, - alias.alias_address(&output_header.output_id()).into(), - )); + owning_addresses + .push_back((depth + 1, AliasAddress::new(*alias.alias_id()).into())); outputs.push((output_header, alias.into())); } 1 => { diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs index 75492767b0f..a530daa9283 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs @@ -75,10 +75,10 @@ pub async fn add_snapshot_test_outputs + core::fmt::Debug, const let mut vested_index = u32::MAX; let new_outputs = [ + alias_ownership::outputs().await?, stardust_mix::outputs(&mut vested_index).await?, vesting_schedule_entity::outputs(&mut vested_index).await?, vesting_schedule_iota_airdrop::outputs(&mut vested_index).await?, - alias_ownership::outputs().await?, ] .concat(); let new_amount = new_outputs.iter().map(|o| o.1.amount()).sum::(); From d2170ceaa866955400e0aa614742ac28cb92cbce Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 3 Jul 2024 15:20:29 +0200 Subject: [PATCH 16/19] fix compile --- crates/iota-genesis-builder/examples/snapshot_test_outputs.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/iota-genesis-builder/examples/snapshot_test_outputs.rs b/crates/iota-genesis-builder/examples/snapshot_test_outputs.rs index c8150ae7079..e0c1cf07226 100644 --- a/crates/iota-genesis-builder/examples/snapshot_test_outputs.rs +++ b/crates/iota-genesis-builder/examples/snapshot_test_outputs.rs @@ -43,11 +43,11 @@ async fn main() -> anyhow::Result<()> { new_path.push_str(¤t_path); } - parse_snapshot::<_, true>(¤t_path)?; + parse_snapshot::(¤t_path)?; add_snapshot_test_outputs::<_, true>(¤t_path, &new_path).await?; - parse_snapshot::<_, true>(&new_path)?; + parse_snapshot::(&new_path)?; Ok(()) } From 6b352eed375941fc4c943731b0aa1214d81db34b Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 3 Jul 2024 15:38:00 +0200 Subject: [PATCH 17/19] disable global snapshot verification for test data --- .../iota-genesis-builder/examples/snapshot_test_outputs.rs | 6 +++--- .../iota-genesis-builder/src/stardust/test_outputs/mod.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/iota-genesis-builder/examples/snapshot_test_outputs.rs b/crates/iota-genesis-builder/examples/snapshot_test_outputs.rs index e0c1cf07226..6eb1de74775 100644 --- a/crates/iota-genesis-builder/examples/snapshot_test_outputs.rs +++ b/crates/iota-genesis-builder/examples/snapshot_test_outputs.rs @@ -43,11 +43,11 @@ async fn main() -> anyhow::Result<()> { new_path.push_str(¤t_path); } - parse_snapshot::(¤t_path)?; + parse_snapshot::(¤t_path)?; - add_snapshot_test_outputs::<_, true>(¤t_path, &new_path).await?; + add_snapshot_test_outputs::(¤t_path, &new_path).await?; - parse_snapshot::(&new_path)?; + parse_snapshot::(&new_path)?; Ok(()) } diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs index a530daa9283..13cc2138d68 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs @@ -61,9 +61,9 @@ pub(crate) fn new_vested_output( } /// Adds outputs to test specific and intricate scenario in the full snapshot. -pub async fn add_snapshot_test_outputs + core::fmt::Debug, const VERIFY: bool>( - current_path: P, - new_path: P, +pub async fn add_snapshot_test_outputs( + current_path: impl AsRef + core::fmt::Debug, + new_path: impl AsRef + core::fmt::Debug, ) -> anyhow::Result<()> { let current_file = File::open(current_path)?; let new_file = File::create(new_path)?; From 4b20ce0f5d483ab2d877dadd08f9ab045ffe6eee Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 3 Jul 2024 15:44:21 +0200 Subject: [PATCH 18/19] consistency --- .../src/stardust/test_outputs/alias_ownership.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs index c9ad4b4af93..1b748006174 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs @@ -6,7 +6,7 @@ use std::collections::VecDeque; use iota_sdk::{ client::secret::{mnemonic::MnemonicSecretManager, SecretManage}, types::block::{ - address::{Address, AliasAddress}, + address::{Address, AliasAddress, NftAddress}, output::{ feature::{Irc27Metadata, IssuerFeature, MetadataFeature}, unlock_condition::{ @@ -80,10 +80,8 @@ pub(crate) async fn outputs() -> anyhow::Result> { 1 => { // nft let (output_header, nft) = random_nft_output(&mut rng, owning_addr); - owning_addresses.push_back(( - depth + 1, - nft.nft_address(&output_header.output_id()).into(), - )); + owning_addresses + .push_back((depth + 1, NftAddress::new(*nft.nft_id()).into())); outputs.push((output_header, nft.into())); } 2 => { From 506210d0c8b8d29b25a0a51833bc6a50f3d5ac57 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Mon, 8 Jul 2024 10:01:08 +0200 Subject: [PATCH 19/19] bubble up --- .../stardust/test_outputs/alias_ownership.rs | 84 ++++++++++--------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs index 1b748006174..f31a4d8d25a 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs @@ -6,7 +6,7 @@ use std::collections::VecDeque; use iota_sdk::{ client::secret::{mnemonic::MnemonicSecretManager, SecretManage}, types::block::{ - address::{Address, AliasAddress, NftAddress}, + address::{Address, AliasAddress}, output::{ feature::{Irc27Metadata, IssuerFeature, MetadataFeature}, unlock_condition::{ @@ -53,8 +53,7 @@ pub(crate) async fn outputs() -> anyhow::Result> { ) .add_unlock_condition(GovernorAddressUnlockCondition::new(alias_owner)) .add_unlock_condition(StateControllerAddressUnlockCondition::new(alias_owner)) - .finish() - .unwrap(); + .finish()?; let alias_address = AliasAddress::new(*alias_output.alias_id()); // let this alias own various other assets, that may themselves own other assets @@ -72,28 +71,30 @@ pub(crate) async fn outputs() -> anyhow::Result> { match rng.gen_range(0..=3) { 0 => { // alias - let (output_header, alias) = random_alias_output(&mut rng, owning_addr); + let (output_header, alias) = random_alias_output(&mut rng, owning_addr)?; owning_addresses .push_back((depth + 1, AliasAddress::new(*alias.alias_id()).into())); outputs.push((output_header, alias.into())); } 1 => { // nft - let (output_header, nft) = random_nft_output(&mut rng, owning_addr); - owning_addresses - .push_back((depth + 1, NftAddress::new(*nft.nft_id()).into())); + let (output_header, nft) = random_nft_output(&mut rng, owning_addr)?; + owning_addresses.push_back(( + depth + 1, + nft.nft_address(&output_header.output_id()).into(), + )); outputs.push((output_header, nft.into())); } 2 => { // basic - let (output_header, basic) = random_basic_output(&mut rng, owning_addr); + let (output_header, basic) = random_basic_output(&mut rng, owning_addr)?; outputs.push((output_header, basic.into())); } 3 => { // foundry if let Address::Alias(owning_addr) = owning_addr { let (output_header, foundry) = - random_foundry_output(&mut rng, &mut serial_number, owning_addr); + random_foundry_output(&mut rng, &mut serial_number, owning_addr)?; outputs.push((output_header, foundry.into())); } } @@ -105,46 +106,47 @@ pub(crate) async fn outputs() -> anyhow::Result> { Ok(outputs) } -fn random_basic_output(owner: impl Into
) -> (OutputHeader, BasicOutput) { - let basic_output_header = random_output_header(); +fn random_basic_output( + rng: &mut StdRng, + owner: impl Into
, +) -> anyhow::Result<(OutputHeader, BasicOutput)> { + let basic_output_header = random_output_header(rng); let amount = rng.gen_range(1_000_000..10_000_000); let basic_output = BasicOutputBuilder::new_with_amount(amount) .add_unlock_condition(AddressUnlockCondition::new(owner)) - .finish() - .unwrap(); + .finish()?; - (basic_output_header, basic_output) + Ok((basic_output_header, basic_output)) } -fn random_nft_output(owner: impl Into
) -> (OutputHeader, NftOutput) { +fn random_nft_output( + rng: &mut StdRng, + owner: impl Into
, +) -> anyhow::Result<(OutputHeader, NftOutput)> { let owner = owner.into(); - let nft_output_header = random_output_header(); - let nft_metadata = Irc27Metadata::new( - "image/png", - "https://nft.org/nft.png".parse().unwrap(), - "NFT", - ) - .with_issuer_name("issuer_name") - .with_collection_name("collection_name") - .with_description("description"); + let nft_output_header = random_output_header(rng); + let nft_metadata = Irc27Metadata::new("image/png", "https://nft.org/nft.png".parse()?, "NFT") + .with_issuer_name("issuer_name") + .with_collection_name("collection_name") + .with_description("description"); let amount = rng.gen_range(1_000_000..10_000_000); let nft_output = NftOutputBuilder::new_with_amount(amount, NftId::new(rng.gen())) .add_unlock_condition(AddressUnlockCondition::new(owner.clone())) .with_immutable_features(vec![ - Feature::Metadata( - MetadataFeature::new(serde_json::to_vec(&nft_metadata).unwrap()).unwrap(), - ), + Feature::Metadata(MetadataFeature::new(serde_json::to_vec(&nft_metadata)?)?), Feature::Issuer(IssuerFeature::new(owner)), ]) - .finish() - .unwrap(); + .finish()?; - (nft_output_header, nft_output) + Ok((nft_output_header, nft_output)) } -fn random_alias_output(rng: &mut StdRng, owner: impl Into
) -> (OutputHeader, AliasOutput) { +fn random_alias_output( + rng: &mut StdRng, + owner: impl Into
, +) -> anyhow::Result<(OutputHeader, AliasOutput)> { let owner = owner.into(); let alias_output_header = random_output_header(rng); @@ -152,29 +154,31 @@ fn random_alias_output(rng: &mut StdRng, owner: impl Into
) -> (OutputHe let alias_output = AliasOutputBuilder::new_with_amount(amount, AliasId::new(rng.gen())) .add_unlock_condition(GovernorAddressUnlockCondition::new(owner.clone())) .add_unlock_condition(StateControllerAddressUnlockCondition::new(owner)) - .finish() - .unwrap(); + .finish()?; - (alias_output_header, alias_output) + Ok((alias_output_header, alias_output)) } -fn random_foundry_output(owner: impl Into) -> (OutputHeader, FoundryOutput) { - let foundry_output_header = random_output_header(); +fn random_foundry_output( + rng: &mut StdRng, + serial_number: &mut u32, + owner: impl Into, +) -> anyhow::Result<(OutputHeader, FoundryOutput)> { + let foundry_output_header = random_output_header(rng); let amount = rng.gen_range(1_000_000..10_000_000); let supply = rng.gen_range(1_000_000..100_000_000); - let token_scheme = SimpleTokenScheme::new(supply, 0, supply).unwrap(); + let token_scheme = SimpleTokenScheme::new(supply, 0, supply)?; let foundry_output = FoundryOutputBuilder::new_with_amount(amount, *serial_number, token_scheme.into()) .with_unlock_conditions([UnlockCondition::from( ImmutableAliasAddressUnlockCondition::new(owner), )]) - .finish() - .unwrap(); + .finish()?; *serial_number += 1; - (foundry_output_header, foundry_output) + Ok((foundry_output_header, foundry_output)) } fn random_output_header(rng: &mut StdRng) -> OutputHeader {