LimeChain / etherlime

Dapp Development framework based on ethers.js
MIT License
185 stars 41 forks source link

Assorted "call stack depth" errors when running coverage #298

Open elenadimitrova opened 4 years ago

elenadimitrova commented 4 years ago

The following are errors when trying to run coverage against the argent repo

etherlime coverage produces

Preparing coverage environment and building artifacts...
RangeError: Maximum call stack size exceeded
    at Array.values (<anonymous>)
    at new FastBuffer (buffer.js:80:1)
    at allocate (buffer.js:326:13)
    at Function.allocUnsafe (buffer.js:293:10)
    at tryCreateBuffer (fs.js:318:21)
    at Object.readFileSync (fs.js:352:14)

Picking a small subfolder with just a couple of base contracts and running etherlime coverage --runs=200 --workingDirectory=./contracts/base compiles and starts to run tests successfully but has numerous of the following messages

Unable to find matching bytecode for contract address 0x40f83BA36bA49901E5e1E8a3f4baBF436aeD4C32, please check your artifacts. Ignoring...

followed by another stack depth error towards the end of the test run

Error: Malformed trace. Trace depth doesn't match call stack depth
    at Object.getContractAddressToTraces (/Users/Elena/Source/argent-contracts/node_modules/@0x/sol-tracing-utils/src/trace.ts:28:19)
    at CoverageSubprovider.<anonymous> (/Users/Elena/Source/argent-contracts/node_modules/@0x/sol-tracing-utils/src/trace_info_subprovider.ts:86:41)
    at step (/Users/Elena/Source/argent-contracts/node_modules/@0x/sol-tracing-utils/lib/src/trace_info_subprovider.js:45:23)
    at Object.next (/Users/Elena/Source/argent-contracts/node_modules/@0x/sol-tracing-utils/lib/src/trace_info_subprovider.js:26:53)
    at fulfilled (/Users/Elena/Source/argent-contracts/node_modules/@0x/sol-tracing-utils/lib/src/trace_info_subprovider.js:17:58)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Error: Malformed trace. Trace depth doesn't match call stack depth
    at Object.getContractAddressToTraces (/Users/Elena/Source/argent-contracts/node_modules/@0x/sol-tracing-utils/src/trace.ts:28:19)
    at CoverageSubprovider.<anonymous> (/Users/Elena/Source/argent-contracts/node_modules/@0x/sol-tracing-utils/src/trace_info_subprovider.ts:86:41)
    at step (/Users/Elena/Source/argent-contracts/node_modules/@0x/sol-tracing-utils/lib/src/trace_info_subprovider.js:45:23)
    at Object.next (/Users/Elena/Source/argent-contracts/node_modules/@0x/sol-tracing-utils/lib/src/trace_info_subprovider.js:26:53)
    at fulfilled (/Users/Elena/Source/argent-contracts/node_modules/@0x/sol-tracing-utils/lib/src/trace_info_subprovider.js:17:58)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Error: Malformed trace. Trace depth doesn't match call stack depth
    at Object.getContractAddressToTraces (/Users/Elena/Source/argent-contracts/node_modules/@0x/sol-tracing-utils/src/trace.ts:28:19)
    at CoverageSubprovider.<anonymous> (/Users/Elena/Source/argent-contracts/node_modules/@0x/sol-tracing-utils/src/trace_info_subprovider.ts:86:41)
    at step (/Users/Elena/Source/argent-contracts/node_modules/@0x/sol-tracing-utils/lib/src/trace_info_subprovider.js:45:23)
    at Object.next (/Users/Elena/Source/argent-contracts/node_modules/@0x/sol-tracing-utils/lib/src/trace_info_subprovider.js:26:53)
    at fulfilled (/Users/Elena/Source/argent-contracts/node_modules/@0x/sol-tracing-utils/lib/src/trace_info_subprovider.js:17:58)
    at process._tickCallback (internal/process/next_tick.js:68:7)
/Users/Elena/Source/argent-contracts/node_modules/mocha/lib/runner.js:726
  err.uncaught = true;
               ^

TypeError: Cannot create property 'uncaught' on string 'abort({}). Build with -s ASSERTIONS=1 for more info.'
    at Runner.uncaught (/Users/Elena/Source/argent-contracts/node_modules/mocha/lib/runner.js:726:16)
    at process.uncaught (/Users/Elena/Source/argent-contracts/node_modules/mocha/lib/runner.js:839:10)
    at process.emit (events.js:182:13)
    at process.C.process.emit (/Users/Elena/Source/argent-contracts/node_modules/ganache-cli/build/ganache-core.node.cli.js:52:196078)
    at process.C.process.emit (/Users/Elena/Source/argent-contracts/node_modules/ganache-cli/build/ganache-core.node.cli.js:52:219702)
    at process.emit (/Users/Elena/Source/argent-contracts/node_modules/ganache-core/node_modules/source-map-support/source-map-support.js:465:21)
    at process._fatalException (internal/bootstrap/node.js:491:27)
ochikov commented 4 years ago

Thank you for your issue. We will investigate the problem. I am going to keep you updated.

ochikov commented 4 years ago

@elenadimitrova I cloned the repo and reproduced all the errors that you have described.

The issue with the Maximum call stack size exceeded is coming from storing more than 1024 items in the stack. I am going to make deeper research and then I will try to propose you a workaround.

The issue with testing only the base folder is that we are creating coverage-artifacts (compiling) only the contracts from that folder, but we are trying to run all the tests (which are related to other contracts as well).

How the coverage is working - we are compiling all the contracts two times (ones with solc compiler and once with 0x sol-compiler). Then we are using necessary parts from the compiled contracts (with 0x sol-compiler) to run coverage.

You are receiving the messages Unable to find matching bytecode for contract creation....etc...etc, please check your artifacts. Ignoring... because there aren't compiled contracts in coverage-artifacts folder, but there are transactions which are coming from contract addresses and the coverage cannot find them.

Could we run test file for only those contracts in the base folder or test file for any random contract from your contracts ?

elenadimitrova commented 4 years ago

storing more than 1024 items in the stack

Is this an etherlime issue or are you talking about the tests in the argent repo?

Also I don't understand your question at the end. Do you mean if we can pick the tests which use just the compiled contracts for coverage?

ochikov commented 4 years ago

Right now, we are currently working on implementing solidity-coverage library in etherlime. (Expecting release is in the next week).

elenadimitrova commented 4 years ago

Thanks. I was going to ask about using solidity-coverage which has recently been modularised better for this sort of integration but you beat me to it. It's great to know you're looking to integrate it. On the second question, it would be rather difficult to incise tests that just run on a subset of contracts, plus I do need it running on the entire contracts folder not just the base one I picked for testing. I am okay to hold off until you have a solidity-coverage version to test with. Happy to test that when available.

cgewecke commented 4 years ago

@ochikov Hi, I help maintain solidity-coverage. If you run into any difficulties with the API (or have suggestions about how to improve it for your case) please just lmk.

ochikov commented 4 years ago

Hey @cgewecke, how are you ? I have implemented the solidity-coverage library in a separate development branch. I used argent repo to test it, but there is a problem compiling the instrumented contracts. If I compile the raw contracts, they are compiling successfully. Once I instrument them with solidity-coverage, the following error occurs:

Screenshot 2020-01-15 at 15 24 02

Any help with the issiue ?

Thanks.

cgewecke commented 4 years ago

@ochikov I'm not sure exactly what's going on there yet but I was able to get compilation to succeed using one of the existing plugin implementations if I set .solcover.js like this:

module.exports = {
  skipFiles: ["test"]
}

... which skips instrumentation for all the contracts in the contracts/test folder. Did you build in the ability to use a solcover config file? All you really have to do is load it and pass it to the API constructor. And then sort of follow the API examples for getting it to filter the sources into skipped and targets which both get written to .coverage_contracts before compilation.

cgewecke commented 4 years ago

I think the problem is that there are non-solidity files in the contracts folder getting passed to the compiler. Uniswap JSONs at https://github.com/argentlabs/argent-contracts/tree/develop/contracts/test/uniswap

[EDIT - Actually those are getting filtered out correctly by assembleFiles... I will have to experiment a bit more.]

@elenadimitrova do you need coverage on the contracts in the test folder?

elenadimitrova commented 4 years ago

For the purposes of getting solidity-coverage working with etherlime we don't need the test contracts covered for now @cgewecke . @ochikov you can even use a simpler project for testing if you prefer, it doesn't have to be the argent contracts base.

ochikov commented 4 years ago

@elenadimitrova I've already implemented it and test it with simplе projects. It is perfectly working. I just wanted to test it with your repo, because it is quite complex. I am going to try the @cgewecke approach.

cgewecke commented 4 years ago

Investigated a bit more: suspect the problem is the number & size of the contracts in the Argent repo. Compilation succeeds even if you skip a subset of the test contracts, (e.g. test/maker, or test/compound). Did not find a specific contract which is problematic.

RE: size, by way of comparison with another large project

The coverage tool almost doubles that by injecting additional statements to track line execution.

The size of the compiler outputs for Argent,(json-stringified and written to file) are:

SolcJS might have an upper bound on how much data it can process in one go.

elenadimitrova commented 4 years ago

@ochikov is there a way to configure coverage to exclude the test folder?

ochikov commented 4 years ago

@elenadimitrova I have released a new etherlime version.

elenadimitrova commented 4 years ago

@ochikov thanks, I'm testing now. Facing some issues which I'll log separately.

Also, are you accepting a .solcover.js file for configuration?