Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] #4429: Dont clear trigger execution queue (STABLE) #4430

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions client/tests/integration/triggers/data_trigger.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use eyre::Result;
use iroha_client::{client, data_model::prelude::*};
use iroha_data_model::{trigger::Trigger, Level};
use test_network::*;

#[test]
Expand Down Expand Up @@ -108,6 +109,43 @@ fn domain_scoped_trigger_must_be_executed_only_on_events_in_its_domain() -> Resu
Ok(())
}

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

let account_id: AccountId = "alice@wonderland".parse()?;
let asset_definition_id = "rose#wonderland".parse()?;
let asset_id = AssetId::new(asset_definition_id, account_id.clone());

let prev_value = get_asset_value(&test_client, asset_id.clone())?;

let instruction = MintExpr::new(1u32, asset_id.clone());
// Trigger produce 5 events
let register_trigger = RegisterExpr::new(Trigger::new(
"mint_rose".parse()?,
Action::new(
[instruction.clone()],
Repeats::Indefinitely,
account_id.clone(),
DataEventFilter::AcceptAll.into(),
),
));
// Trigger is triggered on it's own registration
test_client.submit_blocking(register_trigger)?;

// Every block x5 events would be produced
for _ in 0..3 {
test_client.submit_blocking(LogExpr::new(Level::INFO, "just message".to_string()))?;
}

let new_value = get_asset_value(&test_client, asset_id)?;
// 1 + 5 + 25 + 125 = 156
assert_eq!(new_value, prev_value + 156);

Ok(())
}

fn get_asset_value(client: &client::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
16 changes: 1 addition & 15 deletions core/src/smartcontracts/isi/triggers/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ type WasmSmartContractMap = IndexMap<HashOf<WasmSmartContract>, (WasmSmartContra
/// Specialized structure that maps event filters to Triggers.
// NB: `Set` has custom `Serialize` and `DeserializeSeed` implementations
// which need to be manually updated when changing the struct
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct Set {
/// Triggers using [`DataEventFilter`]
data_triggers: IndexMap<TriggerId, LoadedAction<DataEventFilter>>,
Expand Down Expand Up @@ -318,20 +318,6 @@ impl<'de> DeserializeSeed<'de> for WasmSeed<'_, Set> {
}
}

impl Clone for Set {
fn clone(&self) -> Self {
Self {
data_triggers: self.data_triggers.clone(),
pipeline_triggers: self.pipeline_triggers.clone(),
time_triggers: self.time_triggers.clone(),
by_call_triggers: self.by_call_triggers.clone(),
ids: self.ids.clone(),
original_contracts: self.original_contracts.clone(),
matched_ids: Vec::default(),
}
}
}

impl Set {
/// Add trigger with [`DataEventFilter`]
///
Expand Down