Skip to content

Commit

Permalink
Merge pull request #29 from chachaleo/feat/RegistrationTest
Browse files Browse the repository at this point in the history
Feat/registration test
  • Loading branch information
lana-shanghai authored Aug 21, 2024
2 parents 7cf4e1d + 65e3483 commit 105639c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion contracts/src/components/registry/interface.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::hash::HashStateExTrait;
use starknet::ContractAddress;
use zkramp::utils::hash::HashSerializable;

#[derive(Drop, Serde, Clone)]
#[derive(Drop, Serde, Clone, Debug, PartialEq)]
pub enum OffchainId {
Revolut: ByteArray
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/src/components/registry/registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ pub mod RegistryComponent {
//

#[event]
#[derive(Drop, starknet::Event)]
#[derive(Drop, Debug, PartialEq, starknet::Event)]
pub enum Event {
RegistrationEvent: RegistrationEvent,
}

#[derive(Drop, starknet::Event)]
#[derive(Drop, Debug, PartialEq, starknet::Event)]
pub struct RegistrationEvent {
#[key]
caller: ContractAddress,
offchain_id: OffchainId,
pub caller: ContractAddress,
pub offchain_id: OffchainId,
}

//
Expand Down
35 changes: 35 additions & 0 deletions contracts/src/components/registry/registry_test.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use core::starknet::contract_address_const;
use starknet::testing::{set_caller_address, set_contract_address};
use zkramp::components::registry::interface::{IRegistryDispatcher, IRegistryDispatcherTrait};
use zkramp::components::registry::registry::{RegistryComponent::{Event, RegistrationEvent},};
use zkramp::components::registry::registry_mock::RegistryMock;
use zkramp::tests::constants;
use zkramp::tests::utils;
Expand All @@ -17,6 +20,38 @@ fn setup_contracts() -> IRegistryDispatcher {
// Externals
//

#[test]
fn test_is_registered() {
set_contract_address(contract_address_const::<'caller'>());
let registry = setup_contracts();

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

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

#[test]
fn test_registration_event() {
set_contract_address(contract_address_const::<'caller'>());
let registry = setup_contracts();

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

assert_eq!(
starknet::testing::pop_log(registry.contract_address),
Option::Some(
Event::RegistrationEvent(
RegistrationEvent {
caller: contract_address_const::<'caller'>(),
offchain_id: constants::REVOLUT_ID()
}
)
)
);
}

#[test]
#[should_panic(expected: ('Caller is the zero address', 'ENTRYPOINT_FAILED'))]
fn test_register_from_zero() {
Expand Down

0 comments on commit 105639c

Please sign in to comment.