Skip to content

Commit

Permalink
[fix] #3440: Stop supporting asset conversion
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 authored and appetrosyan committed May 8, 2023
1 parent b316abe commit cbc3bfe
Show file tree
Hide file tree
Showing 19 changed files with 219 additions and 354 deletions.
12 changes: 6 additions & 6 deletions client/benches/tps/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ impl MeasurerUnit {

fn mint_or_burn(&self) -> InstructionBox {
let is_running_out = Less::new(
EvaluatesTo::new_unchecked(
Expression::Query(FindAssetQuantityById::new(asset_id(self.name)).into()).into(),
),
EvaluatesTo::new_unchecked(Expression::Query(
FindAssetQuantityById::new(asset_id(self.name)).into(),
)),
100_u32,
);
let supply_roses = MintBox::new(100_u32.to_value(), asset_id(self.name));
Expand All @@ -279,9 +279,9 @@ impl MeasurerUnit {
// because if asset value hits 0 it's automatically deleted from account
// and query `FindAssetQuantityById` return error
let enough_to_transfer = Greater::new(
EvaluatesTo::new_unchecked(
Expression::Query(FindAssetQuantityById::new(asset_id(self.name)).into()).into(),
),
EvaluatesTo::new_unchecked(Expression::Query(
FindAssetQuantityById::new(asset_id(self.name)).into(),
)),
1_u32,
);
let transfer_rose = TransferBox::new(
Expand Down
90 changes: 41 additions & 49 deletions client/tests/integration/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ fn find_rate_and_make_exchange_isi_should_succeed() {
));
};

let buyer_account_id = account_id_new("buyer", "company");
let seller_account_id = account_id_new("seller", "company");
let asset_id = asset_id_new(
"btc2eth_rate",
"exchange",
account_id_new("dex", "exchange"),
);
test_client
.submit_all_blocking(vec![
register::domain("exchange").into(),
Expand All @@ -291,19 +298,15 @@ fn find_rate_and_make_exchange_isi_should_succeed() {
register::asset_definition("btc2eth_rate", "exchange").into(),
MintBox::new(
200_u32.to_value(),
IdBox::AssetId(asset_id_new("eth", "crypto", "buyer", "company")),
)
.into(),
MintBox::new(
20_u32.to_value(),
IdBox::AssetId(asset_id_new("btc", "crypto", "seller", "company")),
IdBox::AssetId(asset_id_new("eth", "crypto", buyer_account_id.clone())),
)
.into(),
MintBox::new(
20_u32.to_value(),
IdBox::AssetId(asset_id_new("btc2eth_rate", "exchange", "dex", "exchange")),
IdBox::AssetId(asset_id_new("btc", "crypto", seller_account_id.clone())),
)
.into(),
MintBox::new(20_u32.to_value(), IdBox::AssetId(asset_id.clone())).into(),
])
.expect("Failed to prepare accounts.");

Expand All @@ -313,36 +316,18 @@ fn find_rate_and_make_exchange_isi_should_succeed() {
test_client
.submit_all_blocking(vec![Pair::new(
TransferBox::new(
IdBox::AssetId(asset_id_new("btc", "crypto", "seller", "company")),
EvaluatesTo::new_evaluates_to_value(
Expression::Query(
FindAssetQuantityById::new(asset_id_new(
"btc2eth_rate",
"exchange",
"dex",
"exchange",
))
.into(),
)
.into(),
),
IdBox::AssetId(asset_id_new("btc", "crypto", "buyer", "company")),
IdBox::AssetId(asset_id_new("btc", "crypto", seller_account_id.clone())),
EvaluatesTo::new_evaluates_to_value(Expression::Query(
FindAssetQuantityById::new(asset_id.clone()).into(),
)),
IdBox::AccountId(buyer_account_id.clone()),
),
TransferBox::new(
IdBox::AssetId(asset_id_new("eth", "crypto", "buyer", "company")),
EvaluatesTo::new_evaluates_to_value(
Expression::Query(
FindAssetQuantityById::new(asset_id_new(
"btc2eth_rate",
"exchange",
"dex",
"exchange",
))
.into(),
)
.into(),
),
IdBox::AssetId(asset_id_new("eth", "crypto", "seller", "company")),
IdBox::AssetId(asset_id_new("eth", "crypto", buyer_account_id)),
EvaluatesTo::new_evaluates_to_value(Expression::Query(
FindAssetQuantityById::new(asset_id).into(),
)),
IdBox::AccountId(seller_account_id),
),
)
.into()])
Expand All @@ -354,48 +339,55 @@ fn find_rate_and_make_exchange_isi_should_succeed() {

let eth_quantity = test_client
.request(FindAssetQuantityById::new(asset_id_new(
"eth", "crypto", "seller", "company",
"eth",
"crypto",
account_id_new("seller", "company"),
)))
.expect("Failed to execute Iroha Query");
assert_eq!(expected_seller_eth, eth_quantity);

// For the btc amount we expect an error, as zero assets are purged from accounts
test_client
.request(FindAssetQuantityById::new(asset_id_new(
"btc", "crypto", "seller", "company",
"btc",
"crypto",
account_id_new("seller", "company"),
)))
.expect_err("Query must fail");

let buyer_eth_quantity = test_client
.request(FindAssetQuantityById::new(asset_id_new(
"eth", "crypto", "buyer", "company",
"eth",
"crypto",
account_id_new("buyer", "company"),
)))
.expect("Failed to execute Iroha Query");
assert_eq!(expected_buyer_eth, buyer_eth_quantity);

let buyer_btc_quantity = test_client
.request(FindAssetQuantityById::new(asset_id_new(
"btc", "crypto", "buyer", "company",
"btc",
"crypto",
account_id_new("buyer", "company"),
)))
.expect("Failed to execute Iroha Query");
assert_eq!(expected_buyer_btc, buyer_btc_quantity);
}

fn asset_id_new(
definition_name: &str,
definition_domain: &str,
account_name: &str,
account_domain: &str,
) -> AssetId {
fn account_id_new(account_name: &str, account_domain: &str) -> AccountId {
AccountId::new(
account_name.parse().expect("Valid"),
account_domain.parse().expect("Valid"),
)
}

fn asset_id_new(definition_name: &str, definition_domain: &str, account_id: AccountId) -> AssetId {
AssetId::new(
AssetDefinitionId::new(
definition_name.parse().expect("Valid"),
definition_domain.parse().expect("Valid"),
),
AccountId::new(
account_name.parse().expect("Valid"),
account_domain.parse().expect("Valid"),
),
account_id,
)
}

Expand Down
24 changes: 9 additions & 15 deletions client/tests/integration/multisignature_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,15 @@ fn multisignature_transactions_should_wait_for_all_signatures() {
let asset_definition_id = AssetDefinitionId::from_str("camomile#wonderland").expect("Valid");
let create_asset = RegisterBox::new(AssetDefinition::quantity(asset_definition_id.clone()));
let set_signature_condition = MintBox::new(
SignatureCheckCondition::new(EvaluatesTo::new_unchecked(
ContainsAll::new(
EvaluatesTo::new_unchecked(
ContextValue::new(
Name::from_str(TRANSACTION_SIGNATORIES_VALUE).expect("Can't fail."),
)
.into(),
),
val_vec![
alice_key_pair.public_key().clone(),
key_pair_2.public_key().clone(),
],
)
.into(),
)),
SignatureCheckCondition::new(EvaluatesTo::new_unchecked(ContainsAll::new(
EvaluatesTo::new_unchecked(ContextValue::new(
Name::from_str(TRANSACTION_SIGNATORIES_VALUE).expect("Can't fail."),
)),
val_vec![
alice_key_pair.public_key().clone(),
key_pair_2.public_key().clone(),
],
))),
IdBox::AccountId(alice_id.clone()),
);

Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ fn permissions_disallow_asset_transfer() {

//When
let transfer_asset = TransferBox::new(
IdBox::AssetId(AssetId::new(asset_definition_id.clone(), bob_id)),
IdBox::AssetId(AssetId::new(asset_definition_id, bob_id)),
quantity.to_value(),
IdBox::AssetId(AssetId::new(asset_definition_id, alice_id.clone())),
IdBox::AccountId(alice_id.clone()),
);
let err = iroha_client
.submit_blocking(transfer_asset)
Expand Down
2 changes: 1 addition & 1 deletion client/tests/integration/transfer_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn simulate_transfer<
let transfer_asset = TransferBox::new(
IdBox::AssetId(AssetId::new(asset_definition_id.clone(), alice_id)),
amount_to_transfer.clone().to_value(),
IdBox::AssetId(AssetId::new(asset_definition_id.clone(), mouse_id.clone())),
IdBox::AccountId(mouse_id.clone()),
);
iroha_client
.submit_till(
Expand Down
5 changes: 1 addition & 4 deletions client/tests/integration/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn validator_upgrade_should_work() -> Result<()> {
wait_for_genesis_committed(&vec![client.clone()], 0);

// Register `admin` domain and account

let admin_domain = Domain::new("admin".parse()?);
let register_admin_domain = RegisterBox::new(admin_domain);
client.submit_blocking(register_admin_domain)?;
Expand All @@ -25,7 +24,7 @@ fn validator_upgrade_should_work() -> Result<()> {

// Check that admin isn't allowed to transfer alice's rose by default
let alice_rose: <Asset as Identifiable>::Id = "rose##alice@wonderland".parse()?;
let admin_rose: <Asset as Identifiable>::Id = "rose#wonderland#admin@admin".parse()?;
let admin_rose: <Account as Identifiable>::Id = "admin@admin".parse()?;
let transfer_alice_rose = TransferBox::new(alice_rose, NumericValue::U32(1), admin_rose);
let transfer_rose_tx = TransactionBuilder::new(
admin_id.clone(),
Expand All @@ -38,7 +37,6 @@ fn validator_upgrade_should_work() -> Result<()> {
.expect_err("Should fail");

// Upgrade Validator

info!("Building validator");
let temp_out_dir =
tempfile::tempdir().wrap_err("Failed to create temporary output directory")?;
Expand All @@ -60,7 +58,6 @@ fn validator_upgrade_should_work() -> Result<()> {
client.submit_blocking(upgrade_validator)?;

// Check that admin can transfer alice's rose now

// Creating new transaction instead of cloning, because we need to update it's creation time
let transfer_rose_tx =
TransactionBuilder::new(admin_id, vec![transfer_alice_rose.into()], 100_000)
Expand Down
9 changes: 4 additions & 5 deletions client_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,8 @@ mod account {
condition: Signature(condition),
metadata: Metadata(metadata),
} = self;
let mint_box =
MintBox::new(account, EvaluatesTo::new_unchecked(condition.into())).into();
submit([mint_box], cfg, metadata).wrap_err("Failed to set signature condition")
let mint_box = MintBox::new(account, EvaluatesTo::new_unchecked(condition));
submit([mint_box.into()], cfg, metadata).wrap_err("Failed to set signature condition")
}
}

Expand Down Expand Up @@ -685,9 +684,9 @@ mod asset {
metadata: Metadata(metadata),
} = self;
let transfer_asset = TransferBox::new(
IdBox::AssetId(AssetId::new(asset_id.clone(), from)),
IdBox::AssetId(AssetId::new(asset_id, from)),
quantity.to_value(),
IdBox::AssetId(AssetId::new(asset_id, to)),
IdBox::AccountId(to),
)
.into();
submit([transfer_asset], cfg, metadata).wrap_err("Failed to transfer asset")
Expand Down
Binary file modified configs/peer/validator.wasm
Binary file not shown.
13 changes: 6 additions & 7 deletions core/benches/kura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ async fn measure_block_size_for_n_validators(n_validators: u32) {
let alice_id = AccountId::from_str("alice@test").expect("tested");
let bob_id = AccountId::from_str("bob@test").expect("tested");
let xor_id = AssetDefinitionId::from_str("xor#test").expect("tested");
let alice_xor_id = <Asset as Identifiable>::Id::new(xor_id.clone(), alice_id);
let bob_xor_id = <Asset as Identifiable>::Id::new(xor_id, bob_id);
let transfer = TransferBox {
source_id: IdBox::AssetId(alice_xor_id).into(),
object: 10_u32.to_value().into(),
destination_id: IdBox::AssetId(bob_xor_id).into(),
}
let alice_xor_id = <Asset as Identifiable>::Id::new(xor_id, alice_id);
let transfer = TransferBox::new(
IdBox::AssetId(alice_xor_id),
10_u32.to_value(),
IdBox::AccountId(bob_id),
)
.into();
let keypair = KeyPair::generate().expect("Failed to generate KeyPair.");
let tx = TransactionBuilder::new(
Expand Down
Loading

0 comments on commit cbc3bfe

Please sign in to comment.