Skip to content

Commit a738fd4

Browse files
authored
Merge pull request #53 from sc-forks/readme-gas-example
Add gasEstimation example.
2 parents aa41e80 + 8b627fa commit a738fd4

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

README.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,26 @@ This is because the instrumentation process increases the gas costs for using th
9696
the extra events. If this is the case, then the coverage may be incomplete. To avoid this, using
9797
`estimateGas` to estimate your gas costs should be more resilient in most cases.
9898

99+
Example (in a Truffle test):
100+
```javascript
101+
// Hardcoded Gas Call
102+
MyContract.deployed().then(instance => {
103+
instance.claimTokens(0, {gasLimit: 3000000}).then(() => {
104+
assert(web3.eth.getBalance(instance.address).equals(new BigNumber('0')))
105+
done();
106+
})
107+
});
108+
109+
// Using gas estimation
110+
MyContract.deployed().then(instance => {
111+
const data = instance.contract.claimTokens.getData(0);
112+
const gasEstimate = web3.eth.estimateGas({to: instance.address, data: data});
113+
instance.claimTokens(0, {gasLimit: gasEstimate}).then(() => {
114+
assert(web3.eth.getBalance(instance.address).equals(new BigNumber('0')))
115+
done();
116+
})
117+
});
118+
```
99119
**Using `require` in `migrations.js` files**: Truffle overloads Node's `require` function but
100120
implements a simplified search algorithm for node_modules packages
101121
([see Truffle issue #383](https://github.com/trufflesuite/truffle/issues/383)).
@@ -117,12 +137,12 @@ find discrepancies between the coverage report and your suite's behavior, please
117137
+ **metacoin**: The default truffle project
118138
+ [HTML reports](https://sc-forks.github.io/metacoin/)
119139
+ [Metacoin with solidity-coverage installed](https://github.com/sc-forks/metacoin) (simple, without configuration)
120-
+ **zeppelin-solidity** at commit 453a19825013a586751b87c67bebd551a252fb50
121-
+ [HTML reports]( https://sc-forks.github.io/zeppelin-solidity/)
122-
+ [Zeppelin with solidity-coverage installed](https://github.com/sc-forks/zeppelin-solidity) (declares own coverage network in truffle.js)
123-
+ **numeraire** at commit 5ac3fa432c6b4192468c95a66e52ca086c804c95
124-
+ [HTML reports](https://sc-forks.github.io/contract/)
125-
+ [Numeraire with solidity-coverage installed](https://github.com/sc-forks/contract) (uses .solcover.js)
140+
+ **zeppelin-solidity** at commit [453a198](https://github.com/OpenZeppelin/zeppelin-solidity/tree/453a19825013a586751b87c67bebd551a252fb50)
141+
+ [HTML reports]( https://sc-forks.github.io/zeppelin-solidity/)(declares own coverage network in truffle.js)
142+
+ [Zeppelin with solidity-coverage installed](https://github.com/sc-forks/zeppelin-solidity)
143+
+ **numeraire** at commit [695b0a0](https://github.com/numerai/contract/tree/695b0a073c1f70199138f5e988e8cc20382205a4)(uses .solcover.js)
144+
+ [HTML reports](https://sc-forks.github.io/contract/contracts/index.html)
145+
+ [Numeraire with solidity-coverage installed](https://github.com/sc-forks/contract)
126146

127147
### Contribution Guidelines
128148

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@
4444
"merkle-patricia-tree": "~2.1.2",
4545
"mocha": "^3.1.0",
4646
"solc": "0.4.8",
47-
"truffle": "^3.2.5"
47+
"truffle": "3.2.5"
4848
}
4949
}

0 commit comments

Comments
 (0)