aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-compiler/test/compiler_utils_test.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-05-08 21:42:07 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-05-10 23:47:38 +0800
commita6f72de09d7b2c9738b78d2097baa9906838fbe9 (patch)
tree17126a5b45dabf2c7410d25668c68ce3d78284f0 /packages/sol-compiler/test/compiler_utils_test.ts
parent96037aed5231aa9344e5037aa6cff3d01f4abdae (diff)
downloaddexon-0x-contracts-a6f72de09d7b2c9738b78d2097baa9906838fbe9.tar.gz
dexon-0x-contracts-a6f72de09d7b2c9738b78d2097baa9906838fbe9.tar.zst
dexon-0x-contracts-a6f72de09d7b2c9738b78d2097baa9906838fbe9.zip
Rename deployer to sol-compiler
Diffstat (limited to 'packages/sol-compiler/test/compiler_utils_test.ts')
-rw-r--r--packages/sol-compiler/test/compiler_utils_test.ts83
1 files changed, 83 insertions, 0 deletions
diff --git a/packages/sol-compiler/test/compiler_utils_test.ts b/packages/sol-compiler/test/compiler_utils_test.ts
new file mode 100644
index 000000000..4fe7b994e
--- /dev/null
+++ b/packages/sol-compiler/test/compiler_utils_test.ts
@@ -0,0 +1,83 @@
+import * as chai from 'chai';
+import * as dirtyChai from 'dirty-chai';
+import * as _ from 'lodash';
+import 'mocha';
+
+import {
+ createDirIfDoesNotExistAsync,
+ getNormalizedErrMsg,
+ parseDependencies,
+ parseSolidityVersionRange,
+} from '../src/utils/compiler';
+import { fsWrapper } from '../src/utils/fs_wrapper';
+
+chai.use(dirtyChai);
+const expect = chai.expect;
+
+describe('Compiler utils', () => {
+ describe('#getNormalizedErrorMessage', () => {
+ it('normalizes the error message', () => {
+ const errMsg = 'base/Token.sol:6:46: Warning: Unused local variable';
+ const normalizedErrMsg = getNormalizedErrMsg(errMsg);
+ expect(normalizedErrMsg).to.be.equal('Token.sol:6:46: Warning: Unused local variable');
+ });
+ });
+ describe('#createDirIfDoesNotExistAsync', () => {
+ it('creates artifacts dir', async () => {
+ const artifactsDir = `${__dirname}/artifacts`;
+ expect(fsWrapper.doesPathExistSync(artifactsDir)).to.be.false();
+ await createDirIfDoesNotExistAsync(artifactsDir);
+ expect(fsWrapper.doesPathExistSync(artifactsDir)).to.be.true();
+ fsWrapper.rmdirSync(artifactsDir);
+ expect(fsWrapper.doesPathExistSync(artifactsDir)).to.be.false();
+ });
+ });
+ describe('#parseSolidityVersionRange', () => {
+ it('correctly parses the version range', () => {
+ expect(parseSolidityVersionRange('pragma solidity ^0.0.1;')).to.be.equal('^0.0.1');
+ expect(parseSolidityVersionRange('\npragma solidity 0.0.1;')).to.be.equal('0.0.1');
+ expect(parseSolidityVersionRange('pragma solidity <=1.0.1;')).to.be.equal('<=1.0.1');
+ expect(parseSolidityVersionRange('pragma solidity ~1.0.1;')).to.be.equal('~1.0.1');
+ });
+ // TODO: For now that doesn't work. This will work after we switch to a grammar-based parser
+ it.skip('correctly parses the version range with comments', () => {
+ expect(parseSolidityVersionRange('// pragma solidity ~1.0.1;\npragma solidity ~1.0.2;')).to.be.equal(
+ '~1.0.2',
+ );
+ });
+ });
+ describe('#parseDependencies', () => {
+ it('correctly parses Exchange dependencies', async () => {
+ const path = `${__dirname}/fixtures/contracts/Exchange.sol`;
+ const source = await fsWrapper.readFileAsync(path, {
+ encoding: 'utf8',
+ });
+ const dependencies = parseDependencies({ source, path });
+ const expectedDependencies = [
+ 'zeppelin-solidity/contracts/token/ERC20/ERC20.sol',
+ 'packages/sol-compiler/lib/test/fixtures/contracts/TokenTransferProxy.sol',
+ 'packages/sol-compiler/lib/test/fixtures/contracts/base/SafeMath.sol',
+ ];
+ _.each(expectedDependencies, expectedDepdency => {
+ const foundDependency = _.find(dependencies, dependency => _.endsWith(dependency, expectedDepdency));
+ expect(foundDependency, `${expectedDepdency} not found`).to.not.be.undefined();
+ });
+ });
+ it('correctly parses TokenTransferProxy dependencies', async () => {
+ const path = `${__dirname}/fixtures/contracts/TokenTransferProxy.sol`;
+ const source = await fsWrapper.readFileAsync(path, {
+ encoding: 'utf8',
+ });
+ expect(parseDependencies({ source, path })).to.be.deep.equal([
+ 'zeppelin-solidity/contracts/ownership/Ownable.sol',
+ 'zeppelin-solidity/contracts/token/ERC20/ERC20.sol',
+ ]);
+ });
+ // TODO: For now that doesn't work. This will work after we switch to a grammar-based parser
+ it.skip('correctly parses commented out dependencies', async () => {
+ const path = '';
+ const source = `// import "./TokenTransferProxy.sol";`;
+ expect(parseDependencies({ path, source })).to.be.deep.equal([]);
+ });
+ });
+});