Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
manlikeHB committed Sep 30, 2024
1 parent 74c8e3b commit 96064cc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
56 changes: 50 additions & 6 deletions contracts/src/components/registry/registry_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,63 @@ fn test_register() {
)
}

// #[test]
#[test]
fn test_register_twice_same_offchain_id() {
panic!("Not implemented yet");
let mut state = setup();
let mut _spy = spy_events();
let contract_address = test_address();

// setup caller
start_cheat_caller_address(contract_address, constants::CALLER());

// first registeration
state.register(offchain_id: constants::REVOLUT_ID());

// second registeration
state.register(offchain_id: constants::REVOLUT_ID());

// assert state after
assert!(state.is_registered(constants::CALLER(), constants::REVOLUT_ID()));
//TODO: check on emitted events
}

// #[test]
#[test]
fn test_register_two_different_offchain_id() {
panic!("Not implemented yet");
let mut state = setup();
let mut _spy = spy_events();
let contract_address = test_address();

// setup caller
start_cheat_caller_address(contract_address, constants::CALLER());

// register
state.register(offchain_id: constants::REVOLUT_ID());
state.register(offchain_id: constants::REVOLUT_ID_TWO());

// assert state after
assert!(state.is_registered(constants::CALLER(), constants::REVOLUT_ID()));
assert!(state.is_registered(constants::CALLER(), constants::REVOLUT_ID_TWO()));
//TODO: check on emitted events
}

// #[test]
#[test]
fn test_register_same_offchain_id_from_two_different_callers() {
panic!("Not implemented yet");
let mut state = setup();
let mut _spy = spy_events();
let contract_address = test_address();

// setup caller one and register
start_cheat_caller_address(contract_address, constants::CALLER());
state.register(offchain_id: constants::REVOLUT_ID());

// setup caller two and register
start_cheat_caller_address(contract_address, constants::SPENDER());
state.register(offchain_id: constants::REVOLUT_ID());

// assert state after
assert!(state.is_registered(constants::CALLER(), constants::REVOLUT_ID()));
assert!(state.is_registered(constants::SPENDER(), constants::REVOLUT_ID()));
//TODO: check on emitted events
}

//
Expand Down
5 changes: 5 additions & 0 deletions contracts/src/tests/constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ use core::starknet::{ContractAddress, contract_address_const};
use zkramp::components::registry::interface::OffchainId;

const REVTAG: felt252 = 'just a random revtag hash';
const REVTAG_TWO: felt252 = 'just another random revtag hash';

pub fn REVOLUT_ID() -> OffchainId {
OffchainId::Revolut(REVTAG)
}

pub fn REVOLUT_ID_TWO() -> OffchainId {
OffchainId::Revolut(REVTAG_TWO)
}

pub fn CALLER() -> ContractAddress {
contract_address_const::<'caller'>()
}
Expand Down

0 comments on commit 96064cc

Please sign in to comment.