Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Fix import
Browse files Browse the repository at this point in the history
* Fix the `ethereumjs-tx` import that was a breaking change of its `2.x` release
* Update `ethereumjs-tx` mock
  • Loading branch information
JamesLefrere committed Jul 16, 2019
1 parent a93543d commit 8dec4f6
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 27 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.

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

8 changes: 5 additions & 3 deletions modules/tests/mocks/ethereumjs-tx.js
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -68,7 +68,6 @@ const mockedArgumentsObject = {

describe('`Ledger` Hardware Wallet Module Static Methods', () => {
afterEach(() => {
EthereumTx.mockClear();
derivationPathNormalizer.mockClear();
multipleOfTwoHexValueNormalizer.mockClear();
addressNormalizer.mockClear();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import EthereumTx from 'ethereumjs-tx';

import { transactionObjectValidator } from '@colony/purser-core/helpers';
import { warning } from '@colony/purser-core/utils';

Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 () => {
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -67,7 +67,6 @@ const mockedArgumentsObject = {

describe('`Trezor` Hardware Wallet Module Static Methods', () => {
afterEach(() => {
EthereumTx.mockClear();
derivationPathNormalizer.mockClear();
multipleOfTwoHexValueNormalizer.mockClear();
addressNormalizer.mockClear();
Expand Down

0 comments on commit 8dec4f6

Please sign in to comment.