test receiveApproval caller failure
Test that calls to receiveApproval fail for non-token callers
@@ -531,6 +531,29 @@ describe("VendingMachine", async function() {
"Bad _extraData signature. Call must be to tbtcToBtc.",
)
})
+
+ it("protects receiveApproval from external callers", async () => {
+ const tbtcToBtc = vendingMachine.abi.filter(
+ x => x.name == "tbtcToBtc",
+ )[0]
+ const calldata = web3.eth.abi.encodeFunctionCall(tbtcToBtc, [
+ testDeposit.address,
+ "0x1111111100000000",
+ redeemerOutputScript,
+ owner,
+ ])
+
+ await expectRevert(
+ redemptionScript.receiveApproval(
+ redemptionScript.address,
+ tdtId,
+ owner,
+ calldata,
+ {from: owner},
+ ),
+ "Only token contract can call receiveApproval",
+ )
+ })
})
})
@@ -591,7 +614,7 @@ describe("VendingMachine", async function() {
expect(await feeRebateToken.ownerOf(tdtId)).to.equal(owner)
})
- it("reverts true on success", async () => {
+ it("returns true on success", async () => {
const unqualifiedDepositToTbtcABI = vendingMachine.abi.filter(
x => x.name == "unqualifiedDepositToTbtc",
)[0]
@@ -666,6 +689,37 @@ describe("VendingMachine", async function() {
"Bad _extraData signature. Call must be to unqualifiedDepositToTbtc.",
)
})
+
+ it("protects receiveApproval from external callers", async () => {
+ const unqualifiedDepositToTbtcABI = vendingMachine.abi.filter(
+ x => x.name == "unqualifiedDepositToTbtc",
+ )[0]
+ const calldata = web3.eth.abi.encodeFunctionCall(
+ unqualifiedDepositToTbtcABI,
+ [
+ testDeposit.address,
+ fundingTx.version,
+ fundingTx.txInputVector,
+ fundingTx.txOutputVector,
+ fundingTx.txLocktime,
+ fundingTx.fundingOutputIndex,
+ fundingTx.merkleProof,
+ fundingTx.txIndexInBlock,
+ fundingTx.bitcoinHeaders,
+ ],
+ )
+
+ await expectRevert(
+ fundingScript.receiveApproval(
+ redemptionScript.address,
+ depositValue.add(signerFee),
+ accounts[0],
+ calldata,
+ {from: owner},
+ ),
+ "Only token contract can call receiveApproval",
+ )
+ })
})
describe("getMaxSupply", async () => {
