-
Notifications
You must be signed in to change notification settings - Fork 27
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 #23 from 0xChqrles/feat/setup-tests
[CONTRACTS] setup registry tests
- Loading branch information
Showing
9 changed files
with
133 additions
and
8 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
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,2 +1,8 @@ | ||
pub mod interface; | ||
pub mod registry; | ||
|
||
#[cfg(test)] | ||
pub mod registry_mock; | ||
|
||
#[cfg(test)] | ||
pub mod registry_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use super::registry::RegistryComponent; | ||
|
||
#[starknet::contract] | ||
pub mod RegistryMock { | ||
use starknet::ContractAddress; | ||
use starknet::account::Call; | ||
use zkramp::components::registry::interface::IRegistry; | ||
use zkramp::components::registry::registry::RegistryComponent; | ||
|
||
component!(path: RegistryComponent, storage: registry, event: RegistryEvent); | ||
|
||
// Registry | ||
#[abi(embed_v0)] | ||
impl RegistryImpl = RegistryComponent::RegistryImpl<ContractState>; | ||
|
||
// | ||
// Storage | ||
// | ||
|
||
#[storage] | ||
struct Storage { | ||
#[substorage(v0)] | ||
registry: RegistryComponent::Storage, | ||
} | ||
|
||
// | ||
// Events | ||
// | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
#[flat] | ||
RegistryEvent: RegistryComponent::Event, | ||
} | ||
|
||
// | ||
// Constructor | ||
// | ||
|
||
#[constructor] | ||
fn constructor(ref self: ContractState) { | ||
// Nothing to be done | ||
} | ||
} | ||
|
||
type ComponentState = RegistryComponent::ComponentState<RegistryMock::ContractState>; | ||
|
||
fn COMPONENT() -> ComponentState { | ||
RegistryComponent::component_state_for_testing() | ||
} |
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,24 @@ | ||
use zkramp::components::registry::interface::{IRegistryDispatcher, IRegistryDispatcherTrait}; | ||
use zkramp::components::registry::registry_mock::RegistryMock; | ||
use zkramp::tests::utils; | ||
use zkramp::tests::constants; | ||
|
||
/// Deploys the registry mock contract. | ||
fn setup_contracts() -> IRegistryDispatcher { | ||
// deploy registry | ||
let registry_contract_address = utils::deploy(RegistryMock::TEST_CLASS_HASH, calldata: array![]); | ||
|
||
IRegistryDispatcher { contract_address: registry_contract_address } | ||
} | ||
|
||
// | ||
// Externals | ||
// | ||
|
||
#[test] | ||
#[should_panic(expected: ('Caller is the zero address', 'ENTRYPOINT_FAILED'))] | ||
fn test_register_from_zero() { | ||
let registry = setup_contracts(); | ||
|
||
registry.register(offchain_id: constants::REVOLUT_ID()); | ||
} |
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,3 +1,6 @@ | ||
pub mod components; | ||
pub mod contracts; | ||
pub mod utils; | ||
|
||
#[cfg(test)] | ||
pub mod tests; |
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,2 @@ | ||
pub mod constants; | ||
pub mod utils; |
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,9 @@ | ||
use zkramp::components::registry::interface::OffchainId; | ||
|
||
pub fn REVTAG() -> ByteArray { | ||
"my wonderfull, incredible but also very long, revtag" | ||
} | ||
|
||
pub fn REVOLUT_ID() -> OffchainId { | ||
OffchainId::Revolut(REVTAG()) | ||
} |
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,10 @@ | ||
use starknet::{SyscallResultTrait, syscalls}; | ||
|
||
pub fn deploy(contract_class_hash: felt252, calldata: Array<felt252>) -> starknet::ContractAddress { | ||
let (address, _) = syscalls::deploy_syscall( | ||
contract_class_hash.try_into().unwrap(), 0, calldata.span(), false | ||
) | ||
.unwrap_syscall(); | ||
|
||
address | ||
} |