diff --git a/contracts/token/ERC20/extensions/ERC1363.sol b/contracts/token/ERC20/extensions/ERC1363.sol index 7514254f171..59fc2779e92 100644 --- a/contracts/token/ERC20/extensions/ERC1363.sol +++ b/contracts/token/ERC20/extensions/ERC1363.sol @@ -102,21 +102,17 @@ abstract contract ERC1363 is IERC1363, ERC20, ERC165 { uint256 value, bytes memory data ) private returns (bool) { - if (to.isContract()) { - try IERC1363Receiver(to).onTransferReceived(_msgSender(), from, value, data) returns (bytes4 retval) { - return retval == IERC1363Receiver.onTransferReceived.selector; - } catch (bytes memory reason) { - if (reason.length == 0) { - revert("ERC1363: transfer to non ERC1363Receiver implementer"); - } else { - /// @solidity memory-safe-assembly - assembly { - revert(add(32, reason), mload(reason)) - } + try IERC1363Receiver(to).onTransferReceived(_msgSender(), from, value, data) returns (bytes4 retval) { + return retval == IERC1363Receiver.onTransferReceived.selector; + } catch (bytes memory reason) { + if (reason.length == 0) { + revert("ERC1363: transfer to non ERC1363Receiver implementer"); + } else { + /// @solidity memory-safe-assembly + assembly { + revert(add(32, reason), mload(reason)) } } - } else { - return true; } } @@ -130,21 +126,17 @@ abstract contract ERC1363 is IERC1363, ERC20, ERC165 { uint256 value, bytes memory data ) private returns (bool) { - if (spender.isContract()) { - try IERC1363Spender(spender).onApprovalReceived(owner, value, data) returns (bytes4 retval) { - return retval == IERC1363Spender.onApprovalReceived.selector; - } catch (bytes memory reason) { - if (reason.length == 0) { - revert("ERC1363: transfer to non ERC1363Spender implementer"); - } else { - /// @solidity memory-safe-assembly - assembly { - revert(add(32, reason), mload(reason)) - } + try IERC1363Spender(spender).onApprovalReceived(owner, value, data) returns (bytes4 retval) { + return retval == IERC1363Spender.onApprovalReceived.selector; + } catch (bytes memory reason) { + if (reason.length == 0) { + revert("ERC1363: transfer to non ERC1363Spender implementer"); + } else { + /// @solidity memory-safe-assembly + assembly { + revert(add(32, reason), mload(reason)) } } - } else { - return true; } } } diff --git a/test/token/ERC20/extensions/ERC1363.test.js b/test/token/ERC20/extensions/ERC1363.test.js index d7333437914..453bef0e51a 100644 --- a/test/token/ERC20/extensions/ERC1363.test.js +++ b/test/token/ERC20/extensions/ERC1363.test.js @@ -25,12 +25,14 @@ contract('ERC1363', function (accounts) { describe('transferAndCall', function () { it('to EOA', async function () { - const { receipt } = await this.token.methods['transferAndCall(address,uint256)'](other, value, { from: holder }); - expectEvent(receipt, 'Transfer', { - from: holder, - to: other, - value, - }); + await expectRevert( + this.token.methods['transferAndCall(address,uint256)']( + other, + value, + { from: holder }, + ), + 'function call to a non-contract account', + ); }); describe('to receiver', function () { @@ -107,17 +109,15 @@ contract('ERC1363', function (accounts) { }); it('to EOA', async function () { - const { receipt } = await this.token.methods['transferFromAndCall(address,address,uint256)']( - holder, - other, - value, - { from: operator }, + await expectRevert( + this.token.methods['transferFromAndCall(address,address,uint256)']( + holder, + other, + value, + { from: operator }, + ), + 'function call to a non-contract account', ); - expectEvent(receipt, 'Transfer', { - from: holder, - to: other, - value, - }); }); describe('to receiver', function () { @@ -197,12 +197,10 @@ contract('ERC1363', function (accounts) { describe('approveAndCall', function () { it('to EOA', async function () { - const { receipt } = await this.token.methods['approveAndCall(address,uint256)'](other, value, { from: holder }); - expectEvent(receipt, 'Approval', { - owner: holder, - spender: other, - value, - }); + await expectRevert( + this.token.methods['approveAndCall(address,uint256)'](other, value, { from: holder }), + 'function call to a non-contract account', + ); }); describe('to receiver', function () {