2

I'm getting

AssertionError: expected { Object (tx, receipt, ...) } to be true

Here is my testing code

let apprOrOwnr = await this.erc721.isApprovedOrOwner(owner, tokenId); 
expect(apprOrOwnr).to.be.true;

My contract

function isApprovedOrOwner(address _spender, uint256 _tokenId) external view returns (bool) {
        return _isApprovedOrOwner(_spender, _tokenId);
}

What am I doing wrong?

EDIT (add _isApprovedOrOwner function):

/**
 * @dev Returns whether the given spender can transfer a given token ID
 * @param spender address of the spender to query
 * @param tokenId uint256 ID of the token to be transferred
 * @return bool whether the msg.sender is approved for the given token ID,
 *    is an operator of the owner, or is the owner of the token
 */
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view returns (bool) {
    address owner = ownerOf(tokenId);
    // Disable solium check because of
    // https://github.com/duaraghav8/Solium/issues/175
    // solium-disable-next-line operator-whitespace
    return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
  • Please share the _isApprovedOrOwner() code as well. – shane Feb 14 at 15:55
  • I've updated, but it's ERC721 unchanged function – Ivan Zakharov Feb 14 at 16:00
  • 2
    Your error implies that function isApprovedOrOwner is NOT declared view, although the code that you've posted shows otherwise. Are you sure that you are testing this piece of code? Perhaps you have this piece of code in one contract, but you're testing some other contract? Or perhaps you simply forgot to save the file before running your test? – goodvibration Feb 14 at 16:26
1

Well, I spent the day to figure it out.

To correct this behavior, it is necessary to define the method of interaction with the function. This works well after adding a “call” to a function. Solution in js code:

let apprOrOwnr = await this.erc721.isApprovedOrOwner.call(owner, tokenId); 
expect(apprOrOwnr).to.be.true;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.