Merge pull request #133 from sc-forks/truffle-4

Permit view, pure, experimental and solc 0.4.17
npm-parser
c-g-e-w-e-k-e- 7 years ago committed by GitHub
commit 721fb87c53
  1. 6
      lib/preprocessor.js
  2. 1268
      package-lock.json
  3. 7
      package.json
  4. 23
      test/app.js
  5. 17
      test/cli/pureview.js
  6. 15
      test/sources/cli/PureView.sol

@ -16,12 +16,18 @@ function blockWrap(contract, expression) {
* and brackets them. Instrumenter needs to inject events at these locations and having
* them pre-bracketed simplifies the process. Each time a modification is made the contract
* is passed back to the parser and re-walked because all the starts and ends get shifted.
*
* Also removes pure and view modifiers.
*
* @param {String} contract solidity code
* @return {String} contract
*/
module.exports.run = function r(contract) {
let keepRunning = true;
contract = contract.replace(/ pure /, ' ');
contract = contract.replace(/ view /, ' ');
while (keepRunning) {
const ast = SolidityParser.parse(contract);
keepRunning = false;

1268
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -21,12 +21,10 @@
"author": "",
"license": "ISC",
"dependencies": {
"commander": "^2.9.0",
"death": "^1.1.0",
"ethereumjs-testrpc-sc": "4.0.2",
"istanbul": "^0.4.5",
"keccakjs": "^0.2.1",
"mkdirp": "^0.5.1",
"req-cwd": "^1.0.1",
"shelljs": "^0.7.4",
"sol-explore": "^1.6.2",
@ -43,11 +41,10 @@
"ethereumjs-tx": "^1.2.2",
"ethereumjs-util": "^5.0.1",
"ethereumjs-vm": "https://github.com/sc-forks/ethereumjs-vm-sc.git",
"istanbul": "^0.4.5",
"merkle-patricia-tree": "~2.1.2",
"mocha": "^3.1.0",
"solc": "0.4.13",
"solc": "0.4.17",
"request": "^2.81.0",
"truffle": "3.4.4"
"truffle": "4.0.0-beta.2"
}
}

@ -240,6 +240,29 @@ describe('app', () => {
collectGarbage();
});
it('tests use pure and view modifiers', () => {
// Directory should be clean
assert(pathExists('./coverage') === false, 'should start without: coverage');
assert(pathExists('./coverage.json') === false, 'should start without: coverage.json');
// Run script (exits 0);
mock.install('PureView.sol', 'pureview.js', config);
shell.exec(script);
assert(shell.error() === null, 'script should not error');
// Directory should have coverage report
assert(pathExists('./coverage') === true, 'script should gen coverage folder');
assert(pathExists('./coverage.json') === true, 'script should gen coverage.json');
// Coverage should be real.
// This test is tightly bound to the function names in Simple.sol
const produced = JSON.parse(fs.readFileSync('./coverage.json', 'utf8'));
const path = Object.keys(produced)[0];
assert(produced[path].fnMap['1'].name === 'isPure', 'coverage.json should map "isPure"');
assert(produced[path].fnMap['2'].name === 'isView', 'coverage.json should map "isView"');
collectGarbage();
})
it('tests require assets outside of test folder: should generate coverage, cleanup & exit(0)', () => {
// Directory should be clean
assert(pathExists('./coverage') === false, 'should start without: coverage');

@ -0,0 +1,17 @@
/* eslint-env node, mocha */
/* global artifacts, contract, assert */
const PureView = artifacts.require('./PureView.sol');
contract('PureView', accounts => {
it('calls a pure function', async function(){
const instance = await PureView.deployed();
const value = await instance.isPure(4,5);
});
it('calls a view function', async function(){
const instance = await PureView.deployed();
const value = await instance.isView();
})
});

@ -0,0 +1,15 @@
pragma experimental "v0.5.0";
contract PureView {
// Make sure we aren't corrupting anything with the replace
uint notpureview = 5;
function isPure(uint a, uint b) pure returns (uint){
return a * b;
}
function isView() view returns (uint){
return notpureview;
}
}
Loading…
Cancel
Save