diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-02-28 05:51:12 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-02-28 06:42:49 +0800 |
commit | b6a133cc641617bd1099ec00c62a749f548316b7 (patch) | |
tree | c230cabe28d467a9b4299c6b57b299d4152bd645 /packages/deployer | |
parent | 7aa070f9eaef734274df6e6eaa4590fe30d52899 (diff) | |
download | dexon-sol-tools-b6a133cc641617bd1099ec00c62a749f548316b7.tar dexon-sol-tools-b6a133cc641617bd1099ec00c62a749f548316b7.tar.gz dexon-sol-tools-b6a133cc641617bd1099ec00c62a749f548316b7.tar.bz2 dexon-sol-tools-b6a133cc641617bd1099ec00c62a749f548316b7.tar.lz dexon-sol-tools-b6a133cc641617bd1099ec00c62a749f548316b7.tar.xz dexon-sol-tools-b6a133cc641617bd1099ec00c62a749f548316b7.tar.zst dexon-sol-tools-b6a133cc641617bd1099ec00c62a749f548316b7.zip |
Improve an error message when an inorrect number of constructor params is passed
Diffstat (limited to 'packages/deployer')
-rw-r--r-- | packages/deployer/CHANGELOG.md | 3 | ||||
-rw-r--r-- | packages/deployer/src/deployer.ts | 14 |
2 files changed, 15 insertions, 2 deletions
diff --git a/packages/deployer/CHANGELOG.md b/packages/deployer/CHANGELOG.md index a63d9cf3b..d8bbbbf89 100644 --- a/packages/deployer/CHANGELOG.md +++ b/packages/deployer/CHANGELOG.md @@ -2,7 +2,8 @@ ## v0.2.0 - _TBD, 2018_ - * Check dependencies when determining if contracts should be recompiled (#408). + * Check dependencies when determining if contracts should be recompiled (#408) + * Improve an error message for when deployer is supplied with an incorrect number of constructor arguments (#TBD) ## v0.1.0 - _February 16, 2018_ diff --git a/packages/deployer/src/deployer.ts b/packages/deployer/src/deployer.ts index 6710bcc85..e87d2ab0e 100644 --- a/packages/deployer/src/deployer.ts +++ b/packages/deployer/src/deployer.ts @@ -1,4 +1,4 @@ -import { TxData } from '@0xproject/types'; +import { AbiType, TxData } from '@0xproject/types'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; import * as Web3 from 'web3'; @@ -49,6 +49,18 @@ export class Deployer { gas, }; const abi = contractNetworkDataIfExists.abi; + const constructorAbi = _.find(abi, { type: AbiType.Constructor }) as Web3.ConstructorAbi; + const constructorArgs = _.isUndefined(constructorAbi) ? [] : constructorAbi.inputs; + if (constructorArgs.length !== args.length) { + const constructorSignature = `constructor(${_.map(constructorArgs, arg => `${arg.type} ${arg.name}`).join( + ', ', + )})`; + throw new Error( + `${contractName} expects ${constructorArgs.length} constructor params: ${constructorSignature}. Got ${ + args.length + }`, + ); + } const web3ContractInstance = await this._deployFromAbiAsync(abi, args, txData); utils.consoleLog(`${contractName}.sol successfully deployed at ${web3ContractInstance.address}`); const contractInstance = new Contract(web3ContractInstance, this._defaults); |