Skip to content

Commit

Permalink
Merge branch 'iroha2-dev' into iroha2-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Asem-Abdelhady authored Jan 11, 2024
2 parents da709e0 + f6593ee commit f914a94
Show file tree
Hide file tree
Showing 41 changed files with 521 additions and 360 deletions.
7 changes: 2 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ members = [
"smart_contract/utils",
"smart_contract/executor",
"smart_contract/executor/derive",
"substrate",
"telemetry",
"tools/kagami",
"tools/kura_inspector",
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ Iroha project mainly consists of the following crates:
* [`iroha_macro`](macro) provides the convenience macros.
* [`iroha_p2p`](p2p) defines peer creation and handshake logic.
* [`iroha_default_executor`](default_executor) defines runtime validation logic.
* [`iroha_substrate`](substrate) is the bridge substrate `XClaim` external module.
* [`iroha_telemetry`](telemetry) is used for monitoring and analysis of telemetry data.
* [`iroha_version`](version) provides message versioning for non-simultaneous system updates.

Expand Down
10 changes: 2 additions & 8 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ categories.workspace = true
workspace = true

[features]
default = ["bridge", "telemetry", "schema-endpoint"]
default = ["telemetry", "schema-endpoint"]

# Support interoperability with popular blockchain networks (Substrate, Ether, etc.)
bridge = ["iroha_core/bridge"]
# Support Decentralised Exchange, including functionality for atomic exchange instruction
dex = ["iroha_core/dex"]
# Support lightweight telemetry, including diagnostics
telemetry = ["iroha_telemetry", "iroha_core/telemetry", "iroha_torii/telemetry"]
# Support developer-specific telemetry.
Expand Down Expand Up @@ -82,10 +78,8 @@ vergen = { workspace = true, features = ["cargo"] }

[package.metadata.cargo-all-features]
denylist = [
"bridge",
"dex",
"schema-endpoint",
"telemetry",
"test-network",
] # TODO: remove `dex` and `bridge` once there's code for them.
]
skip_optional_dependencies = true
6 changes: 3 additions & 3 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ The results of the compilation can be found in `<IROHA REPO ROOT>/target/release

### Add features

To add optional features, use ``--features``. For example, to add the support for _dex_, run:
To add optional features, use ``--features``. For example, to add the support for _dev_telemetry_, run:

```bash
cargo build --release --features dex
cargo build --release --features dev-telemetry
```

A full list of features can be found in the [cargo manifest file](Cargo.toml) for this crate.

### Disable default features

By default, the Iroha binary is compiled with the `bridge`, `telemetry`, and `schema-endpoint` features. If you wish to remove those features, add `--no-default-features` to the command.
By default, the Iroha binary is compiled with the `telemetry`, and `schema-endpoint` features. If you wish to remove those features, add `--no-default-features` to the command.

```bash
cargo build --release --no-default-features
Expand Down
2 changes: 1 addition & 1 deletion client/tests/integration/connected_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn register_new_peer() -> Result<()> {
PeerBuilder::new()
.with_configuration(configuration)
.with_into_genesis(WithGenesis::None)
.with_port(11_200)
.with_port(11_225)
.start(),
);

Expand Down
16 changes: 8 additions & 8 deletions client/tests/integration/events/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,46 +181,46 @@ fn produce_multiple_events() -> Result<()> {
}

let expected_domain_events: Vec<DataEvent> = [
WorldEvent::Domain(DomainEvent::Account(AccountEvent::PermissionAdded(
DataEvent::Domain(DomainEvent::Account(AccountEvent::PermissionAdded(
AccountPermissionChanged {
account_id: bob_id.clone(),
permission_id: token_1.definition_id.clone(),
},
))),
WorldEvent::Domain(DomainEvent::Account(AccountEvent::PermissionAdded(
DataEvent::Domain(DomainEvent::Account(AccountEvent::PermissionAdded(
AccountPermissionChanged {
account_id: bob_id.clone(),
permission_id: token_2.definition_id.clone(),
},
))),
WorldEvent::Domain(DomainEvent::Account(AccountEvent::RoleGranted(
DataEvent::Domain(DomainEvent::Account(AccountEvent::RoleGranted(
AccountRoleChanged {
account_id: bob_id.clone(),
role_id: role_id.clone(),
},
))),
WorldEvent::Domain(DomainEvent::Account(AccountEvent::PermissionRemoved(
DataEvent::Domain(DomainEvent::Account(AccountEvent::PermissionRemoved(
AccountPermissionChanged {
account_id: bob_id.clone(),
permission_id: token_1.definition_id,
},
))),
WorldEvent::Domain(DomainEvent::Account(AccountEvent::PermissionRemoved(
DataEvent::Domain(DomainEvent::Account(AccountEvent::PermissionRemoved(
AccountPermissionChanged {
account_id: bob_id.clone(),
permission_id: token_2.definition_id,
},
))),
WorldEvent::Domain(DomainEvent::Account(AccountEvent::RoleRevoked(
DataEvent::Domain(DomainEvent::Account(AccountEvent::RoleRevoked(
AccountRoleChanged {
account_id: bob_id,
role_id: role_id.clone(),
},
))),
WorldEvent::Role(RoleEvent::Deleted(role_id)),
DataEvent::Role(RoleEvent::Deleted(role_id)),
]
.into_iter()
.flat_map(WorldEvent::flatten)
.map(Into::into)
.collect();

for expected_event in expected_domain_events {
Expand Down
36 changes: 36 additions & 0 deletions client/tests/integration/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,39 @@ fn stored_vs_granted_token_payload() -> Result<()> {

Ok(())
}

#[test]
#[allow(deprecated)]
fn permission_tokens_are_unified() {
let (_rt, _peer, iroha_client) = <PeerBuilder>::new().with_port(11_230).start_with_runtime();
wait_for_genesis_committed(&[iroha_client.clone()], 0);

// Given
let alice_id = AccountId::from_str("alice@wonderland").expect("Valid");

let allow_alice_to_transfer_rose_1 = Grant::permission_token(
PermissionToken::from_str_unchecked(
"CanTransferUserAsset".parse().unwrap(),
// NOTE: Introduced additional whitespaces in the serialized form
"{ \"asset_id\" : \"rose#wonderland#alice@wonderland\" }",
),
alice_id.clone(),
);

let allow_alice_to_transfer_rose_2 = Grant::permission_token(
PermissionToken::from_str_unchecked(
"CanTransferUserAsset".parse().unwrap(),
// NOTE: Introduced additional whitespaces in the serialized form
"{ \"asset_id\" : \"rose##alice@wonderland\" }",
),
alice_id,
);

iroha_client
.submit_blocking(allow_alice_to_transfer_rose_1)
.expect("failed to grant permission token");

let _ = iroha_client
.submit_blocking(allow_alice_to_transfer_rose_2)
.expect_err("permission tokens are not unified");
}
2 changes: 1 addition & 1 deletion client/tests/integration/restart_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn restarted_peer_should_have_the_same_asset_amount() -> Result<()> {
let mut removed_peer = {
let n_peers = 4;

let (_rt, network, _) = Network::start_test_with_runtime(n_peers, Some(11_200));
let (_rt, network, _) = Network::start_test_with_runtime(n_peers, Some(11_205));
wait_for_genesis_committed(&network.clients(), 0);
let pipeline_time = Configuration::pipeline_time();
let peer_clients = Network::clients(&network);
Expand Down
39 changes: 39 additions & 0 deletions client/tests/integration/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,42 @@ fn role_with_invalid_permissions_is_not_accepted() -> Result<()> {

Ok(())
}

#[test]
#[allow(deprecated)]
fn role_permissions_unified() {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(11_235).start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);

let allow_alice_to_transfer_rose_1 = PermissionToken::from_str_unchecked(
"CanTransferUserAsset".parse().unwrap(),
// NOTE: Introduced additional whitespaces in the serialized form
"{ \"asset_id\" : \"rose#wonderland#alice@wonderland\" }",
);

let allow_alice_to_transfer_rose_2 = PermissionToken::from_str_unchecked(
"CanTransferUserAsset".parse().unwrap(),
// NOTE: Introduced additional whitespaces in the serialized form
"{ \"asset_id\" : \"rose##alice@wonderland\" }",
);

let role_id: RoleId = "role_id".parse().expect("Valid");
let role = Role::new(role_id.clone())
.add_permission(allow_alice_to_transfer_rose_1)
.add_permission(allow_alice_to_transfer_rose_2);

test_client
.submit_blocking(Register::role(role))
.expect("failed to register role");

let role = test_client
.request(FindRoleByRoleId::new(role_id))
.expect("failed to find role");

// Permission tokens are unified so only one token left
assert_eq!(
role.permissions().len(),
1,
"permission tokens for role aren't deduplicated"
);
}
55 changes: 54 additions & 1 deletion client/tests/integration/triggers/by_call_trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use iroha_client::{
transaction::Executable,
},
};
use iroha_data_model::events::TriggeringFilterBox;
use iroha_data_model::{events::TriggeringFilterBox, transaction::WasmSmartContract};
use iroha_genesis::GenesisNetwork;
use iroha_logger::info;
use test_network::*;
Expand Down Expand Up @@ -480,6 +480,59 @@ fn trigger_burn_repetitions() -> Result<()> {
Ok(())
}

#[test]
fn unregistering_one_of_two_triggers_with_identical_wasm_should_not_cause_original_wasm_loss(
) -> Result<()> {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(11_105).start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);

let account_id = AccountId::from_str("alice@wonderland")?;
let first_trigger_id = TriggerId::from_str("mint_rose_1")?;
let second_trigger_id = TriggerId::from_str("mint_rose_2")?;

let wasm =
iroha_wasm_builder::Builder::new("tests/integration/smartcontracts/mint_rose_trigger")
.show_output()
.build()?
.optimize()?
.into_bytes()?;
let wasm = WasmSmartContract::from_compiled(wasm);

let build_trigger = |trigger_id: TriggerId| {
Trigger::new(
trigger_id.clone(),
Action::new(
wasm.clone(),
Repeats::Indefinitely,
account_id.clone(),
TriggeringFilterBox::ExecuteTrigger(ExecuteTriggerEventFilter::new(
trigger_id,
account_id.clone(),
)),
),
)
};

let first_trigger = build_trigger(first_trigger_id.clone());
let second_trigger = build_trigger(second_trigger_id.clone());

test_client.submit_all_blocking([
Register::trigger(first_trigger),
Register::trigger(second_trigger.clone()),
])?;

test_client.submit_blocking(Unregister::trigger(first_trigger_id))?;
let got_second_trigger = test_client
.request(FindTriggerById {
id: second_trigger_id,
})
.expect("Failed to request second trigger");

assert_eq!(got_second_trigger, second_trigger);

Ok(())
}

fn get_asset_value(client: &mut Client, asset_id: AssetId) -> Result<u32> {
let asset = client.request(client::asset::by_id(asset_id))?;
Ok(*TryAsRef::<u32>::try_as_ref(asset.value())?)
Expand Down
22 changes: 18 additions & 4 deletions client/tests/integration/triggers/data_trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ fn must_execute_both_triggers() -> Result<()> {
[instruction.clone()],
Repeats::Indefinitely,
account_id.clone(),
TriggeringFilterBox::Data(BySome(DataEntityFilter::ByAccount(BySome(
AccountFilter::new(AcceptAll, BySome(AccountEventFilter::ByCreated)),
// FIXME: rewrite the filters using the builder DSL https://github.com/hyperledger/iroha/issues/3068
TriggeringFilterBox::Data(BySome(DataEntityFilter::ByDomain(BySome(
DomainFilter::new(
AcceptAll,
BySome(DomainEventFilter::ByAccount(BySome(AccountFilter::new(
AcceptAll,
BySome(AccountEventFilter::ByCreated),
)))),
),
)))),
),
));
Expand Down Expand Up @@ -86,8 +93,15 @@ fn domain_scoped_trigger_must_be_executed_only_on_events_in_its_domain() -> Resu
[Mint::asset_quantity(1_u32, asset_id.clone())],
Repeats::Indefinitely,
account_id,
TriggeringFilterBox::Data(BySome(DataEntityFilter::ByAccount(BySome(
AccountFilter::new(AcceptAll, BySome(AccountEventFilter::ByCreated)),
// FIXME: rewrite the filters using the builder DSL https://github.com/hyperledger/iroha/issues/3068
TriggeringFilterBox::Data(BySome(DataEntityFilter::ByDomain(BySome(
DomainFilter::new(
AcceptAll,
BySome(DomainEventFilter::ByAccount(BySome(AccountFilter::new(
AcceptAll,
BySome(AccountEventFilter::ByCreated),
)))),
),
)))),
),
));
Expand Down
12 changes: 9 additions & 3 deletions client/tests/integration/triggers/event_trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ fn test_mint_asset_when_new_asset_definition_created() -> Result<()> {
vec![instruction],
Repeats::Indefinitely,
account_id,
TriggeringFilterBox::Data(BySome(DataEntityFilter::ByAssetDefinition(BySome(
AssetDefinitionFilter::new(
// FIXME: rewrite the filters using the builder DSL https://github.com/hyperledger/iroha/issues/3068
TriggeringFilterBox::Data(BySome(DataEntityFilter::ByDomain(BySome(
DomainFilter::new(
AcceptAll,
BySome(AssetDefinitionEventFilter::ByCreated),
BySome(DomainEventFilter::ByAssetDefinition(BySome(
AssetDefinitionFilter::new(
AcceptAll,
BySome(AssetDefinitionEventFilter::ByCreated),
),
))),
),
)))),
),
Expand Down
Binary file modified configs/peer/executor.wasm
Binary file not shown.
10 changes: 2 additions & 8 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ categories.workspace = true
workspace = true

[features]
default = ["bridge", "cli", "telemetry"]
default = ["cli", "telemetry"]

# Interoperability with popular blockchain networks (Substrate, Ether, etc.)
bridge = []
# Support lightweight telemetry, including diagnostics
telemetry = []
# Support the included CLI
cli = []
# Support Decentralised Exchange, including functionality for atomic exchange instruction
dex = []
# Support developer-specific telemetry.
# Should not be enabled on production builds.
dev-telemetry = ["telemetry", "iroha_telemetry/dev-telemetry"]
Expand Down Expand Up @@ -110,10 +106,8 @@ path = "benches/blocks/validate_blocks_oneshot.rs"

[package.metadata.cargo-all-features]
denylist = [
"bridge",
"dex",
"schema-endpoint",
"telemetry",
"test-network"
] # TODO: remove `dex` and `bridge` once there's code for them.
]
skip_optional_dependencies = true
Loading

0 comments on commit f914a94

Please sign in to comment.