Skip to content

Commit

Permalink
fix test functions base on review requested
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarak23 committed Sep 3, 2024
1 parent 87735f5 commit a7f2d89
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
10 changes: 9 additions & 1 deletion src/components/account/account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ pub mod AccountComponent {
return false;
}
}

fn get_root_owner(
self: @ComponentState<TContractState>, token_contract: ContractAddress, token_id: u256
) -> ContractAddress {
self._get_root_owner(token_contract, token_id)
}
}

// *************************************************************************
Expand Down Expand Up @@ -210,9 +216,11 @@ pub mod AccountComponent {
self: @ComponentState<TContractState>, token_contract: ContractAddress, token_id: u256
) -> ContractAddress {
// TODO: implement logic to get root owner
123.try_into().unwrap()

1.try_into().unwrap()
}


/// @notice internal transaction for returning the contract address and token ID of the NFT
fn _get_token(self: @ComponentState<TContractState>) -> (ContractAddress, u256, felt252) {
let contract = self.account_token_contract.read();
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/IAccount.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ pub trait IAccount<TContractState> {
fn owner(self: @TContractState) -> ContractAddress;
fn state(self: @TContractState) -> u256;
fn supports_interface(self: @TContractState, interface_id: felt252) -> bool;
fn get_root_owner(
self: @TContractState, token_contract: ContractAddress, token_id: u256
) -> ContractAddress;
}
27 changes: 15 additions & 12 deletions tests/test_signatory_component.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,15 @@ fn test_is_valid_signer_root_owner() {
let (contract_address, erc721_contract_address) = __setup__();

let token_dispatcher = IERC721Dispatcher { contract_address: erc721_contract_address };
let token_owner1 = token_dispatcher.ownerOf(1.try_into().unwrap());
token_dispatcher.ownerOf(2.try_into().unwrap());
let account_dispatcher = IAccountDispatcher { contract_address };
let token_owner = token_dispatcher.ownerOf(1.try_into().unwrap());

let root_owner = account_dispatcher.get_root_owner(token_owner, 1.try_into().unwrap());
let signatory_dispatcher = ISignatoryDispatcher { contract_address: contract_address };

start_cheat_caller_address(contract_address, token_owner1);
start_cheat_caller_address(contract_address, root_owner);

let is_valid_signer = signatory_dispatcher.is_valid_signer(token_owner1);
let is_valid_signer = signatory_dispatcher.is_valid_signer(root_owner);

assert(is_valid_signer == true, 'should accept valid signer');
stop_cheat_caller_address(contract_address);
Expand All @@ -175,21 +176,23 @@ fn test_is_valid_signature() {
}

#[test]
fn test_is_valid_signature_root_owner() {
fn test_is_valid_signature1_root_owner() {
let (contract_address, erc721_contract_address) = __setup__();

let data = SIGNED_TX_DATA();
let hash = data.transaction_hash;

let token_dispatcher = IERC721Dispatcher { contract_address: erc721_contract_address };
let token_owner1 = token_dispatcher.ownerOf(1.try_into().unwrap());
token_dispatcher.ownerOf(2.try_into().unwrap());
let account_dispatcher = IAccountDispatcher { contract_address };
let token_owner = token_dispatcher.ownerOf(1.try_into().unwrap());

let root_owner = account_dispatcher.get_root_owner(token_owner, 1.try_into().unwrap());
let signatory_dispatcher = ISignatoryDispatcher { contract_address: contract_address };

start_cheat_caller_address(contract_address, token_owner1);
start_cheat_caller_address(contract_address, root_owner);

let mut good_signature = array![data.r, data.s];
let is_valid = signatory_dispatcher.is_valid_signature(hash, good_signature.span());
assert(is_valid == 'VALID', 'should accept valid signature');
let is_valid_signer = signatory_dispatcher.is_valid_signature(hash, good_signature.span());
assert(is_valid_signer == 'VALID', 'should accept valid signature');

stop_cheat_caller_address(contract_address);
}

0 comments on commit a7f2d89

Please sign in to comment.