kleros / openiico-contract

Contract of Interactive Coin Offering
MIT License
11 stars 5 forks source link

Stress test - too many bids - too many to finalize in one go #30

Closed stefek99 closed 6 years ago

stefek99 commented 6 years ago
date; truffle test ./test/StressFinalize.js > output14; date
Tue 15 May 2018 14:41:46 BST
Tue 15 May 2018 15:02:32 BST

Output of the test: https://pastebin.com/XYQ51F0a

I left console.log statements on purpose so that it is possible to observe what's going on, feel free to remove as you see fit.

It is send to a file, otherwise on error there were too many Events emitted and couldn't scroll the console.

clesaege commented 6 years ago

Thanks, I merge.

stefek99 commented 6 years ago

Did you have the patience to run it?

clesaege commented 6 years ago

I just ran it and it fails:

1) Contract: IICO Test case from the blog: AssertionError: Reimbursement amount not correct: expected 91821152005000000000 to be close to 91805038500000000000 +/- 10000000000000000 at Function.assert.closeTo (C:\Users\Clementine\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\chai\lib\chai\interface\assert.js:1223:1) at Context.it (test\IICO.js:899:12) at at process._tickCallback (internal/process/next_tick.js:188:7)

2) Contract: IICO Should gracefull handle situation with many participants (over the block gas limit): Error: VM Exception while processing transaction: revert at Object.InvalidResponse (C:\Users\Clementine\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\errors.js:38:1) at C:\Users\Clementine\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\requestmanager.js:86:1 at C:\Users\Clementine\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\truffle-provider\wrapper.js:134:1 at XMLHttpRequest.request.onreadystatechange (C:\Users\Clementine\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\httpprovider.js:128:1) at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\Clementine\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:64:1) at XMLHttpRequest._setReadyState (C:\Users\Clementine\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:354:1) at XMLHttpRequest._onHttpResponseEnd (C:\Users\Clementine\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:509:1) at IncomingMessage. (C:\Users\Clementine\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:469:1) at endReadableNT (_stream_readable.js:1054:12) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9)

clesaege commented 6 years ago

It may be because of truffle update which now count gas and make things slower.

clesaege commented 6 years ago

@stefek99 Can you look at this?

stefek99 commented 6 years ago

truffle test ./test/StressFinalize.js

I'm running it now, will finish in about 30 minutes...

stefek99 commented 6 years ago

image

truffle version
Truffle v4.1.8 (core: 4.1.8)
Solidity v0.4.23 (solc-js)

image

(might be a good idea to increase closeTo tolerance to 0.3 ether maybe)

clesaege commented 6 years ago

I'm with the new truffle version, that may be the difference.

stefek99 commented 6 years ago

No way, I've updated recently!

ganache-cli --verion
Ganache CLI v7.0.0-beta.0 (ganache-core: 3.0.0-beta.0)
clesaege commented 6 years ago

Your screenshot still display ms. Mine now display the gas used.

clesaege commented 6 years ago

Are you at "truffle@4.1.11" ?

epiqueras commented 6 years ago

No way, I've updated recently!

That's ganache (testrpc). You need to update truffle too.

stefek99 commented 6 years ago
npm update -g truffle
/Users/zen/.nvm/versions/node/v9.5.0/bin/truffle -> /Users/zen/.nvm/versions/node/v9.5.0/lib/node_modules/truffle/build/cli.bundled.js
+ truffle@4.1.11
removed 11 packages and updated 10 packages in 4.335s

truffle version
Truffle v4.1.11 (core: 4.1.11)
Solidity v0.4.24 (solc-js)

Sh!t, it is failing now:

image

clesaege commented 6 years ago

Yeah, it's seems that the new truffle version is breaking stuff.

stefek99 commented 6 years ago

truffle test ./test/StressFinalize.js - works...

image

truffle test - sometimes fails, sometimes works...

image

image

image

stefek99 commented 6 years ago

See #33

Moved to a new folder so that truffle test does not take forever.

Intermittent failure, really tricky to debug.

epiqueras commented 6 years ago

@stefek99 @clesaege I suggest using evm_increaseTime to avoid having to wait so much.

stefek99 commented 6 years ago

It's not about increasing time.

It's about running 5000 * 2 transactions so that finalize takes more than gasLimit of the block.

epiqueras commented 6 years ago

@stefek99 You can set your own block gas limit. ganache-cli --gasLimit X

stefek99 commented 6 years ago

Cannot set gasLimit on the mainnet.

See #26

stefek99 commented 6 years ago

I know!

Set lower gasLimit, start testrpc manually.

Then we will hit it in 10 seconds, not half an hour...

Thanks for suggestions!

I won’t be investing more time on this issue unless explicitly instructed, I’m more interested in baking in affiliate / referral / commission to align incentives of participants as well as the core team when promoting the IICO.

stefek99 commented 6 years ago

Some new lessons learned:

1. Cannot set block gas limit arbitrarily low - there will be not enough gas to deploy contract in the first place.

Maybe there is a dynamic block gas limit somewhere, potentially?

2. Say I start it with testrpc -a 15 --gasLimit 6000000 --gasPrice 10000000000

StackOverflow question: https://ethereum.stackexchange.com/questions/48413/truffle-test-how-to-get-more-than-10-accounts

It needs to have matching truffle.js config:

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*", // Match any network id
      gas: 6000000
    }
  }
};

Without gas: 6000000 it will complain:

Exceeds block gas limit

This issue was helpful - https://github.com/trufflesuite/truffle/issues/660 - figured out I need to explicitly define config.

3. eth_getTransactionByHash vs eth_getTransactionReceipt

There is a difference if you want to get gas used by a transaction: https://ethereum.stackexchange.com/questions/8603/gas-and-gas-used-by-transaction-and-how-to-get-both-values-through-json-rpc

Added a helper for my personal use:

 getTransaction: hash => {
   console.log("getTransaction");
   return web3.currentProvider.send({jsonrpc: "2.0", method: "eth_getTransactionReceipt", params: [hash]})
 },