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

Deal tests #11

Merged
merged 21 commits into from
Mar 2, 2018
Merged

Deal tests #11

merged 21 commits into from
Mar 2, 2018

Conversation

naumenkogs
Copy link
Contributor

No description provided.

src/lib/eth.js Outdated
// Workaround, see https://github.com/FrontierFoundry/web3-server-tools/issues/3
contractInstance.setProvider(provider);
return contractInstance;
options.txParams.to = undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of setting this to undefined, might be better to copy the options that are allowed. eg, what if someone passes in data or other junk that will make it crash

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're definitely right.

I was just too happy that I found this bug and completely forgot about it after hotfix. What if I just add it to the list for next week?

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we just leave this PR open.

@carchrae carchrae requested a review from expede January 31, 2018 01:56
@carchrae
Copy link
Contributor

@expede - can you also take a look. no rush, but will be useful to get you up to speed on how we are interacting w smart contracts

@naumenkogs
Copy link
Contributor Author

naumenkogs commented Feb 6, 2018

closes #5 now
@carchrae

Copy link
Contributor

@carchrae carchrae left a comment

Choose a reason for hiding this comment

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

looks pretty good. i would say the evm_increaseTime is the important thing to fix. having the test actually wait on wall clock time works, but makes for slower tests.

gas: options.txParams.gas,
gasPrice: options.txParams.gasPrice
}
return contractBody.deploy({arguments: options.params}).send(txParams)
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 get eslint on this project. small things; add const txParams (undefined var otherwise)

i did think perhaps you should check options.txParams exists, otherwise code will throw error. however, thinking about it, it is probably better that it throws the error (and the error will be pretty clear)

src/lib/eth.js Outdated
@@ -188,7 +197,7 @@ const Eth = {
.then(([gasPrice, transactionCount]) => {
logger.debug('gas price', gasPrice);
const gasPriceHex = web3.utils.numberToHex(gasPrice);
const gasLimitHex = web3.utils.numberToHex(68308);
const gasLimitHex = web3.utils.numberToHex(683080);
Copy link
Contributor

Choose a reason for hiding this comment

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

this should probably be defined in an env var or some config.

})
.then(result => {
assert.equal(result, 0);
// I wanted to use plain transfer but it reverts for now
Copy link
Contributor

Choose a reason for hiding this comment

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

will be fixed by #13 ? - perhaps just put // FIXME: in this comment and suggest the fix

})
.then(result => {
console.log('Pause 2: ', Date.now())
return deal.methods.authorize(investor).send(options.txParams)
Copy link
Contributor

Choose a reason for hiding this comment

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

there are nicer ways to fastforward the EVM in ganache/testrpc. i haven't looked into it much, but did find it when i had a problem with the start time crashing

https://ethereum.stackexchange.com/questions/21509/truffle-testrpc-time-manipulation

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Creating a separate issue for it

@carchrae
Copy link
Contributor

carchrae commented Feb 8, 2018

@expede - can you please review as well.

.then(() => checkBalance(ownerAccount, 100))
.then(() => transfer(ownerAccount, userAccount, 33, shouldFail))
.then(() => checkBalance(userAccount, 33))
.then(() => checkBalance(ownerAccount, 67));
Copy link
Contributor

Choose a reason for hiding this comment

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

Since each then has no argument dependencies, we could parallelize some of these calls if this test is long-running (noticed the timeout). Promise.all([checkBalance(userAccount, 33), checkBalance(ownerAccount, 67)]) or similar

Copy link
Contributor

Choose a reason for hiding this comment

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

as you likely see, the ordering here is important for the first two.

yes, you could do the last two (as you suggest). i don't think this will be a big impact on speed though. to be clear, @naumenkogs - she means replacing 126+127 with .then(() => Promise.all([checkBalance(userAccount, 33), checkBalance(ownerAccount, 67)]))

i'm not sure i would do this here (code readability>minimal performance), but in general i agree that calling promises async where you can is good practice.

Copy link
Contributor

Choose a reason for hiding this comment

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

btw, the timeout is because he is using a setTimeout instead of evm_increaseTime - that would be the slowness you are seeing. i think it should be changed to evm_increaseTime if not already done

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that for single tests it may not be a huge improvement, but we did also have to up the mocha timeout. As we get more and more tests with more and more expectations, this will only grow.

RE: readability, Promise.all is ugly but can be made more readable with await: [await foo(), await bar()]

Copy link
Contributor

Choose a reason for hiding this comment

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

on readability - sure, but i'd stick it in a helper checkBalances to keep the test easy to read. re time, not sure you saw the comment about evm_increaseTime - that is the problem here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, just seeing the comment above now 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I'm not sure evm_increaseTime will help a lot here. I think the timeout is caused by the fact that I have to check "deal time-window" works well. And to be sure, I make windows bigger. It's easy to make mistakes by running unrealistic evm_increaseTime I think. And it's not that long.

Copy link
Contributor

Choose a reason for hiding this comment

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

to be clear; i am suggesting you use evm_increaseTime to skip the ganache EVM into the future. right now, you are using setTimeout in a few places instead. i believe evm_increaseTime would mean you don't need to use setTimeout (which causes a wall-clock (aka real) time delay )

})
.then(newValueBN => {
//new value should be bignum
let newValue = newValueBN.toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be a const

return simpleContract.methods.value().call()
.then(valueBN => {
//convert from bignum to string
let value = valueBN.toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be a const

Copy link
Contributor

Choose a reason for hiding this comment

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

i think we need some .eslint checking in this project

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. I've submitted a PR to practices, and will bring that file here once that's given the 👌🏻

console.log('New balance ', balance.toString());
assert.equal(balance.toString(), '2')
assert.equal(balance.toString(), '0.02')
Copy link
Contributor

Choose a reason for hiding this comment

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

Are all of these console logs here to debug the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, mostly yes, but it is also helps to double-check that everything is right by reading looks.

It's not the best practice, but we're in the world where there is no way to distinguish whether the error was "not enough tokens" or "transfer not permitted".

@naumenkogs naumenkogs closed this Mar 2, 2018
@naumenkogs naumenkogs reopened this Mar 2, 2018
@naumenkogs naumenkogs merged commit 86d4841 into master Mar 2, 2018
@naumenkogs naumenkogs deleted the deal_tests branch March 2, 2018 01:05
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.

3 participants