aboutsummaryrefslogtreecommitdiffstats
path: root/packages/deployer/test/deploy_test.ts
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2018-01-19 20:43:32 +0800
committerGitHub <noreply@github.com>2018-01-19 20:43:32 +0800
commite1af25c8a6fa96c665d63fff2033d7611b023db2 (patch)
tree5769ca73d50c497e46e6c6c927700ae0fa00bec9 /packages/deployer/test/deploy_test.ts
parent9ccf63b44afe1ae6ccc2b9298ee35697d6be9e30 (diff)
parent6091f818da7cddcb4a22a573f7726ba9b76b398e (diff)
downloaddexon-0x-contracts-e1af25c8a6fa96c665d63fff2033d7611b023db2.tar.gz
dexon-0x-contracts-e1af25c8a6fa96c665d63fff2033d7611b023db2.tar.zst
dexon-0x-contracts-e1af25c8a6fa96c665d63fff2033d7611b023db2.zip
Merge pull request #323 from 0xProject/feature/separate-deployer
Move deployer to a separate package
Diffstat (limited to 'packages/deployer/test/deploy_test.ts')
-rw-r--r--packages/deployer/test/deploy_test.ts91
1 files changed, 91 insertions, 0 deletions
diff --git a/packages/deployer/test/deploy_test.ts b/packages/deployer/test/deploy_test.ts
new file mode 100644
index 000000000..5df729a04
--- /dev/null
+++ b/packages/deployer/test/deploy_test.ts
@@ -0,0 +1,91 @@
+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, ContractData, DoneCallback } from '../src/utils/types';
+import { constructor_args, exchange_binary } from './fixtures/exchange_bin';
+import { constants } from './util/constants';
+
+const expect = chai.expect;
+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,
+};
+const compiler = new Compiler(compilerOpts);
+const deployerOpts = {
+ artifactsDir,
+ networkId: constants.networkId,
+ jsonrpcPort: constants.jsonrpcPort,
+ defaults: {
+ gasPrice: constants.gasPrice,
+ },
+};
+const deployer = new Deployer(deployerOpts);
+
+/* tslint:disable */
+beforeEach(function(done: DoneCallback) {
+ this.timeout(constants.timeoutMs);
+ (async () => {
+ if (fsWrapper.doesPathExistSync(exchangeArtifactPath)) {
+ await fsWrapper.removeFileAsync(exchangeArtifactPath);
+ }
+ await compiler.compileAllAsync();
+ done();
+ })().catch(done);
+});
+/* tslint:enable */
+
+describe('#Compiler', () => {
+ 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: ContractData = exchangeArtifact.networks[constants.networkId];
+ // The last 43 bytes of the binaries are metadata which may not be equivalent
+ const unlinkedBinaryWithoutMetadata = exchangeContractData.unlinked_binary.slice(0, -86);
+ const exchangeBinaryWithoutMetadata = exchange_binary.slice(0, -86);
+ expect(unlinkedBinaryWithoutMetadata).to.equal(exchangeBinaryWithoutMetadata);
+ });
+});
+describe('#Deployer', () => {
+ 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: ContractData = 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: ContractData = exchangeArtifact.networks[constants.networkId];
+ const exchangeAddress = exchangeContractInstance.address;
+ expect(exchangeAddress).to.be.equal(exchangeContractData.address);
+ expect(constructor_args).to.be.equal(exchangeContractData.constructor_args);
+ });
+ });
+});