Skip to content

Commit

Permalink
add error message parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
julianmrodri committed Jun 8, 2020
1 parent ddb602f commit 369f8b7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion contracts/token/ERC721/ERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable
from,
tokenId,
_data
));
), "ERC721: transfer to non ERC721Receiver implementer");
bytes4 retval = abi.decode(returndata, (bytes4));
return (retval == _ERC721_RECEIVED);
}
Expand Down
15 changes: 13 additions & 2 deletions contracts/utils/Address.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,20 @@ library Address {
* call with `data` to the target address `target`. Returns the `returndata`
* provided by the low-level call.
*
* The call is not executed if the target address is not a contract.
* The call is not executed if the target address is not a contract.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}

/**
* @dev Replacement for Solidity's low-level `call`: performs a low-level
* call with `data` to the target address `target`. Returns the `returndata`
* provided by the low-level call. Uses `errorMessage` as default revert message.
* The call is not executed if the target address is not a contract.
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");

// solhint-disable-next-line avoid-low-level-calls
Expand All @@ -78,7 +89,7 @@ library Address {
revert(add(32, returndata), returndata_size)
}
} else {
revert("Address: low-level call failed");
revert(errorMessage);
}
} else {
return returndata;
Expand Down
4 changes: 2 additions & 2 deletions test/token/ERC721/ERC721.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ describe('ERC721', function () {
const nonReceiver = this.token;
await expectRevert(
this.token.safeTransferFrom(owner, nonReceiver.address, tokenId, { from: owner }),
'Address: low-level call failed'
'ERC721: transfer to non ERC721Receiver implementer'
);
});
});
Expand Down Expand Up @@ -463,7 +463,7 @@ describe('ERC721', function () {
const nonReceiver = this.token;
await expectRevert(
this.token.safeMint(nonReceiver.address, tokenId),
'Address: low-level call failed'
'ERC721: transfer to non ERC721Receiver implementer'
);
});
});
Expand Down

0 comments on commit 369f8b7

Please sign in to comment.