Truffle Test – Returns TX Object Instead of Result in Truffle Test

testingtransactionstruffle-test

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));
}

Best Answer

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;
Related Topic