Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Refactor/split tests #102

Merged
merged 6 commits into from
Mar 15, 2018
Merged

Refactor/split tests #102

merged 6 commits into from
Mar 15, 2018

Conversation

satello
Copy link
Contributor

@satello satello commented Mar 14, 2018

Hopefully the tests will be more reliable now and quicker. Next step is to mock the store interactions. Using the hosted store slows the tests down 3x.

NOTE: when running the tests locally you will need 15 accounts on your testrpc client

@coveralls
Copy link

coveralls commented Mar 14, 2018

Pull Request Test Coverage Report for Build 516

  • 81 of 85 (95.29%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+1.3%) to 71.849%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/utils/StoreProviderWrapper.js 77 78 98.72%
src/contractWrappers/ArbitrableTransactionWrapper.js 0 3 0.0%
Totals Coverage Status
Change from base Build 501: 1.3%
Covered Lines: 664
Relevant Lines: 846

💛 - Coveralls

Copy link
Contributor

@epiqueras epiqueras left a comment

Choose a reason for hiding this comment

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

Huge improvement! Just a few changes needed.

.travis.yml Outdated
@@ -12,7 +12,7 @@ addons:
install: yarn install --pure-lockfile
script:
- yarn run lint
- nohup yarn run ganache-cli &
- nohup yarn run ganache-cli -a 15 &
Copy link
Contributor

Choose a reason for hiding this comment

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

yarn run ganache since it is already a script.

package.json Outdated
@@ -28,7 +28,8 @@
"commitmsg": "kleros-scripts commitmsg",
"cz": "kleros-scripts cz",
"start": "webpack --env.NODE_ENV=development --progress --watch",
"build": "webpack --env.NODE_ENV=production -p"
"build": "webpack --env.NODE_ENV=production -p",
"ganache": "ganache-cli -a 15"
Copy link
Contributor

Choose a reason for hiding this comment

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

This can go right before test to make the order clear.

title,
description
contractInstance.address,
{
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

const userProfile = await this._StoreProvider.setUpUserProfile(account)
// FIXME seems like a super hacky way to update store
userProfile.balance =
(parseInt(userProfile.balance, 10) ? userProfile.balance : 0) +
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

dispute.arbitratorAddress,
dispute.disputeId,
(dispute.netPNK ? dispute.netPNK : 0) + amountShift
{
netPNK: (dispute.netPNK ? dispute.netPNK : 0) + amountShift
Copy link
Contributor

Choose a reason for hiding this comment

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

(dispute.netPNK || 0) + amountShift

)

if (_.isNull(notificationIndex)) {
throw new TypeError(`No notification with txHash ${txHash} exists`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not really a TypeError.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The linter makes me do it

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 look into making custom errors later. For cases like these and also the ones described here:
ethereum/EIPs#136

userProfile.notifications[notificationIndex].read = isRead
delete userProfile._id
delete userProfile.created_at
return new Promise(resolve => resolve(JSON.stringify(userProfile)))
Copy link
Contributor

Choose a reason for hiding this comment

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

unnecessary promise

}

userProfile.notifications[notificationIndex].read = isRead
delete userProfile._id
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_id and created_at are generated on the store. You can't push a profile with an id that already exists. And it is ordered by created_at so we need to remove the timestamp so we get a new one

const returnPromise = new Promise(resolve => {
returnResolver = resolve
})
promise = promise.then(fn, fn).then(result => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice work on this.

Just one thing. If fn throws then returnPromise will never resolve. Just add this to fix it:

promise = promise.then(fn, fn).then(res => returnResolver(res), err => returnRejecter(err))

let rngAddress
let pnkAddress

beforeAll(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't really need to use beforeAll. You can just make the function passed to the parent describe async and do all of this inline.

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 think its still useful to have it here so if we want to add more tests to this file we don't need to pull it back out

@satello
Copy link
Contributor Author

satello commented Mar 15, 2018

thanks for the review @epiqueras

@satello satello merged commit 8962fea into develop Mar 15, 2018
@epiqueras epiqueras deleted the refactor/split_tests branch March 15, 2018 21:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants