diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-03-16 23:34:02 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-03-21 22:12:18 +0800 |
commit | 8b52793f2fa21bcb23a3c38b6d3773cfc20186fd (patch) | |
tree | 82ec9791f2d31d1a60e3ddf019da42b3ee4af2e1 /packages/deployer/test/compiler_test.ts | |
parent | 18b9fe525622d9e18491f76136d7697806996a09 (diff) | |
download | dexon-sol-tools-8b52793f2fa21bcb23a3c38b6d3773cfc20186fd.tar dexon-sol-tools-8b52793f2fa21bcb23a3c38b6d3773cfc20186fd.tar.gz dexon-sol-tools-8b52793f2fa21bcb23a3c38b6d3773cfc20186fd.tar.bz2 dexon-sol-tools-8b52793f2fa21bcb23a3c38b6d3773cfc20186fd.tar.lz dexon-sol-tools-8b52793f2fa21bcb23a3c38b6d3773cfc20186fd.tar.xz dexon-sol-tools-8b52793f2fa21bcb23a3c38b6d3773cfc20186fd.tar.zst dexon-sol-tools-8b52793f2fa21bcb23a3c38b6d3773cfc20186fd.zip |
Add tests for compiler utils
Diffstat (limited to 'packages/deployer/test/compiler_test.ts')
-rw-r--r-- | packages/deployer/test/compiler_test.ts | 47 |
1 files changed, 47 insertions, 0 deletions
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); + }); +}); |