Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove ethers dependency from utils #1640

Merged
merged 9 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/tasty-pets-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/interfaces": patch
"@fuel-ts/utils": patch
---

Remove ethers dependency from the utils package
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@changesets/get-github-info": "^0.5.2",
"@fuel-ts/forc": "workspace:*",
"@fuel-ts/fuel-core": "workspace:*",
"@fuel-ts/utils": "workspace:*",
"@fuel-ts/versions": "workspace:^",
"@internal/tsup": "workspace:*",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
Expand All @@ -61,7 +62,7 @@
"@types/web": "^0.0.65",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"@vitest/coverage-istanbul": "^1.1.0",
"@vitest/coverage-istanbul": "^1.1.3",
"compare-versions": "^6.1.0",
"conventional-changelog-angular": "^5.0.13",
"coverage-diff": "^3.2.0",
Expand All @@ -78,7 +79,6 @@
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-tsdoc": "^0.2.17",
"ethers": "^6.7.1",
"glob": "^10.2.6",
"nodemon": "^2.0.22",
"npm-run-all": "^4.1.5",
Expand All @@ -93,10 +93,10 @@
"tsx": "^4.7.0",
"turbo": "^1.8.8",
"typescript": "~5.2.2",
"vite": "^5.0.8",
"vite": "^5.0.11",
"vite-plugin-node-polyfills": "^0.17.0",
"vite-plugin-plain-text": "^1.4.2",
"vitest": "1.0.4"
"vitest": "^1.1.3"
},
"pnpm": {
"overrides": {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"license": "Apache-2.0",
"dependencies": {
"ethers": "^6.7.1",
"@fuel-ts/interfaces": "workspace:*",
"ramda": "^0.29.0",
"rimraf": "^3.0.2"
},
Expand Down
13 changes: 3 additions & 10 deletions packages/utils/src/test-utils/getForcProject.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as ethers from 'ethers';
import * as fs from 'fs';
import * as path from 'path';

import * as utilsMod from '../index';

import {
getForcProject,
getProjectAbiPath,
Expand All @@ -13,14 +14,6 @@ import {
getProjectTempDir,
} from './getForcProject';

vi.mock('ethers', async () => {
const mod = await vi.importActual('ethers');
return {
__esModule: true,
...mod,
};
});

vi.mock('path', async () => {
const mod = await vi.importActual('path');
return {
Expand Down Expand Up @@ -144,7 +137,7 @@ describe('getForcProject', () => {
const fakeAbiContent = { contracts: {} };
const fakeStorageSlots = [{ key: 'key1', value: 'value1' }];

vi.spyOn(ethers, 'hexlify').mockImplementation((param) => param as string);
vi.spyOn(utilsMod, 'hexlify').mockImplementation((param) => param as string);
vi.spyOn(path, 'join').mockImplementation((...segments) => segments.join('/'));
vi.spyOn(fs, 'readFileSync').mockImplementation((pathParam) => {
if ((<string>pathParam).endsWith('.bin')) {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/test-utils/getForcProject.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { hexlify } from 'ethers';
import { existsSync, readFileSync } from 'fs';
import { join } from 'path';

import { hexlify } from '../index';
import { normalizeString } from '../utils/normalizeString';

interface IGetForcProjectParams {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/utils/arrayify.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FuelError, ErrorCode } from '@fuel-ts/errors';
import type { BytesLike } from 'ethers';
import type { BytesLike } from '@fuel-ts/interfaces';

/**
* Converts a bytes-like value to a `Uint8Array`.
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/utils/chunkAndPadBytes.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getBytesCopy } from 'ethers';
import { arrayify } from '../index';

import { chunkAndPadBytes } from './chunkAndPadBytes';

Expand All @@ -7,7 +7,7 @@ import { chunkAndPadBytes } from './chunkAndPadBytes';
*/
describe('chunkAndPadBytes', () => {
it('can chunk and pad bytes to 16 KiB', () => {
const bytes = getBytesCopy(
const bytes = arrayify(
'0x900000044700000000000000000000345dfcc00110fff3005d4060495d47f000134904407348000c72f0007b36f0000024040000000000002151bd4b'
);
const chunkSize = 16 * 1024;
Expand Down
5 changes: 2 additions & 3 deletions packages/utils/src/utils/concat.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getBytesCopy } from 'ethers';

import { arrayify } from './arrayify';
import { concat, concatBytes } from './concat';

/**
Expand All @@ -17,7 +16,7 @@ describe('concat', () => {

expect(output).toBeInstanceOf(Uint8Array);
expect(output).toStrictEqual(
new Uint8Array([...getBytesCopy(byteslike1), ...byteslike2, ...byteslike3])
new Uint8Array([...arrayify(byteslike1), ...byteslike2, ...byteslike3])
);
});
});
Expand Down
7 changes: 4 additions & 3 deletions packages/utils/src/utils/concat.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { BytesLike } from 'ethers';
import { getBytesCopy } from 'ethers';
import type { BytesLike } from '@fuel-ts/interfaces';

import { arrayify } from './arrayify';

/**
* Concatenates multiple Uint8Arrays into a single Uint8Array.
Expand Down Expand Up @@ -35,7 +36,7 @@ export const concatBytes = (
* @returns - The concatenated array.
*/
export const concat = (arrays: ReadonlyArray<BytesLike>): Uint8Array => {
const bytes = arrays.map((v) => getBytesCopy(v));
const bytes = arrays.map((v) => arrayify(v));

return concatBytes(bytes);
};
7 changes: 4 additions & 3 deletions packages/utils/src/utils/hexlify.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { BytesLike } from 'ethers';
import { getBytes } from 'ethers';
import type { BytesLike } from '@fuel-ts/interfaces';

import { arrayify } from './arrayify';

const HexCharacters: string = '0123456789abcdef';

/**
* Returns a hex representation of the inputted bytes.
*/
export function hexlify(data: BytesLike): string {
const bytes = getBytes(data);
const bytes = arrayify(data);

let result = '0x';
for (let i = 0; i < bytes.length; i++) {
Expand Down
Loading
Loading