Skip to content

Restore preprocessing of constant/view #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,13 @@ class App {
postProcessPure(env) {
shell.ls(`${env}/**/*.sol`).forEach(file => {
const pureRe = /\spure\s/gi;

const viewRe = /\sview\s/gi;
const constantRe = /\sconstant\s/gi;
const contractPath = this.platformNeutralPath(file);
let contract = fs.readFileSync(contractPath).toString();
contract = contract.replace(pureRe, ' ');
contract = contract.replace(viewRe, ' ');
contract = contract.replace(constantRe, ' ');
fs.writeFileSync(contractPath, contract);
})
}
Expand Down
2 changes: 1 addition & 1 deletion test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ describe('app', () => {
assert(produced[path].fnMap['1'].name === 'usesThem', 'coverage.json should map "usesThem"');
assert(produced[path].fnMap['2'].name === 'isPure', 'coverage.json should map "getX"');
collectGarbage();
})
});

it('tests require assets outside of test folder: should generate coverage, cleanup & exit(0)', () => {
// Directory should be clean
Expand Down
39 changes: 22 additions & 17 deletions test/cli/totallyPure.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,44 @@
const TotallyPure = artifacts.require('./TotallyPure.sol');

contract('TotallyPure', accounts => {

it('calls imported, inherited pure/view functions within its own function', async function(){
it('calls imported, inherited pure/view functions within its own function', async () => {
const instance = await TotallyPure.deployed();
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 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 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 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 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 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 value = await instance.beConstant();
const value = await instance.beConstant.call();
assert.equal(value.toNumber(), 99);
});
});