Skip to content

Commit

Permalink
Merge branch 'iroha2-dev' into iroha_telemetry_derive_to_syn2
Browse files Browse the repository at this point in the history
  • Loading branch information
VAmuzing committed Dec 27, 2023
2 parents 0965600 + 2ca4b9f commit 18e3123
Show file tree
Hide file tree
Showing 18 changed files with 353 additions and 268 deletions.
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
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
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.
2 changes: 1 addition & 1 deletion core/src/smartcontracts/isi/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub mod isi {

domain.remove_asset_total_quantity(&asset_definition_id);

events.push(WorldEvent::from(DomainEvent::AssetDefinition(
events.push(DataEvent::from(DomainEvent::AssetDefinition(
AssetDefinitionEvent::Deleted(asset_definition_id),
)));

Expand Down
Loading

0 comments on commit 18e3123

Please sign in to comment.