Skip to content

Commit

Permalink
create CALLER test constant
Browse files Browse the repository at this point in the history
  • Loading branch information
0xChqrles committed Aug 26, 2024
1 parent dbec2a4 commit 2986ab6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 4 additions & 8 deletions contracts/src/components/registry/registry_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,21 @@ use zkramp::tests::utils;
fn test_is_registered() {
let test_address: ContractAddress = test_address();

start_cheat_caller_address(test_address, contract_address_const::<'caller'>());
start_cheat_caller_address(test_address, constants::CALLER());

let mut registry: ComponentState = Default::default();

registry.register(offchain_id: constants::REVOLUT_ID());

assert_eq!(
registry.is_registered(contract_address_const::<'caller'>(), constants::REVOLUT_ID()), true
);
assert_eq!(registry.is_registered(constants::CALLER(), constants::REVOLUT_ID()), true);
}

#[test]
fn test_registration_event() {
let test_address: ContractAddress = test_address();
let mut spy = spy_events();

start_cheat_caller_address(test_address, contract_address_const::<'caller'>());
start_cheat_caller_address(test_address, constants::CALLER());

let mut registry: ComponentState = Default::default();

Expand All @@ -51,8 +49,7 @@ fn test_registration_event() {
test_address,
Event::RegistrationEvent(
RegistrationEvent {
caller: contract_address_const::<'caller'>(),
offchain_id: constants::REVOLUT_ID()
caller: constants::CALLER(), offchain_id: constants::REVOLUT_ID()
}
)
)
Expand All @@ -67,4 +64,3 @@ fn test_register_from_zero() {

registry.register(offchain_id: constants::REVOLUT_ID());
}

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

pub fn REVTAG() -> ByteArray {
Expand All @@ -7,3 +8,7 @@ pub fn REVTAG() -> ByteArray {
pub fn REVOLUT_ID() -> OffchainId {
OffchainId::Revolut(REVTAG())
}

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

0 comments on commit 2986ab6

Please sign in to comment.