Skip to content

Commit

Permalink
add data_model mutable_api feature flag
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
  • Loading branch information
mversic committed Mar 21, 2022
1 parent 13f6c5e commit 66ddf1d
Show file tree
Hide file tree
Showing 47 changed files with 468 additions and 590 deletions.
12 changes: 4 additions & 8 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//!
//! `Iroha` is the main instance of the peer program. `Arguments`
//! should be constructed externally: (see `main.rs`).
use std::{collections::BTreeMap, path::PathBuf, sync::Arc};
use std::{path::PathBuf, sync::Arc};

use color_eyre::eyre::{eyre, Result, WrapErr};
use config::Configuration;
Expand Down Expand Up @@ -304,16 +304,12 @@ where
///
/// # Errors
/// - Genesis account public key not specified.
fn domains(configuration: &config::Configuration) -> Result<BTreeMap<DomainId, Domain>> {
fn domains(configuration: &config::Configuration) -> Result<impl Iterator<Item = Domain>> {
let key = configuration
.genesis
.account_public_key
.clone()
.ok_or_else(|| eyre!("Genesis account public key is not specified."))?;
#[allow(clippy::expect_used)]
Ok([(
DomainId::new(GENESIS_DOMAIN_NAME).expect("valid name"),
Domain::from(GenesisDomain::new(key)),
)]
.into())

Ok([Domain::from(GenesisDomain::new(key))].into_iter())
}
45 changes: 16 additions & 29 deletions cli/src/torii/tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#![allow(clippy::pedantic, clippy::restriction)]

use std::{
collections::{BTreeMap, BTreeSet},
time::Duration,
};
use std::{collections::BTreeSet, time::Duration};

use futures::future::FutureExt;
use iroha_actor::{broker::Broker, Actor};
Expand Down Expand Up @@ -32,25 +29,19 @@ async fn create_torii() -> (Torii<World>, KeyPair) {
format!("127.0.0.1:{}", unique_port::get_unique_free_port().unwrap());
let (events, _) = tokio::sync::broadcast::channel(100);
let wsv = Arc::new(WorldStateView::new(World::with(
('a'..'z').map(|name| name.to_string()).map(|name| {
(
DomainId::new(&name).expect("Valid"),
Domain::new(DomainId::new(&name).expect("Valid")),
)
}),
('a'..'z')
.map(|name| name.to_string())
.map(|name| Domain::new(DomainId::new(&name).expect("Valid"))),
vec![],
)));
let keys = KeyPair::generate().expect("Failed to generate keys");
wsv.world.domains.insert(
DomainId::new("wonderland").expect("Valid"),
Domain::with_accounts(
"wonderland",
std::iter::once(Account::with_signatory(
AccountId::new("alice", "wonderland").expect("Valid"),
keys.public_key.clone(),
)),
),
);
let domain_id = DomainId::new("wonderland").expect("Valid");
let mut domain: Domain = Domain::new(domain_id.clone()).into();
domain.add_account(Account::new(
AccountId::new("alice", "wonderland").expect("Valid"),
[keys.public_key.clone()],
));
wsv.world.domains.insert(domain_id, domain);
let queue = Arc::new(Queue::from_configuration(&config.queue, Arc::clone(&wsv)));
let network = IrohaNetwork::new(
Broker::new(),
Expand Down Expand Up @@ -250,9 +241,9 @@ fn register_domain() -> Instruction {
}

fn register_account(name: &str) -> Instruction {
Instruction::Register(RegisterBox::new(NewAccount::with_signatory(
Instruction::Register(RegisterBox::new(Account::new(
AccountId::new(name, DOMAIN).expect("Valid"),
KeyPair::generate().unwrap().public_key,
[KeyPair::generate().unwrap().public_key],
)))
}

Expand Down Expand Up @@ -673,19 +664,15 @@ async fn blocks_stream() {
}

/// Returns the a map of a form `domain_name -> domain`, for initial domains.
pub fn domains(
fn domains(
configuration: &crate::config::Configuration,
) -> eyre::Result<BTreeMap<DomainId, Domain>> {
) -> eyre::Result<impl Iterator<Item = Domain>> {
let key = configuration
.genesis
.account_public_key
.clone()
.ok_or_else(|| eyre!("Genesis account public key is not specified."))?;
Ok(std::iter::once((
DomainId::new(GENESIS_DOMAIN_NAME).expect("Valid"),
Domain::from(GenesisDomain::new(key)),
))
.collect())
Ok([Domain::from(GenesisDomain::new(key))].into_iter())
}

#[test]
Expand Down
38 changes: 13 additions & 25 deletions client/benches/torii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,17 @@ fn query_requests(criterion: &mut Criterion) {
.expect("Should not fail");
let mut group = criterion.benchmark_group("query-requests");
let domain_name = "domain";
let create_domain = RegisterBox::new(IdentifiableBox::Domain(
Domain::new(DomainId::new(domain_name).expect("Valid")).into(),
));
let create_domain = RegisterBox::new(Domain::new(DomainId::new(domain_name).expect("Valid")));
let account_name = "account";
let account_id = AccountId::new(account_name, domain_name).expect("Valid");
let create_account = RegisterBox::new(IdentifiableBox::NewAccount(
NewAccount::with_signatory(
account_id.clone(),
KeyPair::generate()
.expect("Failed to generate KeyPair.")
.public_key,
)
.into(),
let create_account = RegisterBox::new(Account::new(
account_id.clone(),
[KeyPair::generate()
.expect("Failed to generate KeyPair.")
.public_key],
));
let asset_definition_id = AssetDefinitionId::new("xor", domain_name).expect("Valid");
let create_asset = RegisterBox::new(IdentifiableBox::AssetDefinition(
AssetDefinition::new_quantity(asset_definition_id.clone()).into(),
));
let create_asset = RegisterBox::new(AssetDefinition::new_quantity(asset_definition_id.clone()));
let quantity: u32 = 200;
let mint_asset = MintBox::new(
Value::U32(quantity),
Expand Down Expand Up @@ -143,19 +136,14 @@ fn instruction_submits(criterion: &mut Criterion) {
rt.block_on(peer.start_with_config_permissions(configuration, genesis, AllowAll, AllowAll));
let mut group = criterion.benchmark_group("instruction-requests");
let domain_name = "domain";
let create_domain = RegisterBox::new(IdentifiableBox::Domain(
Domain::new(DomainId::new(domain_name).expect("Valid")).into(),
));
let create_domain = RegisterBox::new(Domain::new(DomainId::new(domain_name).expect("Valid")));
let account_name = "account";
let account_id = AccountId::new(account_name, domain_name).expect("Valid");
let create_account = RegisterBox::new(IdentifiableBox::NewAccount(
NewAccount::with_signatory(
account_id.clone(),
KeyPair::generate()
.expect("Failed to generate Key-pair.")
.public_key,
)
.into(),
let create_account = RegisterBox::new(Account::new(
account_id.clone(),
[KeyPair::generate()
.expect("Failed to generate Key-pair.")
.public_key],
));
let asset_definition_id = AssetDefinitionId::new("xor", domain_name).expect("Valid");
let mut client_config = iroha_client::samples::get_client_config(&get_key_pair());
Expand Down
5 changes: 2 additions & 3 deletions client/examples/million_accounts_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ fn main() {
let asset_definition_id =
AssetDefinitionId::new(&format!("xor-{}", num), &format!("wonderland-{}", num))
.expect("Valid");
let create_asset = RegisterBox::new(IdentifiableBox::from(
AssetDefinition::new_quantity(asset_definition_id.clone()),
));
let create_asset =
RegisterBox::new(AssetDefinition::new_quantity(asset_definition_id.clone()));
ret.push(GenesisTransaction {
isi: small::SmallVec(smallvec::smallvec![create_asset.into()]),
});
Expand Down
9 changes: 3 additions & 6 deletions client/examples/million_accounts_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ fn create_million_accounts_directly() {
for i in 0_u32..1_000_000_u32 {
let domain_name = format!("wonderland-{}", i);
let normal_account_id = AccountId::new(&format!("bob-{}", i), &domain_name).expect("Valid");
let create_domain = RegisterBox::new(IdentifiableBox::from(Domain::new(
DomainId::new(&domain_name).expect("Valid"),
)));
let create_account = RegisterBox::new(IdentifiableBox::from(NewAccount::new(
normal_account_id.clone(),
)));
let create_domain =
RegisterBox::new(Domain::new(DomainId::new(&domain_name).expect("Valid")));
let create_account = RegisterBox::new(Account::new(normal_account_id.clone(), []));
if test_client
.submit_all([create_domain.into(), create_account.into()].to_vec())
.is_err()
Expand Down
9 changes: 3 additions & 6 deletions client/examples/ten_million_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ fn create_million_accounts_directly() {
for i in 0_u32..10_000_000_u32 {
let domain_name = format!("wonderland-{}", i);
let normal_account_id = AccountId::new(&format!("bob-{}", i), &domain_name).expect("Valid");
let create_domain = RegisterBox::new(IdentifiableBox::from(Domain::new(
DomainId::new(&domain_name).expect("Valid"),
)));
let create_account = RegisterBox::new(IdentifiableBox::from(NewAccount::new(
normal_account_id.clone(),
)));
let create_domain =
RegisterBox::new(Domain::new(DomainId::new(&domain_name).expect("Valid")));
let create_account = RegisterBox::new(Account::new(normal_account_id.clone(), []));
if test_client
.submit_all([create_domain.into(), create_account.into()].to_vec())
.is_err()
Expand Down
8 changes: 2 additions & 6 deletions client/tests/integration/add_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@ fn client_add_account_with_name_length_more_than_limit_should_not_commit_transac
let pipeline_time = super::Configuration::pipeline_time();

let normal_account_id = AccountId::new("bob", "wonderland").expect("Valid");
let create_account = RegisterBox::new(IdentifiableBox::from(NewAccount::new(
normal_account_id.clone(),
)));
let create_account = RegisterBox::new(Account::new(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::new(&too_long_account_name, "wonderland").expect("Valid");
let create_account = RegisterBox::new(IdentifiableBox::from(NewAccount::new(
incorrect_account_id.clone(),
)));
let create_account = RegisterBox::new(Account::new(incorrect_account_id.clone(), []));
test_client.submit(create_account)?;

thread::sleep(pipeline_time * 2);
Expand Down
19 changes: 8 additions & 11 deletions client/tests/integration/add_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount() ->
// Given
let account_id = AccountId::new("alice", "wonderland").expect("Valid");
let asset_definition_id = AssetDefinitionId::new("xor", "wonderland").expect("Valid");
let create_asset = RegisterBox::new(IdentifiableBox::from(AssetDefinition::new_quantity(
asset_definition_id.clone(),
)));
let create_asset = RegisterBox::new(AssetDefinition::new_quantity(asset_definition_id.clone()));
let metadata = iroha_data_model::metadata::UnlimitedMetadata::default();
//When
let quantity: u32 = 200;
Expand Down Expand Up @@ -50,9 +48,9 @@ fn client_add_big_asset_quantity_to_existing_asset_should_increase_asset_amount(
// Given
let account_id = AccountId::new("alice", "wonderland").expect("Valid");
let asset_definition_id = AssetDefinitionId::new("xor", "wonderland").expect("Valid");
let create_asset = RegisterBox::new(IdentifiableBox::from(AssetDefinition::new_big_quantity(
let create_asset = RegisterBox::new(AssetDefinition::new_big_quantity(
asset_definition_id.clone(),
)));
));
let metadata = iroha_data_model::metadata::UnlimitedMetadata::default();
//When
let quantity: u128 = 2_u128.pow(65);
Expand Down Expand Up @@ -82,8 +80,7 @@ fn client_add_asset_with_decimal_should_increase_asset_amount() -> Result<()> {
// Given
let account_id = AccountId::new("alice", "wonderland").expect("Valid");
let asset_definition_id = AssetDefinitionId::new("xor", "wonderland").expect("Valid");
let identifiable_box =
IdentifiableBox::from(AssetDefinition::with_precision(asset_definition_id.clone()));
let identifiable_box = AssetDefinition::new_fixed_precision(asset_definition_id.clone());
let create_asset = RegisterBox::new(identifiable_box);
let metadata = iroha_data_model::metadata::UnlimitedMetadata::default();

Expand Down Expand Up @@ -135,18 +132,18 @@ fn client_add_asset_with_name_length_more_than_limit_should_not_commit_transacti

// Given
let normal_asset_definition_id = AssetDefinitionId::new("xor", "wonderland").expect("Valid");
let create_asset = RegisterBox::new(IdentifiableBox::from(AssetDefinition::new_quantity(
let create_asset = RegisterBox::new(AssetDefinition::new_quantity(
normal_asset_definition_id.clone(),
)));
));
test_client.submit(create_asset)?;
iroha_logger::info!("Creating asset");

let too_long_asset_name = "0".repeat(2_usize.pow(14));
let incorrect_asset_definition_id =
AssetDefinitionId::new(&too_long_asset_name, "wonderland").expect("Valid");
let create_asset = RegisterBox::new(IdentifiableBox::from(AssetDefinition::new_quantity(
let create_asset = RegisterBox::new(AssetDefinition::new_quantity(
incorrect_asset_definition_id.clone(),
)));
));

test_client.submit(create_asset)?;
iroha_logger::info!("Creating another asset");
Expand Down
8 changes: 2 additions & 6 deletions client/tests/integration/add_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@ fn client_add_domain_with_name_length_more_than_limit_should_not_commit_transact
// Given

let normal_domain_name = DomainId::new("sora")?;
let create_domain = RegisterBox::new(IdentifiableBox::from(Domain::new(
normal_domain_name.clone(),
)));
let create_domain = RegisterBox::new(Domain::new(normal_domain_name.clone()));
test_client.submit(create_domain)?;

let too_long_domain_name = DomainId::new(&"0".repeat(2_usize.pow(14)))?;
let create_domain = RegisterBox::new(IdentifiableBox::from(Domain::new(
too_long_domain_name.clone(),
)));
let create_domain = RegisterBox::new(Domain::new(too_long_domain_name.clone()));
test_client.submit(create_domain)?;

thread::sleep(pipeline_time * 2);
Expand Down
13 changes: 5 additions & 8 deletions client/tests/integration/asset_propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@ fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount_on_a
wait_for_genesis_committed(&network.clients(), 0);
let pipeline_time = Configuration::pipeline_time();

let create_domain = RegisterBox::new(IdentifiableBox::Domain(
Domain::new(DomainId::new("domain")?).into(),
));
let create_domain = RegisterBox::new(Domain::new(DomainId::new("domain")?));
let account_id = AccountId::new("account", "domain")?;
let create_account = RegisterBox::new(IdentifiableBox::NewAccount(
NewAccount::with_signatory(account_id.clone(), KeyPair::generate()?.public_key).into(),
let create_account = RegisterBox::new(Account::new(
account_id.clone(),
[KeyPair::generate()?.public_key],
));
let asset_definition_id = AssetDefinitionId::new("xor", "domain")?;
let create_asset = RegisterBox::new(IdentifiableBox::AssetDefinition(
AssetDefinition::new_quantity(asset_definition_id.clone()).into(),
));
let create_asset = RegisterBox::new(AssetDefinition::new_quantity(asset_definition_id.clone()));
iroha_client.submit_all(vec![
create_domain.into(),
create_account.into(),
Expand Down
11 changes: 6 additions & 5 deletions client/tests/integration/burn_public_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ fn submit_and_get(

fn account_keys_count(client: &mut Client, account_id: AccountId) -> usize {
let account = client.request(account::by_id(account_id)).unwrap();
account.signatories.len()
let signatories = account.signatories();
signatories.len()
}

#[test]
Expand All @@ -33,7 +34,7 @@ fn public_keys_cannot_be_burned_to_nothing() {
let (_rt, _peer, mut client) = <TestPeer>::start_test_with_runtime();
wait_for_genesis_committed(&vec![client.clone()], 0);

let register_bob = RegisterBox::new(NewAccount::new(bob_id.clone())).into();
let register_bob = RegisterBox::new(Account::new(bob_id.clone(), [])).into();

let _ = submit_and_get(&mut client, [register_bob]);
let mut keys_count = bob_keys_count(&mut client);
Expand All @@ -47,16 +48,16 @@ fn public_keys_cannot_be_burned_to_nothing() {
assert_eq!(keys_count, KEYS_COUNT);

let bob = client.request(account::by_id(bob_id.clone())).unwrap();
let mut keys = bob.signatories.into_iter();
let mut keys = bob.signatories();
let burn = |key: PublicKey| Instruction::from(BurnBox::new(key, bob_id.clone()));
let burn_keys_leaving_one = keys.by_ref().take(KEYS_COUNT - 1).map(burn);
let burn_keys_leaving_one = keys.by_ref().take(KEYS_COUNT - 1).cloned().map(burn);

let mut committed_txn = submit_and_get(&mut client, burn_keys_leaving_one);
keys_count = bob_keys_count(&mut client);
assert_eq!(keys_count, 1);
assert!(matches!(committed_txn, TransactionValue::Transaction(_)));

let burn_the_last_key = keys.map(burn);
let burn_the_last_key = keys.cloned().map(burn);

committed_txn = submit_and_get(&mut client, burn_the_last_key);
keys_count = bob_keys_count(&mut client);
Expand Down
5 changes: 2 additions & 3 deletions client/tests/integration/connected_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ fn connected_peers_with_f(faults: u64) {

// Re-register the peer: committed with f = `faults` - 1 then
// `status.peers` increments
let register_peer = RegisterBox::new(IdentifiableBox::Peer(
DataModelPeer::new(peer.id.clone()).into(),
));
let register_peer =
RegisterBox::new(IdentifiableBox::Peer(DataModelPeer::new(peer.id.clone())));
genesis_client.submit(register_peer).unwrap();
thread::sleep(pipeline_time * 4);
status = genesis_client.get_status().unwrap();
Expand Down
Loading

0 comments on commit 66ddf1d

Please sign in to comment.