Skip to content

Commit

Permalink
add check for event emission
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarak23 committed May 14, 2024
1 parent 7f05e54 commit c9394fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
1 change: 0 additions & 1 deletion onchain/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ edition = "2023_11"
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.11.0" }
starknet = "2.6.3"

[dev-dependencies]
Expand Down
22 changes: 20 additions & 2 deletions onchain/src/social_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub mod SocialPayAccount {
#[constructor]
fn constructor(ref self: ContractState, public_key: u256) {
self.public_key.write(public_key);
self.emit(AccountCreated { public_key });
}

#[abi(embed_v0)]
Expand All @@ -46,9 +47,13 @@ mod tests {
ContractAddress, get_caller_address, get_contract_address, contract_address_const
};
use snforge_std as snf;
use snforge_std::{declare, ContractClassTrait};
use snforge_std::{
declare, ContractClassTrait, start_prank, stop_prank, CheatTarget, spy_events, SpyOn,
EventSpy, EventFetcher, Event
};
use super::{ISocialPayAccountDispatcher, ISocialPayAccountDispatcherTrait};


const public_key: u256 = 45;

fn deploy_social_account() -> ContractAddress {
Expand All @@ -57,7 +62,20 @@ mod tests {
let mut social_account_calldata = array![];
public_key.serialize(ref social_account_calldata);

contract.deploy(@social_account_calldata).unwrap()
let address = contract.precalculate_address(@social_account_calldata);

let deployed_contract_address = contract.deploy(@social_account_calldata).unwrap();

let mut spy = spy_events(SpyOn::One(address));

spy.fetch_events();
println!("fetch event numbers: {:?}", spy.fetch_events());

println!("event number: {}", spy.events.len());
assert(spy.events.len() == 1, 'there should be one event');

deployed_contract_address

}

#[test]
Expand Down

0 comments on commit c9394fe

Please sign in to comment.