Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
log warning if bytecode is empty or invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
xianny committed Sep 25, 2019
1 parent 23bc086 commit ab1ee63
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions packages/abi-gen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 2 additions & 3 deletions packages/base-contract/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down

0 comments on commit ab1ee63

Please sign in to comment.