-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from mubarak23/ft_add_event
feat:add event and basic unit test for it
- Loading branch information
Showing
9 changed files
with
123 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Test | ||
|
||
on: [push, pull_request] | ||
permissions: read-all | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: software-mansion/setup-scarb@v1 | ||
- uses: foundry-rs/setup-snfoundry@v3 | ||
with: | ||
starknet-foundry-version: 0.31.0 | ||
- name: Run cairo tests | ||
run: snforge test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod events; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pub mod base; | ||
pub mod interfaces; | ||
pub mod event; | ||
pub mod events; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,47 @@ | ||
// use starknet::ContractAddress; | ||
|
||
// use snforge_std::{declare, ContractClassTrait}; | ||
|
||
// use chainevents_contracts::IHelloStarknetSafeDispatcher; | ||
// use chainevents_contracts::IHelloStarknetSafeDispatcherTrait; | ||
// use chainevents_contracts::IHelloStarknetDispatcher; | ||
// use chainevents_contracts::IHelloStarknetDispatcherTrait; | ||
|
||
// fn deploy_contract(name: ByteArray) -> ContractAddress { | ||
// let contract = declare(name).unwrap(); | ||
// let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); | ||
// contract_address | ||
// } | ||
|
||
// #[test] | ||
// fn test_increase_balance() { | ||
// let contract_address = deploy_contract("HelloStarknet"); | ||
|
||
// let dispatcher = IHelloStarknetDispatcher { contract_address }; | ||
|
||
// let balance_before = dispatcher.get_balance(); | ||
// assert(balance_before == 0, 'Invalid balance'); | ||
|
||
// dispatcher.increase_balance(42); | ||
|
||
// let balance_after = dispatcher.get_balance(); | ||
// assert(balance_after == 42, 'Invalid balance'); | ||
// } | ||
|
||
// #[test] | ||
// #[feature("safe_dispatcher")] | ||
// fn test_cannot_increase_balance_with_zero_value() { | ||
// let contract_address = deploy_contract("HelloStarknet"); | ||
|
||
// let safe_dispatcher = IHelloStarknetSafeDispatcher { contract_address }; | ||
|
||
// let balance_before = safe_dispatcher.get_balance().unwrap(); | ||
// assert(balance_before == 0, 'Invalid balance'); | ||
|
||
// match safe_dispatcher.increase_balance(0) { | ||
// Result::Ok(_) => core::panic_with_felt252('Should have panicked'), | ||
// Result::Err(panic_data) => { | ||
// assert(*panic_data.at(0) == 'Amount cannot be 0', *panic_data.at(0)); | ||
// } | ||
// }; | ||
// } | ||
|
||
// ************************************************************************* | ||
// Events TEST | ||
// ************************************************************************* | ||
use core::option::OptionTrait; | ||
use core::starknet::SyscallResultTrait; | ||
use core::result::ResultTrait; | ||
use core::traits::{TryInto, Into}; | ||
use starknet::{ContractAddress}; | ||
|
||
use snforge_std::{ | ||
declare, start_cheat_caller_address, stop_cheat_caller_address, ContractClassTrait, | ||
DeclareResultTrait, | ||
}; | ||
|
||
use chainevents_contracts::interfaces::IEvent::{IEventDispatcher, IEventDispatcherTrait}; | ||
|
||
|
||
const USER_ONE: felt252 = 'JOE'; | ||
const USER_TWO: felt252 = 'DOE'; | ||
|
||
// ************************************************************************* | ||
// SETUP | ||
// ************************************************************************* | ||
fn __setup__() -> ContractAddress { | ||
// deploy events | ||
let events_class_hash = declare("Events").unwrap().contract_class(); | ||
|
||
let mut events_constructor_calldata: Array<felt252> = array![]; | ||
let (event_contract_address, _) = events_class_hash | ||
.deploy(@events_constructor_calldata) | ||
.unwrap(); | ||
|
||
return (event_contract_address); | ||
} | ||
|
||
#[test] | ||
fn test_add_event() { | ||
let event_contract_address = __setup__(); | ||
|
||
let event_dispatcher = IEventDispatcher { contract_address: event_contract_address }; | ||
|
||
start_cheat_caller_address(event_contract_address, USER_ONE.try_into().unwrap()); | ||
let event_id = event_dispatcher.add_event("bitcoin dev meetup", "Dan Marna road"); | ||
assert(event_id == 1, 'Event was not created'); | ||
stop_cheat_caller_address(event_contract_address); | ||
} | ||
|