Skip to content

Commit

Permalink
Disallow the use of boxed instruction types
Browse files Browse the repository at this point in the history
Signed-off-by: Daniil Polyakov <[email protected]>
  • Loading branch information
Arjentix committed Dec 12, 2023
1 parent 70cfca9 commit e1de609
Show file tree
Hide file tree
Showing 66 changed files with 1,352 additions and 889 deletions.
15 changes: 8 additions & 7 deletions client/benches/torii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use iroha_client::{
data_model::prelude::*,
};
use iroha_crypto::KeyPair;
use iroha_data_model::isi::InstructionBox;
use iroha_genesis::{GenesisNetwork, RawGenesisBlockBuilder};
use iroha_primitives::unique_vec;
use iroha_version::Encode;
Expand Down Expand Up @@ -51,17 +52,17 @@ fn query_requests(criterion: &mut Criterion) {
});
let mut group = criterion.benchmark_group("query-requests");
let domain_id: DomainId = "domain".parse().expect("Valid");
let create_domain = RegisterBox::domain(Domain::new(domain_id.clone()));
let create_domain = Register::domain(Domain::new(domain_id.clone()));
let account_id = AccountId::new("account".parse().expect("Valid"), domain_id.clone());
let (public_key, _) = KeyPair::generate()
.expect("Failed to generate KeyPair")
.into();
let create_account = RegisterBox::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("xor".parse().expect("Valid"), domain_id);
let create_asset =
RegisterBox::asset_definition(AssetDefinition::quantity(asset_definition_id.clone()));
Register::asset_definition(AssetDefinition::quantity(asset_definition_id.clone()));
let quantity: u32 = 200;
let mint_asset = MintBox::asset_quantity(
let mint_asset = Mint::asset_quantity(
quantity,
AssetId::new(asset_definition_id, account_id.clone()),
);
Expand Down Expand Up @@ -141,12 +142,12 @@ fn instruction_submits(criterion: &mut Criterion) {
rt.block_on(builder.start_with_peer(&mut peer));
let mut group = criterion.benchmark_group("instruction-requests");
let domain_id: DomainId = "domain".parse().expect("Valid");
let create_domain = RegisterBox::domain(Domain::new(domain_id.clone()));
let create_domain: InstructionBox = Register::domain(Domain::new(domain_id.clone())).into();
let account_id = AccountId::new("account".parse().expect("Valid"), domain_id.clone());
let (public_key, _) = KeyPair::generate()
.expect("Failed to generate Key-pair.")
.into();
let create_account = RegisterBox::account(Account::new(account_id.clone(), [public_key]));
let create_account = Register::account(Account::new(account_id.clone(), [public_key])).into();
let asset_definition_id = AssetDefinitionId::new("xor".parse().expect("Valid"), domain_id);
let mut client_config = iroha_client::samples::get_client_config(&get_key_pair());
client_config.torii_api_url = format!("http://{}", peer.api_address).parse().unwrap();
Expand All @@ -161,7 +162,7 @@ fn instruction_submits(criterion: &mut Criterion) {
let _dropable = group.bench_function("instructions", |b| {
b.iter(|| {
let quantity: u32 = 200;
let mint_asset = MintBox::asset_quantity(
let mint_asset = Mint::asset_quantity(
quantity,
AssetId::new(asset_definition_id.clone(), account_id.clone()),
);
Expand Down
12 changes: 6 additions & 6 deletions client/benches/tps/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl MeasurerUnit {
let alice_id = AccountId::from_str("alice@wonderland")?;
let asset_id = asset_id(self.name);

let register_me = RegisterBox::account(Account::new(
let register_me = Register::account(Account::new(
account_id.clone(),
[keypair.public_key().clone()],
));
Expand All @@ -183,13 +183,13 @@ impl MeasurerUnit {
&json!({ "asset_id": asset_id }),
);
let allow_alice_to_burn_my_asset =
GrantBox::permission_token(can_burn_my_asset, alice_id.clone());
Grant::permission_token(can_burn_my_asset, alice_id.clone());
let can_transfer_my_asset = PermissionToken::new(
"CanTransferUserAsset".parse().unwrap(),
&json!({ "asset_id": asset_id }),
);
let allow_alice_to_transfer_my_asset =
GrantBox::permission_token(can_transfer_my_asset, alice_id);
Grant::permission_token(can_transfer_my_asset, alice_id);
let grant_tx = TransactionBuilder::new(account_id)
.with_instructions([
allow_alice_to_burn_my_asset,
Expand All @@ -198,7 +198,7 @@ impl MeasurerUnit {
.sign(keypair)?;
self.client.submit_transaction_blocking(&grant_tx)?;

let mint_a_rose = MintBox::asset_quantity(1_u32, asset_id);
let mint_a_rose = Mint::asset_quantity(1_u32, asset_id);
self.client.submit_blocking(mint_a_rose)?;

Ok(self)
Expand Down Expand Up @@ -277,11 +277,11 @@ impl MeasurerUnit {
}

fn mint(&self) -> InstructionBox {
MintBox::asset_quantity(1_u32, asset_id(self.name)).into()
Mint::asset_quantity(1_u32, asset_id(self.name)).into()
}

fn transfer(&self) -> InstructionBox {
TransferBox::asset_quantity(asset_id(self.name), 1_u32, account_id(self.next_name)).into()
Transfer::asset_quantity(asset_id(self.name), 1_u32, account_id(self.next_name)).into()
}
}

Expand Down
5 changes: 3 additions & 2 deletions client/examples/million_accounts_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{thread, time::Duration};

use iroha::samples::{construct_executor, get_config};
use iroha_client::data_model::prelude::*;
use iroha_data_model::isi::InstructionBox;
use iroha_genesis::{GenesisNetwork, RawGenesisBlock, RawGenesisBlockBuilder};
use iroha_primitives::unique_vec;
use test_network::{
Expand Down Expand Up @@ -64,8 +65,8 @@ fn create_million_accounts_directly() {
format!("bob-{i}").parse().expect("Valid"),
domain_id.clone(),
);
let create_domain = RegisterBox::domain(Domain::new(domain_id));
let create_account = RegisterBox::account(Account::new(normal_account_id.clone(), []));
let create_domain: InstructionBox = Register::domain(Domain::new(domain_id)).into();
let create_account = Register::account(Account::new(normal_account_id.clone(), [])).into();
if test_client
.submit_all([create_domain, create_account])
.is_err()
Expand Down
26 changes: 13 additions & 13 deletions client/examples/tutorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn domain_registration_test(config: &Configuration) -> Result<(), Error> {
client::Client,
data_model::{
metadata::UnlimitedMetadata,
prelude::{Domain, DomainId, InstructionBox, RegisterBox},
prelude::{Domain, DomainId, InstructionBox, Register},
},
};
// #endregion domain_register_example_crates
Expand All @@ -62,7 +62,7 @@ fn domain_registration_test(config: &Configuration) -> Result<(), Error> {

// #region domain_register_example_create_isi
// Create an ISI
let create_looking_glass = RegisterBox::domain(Domain::new(looking_glass));
let create_looking_glass = Register::domain(Domain::new(looking_glass));
// #endregion domain_register_example_create_isi

// #region rust_client_create
Expand Down Expand Up @@ -116,7 +116,7 @@ fn account_registration_test(config: &Configuration) -> Result<(), Error> {
client::Client,
data_model::{
metadata::UnlimitedMetadata,
prelude::{Account, AccountId, InstructionBox, RegisterBox},
prelude::{Account, AccountId, InstructionBox, Register},
},
};
use iroha_crypto::KeyPair;
Expand All @@ -140,7 +140,7 @@ fn account_registration_test(config: &Configuration) -> Result<(), Error> {

// #region register_account_generate
// Generate a new account
let create_account = RegisterBox::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
Expand All @@ -167,7 +167,7 @@ fn asset_registration_test(config: &Configuration) -> Result<(), Error> {
use iroha_client::{
client::Client,
data_model::prelude::{
AccountId, AssetDefinition, AssetDefinitionId, AssetId, MintBox, RegisterBox,
AccountId, AssetDefinition, AssetDefinitionId, AssetId, Mint, Register,
},
};
// #endregion register_asset_crates
Expand All @@ -184,7 +184,7 @@ fn asset_registration_test(config: &Configuration) -> Result<(), Error> {
// #region register_asset_init_submit
// Initialise the registration time
let register_time =
RegisterBox::asset_definition(AssetDefinition::fixed(asset_def_id.clone()).mintable_once());
Register::asset_definition(AssetDefinition::fixed(asset_def_id.clone()).mintable_once());

// Submit a registration time
iroha_client.submit(register_time)?;
Expand All @@ -197,7 +197,7 @@ fn asset_registration_test(config: &Configuration) -> Result<(), Error> {

// #region register_asset_mint_submit
// Create a MintBox using a previous asset and account
let mint = MintBox::asset_fixed(
let mint = Mint::asset_fixed(
12.34_f64.try_into()?,
AssetId::new(asset_def_id, account_id),
);
Expand All @@ -216,7 +216,7 @@ fn asset_minting_test(config: &Configuration) -> Result<(), Error> {

use iroha_client::{
client::Client,
data_model::prelude::{AccountId, AssetDefinitionId, AssetId, MintBox},
data_model::prelude::{AccountId, AssetDefinitionId, AssetId, Mint},
};
// #endregion mint_asset_crates

Expand All @@ -233,7 +233,7 @@ fn asset_minting_test(config: &Configuration) -> Result<(), Error> {

// Mint the Asset instance
// #region mint_asset_mint
let mint_roses = MintBox::asset_quantity(42_u32, AssetId::new(roses, alice));
let mint_roses = Mint::asset_quantity(42_u32, AssetId::new(roses, alice));
// #endregion mint_asset_mint

// #region mint_asset_submit_tx
Expand All @@ -248,7 +248,7 @@ fn asset_minting_test(config: &Configuration) -> Result<(), Error> {
// or `roses.to_string() + "#" + alice.to_string()`.
// The `##` is a short-hand for the rose `which belongs to the same domain as the account
// to which it belongs to.
let mint_roses_alt = MintBox::asset_quantity(10_u32, "rose##alice@wonderland".parse()?);
let mint_roses_alt = Mint::asset_quantity(10_u32, "rose##alice@wonderland".parse()?);
// #endregion mint_asset_mint_alt

// #region mint_asset_submit_tx_alt
Expand All @@ -267,7 +267,7 @@ fn asset_burning_test(config: &Configuration) -> Result<(), Error> {

use iroha_client::{
client::Client,
data_model::prelude::{AccountId, AssetDefinitionId, AssetId, BurnBox},
data_model::prelude::{AccountId, AssetDefinitionId, AssetId, Burn},
};
// #endregion burn_asset_crates

Expand All @@ -284,7 +284,7 @@ fn asset_burning_test(config: &Configuration) -> Result<(), Error> {

// #region burn_asset_burn
// Burn the Asset instance
let burn_roses = BurnBox::asset_quantity(10_u32, AssetId::new(roses, alice));
let burn_roses = Burn::asset_quantity(10_u32, AssetId::new(roses, alice));
// #endregion burn_asset_burn

// #region burn_asset_submit_tx
Expand All @@ -299,7 +299,7 @@ fn asset_burning_test(config: &Configuration) -> Result<(), Error> {
// or `roses.to_string() + "#" + alice.to_string()`.
// The `##` is a short-hand for the rose `which belongs to the same domain as the account
// to which it belongs to.
let burn_roses_alt = BurnBox::asset_quantity(10_u32, "rose##alice@wonderland".parse()?);
let burn_roses_alt = Burn::asset_quantity(10_u32, "rose##alice@wonderland".parse()?);
// #endregion burn_asset_burn_alt

// #region burn_asset_submit_tx_alt
Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/add_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ 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 = "bob@wonderland".parse().expect("Valid");
let create_account = RegisterBox::account(Account::new(normal_account_id.clone(), []));
let create_account = Register::account(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 = (too_long_account_name + "@wonderland")
.parse()
.expect("Valid");
let create_account = RegisterBox::account(Account::new(incorrect_account_id.clone(), []));
let create_account = Register::account(Account::new(incorrect_account_id.clone(), []));
test_client.submit(create_account)?;

thread::sleep(pipeline_time * 2);
Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/add_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ fn client_add_domain_with_name_length_more_than_limit_should_not_commit_transact
// Given

let normal_domain_id: DomainId = "sora".parse()?;
let create_domain = RegisterBox::domain(Domain::new(normal_domain_id.clone()));
let create_domain = Register::domain(Domain::new(normal_domain_id.clone()));
test_client.submit(create_domain)?;

let too_long_domain_name: DomainId = "0".repeat(2_usize.pow(14)).parse()?;
let create_domain = RegisterBox::domain(Domain::new(too_long_domain_name.clone()));
let create_domain = Register::domain(Domain::new(too_long_domain_name.clone()));
test_client.submit(create_domain)?;

thread::sleep(pipeline_time * 2);
Expand Down
Loading

0 comments on commit e1de609

Please sign in to comment.