From 3d58b38e4e8565e7ee10e4d6c9f57cd745957ab4 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 7 May 2018 22:11:09 +0200 Subject: Remove deployer from metacoin and contract tests --- packages/base-contract/src/index.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'packages/base-contract/src') diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index e95b18db6..c362a882b 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -1,6 +1,7 @@ import { AbiDefinition, AbiType, + ConstructorAbi, ContractAbi, DataItem, MethodAbi, @@ -37,9 +38,40 @@ export class BaseContract { protected static _bigNumberToString(type: string, value: any): any { return _.isObject(value) && value.isBigNumber ? value.toString() : value; } + protected static _lookupConstructorAbi(abi: ContractAbi): ConstructorAbi { + const constructorAbiIfExists = _.find( + abi, + (abiDefinition: AbiDefinition) => abiDefinition.type === AbiType.Constructor, + ) as ConstructorAbi | undefined; + if (!_.isUndefined(constructorAbiIfExists)) { + return constructorAbiIfExists; + } else { + return { + type: AbiType.Constructor, + stateMutability: 'nonpayable', + payable: false, + inputs: [], + }; + } + } protected static _bnToBigNumber(type: string, value: any): any { return _.isObject(value) && value._bn ? new BigNumber(value.toString()) : value; } + protected static async _applyDefaultsToDeployTxDataAsync>( + txData: T, + defaults: Partial, + estimateGasAsync?: (txData: T) => Promise, + ): Promise { + const txDataWithDefaults: TxData = { + ...defaults, + ...(txData as any), + }; + if (_.isUndefined(txDataWithDefaults.gas) && !_.isUndefined(estimateGasAsync)) { + const estimatedGas = await estimateGasAsync(txData); + txDataWithDefaults.gas = estimatedGas; + } + return txDataWithDefaults; + } protected async _applyDefaultsToTxDataAsync>( txData: T, estimateGasAsync?: (txData: T) => Promise, -- cgit