Skip to content

Commit

Permalink
side stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Oct 2, 2024
1 parent a373980 commit 0a52dac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
7 changes: 5 additions & 2 deletions crates/evm/src/backend/starknet_backend.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,12 @@ mod tests {
};
use crate::test_utils::{evm_address};
use snforge_std::{
test_address, start_mock_call, get_class_hash, spy_events, EventSpyAssertionsTrait
test_address, start_mock_call, get_class_hash, spy_events, EventSpyTrait,
Event as StarknetEvent
};
use snforge_utils::snforge_utils::{
assert_not_called, assert_called, EventsFilterBuilderTrait, ContractEventsTrait
};
use snforge_utils::snforge_utils::{assert_not_called, assert_called};
use super::{commit_storage, emit_events};
use utils::helpers::compute_starknet_address;
use utils::traits::bytes::U8SpanExTrait;
Expand Down
24 changes: 12 additions & 12 deletions crates/snforge_utils/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub mod snforge_utils {
/// A wrapper structure on an array of events emitted by a given contract.
#[derive(Drop, Clone)]
pub struct ContractEvents {
pub events: Array<Event>
pub events: Span<Event>
}

pub trait EventsFilterTrait {
Expand Down Expand Up @@ -246,33 +246,33 @@ pub mod snforge_utils {
}
};

ContractEvents { events: filtered_events }
ContractEvents { events: filtered_events.span() }
}
}

pub trait ContractEventsTrait {
fn assert_emitted<T, impl TEvent: starknet::Event<T>, impl TDrop: Drop<T>>(
self: ContractEvents, event: @T
self: @ContractEvents, event: @T
);
fn assert_not_emitted<T, impl TEvent: starknet::Event<T>, impl TDrop: Drop<T>>(
self: ContractEvents, event: @T
self: @ContractEvents, event: @T
);
}

impl ContractEventsTraitImpl of ContractEventsTrait {
fn assert_emitted<T, impl TEvent: starknet::Event<T>, impl TDrop: Drop<T>>(
self: ContractEvents, event: @T
self: @ContractEvents, event: @T
) {
let mut expected_keys = array![];
let mut expected_data = array![];
event.append_keys_and_data(ref expected_keys, ref expected_data);

let contract_events = (*self.events);
let mut found = false;
for i in 0
..self
.events
..contract_events
.len() {
let event = self.events.at(i);
let event = contract_events.at(i);
if event.keys == @expected_keys && event.data == @expected_data {
found = true;
break;
Expand All @@ -283,17 +283,17 @@ pub mod snforge_utils {
}

fn assert_not_emitted<T, impl TEvent: starknet::Event<T>, impl TDrop: Drop<T>>(
self: ContractEvents, event: @T
self: @ContractEvents, event: @T
) {
let mut expected_keys = array![];
let mut expected_data = array![];
event.append_keys_and_data(ref expected_keys, ref expected_data);

let contract_events = (*self.events);
for i in 0
..self
.events
..contract_events
.len() {
let event = self.events.at(i);
let event = contract_events.at(i);
assert(
event.keys != @expected_keys || event.data != @expected_data,
'Unexpected event was emitted'
Expand Down

0 comments on commit 0a52dac

Please sign in to comment.