Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
chore: fix @ethereumjs/util mock
  • Loading branch information
legobeat committed Dec 23, 2024
1 parent 4908f19 commit f7e1ff7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ module.exports = {
config.resolve.alias['@ethereumjs/util'] = require.resolve(
'../ui/__mocks__/ethereumjs-util.js',
);
config.resolve.alias['ethereumjs-util'] = require.resolve(
'../ui/__mocks__/ethereumjs-util.js',
);
config.resolve.alias['./useNftCollectionsMetadata'] = require.resolve(
'../ui/__mocks__/useNftCollectionsMetadata.js',
);
Expand Down
33 changes: 28 additions & 5 deletions ui/__mocks__/ethereumjs-util.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
const zeroAddress = function() {
const addressLength = 20
const addr = zeros(addressLength)
return bufferToHex(addr)
}
// Vendored from @ethereumjs/[email protected] / [email protected]

/**
* Converts a `Buffer` into a `0x`-prefixed hex `String`.
*
* @param buf - `Buffer` object to convert
*/
const bufferToHex = function (buf) {
// buf = toBuffer(buf);
return `0x${buf.toString('hex')}`;
};

/**
* Returns a buffer filled with 0s.
*
* @param bytes - the number of bytes the buffer should be
*/
const zeros = function (bytes) {
return Buffer.allocUnsafe(bytes).fill(0);
};

/**
* Returns the zero address.
*/
const zeroAddress = function () {
const addressLength = 20;
const addr = zeros(addressLength);
return bufferToHex(addr);
};

module.exports = {
zeroAddress,
Expand Down
4 changes: 0 additions & 4 deletions ui/hooks/bridge/useLatestBalance.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { zeroAddress } from '@ethereumjs/util';
import { BigNumber } from 'bignumber.js';
import { renderHookWithProvider } from '../../../test/lib/render-helpers';
import { CHAIN_IDS } from '../../../shared/constants/network';
import { createBridgeMockStore } from '../../../test/jest/mock-store';
import { createTestProviderTools } from '../../../test/stub/provider';
import * as tokenutil from '../../../shared/lib/token-util';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ const customTransaction = ({
};
// just simulate hash if not provided
if (!props?.hash) {
tx.hash = `0x${Buffer.from(keccak256(Buffer.from(JSON.stringify(tx)))).toString('hex')}`;
tx.hash = `0x${Buffer.from(
keccak256(Buffer.from(JSON.stringify(tx))),
).toString('hex')}`;
}
return tx;
};
Expand Down

0 comments on commit f7e1ff7

Please sign in to comment.