Readme edits, file & deps cleanup

pull/341/head
cgewecke 5 years ago
parent a3a4a97d11
commit f3462cf962
  1. 1
      .eslintignore
  2. 57
      .eslintrc
  3. 33
      README.md
  4. 100
      docs/faq.md
  5. 2
      package.json
  6. 2
      test/cli/wallet.js
  7. 5
      test/sources/cli/Wallet.sol
  8. 5
      yarn.lock

@ -1 +0,0 @@
test/cli/truffle-crash.js

@ -1,57 +0,0 @@
{
"extends": ["airbnb-base"],
"plugins": ["mocha"],
"env":{
"meteor": true,
"node": true,
"commonjs": true
},
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"rules": {
/* General */
"consistent-return": [0],
"no-return-assign": [0],
"complexity": ["error", 20],
"eol-last": [0],
"eqeqeq": ["error", "smart"],
"max-len": ["error", 150, 2],
"no-console": [0],
"no-mixed-requires": [0],
"no-native-reassign": [0],
"no-param-reassign": [0],
"no-use-before-define" : ["error", { "functions": false }],
"no-useless-rename": ["error", {
"ignoreDestructuring": true
}],
"no-undefined": ["error"],
"no-underscore-dangle": ["error", { "allow": ["_id"], "allowAfterThis": true }],
"object-curly-spacing": ["error", "always", {
"objectsInObjects": false,
"arraysInObjects": false
}],
"no-unused-expressions": ["error", { "allowShortCircuit": true, "allowTernary": true }],
"object-curly-newline": ["error", { "minProperties": 1 }],
"object-property-newline": ["error"],
"prefer-template": [0],
"quotes": [2, "single"],
"radix": ["error", "always"],
"require-yield": [0],
"semi": [2, "always"],
"no-unused-vars": 0,
"import/extensions": [0],
"arrow-parens":[2, "as-needed"],
"no-plusplus":[2, { "allowForLoopAfterthoughts": true }],
"no-bitwise": [2],
"import/no-unresolved": [2, { ignore: ['\.sol\.js$'] }],
"class-methods-use-this": [2],
/* Plugins */
"import/no-extraneous-dependencies": [0],
"mocha/no-exclusive-tests": "error"
},
"settings": {
}
}

@ -26,24 +26,22 @@ $ npm install --save-dev solidity-coverage@beta
$ npx solidity-coverage
```
**NB:** for most projects you'll also need to configure a 'coverage' network in
truffle-config.js. See the Network Configuration guide below.
**NB:** Most projects will also need to set a `coverage` network in
truffle-config.js. See [Network Configuration](#network-configuration).
### Usage notes:
+ Requires Solidity pragmas >= `0.5.0`.
+ For solidity pragma >= `0.5.0`.
+ Tests run more slowly while coverage is being generated.
+ Your contracts will be double-compiled and a delay between compilation and
+ Your contracts will be double-compiled and a (long) delay between compilation and
the beginning of test execution is possible if your contracts are large.
+ solidity-coverage expects a globally installed truffle in your environment / on CI. If you
prefer to control which Truffle version your tests are run with, please see the FAQ for
[running truffle as a local dependency](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-truffle-as-a-local-dependency).
+ Solidity fixtures / mocks stored in the `tests/` directory are no longer supported. If your suite uses native Solidity testing or accesses contracts via mocks stored in `tests/` (a la Zeppelin), coverage will trigger test errors because it's unable to rewrite your contract ABIs appropriately. Mocks should be relocated to the root folder's `contracts` directory. More on why this is necessary at issue [146](https://github.com/sc-forks/solidity-coverage/issues/146)
+ Truffle should be globallly installed in your environment.. If you prefer running truffle as
a local dependency, please see [this section](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-truffle-as-a-local-dependency) of the FAQ.
+ If your suite uses native Solidity testing or accesses contracts via mocks stored in `tests/` (a la Zeppelin), coverage will trigger test errors because it's unable to control truffle's compilation of that folder. Mocks should be relocated to the root `contracts` directory. More on why this is necessary at issue [146](https://github.com/sc-forks/solidity-coverage/issues/146)
### Network Configuration
By default, solidity-coverage connects to a coverage-enabled fork of the ganache-cli client
called **testrpc-sc** on port 8555. (It ships with `solidity-coverage` -
there's nothing extra to download.)
By default, this tool connects to a coverage-enabled fork of ganache-cli
called **testrpc-sc** on port 8555. (It's a dependency - there's nothing extra to download.)
In `truffle-config.js`, add a coverage network following the example below.
@ -69,8 +67,8 @@ module.exports = {
```
### Options
You can also create a `.solcover.js` config file in the root directory of your project and specify
additional options if necessary:
Additional options can be specified in a `.solcover.js` config file located in
the root directory of your project.
**Example:**
```javascript
@ -102,7 +100,7 @@ module.exports = {
### FAQ
Solutions to common issues people run into using this tool:
Solutions to common problems people run into:
+ [Running out of gas](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-out-of-gas)
+ [Running out of memory (locally and in CI)](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-out-of-memory-locally-and-in-ci)
@ -110,7 +108,6 @@ Solutions to common issues people run into using this tool:
+ [Running on windows](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-on-windows)
+ [Running testrpc-sc on its own](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-testrpc-sc-on-its-own)
+ [Running truffle as a local dependency](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-truffle-as-a-local-dependency)
+ [Using alongside HDWalletProvider](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#using-alongside-hdwalletprovider)
+ [Integrating into CI](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#continuous-integration-installing-metacoin-on-travisci-with-coveralls)
+ [Why are asserts and requires highlighted as branch points?](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#why-has-my-branch-coverage-decreased-why-is-assert-being-shown-as-a-branch-point)
+ [Why are `send` and `transfer` throwing in my tests?](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#why-are-send-and-transfer-throwing)
@ -119,14 +116,12 @@ Solutions to common issues people run into using this tool:
### Example reports
+ [metacoin](https://sc-forks.github.io/metacoin/) (Istanbul HTML)
+ [openzeppelin-solidity](https://coveralls.io/github/OpenZeppelin/openzeppelin-solidity?branch=master) (Coveralls)
+ [gnosis-contracts](https://codecov.io/gh/gnosis/gnosis-contracts/tree/master/contracts) (Codecov)
### Contribution Guidelines
Contributions are welcome! If you're opening a PR that adds features please consider writing some
[unit tests](https://github.com/sc-forks/solidity-coverage/tree/master/test) for them. You could
also lint your submission with `npm run lint`. Bugs can be reported in the
[issues](https://github.com/sc-forks/solidity-coverage/issues).
[unit tests](https://github.com/sc-forks/solidity-coverage/tree/master/test) for them. Bugs can be
reported in the [issues](https://github.com/sc-forks/solidity-coverage/issues).
Set up the development environment with:
```

@ -6,7 +6,8 @@
**Step 1: Create a metacoin project & install coverage tools**
```bash
$ truffle init
$ truffle unbox metacoin
$ rm test/TestMetacoin.sol # No solidity tests, sorry.
# Install coverage dependencies
$ npm init
@ -19,7 +20,7 @@ $ npm install --save-dev solidity-coverage
```javascript
"scripts": {
"test": "truffle test",
"coverage": "./node_modules/.bin/solidity-coverage"
"coverage": "npx solidity-coverage"
},
```
@ -30,7 +31,7 @@ sudo: required
dist: trusty
language: node_js
node_js:
- '7'
- '10'
install:
- npm install -g truffle
- npm install -g ganache-cli
@ -43,7 +44,7 @@ before_script:
after_script:
- npm run coverage && cat coverage/lcov.info | coveralls
```
**NB:** It's probably best practice to run coverage in CI as an `after_script` or in a [parallel build](https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/.travis.yml) rather than assume its equivalence to `truffle test`. Solidity-coverage's `testrpc` uses gasLimits far above the current blocklimit and rewrites your contracts in ways that might affect their behavior. It's also less robust than Truffle and may fail more frequently.
**NB:** It's best practice to run coverage in a [parallel CI build](https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/.travis.yml) rather than assume its equivalence to `truffle test`. Coverage's `testrpc-sc` uses gasLimits far above the current blocklimit and rewrites your contracts in ways that might affect their behavior. It's also less robust than Truffle and may fail more frequently.
**Step 4: Toggle the project on at Travis and Coveralls and push.**
@ -57,33 +58,12 @@ after_script:
### Running out of gas
If you have hardcoded gas costs into your tests some of them may fail when using solidity-coverage.
This is because the instrumentation process increases the gas costs for using the contracts, due to
the extra events. If this is the case, then the coverage may be incomplete. To avoid this, using
`estimateGas` to estimate your gas costs should be more resilient in most cases.
**Example:**
```javascript
// Hardcoded Gas Call
MyContract.deployed().then(instance => {
instance.claimTokens(0, {gasLimit: 3000000}).then(() => {
assert(web3.eth.getBalance(instance.address).equals(new BigNumber('0')))
done();
})
});
// Using gas estimation
MyContract.deployed().then(instance => {
const data = instance.contract.claimTokens.getData(0);
const gasEstimate = web3.eth.estimateGas({to: instance.address, data: data});
instance.claimTokens(0, {gasLimit: gasEstimate}).then(() => {
assert(web3.eth.getBalance(instance.address).equals(new BigNumber('0')))
done();
})
});
```
### Running out of memory (Locally and in CI)
(See [issue #59](https://github.com/sc-forks/solidity-coverage/issues/59)).
@ -104,55 +84,20 @@ limit to 7.5MB (ProTip courtesy of [@federicobond](https://github.com/federicobo
Truffle sets a default mocha timeout of 5 minutes. Because tests run slower under coverage, it's possible to hit this limit with a test that iterates hundreds of times before producing a result. Timeouts can be disabled by configuring the mocha option in `truffle.js` as below: (ProTip courtesy of [@cag](https://github.com/cag))
```javascript
module.exports = {
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*"
},
...etc...
},
mocha: {
enableTimeouts: false
}
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*"
},
...etc...
},
mocha: {
enableTimeouts: false
}
}
```
### Using alongside HDWalletProvider
[See Truffle issue #348](https://github.com/trufflesuite/truffle/issues/348).
HDWalletProvider crashes solidity-coverage, so its constructor shouldn't be invoked while running this tool.
One way around this is to instantiate the HDWallet conditionally in `truffle.js`:
```javascript
var HDWalletProvider = require('truffle-hdwallet-provider');
var mnemonic = 'bark moss walnuts earth flames felt grateful dead sophia loren';
if (!process.env.SOLIDITY_COVERAGE){
provider = new HDWalletProvider(mnemonic, 'https://ropsten.infura.io/')
}
module.exports = {
networks:
ropsten: {
provider: provider,
network_id: 3
},
coverage: {
host: "localhost",
network_id: "*",
port: 8555,
...etc..
}
...etc...
```
And set up an npm script to run the coverage tool like this:
```javascript
"scripts": {
"coverage": "SOLIDITY_COVERAGE=true ./node_modules/.bin/solidity-coverage"
},
```
### Why has my branch coverage decreased? Why is assert being shown as a branch point?
`assert` and `require` check whether a condition is true or not. If it is, they allow execution to proceed. If not, they throw, and all changes are reverted. Indeed, prior to [Solidity 0.4.10](https://github.com/ethereum/solidity/releases/tag/v0.4.10), when `assert` and `require` were introduced, this functionality was achieved by code that looked like
@ -174,8 +119,8 @@ If an `assert` or `require` is marked with an `I` in the coverage report, then d
If you include contracts that have fallback function in the list of files to instrument and attempt to `send` or `transfer` to them,
the methods will throw because the instrumentation consumes more gas than these methods allow. See the `skipFiles` option in the
README to exclude these files and [issue 118](https://github.com/sc-forks/solidity-coverage/issues/118) for a more detailed discussion of
this problem.
README to exclude these files and [issue 118](https://github.com/sc-forks/solidity-coverage/issues/118) for a more detailed discussion. This problem persists in v0.6.x even though the vm is set to emit free logs.
(Under investigation).
### Running on windows
@ -190,15 +135,8 @@ launching `testrpc-sc` on its own from the command line before running `solidity
Sometimes its useful to launch `testrpc-sc` separately at the command line or with a script, after
setting the `norpc` config option in `.solcover.js` to true:
If you installed using npm
```
$ ./node_modules/.bin/testrpc-sc <options>
```
If you installed using yarn
```
$ ./node_modules/ethereumjs-testrpc-sc/bin/testrpc // v0.1.10 and below (testrpc v3.0.3)
$ ./node_modules/ethereumjs-testrpc-sc/build/cli.node.js // All others (testrpc v4.0.1 +)
$ npx testrpc-sc <options>
```
### Running truffle as a local dependency

@ -25,7 +25,7 @@
"istanbul": "^0.4.5",
"keccakjs": "^0.2.1",
"req-cwd": "^1.0.1",
"shelljs": "https://github.com/sc-forks/shelljs.git",
"shelljs": "^0.8.3",
"sol-explore": "^1.6.2",
"solidity-parser-antlr": "0.4.5",
"tree-kill": "^1.2.0",

@ -9,7 +9,7 @@ contract('Wallet', accounts => {
const walletB = await Wallet.new();
await walletA.sendTransaction({
value: web3.utils.toBN(100), from: accounts[0],
value: web3.utils.toBN(500), from: accounts[0],
});
console.log('transaction done')
await walletA.sendPayment(50, walletB.address, {

@ -9,14 +9,13 @@ contract Wallet {
}
function sendPayment(uint payment, address payable recipient) public {
if (!recipient.send(payment))
revert();
require(recipient.send(payment), 'sendPayment failed');
}
function getBalance() public view returns(uint){
return address(this).balance;
}
function() external payable
{
if (msg.value > 0)

@ -2782,9 +2782,10 @@ shebang-regex@^1.0.0:
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=
"shelljs@https://github.com/sc-forks/shelljs.git":
shelljs@^0.8.3:
version "0.8.3"
resolved "https://github.com/sc-forks/shelljs.git#7aa8ce4ebdcb42b95f59093772afce230f2a3ca0"
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.3.tgz#a7f3319520ebf09ee81275b2368adb286659b097"
integrity sha512-fc0BKlAWiLpwZljmOvAOTE/gXawtCoNrP5oaY7KIaQbbyHeQVg01pSEuEGvGh3HEdBU4baCD7wQBwADmM/7f7A==
dependencies:
glob "^7.0.0"
interpret "^1.0.0"

Loading…
Cancel
Save