Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic committed Jun 19, 2024
1 parent 0d21b35 commit f682e7c
Show file tree
Hide file tree
Showing 62 changed files with 1,170 additions and 668 deletions.
6 changes: 3 additions & 3 deletions client/benches/tps/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use iroha::{
crypto::KeyPair,
data_model::{
events::pipeline::{BlockEventFilter, BlockStatus},
param::BlockParameter,
prelude::*,
},
};
use iroha_data_model::param::BlockLimits;
use nonzero_ext::nonzero;
use serde::Deserialize;
use test_network::*;
Expand All @@ -22,7 +22,7 @@ pub struct Config {
pub peers: u32,
/// Interval in microseconds between transactions to reduce load
pub interval_us_per_tx: u64,
pub block_limits: BlockLimits,
pub block_limits: BlockParameter,
pub blocks: u32,
pub sample_size: u32,
pub genesis_max_retries: u32,
Expand Down Expand Up @@ -51,7 +51,7 @@ impl Config {
let clients = network.clients();
wait_for_genesis_committed_with_max_retries(&clients, 0, self.genesis_max_retries);

client.submit_blocking(SetParameter::new(Parameter::BlockLimits(self.block_limits)))?;
client.submit_blocking(SetParameter::new(Parameter::Block(self.block_limits)))?;

let unit_names = (UnitName::MIN..).take(self.peers as usize);
let units = clients
Expand Down
8 changes: 5 additions & 3 deletions client/src/config/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ use iroha_config_base::{
util::{DurationMs, Emitter, EmitterResultExt},
ReadConfig, WithOrigin,
};
use iroha_crypto::{KeyPair, PrivateKey, PublicKey};
use iroha_data_model::prelude::{AccountId, ChainId, DomainId};
use url::Url;

use crate::config::BasicAuth;
use crate::{
config::BasicAuth,
crypto::{KeyPair, PrivateKey, PublicKey},
data_model::prelude::{AccountId, ChainId, DomainId},
};

/// Root of the user configuration
#[derive(Clone, Debug, ReadConfig)]
Expand Down
12 changes: 6 additions & 6 deletions client/tests/integration/asset_propagation.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::{num::NonZeroU64, str::FromStr as _, thread};
use std::{str::FromStr as _, thread};

use eyre::Result;
use iroha::{
client::{self, QueryResult},
data_model::prelude::*,
data_model::{param::BlockParameter, prelude::*},
};
use iroha_config::parameters::actual::Root as Config;
use iroha_data_model::param::BlockLimits;
use nonzero_ext::nonzero;
use test_network::*;
use test_samples::gen_account_in;

Expand All @@ -20,9 +20,9 @@ fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount_on_a
wait_for_genesis_committed(&network.clients(), 0);
let pipeline_time = Config::pipeline_time();

client.submit_blocking(SetParameter::new(Parameter::BlockLimits(BlockLimits {
max_transactions: NonZeroU64::new(1).unwrap(),
})))?;
client.submit_blocking(SetParameter::new(Parameter::Block(
BlockParameter::MaxTransactions(nonzero!(1_u64)),
)))?;

let create_domain: InstructionBox =
Register::domain(Domain::new(DomainId::from_str("domain")?)).into();
Expand Down
22 changes: 11 additions & 11 deletions client/tests/integration/events/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ fn transaction_execution_should_produce_events(
iroha_logger::info!("Event: {:?}", event);
assert!(matches!(event, DataEvent::Domain(_)));
if let DataEvent::Domain(domain_event) = event {
assert!(matches!(domain_event, DomainEvent::Create(_)));
assert!(matches!(domain_event, DomainEvent::Created(_)));

if let DomainEvent::Create(created_domain) = domain_event {
if let DomainEvent::Created(created_domain) = domain_event {
let domain_id = DomainId::new(i.to_string().parse().expect("Valid"));
assert_eq!(domain_id, *created_domain.id());
}
Expand Down Expand Up @@ -226,9 +226,9 @@ fn produce_multiple_events() -> Result<()> {
let event: DataEvent = event_receiver.recv()??.try_into()?;
assert!(matches!(event, DataEvent::Role(_)));
if let DataEvent::Role(role_event) = event {
assert!(matches!(role_event, RoleEvent::Create(_)));
assert!(matches!(role_event, RoleEvent::Created(_)));

if let RoleEvent::Create(created_role) = role_event {
if let RoleEvent::Created(created_role) = role_event {
assert_eq!(created_role.id(), role.id());
assert!(created_role
.permissions()
Expand All @@ -237,43 +237,43 @@ fn produce_multiple_events() -> Result<()> {
}

let expected_domain_events: Vec<DataEvent> = [
DataEvent::Domain(DomainEvent::Account(AccountEvent::PermissionAdd(
DataEvent::Domain(DomainEvent::Account(AccountEvent::PermissionAdded(
AccountPermissionChanged {
account: bob_id.clone(),
permission: token_1.id.clone(),
},
))),
DataEvent::Domain(DomainEvent::Account(AccountEvent::PermissionAdd(
DataEvent::Domain(DomainEvent::Account(AccountEvent::PermissionAdded(
AccountPermissionChanged {
account: bob_id.clone(),
permission: token_2.id.clone(),
},
))),
DataEvent::Domain(DomainEvent::Account(AccountEvent::RoleGrant(
DataEvent::Domain(DomainEvent::Account(AccountEvent::RoleGranted(
AccountRoleChanged {
account: bob_id.clone(),
role: role_id.clone(),
},
))),
DataEvent::Domain(DomainEvent::Account(AccountEvent::PermissionRemove(
DataEvent::Domain(DomainEvent::Account(AccountEvent::PermissionRemoved(
AccountPermissionChanged {
account: bob_id.clone(),
permission: token_1.id,
},
))),
DataEvent::Domain(DomainEvent::Account(AccountEvent::PermissionRemove(
DataEvent::Domain(DomainEvent::Account(AccountEvent::PermissionRemoved(
AccountPermissionChanged {
account: bob_id.clone(),
permission: token_2.id,
},
))),
DataEvent::Domain(DomainEvent::Account(AccountEvent::RoleRevoke(
DataEvent::Domain(DomainEvent::Account(AccountEvent::RoleRevoked(
AccountRoleChanged {
account: bob_id,
role: role_id.clone(),
},
))),
DataEvent::Role(RoleEvent::Delete(role_id)),
DataEvent::Role(RoleEvent::Deleted(role_id)),
]
.into_iter()
.map(Into::into)
Expand Down
14 changes: 6 additions & 8 deletions client/tests/integration/events/pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
num::NonZeroU64,
thread::{self, JoinHandle},
};
use std::thread::{self, JoinHandle};

use eyre::Result;
use iroha::{
Expand All @@ -11,13 +8,14 @@ use iroha::{
BlockEvent, BlockEventFilter, BlockStatus, TransactionEventFilter, TransactionStatus,
},
isi::error::InstructionExecutionError,
param::BlockParameter,
prelude::*,
transaction::error::TransactionRejectionReason,
ValidationFail,
},
};
use iroha_config::parameters::actual::Root as Config;
use iroha_data_model::param::BlockLimits;
use nonzero_ext::nonzero;
use test_network::*;

// Needed to re-enable ignored tests.
Expand Down Expand Up @@ -56,9 +54,9 @@ fn test_with_instruction_and_status_and_port(
wait_for_genesis_committed(&clients, 0);
let pipeline_time = Config::pipeline_time();

client.submit_blocking(SetParameter::new(Parameter::BlockLimits(BlockLimits {
max_transactions: NonZeroU64::new(1).unwrap(),
})))?;
client.submit_blocking(SetParameter::new(Parameter::Block(
BlockParameter::MaxTransactions(nonzero!(1_u64)),
)))?;

// Given
let submitter = client;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::{num::NonZeroU64, thread};
use std::thread;

use eyre::Result;
use iroha::{
client::{self, Client, QueryResult},
data_model::prelude::*,
data_model::{param::BlockParameter, prelude::*},
};
use iroha_config::parameters::actual::Root as Config;
use iroha_data_model::param::BlockLimits;
use nonzero_ext::nonzero;
use test_network::*;
use test_samples::gen_account_in;

Expand All @@ -20,9 +20,9 @@ fn long_multiple_blocks_created() -> Result<()> {
wait_for_genesis_committed(&network.clients(), 0);
let pipeline_time = Config::pipeline_time();

client.submit_blocking(SetParameter::new(Parameter::BlockLimits(BlockLimits {
max_transactions: NonZeroU64::new(1).unwrap(),
})))?;
client.submit_blocking(SetParameter::new(Parameter::Block(
BlockParameter::MaxTransactions(nonzero!(1_u64)),
)))?;

let create_domain: InstructionBox = Register::domain(Domain::new("domain".parse()?)).into();
let (account_id, _account_keypair) = gen_account_in("domain");
Expand Down
15 changes: 8 additions & 7 deletions client/tests/integration/extra_functional/normal.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::num::NonZeroU64;

use iroha::client::{self, Client};
use iroha::{
client::{self, Client},
data_model::{asset::AssetDefinitionId, param::BlockParameter, prelude::*},
};
use iroha_config::parameters::actual::Root as Config;
use iroha_data_model::{asset::AssetDefinitionId, param::BlockLimits, prelude::*};
use nonzero_ext::nonzero;
use test_network::*;
use tokio::runtime::Runtime;

Expand All @@ -20,9 +21,9 @@ fn tranasctions_should_be_applied() {
});
wait_for_genesis_committed(&network.clients(), 0);
iroha
.submit_blocking(SetParameter::new(Parameter::BlockLimits(BlockLimits {
max_transactions: NonZeroU64::new(1).unwrap(),
})))
.submit_blocking(SetParameter::new(Parameter::Block(
BlockParameter::MaxTransactions(nonzero!(1_u64)),
)))
.unwrap();

let domain_id = "and".parse::<DomainId>().unwrap();
Expand Down
12 changes: 6 additions & 6 deletions client/tests/integration/extra_functional/unregister_peer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::{num::NonZeroU64, thread};
use std::thread;

use eyre::Result;
use iroha::{
client::{self, QueryResult},
data_model::prelude::*,
data_model::{param::BlockParameter, prelude::*},
};
use iroha_config::parameters::actual::Root as Config;
use iroha_data_model::param::BlockLimits;
use nonzero_ext::nonzero;
use test_network::*;
use test_samples::gen_account_in;

Expand Down Expand Up @@ -116,9 +116,9 @@ fn init() -> Result<(
let pipeline_time = Config::pipeline_time();
iroha_logger::info!("Started");

let set_max_txns_in_block = SetParameter::new(Parameter::BlockLimits(BlockLimits {
max_transactions: NonZeroU64::new(1).unwrap(),
}));
let set_max_txns_in_block = SetParameter::new(Parameter::Block(
BlockParameter::MaxTransactions(nonzero!(1_u64)),
));

let create_domain = Register::domain(Domain::new("domain".parse()?));
let (account_id, _account_keypair) = gen_account_in("domain");
Expand Down
22 changes: 15 additions & 7 deletions client/tests/integration/set_parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use std::time::Duration;
use eyre::Result;
use iroha::{
client,
data_model::{param::Parameter, prelude::*},
data_model::{
param::{Parameter, Parameters, SumeragiParameter, SumeragiParameters},
prelude::*,
},
};
use iroha_data_model::param::Parameters;
use test_network::*;

#[test]
Expand All @@ -14,15 +16,21 @@ fn can_change_parameter_value() -> Result<()> {
wait_for_genesis_committed(&vec![test_client.clone()], 0);

let old_params: Parameters = test_client.request(client::parameter::all())?;
assert_eq!(old_params.block_time, Parameters::default().block_time);
assert_eq!(
old_params.sumeragi().block_time(),
SumeragiParameters::default().block_time()
);

let block_time = Duration::from_millis(40_000);
let parameter = Parameter::BlockTime(block_time);
let block_time = 40_000;
let parameter = Parameter::Sumeragi(SumeragiParameter::BlockTimeMs(block_time));
let set_param_isi = SetParameter::new(parameter);
test_client.submit_blocking(set_param_isi)?;

let new_params = test_client.request(client::parameter::all())?;
assert_eq!(new_params.block_time, block_time);
let sumeragi_params = test_client.request(client::parameter::all())?.sumeragi;
assert_eq!(
sumeragi_params.block_time(),
Duration::from_millis(block_time)
);

Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions client/tests/integration/smartcontracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"mint_rose_trigger",
"executor_with_admin",
"executor_with_custom_permission",
"executor_with_custom_parameter",
"executor_remove_permission",
"executor_with_migration_fail",
"executor_custom_instructions_simple",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "executor_with_custom_parameter"

edition.workspace = true
version.workspace = true
authors.workspace = true

license.workspace = true

[lib]
crate-type = ['cdylib']

[dependencies]
iroha_executor.workspace = true
iroha_schema.workspace = true

parity-scale-codec.workspace = true
anyhow.workspace = true
serde_json.workspace = true
serde.workspace = true

panic-halt.workspace = true
lol_alloc.workspace = true
getrandom.workspace = true
Loading

0 comments on commit f682e7c

Please sign in to comment.