Skip to content

Commit

Permalink
[fix] #4418: Trigger is callable by multiple users (#4491)
Browse files Browse the repository at this point in the history
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
  • Loading branch information
Erigara committed Apr 22, 2024
1 parent a9f5525 commit ca37b7f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
3 changes: 1 addition & 2 deletions client/tests/integration/domain_owner.rs
Expand Up @@ -240,10 +240,9 @@ fn domain_owner_trigger_permissions() -> Result<()> {
trigger_instructions,
Repeats::from(2_u32),
bob_id,
// FIXME: due to restriction in `ExecuteTriggerEventFilter` it's impossible to execute trigger on behalf of multiple users
TriggeringFilterBox::ExecuteTrigger(ExecuteTriggerEventFilter::new(
trigger_id.clone(),
alice_id,
FilterOpt::AcceptAll,
)),
),
));
Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/events/notification.rs
Expand Up @@ -23,7 +23,7 @@ fn trigger_completion_success_should_produce_event() -> Result<()> {
asset_id.account_id.clone(),
TriggeringFilterBox::ExecuteTrigger(ExecuteTriggerEventFilter::new(
trigger_id.clone(),
asset_id.account_id,
FilterOpt::BySome(asset_id.account_id),
)),
),
));
Expand Down Expand Up @@ -72,7 +72,7 @@ fn trigger_completion_failure_should_produce_event() -> Result<()> {
account_id.clone(),
TriggeringFilterBox::ExecuteTrigger(ExecuteTriggerEventFilter::new(
trigger_id.clone(),
account_id,
FilterOpt::BySome(account_id),
)),
),
));
Expand Down
25 changes: 13 additions & 12 deletions client/tests/integration/triggers/by_call_trigger.rs
Expand Up @@ -58,8 +58,9 @@ fn execute_trigger_should_produce_event() -> Result<()> {
let thread_client = test_client.clone();
let (sender, receiver) = mpsc::channel();
let _handle = thread::spawn(move || -> Result<()> {
let mut event_it = thread_client
.listen_for_events(ExecuteTriggerEventFilter::new(trigger_id, account_id).into())?;
let mut event_it = thread_client.listen_for_events(
ExecuteTriggerEventFilter::new(trigger_id, FilterOpt::BySome(account_id)).into(),
)?;
if event_it.next().is_some() {
sender.send(())?;
return Ok(());
Expand Down Expand Up @@ -122,7 +123,7 @@ fn trigger_failure_should_not_cancel_other_triggers_execution() -> Result<()> {
account_id.clone(),
TriggeringFilterBox::ExecuteTrigger(ExecuteTriggerEventFilter::new(
bad_trigger_id.clone(),
account_id.clone(),
FilterOpt::BySome(account_id.clone()),
)),
),
));
Expand Down Expand Up @@ -174,7 +175,7 @@ fn trigger_should_not_be_executed_with_zero_repeats_count() -> Result<()> {
account_id.clone(),
TriggeringFilterBox::ExecuteTrigger(ExecuteTriggerEventFilter::new(
trigger_id.clone(),
account_id,
FilterOpt::BySome(account_id),
)),
),
));
Expand Down Expand Up @@ -235,7 +236,7 @@ fn trigger_should_be_able_to_modify_its_own_repeats_count() -> Result<()> {
account_id.clone(),
TriggeringFilterBox::ExecuteTrigger(ExecuteTriggerEventFilter::new(
trigger_id.clone(),
account_id,
FilterOpt::BySome(account_id),
)),
),
));
Expand Down Expand Up @@ -275,7 +276,7 @@ fn unregister_trigger() -> Result<()> {
account_id.clone(),
TriggeringFilterBox::ExecuteTrigger(ExecuteTriggerEventFilter::new(
trigger_id.clone(),
account_id,
FilterOpt::BySome(account_id),
)),
),
);
Expand Down Expand Up @@ -351,7 +352,7 @@ fn trigger_in_genesis_using_base64() -> Result<()> {
account_id.clone(),
TriggeringFilterBox::ExecuteTrigger(ExecuteTriggerEventFilter::new(
trigger_id.clone(),
account_id.clone(),
FilterOpt::BySome(account_id.clone()),
)),
),
);
Expand Down Expand Up @@ -416,7 +417,7 @@ fn trigger_should_be_able_to_modify_other_trigger() -> Result<()> {
account_id.clone(),
TriggeringFilterBox::ExecuteTrigger(ExecuteTriggerEventFilter::new(
trigger_id_unregister.clone(),
account_id.clone(),
FilterOpt::BySome(account_id.clone()),
)),
),
));
Expand All @@ -431,7 +432,7 @@ fn trigger_should_be_able_to_modify_other_trigger() -> Result<()> {
account_id.clone(),
TriggeringFilterBox::ExecuteTrigger(ExecuteTriggerEventFilter::new(
trigger_id_should_be_unregistered.clone(),
account_id,
FilterOpt::BySome(account_id),
)),
),
));
Expand Down Expand Up @@ -476,7 +477,7 @@ fn trigger_burn_repetitions() -> Result<()> {
account_id.clone(),
TriggeringFilterBox::ExecuteTrigger(ExecuteTriggerEventFilter::new(
trigger_id.clone(),
account_id,
FilterOpt::BySome(account_id),
)),
),
));
Expand Down Expand Up @@ -519,7 +520,7 @@ fn unregistering_one_of_two_triggers_with_identical_wasm_should_not_cause_origin
account_id.clone(),
TriggeringFilterBox::ExecuteTrigger(ExecuteTriggerEventFilter::new(
trigger_id,
account_id.clone(),
FilterOpt::BySome(account_id.clone()),
)),
),
)
Expand Down Expand Up @@ -564,7 +565,7 @@ fn build_register_trigger_isi(
asset_id.account_id.clone(),
TriggeringFilterBox::ExecuteTrigger(ExecuteTriggerEventFilter::new(
trigger_id,
asset_id.account_id,
FilterOpt::BySome(asset_id.account_id),
)),
),
))
Expand Down
2 changes: 1 addition & 1 deletion client/tests/integration/triggers/trigger_rollback.rs
Expand Up @@ -26,7 +26,7 @@ fn failed_trigger_revert() -> Result<()> {
account_id.clone(),
TriggeringFilterBox::ExecuteTrigger(ExecuteTriggerEventFilter::new(
trigger_id.clone(),
account_id,
FilterOpt::BySome(account_id),
)),
),
));
Expand Down
Binary file modified configs/peer/executor.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion core/src/smartcontracts/isi/mod.rs
Expand Up @@ -655,7 +655,7 @@ mod tests {
account_id.clone(),
TriggeringFilterBox::ExecuteTrigger(ExecuteTriggerEventFilter::new(
trigger_id.clone(),
account_id.clone(),
FilterOpt::BySome(account_id.clone()),
)),
),
));
Expand Down
8 changes: 6 additions & 2 deletions data_model/src/events/execute_trigger.rs
Expand Up @@ -55,7 +55,7 @@ pub mod model {
/// Id of trigger catch executions of
pub(super) trigger_id: TriggerId,
/// Authority of user who owns trigger
pub(super) authority: AccountId,
pub(super) authority: FilterOpt<AccountId>,
}
}

Expand All @@ -67,7 +67,11 @@ impl Filter for ExecuteTriggerEventFilter {
///
/// Event considered as matched if trigger ids are equal
fn matches(&self, event: &ExecuteTriggerEvent) -> bool {
self.trigger_id == event.trigger_id && self.authority == event.authority
self.trigger_id == event.trigger_id
&& match &self.authority {
FilterOpt::AcceptAll => true,
FilterOpt::BySome(authority) => authority == &event.authority,
}
}
}

Expand Down

0 comments on commit ca37b7f

Please sign in to comment.