aboutsummaryrefslogblamecommitdiffstats
path: root/packages/deployer/test/compiler_test.ts
blob: 817a3b3f94fda397ce139d6663d5dd02d5feb026 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12




                                                    






                            





                                                          

                                      
                                                           




                                                                                                                   


                                                                 
                     




                                                                  
                                        




















                                                                                                         
import * as chai from 'chai';
import 'mocha';

import { Compiler } from '../src/compiler';
import { fsWrapper } from '../src/utils/fs_wrapper';
import {
    CompilerOptions,
    ContractArtifact,
    ContractDirectory,
    ContractNetworkData,
    DoneCallback,
} from '../src/utils/types';

import { exchange_binary } from './fixtures/exchange_bin';
import { constants } from './util/constants';

const expect = chai.expect;

describe('#Compiler', function() {
    this.timeout(constants.timeoutMs);
    const artifactsDir = `${__dirname}/fixtures/artifacts`;
    const mainContractDir: ContractDirectory = { path: `${__dirname}/fixtures/contracts/main`, namespace: 'main' };
    const baseContractDir: ContractDirectory = { path: `${__dirname}/fixtures/contracts/base`, namespace: 'base' };
    const contractDirs: Set<ContractDirectory> = new Set();
    contractDirs.add(mainContractDir);
    contractDirs.add(baseContractDir);
    const exchangeArtifactPath = `${artifactsDir}/Exchange.json`;
    const compilerOpts: CompilerOptions = {
        artifactsDir,
        contractDirs,
        networkId: constants.networkId,
        optimizerEnabled: constants.optimizerEnabled,
        specifiedContracts: new Set(constants.specifiedContracts),
    };
    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 () => {
        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);
    });
});