-
Notifications
You must be signed in to change notification settings - Fork 0
Conversation
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@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 |
This reverts commit 5528b26.
There was a problem hiding this 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) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
test/spec/lib/deal.spec.js
Outdated
}) | ||
.then(result => { | ||
assert.equal(result, 0); | ||
// I wanted to use plain transfer but it reverts for now |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment was mean about the use of setTimeout
: https://github.com/Finhaven/web3-server-tools/pull/11/files/8908915344fd131b77d50304388abe16ebe839fc#diff-e1eaa7016e07dd7f005e46633acf3b5dR205
There was a problem hiding this comment.
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
@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)); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()]
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👍🏻
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 )
test/spec/lib/eth.spec.js
Outdated
}) | ||
.then(newValueBN => { | ||
//new value should be bignum | ||
let newValue = newValueBN.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be a const
test/spec/lib/eth.spec.js
Outdated
return simpleContract.methods.value().call() | ||
.then(valueBN => { | ||
//convert from bignum to string | ||
let value = valueBN.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be a const
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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".
# Conflicts: # test/spec/lib/eth.spec.js
No description provided.