From a93543dfeb7ba46da7255a558d4353fbc06ce18f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Lefr=C3=A8re?= Date: Tue, 16 Jul 2019 16:40:41 +0200 Subject: [PATCH 1/2] Remove typo * Remove a (harmless, but odd) typo in the build script --- scripts/build-individual-module.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build-individual-module.js b/scripts/build-individual-module.js index 91a94638..8a8fec9f 100644 --- a/scripts/build-individual-module.js +++ b/scripts/build-individual-module.js @@ -62,7 +62,7 @@ const buildIndividualModule = async (moduleName) => { )}${chalk.white(' @ ')}${chalk.white.bold( packageFile.version )}`, - );cjsBuildFolder + ); /* * Build ES Modules */ From 8dec4f6ad23c1c7dd8c6b1cc6c13e25911c06a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Lefr=C3=A8re?= Date: Tue, 16 Jul 2019 16:41:59 +0200 Subject: [PATCH 2/2] Fix import * Fix the `ethereumjs-tx` import that was a breaking change of its `2.x` release * Update `ethereumjs-tx` mock --- .../@colony/purser-ledger/staticMethods.js | 2 +- .../@colony/purser-metamask/staticMethods.js | 2 +- .../@colony/purser-trezor/staticMethods.js | 2 +- modules/tests/mocks/ethereumjs-tx.js | 8 +++++--- .../staticMethods/signTransaction.test.js | 3 +-- .../staticMethods/signTransaction.test.js | 19 ++----------------- .../staticMethods/signTransaction.test.js | 3 +-- 7 files changed, 12 insertions(+), 27 deletions(-) diff --git a/modules/node_modules/@colony/purser-ledger/staticMethods.js b/modules/node_modules/@colony/purser-ledger/staticMethods.js index 0a167265..2f00901a 100644 --- a/modules/node_modules/@colony/purser-ledger/staticMethods.js +++ b/modules/node_modules/@colony/purser-ledger/staticMethods.js @@ -1,6 +1,6 @@ /* @flow */ -import EthereumTx from 'ethereumjs-tx'; +import { Transaction as EthereumTx } from 'ethereumjs-tx'; import { derivationPathValidator, diff --git a/modules/node_modules/@colony/purser-metamask/staticMethods.js b/modules/node_modules/@colony/purser-metamask/staticMethods.js index f748c722..42310dfa 100644 --- a/modules/node_modules/@colony/purser-metamask/staticMethods.js +++ b/modules/node_modules/@colony/purser-metamask/staticMethods.js @@ -1,6 +1,6 @@ /* @flow */ -import EthereumTx from 'ethereumjs-tx'; +import { Transaction as EthereumTx } from 'ethereumjs-tx'; import BigNumber from 'bn.js'; import { warning } from '@colony/purser-core/utils'; diff --git a/modules/node_modules/@colony/purser-trezor/staticMethods.js b/modules/node_modules/@colony/purser-trezor/staticMethods.js index ef573139..cf5703e1 100644 --- a/modules/node_modules/@colony/purser-trezor/staticMethods.js +++ b/modules/node_modules/@colony/purser-trezor/staticMethods.js @@ -1,7 +1,7 @@ /* @flow */ import { fromString } from 'bip32-path'; -import EthereumTx from 'ethereumjs-tx'; +import { Transaction as EthereumTx } from 'ethereumjs-tx'; import { addressValidator, diff --git a/modules/tests/mocks/ethereumjs-tx.js b/modules/tests/mocks/ethereumjs-tx.js index fe3f5ff4..e076b2eb 100644 --- a/modules/tests/mocks/ethereumjs-tx.js +++ b/modules/tests/mocks/ethereumjs-tx.js @@ -1,7 +1,9 @@ -export const EthereumTx = jest.fn().mockImplementation(() => ({ +export const Transaction = jest.fn().mockImplementation(() => ({ serialize: () => ({ - toString: () => 'mocked-hex-string', + toString: () => 'mocked-serialized-signed-transaction', }), })); -export default EthereumTx; +const EthereumJsTx = jest.fn(() => ({ Transaction })); + +export default EthereumJsTx; diff --git a/modules/tests/purser-ledger/staticMethods/signTransaction.test.js b/modules/tests/purser-ledger/staticMethods/signTransaction.test.js index 8ea51383..f241d03b 100644 --- a/modules/tests/purser-ledger/staticMethods/signTransaction.test.js +++ b/modules/tests/purser-ledger/staticMethods/signTransaction.test.js @@ -1,4 +1,4 @@ -import EthereumTx from 'ethereumjs-tx'; +import { Transaction as EthereumTx } from 'ethereumjs-tx'; import { transactionObjectValidator } from '@colony/purser-core/helpers'; import * as utils from '@colony/purser-core/utils'; @@ -68,7 +68,6 @@ const mockedArgumentsObject = { describe('`Ledger` Hardware Wallet Module Static Methods', () => { afterEach(() => { - EthereumTx.mockClear(); derivationPathNormalizer.mockClear(); multipleOfTwoHexValueNormalizer.mockClear(); addressNormalizer.mockClear(); diff --git a/modules/tests/purser-metamask/staticMethods/signTransaction.test.js b/modules/tests/purser-metamask/staticMethods/signTransaction.test.js index ec5c2f95..cf2ba8fd 100644 --- a/modules/tests/purser-metamask/staticMethods/signTransaction.test.js +++ b/modules/tests/purser-metamask/staticMethods/signTransaction.test.js @@ -1,5 +1,3 @@ -import EthereumTx from 'ethereumjs-tx'; - import { transactionObjectValidator } from '@colony/purser-core/helpers'; import { warning } from '@colony/purser-core/utils'; @@ -20,6 +18,7 @@ import { STD_ERRORS } from '@colony/purser-metamask/defaults'; jest.dontMock('@colony/purser-metamask/staticMethods'); +jest.mock('ethereumjs-tx'); jest.mock('@colony/purser-core/validators'); /* * @TODO Fix manual mocks @@ -53,19 +52,6 @@ global.web3 = { }, }; -/* - * Mock ethereumjs-tx serialization - */ -const mockedSerializedSignedTransaction = - 'mocked-serialized-signed-transaction'; -jest.mock('ethereumjs-tx', () => - jest.fn().mockImplementation(() => ({ - serialize: jest.fn().mockReturnValue({ - toString: jest.fn().mockReturnValue(mockedSerializedSignedTransaction), - }), - })), -); - /* * These values are not correct. Do not use the as reference. * If the validators wouldn't be mocked, they wouldn't pass. @@ -93,7 +79,6 @@ describe('`Metamask` Wallet Module Static Methods', () => { afterEach(() => { global.web3.eth.sendTransaction.mockClear(); global.web3.eth.getTransaction.mockClear(); - EthereumTx.mockClear(); methodCaller.mockClear(); transactionObjectValidator.mockClear(); addressValidator.mockClear(); @@ -200,7 +185,7 @@ describe('`Metamask` Wallet Module Static Methods', () => { test('Returns the valid hash received from signing', async () => { const signedTransaction = await signTransaction(mockedArgumentsObject); expect(global.web3.eth.getTransaction).toHaveBeenCalled(); - expect(signedTransaction).toEqual(mockedSerializedSignedTransaction); + expect(signedTransaction).toEqual('mocked-serialized-signed-transaction'); }); test('Throws if something goes wrong while processing the signed transaction', async () => { /* diff --git a/modules/tests/purser-trezor/staticMethods/signTransaction.test.js b/modules/tests/purser-trezor/staticMethods/signTransaction.test.js index d2738de5..947bd473 100644 --- a/modules/tests/purser-trezor/staticMethods/signTransaction.test.js +++ b/modules/tests/purser-trezor/staticMethods/signTransaction.test.js @@ -1,4 +1,4 @@ -import EthereumTx from 'ethereumjs-tx'; +import { Transaction as EthereumTx } from 'ethereumjs-tx'; import { transactionObjectValidator } from '@colony/purser-core/helpers'; import * as utils from '@colony/purser-core/utils'; @@ -67,7 +67,6 @@ const mockedArgumentsObject = { describe('`Trezor` Hardware Wallet Module Static Methods', () => { afterEach(() => { - EthereumTx.mockClear(); derivationPathNormalizer.mockClear(); multipleOfTwoHexValueNormalizer.mockClear(); addressNormalizer.mockClear();