From ab1ee635861be2d17196401ad3dcb2f66aa880e1 Mon Sep 17 00:00:00 2001 From: xianny Date: Wed, 25 Sep 2019 11:33:07 -0700 Subject: [PATCH] log warning if bytecode is empty or invalid --- .../src/generated-wrappers/i_asset_proxy.ts | 2 +- .../src/generated-wrappers/i_wallet.ts | 2 +- packages/abi-gen/src/index.ts | 17 +++++++++++++++-- packages/base-contract/src/index.ts | 5 ++--- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/i_asset_proxy.ts b/packages/abi-gen-wrappers/src/generated-wrappers/i_asset_proxy.ts index 2ff2c174fc..dc96b0053b 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/i_asset_proxy.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/i_asset_proxy.ts @@ -28,7 +28,7 @@ import * as ethers from 'ethers'; // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class IAssetProxyContract extends BaseContract { - public static deployedBytecode = '0x'; + public static deployedBytecode = ''; /** * Transfers assets. Either succeeds or throws. */ diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/i_wallet.ts b/packages/abi-gen-wrappers/src/generated-wrappers/i_wallet.ts index 90d6a12469..3f45a4660b 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/i_wallet.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/i_wallet.ts @@ -28,7 +28,7 @@ import * as ethers from 'ethers'; // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class IWalletContract extends BaseContract { - public static deployedBytecode = '0x'; + public static deployedBytecode = ''; /** * Validates a hash with the `Wallet` signature type. */ diff --git a/packages/abi-gen/src/index.ts b/packages/abi-gen/src/index.ts index 9a11ec4932..c7b243e97b 100644 --- a/packages/abi-gen/src/index.ts +++ b/packages/abi-gen/src/index.ts @@ -362,8 +362,21 @@ for (const abiFileName of abiFileNames) { let deployedBytecode; try { deployedBytecode = parsedContent.compilerOutput.evm.deployedBytecode.object; - } catch (e) { - logUtils.log(`Couldn't find deployedBytecode for ${chalk.bold(namedContent.name)}, using undefined`); + if ( + deployedBytecode === '' || + deployedBytecode === undefined || + deployedBytecode === '0x' || + deployedBytecode === '0x00' + ) { + throw new Error(); + } + } catch (err) { + logUtils.log( + `Couldn't find deployedBytecode for ${chalk.bold( + namedContent.name, + )}, using undefined. Found [${deployedBytecode}]`, + ); + deployedBytecode = undefined; } let ctor = ABI.find((abi: AbiDefinition) => abi.type === ABI_TYPE_CONSTRUCTOR) as ConstructorAbi; if (ctor === undefined) { diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index 84317ae03b..2dc978569f 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -268,8 +268,9 @@ export class BaseContract { ) { assert.isString('contractName', contractName); assert.isETHAddressHex('address', address); - if (deployedBytecode !== undefined) { + if (deployedBytecode !== undefined && deployedBytecode !== '') { assert.isHexString('deployedBytecode', deployedBytecode); + this._deployedBytecodeIfExists = Buffer.from(deployedBytecode.substr(2), 'hex'); } const provider = providerUtils.standardizeOrThrow(supportedProvider); if (callAndTxnDefaults !== undefined) { @@ -287,8 +288,6 @@ export class BaseContract { (abiDefinition: AbiDefinition) => abiDefinition.type === AbiType.Function, ) as MethodAbi[]; this._abiEncoderByFunctionSignature = {}; - this._deployedBytecodeIfExists = - deployedBytecode === undefined ? deployedBytecode : Buffer.from(deployedBytecode.substr(2), 'hex'); _.each(methodAbis, methodAbi => { const abiEncoder = new AbiEncoder.Method(methodAbi); const functionSignature = abiEncoder.getSignature();