aboutsummaryrefslogtreecommitdiffstats
path: root/packages/deployer/test/deployer_test.ts
blob: 23862422035a72ed3ec526f9b71cbf81e4821344 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import * as chai from 'chai';
import 'mocha';

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

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

const expect = chai.expect;

describe('#Deployer', () => {
    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);
    const deployerOpts = {
        artifactsDir,
        networkId: constants.networkId,
        provider,
        defaults: {
            gasPrice: constants.gasPrice,
        },
    };
    const deployer = new Deployer(deployerOpts);
    beforeEach(function(done: DoneCallback) {
        this.timeout(constants.timeoutMs);
        (async () => {
            if (fsWrapper.doesPathExistSync(exchangeArtifactPath)) {
                await fsWrapper.removeFileAsync(exchangeArtifactPath);
            }
            await compiler.compileAsync();
            done();
        })().catch(done);
    });
    describe('#deployAsync', () => {
        it('should deploy the Exchange contract without updating the Exchange artifact', async () => {
            const exchangeConstructorArgs = [constants.zrxTokenAddress, constants.tokenTransferProxyAddress];
            const exchangeContractInstance = await deployer.deployAsync('Exchange', exchangeConstructorArgs);
            const opts = {
                encoding: 'utf8',
            };
            const exchangeArtifactString = await fsWrapper.readFileAsync(exchangeArtifactPath, opts);
            const exchangeArtifact: ContractArtifact = JSON.parse(exchangeArtifactString);
            const exchangeContractData: ContractNetworkData = exchangeArtifact.networks[constants.networkId];
            const exchangeAddress = exchangeContractInstance.address;
            expect(exchangeAddress).to.not.equal(undefined);
            expect(exchangeContractData.address).to.equal(undefined);
            expect(exchangeContractData.constructor_args).to.equal(undefined);
        });
    });
    describe('#deployAndSaveAsync', () => {
        it('should save the correct contract address and constructor arguments to the Exchange artifact', async () => {
            const exchangeConstructorArgs = [constants.zrxTokenAddress, constants.tokenTransferProxyAddress];
            const exchangeContractInstance = await deployer.deployAndSaveAsync('Exchange', exchangeConstructorArgs);
            const opts = {
                encoding: 'utf8',
            };
            const exchangeArtifactString = await fsWrapper.readFileAsync(exchangeArtifactPath, opts);
            const exchangeArtifact: ContractArtifact = JSON.parse(exchangeArtifactString);
            const exchangeContractData: ContractNetworkData = exchangeArtifact.networks[constants.networkId];
            const exchangeAddress = exchangeContractInstance.address;
            expect(exchangeAddress).to.be.equal(exchangeContractData.address);
            expect(constructor_args).to.be.equal(exchangeContractData.constructor_args);
        });
    });
});