aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-compiler/test/compiler_test.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-08-22 18:41:42 +0800
committerFabio Berger <me@fabioberger.com>2018-08-22 18:41:42 +0800
commit0248add542ac801bcb021fa7b13c182baec5612e (patch)
tree1d04404632ee381621b384f1e82ade97c06c9b92 /packages/sol-compiler/test/compiler_test.ts
parentc12f0d04bb2f0d5ad73943d02a592a110423a423 (diff)
parent80e52464a6fdf9576776214f77e46d441b959b06 (diff)
downloaddexon-sol-tools-0248add542ac801bcb021fa7b13c182baec5612e.tar
dexon-sol-tools-0248add542ac801bcb021fa7b13c182baec5612e.tar.gz
dexon-sol-tools-0248add542ac801bcb021fa7b13c182baec5612e.tar.bz2
dexon-sol-tools-0248add542ac801bcb021fa7b13c182baec5612e.tar.lz
dexon-sol-tools-0248add542ac801bcb021fa7b13c182baec5612e.tar.xz
dexon-sol-tools-0248add542ac801bcb021fa7b13c182baec5612e.tar.zst
dexon-sol-tools-0248add542ac801bcb021fa7b13c182baec5612e.zip
Merge development branch
Diffstat (limited to 'packages/sol-compiler/test/compiler_test.ts')
-rw-r--r--packages/sol-compiler/test/compiler_test.ts88
1 files changed, 76 insertions, 12 deletions
diff --git a/packages/sol-compiler/test/compiler_test.ts b/packages/sol-compiler/test/compiler_test.ts
index 46853e882..e41a268f2 100644
--- a/packages/sol-compiler/test/compiler_test.ts
+++ b/packages/sol-compiler/test/compiler_test.ts
@@ -1,4 +1,5 @@
-import { DoneCallback } from '@0xproject/types';
+import { join } from 'path';
+
import * as chai from 'chai';
import { CompilerOptions, ContractArtifact } from 'ethereum-types';
import 'mocha';
@@ -7,31 +8,31 @@ import { Compiler } from '../src/compiler';
import { fsWrapper } from '../src/utils/fs_wrapper';
import { exchange_binary } from './fixtures/exchange_bin';
+import { chaiSetup } from './util/chai_setup';
import { constants } from './util/constants';
+chaiSetup.configure();
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,67 @@ 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.rejected();
+ });
+ describe('after a successful compilation', () => {
+ const contract = 'Exchange';
+ let artifactPath: string;
+ let artifactCreatedAtMs: number;
+ beforeEach(async () => {
+ compilerOpts.contracts = [contract];
+
+ artifactPath = `${artifactsDir}/${contract}.json`;
+ if (fsWrapper.doesPathExistSync(artifactPath)) {
+ await fsWrapper.removeFileAsync(artifactPath);
+ }
+
+ await new Compiler(compilerOpts).compileAsync();
+
+ artifactCreatedAtMs = (await fsWrapper.statAsync(artifactPath)).mtimeMs;
+ });
+ it('recompilation should update artifact when source has changed', async () => {
+ // append some meaningless data to the contract, so that its hash
+ // will change, so that the compiler will decide to recompile it.
+ fsWrapper.appendFileAsync(join(contractsDir, `${contract}.sol`), ' ');
+
+ await new Compiler(compilerOpts).compileAsync();
+
+ const artifactModifiedAtMs = (await fsWrapper.statAsync(artifactPath)).mtimeMs;
+
+ expect(artifactModifiedAtMs).to.be.greaterThan(artifactCreatedAtMs);
+ });
+ it("recompilation should NOT update artifact when source hasn't changed", async () => {
+ await new Compiler(compilerOpts).compileAsync();
+
+ const artifactModifiedAtMs = (await fsWrapper.statAsync(artifactPath)).mtimeMs;
+
+ expect(artifactModifiedAtMs).to.equal(artifactCreatedAtMs);
+ });
+ });
+ 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');
+ }
+ });
});