Merge pull request #147 from sc-forks/fix/constant-pure-view

Restore preprocessing of constant/view
fix/constant-variables
c-g-e-w-e-k-e- 7 years ago committed by GitHub
commit 46291c6d8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      lib/app.js
  2. 2
      test/app.js
  3. 39
      test/cli/totallyPure.js

@ -285,10 +285,13 @@ class App {
postProcessPure(env) { postProcessPure(env) {
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 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(constantRe, ' ');
fs.writeFileSync(contractPath, contract); fs.writeFileSync(contractPath, contract);
}) })
} }

@ -261,7 +261,7 @@ describe('app', () => {
assert(produced[path].fnMap['1'].name === 'usesThem', 'coverage.json should map "usesThem"'); assert(produced[path].fnMap['1'].name === 'usesThem', 'coverage.json should map "usesThem"');
assert(produced[path].fnMap['2'].name === 'isPure', 'coverage.json should map "getX"'); assert(produced[path].fnMap['2'].name === 'isPure', 'coverage.json should map "getX"');
collectGarbage(); collectGarbage();
}) });
it('tests require assets outside of test folder: should generate coverage, cleanup & exit(0)', () => { it('tests require assets outside of test folder: should generate coverage, cleanup & exit(0)', () => {
// Directory should be clean // Directory should be clean

@ -4,39 +4,44 @@
const TotallyPure = artifacts.require('./TotallyPure.sol'); const TotallyPure = artifacts.require('./TotallyPure.sol');
contract('TotallyPure', accounts => { contract('TotallyPure', accounts => {
it('calls imported, inherited pure/view functions within its own function', async () => {
it('calls imported, inherited pure/view functions within its own function', async function(){
const instance = await TotallyPure.deployed(); const instance = await TotallyPure.deployed();
await instance.usesThem(); await instance.usesThem();
}); });
it('calls an imported, inherited pure function', async function(){ it('calls an imported, inherited pure function', async () => {
const instance = await TotallyPure.deployed(); const instance = await TotallyPure.deployed();
const value = await instance.isPure(4,5); const value = await instance.isPure.call(4, 5);
assert.equal(value.toNumber(), 20);
}); });
it('calls an imported, inherited view function', async function(){ it('calls an imported, inherited view function', async () => {
const instance = await TotallyPure.deployed(); const instance = await TotallyPure.deployed();
const value = await instance.isView(); const value = await instance.isView.call();
}) assert.equal(value.toNumber(), 5);
});
it('calls an imported, inherited constant function', async function(){ it('calls an imported, inherited constant function', async () => {
const instance = await TotallyPure.deployed(); const instance = await TotallyPure.deployed();
const value = await instance.isConstant(); const value = await instance.isConstant.call();
}) assert.equal(value.toNumber(), 99);
});
it('overrides an imported, inherited abstract pure function', async function(){ it('overrides an imported, inherited abstract pure function', async () => {
const instance = await TotallyPure.deployed(); const instance = await TotallyPure.deployed();
const value = await instance.bePure(4,5); const value = await instance.bePure.call(4, 5);
}) assert.equal(value.toNumber(), 9);
});
it('overrides an imported, inherited abstract view function', async function(){ it('overrides an imported, inherited abstract view function', async () => {
const instance = await TotallyPure.deployed(); const instance = await TotallyPure.deployed();
const value = await instance.beView(); const value = await instance.beView.call();
assert.equal(value.toNumber(), 99);
}); });
it('overrides an imported, inherited abstract constant function', async function(){ it('overrides an imported, inherited abstract constant function', async () => {
const instance = await TotallyPure.deployed(); const instance = await TotallyPure.deployed();
const value = await instance.beConstant(); const value = await instance.beConstant.call();
assert.equal(value.toNumber(), 99);
}); });
}); });
Loading…
Cancel
Save