Skip to content

Commit

Permalink
chore: modify registry
Browse files Browse the repository at this point in the history
  • Loading branch information
Darlington02 committed Dec 17, 2024
1 parent 4da642c commit 944b3ca
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 59 deletions.
42 changes: 2 additions & 40 deletions src/registry/registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ pub mod Registry {
// *************************************************************************
// IMPORTS
// *************************************************************************
use core::result::ResultTrait;
use core::hash::HashStateTrait;
use core::pedersen::PedersenTrait;
use starknet::{
ContractAddress, get_caller_address, get_contract_address,
syscalls::{call_contract_syscall, deploy_syscall}, class_hash::ClassHash, SyscallResultTrait
ContractAddress, get_contract_address, syscalls::deploy_syscall, class_hash::ClassHash,
SyscallResultTrait
};
use token_bound_accounts::interfaces::IRegistry::IRegistry;

Expand Down Expand Up @@ -41,12 +40,6 @@ pub mod Registry {
pub token_id: u256,
}

// *************************************************************************
// ERRORS
// *************************************************************************
pub mod Errors {
pub const CALLER_IS_NOT_OWNER: felt252 = 'Registry: caller is not owner';
}

// *************************************************************************
// EXTERNAL FUNCTIONS
Expand All @@ -66,9 +59,6 @@ pub mod Registry {
salt: felt252,
chain_id: felt252
) -> ContractAddress {
let owner = self._get_owner(token_contract, token_id);
assert(owner == get_caller_address(), Errors::CALLER_IS_NOT_OWNER);

let mut constructor_calldata: Array<felt252> = array![
token_contract.into(),
token_id.low.into(),
Expand Down Expand Up @@ -122,32 +112,4 @@ pub mod Registry {
account_address.try_into().unwrap()
}
}

// *************************************************************************
// PRIVATE FUNCTIONS
// *************************************************************************
#[generate_trait]
impl internalImpl of InternalTrait {
/// @notice internal function for getting NFT owner
/// @param token_contract contract address of NFT
// @param token_id token ID of NFT
// NB: This function aims for compatibility with all contracts (snake or camel case) but do
// not work as expected on mainnet as low level calls do not return err at the moment.
// Should work for contracts which implements CamelCase but not snake_case until starknet
// v0.15.
fn _get_owner(
self: @ContractState, token_contract: ContractAddress, token_id: u256
) -> ContractAddress {
let mut calldata: Array<felt252> = ArrayTrait::new();
Serde::serialize(@token_id, ref calldata);
let mut res = call_contract_syscall(
token_contract, selector!("ownerOf"), calldata.span()
);
if (res.is_err()) {
res = call_contract_syscall(token_contract, selector!("owner_of"), calldata.span());
}
let mut address = res.unwrap();
Serde::<ContractAddress>::deserialize(ref address).unwrap()
}
}
}
19 changes: 0 additions & 19 deletions tests/test_registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,6 @@ fn test_create_account() {
assert(TBA_owner == token_owner, 'acct deployed wrongly');
}

#[test]
#[should_panic(expected: ('Registry: caller is not owner',))]
fn test_create_account_should_fail_if_not_nft_owner() {
let (registry_contract_address, erc721_contract_address) = __setup__();
let registry_dispatcher = IRegistryDispatcher { contract_address: registry_contract_address };

// create account
let account_class = declare("AccountPreset").unwrap().contract_class();
let acct_class_hash = *account_class.class_hash;
registry_dispatcher
.create_account(
acct_class_hash.into(),
erc721_contract_address,
1.try_into().unwrap(),
245828,
'SN_SEPOLIA'
);
}

#[test]
fn test_create_account_emits_event() {
let (registry_contract_address, erc721_contract_address) = __setup__();
Expand Down

0 comments on commit 944b3ca

Please sign in to comment.