Merge pull request #143 from sc-forks/constant-is-view

Post-process exclude constant modifier too
pull/144/head
c-g-e-w-e-k-e- 7 years ago committed by GitHub
commit 62360bdae0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      lib/app.js
  2. 12
      test/cli/totallyPure.js
  3. 1
      test/sources/cli/PureView.sol
  4. 8
      test/sources/cli/TotallyPure.sol

@ -286,11 +286,13 @@ class App {
shell.ls(`${env}/**/*.sol`).forEach(file => { shell.ls(`${env}/**/*.sol`).forEach(file => {
const pureRe = /\spure\s/gi; const pureRe = /\spure\s/gi;
const viewRe = /\sview\s/gi; const viewRe = /\sview\s/gi;
const constantRe = /\sconstant\s/gi;
const contractPath = this.platformNeutralPath(file); const contractPath = this.platformNeutralPath(file);
let contract = fs.readFileSync(contractPath).toString(); let contract = fs.readFileSync(contractPath).toString();
contract = contract.replace(pureRe, ' '); contract = contract.replace(pureRe, ' ');
contract = contract.replace(viewRe, ' '); contract = contract.replace(viewRe, ' ');
contract = contract.replace(constantRe, ' ');
fs.writeFileSync(contractPath, contract); fs.writeFileSync(contractPath, contract);
}) })
} }

@ -15,11 +15,16 @@ contract('TotallyPure', accounts => {
const value = await instance.isPure(4,5); const value = await instance.isPure(4,5);
}); });
it('calls an importend, inherited view function', async function(){ it('calls an imported, inherited view function', async function(){
const instance = await TotallyPure.deployed(); const instance = await TotallyPure.deployed();
const value = await instance.isView(); const value = await instance.isView();
}) })
it('calls an imported, inherited constant function', async function(){
const instance = await TotallyPure.deployed();
const value = await instance.isConstant();
})
it('overrides an imported, inherited abstract pure function', async function(){ it('overrides an imported, inherited abstract pure function', async function(){
const instance = await TotallyPure.deployed(); const instance = await TotallyPure.deployed();
const value = await instance.bePure(4,5); const value = await instance.bePure(4,5);
@ -29,4 +34,9 @@ contract('TotallyPure', accounts => {
const instance = await TotallyPure.deployed(); const instance = await TotallyPure.deployed();
const value = await instance.beView(); const value = await instance.beView();
}); });
it('overrides an imported, inherited abstract constant function', async function(){
const instance = await TotallyPure.deployed();
const value = await instance.beConstant();
});
}); });

@ -8,4 +8,5 @@ contract PureView {
// Abstract functions to inherit from an uninstrumented, imported file. // Abstract functions to inherit from an uninstrumented, imported file.
function bePure(uint a, uint b) pure returns (uint); function bePure(uint a, uint b) pure returns (uint);
function beView() view returns (uint); function beView() view returns (uint);
function beConstant() constant returns (uint);
} }

@ -18,6 +18,14 @@ contract TotallyPure is PureView {
return notpureview; return notpureview;
} }
function isConstant() constant returns (uint){
return onehundred;
}
function beConstant() constant returns (uint){
return onehundred;
}
function bePure(uint a, uint b) pure returns (uint) { function bePure(uint a, uint b) pure returns (uint) {
return a + b; return a + b;
} }

Loading…
Cancel
Save