diff --git a/implementation/contracts/system/TBTCDepositToken.sol b/implementation/contracts/system/TBTCDepositToken.sol index 40bded890..08aea645b 100644 --- a/implementation/contracts/system/TBTCDepositToken.sol +++ b/implementation/contracts/system/TBTCDepositToken.sol @@ -50,10 +50,11 @@ contract TBTCDepositToken is ERC721Metadata, DepositFactoryAuthority { /// @param _spender Address of contract authorized to spend. /// @param _tdtId The TDT they can spend. /// @param _extraData Extra information to send to the approved contract. - function approveAndCall(address _spender, uint256 _tdtId, bytes memory _extraData) public returns (bool success) { + function approveAndCall(address _spender, uint256 _tdtId, bytes memory _extraData) public returns (bool) { tokenRecipient spender = tokenRecipient(_spender); approve(_spender, _tdtId); spender.receiveApproval(msg.sender, _tdtId, address(this), _extraData); + return true; } } diff --git a/implementation/contracts/system/TBTCToken.sol b/implementation/contracts/system/TBTCToken.sol index f0734a53b..d44f285dc 100644 --- a/implementation/contracts/system/TBTCToken.sol +++ b/implementation/contracts/system/TBTCToken.sol @@ -53,12 +53,13 @@ contract TBTCToken is ERC20Detailed, ERC20, VendingMachineAuthority { /// @param _spender Address of contract authorized to spend. /// @param _value The max amount they can spend. /// @param _extraData Extra information to send to the approved contract. - function approveAndCall(address _spender, uint256 _value, bytes memory _extraData) public returns (bool success) { + function approveAndCall(address _spender, uint256 _value, bytes memory _extraData) public returns (bool) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, address(this), _extraData); return true; } + return false; } } diff --git a/implementation/test/VendingMachineTest.js b/implementation/test/VendingMachineTest.js index b9fec5b13..8a0169713 100644 --- a/implementation/test/VendingMachineTest.js +++ b/implementation/test/VendingMachineTest.js @@ -443,6 +443,31 @@ describe("VendingMachine", async function() { expect(eventList[0].returnValues._digest).to.equal(sighash) }) + it("returns true on success", async () => { + await testDeposit.setState(states.ACTIVE) + await tbtcDepositToken.forceMint(vendingMachine.address, tdtId) + await tbtcToken.forceMint(owner, depositValue.add(signerFee)) + await feeRebateToken.forceMint(owner, tdtId) + const tbtcToBtc = vendingMachine.abi.filter( + x => x.name == "tbtcToBtc", + )[0] + const calldata = web3.eth.abi.encodeFunctionCall(tbtcToBtc, [ + testDeposit.address, + "0x1111111100000000", + redeemerOutputScript, + owner, + ]) + + const success = await tbtcToken.approveAndCall.call( + redemptionScript.address, + depositValue.add(signerFee), + calldata, + {from: owner}, + ) + + expect(success).to.equal(true) + }) + it("reverts for unknown function calls encoded in _extraData", async () => { const unknownFunctionSignature = "0xCAFEBABE" await tbtcToken.forceMint(owner, depositValue.add(signerFee)) @@ -514,6 +539,35 @@ describe("VendingMachine", async function() { expect(await feeRebateToken.ownerOf(tdtId)).to.equal(owner) }) + it("reverts true on success", async () => { + const unqualifiedDepositToTbtcABI = vendingMachine.abi.filter( + x => x.name == "unqualifiedDepositToTbtc", + )[0] + const calldata = web3.eth.abi.encodeFunctionCall( + unqualifiedDepositToTbtcABI, + [ + testDeposit.address, + _version, + _txInputVector, + _txOutputVector, + _txLocktime, + _fundingOutputIndex, + _merkleProof, + _txIndexInBlock, + _bitcoinHeaders, + ], + ) + + const success = await tbtcDepositToken.approveAndCall.call( + fundingScript.address, + tdtId, + calldata, + {from: owner}, + ) + + expect(success).to.be.true + }) + it("reverts for unknown function calls encoded in _extraData", async () => { const unknownFunctionSignature = "0xCAFEBABE"