Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

ApproveAndCall return values #527

Merged
merged 5 commits into from
Mar 21, 2020
Merged

ApproveAndCall return values #527

merged 5 commits into from
Mar 21, 2020

Conversation

NicholasDotSol
Copy link
Contributor

closes: #505

approveAndCall always returns false because the return value bool success is never set.

Success was not defined, so the function was
always returning false.
Copy link
Contributor

@Shadowfiend Shadowfiend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test here? That appears to be how we missed it in the first place 😬

Enforce approveAndCall returns true on successful flow
)

expect(success).to.equal(true)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add this, do we still need the approveAndCall below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this one is .call so we don't get any state change

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that we can observe the success, I guess…

These feel like separate tests. Any reason we've glommed them on to the existing ones rather than firing up a separate test that handles approveAndCall specifically?

tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, address(this), _extraData);
return true;
}
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This structure seems different---do we need to introduce the same if (approve...) guard to the TDT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approve() does not return bool for ERC721

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -27,7 +27,8 @@ const _expectedUTXOoutpoint =
"0x5f40bccf997d221cd0e9cb6564643f9808a89a5e1c65ea5e6530c0b51c18487c00000000"
const _outValueBytes = "0x2040351d00000000"

describe("VendingMachine", async function() {
// eslint-disable-next-line no-only-tests/no-only-tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂

@@ -443,6 +444,31 @@ describe("VendingMachine", async function() {
expect(eventList[0].returnValues._digest).to.equal(sighash)
})

it("returns true on success", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of things here:

  • This block describes RedemptionScript, but as far as I can see, you're not actually returning true on success for RedemptionScript?
  • This is really a test of TBTCToken, not RedemptionScript, right?

Same note below for TBTCDepositToken vs FundingScript.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really a test of TBTCToken

Yes In a way. In order to test approveAndCall specifically, we would still have to go through receiveApproval, and this is implemented in our funding/redemption scripts. I can see how it's not ideal.

The tests themselves are testing approveAndCall though.
returns true on success -> approveAndCall returns true on success?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests themselves are testing approveAndCall though.

I believe we should add isolated tests to contract-related test suites like TBTCDepositTokenTest.js and TBTCTokenTest.js to cover there just approveAndCall functions calls with some simple stubs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I should have made my point clearer: this test is entirely a test of TBTCToken, so it feels like it should live in TBTCTokenTest. Similarly, the TDT one should live in TBTCDepositTokenTest. It feels fine to wrap these up into one TokenTest file or similar, but putting them in unrelated tests is not ideal.

In the interest of keeping things moving I'm going to merge this as-is, since it implements the underlying functionality we're looking for---but let's strive to make the changes quickly unless there was a good reason to have it in the current structure.

Run all tests, not just VendingMachine...
@Shadowfiend Shadowfiend merged commit 6d3d58b into master Mar 21, 2020
@Shadowfiend Shadowfiend deleted the approveAndCall-return branch March 21, 2020 22:07
Copy link
Member

@nkuba nkuba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed I have some pending unsubmitted review. 🤦‍♂ Sorry for the delay.

@@ -514,6 +539,35 @@ describe("VendingMachine", async function() {
expect(await feeRebateToken.ownerOf(tdtId)).to.equal(owner)
})

it("reverts true on success", async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverts -> returns ?

@@ -443,6 +444,31 @@ describe("VendingMachine", async function() {
expect(eventList[0].returnValues._digest).to.equal(sighash)
})

it("returns true on success", async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests themselves are testing approveAndCall though.

I believe we should add isolated tests to contract-related test suites like TBTCDepositTokenTest.js and TBTCTokenTest.js to cover there just approveAndCall functions calls with some simple stubs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

approveAndCall unused return parameter
4 participants