From 8b52793f2fa21bcb23a3c38b6d3773cfc20186fd Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 16 Mar 2018 16:34:02 +0100 Subject: Add tests for compiler utils --- packages/deployer/test/compiler_test.ts | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 packages/deployer/test/compiler_test.ts (limited to 'packages/deployer/test/compiler_test.ts') diff --git a/packages/deployer/test/compiler_test.ts b/packages/deployer/test/compiler_test.ts new file mode 100644 index 000000000..1c4d3c697 --- /dev/null +++ b/packages/deployer/test/compiler_test.ts @@ -0,0 +1,47 @@ +import * as chai from 'chai'; +import 'mocha'; + +import { Compiler } from '../src/compiler'; +import { fsWrapper } from '../src/utils/fs_wrapper'; +import { CompilerOptions, ContractArtifact, ContractNetworkData, DoneCallback } from '../src/utils/types'; + +import { exchange_binary } from './fixtures/exchange_bin'; +import { constants } from './util/constants'; + +const expect = chai.expect; + +describe('#Compiler', () => { + const artifactsDir = `${__dirname}/fixtures/artifacts`; + const contractsDir = `${__dirname}/fixtures/contracts`; + const exchangeArtifactPath = `${artifactsDir}/Exchange.json`; + const compilerOpts: CompilerOptions = { + artifactsDir, + contractsDir, + networkId: constants.networkId, + optimizerEnabled: constants.optimizerEnabled, + specifiedContracts: new Set(constants.specifiedContracts), + }; + const compiler = new Compiler(compilerOpts); + beforeEach(function(done: DoneCallback) { + this.timeout(constants.timeoutMs); + (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 () => { + const opts = { + encoding: 'utf8', + }; + const exchangeArtifactString = await fsWrapper.readFileAsync(exchangeArtifactPath, opts); + const exchangeArtifact: ContractArtifact = JSON.parse(exchangeArtifactString); + const exchangeContractData: ContractNetworkData = exchangeArtifact.networks[constants.networkId]; + // The last 43 bytes of the binaries are metadata which may not be equivalent + const unlinkedBinaryWithoutMetadata = exchangeContractData.bytecode.slice(0, -86); + const exchangeBinaryWithoutMetadata = exchange_binary.slice(0, -86); + expect(unlinkedBinaryWithoutMetadata).to.equal(exchangeBinaryWithoutMetadata); + }); +}); -- cgit v1.2.3 From 7ef6bd4b14b7502617c6929010d4a9991e1d577d Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 22 Mar 2018 14:26:24 +0100 Subject: Set timeout for compiler tests --- packages/deployer/test/compiler_test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/deployer/test/compiler_test.ts') diff --git a/packages/deployer/test/compiler_test.ts b/packages/deployer/test/compiler_test.ts index 1c4d3c697..b03ae7935 100644 --- a/packages/deployer/test/compiler_test.ts +++ b/packages/deployer/test/compiler_test.ts @@ -10,7 +10,8 @@ import { constants } from './util/constants'; const expect = chai.expect; -describe('#Compiler', () => { +describe('#Compiler', function() { + this.timeout(constants.timeoutMs); const artifactsDir = `${__dirname}/fixtures/artifacts`; const contractsDir = `${__dirname}/fixtures/contracts`; const exchangeArtifactPath = `${artifactsDir}/Exchange.json`; @@ -22,8 +23,7 @@ describe('#Compiler', () => { specifiedContracts: new Set(constants.specifiedContracts), }; const compiler = new Compiler(compilerOpts); - beforeEach(function(done: DoneCallback) { - this.timeout(constants.timeoutMs); + beforeEach((done: DoneCallback) => { (async () => { if (fsWrapper.doesPathExistSync(exchangeArtifactPath)) { await fsWrapper.removeFileAsync(exchangeArtifactPath); -- cgit v1.2.3