diff --git a/src/components/account/account.cairo b/src/components/account/account.cairo index a5120c1..2dbb1ef 100644 --- a/src/components/account/account.cairo +++ b/src/components/account/account.cairo @@ -111,6 +111,12 @@ pub mod AccountComponent { return false; } } + + fn get_root_owner( + self: @ComponentState, token_contract: ContractAddress, token_id: u256 + ) -> ContractAddress { + self._get_root_owner(token_contract, token_id) + } } // ************************************************************************* @@ -210,9 +216,11 @@ pub mod AccountComponent { self: @ComponentState, 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) -> (ContractAddress, u256, felt252) { let contract = self.account_token_contract.read(); diff --git a/src/interfaces/IAccount.cairo b/src/interfaces/IAccount.cairo index 8f5e26d..50fbc6d 100644 --- a/src/interfaces/IAccount.cairo +++ b/src/interfaces/IAccount.cairo @@ -15,4 +15,7 @@ pub trait IAccount { 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; } diff --git a/tests/test_signatory_component.cairo b/tests/test_signatory_component.cairo index f13f8cd..e2f52b5 100644 --- a/tests/test_signatory_component.cairo +++ b/tests/test_signatory_component.cairo @@ -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); @@ -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); }