Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.3.1 #60

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: modify registry
Darlington02 committed Dec 17, 2024
commit 944b3ca7366b7724620b346bf54201a505663068
42 changes: 2 additions & 40 deletions src/registry/registry.cairo
Original file line number Diff line number Diff line change
@@ -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;

@@ -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
@@ -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(),
@@ -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
@@ -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__();