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

issue #57: Async await tests #97

Merged
merged 4 commits into from
Dec 3, 2016

Conversation

sogoiii
Copy link
Contributor

@sogoiii sogoiii commented Nov 30, 2016

Transformed all tests to async await pattern.

Tests are now consistent ---> #57

Copy link
Contributor

@federicobond federicobond left a comment

Choose a reason for hiding this comment

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

Looks really good! I would remove all done parameters and calls, create a small helper for asserting throws, and give a bit more breathing space between each let/assert block.

let token = await BasicTokenMock.new(accounts[0], 100);
let totalSupply = await token.totalSupply();
assert.equal(totalSupply, 100);
done();
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to call done here, and we can remove it from the parameter too.

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 have 2 or 3 tests that require the done. I basically went with consistency. Ill remove the done from all the other tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you point me towards these tests? Mention me on the appropriate line.

Copy link
Contributor Author

@sogoiii sogoiii Dec 1, 2016

Choose a reason for hiding this comment

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

@federicobond Its the ones in bounty.js test. Its because those are events.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it's fine to use done when you have to listen to events.

assert.equal(firstAccountBalance, 0);
let secondAccountBalance = await token.balanceOf(accounts[1]);
assert.equal(secondAccountBalance, 100);
done();
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here with done. We can also add an empty line before each let/assert to improve readability.

let transfer = await token.transfer(accounts[1], 101);
} catch(error) {
if (error.message.search('invalid JUMP') === -1) throw error
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
Copy link
Contributor

Choose a reason for hiding this comment

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

We should write a quick helper for asserting throws, as it will be used many times.

@sogoiii
Copy link
Contributor Author

sogoiii commented Dec 1, 2016

@federicobond ok, I addressed your comments.

it("checkInvariant returns false", async function(){
let bounty = await InsecureTargetBounty.new();
let target = await bounty.createTarget();
let invarriantCall = await bounty.checkInvariant.call();
Copy link
Contributor

Choose a reason for hiding this comment

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

invariantCall

@federicobond
Copy link
Contributor

@sogoiii there is a failing test case for PullPayment can withdraw payment. I could reproduce it locally but could not find the cause. Do you have any ideas?

@maraoz
Copy link
Contributor

maraoz commented Dec 2, 2016

All tests passed locally for me. Weird. Is any test non-deterministic?

@sogoiii
Copy link
Contributor Author

sogoiii commented Dec 2, 2016

@federicobond I was on node 6.3.1, which makes that error go away. I rememeber as i was doing this, i found an issue that suggested the downgrade. I currently cannot find that issue. But that was why i changed my node version.

@sogoiii
Copy link
Contributor Author

sogoiii commented Dec 2, 2016

Hmm... I Dont know the combination of testrpc and node to make this work.

@sogoiii
Copy link
Contributor Author

sogoiii commented Dec 2, 2016

@federicobond can you try truffle test instead of npm test?

@federicobond
Copy link
Contributor

Yes, it works with my globally installed truffle. A dependencies issue, maybe?

@sogoiii
Copy link
Contributor Author

sogoiii commented Dec 2, 2016

Yea, ill keep looking for the problem. Glad im not crazy about that npm and truffle difference.

@sogoiii
Copy link
Contributor Author

sogoiii commented Dec 3, 2016

@federicobond @maraoz Looks like if i change the version of solc from 0.4.4 to either 0.4.5 or 0.4.6, the error appears.

Looking at their repo, the only thing they added between 0.4.4 and 0.4.5 is this commit

Just to be clear on my procedure. On my global truffle folder, i hardcoded the 0.4.4 and ran a successful truffle test. I then hard coded the package to 0.4.5, npm installed, and ran truffle test, only to get the error. I was the able to go back down to 0.4.4 and it completed successfully.

@maraoz
Copy link
Contributor

maraoz commented Dec 3, 2016

I created this branch to see if travis was failing on master: #98

Apparently this problem is unrelated to this PR, so I'll merge.
Opening an issue to investigate and solve this problem: #99

@maraoz maraoz mentioned this pull request Dec 3, 2016
@maraoz
Copy link
Contributor

maraoz commented Dec 3, 2016

@sogoiii thanks for the PR and the research on the problem with travis!

@maraoz maraoz merged commit ab93a8e into OpenZeppelin:master Dec 3, 2016
@sogoiii
Copy link
Contributor Author

sogoiii commented Dec 3, 2016

sweet!

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

Successfully merging this pull request may close these issues.

3 participants