diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 5dbf5318efd..95030eecf89 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -472,7 +472,7 @@ enum TelemetryStartStatus { } fn genesis_account(public_key: PublicKey) -> Account { - Account::new(iroha_genesis::GENESIS_ACCOUNT_ID.clone(), [public_key]) + Account::new(iroha_genesis::GENESIS_ACCOUNT_ID.clone(), public_key) .build(&iroha_genesis::GENESIS_ACCOUNT_ID) } diff --git a/client/benches/torii.rs b/client/benches/torii.rs index 669fcc0c917..e9bb7f48008 100644 --- a/client/benches/torii.rs +++ b/client/benches/torii.rs @@ -64,7 +64,7 @@ fn query_requests(criterion: &mut Criterion) { let create_domain = Register::domain(Domain::new(domain_id.clone())); let account_id = AccountId::new(domain_id.clone(), "account".parse().expect("Valid")); let (public_key, _) = KeyPair::generate().into(); - let create_account = Register::account(Account::new(account_id.clone(), [public_key])); + let create_account = Register::account(Account::new(account_id.clone(), public_key)); let asset_definition_id = AssetDefinitionId::new(domain_id, "xor".parse().expect("Valid")); let create_asset = Register::asset_definition(AssetDefinition::quantity(asset_definition_id.clone())); @@ -164,7 +164,7 @@ fn instruction_submits(criterion: &mut Criterion) { let create_domain: InstructionBox = Register::domain(Domain::new(domain_id.clone())).into(); let account_id = AccountId::new(domain_id.clone(), "account".parse().expect("Valid")); let (public_key, _) = KeyPair::generate().into(); - let create_account = Register::account(Account::new(account_id.clone(), [public_key])).into(); + let create_account = Register::account(Account::new(account_id.clone(), public_key)).into(); let asset_definition_id = AssetDefinitionId::new(domain_id, "xor".parse().expect("Valid")); let client_config = iroha_client::samples::get_client_config( get_chain_id(), diff --git a/client/benches/tps/utils.rs b/client/benches/tps/utils.rs index f078481269b..6d417b2e9e4 100644 --- a/client/benches/tps/utils.rs +++ b/client/benches/tps/utils.rs @@ -158,8 +158,7 @@ impl MeasurerUnit { let account_id = account_id(self.name); let asset_id = asset_id(self.name); - let register_me = - Register::account(Account::new(account_id, [keypair.public_key().clone()])); + let register_me = Register::account(Account::new(account_id, keypair.public_key().clone())); self.client.submit_blocking(register_me)?; let mint_a_rose = Mint::asset_quantity(1_u32, asset_id); diff --git a/client/examples/million_accounts_genesis.rs b/client/examples/million_accounts_genesis.rs index c618caf700b..7b9f805de7a 100644 --- a/client/examples/million_accounts_genesis.rs +++ b/client/examples/million_accounts_genesis.rs @@ -3,6 +3,7 @@ use std::{thread, time::Duration}; use iroha::samples::{construct_executor, get_config}; use iroha_client::data_model::prelude::*; +use iroha_crypto::KeyPair; use iroha_data_model::isi::InstructionBox; use iroha_genesis::{GenesisNetwork, RawGenesisBlock, RawGenesisBlockBuilder}; use iroha_primitives::unique_vec; @@ -77,7 +78,11 @@ fn create_million_accounts_directly() { format!("bob-{i}").parse().expect("Valid"), ); let create_domain: InstructionBox = Register::domain(Domain::new(domain_id)).into(); - let create_account = Register::account(Account::new(normal_account_id.clone(), [])).into(); + let create_account = Register::account(Account::new( + normal_account_id.clone(), + KeyPair::generate().into_raw_parts().0, + )) + .into(); if test_client .submit_all([create_domain, create_account]) .is_err() diff --git a/client/examples/tutorial.rs b/client/examples/tutorial.rs index bec8227f6a5..b58dbdc95df 100644 --- a/client/examples/tutorial.rs +++ b/client/examples/tutorial.rs @@ -120,7 +120,7 @@ fn account_registration_test(config: Config) -> Result<(), Error> { // #region register_account_generate // Generate a new account - let create_account = Register::account(Account::new(account_id, [public_key])); + let create_account = Register::account(Account::new(account_id, public_key)); // #endregion register_account_generate // #region register_account_prepare_tx diff --git a/client/tests/integration/add_account.rs b/client/tests/integration/add_account.rs index 49d15f1ebd9..58c5e35e3c9 100644 --- a/client/tests/integration/add_account.rs +++ b/client/tests/integration/add_account.rs @@ -5,6 +5,8 @@ use iroha_client::{client, data_model::prelude::*}; use iroha_config::parameters::actual::Root as Config; use test_network::*; +use crate::integration::new_account_with_random_public_key; + #[test] // This test suite is also covered at the UI level in the iroha_client_cli tests // in test_register_accounts.py @@ -16,14 +18,18 @@ fn client_add_account_with_name_length_more_than_limit_should_not_commit_transac let pipeline_time = Config::pipeline_time(); let normal_account_id: AccountId = "bob@wonderland".parse().expect("Valid"); - let create_account = Register::account(Account::new(normal_account_id.clone(), [])); + let create_account = Register::account(new_account_with_random_public_key( + normal_account_id.clone(), + )); test_client.submit(create_account)?; let too_long_account_name = "0".repeat(2_usize.pow(14)); let incorrect_account_id: AccountId = (too_long_account_name + "@wonderland") .parse() .expect("Valid"); - let create_account = Register::account(Account::new(incorrect_account_id.clone(), [])); + let create_account = Register::account(new_account_with_random_public_key( + incorrect_account_id.clone(), + )); test_client.submit(create_account)?; thread::sleep(pipeline_time * 2); diff --git a/client/tests/integration/asset.rs b/client/tests/integration/asset.rs index 3c3d719d694..0d97a8b4f61 100644 --- a/client/tests/integration/asset.rs +++ b/client/tests/integration/asset.rs @@ -271,7 +271,7 @@ fn find_rate_and_make_exchange_isi_should_succeed() { let buyer_keypair = KeyPair::generate(); let register_account = |account_id: AccountId, signature: PublicKey| { - Register::account(Account::new(account_id, [signature])) + Register::account(Account::new(account_id, signature)) }; let grant_alice_asset_transfer_permission = |asset_id: AssetId, owner_keypair: KeyPair| { @@ -448,19 +448,17 @@ fn asset_id_new(definition_name: &str, definition_domain: &str, account_id: Acco mod register { use super::*; + use crate::integration::new_account_with_random_public_key; pub fn domain(name: &str) -> Register { Register::domain(Domain::new(DomainId::from_str(name).expect("Valid"))) } pub fn account(account_name: &str, domain_name: &str) -> Register { - Register::account(Account::new( - AccountId::new( - domain_name.parse().expect("Valid"), - account_name.parse().expect("Valid"), - ), - [], - )) + Register::account(new_account_with_random_public_key(AccountId::new( + domain_name.parse().expect("Valid"), + account_name.parse().expect("Valid"), + ))) } pub fn asset_definition(asset_name: &str, domain_name: &str) -> Register { diff --git a/client/tests/integration/asset_propagation.rs b/client/tests/integration/asset_propagation.rs index 29122fc9560..c26d142e67e 100644 --- a/client/tests/integration/asset_propagation.rs +++ b/client/tests/integration/asset_propagation.rs @@ -32,7 +32,7 @@ fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount_on_a Register::domain(Domain::new(DomainId::from_str("domain")?)).into(); let account_id = AccountId::from_str("account@domain")?; let (public_key, _) = KeyPair::generate().into(); - let create_account = Register::account(Account::new(account_id.clone(), [public_key])).into(); + let create_account = Register::account(Account::new(account_id.clone(), public_key)).into(); let asset_definition_id = AssetDefinitionId::from_str("xor#domain")?; let create_asset = Register::asset_definition(AssetDefinition::quantity(asset_definition_id.clone())).into(); diff --git a/client/tests/integration/burn_public_keys.rs b/client/tests/integration/burn_public_keys.rs index a50bb6cec0e..b28c9637eae 100644 --- a/client/tests/integration/burn_public_keys.rs +++ b/client/tests/integration/burn_public_keys.rs @@ -52,7 +52,7 @@ fn public_keys_cannot_be_burned_to_nothing() { let charlie_initial_keypair = KeyPair::generate(); let register_charlie = Register::account(Account::new( charlie_id.clone(), - [charlie_initial_keypair.public_key().clone()], + charlie_initial_keypair.public_key().clone(), )); let (tx_hash, res) = submit(&client, [register_charlie], None); diff --git a/client/tests/integration/domain_owner_permissions.rs b/client/tests/integration/domain_owner_permissions.rs index d2901928317..611d0e5fbd7 100644 --- a/client/tests/integration/domain_owner_permissions.rs +++ b/client/tests/integration/domain_owner_permissions.rs @@ -6,6 +6,8 @@ use iroha_client::{ use serde_json::json; use test_network::*; +use super::new_account_with_random_public_key; + #[test] fn domain_owner_domain_permissions() -> Result<()> { let chain_id = ChainId::from("0"); @@ -23,7 +25,7 @@ fn domain_owner_domain_permissions() -> Result<()> { test_client.submit_blocking(Register::domain(kingdom))?; let bob_keypair = KeyPair::generate(); - let bob = Account::new(bob_id.clone(), [bob_keypair.public_key().clone()]); + let bob = Account::new(bob_id.clone(), bob_keypair.public_key().clone()); test_client.submit_blocking(Register::account(bob))?; // Asset definitions can't be registered by "bob@kingdom" by default @@ -96,7 +98,7 @@ fn domain_owner_account_permissions() -> Result<()> { let mad_hatter_keypair = KeyPair::generate(); let mad_hatter = Account::new( mad_hatter_id.clone(), - [mad_hatter_keypair.public_key().clone()], + mad_hatter_keypair.public_key().clone(), ); test_client.submit_blocking(Register::account(mad_hatter))?; @@ -158,10 +160,10 @@ fn domain_owner_asset_definition_permissions() -> Result<()> { test_client.submit_blocking(Register::domain(kingdom))?; let bob_keypair = KeyPair::generate(); - let bob = Account::new(bob_id.clone(), [bob_keypair.public_key().clone()]); + let bob = Account::new(bob_id.clone(), bob_keypair.public_key().clone()); test_client.submit_blocking(Register::account(bob))?; - let rabbit = Account::new(rabbit_id.clone(), []); + let rabbit = new_account_with_random_public_key(rabbit_id.clone()); test_client.submit_blocking(Register::account(rabbit))?; // Grant permission to register asset definitions to "bob@kingdom" @@ -228,7 +230,7 @@ fn domain_owner_asset_permissions() -> Result<()> { test_client.submit_blocking(Register::domain(kingdom))?; let bob_keypair = KeyPair::generate(); - let bob = Account::new(bob_id.clone(), [bob_keypair.public_key().clone()]); + let bob = Account::new(bob_id.clone(), bob_keypair.public_key().clone()); test_client.submit_blocking(Register::account(bob))?; // Grant permission to register asset definitions to "bob@kingdom" @@ -293,7 +295,7 @@ fn domain_owner_trigger_permissions() -> Result<()> { test_client.submit_blocking(Register::domain(kingdom))?; let bob_keypair = KeyPair::generate(); - let bob = Account::new(bob_id.clone(), [bob_keypair.public_key().clone()]); + let bob = Account::new(bob_id.clone(), bob_keypair.public_key().clone()); test_client.submit_blocking(Register::account(bob))?; let asset_definition_id = "rose#wonderland".parse()?; @@ -354,7 +356,7 @@ fn domain_owner_transfer() -> Result<()> { test_client.submit_blocking(Register::domain(kingdom))?; let bob_keypair = KeyPair::generate(); - let bob = Account::new(bob_id.clone(), [bob_keypair.public_key().clone()]); + let bob = Account::new(bob_id.clone(), bob_keypair.public_key().clone()); test_client.submit_blocking(Register::account(bob))?; let domain = test_client.request(FindDomainById::new(kingdom_id.clone()))?; diff --git a/client/tests/integration/extra_functional/multiple_blocks_created.rs b/client/tests/integration/extra_functional/multiple_blocks_created.rs index 1b56abe5590..081c30e91a3 100644 --- a/client/tests/integration/extra_functional/multiple_blocks_created.rs +++ b/client/tests/integration/extra_functional/multiple_blocks_created.rs @@ -31,7 +31,7 @@ fn long_multiple_blocks_created() -> Result<()> { let create_domain: InstructionBox = Register::domain(Domain::new("domain".parse()?)).into(); let account_id: AccountId = "account@domain".parse()?; let (public_key, _) = KeyPair::generate().into(); - let create_account = Register::account(Account::new(account_id.clone(), [public_key])).into(); + let create_account = Register::account(Account::new(account_id.clone(), public_key)).into(); let asset_definition_id: AssetDefinitionId = "xor#domain".parse()?; let create_asset = Register::asset_definition(AssetDefinition::quantity(asset_definition_id.clone())).into(); diff --git a/client/tests/integration/extra_functional/unregister_peer.rs b/client/tests/integration/extra_functional/unregister_peer.rs index e73112ae920..b83ac7c1f54 100644 --- a/client/tests/integration/extra_functional/unregister_peer.rs +++ b/client/tests/integration/extra_functional/unregister_peer.rs @@ -108,7 +108,7 @@ fn init() -> Result<( let create_domain = Register::domain(Domain::new("domain".parse()?)); let account_id: AccountId = "account@domain".parse()?; let (public_key, _) = KeyPair::generate().into(); - let create_account = Register::account(Account::new(account_id.clone(), [public_key])); + let create_account = Register::account(Account::new(account_id.clone(), public_key)); let asset_definition_id: AssetDefinitionId = "xor#domain".parse()?; let create_asset = Register::asset_definition(AssetDefinition::quantity(asset_definition_id.clone())); diff --git a/client/tests/integration/mod.rs b/client/tests/integration/mod.rs index 4340f7de2bd..c9ca0bc1052 100644 --- a/client/tests/integration/mod.rs +++ b/client/tests/integration/mod.rs @@ -1,3 +1,6 @@ +use iroha_crypto::KeyPair; +use iroha_data_model::account::{Account, AccountId, NewAccount}; + mod add_account; mod add_domain; mod asset; @@ -20,3 +23,7 @@ mod triggers; mod tx_history; mod tx_rollback; mod upgrade; + +fn new_account_with_random_public_key(account_id: AccountId) -> NewAccount { + Account::new(account_id, KeyPair::generate().into_raw_parts().0) +} diff --git a/client/tests/integration/permissions.rs b/client/tests/integration/permissions.rs index 0d95e964396..1ceb1569123 100644 --- a/client/tests/integration/permissions.rs +++ b/client/tests/integration/permissions.rs @@ -206,7 +206,7 @@ fn permissions_differ_not_only_by_names() { // Registering mouse let outfit_domain: DomainId = "outfit".parse().unwrap(); let create_outfit_domain = Register::domain(Domain::new(outfit_domain.clone())); - let new_mouse_account = Account::new(mouse_id.clone(), [mouse_keypair.public_key().clone()]); + let new_mouse_account = Account::new(mouse_id.clone(), mouse_keypair.public_key().clone()); client .submit_all_blocking([ InstructionBox::from(create_outfit_domain), @@ -306,7 +306,7 @@ fn stored_vs_granted_token_payload() -> Result<()> { Register::asset_definition(AssetDefinition::store(asset_definition_id.clone())); let mouse_id: AccountId = "mouse@wonderland".parse().expect("Valid"); let mouse_keypair = KeyPair::generate(); - let new_mouse_account = Account::new(mouse_id.clone(), [mouse_keypair.public_key().clone()]); + let new_mouse_account = Account::new(mouse_id.clone(), mouse_keypair.public_key().clone()); let instructions: [InstructionBox; 2] = [ Register::account(new_mouse_account).into(), create_asset.into(), diff --git a/client/tests/integration/queries/account.rs b/client/tests/integration/queries/account.rs index 69d28c66e6f..2123cbb311b 100644 --- a/client/tests/integration/queries/account.rs +++ b/client/tests/integration/queries/account.rs @@ -7,6 +7,8 @@ use iroha_client::{ }; use test_network::*; +use crate::integration::new_account_with_random_public_key; + #[test] fn find_accounts_with_asset() -> Result<()> { let (_rt, _peer, test_client) = ::new().with_port(10_760).start_with_runtime(); @@ -40,7 +42,7 @@ fn find_accounts_with_asset() -> Result<()> { .iter() .skip(1) // Alice has already been registered in genesis .cloned() - .map(|account_id| Register::account(Account::new(account_id, []))) + .map(|account_id| Register::account(new_account_with_random_public_key(account_id))) .collect::>(); test_client.submit_all_blocking(register_accounts)?; diff --git a/client/tests/integration/queries/asset.rs b/client/tests/integration/queries/asset.rs index d987395f76c..982d9873dfe 100644 --- a/client/tests/integration/queries/asset.rs +++ b/client/tests/integration/queries/asset.rs @@ -41,7 +41,7 @@ fn find_asset_total_quantity() -> Result<()> { .skip(1) // Alice has already been registered in genesis .cloned() .zip(keys.iter().map(KeyPair::public_key).cloned()) - .map(|(account_id, public_key)| Register::account(Account::new(account_id, [public_key]))) + .map(|(account_id, public_key)| Register::account(Account::new(account_id, public_key))) .collect::>(); test_client.submit_all_blocking(register_accounts)?; diff --git a/client/tests/integration/roles.rs b/client/tests/integration/roles.rs index f7cc75fdaa4..a0a33516473 100644 --- a/client/tests/integration/roles.rs +++ b/client/tests/integration/roles.rs @@ -9,6 +9,8 @@ use iroha_client::{ use serde_json::json; use test_network::*; +use crate::integration::new_account_with_random_public_key; + #[test] fn register_empty_role() -> Result<()> { let (_rt, _peer, test_client) = ::new().with_port(10_695).start_with_runtime(); @@ -58,7 +60,7 @@ fn register_and_grant_role_for_metadata_access() -> Result<()> { let mouse_key_pair = KeyPair::generate(); let register_mouse = Register::account(Account::new( mouse_id.clone(), - [mouse_key_pair.public_key().clone()], + mouse_key_pair.public_key().clone(), )); test_client.submit_blocking(register_mouse)?; @@ -110,7 +112,7 @@ fn unregistered_role_removed_from_account() -> Result<()> { let mouse_id: AccountId = "mouse@wonderland".parse().expect("Valid"); // Registering Mouse - let register_mouse = Register::account(Account::new(mouse_id.clone(), [])); + let register_mouse = Register::account(new_account_with_random_public_key(mouse_id.clone())); test_client.submit_blocking(register_mouse)?; // Register root role diff --git a/client/tests/integration/sorting.rs b/client/tests/integration/sorting.rs index 19f69f3b86e..3d50a1a419f 100644 --- a/client/tests/integration/sorting.rs +++ b/client/tests/integration/sorting.rs @@ -17,6 +17,8 @@ use iroha_client::{ use iroha_data_model::isi::InstructionBox; use test_network::*; +use crate::integration::new_account_with_random_public_key; + #[test] fn correct_pagination_assets_after_creating_new_one() { let (_rt, _peer, test_client) = ::new().with_port(10_635).start_with_runtime(); @@ -201,7 +203,8 @@ fn correct_sorting_of_entities() { MetadataLimits::new(10, 28), ) .expect("Valid"); - let account = Account::new(account_id.clone(), []).with_metadata(account_metadata.clone()); + let account = new_account_with_random_public_key(account_id.clone()) + .with_metadata(account_metadata.clone()); accounts.push(account_id); metadata_of_accounts.push(account_metadata); @@ -342,7 +345,7 @@ fn sort_only_elements_which_have_sorting_key() -> Result<()> { for i in 0..n { let account_id = AccountId::from_str(&format!("charlie{i}@wonderland")).expect("Valid"); let account = if skip_set.contains(&i) { - let account = Account::new(account_id.clone(), []); + let account = new_account_with_random_public_key(account_id.clone()); accounts_b.push(account_id); account } else { @@ -354,7 +357,8 @@ fn sort_only_elements_which_have_sorting_key() -> Result<()> { MetadataLimits::new(10, 28), ) .expect("Valid"); - let account = Account::new(account_id.clone(), []).with_metadata(account_metadata); + let account = new_account_with_random_public_key(account_id.clone()) + .with_metadata(account_metadata); accounts_a.push(account_id); account }; diff --git a/client/tests/integration/transfer_asset.rs b/client/tests/integration/transfer_asset.rs index 6b3ee6540dc..2c2122f2927 100644 --- a/client/tests/integration/transfer_asset.rs +++ b/client/tests/integration/transfer_asset.rs @@ -184,5 +184,5 @@ fn generate_two_ids() -> (AccountId, AccountId) { fn create_mouse(mouse_id: AccountId) -> Register { let (mouse_public_key, _) = KeyPair::generate().into(); - Register::account(Account::new(mouse_id, [mouse_public_key])) + Register::account(Account::new(mouse_id, mouse_public_key)) } diff --git a/client/tests/integration/triggers/data_trigger.rs b/client/tests/integration/triggers/data_trigger.rs index 2c197c9da18..b9db571de16 100644 --- a/client/tests/integration/triggers/data_trigger.rs +++ b/client/tests/integration/triggers/data_trigger.rs @@ -2,6 +2,8 @@ use eyre::Result; use iroha_client::{client, data_model::prelude::*}; use test_network::*; +use crate::integration::new_account_with_random_public_key; + #[test] fn must_execute_both_triggers() -> Result<()> { let (_rt, _peer, test_client) = ::new().with_port(10_650).start_with_runtime(); @@ -47,9 +49,8 @@ fn must_execute_both_triggers() -> Result<()> { )); test_client.submit_blocking(register_trigger)?; - test_client.submit_blocking(Register::account(Account::new( + test_client.submit_blocking(Register::account(new_account_with_random_public_key( "bunny@wonderland".parse()?, - [], )))?; test_client.submit_blocking(Register::domain(Domain::new("neverland".parse()?)))?; @@ -68,7 +69,8 @@ fn domain_scoped_trigger_must_be_executed_only_on_events_in_its_domain() -> Resu Register::domain(Domain::new("neverland".parse()?)).into(); let account_id: AccountId = "sapporo@neverland".parse()?; - let create_sapporo_account = Register::account(Account::new(account_id.clone(), [])).into(); + let create_sapporo_account = + Register::account(new_account_with_random_public_key(account_id.clone())).into(); let asset_definition_id: AssetDefinitionId = "sakura#neverland".parse()?; let create_sakura_asset_definition = @@ -107,14 +109,12 @@ fn domain_scoped_trigger_must_be_executed_only_on_events_in_its_domain() -> Resu )); test_client.submit_blocking(register_trigger)?; - test_client.submit_blocking(Register::account(Account::new( + test_client.submit_blocking(Register::account(new_account_with_random_public_key( "asahi@wonderland".parse()?, - [], )))?; - test_client.submit_blocking(Register::account(Account::new( + test_client.submit_blocking(Register::account(new_account_with_random_public_key( "asahi@neverland".parse()?, - [], )))?; let new_value = get_asset_value(&test_client, asset_id)?; diff --git a/client/tests/integration/triggers/time_trigger.rs b/client/tests/integration/triggers/time_trigger.rs index 319467fc24a..d8ab1722a1a 100644 --- a/client/tests/integration/triggers/time_trigger.rs +++ b/client/tests/integration/triggers/time_trigger.rs @@ -9,6 +9,8 @@ use iroha_config::parameters::defaults::chain_wide::DEFAULT_CONSENSUS_ESTIMATION use iroha_logger::info; use test_network::*; +use crate::integration::new_account_with_random_public_key; + /// Macro to abort compilation, if `e` isn't `true` macro_rules! const_assert { ($e:expr) => { @@ -195,7 +197,7 @@ fn mint_nft_for_every_user_every_1_sec() -> Result<()> { .iter() .skip(1) // Alice has already been registered in genesis .cloned() - .map(|account_id| Register::account(Account::new(account_id, []))) + .map(|account_id| Register::account(new_account_with_random_public_key(account_id))) .collect::>(); test_client.submit_all_blocking(register_accounts)?; diff --git a/client/tests/integration/upgrade.rs b/client/tests/integration/upgrade.rs index b7d0f9a1c04..60a0447a095 100644 --- a/client/tests/integration/upgrade.rs +++ b/client/tests/integration/upgrade.rs @@ -24,7 +24,7 @@ fn executor_upgrade_should_work() -> Result<()> { let admin_id: AccountId = "admin@admin".parse()?; let admin_keypair = KeyPair::generate(); - let admin_account = Account::new(admin_id.clone(), [admin_keypair.public_key().clone()]); + let admin_account = Account::new(admin_id.clone(), admin_keypair.public_key().clone()); let register_admin_account = Register::account(admin_account); client.submit_blocking(register_admin_account)?; diff --git a/client_cli/src/main.rs b/client_cli/src/main.rs index 25e8eaf93c0..8e89a729d9a 100644 --- a/client_cli/src/main.rs +++ b/client_cli/src/main.rs @@ -586,7 +586,7 @@ mod account { fn run(self, context: &mut dyn RunContext) -> Result<()> { let Self { id, key, metadata } = self; let create_account = - iroha_client::data_model::isi::Register::account(Account::new(id, [key])); + iroha_client::data_model::isi::Register::account(Account::new(id, key)); submit([create_account], metadata.load()?, context) .wrap_err("Failed to register account") } diff --git a/configs/swarm/executor.wasm b/configs/swarm/executor.wasm index 135f1021cc0..df2831647bf 100644 Binary files a/configs/swarm/executor.wasm and b/configs/swarm/executor.wasm differ diff --git a/core/benches/blocks/common.rs b/core/benches/blocks/common.rs index bfe24efe223..8b394faba0c 100644 --- a/core/benches/blocks/common.rs +++ b/core/benches/blocks/common.rs @@ -74,7 +74,7 @@ pub fn populate_wsv( instructions.push(can_unregister_domain.into()); for j in 0..accounts_per_domain { let account_id = construct_account_id(j, domain_id.clone()); - let account = Account::new(account_id.clone(), []); + let account = Account::new(account_id.clone(), KeyPair::generate().into_raw_parts().0); instructions.push(Register::account(account).into()); let can_unregister_account = Grant::permission( PermissionToken::new( @@ -150,7 +150,8 @@ pub fn restore_every_nth( for j in 0..accounts_per_domain { if j % nth == 0 || i % nth == 0 { let account_id = construct_account_id(j, domain_id.clone()); - let account = Account::new(account_id.clone(), []); + let account = + Account::new(account_id.clone(), KeyPair::generate().into_raw_parts().0); instructions.push(Register::account(account).into()); } } @@ -181,7 +182,7 @@ pub fn build_wsv( let mut domain = Domain::new(account_id.domain_id.clone()).build(account_id); domain.accounts.insert( account_id.clone(), - Account::new(account_id.clone(), [key_pair.public_key().clone()]).build(account_id), + Account::new(account_id.clone(), key_pair.public_key().clone()).build(account_id), ); let mut wsv = WorldStateView::new(World::with([domain], UniqueVec::new()), kura, query_handle); wsv.config.transaction_limits = TransactionLimits::new(u64::MAX, u64::MAX); diff --git a/core/benches/validation.rs b/core/benches/validation.rs index 037e031cd12..04097530119 100644 --- a/core/benches/validation.rs +++ b/core/benches/validation.rs @@ -34,7 +34,7 @@ fn build_test_transaction(keys: &KeyPair, chain_id: ChainId) -> SignedTransactio domain_name.parse().expect("Valid"), account_name.parse().expect("Valid"), ), - [public_key], + public_key, )) .into(); let asset_definition_id = AssetDefinitionId::new( @@ -69,7 +69,7 @@ fn build_test_and_transient_wsv(keys: KeyPair) -> WorldStateView { Name::from_str(START_ACCOUNT).expect("Valid"), ); let mut domain = Domain::new(domain_id).build(&account_id); - let account = Account::new(account_id.clone(), [public_key]).build(&account_id); + let account = Account::new(account_id.clone(), public_key).build(&account_id); assert!(domain.add_account(account).is_none()); World::with([domain], UniqueVec::new()) }, diff --git a/core/src/block.rs b/core/src/block.rs index b2b0a6bc82d..8fa62f2fdb3 100644 --- a/core/src/block.rs +++ b/core/src/block.rs @@ -699,7 +699,7 @@ mod tests { let alice_id = AccountId::from_str("alice@wonderland").expect("Valid"); let alice_keys = KeyPair::generate(); let account = - Account::new(alice_id.clone(), [alice_keys.public_key().clone()]).build(&alice_id); + Account::new(alice_id.clone(), alice_keys.public_key().clone()).build(&alice_id); let domain_id = DomainId::from_str("wonderland").expect("Valid"); let mut domain = Domain::new(domain_id).build(&alice_id); assert!(domain.add_account(account).is_none()); @@ -742,7 +742,7 @@ mod tests { let alice_id = AccountId::from_str("alice@wonderland").expect("Valid"); let alice_keys = KeyPair::generate(); let account = - Account::new(alice_id.clone(), [alice_keys.public_key().clone()]).build(&alice_id); + Account::new(alice_id.clone(), alice_keys.public_key().clone()).build(&alice_id); let domain_id = DomainId::from_str("wonderland").expect("Valid"); let mut domain = Domain::new(domain_id).build(&alice_id); assert!(domain.add_account(account).is_none()); @@ -808,7 +808,7 @@ mod tests { let alice_id = AccountId::from_str("alice@wonderland").expect("Valid"); let alice_keys = KeyPair::generate(); let account = - Account::new(alice_id.clone(), [alice_keys.public_key().clone()]).build(&alice_id); + Account::new(alice_id.clone(), alice_keys.public_key().clone()).build(&alice_id); let domain_id = DomainId::from_str("wonderland").expect("Valid"); let mut domain = Domain::new(domain_id).build(&alice_id); assert!( diff --git a/core/src/queue.rs b/core/src/queue.rs index 3beab0a9546..db705fb20d3 100644 --- a/core/src/queue.rs +++ b/core/src/queue.rs @@ -411,12 +411,17 @@ mod tests { } pub fn world_with_test_domains( - signatures: impl IntoIterator, + signatories: impl IntoIterator, ) -> World { let domain_id = DomainId::from_str("wonderland").expect("Valid"); let account_id = AccountId::from_str("alice@wonderland").expect("Valid"); let mut domain = Domain::new(domain_id).build(&account_id); - let account = Account::new(account_id.clone(), signatures).build(&account_id); + let mut signatories = signatories.into_iter(); + let mut account = Account::new(account_id.clone(), signatories.next().unwrap()); + for signatory in signatories { + account = account.add_signatory(signatory); + } + let account = account.build(&account_id); assert!(domain.add_account(account).is_none()); World::with([domain], PeersIds::new()) } @@ -493,11 +498,9 @@ mod tests { let domain_id = DomainId::from_str("wonderland").expect("Valid"); let account_id = AccountId::from_str("alice@wonderland").expect("Valid"); let mut domain = Domain::new(domain_id).build(&account_id); - let mut account = Account::new( - account_id.clone(), - key_pairs.iter().map(KeyPair::public_key).cloned(), - ) - .build(&account_id); + let mut account = Account::new(account_id.clone(), key_pairs[0].public_key().clone()) + .add_signatory(key_pairs[1].public_key().clone()) + .build(&account_id); account.signature_check_condition = SignatureCheckCondition::all_account_signatures(); assert!(domain.add_account(account).is_none()); let query_handle = LiveQueryStore::test().start(); @@ -887,11 +890,11 @@ mod tests { let mut domain = Domain::new(domain_id).build(&alice_account_id); let alice_account = Account::new( alice_account_id.clone(), - [alice_key_pair.public_key().clone()], + alice_key_pair.public_key().clone(), ) .build(&alice_account_id); let bob_account = - Account::new(bob_account_id.clone(), [bob_key_pair.public_key().clone()]) + Account::new(bob_account_id.clone(), bob_key_pair.public_key().clone()) .build(&bob_account_id); assert!(domain.add_account(alice_account).is_none()); assert!(domain.add_account(bob_account).is_none()); diff --git a/core/src/smartcontracts/isi/account.rs b/core/src/smartcontracts/isi/account.rs index 7c803c76b43..e94fe6826f5 100644 --- a/core/src/smartcontracts/isi/account.rs +++ b/core/src/smartcontracts/isi/account.rs @@ -164,16 +164,14 @@ pub mod isi { wsv.account_mut(&account_id) .map_err(Error::from) .and_then(|account| { - if account.signatories.len() < 2 { - return Err(Error::InvariantViolation(String::from( + match account.remove_signatory(&public_key) { + None => Err(Error::InvariantViolation(String::from( "Public keys cannot be burned to nothing, \ if you want to delete the account, please use an unregister instruction", - ))); + ))), + Some(false) => Err(FindError::PublicKey(public_key).into()), + Some(true) => Ok(()) } - if !account.remove_signatory(&public_key) { - return Err(FindError::PublicKey(public_key).into()); - } - Ok(()) })?; wsv.emit_events(Some(AccountEvent::AuthenticationRemoved(account_id))); diff --git a/core/src/smartcontracts/isi/mod.rs b/core/src/smartcontracts/isi/mod.rs index ccd65f6d8cb..437ef7c1c91 100644 --- a/core/src/smartcontracts/isi/mod.rs +++ b/core/src/smartcontracts/isi/mod.rs @@ -248,7 +248,7 @@ mod tests { let asset_definition_id = AssetDefinitionId::from_str("rose#wonderland")?; Register::domain(Domain::new(DomainId::from_str("wonderland")?)) .execute(&genesis_account_id, &mut wsv)?; - Register::account(Account::new(account_id, [public_key])) + Register::account(Account::new(account_id, public_key)) .execute(&genesis_account_id, &mut wsv)?; Register::asset_definition(AssetDefinition::store(asset_definition_id)) .execute(&genesis_account_id, &mut wsv)?; @@ -395,8 +395,7 @@ mod tests { // register fake account let (public_key, _) = KeyPair::generate().into(); - let register_account = - Register::account(Account::new(fake_account_id.clone(), [public_key])); + let register_account = Register::account(Account::new(fake_account_id.clone(), public_key)); register_account.execute(&account_id, &mut wsv)?; // register the trigger diff --git a/core/src/smartcontracts/isi/query.rs b/core/src/smartcontracts/isi/query.rs index f7695a93c1c..e43f3354967 100644 --- a/core/src/smartcontracts/isi/query.rs +++ b/core/src/smartcontracts/isi/query.rs @@ -187,7 +187,7 @@ mod tests { let domain_id = DomainId::from_str("wonderland").expect("Valid"); let mut domain = Domain::new(domain_id).build(&ALICE_ID); let account = - Account::new(ALICE_ID.clone(), [ALICE_KEYS.public_key().clone()]).build(&ALICE_ID); + Account::new(ALICE_ID.clone(), ALICE_KEYS.public_key().clone()).build(&ALICE_ID); assert!(domain.add_account(account).is_none()); let asset_definition_id = AssetDefinitionId::from_str("rose#wonderland").expect("Valid"); assert!(domain @@ -201,7 +201,7 @@ mod tests { let mut domain = Domain::new(DomainId::from_str("wonderland").expect("Valid")).build(&ALICE_ID); let mut account = - Account::new(ALICE_ID.clone(), [ALICE_KEYS.public_key().clone()]).build(&ALICE_ID); + Account::new(ALICE_ID.clone(), ALICE_KEYS.public_key().clone()).build(&ALICE_ID); assert!(domain .add_asset_definition( AssetDefinition::quantity(asset_definition_id.clone()).build(&ALICE_ID) @@ -233,7 +233,7 @@ mod tests { )?; let mut domain = Domain::new(DomainId::from_str("wonderland")?).build(&ALICE_ID); - let account = Account::new(ALICE_ID.clone(), [ALICE_KEYS.public_key().clone()]) + let account = Account::new(ALICE_ID.clone(), ALICE_KEYS.public_key().clone()) .with_metadata(metadata) .build(&ALICE_ID); assert!(domain.add_account(account).is_none()); @@ -466,7 +466,7 @@ mod tests { .with_metadata(metadata) .build(&ALICE_ID); let account = - Account::new(ALICE_ID.clone(), [ALICE_KEYS.public_key().clone()]).build(&ALICE_ID); + Account::new(ALICE_ID.clone(), ALICE_KEYS.public_key().clone()).build(&ALICE_ID); assert!(domain.add_account(account).is_none()); let asset_definition_id = AssetDefinitionId::from_str("rose#wonderland")?; assert!(domain diff --git a/core/src/smartcontracts/wasm.rs b/core/src/smartcontracts/wasm.rs index ec431e8e458..5d5db7b02af 100644 --- a/core/src/smartcontracts/wasm.rs +++ b/core/src/smartcontracts/wasm.rs @@ -1649,7 +1649,7 @@ mod tests { fn world_with_test_account(authority: &AccountId) -> World { let domain_id = authority.domain_id.clone(); let (public_key, _) = KeyPair::generate().into(); - let account = Account::new(authority.clone(), [public_key]).build(authority); + let account = Account::new(authority.clone(), public_key).build(authority); let mut domain = Domain::new(domain_id).build(authority); assert!(domain.add_account(account).is_none()); @@ -1709,7 +1709,10 @@ mod tests { let isi_hex = { let new_authority = AccountId::from_str("mad_hatter@wonderland").expect("Valid"); - let register_isi = Register::account(Account::new(new_authority, [])); + let register_isi = Register::account(Account::new( + new_authority, + KeyPair::generate().into_raw_parts().0, + )); encode_hex(InstructionBox::from(register_isi)) }; @@ -1795,7 +1798,10 @@ mod tests { let isi_hex = { let new_authority = AccountId::from_str("mad_hatter@wonderland").expect("Valid"); - let register_isi = Register::account(Account::new(new_authority, [])); + let register_isi = Register::account(Account::new( + new_authority, + KeyPair::generate().into_raw_parts().0, + )); encode_hex(InstructionBox::from(register_isi)) }; @@ -1844,7 +1850,10 @@ mod tests { let isi_hex = { let new_authority = AccountId::from_str("mad_hatter@wonderland").expect("Valid"); - let register_isi = Register::account(Account::new(new_authority, [])); + let register_isi = Register::account(Account::new( + new_authority, + KeyPair::generate().into_raw_parts().0, + )); encode_hex(InstructionBox::from(register_isi)) }; diff --git a/core/src/sumeragi/main_loop.rs b/core/src/sumeragi/main_loop.rs index b545e281338..2959afa1151 100644 --- a/core/src/sumeragi/main_loop.rs +++ b/core/src/sumeragi/main_loop.rs @@ -1198,7 +1198,7 @@ mod tests { let alice_id: AccountId = "alice@wonderland".parse().expect("Valid"); let alice_keys = KeyPair::generate(); let account = - Account::new(alice_id.clone(), [alice_keys.public_key().clone()]).build(&alice_id); + Account::new(alice_id.clone(), alice_keys.public_key().clone()).build(&alice_id); let domain_id = "wonderland".parse().expect("Valid"); let mut domain = Domain::new(domain_id).build(&alice_id); assert!(domain.add_account(account).is_none()); diff --git a/crypto/src/lib.rs b/crypto/src/lib.rs index 913bc1ae6aa..c985ab60dca 100755 --- a/crypto/src/lib.rs +++ b/crypto/src/lib.rs @@ -204,6 +204,7 @@ impl KeyPair { } /// Construct a [`KeyPair`] + /// /// # Errors /// If public and private key don't match, i.e. if they don't make a pair pub fn new(public_key: PublicKey, private_key: PrivateKey) -> Result { @@ -239,6 +240,11 @@ impl KeyPair { Algorithm::BlsSmall => signature::bls::BlsSmall::keypair(key_gen_option).into(), } } + + /// Get [`PublicKey`] and [`PrivateKey`] contained in the [`KeyPair`]. + pub fn into_raw_parts(self) -> (PublicKey, PrivateKey) { + (self.public_key, self.private_key) + } } impl From<(ed25519::PublicKey, ed25519::PrivateKey)> for KeyPair { @@ -303,7 +309,7 @@ impl<'de> Deserialize<'de> for KeyPair { #[cfg(not(feature = "ffi_import"))] impl From for (PublicKey, PrivateKey) { fn from(key_pair: KeyPair) -> Self { - (key_pair.public_key, key_pair.private_key) + key_pair.into_raw_parts() } } diff --git a/data_model/src/account.rs b/data_model/src/account.rs index 59ad7b0a4d9..cffeaf4f027 100644 --- a/data_model/src/account.rs +++ b/data_model/src/account.rs @@ -79,20 +79,12 @@ pub mod model { /// Account entity is an authority which is used to execute `Iroha Special Instructions`. #[derive( - Debug, - Display, - Clone, - IdEqOrdHash, - Getters, - Decode, - Encode, - Deserialize, - Serialize, - IntoSchema, + Debug, Display, Clone, IdEqOrdHash, Getters, Encode, Deserialize, Serialize, IntoSchema, )] #[allow(clippy::multiple_inherent_impl)] #[display(fmt = "({id})")] // TODO: Add more? #[ffi_type] + #[serde(try_from = "candidate::Account")] pub struct Account { /// An Identification of the [`Account`]. pub id: AccountId, @@ -109,15 +101,17 @@ pub mod model { /// Builder which should be submitted in a transaction to create a new [`Account`] #[derive( - DebugCustom, Display, Clone, IdEqOrdHash, Decode, Encode, Serialize, Deserialize, IntoSchema, + DebugCustom, Display, Clone, IdEqOrdHash, Encode, Serialize, Deserialize, IntoSchema, )] #[display(fmt = "[{id}]")] #[debug(fmt = "[{id:?}] {{ signatories: {signatories:?}, metadata: {metadata} }}")] #[ffi_type] + #[serde(try_from = "candidate::NewAccount")] pub struct NewAccount { /// Identification pub id: AccountId, /// Signatories, i.e. signatures attached to this message. + /// Cannot be empty, guaranteed by constructors. pub signatories: Signatories, /// Metadata that should be submitted with the builder pub metadata: Metadata, @@ -148,15 +142,73 @@ pub mod model { } } +mod candidate { + //! Contains structs for deserialization checks + + use super::*; + + #[derive(Decode, Deserialize)] + /// [`Account`] candidate used for deserialization checks + pub struct Account { + id: AccountId, + assets: AssetsMap, + signatories: Signatories, + signature_check_condition: SignatureCheckCondition, + metadata: Metadata, + } + + impl TryFrom for super::Account { + type Error = &'static str; + + fn try_from(candidate: Account) -> Result { + check_signatories(&candidate.signatories)?; + + Ok(Self { + id: candidate.id, + assets: candidate.assets, + signatories: candidate.signatories, + signature_check_condition: candidate.signature_check_condition, + metadata: candidate.metadata, + }) + } + } + + /// [`NewAccount`] candidate used for deserialization checks + #[derive(Decode, Deserialize)] + pub struct NewAccount { + id: AccountId, + signatories: Signatories, + metadata: Metadata, + } + + impl TryFrom for super::NewAccount { + type Error = &'static str; + + fn try_from(candidate: NewAccount) -> Result { + check_signatories(&candidate.signatories)?; + + Ok(Self { + id: candidate.id, + signatories: candidate.signatories, + metadata: candidate.metadata, + }) + } + } + + fn check_signatories(signatories: &Signatories) -> Result<(), &'static str> { + if signatories.is_empty() { + return Err("Signatories cannot be empty"); + } + Ok(()) + } +} + impl Account { - /// Construct builder for [`Account`] identifiable by [`Id`] containing the given signatories. + /// Construct builder for [`Account`] identifiable by [`Id`] containing the given signatory. #[inline] #[must_use] - pub fn new( - id: AccountId, - signatories: impl IntoIterator, - ) -> ::With { - ::With::new(id, signatories) + pub fn new(id: AccountId, signatory: PublicKey) -> ::With { + ::With::new(id, signatory) } /// Get an iterator over [`signatories`](PublicKey) of the `Account` @@ -197,32 +249,58 @@ impl Account { pub fn remove_asset(&mut self, asset_id: &AssetId) -> Option { self.assets.remove(asset_id) } + /// Add [`signatory`](PublicKey) into the [`Account`]. /// - /// If `Account` did not have this signatory present, `true` is returned. - /// If `Account` did have this signatory present, `false` is returned. + /// If [`Account`] did not have this signatory present, `true` is returned. + /// If [`Account`] did have this signatory present, `false` is returned. #[inline] pub fn add_signatory(&mut self, signatory: PublicKey) -> bool { self.signatories.insert(signatory) } - /// Remove a signatory from the `Account` and return whether the signatory was present in the `Account` + /// Remove a signatory from the [`Account`]. + /// + /// Does nothing and returns [`None`] if only one signature is left. + /// Otherwise returns whether the signatory was presented in the Account. #[inline] - pub fn remove_signatory(&mut self, signatory: &PublicKey) -> bool { - self.signatories.remove(signatory) + pub fn remove_signatory(&mut self, signatory: &PublicKey) -> Option { + if self.signatories.len() < 2 { + return None; + } + + Some(self.signatories.remove(signatory)) + } +} + +impl Decode for Account { + fn decode( + input: &mut I, + ) -> Result { + let candidate = candidate::Account::decode(input)?; + Self::try_from(candidate).map_err(Into::into) } } impl NewAccount { - fn new(id: AccountId, signatories: impl IntoIterator) -> Self { + fn new(id: AccountId, signatory: PublicKey) -> Self { Self { id, - signatories: signatories.into_iter().collect(), + signatories: Signatories::from([signatory]), metadata: Metadata::default(), } } + /// Add signatory to account. + #[inline] + #[must_use] + pub fn add_signatory(mut self, signatory: PublicKey) -> Self { + self.signatories.insert(signatory); + self + } + /// Add [`Metadata`] to the account replacing any previously defined metadata + #[inline] #[must_use] pub fn with_metadata(mut self, metadata: Metadata) -> Self { self.metadata = metadata; @@ -236,6 +314,15 @@ impl HasMetadata for NewAccount { } } +impl Decode for NewAccount { + fn decode( + input: &mut I, + ) -> Result { + let candidate = candidate::NewAccount::decode(input)?; + Self::try_from(candidate).map_err(Into::into) + } +} + impl HasMetadata for Account { fn metadata(&self) -> &Metadata { &self.metadata diff --git a/data_model/src/predicate.rs b/data_model/src/predicate.rs index e50157fdaf7..704c619c14b 100644 --- a/data_model/src/predicate.rs +++ b/data_model/src/predicate.rs @@ -1150,6 +1150,7 @@ pub mod value { #[cfg(test)] mod test { + use iroha_crypto::KeyPair; use iroha_primitives::addr::socket_addr; use peer::Peer; use prelude::Metadata; @@ -1169,7 +1170,10 @@ pub mod value { )))); assert!( pred.applies(&Value::Identifiable(IdentifiableBox::NewAccount( - Account::new("alice@wonderland".parse().expect("Valid"), []) + Account::new( + "alice@wonderland".parse().expect("Valid"), + KeyPair::generate().into_raw_parts().0, + ) ))) ); assert!(!pred.applies(&Value::Name("alice".parse().expect("Valid")))); diff --git a/genesis/src/lib.rs b/genesis/src/lib.rs index b9eab5b2b2e..44143ad08fb 100644 --- a/genesis/src/lib.rs +++ b/genesis/src/lib.rs @@ -302,13 +302,17 @@ impl RawGenesisDomainBuilder { } } - /// Add an account to this domain without a public key. + /// Add an account to this domain with random public key. #[cfg(test)] - fn account_without_public_key(mut self, account_name: Name) -> Self { + fn account_with_random_public_key(mut self, account_name: Name) -> Self { let account_id = AccountId::new(self.domain_id.clone(), account_name); - self.transaction - .isi - .push(Register::account(Account::new(account_id, [])).into()); + self.transaction.isi.push( + Register::account(Account::new( + account_id, + KeyPair::generate().into_raw_parts().0, + )) + .into(), + ); self } @@ -326,7 +330,7 @@ impl RawGenesisDomainBuilder { ) -> Self { let account_id = AccountId::new(self.domain_id.clone(), account_name); let register = - Register::account(Account::new(account_id, [public_key]).with_metadata(metadata)); + Register::account(Account::new(account_id, public_key).with_metadata(metadata)); self.transaction.isi.push(register.into()); self } @@ -385,11 +389,11 @@ mod tests { genesis_builder = genesis_builder .domain("wonderland".parse().unwrap()) - .account_without_public_key("alice".parse().unwrap()) - .account_without_public_key("bob".parse().unwrap()) + .account_with_random_public_key("alice".parse().unwrap()) + .account_with_random_public_key("bob".parse().unwrap()) .finish_domain() .domain("tulgey_wood".parse().unwrap()) - .account_without_public_key("Cheshire_Cat".parse().unwrap()) + .account_with_random_public_key("Cheshire_Cat".parse().unwrap()) .finish_domain() .domain("meadow".parse().unwrap()) .account("Mad_Hatter".parse().unwrap(), public_key.parse().unwrap()) @@ -408,7 +412,7 @@ mod tests { finished_genesis_block.transactions[0].isi[1], Register::account(Account::new( AccountId::new(domain_id.clone(), "alice".parse().unwrap()), - [] + KeyPair::generate().into_raw_parts().0, )) .into() ); @@ -416,7 +420,7 @@ mod tests { finished_genesis_block.transactions[0].isi[2], Register::account(Account::new( AccountId::new(domain_id, "bob".parse().unwrap()), - [] + KeyPair::generate().into_raw_parts().0, )) .into() ); @@ -431,7 +435,7 @@ mod tests { finished_genesis_block.transactions[0].isi[4], Register::account(Account::new( AccountId::new(domain_id, "Cheshire_Cat".parse().unwrap()), - [] + KeyPair::generate().into_raw_parts().0, )) .into() ); @@ -446,7 +450,7 @@ mod tests { finished_genesis_block.transactions[0].isi[6], Register::account(Account::new( AccountId::new(domain_id, "Mad_Hatter".parse().unwrap()), - [public_key.parse().unwrap()], + public_key.parse().unwrap(), )) .into() ); diff --git a/smart_contract/src/lib.rs b/smart_contract/src/lib.rs index 005b2c69338..017fb5f867a 100644 --- a/smart_contract/src/lib.rs +++ b/smart_contract/src/lib.rs @@ -471,8 +471,8 @@ mod tests { const ISI_RESULT: Result<(), ValidationFail> = Ok(()); fn get_test_instruction() -> InstructionBox { - let new_account_id = "mad_hatter@wonderland".parse().expect("Valid"); - let register_isi = Register::account(Account::new(new_account_id, [])); + let new_asset_id = "tulip##alice@wonderland".parse().unwrap(); + let register_isi = Register::asset(Asset::new(new_asset_id, 1_u32)); register_isi.into() } diff --git a/tools/parity_scale_decoder/Cargo.toml b/tools/parity_scale_decoder/Cargo.toml index e2cb948ff7a..37087501892 100644 --- a/tools/parity_scale_decoder/Cargo.toml +++ b/tools/parity_scale_decoder/Cargo.toml @@ -33,5 +33,6 @@ colored = "2.0.4" iroha_data_model = { workspace = true } parity-scale-codec = { workspace = true } -serde_json = { workspace = true } +serde_json = { workspace = true, features = ["std"]} serde = { workspace = true } +eyre = { workspace = true } diff --git a/tools/parity_scale_decoder/build.rs b/tools/parity_scale_decoder/build.rs index 49223203f69..00391f5e58e 100644 --- a/tools/parity_scale_decoder/build.rs +++ b/tools/parity_scale_decoder/build.rs @@ -1,7 +1,8 @@ //! Build script that auto-updates sample binaries from sources. -use std::{fs, io::Result, path::PathBuf}; +use std::{fs, path::PathBuf}; +use eyre::Result; use iroha_data_model::{account::NewAccount, domain::NewDomain, prelude::*}; use parity_scale_codec::Encode; use serde::de::DeserializeOwned; diff --git a/tools/parity_scale_decoder/samples/account.bin b/tools/parity_scale_decoder/samples/account.bin index 04aea960c0e..c0ac2716337 100644 Binary files a/tools/parity_scale_decoder/samples/account.bin and b/tools/parity_scale_decoder/samples/account.bin differ diff --git a/tools/parity_scale_decoder/samples/account.json b/tools/parity_scale_decoder/samples/account.json index 08c2536561c..7bb4321521b 100644 --- a/tools/parity_scale_decoder/samples/account.json +++ b/tools/parity_scale_decoder/samples/account.json @@ -1,6 +1,8 @@ { "id": "alice@wonderland", - "signatories": [], + "signatories": [ + "ed0120EDF6D7B52C7032D03AEC696F2068BD53101528F3C7B6081BFF05A1662D7FC245" + ], "metadata": { "hat": { "Name": "white" diff --git a/tools/parity_scale_decoder/src/main.rs b/tools/parity_scale_decoder/src/main.rs index 6a60e0396ad..b01d9e9b3af 100644 --- a/tools/parity_scale_decoder/src/main.rs +++ b/tools/parity_scale_decoder/src/main.rs @@ -219,13 +219,17 @@ mod tests { let mut metadata = Metadata::new(); metadata .insert_with_limits( - "hat".parse().expect("Valid"), - Value::Name("white".parse().expect("Valid")), + "hat".parse().unwrap(), + Value::Name("white".parse().unwrap()), limits, ) .expect("Valid"); + let signature = PublicKey::from_str( + "ed0120EDF6D7B52C7032D03AEC696F2068BD53101528F3C7B6081BFF05A1662D7FC245", + ) + .unwrap(); let account = - Account::new("alice@wonderland".parse().expect("Valid"), []).with_metadata(metadata); + Account::new("alice@wonderland".parse().unwrap(), signature).with_metadata(metadata); decode_sample("account.bin", String::from("NewAccount"), &account); }