-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot run coverage on imported contracts from node_modules #376
Comments
This is an interesting suggestion.
Can you give more info on this? I'm just curious. |
Just like @alcuadrado, I'm also curious to find out more about your use case. As far as I know, everyone expects the files under "node_modules" to be production-ready. That is, no tests or coverage should be run against them.
Yes, that is bad practice. UpdateIt seems Alec left more comments on the PR page at #375. |
I agree that the files under node_modules are expected to be production ready. However, I have encountered requests from mangers to demonstrate full coverage on all contracts, and needed to fork the tool in order to satisfy those requests. It's probably not a feature every dev will need, so if it's a pain to add it feel free to close |
@AlecSchaefer In defense of your proposal - nyc (the JS coverage tool) has a special option to allow this so it's a valid use case in JS world. My original feeling was that if there were coverage gaps in the dependencies ideally one would open PRs addressing that deficit at the source. But I can see how that might not be acceptable (or convenient) for some risk regimes. In some cases it might be quite difficult - dappsys is an example. @AlecSchaefer @PaulRBerg Do you either of you have a link / citation for the judgement that it's bad practice to maintain local versions of the deps? Not questioning correctness of this view but it would be nice to have an authoritative reference in the thread. Maybe the principle has some flexibility. |
Not off the top of my head, but I do have indirect proof. The node ecosystem is increasingly moving towards a node_module-less world (see npx, yarn pnp), hence in the future it won't even be possible to move a dependency out of "node_modules" because there will be no "node_modules". However, forking and installing from there is totally fine. Having your changes on GitHub is a much better and cohesive way of maintaining diffs. But yeah this is not a hard and fast rule and it might be just an anecdote from me and @alcuadrado. |
Just to avoid confusion: I think adding this option is a good idea. At Nomic Labs we conduct smart contract security audits, so I empathize with such a strict testing requirement, and that was the reason for my curiosity. |
The best authoritative citation I could find saying that it's bad practice to move contracts out of node_modules is in Zeppelin's public audit of Augur. In the "Medium severity" section, the audit recommends to Install OpenZeppelin via NPM. Their reasoning is partly because of a licensing issue, but they also point out that maintaining dependency contracts locally "makes it difficult and error-prone to update to a more recent version," and to, "Consider following the recommended way to use OpenZeppelin contracts, which is via the zeppelin-solidity NPM package." This advice is echoed in subsequent comments as well. I can also add that I've heard the same advice during security audits. |
@AlecSchaefer Excellent, thank you. |
@cgewecke: So where does this issue stand then? I am getting I can resolve the problem by copying that contract (from under the But it makes very little sense to resolve the problem this way. BTW, the problem appears to be Now, I know that it has to be done in order to instrument the function and allow it to emit events. What I don't understand is, how come this problem is resolved when the import is from my "local" Thanks |
Unfortunately I also don't understand this. Tbh 6.x has been substantially rewritten in 7.x because the strategy of modifying the state mutability modifiers to permit Event statements has been brittle. The most common failure comes from Truffle running Your description reminds me a little of #371. Is it possible you have identically named contracts in your inheritance tree, one in the |
@cgewecke : Thank you for your very quick response. One type is what I've described above - the The other one is even more severe IMO: For that same function, no compilation error is issued, but when called from my Truffle test, instead of returning the expected value, it returns a tx-receipt object, which is exactly what you'd expect from a non-constant function. Now, again, I'm not sure how SC handles those constant functions in general (I mean, I understand that it changes them to non-constant, but I don't know how they "behave" like constant functions when called from a Truffle test). But the two error types that I've mentioned above seem to be two sides of the same problem - a function which has changed from constant to non-constant (with the only difference being that in one case we get a compilation error and in the other case we get a runtime error). Here is a "kinda-MVP" for the first scenario (compilation error) in case you'd like to investigate it: Use:
P.S.: Thanks again :) |
@barakman I will check out the example. People are often alarmed when they see the modifiers removed, but behind the scenes the ABI's are rewritten so that truffle
Oh yes, this is a sound approach. |
@cgewecke: The difference appears to be that the I'm going to look into that now (in file But the fact is, taking a working project and adding even just an empty contract which imports from the preinstalled package, already yields a mess. |
@barakman There is an option |
@cgewecke : Thank you, but that's not the cause of the problem anyhow. I have uploaded an actual repo, in which I was hoping to rely on contracts from an npm-installed package, but instead ended up downloading those contracts at the end of the This is far from ideal of course, because But in any case, the repo is at https://github.com/bancorprotocol/airhodl. In file package.json, I am installing Then, at the end of the post-install script fix-modules.js, I am downloading all the required files - Solidity contracts, Javascript helpers, and (though not directly related to Truffle or SC) some artifacts. My alternative to this is:
If you follow the steps above, then you'll run into the I'm not expecting you to do all of this of course, but I figured I'd leave it here for future reference. Thanks. |
Ah! I wonder if this is artifact related. I noticed the Zeppelin package ships with it's own build directory. Perhaps Truffle 4 is checking those and ignoring SC's changes to the root directory build. If you run:
...does that have any effect? PS thanks for putting your solutions here, I'm sure this is not an isolated incident. |
By artifacts, I was not referring to those json files generated by Although these artifacts were extracted from Nevertheless... you've given me an idea - I'll try to preinstall the node-modules package ( Thanks Update: no luck with that ( |
This issue is pretty old, but I'm posting my personnal fix to that anyway: Add this to your
|
@Amxx This issue thread is a bit confusing and has several different topics woven through it . . . for clarity could you describe what problem your Are you expecting coverage reporting on your dependencies, or having difficult resolving dependencies while running the tool? |
Currently, you can only run coverage on custom contracts located in the /contracts directory and not on any npm installed contracts that are inherited by the custom contracts. Some developers need to demonstrate full test coverage for all smart contracts used in their projects, including those in node_modules. However, it is also considered bad practice to move npm installed contracts out of node modules and into the /contracts directory alongside custom contracts. There should be an option to configure .solcover.js to instrument all inherited contracts including those in node_modules.
I've suggested a solution for this in PR #375
The text was updated successfully, but these errors were encountered: