Skip to content

Commit

Permalink
Add support for custom allowed paths (TrueFiEng#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
marekkirejczyk authored Jan 22, 2019
1 parent 8599a25 commit b093aca
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
43 changes: 43 additions & 0 deletions docs/source/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,46 @@ You can generate files that are compatible with both current and previous versio
...
"legacyOutput": "true"
}

Monorepo
--------
Waffle works well with mono-repositories. It is enough to set up common npmPath in the configuration file to make it work.
We recommend using `yarn workspaces <https://yarnpkg.com/lang/en/docs/workspaces/>`_ and `wsrun <https://github.com/whoeverest/wsrun>`_ for monorepo management.

Lernajs + Native solc
^^^^^^^^^^^^^^^^^^^^^
Waffle works with `lerna <https://lernajs.io/>`_, but require additional configuration.
When lerna cross-links npm packages in monorepo, it creates symbolic links to original catalog.
That leads to sources files located beyond allowed paths. This process breaks compilation with native solc.


If you see a message like below in your monorepo setup:
::

contracts/Contract.sol:4:1: ParserError: Source ".../monorepo/node_modules/YourProjectContracts/contracts/Contract.sol" not found: File outside of allowed directories.
import "YourProjectContracts/contracts/Contract.sol";


you probably need to add allowedPath to your waffle configuration.

Assuming you have the following setup:
::

/monorepo
/YourProjectContracts
/contracts
/YourProjectDapp
/contracts

Add to waffle configuration in YourProjectDapp:
::

{
...
allowedPath: ["../YourProjectContracts"]
}


That should solve a problem.

Currently Waffle does not support similar feature for dockerized solc.
1 change: 1 addition & 0 deletions lib/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface Config {
'docker-tag'?: string;
solcVersion?: string;
legacyOutput?: string;
allowedPaths?: string[];
}

const defaultConfig: Config = {
Expand Down
5 changes: 3 additions & 2 deletions lib/wrappers/nativeWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default class NativeWrapper extends BaseWrapper {
public buildCommand() {
const command = 'solc';
const params = '--standard-json';
const allowedPaths = `${resolve(this.config.sourcesPath)},${resolve(this.config.npmPath)}`;
return `${command} ${params} --allow-paths ${allowedPaths}`;
const customAllowedPaths = (this.config.allowedPaths || []).map( (path) => resolve(path));
const allowedPaths = [resolve(this.config.sourcesPath), resolve(this.config.npmPath), ...customAllowedPaths];
return `${command} ${params} --allow-paths ${allowedPaths.join(',')}`;
}
}
21 changes: 13 additions & 8 deletions test/compiler/wrappers/nativeWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@ const npmPath = './test/projects/custom/custom_node_modules';
const config = {sourcesPath, npmPath};

describe('UNIT: NativeWrapper', () => {
let wrapper: NativeWrapper;

before(() => {
wrapper = new NativeWrapper(config);
it('buildCommand', async () => {
const wrapper = new NativeWrapper(config);
const actualCommand = wrapper.buildCommand();
const expectedCommand = 'solc --standard-json --allow-paths ' +
'.*test/projects/custom/custom_contracts,.*/test/projects/custom/custom_node_modules';
expect(actualCommand).to.match(new RegExp(expectedCommand));
});

it('buildCommand', async () => {
const expectedPrefix = 'solc --standard-json --allow-paths';
const expectedSuffix = 'test/projects/custom/custom_node_modules';
it('buildCommand with custom allow_paths', async () => {
const configWithAllowedPaths = {...config, allowedPaths: ['some/random/path', './yet/another/path']};
const wrapper = new NativeWrapper(configWithAllowedPaths);
const actualCommand = wrapper.buildCommand();
expect(actualCommand).to.startWith(expectedPrefix);
expect(actualCommand).to.endWith(expectedSuffix);
const expectedCommand = 'solc --standard-json --allow-paths ' +
'.*test/projects/custom/custom_contracts,.*/test/projects/custom/custom_node_modules' +
',.*/some/random/path.*/yet/another/path';
expect(actualCommand).to.match(new RegExp(expectedCommand));
});
});

0 comments on commit b093aca

Please sign in to comment.