diff --git a/contracts/src/components/registry/interface.cairo b/contracts/src/components/registry/interface.cairo index 60c5304..d984d0d 100644 --- a/contracts/src/components/registry/interface.cairo +++ b/contracts/src/components/registry/interface.cairo @@ -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 } diff --git a/contracts/src/components/registry/registry.cairo b/contracts/src/components/registry/registry.cairo index 760acd2..24f43c6 100644 --- a/contracts/src/components/registry/registry.cairo +++ b/contracts/src/components/registry/registry.cairo @@ -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, } // diff --git a/contracts/src/components/registry/registry_test.cairo b/contracts/src/components/registry/registry_test.cairo index f241cd5..10ab8a2 100644 --- a/contracts/src/components/registry/registry_test.cairo +++ b/contracts/src/components/registry/registry_test.cairo @@ -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; @@ -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() {