Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a broken payment test (+ another small fix) #1318

Merged
merged 3 commits into from Sep 11, 2018

Conversation

dwardu
Copy link
Contributor

@dwardu dwardu commented Sep 11, 2018

Test was referencing a local variable instead of calling the contract method.

@dwardu
Copy link
Contributor Author

dwardu commented Sep 11, 2018

As a sidenote, I believe the public getter payee(uint256) should be renamed payees(uint256).

The standard way to implement this would have been to declare a public variable payees as follows:

address[] public payees;

and then let the payees(uint256) getter be generated automatically.

But I can see that the implementation is as follows:

address[] private _payees;
function payee(uint256 index) public view returns(address) {
  return _payees[index];
}

I gather that this was done so that contract variables could be _prefixed, but the public getter would be “clean”. However I think that at least the public getter should be named as it would have been named if there weren’t this “workaround.”

@nventuro nventuro added bug tests Test suite and helpers. labels Sep 11, 2018
@nventuro nventuro added this to the v2.0 milestone Sep 11, 2018
@nventuro nventuro self-assigned this Sep 11, 2018
Copy link
Contributor

@nventuro nventuro left a comment

Choose a reason for hiding this comment

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

Awesome @dwardu, thanks! It's a bit worrying that this didn't cause an error in the suite, I'll review the other tests.

test/payment/SplitPayment.test.js Outdated Show resolved Hide resolved
@@ -14,4 +14,4 @@ Fixes #
- [ ] 📘 I've reviewed the [OpenZeppelin Contributor Guidelines](../blob/master/CONTRIBUTING.md)
- [ ] ✅ I've added tests where applicable to test my new functionality.
- [ ] 📖 I've made sure that my contracts are well-documented.
- [ ] 🎨 I've run the JS/Solidity linters and fixed any issues (`npm run lint:all:fix`).
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I caught the mistake in the PR template… because I was obeying the PR template 😀

@nventuro
Copy link
Contributor

Regarding the naming of the getter, I think it was @ElOpio who made that call, and I agree with it. payees makes sense for an array variable, but payees(index) feels a bit weird to me, kind of looks like you're retrieving many of them.

@dwardu
Copy link
Contributor Author

dwardu commented Sep 11, 2018

Yes, despite payees[index] not feeling bad, payees(index) feels strange… but that’s how Solidity does it for public getters… I have no issue with it, it was just a sidenote.

@dwardu
Copy link
Contributor Author

dwardu commented Sep 11, 2018

Yes, I was also wondering how the failed test had managed to go through!

Copy link
Contributor

@nventuro nventuro left a comment

Choose a reason for hiding this comment

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

I think the fact that we didn't get an error was related to the promises not being awaited, Mocha sometimes does weird stuff in those cases.

Anyway, thanks a lot!

@nventuro
Copy link
Contributor

Btw, regarding your naming suggestion, feel free to open an issue for us to discuss this, if you think it may be a source of confusion :)

@nventuro nventuro merged commit b79196f into OpenZeppelin:master Sep 11, 2018
frangio pushed a commit that referenced this pull request Sep 28, 2018
* Fixed a broken payment test

* In PR template, npm run lint:fix, not lint:all:fix

* In SplitPayment test, replaced an await-in-loop with Promise.all

(cherry picked from commit b79196f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug tests Test suite and helpers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants