aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-compiler/test
diff options
context:
space:
mode:
authorF. Eugene Aumson <gene@aumson.org>2018-08-15 08:40:31 +0800
committerF. Eugene Aumson <gene@aumson.org>2018-08-15 08:40:31 +0800
commitbb4558e0be3aa9c182217e56cd2ff2f042d5473a (patch)
tree667d8d7f8af53d1f8b9f4826fcdc1157ef86bc37 /packages/sol-compiler/test
parente79c7632e6e82ecc53563da6d8727ce4475078c6 (diff)
downloaddexon-sol-tools-bb4558e0be3aa9c182217e56cd2ff2f042d5473a.tar
dexon-sol-tools-bb4558e0be3aa9c182217e56cd2ff2f042d5473a.tar.gz
dexon-sol-tools-bb4558e0be3aa9c182217e56cd2ff2f042d5473a.tar.bz2
dexon-sol-tools-bb4558e0be3aa9c182217e56cd2ff2f042d5473a.tar.lz
dexon-sol-tools-bb4558e0be3aa9c182217e56cd2ff2f042d5473a.tar.xz
dexon-sol-tools-bb4558e0be3aa9c182217e56cd2ff2f042d5473a.tar.zst
dexon-sol-tools-bb4558e0be3aa9c182217e56cd2ff2f042d5473a.zip
test compiler
Diffstat (limited to 'packages/sol-compiler/test')
-rw-r--r--packages/sol-compiler/test/compiler_test.ts86
-rw-r--r--packages/sol-compiler/test/fixtures/contracts/BadContractName.sol3
-rw-r--r--packages/sol-compiler/test/fixtures/contracts/EmptyContract.sol3
3 files changed, 80 insertions, 12 deletions
diff --git a/packages/sol-compiler/test/compiler_test.ts b/packages/sol-compiler/test/compiler_test.ts
index c9e141ee9..4a3b6e4a7 100644
--- a/packages/sol-compiler/test/compiler_test.ts
+++ b/packages/sol-compiler/test/compiler_test.ts
@@ -1,5 +1,7 @@
-import { DoneCallback } from '@0xproject/types';
+import { join } from 'path';
+
import * as chai from 'chai';
+import * as chaiAsPromised from 'chai-as-promised';
import 'mocha';
import { Compiler } from '../src/compiler';
@@ -9,29 +11,28 @@ import { CompilerOptions, ContractArtifact } from '../src/utils/types';
import { exchange_binary } from './fixtures/exchange_bin';
import { constants } from './util/constants';
+chai.use(chaiAsPromised);
const expect = chai.expect;
describe('#Compiler', function(): void {
this.timeout(constants.timeoutMs); // tslint:disable-line:no-invalid-this
const artifactsDir = `${__dirname}/fixtures/artifacts`;
const contractsDir = `${__dirname}/fixtures/contracts`;
- const exchangeArtifactPath = `${artifactsDir}/Exchange.json`;
const compilerOpts: CompilerOptions = {
artifactsDir,
contractsDir,
contracts: constants.contracts,
};
- const compiler = new Compiler(compilerOpts);
- beforeEach((done: DoneCallback) => {
- (async () => {
- if (fsWrapper.doesPathExistSync(exchangeArtifactPath)) {
- await fsWrapper.removeFileAsync(exchangeArtifactPath);
- }
- await compiler.compileAsync();
- done();
- })().catch(done);
- });
it('should create an Exchange artifact with the correct unlinked binary', async () => {
+ compilerOpts.contracts = ['Exchange'];
+
+ const exchangeArtifactPath = `${artifactsDir}/Exchange.json`;
+ if (fsWrapper.doesPathExistSync(exchangeArtifactPath)) {
+ await fsWrapper.removeFileAsync(exchangeArtifactPath);
+ }
+
+ await new Compiler(compilerOpts).compileAsync();
+
const opts = {
encoding: 'utf8',
};
@@ -47,4 +48,65 @@ describe('#Compiler', function(): void {
const exchangeBinaryWithoutMetadata = exchange_binary.slice(0, -metadataHexLength);
expect(unlinkedBinaryWithoutMetadata).to.equal(exchangeBinaryWithoutMetadata);
});
+ it("should throw when Whatever.sol doesn't contain a Whatever contract", async () => {
+ const contract = 'BadContractName';
+
+ const exchangeArtifactPath = `${artifactsDir}/${contract}.json`;
+ if (fsWrapper.doesPathExistSync(exchangeArtifactPath)) {
+ await fsWrapper.removeFileAsync(exchangeArtifactPath);
+ }
+
+ compilerOpts.contracts = [contract];
+ const compiler = new Compiler(compilerOpts);
+
+ expect(compiler.compileAsync()).to.be.rejectedWith(Error);
+ });
+ describe('after a successful compilation', () => {
+ const contract = 'Exchange';
+ let artifactPath: string;
+ let timeCompiled: number;
+ beforeEach(async () => {
+ compilerOpts.contracts = [contract];
+
+ artifactPath = `${artifactsDir}/${contract}.json`;
+ if (fsWrapper.doesPathExistSync(artifactPath)) {
+ await fsWrapper.removeFileAsync(artifactPath);
+ }
+
+ await new Compiler(compilerOpts).compileAsync();
+
+ timeCompiled = (await fsWrapper.statAsync(artifactPath)).mtimeMs;
+ });
+ it('recompilation should update artifact when source has changed', async () => {
+ fsWrapper.appendFileAsync(join(contractsDir, `${contract}.sol`), ' ');
+
+ await new Compiler(compilerOpts).compileAsync();
+
+ const timeRecompiled = (await fsWrapper.statAsync(artifactPath)).mtimeMs;
+
+ expect(timeRecompiled).to.not.equal(timeCompiled);
+ });
+ it("recompilation should NOT update artifact when source hasn't changed", async () => {
+ await new Compiler(compilerOpts).compileAsync();
+
+ const timeRecompiled = (await fsWrapper.statAsync(artifactPath)).mtimeMs;
+
+ expect(timeRecompiled).to.equal(timeCompiled);
+ });
+ });
+ it('should only compile what was requested', async () => {
+ // remove all artifacts
+ for (const artifact of await fsWrapper.readdirAsync(artifactsDir)) {
+ await fsWrapper.removeFileAsync(join(artifactsDir, artifact));
+ }
+
+ // compile EmptyContract
+ compilerOpts.contracts = ['EmptyContract'];
+ await new Compiler(compilerOpts).compileAsync();
+
+ // make sure the artifacts dir only contains EmptyContract.json
+ for (const artifact of await fsWrapper.readdirAsync(artifactsDir)) {
+ expect(artifact).to.equal('EmptyContract.json');
+ }
+ });
});
diff --git a/packages/sol-compiler/test/fixtures/contracts/BadContractName.sol b/packages/sol-compiler/test/fixtures/contracts/BadContractName.sol
new file mode 100644
index 000000000..3193cc0eb
--- /dev/null
+++ b/packages/sol-compiler/test/fixtures/contracts/BadContractName.sol
@@ -0,0 +1,3 @@
+pragma solidity ^0.4.14;
+
+contract ContractNameThatDoesntMatchFilename { }
diff --git a/packages/sol-compiler/test/fixtures/contracts/EmptyContract.sol b/packages/sol-compiler/test/fixtures/contracts/EmptyContract.sol
new file mode 100644
index 000000000..971ca7826
--- /dev/null
+++ b/packages/sol-compiler/test/fixtures/contracts/EmptyContract.sol
@@ -0,0 +1,3 @@
+pragma solidity ^0.4.14;
+
+contract EmptyContract { }