From ad8a96bfdfac42c7ebd8374becfed8cc28609446 Mon Sep 17 00:00:00 2001 From: Samuel Furter Date: Fri, 29 Mar 2019 13:11:41 +0100 Subject: [PATCH 01/10] TransactionSigner updated for production build --- .../methods/transaction/EthSendTransactionMethod.js | 2 +- packages/web3-eth/src/signers/TransactionSigner.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js b/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js index 00618fac073..417dbf29ca0 100644 --- a/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js +++ b/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js @@ -158,7 +158,7 @@ export default class EthSendTransactionMethod extends SendTransactionMethod { * @returns {Boolean} */ isDefaultSigner() { - return this.moduleInstance.transactionSigner.constructor.name === 'TransactionSigner'; + return this.moduleInstance.transactionSigner.Type && this.moduleInstance.transactionSigner.Type === 'TransactionSigner'; } /** diff --git a/packages/web3-eth/src/signers/TransactionSigner.js b/packages/web3-eth/src/signers/TransactionSigner.js index 03d759f46a4..a0da6ba364c 100644 --- a/packages/web3-eth/src/signers/TransactionSigner.js +++ b/packages/web3-eth/src/signers/TransactionSigner.js @@ -31,6 +31,17 @@ export default class TransactionSigner { this.formatters = formatters; } + /** + * Add to be production build save + * + * @property Type + * + * @returns {String} + */ + static get Type() { + return 'TransactionSigner'; + } + /** * Signs the transaction * From e31cb4f3616442fd8fa65489aca41f44eede22e4 Mon Sep 17 00:00:00 2001 From: Samuel Furter Date: Fri, 29 Mar 2019 13:20:53 +0100 Subject: [PATCH 02/10] type property updated from TransactionSigner and check added in index.js of the eth module --- packages/web3-eth/src/index.js | 2 +- packages/web3-eth/src/signers/TransactionSigner.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web3-eth/src/index.js b/packages/web3-eth/src/index.js index 8b8a4b24dc5..b24611dfc6b 100644 --- a/packages/web3-eth/src/index.js +++ b/packages/web3-eth/src/index.js @@ -58,7 +58,7 @@ export function TransactionSigner() { * @constructor */ export function Eth(provider, net = null, options = {}) { - if (!options.transactionSigner) { + if (!options.transactionSigner || options.transactionSigner.type === 'TransactionSigner') { options.transactionSigner = new TransactionSigner(); } diff --git a/packages/web3-eth/src/signers/TransactionSigner.js b/packages/web3-eth/src/signers/TransactionSigner.js index a0da6ba364c..9d892f37860 100644 --- a/packages/web3-eth/src/signers/TransactionSigner.js +++ b/packages/web3-eth/src/signers/TransactionSigner.js @@ -38,7 +38,7 @@ export default class TransactionSigner { * * @returns {String} */ - static get Type() { + get type() { return 'TransactionSigner'; } From f2188fcd3e89a424aa66952c9e3637dcb3e96275 Mon Sep 17 00:00:00 2001 From: Samuel Furter Date: Fri, 29 Mar 2019 13:26:52 +0100 Subject: [PATCH 03/10] transaction signer setter updated --- .../transaction/EthSendTransactionMethod.js | 2 +- packages/web3-eth-accounts/src/Accounts.js | 30 ++++++++++++++++++- packages/web3-eth/src/Eth.js | 4 +++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js b/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js index 417dbf29ca0..fa24f09eb64 100644 --- a/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js +++ b/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js @@ -158,7 +158,7 @@ export default class EthSendTransactionMethod extends SendTransactionMethod { * @returns {Boolean} */ isDefaultSigner() { - return this.moduleInstance.transactionSigner.Type && this.moduleInstance.transactionSigner.Type === 'TransactionSigner'; + return this.moduleInstance.transactionSigner.type && this.moduleInstance.transactionSigner.type === 'TransactionSigner'; } /** diff --git a/packages/web3-eth-accounts/src/Accounts.js b/packages/web3-eth-accounts/src/Accounts.js index 5b9a6155784..204be5343f1 100644 --- a/packages/web3-eth-accounts/src/Accounts.js +++ b/packages/web3-eth-accounts/src/Accounts.js @@ -47,13 +47,41 @@ export default class Accounts extends AbstractWeb3Module { this.utils = utils; this.formatters = formatters; - this.transactionSigner = options.transactionSigner; + this._transactionSigner = options.transactionSigner; this.defaultKeyName = 'web3js_wallet'; this.accounts = {}; this.accountsIndex = 0; this.wallet = new Wallet(utils, this); } + /** + * Getter for the transactionSigner property + * + * @property transactionSigner + * + * @returns {TransactionSigner} + */ + get transactionSigner() { + return this._transactionSigner; + } + + /** + * TODO: Remove setter + * + * Setter for the transactionSigner property + * + * @property transactionSigner + * + * @param {TransactionSigner} transactionSigner + */ + set transactionSigner(transactionSigner) { + if (transactionSigner.type && transactionSigner.type === 'TransactionSigner') { + throw Error('Invalid TransactionSigner given!'); + } + + this._transactionSigner = transactionSigner; + } + /** * Creates an account with a given entropy * diff --git a/packages/web3-eth/src/Eth.js b/packages/web3-eth/src/Eth.js index 239ebe07161..889bb11e3d3 100644 --- a/packages/web3-eth/src/Eth.js +++ b/packages/web3-eth/src/Eth.js @@ -131,6 +131,10 @@ export default class Eth extends AbstractWeb3Module { * @param {TransactionSigner} transactionSigner */ set transactionSigner(transactionSigner) { + if (transactionSigner.type && transactionSigner.type === 'TransactionSigner') { + throw Error('Invalid TransactionSigner given!'); + } + this._transactionSigner = transactionSigner; this.accounts.transactionSigner = transactionSigner; this.ens.transactionSigner = transactionSigner; From 60b75aef716e08f94c68e0b685ea3311fc7228fb Mon Sep 17 00:00:00 2001 From: Samuel Furter Date: Fri, 29 Mar 2019 13:32:27 +0100 Subject: [PATCH 04/10] TransactionObserver updated for prod build --- .../src/methods/transaction/EthSendTransactionMethod.js | 2 +- .../web3-core-method/src/observers/TransactionObserver.js | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js b/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js index fa24f09eb64..74d4aa4e9bf 100644 --- a/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js +++ b/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js @@ -158,7 +158,7 @@ export default class EthSendTransactionMethod extends SendTransactionMethod { * @returns {Boolean} */ isDefaultSigner() { - return this.moduleInstance.transactionSigner.type && this.moduleInstance.transactionSigner.type === 'TransactionSigner'; + return this.moduleInstance.transactionSigner.type === 'TransactionSigner'; } /** diff --git a/packages/web3-core-method/src/observers/TransactionObserver.js b/packages/web3-core-method/src/observers/TransactionObserver.js index ac0a9480e5c..6317888bd20 100644 --- a/packages/web3-core-method/src/observers/TransactionObserver.js +++ b/packages/web3-core-method/src/observers/TransactionObserver.js @@ -278,13 +278,7 @@ export default class TransactionObserver { * @returns {Boolean} */ isSocketBasedProvider() { - switch (this.provider.constructor.name) { - case 'CustomProvider': - case 'HttpProvider': - return false; - default: - return true; - } + return !!this.provider.SOCKET_MESSAGE; } /** From 45b0992f20ce92944a4296aee217b9ab1d6748a7 Mon Sep 17 00:00:00 2001 From: Samuel Furter Date: Fri, 29 Mar 2019 13:42:26 +0100 Subject: [PATCH 05/10] latest added as parameter for the GetTransactionCountMethod in the EthSendTransactionMethod --- .../src/methods/transaction/EthSendTransactionMethod.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js b/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js index 74d4aa4e9bf..fa6ac6493e1 100644 --- a/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js +++ b/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js @@ -129,7 +129,7 @@ export default class EthSendTransactionMethod extends SendTransactionMethod { } if (!this.parameters[0].nonce && this.parameters[0].nonce !== 0) { - this.getTransactionCountMethod.parameters = [this.parameters[0].from]; + this.getTransactionCountMethod.parameters = [this.parameters[0].from, 'latest']; this.parameters[0].nonce = await this.getTransactionCountMethod.execute(); } From 507d2b05cce502ffdb25bc1368c33bd1d75f6d6d Mon Sep 17 00:00:00 2001 From: Samuel Furter Date: Fri, 29 Mar 2019 13:51:30 +0100 Subject: [PATCH 06/10] contract MethodFactory updated for production build --- .../transaction/EthSendTransactionMethod.js | 2 +- .../src/factories/MethodFactory.js | 58 +++++++++++-------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js b/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js index fa6ac6493e1..f685abd7e80 100644 --- a/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js +++ b/packages/web3-core-method/src/methods/transaction/EthSendTransactionMethod.js @@ -180,6 +180,6 @@ export default class EthSendTransactionMethod extends SendTransactionMethod { * @returns {Boolean} */ hasCustomSigner() { - return this.moduleInstance.transactionSigner.constructor.name !== 'TransactionSigner'; + return this.moduleInstance.transactionSigner.type !== 'TransactionSigner'; } } diff --git a/packages/web3-eth-contract/src/factories/MethodFactory.js b/packages/web3-eth-contract/src/factories/MethodFactory.js index 61ea0651836..7a761efd535 100644 --- a/packages/web3-eth-contract/src/factories/MethodFactory.js +++ b/packages/web3-eth-contract/src/factories/MethodFactory.js @@ -154,14 +154,7 @@ export default class MethodFactory { * @returns {SendContractMethod} */ createSendContractMethod(contract) { - const transactionObserver = new TransactionObserver( - contract.currentProvider, - this.getTransactionObserverTimeout(contract), - contract.transactionConfirmationBlocks, - new GetTransactionReceiptMethod(this.utils, this.formatters, contract), - new GetBlockByNumberMethod(this.utils, this.formatters, contract), - new NewHeadsSubscription(this.utils, this.formatters, contract) - ); + const transactionObserver = this.createTransactionObserver(contract); return new SendContractMethod( this.utils, @@ -186,21 +179,16 @@ export default class MethodFactory { * @returns {ContractDeployMethod} */ createContractDeployMethod(contract) { + const transactionObserver = this.createTransactionObserver(contract); + return new ContractDeployMethod( this.utils, this.formatters, contract, - new TransactionObserver( - contract.currentProvider, - this.getTransactionObserverTimeout(contract), - contract.transactionConfirmationBlocks, - new GetTransactionReceiptMethod(this.utils, this.formatters, contract), - new GetBlockByNumberMethod(this.utils, this.formatters, contract), - new NewHeadsSubscription(this.utils, this.formatters, contract) - ), + transactionObserver, new ChainIdMethod(this.utils, this.formatters, contract), new GetTransactionCountMethod(this.utils, this.formatters, contract), - new SendRawTransactionMethod(this.utils, this.formatters, contract) + new SendRawTransactionMethod(this.utils, this.formatters, contract, transactionObserver) ); } @@ -217,23 +205,43 @@ export default class MethodFactory { return new EstimateGasMethod(this.utils, this.formatters, contract); } + /** - * Returns the correct timeout value based on the provider type + * Returns the correct timeout value * - * @method getTransactionObserverTimeout + * @method getTimeout * - * @param {AbstractContract} contract + * @param {AbstractWeb3Module} moduleInstance * * @returns {Number} */ - getTransactionObserverTimeout(contract) { - let timeout = contract.transactionBlockTimeout; - const providerName = contract.currentProvider.constructor.name; + getTimeout(moduleInstance) { + let timeout = moduleInstance.transactionBlockTimeout; - if (providerName === 'HttpProvider' || providerName === 'CustomProvider') { - timeout = contract.transactionPollingTimeout; + if (!moduleInstance.currentProvider.SOCKET_MESSAGE) { + timeout = moduleInstance.transactionPollingTimeout; } return timeout; } + + /** + * Returns a object of type TransactionObserver + * + * @method createTransactionObserver + * + * @param {AbstractContract} contract + * + * @returns {TransactionObserver} + */ + createTransactionObserver(contract) { + return new TransactionObserver( + contract.currentProvider, + this.getTimeout(contract), + contract.transactionConfirmationBlocks, + new GetTransactionReceiptMethod(this.utils, this.formatters, contract), + new GetBlockByNumberMethod(this.utils, this.formatters, contract), + new NewHeadsSubscription(this.utils, this.formatters, contract) + ); + } } From 3cd9b24555e1b789ece18f1b40d0a4da5b7ba5a1 Mon Sep 17 00:00:00 2001 From: Samuel Furter Date: Fri, 29 Mar 2019 15:02:31 +0100 Subject: [PATCH 07/10] EthSendTransactionMethodTest updated --- .../methods/transaction/EthSendTransactionMethodTest.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/web3-core-method/tests/src/methods/transaction/EthSendTransactionMethodTest.js b/packages/web3-core-method/tests/src/methods/transaction/EthSendTransactionMethodTest.js index f728fe6d4e0..defefeca1cf 100644 --- a/packages/web3-core-method/tests/src/methods/transaction/EthSendTransactionMethodTest.js +++ b/packages/web3-core-method/tests/src/methods/transaction/EthSendTransactionMethodTest.js @@ -43,6 +43,7 @@ describe('EthSendTransactionMethodTest', () => { moduleInstanceMock.currentProvider = providerMock; transactionSignerMock = new TransactionSigner(); + transactionSignerMock.type = 'TransactionSigner'; transactionSignerMock.sign = jest.fn(); new SendRawTransactionMethod(); @@ -81,6 +82,10 @@ describe('EthSendTransactionMethodTest', () => { expect(method).toBeInstanceOf(AbstractObservedTransactionMethod); }); + it('calls the static property Type and it returns the expect value', () => { + expect(EthSendTransactionMethod.Type).toEqual('eth-send-transaction-method'); + }); + it('calls execute with wallets defined and returns with a resolved promise', async () => { transactionSignerMock.sign = jest.fn(() => { return Promise.resolve({rawTransaction: '0x0'}); @@ -384,7 +389,7 @@ describe('EthSendTransactionMethodTest', () => { expect(sendRawTransactionMethodMock.parameters).toEqual(['0x0']); - expect(getTransactionCountMethodMock.parameters).toEqual([method.parameters[0].from]); + expect(getTransactionCountMethodMock.parameters).toEqual([method.parameters[0].from, 'latest']); expect(getTransactionCountMethodMock.execute).toHaveBeenCalledWith(); From 02a30ed7767fa2711ec2360098458310c71c0c96 Mon Sep 17 00:00:00 2001 From: Samuel Furter Date: Fri, 29 Mar 2019 15:06:54 +0100 Subject: [PATCH 08/10] TransactionObserverTest updated --- .../tests/src/observers/TransactionObserverTest.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/web3-core-method/tests/src/observers/TransactionObserverTest.js b/packages/web3-core-method/tests/src/observers/TransactionObserverTest.js index b7ed57c511e..8fccbf34f62 100644 --- a/packages/web3-core-method/tests/src/observers/TransactionObserverTest.js +++ b/packages/web3-core-method/tests/src/observers/TransactionObserverTest.js @@ -67,6 +67,8 @@ describe('TransactionObserverTest', () => { it('calls observe with a socket provider and returns a transaction receipt', (done) => { transactionObserver.blockConfirmations = 2; + providerMock.SOCKET_MESSAGE = true; + const blockHeadOne = { number: 0 }; @@ -111,6 +113,8 @@ describe('TransactionObserverTest', () => { transactionObserver.blockConfirmations = 2; transactionObserver.timeout = 1; + providerMock.SOCKET_MESSAGE = true; + const blockHeadOne = { number: 0 }; @@ -152,6 +156,8 @@ describe('TransactionObserverTest', () => { it('calls observe with a socket provider and the newHeads subscription returns a error', (done) => { transactionObserver.blockConfirmations = 2; + providerMock.SOCKET_MESSAGE = true; + newHeadsSubscriptionMock.subscribe = jest.fn((callback) => { callback(true, false); }); @@ -175,8 +181,6 @@ describe('TransactionObserverTest', () => { it('calls observe with a http provider and returns a transaction receipt', (done) => { transactionObserver.blockConfirmations = 2; - providerMock.constructor.name = 'CustomProvider'; - const receipt = {blockNumber: '0xa'}; const blockOne = {number: '0xa', hash: '0x0'}; const blockTwo = {number: '0xc', parentHash: '0x0'}; @@ -219,8 +223,6 @@ describe('TransactionObserverTest', () => { transactionObserver.blockConfirmations = 2; transactionObserver.timeout = 1; - providerMock.constructor.name = 'CustomProvider'; - const receipt = {blockNumber: '0xa'}; const blockOne = {number: '0xa', hash: '0x0'}; @@ -256,8 +258,6 @@ describe('TransactionObserverTest', () => { transactionObserver.blockConfirmations = 2; transactionObserver.timeout = 1; - providerMock.constructor.name = 'CustomProvider'; - getTransactionReceiptMethodMock.execute = jest.fn(() => { return Promise.reject(new Error('ERROR')); }); From 63a8b525fbe20e959124d5b2cd1bca7f81ef02f6 Mon Sep 17 00:00:00 2001 From: Samuel Furter Date: Fri, 29 Mar 2019 15:13:53 +0100 Subject: [PATCH 09/10] WebsocketProviderTest improved --- .../web3-providers/tests/src/providers/WebsocketProviderTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web3-providers/tests/src/providers/WebsocketProviderTest.js b/packages/web3-providers/tests/src/providers/WebsocketProviderTest.js index 75132247060..0588808385c 100644 --- a/packages/web3-providers/tests/src/providers/WebsocketProviderTest.js +++ b/packages/web3-providers/tests/src/providers/WebsocketProviderTest.js @@ -372,7 +372,7 @@ describe('WebsocketProviderTest', () => { socketMock.readyState = 4; socketMock.CONNECTING = 0; socketMock.send = jest.fn(); - websocketProvider.timeout = 2; + websocketProvider.timeout = 4; setTimeout(() => { websocketProvider.emit('0x0', {result: true}); From ebf137a502bfec15d2a6d8139b75cbeee5c4e308 Mon Sep 17 00:00:00 2001 From: Samuel Furter Date: Fri, 29 Mar 2019 15:40:27 +0100 Subject: [PATCH 10/10] MethodFactoryTest improved --- packages/web3-eth-contract/jest.config.js | 6 +- .../src/factories/MethodFactory.js | 10 +- .../tests/src/factories/MethodFactoryTest.js | 116 +++++++++++++++--- 3 files changed, 106 insertions(+), 26 deletions(-) diff --git a/packages/web3-eth-contract/jest.config.js b/packages/web3-eth-contract/jest.config.js index a8ad2d7f8f7..16ff7a4f983 100644 --- a/packages/web3-eth-contract/jest.config.js +++ b/packages/web3-eth-contract/jest.config.js @@ -9,5 +9,9 @@ module.exports = jestConfig({ 'ProvidersModuleFactory': 'web3-providers', 'ProviderDetector': 'web3-providers', 'ProviderResolver': 'web3-providers', - 'Utils': 'web3-utils' + 'Utils': 'web3-utils', + 'ChainIdMethod': 'web3-core-method', + 'EstimateGasMethod': 'web3-core-method', + 'GetTransactionCountMethod': 'web3-core-method', + 'SendRawTransactionMethod': 'web3-core-method' }); diff --git a/packages/web3-eth-contract/src/factories/MethodFactory.js b/packages/web3-eth-contract/src/factories/MethodFactory.js index 7a761efd535..0ec33e8a101 100644 --- a/packages/web3-eth-contract/src/factories/MethodFactory.js +++ b/packages/web3-eth-contract/src/factories/MethodFactory.js @@ -211,15 +211,15 @@ export default class MethodFactory { * * @method getTimeout * - * @param {AbstractWeb3Module} moduleInstance + * @param {AbstractContract} contract * * @returns {Number} */ - getTimeout(moduleInstance) { - let timeout = moduleInstance.transactionBlockTimeout; + getTimeout(contract) { + let timeout = contract.transactionBlockTimeout; - if (!moduleInstance.currentProvider.SOCKET_MESSAGE) { - timeout = moduleInstance.transactionPollingTimeout; + if (!contract.currentProvider.SOCKET_MESSAGE) { + timeout = contract.transactionPollingTimeout; } return timeout; diff --git a/packages/web3-eth-contract/tests/src/factories/MethodFactoryTest.js b/packages/web3-eth-contract/tests/src/factories/MethodFactoryTest.js index e3c339dd1a6..4bf4f7bfdfe 100644 --- a/packages/web3-eth-contract/tests/src/factories/MethodFactoryTest.js +++ b/packages/web3-eth-contract/tests/src/factories/MethodFactoryTest.js @@ -1,4 +1,4 @@ -import {EstimateGasMethod} from 'web3-core-method'; +import {ChainIdMethod, EstimateGasMethod, GetTransactionCountMethod, SendRawTransactionMethod} from 'web3-core-method'; import * as Utils from 'web3-utils'; import {formatters} from 'web3-core-helpers'; import {AbiCoder} from 'web3-eth-abi'; @@ -16,6 +16,10 @@ jest.mock('Accounts'); jest.mock('Utils'); jest.mock('formatters'); jest.mock('AbiCoder'); +jest.mock('EstimateGasMethod'); +jest.mock('ChainIdMethod'); +jest.mock('GetTransactionCountMethod'); +jest.mock('SendRawTransactionMethod'); jest.mock('../../../src/factories/ContractModuleFactory'); jest.mock('../../../src/methods/CallContractMethod'); jest.mock('../../../src/methods/SendContractMethod'); @@ -27,9 +31,11 @@ jest.mock('../../../src/methods/AllPastEventLogsMethod'); * MethodFactory test */ describe('MethodFactoryTest', () => { - let methodFactory, contractModuleFactoryMock, abiCoderMock; + let methodFactory, contractModuleFactoryMock, abiCoderMock, contract; beforeEach(() => { + contract = {currentProvider: {SOCKET_MESSAGE: false}}; + new ContractModuleFactory({}, {}, {}); contractModuleFactoryMock = ContractModuleFactory.mock.instances[0]; @@ -48,70 +54,140 @@ describe('MethodFactoryTest', () => { }); it('calls createMethodByRequestType with requestType call', () => { - expect(methodFactory.createMethodByRequestType({}, {}, 'call')).toBeInstanceOf(CallContractMethod); + expect(methodFactory.createMethodByRequestType({}, contract, 'call')).toBeInstanceOf(CallContractMethod); + + expect(CallContractMethod).toHaveBeenCalledWith(Utils, formatters, contract, abiCoderMock, {}); }); it('calls createMethodByRequestType with requestType send', () => { - const contract = {currentProvider: {constructor: {name: 'HttpProvider'}}}; - expect(methodFactory.createMethodByRequestType({}, contract, 'send')).toBeInstanceOf(SendContractMethod); + + expect(SendContractMethod).toHaveBeenCalled(); + + expect(ChainIdMethod).toHaveBeenCalledWith(Utils, formatters, contract); + + expect(GetTransactionCountMethod).toHaveBeenCalledWith(Utils, formatters, contract); + + expect(SendRawTransactionMethod).toHaveBeenCalled(); }); it('calls createMethodByRequestType with requestType send and a socketProvider', () => { - const contract = {currentProvider: {constructor: {name: 'WebsocketProvider'}}}; - expect(methodFactory.createMethodByRequestType({}, contract, 'send')).toBeInstanceOf(SendContractMethod); + + expect(SendContractMethod).toHaveBeenCalled(); + + expect(ChainIdMethod).toHaveBeenCalledWith(Utils, formatters, contract); + + expect(GetTransactionCountMethod).toHaveBeenCalledWith(Utils, formatters, contract); + + expect(SendRawTransactionMethod).toHaveBeenCalled(); }); it('calls createMethodByRequestType with requestType estimate', () => { - expect(methodFactory.createMethodByRequestType({}, {}, 'estimate')).toBeInstanceOf(EstimateGasMethod); + expect(methodFactory.createMethodByRequestType({}, contract, 'estimate')).toBeInstanceOf(EstimateGasMethod); + + expect(EstimateGasMethod).toHaveBeenCalledWith(Utils, formatters, contract); }); it('calls createMethodByRequestType with requestType contract-deployment', () => { - const contract = {currentProvider: {constructor: {name: 'WebsocketProvider'}}}; - expect(methodFactory.createMethodByRequestType({}, contract, 'contract-deployment')).toBeInstanceOf( ContractDeployMethod ); + + expect(ContractDeployMethod).toHaveBeenCalled(); + + expect(ChainIdMethod).toHaveBeenCalledWith(Utils, formatters, contract); + + expect(GetTransactionCountMethod).toHaveBeenCalledWith(Utils, formatters, contract); + + expect(SendRawTransactionMethod).toHaveBeenCalled(); }); it('calls createMethodByRequestType with unknown requestType', () => { expect(() => { - methodFactory.createMethodByRequestType({}, {}, 'nope'); + methodFactory.createMethodByRequestType({}, contract, 'nope'); }).toThrow('RPC call not found with requestType: "nope"'); }); it('calls createPastEventLogsMethod and returns PastEventLogsMethod object', () => { - expect(methodFactory.createPastEventLogsMethod({})).toBeInstanceOf(PastEventLogsMethod); + contractModuleFactoryMock.createEventLogDecoder.mockReturnValueOnce({}); + + contractModuleFactoryMock.createEventOptionsMapper.mockReturnValueOnce({}); + + expect(methodFactory.createPastEventLogsMethod({}, contract)).toBeInstanceOf(PastEventLogsMethod); expect(contractModuleFactoryMock.createEventLogDecoder).toHaveBeenCalled(); + + expect(contractModuleFactoryMock.createEventOptionsMapper).toHaveBeenCalled(); + + expect(PastEventLogsMethod).toHaveBeenCalledWith(Utils, formatters, contract, {}, {}, {}); }); - it('calls createAllPastEventLogsMethod and returns PastEventLogsMethod object', () => { - expect(methodFactory.createAllPastEventLogsMethod({})).toBeInstanceOf(AllPastEventLogsMethod); + it('calls createAllPastEventLogsMethod and returns AllPastEventLogsMethod object', () => { + contractModuleFactoryMock.createAllEventsLogDecoder.mockReturnValueOnce({}); + + contractModuleFactoryMock.createAllEventsOptionsMapper.mockReturnValueOnce({}); + + expect(methodFactory.createAllPastEventLogsMethod({}, contract)).toBeInstanceOf(AllPastEventLogsMethod); expect(contractModuleFactoryMock.createAllEventsLogDecoder).toHaveBeenCalled(); + + expect(contractModuleFactoryMock.createAllEventsOptionsMapper).toHaveBeenCalled(); + + expect(AllPastEventLogsMethod).toHaveBeenCalledWith(Utils, formatters, contract, {}, {}, {}); }); it('calls createCallContractMethod and returns CallContractMethod object', () => { - expect(methodFactory.createCallContractMethod({})).toBeInstanceOf(CallContractMethod); + expect(methodFactory.createCallContractMethod({}, contract)).toBeInstanceOf(CallContractMethod); + + expect(CallContractMethod).toHaveBeenCalledWith(Utils, formatters, contract, abiCoderMock, {}); }); it('calls createSendContractMethod and returns SendContractMethod object', () => { - const contract = {currentProvider: {constructor: {name: 'HttpProvider'}}}; - expect(methodFactory.createSendContractMethod(contract)).toBeInstanceOf(SendContractMethod); expect(contractModuleFactoryMock.createAllEventsLogDecoder).toHaveBeenCalled(); + + expect(SendContractMethod).toHaveBeenCalled(); + + expect(ChainIdMethod).toHaveBeenCalledWith(Utils, formatters, contract); + + expect(GetTransactionCountMethod).toHaveBeenCalledWith(Utils, formatters, contract); + + expect(SendRawTransactionMethod).toHaveBeenCalled(); }); it('calls createContractDeployMethod and returns ContractDeployMethod object', () => { - const contract = {currentProvider: {constructor: {name: 'HttpProvider'}}}; - expect(methodFactory.createContractDeployMethod(contract)).toBeInstanceOf(ContractDeployMethod); + + expect(ContractDeployMethod).toHaveBeenCalled(); + + expect(ChainIdMethod).toHaveBeenCalledWith(Utils, formatters, contract); + + expect(GetTransactionCountMethod).toHaveBeenCalledWith(Utils, formatters, contract); + + expect(SendRawTransactionMethod).toHaveBeenCalled(); }); it('calls createEstimateGasMethod and returns EstimateGasMethod object', () => { - expect(methodFactory.createEstimateGasMethod({})).toBeInstanceOf(EstimateGasMethod); + expect(methodFactory.createEstimateGasMethod(contract)).toBeInstanceOf(EstimateGasMethod); + + expect(EstimateGasMethod).toHaveBeenCalledWith(Utils, formatters, contract); + }); + + it('calls createSendContractMethod with a socket based provider and returns SendContractMethod object', () => { + const contract = {currentProvider: {SOCKET_MESSAGE: true}}; + + expect(methodFactory.createSendContractMethod(contract)).toBeInstanceOf(SendContractMethod); + + expect(contractModuleFactoryMock.createAllEventsLogDecoder).toHaveBeenCalled(); + + expect(SendContractMethod).toHaveBeenCalled(); + + expect(ChainIdMethod).toHaveBeenCalledWith(Utils, formatters, contract); + + expect(GetTransactionCountMethod).toHaveBeenCalledWith(Utils, formatters, contract); + + expect(SendRawTransactionMethod).toHaveBeenCalled(); }); });