From b25b88355a5cdfe20ca8c46c54dd0385e4c5adfa Mon Sep 17 00:00:00 2001 From: destinyae <109734765+destinyae@users.noreply.github.com> Date: Wed, 28 Feb 2024 17:22:43 +0100 Subject: [PATCH 01/19] Update CONTRIBUTING.md (#6838) fix typo Co-authored-by: Oleksii Kosynskyi --- .github/CONTRIBUTING.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index f9790002769..2702e75d4d2 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,10 +1,10 @@ # Contributing -Thank you for contributing to web3.js! We appreciate your interest and welcome any contributions that can help improve our documentation, functionality, addressing bugs, or any other aspects that can contribute to the overall improvement of our project. Before you start contributing, please take a moment to review the guidelines below. +Thank you for contributing to Web3.js! We appreciate your interest and welcome any contributions that can help improve our documentation, functionality, address bugs, or any other aspects that can contribute to the overall improvement of our project. Before you start contributing, please take a moment to review the guidelines below. ## Help and Support -If you face any issues while contributing, or you want any type of support, we encourage you to join our [Discord Community](https://discord.com/invite/3shNX8cqGR) and ask any question in the `#web3js-general` channel, and/or submit a [New Issue](https://github.com/web3/web3.js/issues/new). +If you face any issues while contributing or want any type of support, we encourage you to join our [Discord Community](https://discord.com/invite/3shNX8cqGR), ask any question in the `#web3js-general` channel, and/or submit a [new issue](https://github.com/web3/web3.js/issues/new). ## Prerequisites @@ -15,12 +15,12 @@ If you face any issues while contributing, or you want any type of support, we e 1. **Fork the docs:** Start by forking our repository to your GitHub account. -2. **Clone the repo:** Clone the forked repository to your local machine using the following command +2. **Clone the repo:** Clone the forked repository to your local machine using the following command: ```bash git clone https://github.com/your-username/web3.js.git ``` 3. **Create a Branch:** Create a new branch for your changes with a descriptive name. - **NOTE: The branch name must include the issue number (if there is no issue created for your contribution, please create one)** + **NOTE: The branch name must include the issue number (if there is no issue created for your contribution, please create one).** ```bash git checkout -b issue-name-1234 ``` @@ -32,7 +32,7 @@ yarn ``` 6. **Make your changes:**... -7. Check changes in local environment: Run the command `yarn start` and you'll see a local environment in `localhost:3000` with the docs +7. Check changes in the local environment: Run the command `yarn start` and you'll see a local environment in `localhost:3000` with the documents. 8. **Commit your changes:** `git add .` and `git commit -m 'descriptive msg'` @@ -41,9 +41,9 @@ yarn git push origin branch-name ``` -10. **Open a Pull request(PR):** Provide a detailed description of your changes, the problem you are solving, and any additional context(you can use the PR template). +10. **Open a Pull Request (PR):** Provide a detailed description of your changes, the problem you are solving, and any additional context (you can use the PR template). -11. **Wait for review**: Before merging any branch into the main branch, it must be approved by 2 devs, after succesfully approved, you can `Squash and merge` your branch, Please be responsive to any feedback on your pull request and make necessary changes based on the review. +11. **Wait for review**: Before merging any branch into the main branch, it must be approved by two devs, after it is successfully approved, you can `Squash and merge` your branch, Please be responsive to any feedback on your pull request and make necessary changes based on the review. ## Guidelines for Pull Requests and Releases (Web3 4.x) @@ -54,7 +54,7 @@ that **Web3 not break**. ### Pull Requests for substantive changes (e.g. everything except comments and docs) 1. Any PR that introduces a logic change should include tests. (In many cases, the tests will take more time to write than the actual code). -1. All PRs should sit for 72 hours with the `pleasereview` tag in order to garner feedback. +1. All PRs should sit for 72 hours with the `please review` tag to garner feedback. 1. No PR should be merged until it has been reviewed, passes CI, and all reviews' comments are addressed. 1. PRs should: @@ -62,17 +62,17 @@ that **Web3 not break**. 1. make the smallest set of changes possible to achieve their goal. 1. include a clear description in the opening comment. 1. preserve the conventions and stylistic consistency of any files they modify. -1. Given the choice between a conservative change that mostly works and an adventurous change which seems better but introduces uncertainty - prefer the conservative change. +1. Given the choice between a conservative change that mostly works and an adventurous change that seems better but introduces uncertainty - prefer the conservative change. ### Reviews -The end goal of review is to suggest useful improvements to the author. Reviews should finish with approval unless there are issues that would result in: +The end goal of the review is to suggest useful improvements to the author. Reviews should finish with approval unless there are issues that would result in: -1. Buggy behaviour. +1. Buggy behavior. 1. Undue maintenance burden. -1. Pessimisation (i.e. speed reduction / meaningful build-size increases). +1. Pessimisation (i.e. speed reduction or meaningful build-size increases). 1. Feature reduction (i.e. it removes some aspect of functionality that users rely on). -1. Avoidable risk (i.e it's difficult to test or hard to anticipate the implications of, without +1. Avoidable risk (i.e. it's difficult to test or hard to anticipate the implications of, without being strictly necessary to fix something broken). Read more in [Review Guidelines](./REVIEW.md). @@ -85,9 +85,9 @@ Read more in [Review Guidelines](./REVIEW.md). 1. Changes should trigger a new `rc` release and set the release clock back enough that reviewers have the time they need to test new changes. 1. Regular maintainers should manually test the `rc` against a Node project and the published minified bundle in a browser context. An external reviewer should verify they've done the same. -1. A release PR must be approved at least by two known contributors of the web3.js project. +1. A release PR must be approved at least by two known contributors to the web3.js project. -Read more in [Release Guidelines](./RELEASE.md). +Read more in the [Release Guidelines](./RELEASE.md). ### Emergencies From ab1b250624504bff46cfce4bdc87b77c160528ec Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Wed, 28 Feb 2024 11:40:20 -0500 Subject: [PATCH 02/19] fix (#6842) --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6f75f28bb6a..21b9dac7d5f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -239,7 +239,7 @@ jobs: path: ./ key: web3-18-${{github.sha}} # @octokit/core not supported on node 16, so I can't add it to the package.json - - run: npm install --no-package-lock --no-save --force @octokit/core + - run: npm install --no-package-lock --no-save --force @octokit/core@5.1.0 - name: Restore main branch benchmark data uses: actions/cache/restore@v3 with: From 0e59f28b2fc046836aa1774ffc3e1faec6fddf07 Mon Sep 17 00:00:00 2001 From: cyborgRen <107702661+cyborgRen@users.noreply.github.com> Date: Thu, 29 Feb 2024 12:52:31 -0500 Subject: [PATCH 03/19] [docs] add stripHexPrefix method to migration guide (#6843) * add stripHexPrefix method to accounts migration guide * add stripHexPrefix method to web3-utils migration guide --- .../1.x/accounts_migration_guide.md | 11 +++++++++++ .../1.x/web3_utils_migration_guide.md | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/docs/docs/guides/web3_upgrade_guide/1.x/accounts_migration_guide.md b/docs/docs/guides/web3_upgrade_guide/1.x/accounts_migration_guide.md index 9446135ef4b..f6505e460f8 100644 --- a/docs/docs/guides/web3_upgrade_guide/1.x/accounts_migration_guide.md +++ b/docs/docs/guides/web3_upgrade_guide/1.x/accounts_migration_guide.md @@ -34,3 +34,14 @@ const wallet = web3.eth.accounts.wallet.create(1, 'optionalEntropy'); // entropy const account = web3.eth.accounts.wallet.create(1, 'optionalEntropy'); // will result in an error const account = web3.eth.accounts.wallet.create(); // correct way ``` + +## stripHexPrefix method + +In 1.x `stripHexPrefix` method is located in the `web3-utils` package, in 4.x this has been moved to `web3-eth-accounts` + +```typescript +import { stripHexPrefix } from 'web3-eth-accounts'; + +console.log(stripHexPrefix('0x123')); // "123" + +``` diff --git a/docs/docs/guides/web3_upgrade_guide/1.x/web3_utils_migration_guide.md b/docs/docs/guides/web3_upgrade_guide/1.x/web3_utils_migration_guide.md index 04886c52351..0b977890e6e 100644 --- a/docs/docs/guides/web3_upgrade_guide/1.x/web3_utils_migration_guide.md +++ b/docs/docs/guides/web3_upgrade_guide/1.x/web3_utils_migration_guide.md @@ -79,6 +79,16 @@ isHex('-0x'); // in 1.x used to return `true`. But changed in 4.x to return `fal isHexStrict('-0x'); // in 1.x used to return `true`. But changed in 4.x to return `false` // `false` +``` +## stripHexPrefix method + +In 1.x `stripHexPrefix` method is located in the `web3-utils` package, in 4.x this has been moved to `web3-eth-accounts` + +```typescript +import { stripHexPrefix } from 'web3-eth-accounts'; + +console.log(stripHexPrefix('0x123')); // "123" + ``` ## Other functions From bd6cc71cda1b6660bd28f9dd35064b7cd49003bc Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Fri, 1 Mar 2024 16:11:13 -0500 Subject: [PATCH 04/19] Fix bundle stats (#6846) * save cache to 4.x * save fix * save again * test * test * test * fix * finish --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 21b9dac7d5f..ba60ce39f22 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -89,13 +89,12 @@ jobs: uses: actions/cache/restore@v3 with: path: packages/web3/dist/4.x.json - key: web3-bundle-stats-4x-${{github.sha}} + key: web3-bundle-stats-4x-${{github.event.pull_request.base.sha}} - run: yarn build:web:analyze env: STATS_FILE: ${{ github.ref_name }}.json - name: Compare bundle stats - uses: github/webpack-bundlesize-compare-action@v1 - if: github.event_name != 'push' + uses: github/webpack-bundlesize-compare-action@v1.8.2 continue-on-error: true with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -105,9 +104,10 @@ jobs: uses: actions/cache/save@v3 if: github.event_name == 'push' && github.ref == 'refs/heads/4.x' with: - path: packages/web3/dist/4.x.json + path: packages/web3/dist/${{ github.ref_name }}.json key: web3-bundle-stats-4x-${{github.sha}} + unit: name: Unit Tests needs: build From 8ed041c6635d807b3da8960ad49e125e3d1b0e80 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Tue, 5 Mar 2024 10:36:27 -0500 Subject: [PATCH 05/19] Research (#6841) * add nopp * fix * custom fix * add space * fix * fix --- packages/web3-utils/src/index.ts | 2 +- packages/web3-utils/src/objects.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web3-utils/src/index.ts b/packages/web3-utils/src/index.ts index e5f467ec5f8..23eb49dde9a 100644 --- a/packages/web3-utils/src/index.ts +++ b/packages/web3-utils/src/index.ts @@ -33,4 +33,4 @@ export * from './web3_eip1193_provider.js'; export * from './socket_provider.js'; export * from './uint8array.js'; // for backwards compatibility with v1 -export {AbiItem} from 'web3-types'; \ No newline at end of file +export { AbiItem } from 'web3-types'; diff --git a/packages/web3-utils/src/objects.ts b/packages/web3-utils/src/objects.ts index 4ed6c328ef8..6417465e57b 100644 --- a/packages/web3-utils/src/objects.ts +++ b/packages/web3-utils/src/objects.ts @@ -36,7 +36,7 @@ export const mergeDeep = ( destination: Record, ...sources: Record[] ): Record => { - const result = destination; // clone deep here + const result = { ...destination }; // clone deep here if (!isIterable(result)) { return result; } From ca31f6a264a51f2c522e085c2d19c116fe9dcc06 Mon Sep 17 00:00:00 2001 From: Junaid <86780488+jdevcs@users.noreply.github.com> Date: Tue, 5 Mar 2024 18:01:36 +0100 Subject: [PATCH 06/19] EIP6963 web3 provider update event (#6855) * added web3:providersMapUpdated event and exports * doc updated * updated test * lint fix * doc update * added onNewProviderDiscovered * exporting onNewProviderDiscovered via web3 as static * unit tests of onNewProviderDiscovered * updated doc --- .../guides/web3_providers_guide/eip6963.md | 15 +- packages/web3/src/providers.exports.ts | 1 + packages/web3/src/web3.ts | 3 +- packages/web3/src/web3_eip6963.ts | 38 ++++-- packages/web3/test/unit/web3eip6963.test.ts | 129 +++++++++--------- 5 files changed, 111 insertions(+), 75 deletions(-) diff --git a/docs/docs/guides/web3_providers_guide/eip6963.md b/docs/docs/guides/web3_providers_guide/eip6963.md index c6d9b676804..0965e440c9b 100644 --- a/docs/docs/guides/web3_providers_guide/eip6963.md +++ b/docs/docs/guides/web3_providers_guide/eip6963.md @@ -9,9 +9,11 @@ sidebar_label: 'EIP-6963: Multi Injected Provider Discovery' EIP-6963 proposes the "Multi Injected Provider Discovery" standard, which aims to enhance the discoverability and interaction with multiple injected Ethereum providers in a browser environment. Injected providers refer to browser extensions or other injected scripts that provide access to an Ethereum provider within the context of a web application. -Web3.js library has utility function for discovery of injected providers using `requestEIP6963Providers()` function. When `requestEIP6963Providers()` is used it returns `eip6963Providers` Map object. This Map object is in global scope so every time `requestEIP6963Providers()` function is called it will update Map object and return it. +Web3.js library has utility functions for discovery of injected providers using `requestEIP6963Providers()` and `onNewProviderDiscovered(eventDetails)`. -`eip6963Providers` Map object has provider's `UUID` as keys and `EIP6963ProviderDetail` as values. `EIP6963ProviderDetail` is: +`onNewProviderDiscovered(eventDetails)` can be used to subscribe to events of provider discovery & providers map update and `requestEIP6963Providers()` returns Promise object that resolves to `Map` object containing list of providers. For updated providers `eip6963:providersMapUpdated` event is emitted and it has updated Map object. This event can be subscribed as mentioned earlier using `onNewProviderDiscovered(eventDetails)` + +`eip6963ProvidersMap` object has provider's `UUID` as keys and `EIP6963ProviderDetail` as values. `EIP6963ProviderDetail` is: ```ts export interface EIP6963ProviderDetail { @@ -40,8 +42,15 @@ Following code snippet demonstrates usage of `requestEIP6963Providers()` functio import { Web3 } from 'web3'; -const providers = Web3.requestEIP6963Providers(); +// Following will subscribe to event that will be triggered when providers map is updated. + +Web3.onNewProviderDiscovered((provider) => { + console.log(provider.detail); // This will log the populated providers map object, provider.detail has Map of all providers yet discovered + // add logic here for updating UI of your DApp +}); +// Call the function and wait for the promise to resolve +let providers = await Web3.requestEIP6963Providers(); for (const [key, value] of providers) { console.log(value); diff --git a/packages/web3/src/providers.exports.ts b/packages/web3/src/providers.exports.ts index c0bbadc1b23..c3d8bfcba08 100644 --- a/packages/web3/src/providers.exports.ts +++ b/packages/web3/src/providers.exports.ts @@ -19,3 +19,4 @@ export { Eip1193Provider, SocketProvider } from 'web3-utils'; export * as http from 'web3-providers-http'; export * as ws from 'web3-providers-ws'; +export * from './web3_eip6963.js'; \ No newline at end of file diff --git a/packages/web3/src/web3.ts b/packages/web3/src/web3.ts index 0512110d32d..2953e67d364 100644 --- a/packages/web3/src/web3.ts +++ b/packages/web3/src/web3.ts @@ -44,7 +44,7 @@ import abi from './abi.js'; import { initAccountsForContext } from './accounts.js'; import { Web3EthInterface } from './types.js'; import { Web3PkgInfo } from './version.js'; -import { requestEIP6963Providers } from './web3_eip6963.js'; +import { onNewProviderDiscovered, requestEIP6963Providers } from './web3_eip6963.js'; export class Web3< CustomRegisteredSubscription extends { @@ -54,6 +54,7 @@ export class Web3< public static version = Web3PkgInfo.version; public static utils = utils; public static requestEIP6963Providers = requestEIP6963Providers; + public static onNewProviderDiscovered = onNewProviderDiscovered; public static modules = { Web3Eth, Iban, diff --git a/packages/web3/src/web3_eip6963.ts b/packages/web3/src/web3_eip6963.ts index 61b1a53e520..787502a4125 100644 --- a/packages/web3/src/web3_eip6963.ts +++ b/packages/web3/src/web3_eip6963.ts @@ -44,28 +44,48 @@ export interface EIP6963RequestProviderEvent extends Event { type: Eip6963EventName.eip6963requestProvider; } -export const eip6963Providers: Map = new Map(); +export const eip6963ProvidersMap: Map = new Map(); -export const requestEIP6963Providers = () => { +export const web3ProvidersMapUpdated = "web3:providersMapUpdated"; +export interface EIP6963ProvidersMapUpdateEvent extends CustomEvent { + type: string; + detail: Map; +} - if (typeof window === 'undefined') - throw new Error( - "window object not available, EIP-6963 is intended to be used within a browser" - ); +export const requestEIP6963Providers = async () => + new Promise((resolve, reject) => { + if (typeof window === 'undefined') { + reject(new Error("window object not available, EIP-6963 is intended to be used within a browser")); + } window.addEventListener( Eip6963EventName.eip6963announceProvider as any, (event: EIP6963AnnounceProviderEvent) => { - eip6963Providers.set( + eip6963ProvidersMap.set( event.detail.info.uuid, event.detail); + + const newEvent: EIP6963ProvidersMapUpdateEvent = new CustomEvent( + web3ProvidersMapUpdated, + { detail: eip6963ProvidersMap } + ); + + window.dispatchEvent(newEvent); + resolve(eip6963ProvidersMap); + } ); window.dispatchEvent(new Event(Eip6963EventName.eip6963requestProvider)); - return eip6963Providers; -} + }); +export const onNewProviderDiscovered = (callback: (providerEvent: EIP6963AnnounceProviderEvent) => void) => { + if (typeof window === 'undefined') { + throw new Error("window object not available, EIP-6963 is intended to be used within a browser"); + } + window.addEventListener(web3ProvidersMapUpdated as any, callback ); +} + diff --git a/packages/web3/test/unit/web3eip6963.test.ts b/packages/web3/test/unit/web3eip6963.test.ts index b584c91e934..1f465aba124 100644 --- a/packages/web3/test/unit/web3eip6963.test.ts +++ b/packages/web3/test/unit/web3eip6963.test.ts @@ -16,71 +16,76 @@ along with web3.js. If not, see . */ import { - EIP6963AnnounceProviderEvent, - EIP6963ProviderDetail, - Eip6963EventName, - eip6963Providers, + onNewProviderDiscovered, requestEIP6963Providers } from "../../src/web3_eip6963"; describe('requestEIP6963Providers', () => { + it('should reject with an error if window object is not available', async () => { + // Mocking window object absence + (global as any).window = undefined; + + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + await expect(requestEIP6963Providers()).rejects.toThrow("window object not available, EIP-6963 is intended to be used within a browser"); + }); + + it('should resolve with updated providers map when events are triggered', async () => { + class CustomEventPolyfill extends Event { + public detail: any; + public constructor(eventType: string, eventInitDict: any) { + super(eventType, eventInitDict); + this.detail = eventInitDict.detail; + } + } + + (global as any).CustomEvent = CustomEventPolyfill; + + const mockProviderDetail = { + info: { uuid: 'test-uuid', name: 'Test Provider', icon: 'test-icon', rdns: 'test-rdns' }, + provider: {} // Mock provider object + }; + + const mockEvent = { + type: 'eip6963:announceProvider', + detail: mockProviderDetail + }; + + // Mock window methods + (global as any).window = { + addEventListener: jest.fn().mockImplementation( + + (_event, callback) => callback(mockEvent)), // eslint-disable-line + dispatchEvent: jest.fn() + }; + + const result = await requestEIP6963Providers(); + + expect(result).toEqual(new Map([['test-uuid', mockProviderDetail]])); + }); + + it('onNewProviderDiscovered should throw an error if window object is not available', () => { + // Mock the window object not being available + (global as any).window = undefined; + + // Expect an error to be thrown + expect(() => { + // eslint-disable-next-line @typescript-eslint/no-empty-function + onNewProviderDiscovered((_providerEvent) => {}); + }).toThrow("window object not available, EIP-6963 is intended to be used within a browser"); + + + }); + + it('onNewProviderDiscovered should add an event listener when window object is available', () => { + (global as any).window = { + addEventListener: jest.fn(), + }; + + const callback = jest.fn(); + onNewProviderDiscovered(callback); + + // Expect the callback to have been called when the event listener is added + expect(global.window.addEventListener).toHaveBeenCalledWith('web3:providersMapUpdated', callback); + }); - it('should request EIP6963 providers and store them in eip6963Providers', () => { - - const mockProviderDetail: EIP6963ProviderDetail = { - info: { - uuid: '1', - name: 'MockProvider', - icon: 'icon-path', - rdns: 'mock.rdns' - }, - - provider: {} as any - }; - - const mockAnnounceEvent: EIP6963AnnounceProviderEvent = { - type: Eip6963EventName.eip6963announceProvider, - detail: mockProviderDetail - } as any; - - // Mock the window object - (global as any).window = { - addEventListener: jest.fn(), - dispatchEvent: jest.fn() - }; - - // Call the function - requestEIP6963Providers(); - - // Validate event listener setup and event dispatch - expect((global as any).window.addEventListener) - .toHaveBeenCalledWith(Eip6963EventName.eip6963announceProvider, expect.any(Function)); - - expect((global as any).window.dispatchEvent).toHaveBeenCalled(); - - // Simulate the announce event - // Access the mock function calls for addEventListener - const addEventListenerMockCalls = (global as any).window.addEventListener.mock.calls; - - // Retrieve the first call to addEventListener and access its second argument - const eventListenerArg = addEventListenerMockCalls[0][1]; - - // Now "eventListenerArg" represents the function to be called when the event occurs - const announceEventListener = eventListenerArg; - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - announceEventListener(mockAnnounceEvent); - - // Validate if the provider detail is stored in the eip6963Providers map - expect(eip6963Providers.get('1')).toEqual(mockProviderDetail); - }); - - it('should throw an error if window object is not available', () => { - // Remove the window object - delete (global as any).window; - - // Call the function and expect it to throw an error - expect(() => { - requestEIP6963Providers(); - }).toThrow("window object not available, EIP-6963 is intended to be used within a browser"); - }); }); \ No newline at end of file From 040d3a35e569f47d35a287346451ded4b08c7bbe Mon Sep 17 00:00:00 2001 From: teslaedison <156734008+teslaedison@users.noreply.github.com> Date: Wed, 6 Mar 2024 23:01:37 +0800 Subject: [PATCH 07/19] fix some typos (#6863) Signed-off-by: teslaedison --- docs/docs/guides/hardhat_tutorial/index.md | 2 +- fixtures/contracts/GreeterWithOverloading.sol | 2 +- .../test/integration/web3_eth/sign_transaction.test.ts | 4 ++-- packages/web3-utils/src/converters.ts | 2 +- packages/web3/test/integration/web3.config.test.ts | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/docs/guides/hardhat_tutorial/index.md b/docs/docs/guides/hardhat_tutorial/index.md index 74d92b868ef..3b6166db2b3 100644 --- a/docs/docs/guides/hardhat_tutorial/index.md +++ b/docs/docs/guides/hardhat_tutorial/index.md @@ -72,7 +72,7 @@ export default config; ``` -By default, `hardhat-toolbox` is added to the file. You will need to explicity invoke the plugin. This will modify the Hardhat Run-time Environment - HRE and to include both the Web3 class and an instantiated web3 object. With the latter, you get a modified ready-to-use web3 object can comes with an initialized local/Hardhat provider. The object will be available to use anywhere in the project such as testing and deployment files. +By default, `hardhat-toolbox` is added to the file. You will need to explicitly invoke the plugin. This will modify the Hardhat Run-time Environment - HRE and to include both the Web3 class and an instantiated web3 object. With the latter, you get a modified ready-to-use web3 object can comes with an initialized local/Hardhat provider. The object will be available to use anywhere in the project such as testing and deployment files. ### Write the Smart Contract When you start a new project, Hardhat provides a sample `Lock` contracts. Please refer to the contract in `myproject/contracts/Lock.sol` file. diff --git a/fixtures/contracts/GreeterWithOverloading.sol b/fixtures/contracts/GreeterWithOverloading.sol index ca2a00dadd3..384709287b2 100644 --- a/fixtures/contracts/GreeterWithOverloading.sol +++ b/fixtures/contracts/GreeterWithOverloading.sol @@ -25,7 +25,7 @@ contract GreeterWithOverloading { return (true, greeting); } - // function overlading with addtional parameter + // function overlading with additional parameter function setGreeting(string memory _greeting, bool _raiseEvents) public returns (bool, string memory) { if(_raiseEvents) { emit GREETING_CHANGING(greeting, _greeting); diff --git a/packages/web3-eth/test/integration/web3_eth/sign_transaction.test.ts b/packages/web3-eth/test/integration/web3_eth/sign_transaction.test.ts index 317c180519f..630a67cfba2 100644 --- a/packages/web3-eth/test/integration/web3_eth/sign_transaction.test.ts +++ b/packages/web3-eth/test/integration/web3_eth/sign_transaction.test.ts @@ -66,7 +66,7 @@ describeIf(getSystemTestBackend() !== BACKEND.HARDHAT)('Web3Eth.signTransaction' expect(response).toMatchObject(expectedResponse); - // Pulling out of toMatchObject to be compatiable with Cypress + // Pulling out of toMatchObject to be compatible with Cypress expect(response.raw).toMatch(/0[xX][0-9a-fA-F]+/); expect(typeof (response.tx as TransactionLegacySignedAPI).v).toBe('bigint'); expect(response.tx.r).toMatch(/0[xX][0-9a-fA-F]{64}/); @@ -98,7 +98,7 @@ describeIf(getSystemTestBackend() !== BACKEND.HARDHAT)('Web3Eth.signTransaction' // eslint-disable-next-line jest/no-standalone-expect expect(response).toMatchObject(expectedResponse); - // Pulling out of toMatchObject to be compatiable with Cypress + // Pulling out of toMatchObject to be compatible with Cypress expect(response.raw).toMatch(/0[xX][0-9a-fA-F]+/); expect(typeof (response.tx as TransactionLegacySignedAPI).v).toBe('bigint'); expect(response.tx.r).toMatch(/0[xX][0-9a-fA-F]{64}/); diff --git a/packages/web3-utils/src/converters.ts b/packages/web3-utils/src/converters.ts index b84d5c28335..3d005ca3deb 100644 --- a/packages/web3-utils/src/converters.ts +++ b/packages/web3-utils/src/converters.ts @@ -187,7 +187,7 @@ export const numberToHex = (value: Numbers, hexstrict?: boolean): HexString => { let updatedValue = validatorUtils.numberToHex(value); if (hexstrict) { if (!updatedValue.startsWith('-') && updatedValue.length % 2 === 1) { - // To avoid duplicate a circular dependancy we will not be using the padLeft method + // To avoid duplicate a circular dependency we will not be using the padLeft method updatedValue = '0x0'.concat(updatedValue.slice(2)); } else if (updatedValue.length % 2 === 0 && updatedValue.startsWith('-')) updatedValue = '-0x0'.concat(updatedValue.slice(3)); diff --git a/packages/web3/test/integration/web3.config.test.ts b/packages/web3/test/integration/web3.config.test.ts index abf115b7276..33a3e8e2ad0 100644 --- a/packages/web3/test/integration/web3.config.test.ts +++ b/packages/web3/test/integration/web3.config.test.ts @@ -65,7 +65,7 @@ describe('Web3 instance', () => { } }); - it('should be send transaction, change for defaultTransactionType and sucesfully send transaction with different type', async () => { + it('should be send transaction, change for defaultTransactionType and successfully send transaction with different type', async () => { const transaction = { from: accounts[0], to: accounts[0], From edf3164b89dae889a315d87553b4522bf95aaf49 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 7 Mar 2024 03:50:46 -0500 Subject: [PATCH 08/19] add eventemitter3 (#6823) * update utils * replace web3 eventemitter for eventemitter3 * update tests * update snapshot * remove connection error test --------- Co-authored-by: Junaid <86780488+jdevcs@users.noreply.github.com> --- .../__snapshots__/web3_context.test.ts.snap | 46 +++++++-- packages/web3-eth-contract/package.json | 1 + .../test/unit/contract.test.ts | 5 +- .../test/unit/check_implementation.test.ts | 17 ---- .../web_socket_provider_integration.test.ts | 15 +++ .../test/unit/__mocks__/isomorphic-ws.ts | 16 ++- .../test/unit/check_implementation.test.ts | 20 +--- packages/web3-utils/CHANGELOG.md | 6 +- packages/web3-utils/package.json | 1 + .../web3-utils/src/chunk_response_parser.ts | 2 +- packages/web3-utils/src/event_emitter.ts | 97 +------------------ packages/web3-utils/src/socket_provider.ts | 2 - .../web3-utils/src/web3_eip1193_provider.ts | 2 +- .../test/unit/chunk_response_parser.test.ts | 2 +- yarn.lock | 10 ++ 15 files changed, 90 insertions(+), 152 deletions(-) diff --git a/packages/web3-core/test/unit/__snapshots__/web3_context.test.ts.snap b/packages/web3-core/test/unit/__snapshots__/web3_context.test.ts.snap index b832a1f8200..7e9121c85d2 100644 --- a/packages/web3-core/test/unit/__snapshots__/web3_context.test.ts.snap +++ b/packages/web3-core/test/unit/__snapshots__/web3_context.test.ts.snap @@ -42,12 +42,27 @@ exports[`Web3Context getContextObject should return correct context object 1`] = "requestManager": Web3RequestManager { "_emitter": { "_events": { - "BEFORE_PROVIDER_CHANGE": [Function], - "PROVIDER_CHANGED": [Function], + "BEFORE_PROVIDER_CHANGE": EE { + "context": EventEmitter { + "_events": [Circular], + "_eventsCount": 2, + "maxListeners": 9007199254740991, + }, + "fn": [Function], + "once": false, + }, + "PROVIDER_CHANGED": EE { + "context": EventEmitter { + "_events": [Circular], + "_eventsCount": 2, + "maxListeners": 9007199254740991, + }, + "fn": [Function], + "once": false, + }, }, "_eventsCount": 2, - "_maxListeners": undefined, - Symbol(kCapture): false, + "maxListeners": 9007199254740991, Symbol(shapeMode): false, }, "_provider": HttpProvider { @@ -62,12 +77,27 @@ exports[`Web3Context getContextObject should return correct context object 1`] = "requestManager": Web3RequestManager { "_emitter": { "_events": { - "BEFORE_PROVIDER_CHANGE": [Function], - "PROVIDER_CHANGED": [Function], + "BEFORE_PROVIDER_CHANGE": EE { + "context": EventEmitter { + "_events": [Circular], + "_eventsCount": 2, + "maxListeners": 9007199254740991, + }, + "fn": [Function], + "once": false, + }, + "PROVIDER_CHANGED": EE { + "context": EventEmitter { + "_events": [Circular], + "_eventsCount": 2, + "maxListeners": 9007199254740991, + }, + "fn": [Function], + "once": false, + }, }, "_eventsCount": 2, - "_maxListeners": undefined, - Symbol(kCapture): false, + "maxListeners": 9007199254740991, Symbol(shapeMode): false, }, "_provider": HttpProvider { diff --git a/packages/web3-eth-contract/package.json b/packages/web3-eth-contract/package.json index a587cbd8679..1218671f498 100644 --- a/packages/web3-eth-contract/package.json +++ b/packages/web3-eth-contract/package.json @@ -62,6 +62,7 @@ "eslint-config-base-web3": "0.1.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-import": "^2.26.0", + "flatted": "^3.3.1", "jest": "^29.7.0", "jest-extended": "^3.0.1", "prettier": "^2.7.1", diff --git a/packages/web3-eth-contract/test/unit/contract.test.ts b/packages/web3-eth-contract/test/unit/contract.test.ts index b55a19c1457..c870f56e255 100644 --- a/packages/web3-eth-contract/test/unit/contract.test.ts +++ b/packages/web3-eth-contract/test/unit/contract.test.ts @@ -21,6 +21,7 @@ import { Web3ContractError } from 'web3-errors'; import { Web3Context , Web3ConfigEvent } from 'web3-core'; import { Web3ValidatorError } from 'web3-validator'; import { AbiItem } from 'web3-utils'; +import { stringify } from 'flatted'; import {Abi} from '../fixtures/AbiItem' import { Contract } from '../../src'; import { sampleStorageContractABI } from '../fixtures/storage'; @@ -755,7 +756,7 @@ describe('Contract', () => { const clonnedContract = contract.clone(); - expect(JSON.stringify(contract)).toStrictEqual(JSON.stringify(clonnedContract)); + expect(stringify(contract)).toStrictEqual(stringify(clonnedContract)); contract.options.jsonInterface = GreeterAbi; }); @@ -764,7 +765,7 @@ describe('Contract', () => { const contract = new Contract(sampleStorageContractABI); const clonnedContract = contract.clone(); - expect(JSON.stringify(contract)).toStrictEqual(JSON.stringify(clonnedContract)); + expect(stringify(contract)).toStrictEqual(stringify(clonnedContract)); }); it('should be able to update the jsonInterface', () => { diff --git a/packages/web3-providers-ipc/test/unit/check_implementation.test.ts b/packages/web3-providers-ipc/test/unit/check_implementation.test.ts index 3b75744a25a..cc13c1b0281 100644 --- a/packages/web3-providers-ipc/test/unit/check_implementation.test.ts +++ b/packages/web3-providers-ipc/test/unit/check_implementation.test.ts @@ -97,23 +97,6 @@ describe('IPCProvider', () => { expect(end).toHaveBeenCalled(); }); - it('connection error', async () => { - const ipc = new IpcProvider(socketPath); - // @ts-expect-error mock method - ipc._socketConnection.connecting = false; - // @ts-expect-error mock method - ipc._connectionStatus = 'disconnected'; - ipc.connect = jest.fn(); - - await expect( - ipc.request({ - jsonrpc: '2.0', - id: 42, - method: 'eth_getBalance', - params: ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', 'latest'], - }), - ).rejects.toThrow('Connection not open'); - }); it('_onCloseHandler autoReconnect=false', () => { const ipc = new IpcProvider(socketPath, {}, { autoReconnect: false }); const _clearQueues = jest.fn(); diff --git a/packages/web3-providers-ws/test/integration/web_socket_provider_integration.test.ts b/packages/web3-providers-ws/test/integration/web_socket_provider_integration.test.ts index d93521be0c2..ccc1a97714f 100644 --- a/packages/web3-providers-ws/test/integration/web_socket_provider_integration.test.ts +++ b/packages/web3-providers-ws/test/integration/web_socket_provider_integration.test.ts @@ -137,6 +137,21 @@ describeIf(isWs)('WebSocketProvider - implemented methods', () => { webSocketProvider.disconnect(code); await closePromise; }); + + it('should error when no connection is established', async () => { + const wsProvider = new WebSocketProvider("ws://localhost:999",{}, { autoReconnect: false }); + let errored = false; + try{ + await wsProvider.request(jsonRpcPayload); + // should not be able to reach here + + }catch(e){ + // eslint-disable-next-line jest/no-conditional-expect + expect((e as any).message).toBe('Connection not open') + errored = true; + } + expect(errored).toBe(true); + }); }); describe('disconnect and reset test', () => { diff --git a/packages/web3-providers-ws/test/unit/__mocks__/isomorphic-ws.ts b/packages/web3-providers-ws/test/unit/__mocks__/isomorphic-ws.ts index 42a0cdf4871..d5e9d79cef9 100644 --- a/packages/web3-providers-ws/test/unit/__mocks__/isomorphic-ws.ts +++ b/packages/web3-providers-ws/test/unit/__mocks__/isomorphic-ws.ts @@ -23,10 +23,9 @@ export default class WebSocket extends EventEmitter { public CONNECTING = 0; public OPEN = 1; - public constructor(...args: any[]) { + public constructor() { + super() // eslint-disable-next-line @typescript-eslint/no-unsafe-call - super(...args); - // Connected state this.readyState = 1; } @@ -43,13 +42,12 @@ export default class WebSocket extends EventEmitter { }, 100); } - public addEventListener(event: any, cb: () => void) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - this.prependListener(event, cb); + public addEventListener(_event: any, _cb: () => void) { + this.on(_event, _cb) + } - public removeEventListener(event: any, cb: () => void) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - this.removeListener(event, cb); + public removeEventListener(_event: any, _cb: () => void) { + this.off(_event, _cb) } } diff --git a/packages/web3-providers-ws/test/unit/check_implementation.test.ts b/packages/web3-providers-ws/test/unit/check_implementation.test.ts index 99d7013b45b..138855b9509 100644 --- a/packages/web3-providers-ws/test/unit/check_implementation.test.ts +++ b/packages/web3-providers-ws/test/unit/check_implementation.test.ts @@ -85,21 +85,6 @@ describe('WebSocketProvider', () => { ws.disconnect(code, data); expect(close).toHaveBeenCalledWith(code, data); }); - it('connection error', async () => { - const ws = new WebSocketProvider('ws://localhost:8545'); - // @ts-expect-error mock method - ws._socketConnection.readyState = 2; - ws.connect = jest.fn(); - - await expect( - ws.request({ - jsonrpc: '2.0', - id: 42, - method: 'eth_getBalance', - params: ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', 'latest'], - }), - ).rejects.toThrow('Connection not open'); - }); it('onCloseEvent autoReconnect=false', () => { const ws = new WebSocketProvider('ws://localhost:8545', {}, { autoReconnect: false }); const _clearQueues = jest.fn(); @@ -107,6 +92,7 @@ describe('WebSocketProvider', () => { const _onDisconnect = jest.fn(); // @ts-expect-error mock method ws._socketConnection.close = jest.fn(); + // @ts-expect-error mock method ws._clearQueues = _clearQueues; // @ts-expect-error mock method @@ -140,7 +126,7 @@ describe('WebSocketProvider', () => { const ws = new WebSocketProvider('ws://localhost:8545'); // @ts-expect-error mock method ws._socketConnection.listeners = () => { - throw new Error('error'); + throw new Error('error'); }; const addEventListener = jest.fn(); // @ts-expect-error mock method @@ -161,6 +147,6 @@ describe('WebSocketProvider', () => { expect(removeEventListener).toHaveBeenCalledWith('open', ws._onOpenHandler); // @ts-expect-error mock method expect(removeEventListener).toHaveBeenCalledWith('close', ws._onCloseHandler); - }); + }); }); }); diff --git a/packages/web3-utils/CHANGELOG.md b/packages/web3-utils/CHANGELOG.md index 477b9031953..3bb09ffe5e0 100644 --- a/packages/web3-utils/CHANGELOG.md +++ b/packages/web3-utils/CHANGELOG.md @@ -193,4 +193,8 @@ Documentation: - Adds missing exported type `AbiItem` from 1.x to v4 for compatabiltiy (#6678) -## [Unreleased] \ No newline at end of file +## [Unreleased] + +### Fixed + +- replaced our eventEmitter to EventEmitter3 to support react native builds (#6253) \ No newline at end of file diff --git a/packages/web3-utils/package.json b/packages/web3-utils/package.json index 8d5a9296086..299fb8333c7 100644 --- a/packages/web3-utils/package.json +++ b/packages/web3-utils/package.json @@ -64,6 +64,7 @@ }, "dependencies": { "ethereum-cryptography": "^2.0.0", + "eventemitter3": "^5.0.1", "web3-errors": "^1.1.4", "web3-types": "^1.4.0", "web3-validator": "^2.0.4" diff --git a/packages/web3-utils/src/chunk_response_parser.ts b/packages/web3-utils/src/chunk_response_parser.ts index 629323415cb..68e708e58b5 100644 --- a/packages/web3-utils/src/chunk_response_parser.ts +++ b/packages/web3-utils/src/chunk_response_parser.ts @@ -16,7 +16,7 @@ along with web3.js. If not, see . */ import { JsonRpcResponse } from 'web3-types'; import { InvalidResponseError } from 'web3-errors'; -import { EventEmitter } from 'events'; +import { EventEmitter } from 'eventemitter3'; import { Timeout } from './promise_helpers.js'; export class ChunkResponseParser { diff --git a/packages/web3-utils/src/event_emitter.ts b/packages/web3-utils/src/event_emitter.ts index 7d9c3ccdb2e..bc7fee36f04 100644 --- a/packages/web3-utils/src/event_emitter.ts +++ b/packages/web3-utils/src/event_emitter.ts @@ -16,75 +16,17 @@ along with web3.js. If not, see . */ /* eslint-disable max-classes-per-file */ -import { EventEmitter as EventEmitterAtNode } from 'events'; +import EventEmitter3 from 'eventemitter3'; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -type Callback = (params: any) => void | Promise; - -type EventTargetCallback = (params: CustomEvent) => void; - -const wrapFunction = - (fn: Callback): EventTargetCallback => - (params: CustomEvent) => - fn(params.detail); /** * This class copy the behavior of Node.js EventEmitter class. * It is used to provide the same interface for the browser environment. */ -class EventEmitterAtBrowser extends EventTarget { - private _listeners: Record = {}; +export class EventEmitter extends EventEmitter3 { + // must be defined for backwards compatibility private maxListeners = Number.MAX_SAFE_INTEGER; - public on(eventName: string, fn: Callback) { - this.addEventListener(eventName, fn); - return this; - } - - public once(eventName: string, fn: Callback) { - const onceCallback = async (params: Callback) => { - this.off(eventName, onceCallback); - await fn(params); - }; - return this.on(eventName, onceCallback); - } - - public off(eventName: string, fn: Callback) { - this.removeEventListener(eventName, fn); - return this; - } - - public emit(eventName: string, params: unknown) { - const event = new CustomEvent(eventName, { detail: params }); - return super.dispatchEvent(event); - } - - public listenerCount(eventName: string): number { - const eventListeners = this._listeners[eventName]; - return eventListeners ? eventListeners.length : 0; - } - - public listeners(eventName: string): Callback[] { - return this._listeners[eventName].map(value => value[0]) || []; - } - - public eventNames(): string[] { - return Object.keys(this._listeners); - } - - public removeAllListeners() { - Object.keys(this._listeners).forEach(event => { - this._listeners[event].forEach( - (listener: [key: Callback, value: EventTargetCallback]) => { - super.removeEventListener(event, listener[1] as EventListener); - }, - ); - }); - - this._listeners = {}; - return this; - } - public setMaxListeners(maxListeners: number) { this.maxListeners = maxListeners; return this; @@ -94,35 +36,4 @@ class EventEmitterAtBrowser extends EventTarget { return this.maxListeners; } - public addEventListener(eventName: string, fn: Callback) { - const wrappedFn = wrapFunction(fn); - super.addEventListener(eventName, wrappedFn as EventListener); - if (!this._listeners[eventName]) { - this._listeners[eventName] = []; - } - this._listeners[eventName].push([fn, wrappedFn]); - } - - public removeEventListener(eventName: string, fn: Callback) { - const eventListeners = this._listeners[eventName]; - if (eventListeners) { - const index = eventListeners.findIndex(item => item[0] === fn); - if (index !== -1) { - super.removeEventListener(eventName, eventListeners[index][1] as EventListener); - eventListeners.splice(index, 1); - } - } - } -} - -// eslint-disable-next-line import/no-mutable-exports -let EventEmitterType: typeof EventEmitterAtNode; -// Check if the code is running in a Node.js environment -if (typeof window === 'undefined') { - EventEmitterType = EventEmitterAtNode; -} else { - // Fallback for the browser environment - EventEmitterType = EventEmitterAtBrowser as unknown as typeof EventEmitterAtNode; -} - -export class EventEmitter extends EventEmitterType {} \ No newline at end of file +} \ No newline at end of file diff --git a/packages/web3-utils/src/socket_provider.ts b/packages/web3-utils/src/socket_provider.ts index 3c879a2df84..d847dcbccc9 100644 --- a/packages/web3-utils/src/socket_provider.ts +++ b/packages/web3-utils/src/socket_provider.ts @@ -118,7 +118,6 @@ export abstract class SocketProvider< this._socketPath = socketPath; this._socketOptions = socketOptions; - this._reconnectOptions = { ...DEFAULT_RECONNECTION_OPTIONS, ...(reconnectOptions ?? {}), @@ -465,7 +464,6 @@ export abstract class SocketProvider< if (this._sentRequestsQueue.has(requestId)) { throw new RequestAlreadySentError(requestId); } - const deferredPromise = new Web3DeferredPromise>(); deferredPromise.catch(error => { this._eventEmitter.emit('error', error); diff --git a/packages/web3-utils/src/web3_eip1193_provider.ts b/packages/web3-utils/src/web3_eip1193_provider.ts index 15f132f6215..f0e2d4d30bf 100644 --- a/packages/web3-utils/src/web3_eip1193_provider.ts +++ b/packages/web3-utils/src/web3_eip1193_provider.ts @@ -23,7 +23,7 @@ import { Web3APISpec, Web3BaseProvider, } from 'web3-types'; -import { EventEmitter } from 'events'; +import { EventEmitter } from 'eventemitter3'; import { EIP1193ProviderRpcError } from 'web3-errors'; import { toPayload } from './json_rpc.js'; diff --git a/packages/web3-utils/test/unit/chunk_response_parser.test.ts b/packages/web3-utils/test/unit/chunk_response_parser.test.ts index 1fc08c2fceb..27241b4243b 100644 --- a/packages/web3-utils/test/unit/chunk_response_parser.test.ts +++ b/packages/web3-utils/test/unit/chunk_response_parser.test.ts @@ -15,7 +15,7 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -import { EventEmitter } from 'events'; +import { EventEmitter } from 'eventemitter3'; import { InvalidResponseError } from 'web3-errors'; import { ChunkResponseParser } from '../../src/chunk_response_parser'; import { hugeData } from '../fixtures/hugeData'; diff --git a/yarn.lock b/yarn.lock index 98bbc72e352..bc653ed8db7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5676,6 +5676,11 @@ eventemitter3@^4.0.0, eventemitter3@^4.0.4: resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f" integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw== +eventemitter3@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-5.0.1.tgz#53f5ffd0a492ac800721bb42c66b841de96423c4" + integrity sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA== + events@^3.0.0, events@^3.2.0, events@^3.3.0: version "3.3.0" resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400" @@ -6052,6 +6057,11 @@ flatted@^3.1.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.6.tgz#022e9218c637f9f3fc9c35ab9c9193f05add60b2" integrity sha512-0sQoMh9s0BYsm+12Huy/rkKxVu4R1+r96YX5cG44rHV0pQ6iC3Q+mkoMFaGWObMFYQxCVT+ssG1ksneA2MI9KQ== +flatted@^3.3.1: + version "3.3.1" + resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.3.1.tgz#21db470729a6734d4997002f439cb308987f567a" + integrity sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw== + follow-redirects@^1.0.0, follow-redirects@^1.12.1: version "1.15.1" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.1.tgz#0ca6a452306c9b276e4d3127483e29575e207ad5" From cf60f713170781305f8094b18b4248aea1b1437b Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Thu, 7 Mar 2024 07:03:57 -0500 Subject: [PATCH 09/19] Fix unstable tests [DRAFT] (#6857) * void test * set arc * fix jest warnings * increase cache * increase cache * try diff version * fix bigint problem * ix * + * hot fix * update geth-binary version * increase timout for accounts test * fix * revert * fix --------- Co-authored-by: Junaid <86780488+jdevcs@users.noreply.github.com> --- .github/workflows/build.yml | 1 + packages/web3-core/test/config/jest.config.js | 14 +++---- .../web3-eth-abi/test/config/jest.config.js | 12 +++--- .../test/unit/account.test.ts | 2 + .../test/config/jest.config.js | 12 +++--- .../test/integration/resolver.test.ts | 1 + .../test/config/jest.config.js | 12 +++--- .../test/unit/format_transaction.test.ts | 32 +++++++++------ packages/web3-net/test/config/jest.config.js | 12 +++--- .../test/config/jest.config.js | 12 +++--- .../web3-types/test/config/jest.config.js | 12 +++--- packages/web3-utils/src/objects.ts | 9 +++-- .../web3-utils/test/config/jest.config.js | 14 +++---- packages/web3-utils/test/unit/objects.test.ts | 4 +- .../web3-validator/test/config/jest.config.js | 12 +++--- .../test/integration/void.test.ts | 22 ++++++++++ .../web3/test/cjs_black_box/jest.config.js | 7 +++- packages/web3/test/config/jest.config.js | 12 +++--- .../web3/test/esm_black_box/jest.config.js | 7 +++- scripts/geth.sh | 8 ++-- scripts/geth_binary.sh | 10 ++--- scripts/system_tests_utils.ts | 40 +++++++++++-------- templates/jest.config.js.tmpl | 17 ++++---- .../test/config/jest.config.js | 12 +++--- 24 files changed, 172 insertions(+), 124 deletions(-) create mode 100644 packages/web3-validator/test/integration/void.test.ts diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ba60ce39f22..ee95deaf804 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -118,6 +118,7 @@ jobs: steps: - uses: actions/setup-node@v4 with: + architecture: x64 node-version: ${{ matrix.node }} - uses: actions/cache/restore@v3 with: diff --git a/packages/web3-core/test/config/jest.config.js b/packages/web3-core/test/config/jest.config.js index 4a60f95b353..74597df99d0 100644 --- a/packages/web3-core/test/config/jest.config.js +++ b/packages/web3-core/test/config/jest.config.js @@ -1,18 +1,18 @@ module.exports = { - globals: { - 'ts-jest': { - tsconfig: './test/tsconfig.json', - }, - }, rootDir: '../..', testMatch: ['/test/**/?(*.)+(spec|test).+(ts|tsx|js)'], setupFilesAfterEnv: ['/test/config/setup.js'], transform: { - '^.+\\.(ts|tsx)$': 'ts-jest', + '^.+\\.(ts|tsx)$': [ + 'ts-jest', + { + tsconfig: './test/tsconfig.json', + }, + ], }, moduleNameMapper: { '^(\\.{1,2}/.*)\\.js$': '$1', - }, + }, verbose: false, collectCoverage: false, coverageReporters: ['json'], diff --git a/packages/web3-eth-abi/test/config/jest.config.js b/packages/web3-eth-abi/test/config/jest.config.js index c8c21e06e6a..74597df99d0 100644 --- a/packages/web3-eth-abi/test/config/jest.config.js +++ b/packages/web3-eth-abi/test/config/jest.config.js @@ -1,14 +1,14 @@ module.exports = { - globals: { - 'ts-jest': { - tsconfig: './test/tsconfig.json', - }, - }, rootDir: '../..', testMatch: ['/test/**/?(*.)+(spec|test).+(ts|tsx|js)'], setupFilesAfterEnv: ['/test/config/setup.js'], transform: { - '^.+\\.(ts|tsx)$': 'ts-jest', + '^.+\\.(ts|tsx)$': [ + 'ts-jest', + { + tsconfig: './test/tsconfig.json', + }, + ], }, moduleNameMapper: { '^(\\.{1,2}/.*)\\.js$': '$1', diff --git a/packages/web3-eth-accounts/test/unit/account.test.ts b/packages/web3-eth-accounts/test/unit/account.test.ts index 713ac9e4829..10dae39fbc7 100644 --- a/packages/web3-eth-accounts/test/unit/account.test.ts +++ b/packages/web3-eth-accounts/test/unit/account.test.ts @@ -49,6 +49,8 @@ import { import { TransactionFactory } from '../../src/tx/transactionFactory'; import { TxData } from '../../src/tx/types'; +jest.setTimeout(25000); + describe('accounts', () => { describe('create', () => { describe('valid cases', () => { diff --git a/packages/web3-eth-contract/test/config/jest.config.js b/packages/web3-eth-contract/test/config/jest.config.js index c8c21e06e6a..74597df99d0 100644 --- a/packages/web3-eth-contract/test/config/jest.config.js +++ b/packages/web3-eth-contract/test/config/jest.config.js @@ -1,14 +1,14 @@ module.exports = { - globals: { - 'ts-jest': { - tsconfig: './test/tsconfig.json', - }, - }, rootDir: '../..', testMatch: ['/test/**/?(*.)+(spec|test).+(ts|tsx|js)'], setupFilesAfterEnv: ['/test/config/setup.js'], transform: { - '^.+\\.(ts|tsx)$': 'ts-jest', + '^.+\\.(ts|tsx)$': [ + 'ts-jest', + { + tsconfig: './test/tsconfig.json', + }, + ], }, moduleNameMapper: { '^(\\.{1,2}/.*)\\.js$': '$1', diff --git a/packages/web3-eth-ens/test/integration/resolver.test.ts b/packages/web3-eth-ens/test/integration/resolver.test.ts index d0d4d5095b1..587ce2e7b29 100644 --- a/packages/web3-eth-ens/test/integration/resolver.test.ts +++ b/packages/web3-eth-ens/test/integration/resolver.test.ts @@ -44,6 +44,7 @@ import { ENSRegistryBytecode } from '../fixtures/ens/bytecode/ENSRegistryBytecod import { NameWrapperBytecode } from '../fixtures/ens/bytecode/NameWrapperBytecode'; import { PublicResolverBytecode } from '../fixtures/ens/bytecode/PublicResolverBytecode'; +jest.setTimeout(25000); describe('ens', () => { let registry: Contract; let resolver: Contract; diff --git a/packages/web3-eth-personal/test/config/jest.config.js b/packages/web3-eth-personal/test/config/jest.config.js index c8c21e06e6a..74597df99d0 100644 --- a/packages/web3-eth-personal/test/config/jest.config.js +++ b/packages/web3-eth-personal/test/config/jest.config.js @@ -1,14 +1,14 @@ module.exports = { - globals: { - 'ts-jest': { - tsconfig: './test/tsconfig.json', - }, - }, rootDir: '../..', testMatch: ['/test/**/?(*.)+(spec|test).+(ts|tsx|js)'], setupFilesAfterEnv: ['/test/config/setup.js'], transform: { - '^.+\\.(ts|tsx)$': 'ts-jest', + '^.+\\.(ts|tsx)$': [ + 'ts-jest', + { + tsconfig: './test/tsconfig.json', + }, + ], }, moduleNameMapper: { '^(\\.{1,2}/.*)\\.js$': '$1', diff --git a/packages/web3-eth/test/unit/format_transaction.test.ts b/packages/web3-eth/test/unit/format_transaction.test.ts index 028ac043b20..9ce83aaa941 100644 --- a/packages/web3-eth/test/unit/format_transaction.test.ts +++ b/packages/web3-eth/test/unit/format_transaction.test.ts @@ -26,6 +26,7 @@ import { numbersAsNumberTransaction, bytesAsUint8ArrayTransaction, } from '../fixtures/format_transaction'; +import { objectBigintToString } from '../fixtures/system_test_utils'; const transactionsDataForNumberTypes: Record> = { [FMT_NUMBER.BIGINT]: numbersAsBigIntTransaction, @@ -59,14 +60,16 @@ describe('formatTransaction', () => { delete expectedFormattedTransaction.data; expect( - formatTransaction( - transactionsDataForNumberTypes[sourceType as FMT_NUMBER], - { - ...DEFAULT_RETURN_FORMAT, - number: destinationType as FMT_NUMBER, - }, + objectBigintToString( + formatTransaction( + transactionsDataForNumberTypes[sourceType as FMT_NUMBER], + { + ...DEFAULT_RETURN_FORMAT, + number: destinationType as FMT_NUMBER, + }, + ), ), - ).toStrictEqual(expectedFormattedTransaction); + ).toStrictEqual(objectBigintToString(expectedFormattedTransaction)); }); } } @@ -85,11 +88,16 @@ describe('formatTransaction', () => { delete expectedFormattedTransaction.data; expect( - formatTransaction(transactionsDataForByteTypes[sourceType as FMT_BYTES], { - ...DEFAULT_RETURN_FORMAT, - bytes: destinationType as FMT_BYTES, - }), - ).toStrictEqual(expectedFormattedTransaction); + objectBigintToString( + formatTransaction( + transactionsDataForByteTypes[sourceType as FMT_BYTES], + { + ...DEFAULT_RETURN_FORMAT, + bytes: destinationType as FMT_BYTES, + }, + ), + ), + ).toStrictEqual(objectBigintToString(expectedFormattedTransaction)); }); } } diff --git a/packages/web3-net/test/config/jest.config.js b/packages/web3-net/test/config/jest.config.js index c8c21e06e6a..74597df99d0 100644 --- a/packages/web3-net/test/config/jest.config.js +++ b/packages/web3-net/test/config/jest.config.js @@ -1,14 +1,14 @@ module.exports = { - globals: { - 'ts-jest': { - tsconfig: './test/tsconfig.json', - }, - }, rootDir: '../..', testMatch: ['/test/**/?(*.)+(spec|test).+(ts|tsx|js)'], setupFilesAfterEnv: ['/test/config/setup.js'], transform: { - '^.+\\.(ts|tsx)$': 'ts-jest', + '^.+\\.(ts|tsx)$': [ + 'ts-jest', + { + tsconfig: './test/tsconfig.json', + }, + ], }, moduleNameMapper: { '^(\\.{1,2}/.*)\\.js$': '$1', diff --git a/packages/web3-providers-ipc/test/config/jest.config.js b/packages/web3-providers-ipc/test/config/jest.config.js index 6c71b126961..068de35aa8e 100644 --- a/packages/web3-providers-ipc/test/config/jest.config.js +++ b/packages/web3-providers-ipc/test/config/jest.config.js @@ -1,14 +1,14 @@ module.exports = { - globals: { - 'ts-jest': { - tsconfig: './test/tsconfig.json', - }, - }, rootDir: '../..', testMatch: ['/test/**/?(*.)+(spec|test).+(ts|tsx|js)'], setupFilesAfterEnv: ['/test/config/setup.js'], transform: { - '^.+\\.(ts|tsx)$': 'ts-jest', + '^.+\\.(ts|tsx)$': [ + 'ts-jest', + { + tsconfig: './test/tsconfig.json', + }, + ], }, moduleNameMapper: { '^(\\.{1,2}/.*)\\.js$': '$1', diff --git a/packages/web3-types/test/config/jest.config.js b/packages/web3-types/test/config/jest.config.js index eaa5e9049da..7d959c45719 100644 --- a/packages/web3-types/test/config/jest.config.js +++ b/packages/web3-types/test/config/jest.config.js @@ -1,14 +1,14 @@ module.exports = { - globals: { - 'ts-jest': { - tsconfig: './test/tsconfig.json', - }, - }, rootDir: '../..', testMatch: ['/test/**/?(*.)+(spec|test).+(ts|tsx|js)'], setupFilesAfterEnv: ['/test/config/setup.js'], transform: { - '^.+\\.(ts|tsx)$': 'ts-jest', + '^.+\\.(ts|tsx)$': [ + 'ts-jest', + { + tsconfig: './test/tsconfig.json', + }, + ], }, verbose: false, collectCoverage: false, diff --git a/packages/web3-utils/src/objects.ts b/packages/web3-utils/src/objects.ts index 6417465e57b..feda5510e4f 100644 --- a/packages/web3-utils/src/objects.ts +++ b/packages/web3-utils/src/objects.ts @@ -36,18 +36,19 @@ export const mergeDeep = ( destination: Record, ...sources: Record[] ): Record => { - const result = { ...destination }; // clone deep here - if (!isIterable(result)) { - return result; + if (!isIterable(destination)) { + return destination; } + const result = { ...destination }; // clone deep here for (const src of sources) { + // const src = { ..._src }; // eslint-disable-next-line no-restricted-syntax for (const key in src) { if (isIterable(src[key])) { if (!result[key]) { result[key] = {}; } - mergeDeep( + result[key] = mergeDeep( result[key] as Record, src[key] as Record, ); diff --git a/packages/web3-utils/test/config/jest.config.js b/packages/web3-utils/test/config/jest.config.js index 4a60f95b353..74597df99d0 100644 --- a/packages/web3-utils/test/config/jest.config.js +++ b/packages/web3-utils/test/config/jest.config.js @@ -1,18 +1,18 @@ module.exports = { - globals: { - 'ts-jest': { - tsconfig: './test/tsconfig.json', - }, - }, rootDir: '../..', testMatch: ['/test/**/?(*.)+(spec|test).+(ts|tsx|js)'], setupFilesAfterEnv: ['/test/config/setup.js'], transform: { - '^.+\\.(ts|tsx)$': 'ts-jest', + '^.+\\.(ts|tsx)$': [ + 'ts-jest', + { + tsconfig: './test/tsconfig.json', + }, + ], }, moduleNameMapper: { '^(\\.{1,2}/.*)\\.js$': '$1', - }, + }, verbose: false, collectCoverage: false, coverageReporters: ['json'], diff --git a/packages/web3-utils/test/unit/objects.test.ts b/packages/web3-utils/test/unit/objects.test.ts index 07c4f225022..1201b3b7345 100644 --- a/packages/web3-utils/test/unit/objects.test.ts +++ b/packages/web3-utils/test/unit/objects.test.ts @@ -21,9 +21,7 @@ import { mergeDeepData } from '../fixtures/objects'; describe('objects', () => { describe('mergeDeep', () => { it.each(mergeDeepData)('$message', ({ destination, sources, output }) => { - mergeDeep(destination, ...sources); - - expect(destination).toEqual(output); + expect(mergeDeep(destination, ...sources)).toEqual(output); }); it('should not mutate the sources', () => { diff --git a/packages/web3-validator/test/config/jest.config.js b/packages/web3-validator/test/config/jest.config.js index c8c21e06e6a..74597df99d0 100644 --- a/packages/web3-validator/test/config/jest.config.js +++ b/packages/web3-validator/test/config/jest.config.js @@ -1,14 +1,14 @@ module.exports = { - globals: { - 'ts-jest': { - tsconfig: './test/tsconfig.json', - }, - }, rootDir: '../..', testMatch: ['/test/**/?(*.)+(spec|test).+(ts|tsx|js)'], setupFilesAfterEnv: ['/test/config/setup.js'], transform: { - '^.+\\.(ts|tsx)$': 'ts-jest', + '^.+\\.(ts|tsx)$': [ + 'ts-jest', + { + tsconfig: './test/tsconfig.json', + }, + ], }, moduleNameMapper: { '^(\\.{1,2}/.*)\\.js$': '$1', diff --git a/packages/web3-validator/test/integration/void.test.ts b/packages/web3-validator/test/integration/void.test.ts new file mode 100644 index 00000000000..9fe194cc5fc --- /dev/null +++ b/packages/web3-validator/test/integration/void.test.ts @@ -0,0 +1,22 @@ +/* +This file is part of web3.js. + +web3.js is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +web3.js is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with web3.js. If not, see . +*/ + +describe('Web3 validator test', () => { + it('void', () => { + expect(1).toBe(1); + }); +}); diff --git a/packages/web3/test/cjs_black_box/jest.config.js b/packages/web3/test/cjs_black_box/jest.config.js index 06b150fe5c8..ce489d3d015 100644 --- a/packages/web3/test/cjs_black_box/jest.config.js +++ b/packages/web3/test/cjs_black_box/jest.config.js @@ -6,6 +6,11 @@ module.exports = { }, }, transform: { - '^.+\\.(ts|tsx)$': 'ts-jest', + '^.+\\.(ts|tsx)$': [ + 'ts-jest', + { + tsconfig: './test/tsconfig.json', + }, + ], }, }; diff --git a/packages/web3/test/config/jest.config.js b/packages/web3/test/config/jest.config.js index c8c21e06e6a..74597df99d0 100644 --- a/packages/web3/test/config/jest.config.js +++ b/packages/web3/test/config/jest.config.js @@ -1,14 +1,14 @@ module.exports = { - globals: { - 'ts-jest': { - tsconfig: './test/tsconfig.json', - }, - }, rootDir: '../..', testMatch: ['/test/**/?(*.)+(spec|test).+(ts|tsx|js)'], setupFilesAfterEnv: ['/test/config/setup.js'], transform: { - '^.+\\.(ts|tsx)$': 'ts-jest', + '^.+\\.(ts|tsx)$': [ + 'ts-jest', + { + tsconfig: './test/tsconfig.json', + }, + ], }, moduleNameMapper: { '^(\\.{1,2}/.*)\\.js$': '$1', diff --git a/packages/web3/test/esm_black_box/jest.config.js b/packages/web3/test/esm_black_box/jest.config.js index d01db385b4b..678e0222c26 100644 --- a/packages/web3/test/esm_black_box/jest.config.js +++ b/packages/web3/test/esm_black_box/jest.config.js @@ -6,6 +6,11 @@ export default { }, }, transform: { - '^.+\\.(ts|tsx)$': 'ts-jest', + '^.+\\.(ts|tsx)$': [ + 'ts-jest', + { + tsconfig: './test/tsconfig.json', + }, + ], }, }; diff --git a/scripts/geth.sh b/scripts/geth.sh index 8469b4e65ab..62c7213ccfb 100755 --- a/scripts/geth.sh +++ b/scripts/geth.sh @@ -12,12 +12,12 @@ start() { if [ -z "${ORIGARGS[1]}" ] then echo "Starting geth..." - echo "docker run -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:latest --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev" - docker run -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:latest --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev + echo "docker run -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:v1.13.14-amd64 --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev" + docker run -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:v1.13.14-amd64 --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev else echo "Starting geth..." - echo "docker run -d -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:latest --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev" - docker run -d -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:latest --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev + echo "docker run -d -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:v1.13.14-amd64 --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev" + docker run -d -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:v1.13.14-amd64 --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev echo "Waiting for geth..." npx wait-port -t 10000 "$WEB3_SYSTEM_TEST_PORT" echo "Geth started" diff --git a/scripts/geth_binary.sh b/scripts/geth_binary.sh index 927783acbe2..96212d04a77 100755 --- a/scripts/geth_binary.sh +++ b/scripts/geth_binary.sh @@ -21,11 +21,11 @@ getOS(){ getDownloadLink(){ case "$OS" in SOLARIS*) LINK="-" ;; - OSX*) LINK="https://gethstore.blob.core.windows.net/builds/geth-darwin-amd64-1.13.8-b20b4a71.tar.gz" ;; - LINUX*) LINK="https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.13.8-b20b4a71.tar.gz" ;; - BSD*) LINK="https://gethstore.blob.core.windows.net/builds/geth-darwin-amd64-1.13.8-b20b4a71.tar.gz" ;; - WINDOWS*) LINK="https://gethstore.blob.core.windows.net/builds/geth-windows-amd64-1.13.8-b20b4a71.exe" ;; - "ALSO WINDOWS"*) LINK="https://gethstore.blob.core.windows.net/builds/geth-windows-amd64-1.13.8-b20b4a71.exe" ;; + OSX*) LINK="https://gethstore.blob.core.windows.net/builds/geth-darwin-arm64-1.13.14-2bd6bd01.tar.gz" ;; + LINUX*) LINK="https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.13.14-2bd6bd01.tar.gz" ;; + BSD*) LINK="https://gethstore.blob.core.windows.net/builds/geth-darwin-arm64-1.13.14-2bd6bd01.tar.gz" ;; + WINDOWS*) LINK="https://gethstore.blob.core.windows.net/builds/geth-windows-amd64-1.13.14-2bd6bd01.exe" ;; + "ALSO WINDOWS"*) LINK="https://gethstore.blob.core.windows.net/builds/geth-windows-amd64-1.13.14-2bd6bd01.exe" ;; *) LINK="-" ;; esac } diff --git a/scripts/system_tests_utils.ts b/scripts/system_tests_utils.ts index ea84d21f03e..a502c44825e 100644 --- a/scripts/system_tests_utils.ts +++ b/scripts/system_tests_utils.ts @@ -26,7 +26,7 @@ import { } from 'web3-eth-accounts'; // eslint-disable-next-line import/no-extraneous-dependencies -import HardhatPlugin from 'web3-hardhat-plugin'; +import HardhatPlugin from 'web3-hardhat-plugin'; // eslint-disable-next-line import/no-extraneous-dependencies import { prepareTransactionForSigning, Web3Eth } from 'web3-eth'; // eslint-disable-next-line import/no-extraneous-dependencies @@ -257,33 +257,34 @@ export const createNewAccount = async (config?: { const clientUrl = DEFAULT_SYSTEM_PROVIDER; if (config?.unlock) { - - if (getSystemTestBackend() === BACKEND.HARDHAT){ + if (getSystemTestBackend() === BACKEND.HARDHAT) { const url = getSystemTestProviderUrl(); const web3 = new Web3(url); - web3.registerPlugin(new HardhatPlugin()) + web3.registerPlugin(new HardhatPlugin()); await web3.hardhat.impersonateAccount(acc.address); // await impersonateAccount(acc.address); await web3.hardhat.setBalance(acc.address, web3.utils.toHex('100000000')); } else { - const web3Personal = new Personal(clientUrl); - if (!config?.doNotImport) { - await web3Personal.importRawKey( - getSystemTestBackend() === BACKEND.GETH ? acc.privateKey.slice(2) : acc.privateKey, - config.password ?? '123456', - ); - } + const web3Personal = new Personal(clientUrl); + if (!config?.doNotImport) { + await web3Personal.importRawKey( + getSystemTestBackend() === BACKEND.GETH + ? acc.privateKey.slice(2) + : acc.privateKey, + config.password ?? '123456', + ); + } - await web3Personal.unlockAccount(acc.address, config.password ?? '123456', 100000000); + await web3Personal.unlockAccount(acc.address, config.password ?? '123456', 100000000); } } if (config?.refill) { - if (getSystemTestBackend() === BACKEND.HARDHAT){ + if (getSystemTestBackend() === BACKEND.HARDHAT) { const url = getSystemTestProviderUrl(); const web3 = new Web3(url); - web3.registerPlugin(new HardhatPlugin()) - await web3.hardhat.setBalance(acc.address, web3.utils.toHex('100000000')) + web3.registerPlugin(new HardhatPlugin()); + await web3.hardhat.setBalance(acc.address, web3.utils.toHex('100000000')); } else { const web3Personal = new Personal(clientUrl); if (!mainAcc) { @@ -337,7 +338,7 @@ export const createTempAccount = async ( currentIndex += 1; return acc; - } +}; export const getSystemTestAccountsWithKeys = async (): Promise< { @@ -496,3 +497,10 @@ export const sendFewSampleTxs = async (cnt = 1) => { await closeOpenConnection(web3); return res; }; + +export const objectBigintToString = (obj: object): object => + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + JSON.parse( + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + JSON.stringify(obj, (_, value) => (typeof value === 'bigint' ? value.toString() : value)), + ); diff --git a/templates/jest.config.js.tmpl b/templates/jest.config.js.tmpl index d7789fbbbd0..e4d70e55a94 100644 --- a/templates/jest.config.js.tmpl +++ b/templates/jest.config.js.tmpl @@ -15,23 +15,20 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ module.exports = { - globals: { - 'ts-jest': { - tsconfig: './test/tsconfig.json', - }, - }, moduleNameMapper: { '^(\\.{1,2}/.*)\\.js$': '$1', - }, + }, rootDir: '../..', testMatch: ['/test/**/?(*.)+(spec|test).+(ts|tsx|js)'], setupFilesAfterEnv: ['/test/config/setup.js'], transform: { - '^.+\\.(ts|tsx)$': 'ts-jest', + '^.+\\.(ts|tsx)$': [ + 'ts-jest', + { + tsconfig: './test/tsconfig.json', + }, + ], }, - moduleNameMapper: { - '^(\\.{1,2}/.*)\\.js$': '$1', - }, verbose: false, collectCoverage: false, coverageReporters: ['json'], diff --git a/tools/web3-plugin-example/test/config/jest.config.js b/tools/web3-plugin-example/test/config/jest.config.js index eaa5e9049da..7d959c45719 100644 --- a/tools/web3-plugin-example/test/config/jest.config.js +++ b/tools/web3-plugin-example/test/config/jest.config.js @@ -1,14 +1,14 @@ module.exports = { - globals: { - 'ts-jest': { - tsconfig: './test/tsconfig.json', - }, - }, rootDir: '../..', testMatch: ['/test/**/?(*.)+(spec|test).+(ts|tsx|js)'], setupFilesAfterEnv: ['/test/config/setup.js'], transform: { - '^.+\\.(ts|tsx)$': 'ts-jest', + '^.+\\.(ts|tsx)$': [ + 'ts-jest', + { + tsconfig: './test/tsconfig.json', + }, + ], }, verbose: false, collectCoverage: false, From e383ae38c83119a645f0d94a74416d8c60de2d95 Mon Sep 17 00:00:00 2001 From: Junaid <86780488+jdevcs@users.noreply.github.com> Date: Fri, 8 Mar 2024 16:37:40 +0100 Subject: [PATCH 10/19] Release/4.6.0 (#6869) * lerna version bumps * changelog updates * Fix blackbox test (#6873) * Fix blackbox test * revert --------- Co-authored-by: Oleksii Kosynskyi --- CHANGELOG.md | 30 +++++++++++++++++++ packages/web3-eth-ens/CHANGELOG.md | 6 ++-- packages/web3-eth-ens/package.json | 16 +++++----- packages/web3-eth/CHANGELOG.md | 4 ++- packages/web3-eth/package.json | 8 ++--- packages/web3-rpc-methods/CHANGELOG.md | 4 ++- packages/web3-rpc-methods/package.json | 6 ++-- packages/web3-types/CHANGELOG.md | 4 ++- packages/web3-types/package.json | 2 +- packages/web3-utils/CHANGELOG.md | 6 ++-- packages/web3-utils/package.json | 4 +-- packages/web3/CHANGELOG.md | 6 ++-- packages/web3/package.json | 12 ++++---- packages/web3/src/version.ts | 2 +- .../web3/test/cjs_black_box/jest.config.js | 7 +---- .../web3/test/esm_black_box/jest.config.js | 7 +---- 16 files changed, 78 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8cef1e3891..1f0bac6b9c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2353,4 +2353,34 @@ If there are any bugs, improvements, optimizations or any new feature proposal f - Dependencies updated +## [4.6.0] + +### Added + +#### web3 + +- Added EIP-6963 utility function `requestEIP6963Providers` for multi provider discovery + +#### web3-eth + +- Added `eth.getMaxPriorityFeePerGas` method (#6748) + +#### web3-eth-ens + +- Added function `setAddress` in ENS and Resolver classes (#5956) + +#### web3-rpc-methods + +- Added `getMaxPriorityFeePerGas` method (#6748) + +#### web3-types + +- Type `FeeData` to be filled by `await web3.eth.calculateFeeData()` to be used with EIP-1559 transactions (#6795) + +### Fixed + +#### web3-utils + +- replaced our eventEmitter to EventEmitter3 to support react native builds (#6253) + ## [Unreleased] \ No newline at end of file diff --git a/packages/web3-eth-ens/CHANGELOG.md b/packages/web3-eth-ens/CHANGELOG.md index 54253823dfc..2bf6468be08 100644 --- a/packages/web3-eth-ens/CHANGELOG.md +++ b/packages/web3-eth-ens/CHANGELOG.md @@ -141,8 +141,10 @@ Documentation: - Dependencies updated -## [Unreleased] +## [4.1.0] ### Added -- Added function `setAddress` in ENS and Resolver classes (#5956) \ No newline at end of file +- Added function `setAddress` in ENS and Resolver classes (#5956) + +## [Unreleased] \ No newline at end of file diff --git a/packages/web3-eth-ens/package.json b/packages/web3-eth-ens/package.json index 3c82d10b2b1..171dd2ab380 100644 --- a/packages/web3-eth-ens/package.json +++ b/packages/web3-eth-ens/package.json @@ -1,6 +1,6 @@ { "name": "web3-eth-ens", - "version": "4.0.8", + "version": "4.1.0", "description": "This package has ENS functions for interacting with Ethereum Name Service.", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -59,13 +59,13 @@ }, "dependencies": { "@adraffy/ens-normalize": "^1.8.8", - "web3-core": "^4.3.0", - "web3-errors": "^1.1.3", - "web3-eth": "^4.3.1", - "web3-eth-contract": "^4.1.2", + "web3-core": "^4.3.2", + "web3-errors": "^1.1.4", + "web3-eth": "^4.5.0", + "web3-eth-contract": "^4.2.0", "web3-net": "^4.0.7", - "web3-types": "^1.3.0", - "web3-utils": "^4.0.7", - "web3-validator": "^2.0.3" + "web3-types": "^1.5.0", + "web3-utils": "^4.2.1", + "web3-validator": "^2.0.4" } } diff --git a/packages/web3-eth/CHANGELOG.md b/packages/web3-eth/CHANGELOG.md index f1ab3d6b532..90ad4805704 100644 --- a/packages/web3-eth/CHANGELOG.md +++ b/packages/web3-eth/CHANGELOG.md @@ -219,8 +219,10 @@ Documentation: - Catch `TransactionPollingTimeoutError` was added to send transaction events (#6623) -## [Unreleased] +## [4.5.0] ### Added - Added `eth.getMaxPriorityFeePerGas` method (#6748) + +## [Unreleased] \ No newline at end of file diff --git a/packages/web3-eth/package.json b/packages/web3-eth/package.json index b4d0b8fdf15..7b53c9df5ab 100644 --- a/packages/web3-eth/package.json +++ b/packages/web3-eth/package.json @@ -1,6 +1,6 @@ { "name": "web3-eth", - "version": "4.4.0", + "version": "4.5.0", "description": "Web3 module to interact with the Ethereum blockchain and smart contracts.", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -69,9 +69,9 @@ "web3-eth-accounts": "^4.1.1", "web3-net": "^4.0.7", "web3-providers-ws": "^4.0.7", - "web3-rpc-methods": "^1.1.4", - "web3-types": "^1.3.1", - "web3-utils": "^4.1.1", + "web3-rpc-methods": "^1.2.0", + "web3-types": "^1.5.0", + "web3-utils": "^4.2.1", "web3-validator": "^2.0.4" } } diff --git a/packages/web3-rpc-methods/CHANGELOG.md b/packages/web3-rpc-methods/CHANGELOG.md index 9b2c602e962..c2385435cac 100644 --- a/packages/web3-rpc-methods/CHANGELOG.md +++ b/packages/web3-rpc-methods/CHANGELOG.md @@ -132,8 +132,10 @@ Documentation: - Fix web3-types import #6590 (#6589) -## [Unreleased] +## [1.2.0] ### Added - Added `getMaxPriorityFeePerGas` method (#6748) + +## [Unreleased] \ No newline at end of file diff --git a/packages/web3-rpc-methods/package.json b/packages/web3-rpc-methods/package.json index adc64dd839d..9a6605d1939 100644 --- a/packages/web3-rpc-methods/package.json +++ b/packages/web3-rpc-methods/package.json @@ -1,6 +1,6 @@ { "name": "web3-rpc-methods", - "version": "1.1.4", + "version": "1.2.0", "description": "Ethereum RPC methods for Web3 4.x.x", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -57,7 +57,7 @@ }, "dependencies": { "web3-core": "^4.3.2", - "web3-types": "^1.3.1", - "web3-validator": "^2.0.3" + "web3-types": "^1.5.0", + "web3-validator": "^2.0.4" } } diff --git a/packages/web3-types/CHANGELOG.md b/packages/web3-types/CHANGELOG.md index 7527a33da64..05c944dc38c 100644 --- a/packages/web3-types/CHANGELOG.md +++ b/packages/web3-types/CHANGELOG.md @@ -183,8 +183,10 @@ Documentation: - Adds missing exported type `AbiItem` from 1.x to v4 for compatabiltiy (#6678) -## [Unreleased] +## [1.5.0] ### Added - Type `FeeData` to be filled by `await web3.eth.calculateFeeData()` to be used with EIP-1559 transactions (#6795) + +## [Unreleased] \ No newline at end of file diff --git a/packages/web3-types/package.json b/packages/web3-types/package.json index 1f5067ecf87..a254eb19f19 100644 --- a/packages/web3-types/package.json +++ b/packages/web3-types/package.json @@ -1,6 +1,6 @@ { "name": "web3-types", - "version": "1.4.0", + "version": "1.5.0", "description": "Provide the common data structures and interfaces for web3 modules.", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", diff --git a/packages/web3-utils/CHANGELOG.md b/packages/web3-utils/CHANGELOG.md index 3bb09ffe5e0..35301f35341 100644 --- a/packages/web3-utils/CHANGELOG.md +++ b/packages/web3-utils/CHANGELOG.md @@ -193,8 +193,10 @@ Documentation: - Adds missing exported type `AbiItem` from 1.x to v4 for compatabiltiy (#6678) -## [Unreleased] +## [4.2.1] ### Fixed -- replaced our eventEmitter to EventEmitter3 to support react native builds (#6253) \ No newline at end of file +- replaced our eventEmitter to EventEmitter3 to support react native builds (#6253) + +## [Unreleased] \ No newline at end of file diff --git a/packages/web3-utils/package.json b/packages/web3-utils/package.json index 299fb8333c7..f0e0ee07628 100644 --- a/packages/web3-utils/package.json +++ b/packages/web3-utils/package.json @@ -1,7 +1,7 @@ { "name": "web3-utils", "sideEffects": false, - "version": "4.2.0", + "version": "4.2.1", "description": "Collection of utility functions used in web3.js.", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -66,7 +66,7 @@ "ethereum-cryptography": "^2.0.0", "eventemitter3": "^5.0.1", "web3-errors": "^1.1.4", - "web3-types": "^1.4.0", + "web3-types": "^1.5.0", "web3-validator": "^2.0.4" } } diff --git a/packages/web3/CHANGELOG.md b/packages/web3/CHANGELOG.md index e87edb57ec4..7557dcb0ff0 100644 --- a/packages/web3/CHANGELOG.md +++ b/packages/web3/CHANGELOG.md @@ -191,8 +191,10 @@ Documentation: - Dependencies updated ( details are in root changelog ) -## [Unreleased] +## [4.6.0] ### Added -- Added EIP-6963 utility function `requestEIP6963Providers` for multi provider discovery \ No newline at end of file +- Added EIP-6963 utility function `requestEIP6963Providers` for multi provider discovery ( other details are in root changelog ) + +## [Unreleased] \ No newline at end of file diff --git a/packages/web3/package.json b/packages/web3/package.json index c72180f8eb2..6ad2790932f 100644 --- a/packages/web3/package.json +++ b/packages/web3/package.json @@ -1,6 +1,6 @@ { "name": "web3", - "version": "4.5.0", + "version": "4.6.0", "description": "Ethereum JavaScript API", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -88,19 +88,19 @@ "dependencies": { "web3-core": "^4.3.2", "web3-errors": "^1.1.4", - "web3-eth": "^4.4.0", + "web3-eth": "^4.5.0", "web3-eth-abi": "^4.2.0", "web3-eth-accounts": "^4.1.1", "web3-eth-contract": "^4.2.0", - "web3-eth-ens": "^4.0.8", + "web3-eth-ens": "^4.1.0", "web3-eth-iban": "^4.0.7", "web3-eth-personal": "^4.0.8", "web3-net": "^4.0.7", "web3-providers-http": "^4.1.0", "web3-providers-ws": "^4.0.7", - "web3-rpc-methods": "^1.1.4", - "web3-types": "^1.4.0", - "web3-utils": "^4.2.0", + "web3-rpc-methods": "^1.2.0", + "web3-types": "^1.5.0", + "web3-utils": "^4.2.1", "web3-validator": "^2.0.4" } } diff --git a/packages/web3/src/version.ts b/packages/web3/src/version.ts index 21594d54456..eadb7198174 100644 --- a/packages/web3/src/version.ts +++ b/packages/web3/src/version.ts @@ -1 +1 @@ -/* eslint-disable header/header */ export const Web3PkgInfo = { version: '4.5.0' }; +/* eslint-disable header/header */ export const Web3PkgInfo = { version: '4.6.0' }; diff --git a/packages/web3/test/cjs_black_box/jest.config.js b/packages/web3/test/cjs_black_box/jest.config.js index ce489d3d015..af2cbbc57cf 100644 --- a/packages/web3/test/cjs_black_box/jest.config.js +++ b/packages/web3/test/cjs_black_box/jest.config.js @@ -1,15 +1,10 @@ /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ module.exports = { - globals: { - 'ts-jest': { - tsconfig: '../config/tsconfig.cjs.json', - }, - }, transform: { '^.+\\.(ts|tsx)$': [ 'ts-jest', { - tsconfig: './test/tsconfig.json', + tsconfig: '../config/tsconfig.cjs.json', }, ], }, diff --git a/packages/web3/test/esm_black_box/jest.config.js b/packages/web3/test/esm_black_box/jest.config.js index 678e0222c26..55447c6ee20 100644 --- a/packages/web3/test/esm_black_box/jest.config.js +++ b/packages/web3/test/esm_black_box/jest.config.js @@ -1,15 +1,10 @@ /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ export default { - globals: { - 'ts-jest': { - tsconfig: '../config/tsconfig.esm.json', - }, - }, transform: { '^.+\\.(ts|tsx)$': [ 'ts-jest', { - tsconfig: './test/tsconfig.json', + tsconfig: '../config/tsconfig.esm.json', }, ], }, From d2543161b96dcd08038d66f86e8ad0057dcaba7e Mon Sep 17 00:00:00 2001 From: pengqiseven <134899215+pengqiseven@users.noreply.github.com> Date: Tue, 12 Mar 2024 03:10:59 +0800 Subject: [PATCH 11/19] Fix some comments (#6878) Signed-off-by: pengqiseven Co-authored-by: pengqiseven --- .../guides/web3_upgrade_guide/1.x/contracts_migration_guide.md | 2 +- packages/web3-eth/test/e2e/e2e_utils.ts | 2 +- packages/web3-types/src/eth_types.ts | 2 +- packages/web3/test/e2e/e2e_utils.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/docs/guides/web3_upgrade_guide/1.x/contracts_migration_guide.md b/docs/docs/guides/web3_upgrade_guide/1.x/contracts_migration_guide.md index c78af41704d..7df5a06d9bd 100644 --- a/docs/docs/guides/web3_upgrade_guide/1.x/contracts_migration_guide.md +++ b/docs/docs/guides/web3_upgrade_guide/1.x/contracts_migration_guide.md @@ -9,7 +9,7 @@ sidebar_label: web3.eth.Contract ### Receipt Status -The `receipt.status` will now be be an `unsigned integer` instead of `boolean` value to comply with the specification. +The `receipt.status` will now be an `unsigned integer` instead of `boolean` value to comply with the specification. ```ts // in 1.x diff --git a/packages/web3-eth/test/e2e/e2e_utils.ts b/packages/web3-eth/test/e2e/e2e_utils.ts index 80fd40196c2..ff9717a9370 100644 --- a/packages/web3-eth/test/e2e/e2e_utils.ts +++ b/packages/web3-eth/test/e2e/e2e_utils.ts @@ -16,7 +16,7 @@ along with web3.js. If not, see . */ /** - * @NOTE This Util method is kept seperate from shared system_test_utils.ts file because + * @NOTE This Util method is kept separate from shared system_test_utils.ts file because * of it's import of .secrets.json. For this method to exist in shared system_test_utils.ts * file, the import path would be ../.secrets.json which doesn't resolve when the file is * copied over to each package's test directory. Because web3 package is the only package diff --git a/packages/web3-types/src/eth_types.ts b/packages/web3-types/src/eth_types.ts index 66ede2c7008..cae32515332 100644 --- a/packages/web3-types/src/eth_types.ts +++ b/packages/web3-types/src/eth_types.ts @@ -548,7 +548,7 @@ export interface FeeData { readonly gasPrice?: Numbers; /** - * The baseFeePerGas returned from the the last available block. + * The baseFeePerGas returned from the last available block. * * If EIP-1559 is not supported, this will be `undefined` * diff --git a/packages/web3/test/e2e/e2e_utils.ts b/packages/web3/test/e2e/e2e_utils.ts index cf7db8b66ec..91165ddd899 100644 --- a/packages/web3/test/e2e/e2e_utils.ts +++ b/packages/web3/test/e2e/e2e_utils.ts @@ -16,7 +16,7 @@ along with web3.js. If not, see . */ /** - * @NOTE This Util method is kept seperate from shared system_test_utils.ts file because + * @NOTE This Util method is kept separate from shared system_test_utils.ts file because * of it's import of .secrets.json. For this method to exist in shared system_test_utils.ts * file, the import path would be ../.secrets.json which doesn't resolve when the file is * copied over to each package's test directory. Because web3 package is the only package From 6187f308480f8c6b526995b3e89aa0fc73a017d3 Mon Sep 17 00:00:00 2001 From: guangwu Date: Tue, 12 Mar 2024 18:09:23 +0800 Subject: [PATCH 12/19] fix: typo (#6889) --- .../stress/long_ws_tests/nodejs_test/long_connection_ws.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web3/test/stress/long_ws_tests/nodejs_test/long_connection_ws.js b/packages/web3/test/stress/long_ws_tests/nodejs_test/long_connection_ws.js index 9abc2a4e9df..6d7a60a04cb 100644 --- a/packages/web3/test/stress/long_ws_tests/nodejs_test/long_connection_ws.js +++ b/packages/web3/test/stress/long_ws_tests/nodejs_test/long_connection_ws.js @@ -60,11 +60,11 @@ const main = async () => { end = new Date(); console.log("websocket test successful") } catch (e) { - console.warn("error occured during ws test, on attempt: ", attempt, "program ran for: ", attempt ,"minutes with error: ", e) + console.warn("error occurred during ws test, on attempt: ", attempt, "program ran for: ", attempt ,"minutes with error: ", e) } console.log("start", start) console.log("end", end) process.exit(); } -main(); \ No newline at end of file +main(); From a1f9dc4a793d9e151cb63f0229bd9c32f772a58a Mon Sep 17 00:00:00 2001 From: edison Date: Tue, 12 Mar 2024 18:12:18 +0800 Subject: [PATCH 13/19] fix: timout => timeout (#6888) --- .../test/integration/contract_defaults_extra.test.ts | 2 +- packages/web3-utils/src/chunk_response_parser.ts | 6 +++--- packages/web3-utils/test/unit/chunk_response_parser.test.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/web3-eth-contract/test/integration/contract_defaults_extra.test.ts b/packages/web3-eth-contract/test/integration/contract_defaults_extra.test.ts index b6d47be1442..206b10ee709 100644 --- a/packages/web3-eth-contract/test/integration/contract_defaults_extra.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_defaults_extra.test.ts @@ -236,7 +236,7 @@ describe('contract defaults (extra)', () => { }); describeIf(isWs)('blockHeaderTimeout', () => { - it('should use "blockHeaderTimout" on "instance" level', async () => { + it('should use "blockHeaderTimeout" on "instance" level', async () => { contract = new Contract(GreeterAbi, undefined, { provider: getSystemTestProvider(), }); diff --git a/packages/web3-utils/src/chunk_response_parser.ts b/packages/web3-utils/src/chunk_response_parser.ts index 68e708e58b5..76bd00504fe 100644 --- a/packages/web3-utils/src/chunk_response_parser.ts +++ b/packages/web3-utils/src/chunk_response_parser.ts @@ -25,12 +25,12 @@ export class ChunkResponseParser { private _clearQueues: (() => void) | undefined; private readonly eventEmitter: EventEmitter; private readonly autoReconnect: boolean; - private readonly chunkTimout: number; + private readonly chunkTimeout: number; public constructor(eventEmitter: EventEmitter, autoReconnect: boolean) { this.eventEmitter = eventEmitter; this.autoReconnect = autoReconnect; - this.chunkTimout = 1000 * 15; + this.chunkTimeout = 1000 * 15; } private clearQueues(): void { if (typeof this._clearQueues === 'function') { @@ -83,7 +83,7 @@ export class ChunkResponseParser { error: { code: 2, message: 'Chunk timeout' }, }), ); - }, this.chunkTimout); + }, this.chunkTimeout); return; } diff --git a/packages/web3-utils/test/unit/chunk_response_parser.test.ts b/packages/web3-utils/test/unit/chunk_response_parser.test.ts index 27241b4243b..22100a3e6a8 100644 --- a/packages/web3-utils/test/unit/chunk_response_parser.test.ts +++ b/packages/web3-utils/test/unit/chunk_response_parser.test.ts @@ -55,7 +55,7 @@ describe('chunk_response_parser', () => { it('lastChunkTimeout error', async () => { // @ts-expect-error set private property - parser.chunkTimout = 10; + parser.chunkTimeout = 10; parser.parseResponse( '{"jsonrpc":"2.0","id":"96aa3f13-077c-4c82-a64a-64b8626f8192","result":"0x141414141', ); From 9657b865ee3dbbd9cf041361084899bfc16f805d Mon Sep 17 00:00:00 2001 From: Cong Date: Tue, 12 Mar 2024 18:13:56 +0800 Subject: [PATCH 14/19] fix(docs): json syntax error (#6886) --- docs/docs/guides/glossary/index.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/docs/guides/glossary/index.md b/docs/docs/guides/glossary/index.md index 6b11ab0cd5e..e8962c28966 100644 --- a/docs/docs/guides/glossary/index.md +++ b/docs/docs/guides/glossary/index.md @@ -83,24 +83,24 @@ contract Test { ```json title='Resulting JSON ABI' [ { - "type": "constructor" + "type": "constructor", "stateMutability": "nonpayable", "inputs": [{"internalType":"uint256","name":"testInt","type":"uint256"}], }, { - "type": "event" + "type": "event", "name": "Event", "inputs": [{"indexed":true,"internalType":"uint256","name":"b","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"c","type":"bytes32"}], "anonymous": false, }, { - "type": "event" + "type": "event", "name": "Event2", "inputs": [{"indexed":true,"internalType":"uint256","name":"b","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"c","type":"bytes32"}], "anonymous": false, }, { - "type": "function" + "type": "function", "name": "foo", "stateMutability": "nonpayable", "inputs": [{"internalType":"uint256","name":"b","type":"uint256"},{"internalType":"bytes32","name":"c","type":"bytes32"}], From 43e70c179e0047be13d7b2142d4e11e30a374780 Mon Sep 17 00:00:00 2001 From: edison Date: Tue, 12 Mar 2024 19:44:27 +0800 Subject: [PATCH 15/19] chore: fix typos (#6885) * chore: fix typos * chore: fix typos --- CHANGELOG.md | 20 +++++++++---------- RELEASE.md | 4 ++-- docs/docs/guides/hardhat_tutorial/index.md | 4 ++-- .../smart_contracts/infer_contract_types.md | 4 ++-- .../web3-eth-accounts/src/common/common.ts | 2 +- packages/web3-eth-contract/README.md | 4 ++-- packages/web3-eth-contract/src/contract.ts | 2 +- packages/web3-validator/CHANGELOG.md | 2 +- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f0bac6b9c1..5049f52f06d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -179,13 +179,13 @@ Released with 1.0.0-beta.37 code base. - Introduce review and release guidelines. (#3460) - Add EIP-1193 compatible provider to `AbstractProvider` interface. (#3499) -- Add Typescript definitions for contract `methods` and `call`. (#3454) +- Add TypeScript definitions for contract `methods` and `call`. (#3454) - Update AbstractProvider and contract.methods TS definitions (#3521) - Add support for ENS contenthash methods. (#3392, #2782) ### Changed -- Change CI provider from Travis to Github Actions. (#3468) +- Change CI provider from Travis to GitHub Actions. (#3468) - Update `web3-eth-abi` ABICoder dependency. (#3490) - Update AbiCoder param formatting (#3522) - Improve code clarity of HttpProvider keepAlive option setting. (#3463) @@ -354,7 +354,7 @@ Released with 1.0.0-beta.37 code base. ### Added -- Github action for running tests for `web3-eth2-core` and `web3-eth2-beaconchain` packages (#3892) +- GitHub action for running tests for `web3-eth2-core` and `web3-eth2-beaconchain` packages (#3892) - Added description to documentation on how to connect using a remote node provider (#3884) - Added Security risk warning to docs for `web3.utils.soliditySha3` (#3908) - `.nvmrc` file using Node.js version `v.14.15.1` (#3817) @@ -366,7 +366,7 @@ Released with 1.0.0-beta.37 code base. - Renamed the `tsc` script in all packages to `compile`; updates the corresponding `lerna run` usage in the main `package.json` (#3894) - moved deprecation warnings to postinstall scripts (#3917) - Upgrade `@chainsafe/geth-dev-assistant` from `0.1.5` to `0.1.9` (#3950) -- Replaced hardcoded infura link with Github Secret for some tests (#3943) +- Replaced hardcoded infura link with GitHub Secret for some tests (#3943) - Bump `elliptic` from `6.5.3` to `6.5.4` for `web3-eth-accounts` (#3941) - Bump `elliptic` from `6.5.3` to `6.5.4` for `web3-bzz` (#3940) - Bump `elliptic` from `6.5.3` to `6.5.4` for `web3-core-requestmanager` (#3945) @@ -466,13 +466,13 @@ Released with 1.0.0-beta.37 code base. - Not considering `tx.chainId` if `tx.common.customChain.chainId` is provided for `web3.eth.accounts.signTransaction` function (#4293) - Added missing PromiEvent handler types (#4194) -- Updated README to include Webpack 5 angular support instructions (#4174) +- Updated README to include webpack 5 angular support instructions (#4174) - Updated the documentation for the `Web3.utils`, removed context for `_` (underscore lib) (#4403) - Emit subscription id with connect event when creating a subscription (#4300) - Introduced new configuration "blockHeaderTimeout" for waiting of block headers for transaction receipt (#3891) - Format `block.baseFeePerGas` to number (#4330) - Correct `web3-eth-personal.sendTransaction` example in documentation (#4409) -- Updated README to include Webpack 5 angular support instructions (#4174) +- Updated README to include webpack 5 angular support instructions (#4174) ### Fixed @@ -509,7 +509,7 @@ Released with 1.0.0-beta.37 code base. - Fix typos in web3-utils.rst (#4662) - Added effectiveGasPrice to TransactionReceipt (#4692) - Correction in documentation for `web3.eth.accounts.signTransaction` (#4576) -- Updated README to include Webpack 5 create-react-app support instructions (#4173) +- Updated README to include webpack 5 create-react-app support instructions (#4173) - Update the documentation for `methods.myMethod.estimateGas` (#4702) - Fix typos in REVIEW.md and TESTING.md (#4691) - Fix encoding for "0x" string values (#4512) @@ -562,7 +562,7 @@ Released with 1.0.0-beta.37 code base. - Replace deprecated String.prototype.substr() (#4855) - Exporting AbiCoder as coder (#4937) -- Github build workflow updated min build for node.js 12 and tests for 12, 14 and 16 (#5014) +- GitHub build workflow updated min build for node.js 12 and tests for 12, 14 and 16 (#5014) - Updated libraries using BN and the BN library (#5072) ### Added @@ -950,7 +950,7 @@ should use 4.0.1-alpha.0 for testing. #### web3-validator -- Fix issue when importing `web3-validator` package within browser environments (Webpack minified filename changed from `index.min.js` to `web3-validator.min.js`) (#5710) +- Fix issue when importing `web3-validator` package within browser environments (webpack minified filename changed from `index.min.js` to `web3-validator.min.js`) (#5710) - Fix build error '"type"' does not satisfy the constraint (#5712) #### web3-eth-abi @@ -2260,7 +2260,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f #### web3-core -- Web3config `contractDataInputFill` has been defaulted to `data`, istead of `input`. (#6622) +- Web3config `contractDataInputFill` has been defaulted to `data`, instead of `input`. (#6622) #### web3-eth-contracts diff --git a/RELEASE.md b/RELEASE.md index b85c0030d26..5e2182e995f 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -22,7 +22,7 @@ Further details about versioning can be found in the [semver 2.0.0 specification ### Running E2E Tests -`E2E Network Tests` will be triggered to run via a Github workflow when a PR is open for a branch prefixed with `release/` and is being merged into `4.x` branch. These tests depend on a couple of ENVs to be set that are configurable in Github's Action Secrets when running these tests in CI. The following required secrets are: +`E2E Network Tests` will be triggered to run via a GitHub workflow when a PR is open for a branch prefixed with `release/` and is being merged into `4.x` branch. These tests depend on a couple of ENVs to be set that are configurable in GitHub's Action Secrets when running these tests in CI. The following required secrets are: - `E2E_TESTS_ALLOWED_SEND_TRANSACTION`: If set to `false` this will keep the Sepolia tests that spend ETH from running, setting to anything else will cause them to run - `TEST_ACCOUNT_PRIVATE_KEY`: The private key of the Sepolia account to use when submitting transactions @@ -50,7 +50,7 @@ Further details about versioning can be found in the [semver 2.0.0 specification 8. `git tag bumped-version`: Tag the commit with bumped version having prefix `v` , e.g. `git tag v4.0.1-alpha.0` 9. `git push origin release/bumped-version`: Push release branch to `origin` 10. `git push origin --tags`: Push release tag created in `Step 8` to `origin` -11. Create a draft release on Github similar to [this](https://github.com/web3/web3.js/releases/tag/v4.2.0) +11. Create a draft release on GitHub similar to [this](https://github.com/web3/web3.js/releases/tag/v4.2.0) - Select recently pushed tag in `choose a tag` drop down diff --git a/docs/docs/guides/hardhat_tutorial/index.md b/docs/docs/guides/hardhat_tutorial/index.md index 3b6166db2b3..9109004467c 100644 --- a/docs/docs/guides/hardhat_tutorial/index.md +++ b/docs/docs/guides/hardhat_tutorial/index.md @@ -11,7 +11,7 @@ Following the recent compatibility update of Hardhat plugin [hardhat-web3-v4](ht This tutorial will guide you through using Web3js as a plugin to interact with the Blockchain. ## Pre-requisite -This tutorial assumes you have previous knowledge of writing Smart contracts, and are convenient working with Javascript/Typescript. You should have [NodeJS](https://nodejs.org/en) version greater than v16 installed. +This tutorial assumes you have previous knowledge of writing Smart contracts, and are convenient working with JavaScript/TypeScript. You should have [NodeJS](https://nodejs.org/en) version greater than v16 installed. :::note To install dependencies, we will use `NPM`. @@ -49,7 +49,7 @@ npx hardhat init ### Install required dependencies (including `hardhat-web3-v4`) -Select `Typescript` and `Yes` for the rest of the options. +Select `TypeScript` and `Yes` for the rest of the options. You will be prompted to install the required dependencies. Reply `yes` to complete the installation. To include the `Hardhat-web3-v4` plugin, we will install it via `npm`. diff --git a/docs/docs/guides/smart_contracts/infer_contract_types.md b/docs/docs/guides/smart_contracts/infer_contract_types.md index e070f19b1b8..04ee5e49201 100644 --- a/docs/docs/guides/smart_contracts/infer_contract_types.md +++ b/docs/docs/guides/smart_contracts/infer_contract_types.md @@ -14,7 +14,7 @@ Web3.js is a popular library used for interacting with EVM blockchains. One of i Before we dive into the problem, let's take a quick look at the problem. Web3.js provides a simple and convenient way to interact with Solidity contracts. To use Web3.js to interact with a Solidity contract, you need to know the contract's address and the ABI (Application Binary Interface) of the contract. The ABI is JSON data that contains the definition of the functions in the contract, including their, name, input parameters and return values. -Web3.js uses ABI type to dynamically load available methods and events but Typescript currently [doesn't support loading JSON as const](https://github.com/microsoft/TypeScript/issues/32063). If you go to the [Playground Link](https://www.typescriptlang.org/play?#code/MYewdgzgLgBAhgIwJYwLwwNoCga5gbxz1wCIkwAHAVyghIC5MjjdCWWywoBTAJzDgAbACoBPCtwYwS0XuQDmJADTN20gQFtJjEpu4B9ZavYko47dNkKSxvAF8VagreKce-IWIlSZUOWEVHJ3U4LR8IUQ0EEEFDIKdTc3C-axcYO1sAXXi8XzgeAFkaRCRBJDMfMHAKOFFEQUkc0jNvHVBIPypgKBBeG2IHVTYOOCqwSJAqOkYAMyEIbibpcmpaKWwnYYTyABNuAA9uHalOxbTScncBESSdOB2d3m4IOiXXPR8QAHcwPiNg6QtCwke6PZ50NKDTbnZZgPaHY6MU5vXKXPjXLzA0FPF7-YK6ULAiASOF-FHNW7SbHg-pqKFqLZqTjwo5SOaCBbk2FXTyUkhUS4AJgArAA2PEJD46ABuQiojRhiVa0gFXBF4shWSWBLCOgAghQKLwQLLBBLckCfNxpdwuLTcPTWLYQWMJlM2fMziYVjRpkxoQDmQdWUjePKuW50bzlSCHjjXoqpdIZsaNOaTJa7nGaZCUYzvaSEScw178WiPDcY9TcRGk6YQOmOJmqdncbm0vmOLtg4iYOzOYryxi+aqoOrG+9CT5TfKJxaR0KxfaWBl2NlnXXhLxRhAZmTnc2SNbbVBl47nAXVn6NgzB1wo5Wsa2E4G699fn0I4fqxCnOfiJ2rhDtGT5gjWiZTjoxK2nsn6Kt+z7LgMWobpBVKCII3yjMAComJMUBXusHZ3jyj4+KO461mhJBzhSMYUUumprtq0D5NwRRQCUZQVDKSDcF8jZKsCMxUGA3RIOAZ45J2nCEYwN7sIBqL3hWmI+D+tEhLqlgkrBmlCepiHtgGZYqcO9GLuKVHaSCGiTHaX4LmqjF-ihJh1nAhrGjagn4XJ-q3oGwFkTo0QxPpdb6YeYVmkxLDriYrGFMUyDcaIlTVLU9S4U2fIiWJUASWAUlDM6PprPJxFBWZIGGWBL74h5wCgKJp6OVWRmucxqE2QgQjYdwADyMy+TQ-kKSwSkXDVIUqpZEXUVFTlji5dJuRwSXsSlpTlOlvH8YJh75eJkmqOeMnldeCUcHWezAEgGjzKNBG+kRJnbDNak6KOAAcC02UtFlcH9cXENdribRxXG7dOfECdqR2iSdxVndJZWUK9lXvUywVfS29X-USun7oGCEE8ZgWmaReP8vN1lElQCB+HA3RHAAanKOUJIeDEal18Xard3DAE8cALHqGFYWJXO5H5mMBYpJEPjTMWEz4gPAqroN4ODuSQ9taUZZQWUIA0h15UjhWnQMaOXvLE0AUrql8hp9PhMTcGky7nV0nmTvmcCvNq1mew7Bzgizu1gfzdruC66QdbkCL3Bi9wEuYV8A3PeNVVU8rfKq27Ogaz4Wv82DLGcclnGpTDOhjDUdSmzLdHCZbRUlY7dsVZg8dacCHzanLPcO3gU3cvnMZWAEwfSCXUEpDPscwH3eTV9DPHSNKcPmzGx1WyjNuld3V2C9RERROFQ9jfbucfdTfLT4EEEA1HyT+Ioy+r-rNc7ZvJDbwOgjC2BUO6o2Pl2DGI9V51h6JxQQABlKghpBDpWvi9Eed8cafWWpRF+wJ55zWcnzNa3VEpVy2r-Q2+14YHhAcjTuY90Y52xgWB+HUCZF0BA2N+Id4xIXsH7aq7Do7ENnrZeybV4K4NWuwVcAserAmZpAPcnsODD2vFgthk9NYgCvvg9WvDpBl1IQo8hbEoa13-g3E2ZtgF73btbQRECgJQM0awyBIi6r8K4SQFMIA0xGNjOTP8Qi87Ow4T4gxOgeiEOCfwimithE6PInTaJVI7KtTiUHL+Z8bLKN3HwAAYqmbOt8PGuK8aFPRZpfFxJMXI9aEMKGWL-ntdQmUm52LoQ40BTiHREEyPACAMB2jQAANxAA) and choose '.d.ts' you can check type difference with and without `as const`. +Web3.js uses ABI type to dynamically load available methods and events but TypeScript currently [doesn't support loading JSON as const](https://github.com/microsoft/TypeScript/issues/32063). If you go to the [Playground Link](https://www.typescriptlang.org/play?#code/MYewdgzgLgBAhgIwJYwLwwNoCga5gbxz1wCIkwAHAVyghIC5MjjdCWWywoBTAJzDgAbACoBPCtwYwS0XuQDmJADTN20gQFtJjEpu4B9ZavYko47dNkKSxvAF8VagreKce-IWIlSZUOWEVHJ3U4LR8IUQ0EEEFDIKdTc3C-axcYO1sAXXi8XzgeAFkaRCRBJDMfMHAKOFFEQUkc0jNvHVBIPypgKBBeG2IHVTYOOCqwSJAqOkYAMyEIbibpcmpaKWwnYYTyABNuAA9uHalOxbTScncBESSdOB2d3m4IOiXXPR8QAHcwPiNg6QtCwke6PZ50NKDTbnZZgPaHY6MU5vXKXPjXLzA0FPF7-YK6ULAiASOF-FHNW7SbHg-pqKFqLZqTjwo5SOaCBbk2FXTyUkhUS4AJgArAA2PEJD46ABuQiojRhiVa0gFXBF4shWSWBLCOgAghQKLwQLLBBLckCfNxpdwuLTcPTWLYQWMJlM2fMziYVjRpkxoQDmQdWUjePKuW50bzlSCHjjXoqpdIZsaNOaTJa7nGaZCUYzvaSEScw178WiPDcY9TcRGk6YQOmOJmqdncbm0vmOLtg4iYOzOYryxi+aqoOrG+9CT5TfKJxaR0KxfaWBl2NlnXXhLxRhAZmTnc2SNbbVBl47nAXVn6NgzB1wo5Wsa2E4G699fn0I4fqxCnOfiJ2rhDtGT5gjWiZTjoxK2nsn6Kt+z7LgMWobpBVKCII3yjMAComJMUBXusHZ3jyj4+KO461mhJBzhSMYUUumprtq0D5NwRRQCUZQVDKSDcF8jZKsCMxUGA3RIOAZ45J2nCEYwN7sIBqL3hWmI+D+tEhLqlgkrBmlCepiHtgGZYqcO9GLuKVHaSCGiTHaX4LmqjF-ihJh1nAhrGjagn4XJ-q3oGwFkTo0QxPpdb6YeYVmkxLDriYrGFMUyDcaIlTVLU9S4U2fIiWJUASWAUlDM6PprPJxFBWZIGGWBL74h5wCgKJp6OVWRmucxqE2QgQjYdwADyMy+TQ-kKSwSkXDVIUqpZEXUVFTlji5dJuRwSXsSlpTlOlvH8YJh75eJkmqOeMnldeCUcHWezAEgGjzKNBG+kRJnbDNak6KOAAcC02UtFlcH9cXENdribRxXG7dOfECdqR2iSdxVndJZWUK9lXvUywVfS29X-USun7oGCEE8ZgWmaReP8vN1lElQCB+HA3RHAAanKOUJIeDEal18Xard3DAE8cALHqGFYWJXO5H5mMBYpJEPjTMWEz4gPAqroN4ODuSQ9taUZZQWUIA0h15UjhWnQMaOXvLE0AUrql8hp9PhMTcGky7nV0nmTvmcCvNq1mew7Bzgizu1gfzdruC66QdbkCL3Bi9wEuYV8A3PeNVVU8rfKq27Ogaz4Wv82DLGcclnGpTDOhjDUdSmzLdHCZbRUlY7dsVZg8dacCHzanLPcO3gU3cvnMZWAEwfSCXUEpDPscwH3eTV9DPHSNKcPmzGx1WyjNuld3V2C9RERROFQ9jfbucfdTfLT4EEEA1HyT+Ioy+r-rNc7ZvJDbwOgjC2BUO6o2Pl2DGI9V51h6JxQQABlKghpBDpWvi9Eed8cafWWpRF+wJ55zWcnzNa3VEpVy2r-Q2+14YHhAcjTuY90Y52xgWB+HUCZF0BA2N+Id4xIXsH7aq7Do7ENnrZeybV4K4NWuwVcAserAmZpAPcnsODD2vFgthk9NYgCvvg9WvDpBl1IQo8hbEoa13-g3E2ZtgF73btbQRECgJQM0awyBIi6r8K4SQFMIA0xGNjOTP8Qi87Ow4T4gxOgeiEOCfwimithE6PInTaJVI7KtTiUHL+Z8bLKN3HwAAYqmbOt8PGuK8aFPRZpfFxJMXI9aEMKGWL-ntdQmUm52LoQ40BTiHREEyPACAMB2jQAANxAA) and choose '.d.ts' you can check type difference with and without `as const`. ```typescript import { Contract, Web3 } from 'web3'; @@ -32,7 +32,7 @@ import ERC20 from './node_modules/@openzeppelin/contracts/build/contracts/ERC20. })(); ``` -To work around it you need to copy abi into a Typescript file like this: +To work around it you need to copy abi into a TypeScript file like this: ```typescript import {Contract, Web3} from 'web3'; diff --git a/packages/web3-eth-accounts/src/common/common.ts b/packages/web3-eth-accounts/src/common/common.ts index e941338763a..1569050d2f6 100644 --- a/packages/web3-eth-accounts/src/common/common.ts +++ b/packages/web3-eth-accounts/src/common/common.ts @@ -903,7 +903,7 @@ export class Common extends EventEmitter { // eslint-disable-next-line no-null/no-null hf.block === null || (hf.ttd !== undefined && hf.ttd !== null) ? 0 : hf.block, ); - // Typescript can't seem to follow that the hfBlock is not null at this point + // TypeScript can't seem to follow that the hfBlock is not null at this point // eslint-disable-next-line no-null/no-null return block > hfBlock! && acc === null ? block : acc; // eslint-disable-next-line no-null/no-null diff --git a/packages/web3-eth-contract/README.md b/packages/web3-eth-contract/README.md index 9de73d9556e..d3e752a9b97 100644 --- a/packages/web3-eth-contract/README.md +++ b/packages/web3-eth-contract/README.md @@ -58,9 +58,9 @@ const contract = new Contract(abi); ## Compatibility -We have tested the Typescript interface support for the ABIs compiled with solidity version `v0.4.x` and above. If you face any issue regarding the contract typing, please create an issue to report to us. +We have tested the TypeScript interface support for the ABIs compiled with solidity version `v0.4.x` and above. If you face any issue regarding the contract typing, please create an issue to report to us. -The Typescript support for fixed length array types are supported up 30 elements. See more details [here](https://github.com/ChainSafe/web3.js/blob/nh%2F4562-contract-typing/packages/web3-eth-abi/src/number_map_type.ts#L1). This limitation is only to provide more performant developer experience in IDEs. In future we may come up with a workaround to avoid this limitation. If you have any idea feel free to share. +The TypeScript support for fixed length array types are supported up 30 elements. See more details [here](https://github.com/ChainSafe/web3.js/blob/nh%2F4562-contract-typing/packages/web3-eth-abi/src/number_map_type.ts#L1). This limitation is only to provide more performant developer experience in IDEs. In future we may come up with a workaround to avoid this limitation. If you have any idea feel free to share. ## Package.json Scripts diff --git a/packages/web3-eth-contract/src/contract.ts b/packages/web3-eth-contract/src/contract.ts index 72fe8acb78e..44e8d2f74df 100644 --- a/packages/web3-eth-contract/src/contract.ts +++ b/packages/web3-eth-contract/src/contract.ts @@ -395,7 +395,7 @@ export class Contract * }); * ``` * - * To use the type safe interface for these contracts you have to include the ABI definitions in your Typescript project and then declare these as `const`. + * To use the type safe interface for these contracts you have to include the ABI definitions in your TypeScript project and then declare these as `const`. * * ```ts title="Example" * const myContractAbi = [....] as const; // ABI definitions diff --git a/packages/web3-validator/CHANGELOG.md b/packages/web3-validator/CHANGELOG.md index 46e3a9a15f0..d63f8cfe25c 100644 --- a/packages/web3-validator/CHANGELOG.md +++ b/packages/web3-validator/CHANGELOG.md @@ -55,7 +55,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Fix issue when importing `web3-validator` package within browser environments (Webpack minified filename changed from `index.min.js` to `web3-validator.min.js`) (#5710) +- Fix issue when importing `web3-validator` package within browser environments (webpack minified filename changed from `index.min.js` to `web3-validator.min.js`) (#5710) ## [0.1.1-alpha.4] From 6d0a0ae77f9c95de58e2b0177f604491011e4b23 Mon Sep 17 00:00:00 2001 From: sarthak1dev <149048369+sarthak1dev@users.noreply.github.com> Date: Tue, 12 Mar 2024 18:21:40 +0530 Subject: [PATCH 16/19] interactive code moved to the top (#6867) Co-authored-by: Junaid <86780488+jdevcs@users.noreply.github.com> --- docs/docs/guides/getting_started/getting_started.md | 9 +++++---- docs/docs/guides/wallet/index.md | 9 +++++---- docs/docs/guides/web3_providers_guide/index.md | 9 +++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/docs/docs/guides/getting_started/getting_started.md b/docs/docs/guides/getting_started/getting_started.md index cad3029470d..18b95035957 100644 --- a/docs/docs/guides/getting_started/getting_started.md +++ b/docs/docs/guides/getting_started/getting_started.md @@ -6,6 +6,11 @@ sidebar_label: Quickstart # Quickstart + +## Live code editor + + + ## Installation If NPM is being used as package manager, use the following for installing the web3.js library. @@ -247,7 +252,3 @@ const subscription = uniswapToken.events.Transfer(); subscription.on('data',console.log); // ↳ [{...},{...}, ...] live events will be printed in the console ``` - -## Live code editor - - \ No newline at end of file diff --git a/docs/docs/guides/wallet/index.md b/docs/docs/guides/wallet/index.md index 5da33cdabaf..9dd38e750b5 100644 --- a/docs/docs/guides/wallet/index.md +++ b/docs/docs/guides/wallet/index.md @@ -5,6 +5,11 @@ sidebar_label: 'Mastering Wallets & Accounts' # Wallets and Accounts Overview + +## Live code editor + + + ## Introduction A Web3.js `Wallet` is your main entry point if you want to use a private key directly to do any blockchain operations (transactions), also called `Signer` in other libraries. @@ -220,7 +225,3 @@ The following is a list of `Accounts` [methods](/libdocs/Wallet) in the `web3.et - [sign](/libdocs/Accounts#sign) - [signTransaction](/libdocs/Accounts#signtransaction) - -## Live code editor - - \ No newline at end of file diff --git a/docs/docs/guides/web3_providers_guide/index.md b/docs/docs/guides/web3_providers_guide/index.md index d405a80f065..e3ecc880cb0 100644 --- a/docs/docs/guides/web3_providers_guide/index.md +++ b/docs/docs/guides/web3_providers_guide/index.md @@ -5,6 +5,11 @@ sidebar_label: 'Mastering Providers' # Web3js providers overview + +## Live code editor + + + ## Introduction web3.js providers are objects responsible for enabling connectivity with the Ethereum network in various ways. Connecting your web application to an Ethereum node is necessary for sending transactions, querying data, and interacting with smart contracts on the network. In this guide, we will explore the different types of providers available in web3.js, how to set them up, and how to use them in your code. @@ -375,7 +380,3 @@ provider.on('error', (error) => { ``` - -## Live code editor - - \ No newline at end of file From 383af3940fbc801a958496a49e3c977b007b9e6f Mon Sep 17 00:00:00 2001 From: Joseph Yu <91873054+Jouzep@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:56:09 +0100 Subject: [PATCH 17/19] docs(): How to install Yarn for https://docs.web3js.org/ setup (#6853) --- docs/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/README.md b/docs/README.md index 5cc68943445..e77646ffb81 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,7 +1,11 @@ # Website This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator. +### Requirement +Before getting started, ensure that you have ``Yarn`` installed on your machine. + +[How to install Yarn](https://www.hostinger.com/tutorials/how-to-install-yarn) ### Installation ``` From 16a2c27ba0eeb70d25a6e4e3fdb8bf5c2630753f Mon Sep 17 00:00:00 2001 From: Santiago Trujillo Zuluaga Date: Thu, 14 Mar 2024 14:37:59 +0000 Subject: [PATCH 18/19] added live code editor to mastering smart contracts with contract sample (#6893) --- docs/docs/guides/smart_contracts/index.md | 31 ++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/docs/docs/guides/smart_contracts/index.md b/docs/docs/guides/smart_contracts/index.md index 6e73975a550..4cb6c9eed34 100644 --- a/docs/docs/guides/smart_contracts/index.md +++ b/docs/docs/guides/smart_contracts/index.md @@ -2,15 +2,40 @@ sidebar_position: 1 sidebar_label: 'Mastering Smart Contracts' --- - # Mastering Smart Contracts +## Live code editor + +### Deploy and Interact with smart contracts: + +This contract is deployed on the [mumbai testnet](https://mumbai.polygonscan.com/address/0xB9433C87349134892f6C9a9E342Ed6adce39F8dF). In this live code editor, you will find the following: + +In the code editor you'll find: +- `ContractCounter.sol`: the solidity code of the contract with: + - `uint256 number`: state variable of the contract. + - `increase()`: this function will increment by 1 the `number` variable. + - `getNumber()`: this function will return the current value of the `number` variable. +- `counterABI.json`: the ABI of the ContractCounter.sol +- `counterBytecode.json`: the compiled Bytecode of the ContractCounter.sol +- `main.js`: here you will find 3 funtions: + - `deploy()`: sample script to deploy the smart contract using the ABI and Bytecode + - `getNumber()`: sample script to call the reading function getNumber() of the smart contract + - `increase()`: sample script to interact with the increase() function of the smart contract + +- Contract address: +```bash +0xB9433C87349134892f6C9a9E342Ed6adce39F8dF +``` + + + + +## Contract class + :::info This guide expects you to have some basic knowledge. If you are just starting, it is recommended to first check out this [Tutorial: Deploying and Interacting with Smart Contracts](./smart_contracts_guide.md). ::: -## Contract class - The `Contract` class is the main object exported by the `web3-eth-contract` package. It is also available in the `web3` package. ### Importing the Contract Class From 2373e94757f68af90e67892be3f9a32309cf1bdb Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Fri, 15 Mar 2024 04:57:48 -0400 Subject: [PATCH 19/19] Result of contract method .send is hard to type (#6883) * fix: Add videos to Plugin Section * add deploy and send types * lint fix * add types to web3 packcage * fix unit tests * test * test * test * revert * changelog --- CHANGELOG.md | 12 ++++++++- packages/web3-eth-contract/CHANGELOG.md | 4 +++ packages/web3-eth-contract/src/contract.ts | 31 +++++++++++++++------- packages/web3/CHANGELOG.md | 6 ++++- packages/web3/src/index.ts | 4 +-- 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5049f52f06d..610c70a2cd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2383,4 +2383,14 @@ If there are any bugs, improvements, optimizations or any new feature proposal f - replaced our eventEmitter to EventEmitter3 to support react native builds (#6253) -## [Unreleased] \ No newline at end of file +## [Unreleased] +### Changed + +#### web3 + +- Types `ContractDeploySend`, `ContractMethodSend`, `Web3PromiEvent` was exported (#6883) + +### Added + +#### web3-eth-contract + diff --git a/packages/web3-eth-contract/CHANGELOG.md b/packages/web3-eth-contract/CHANGELOG.md index 38436bdb830..19fb98ecdcc 100644 --- a/packages/web3-eth-contract/CHANGELOG.md +++ b/packages/web3-eth-contract/CHANGELOG.md @@ -365,3 +365,7 @@ Documentation: - Fixed: The Contract is not using the context wallet passed if context was passed at constructor. (#6661) ## [Unreleased] + +### Added + +- Types `ContractDeploySend`, `ContractMethodSend` was added (#6883) diff --git a/packages/web3-eth-contract/src/contract.ts b/packages/web3-eth-contract/src/contract.ts index 44e8d2f74df..54b7e4e792d 100644 --- a/packages/web3-eth-contract/src/contract.ts +++ b/packages/web3-eth-contract/src/contract.ts @@ -82,8 +82,16 @@ import { EventLog, ContractAbiWithSignature, ContractOptions, + TransactionReceipt, + FormatType, } from 'web3-types'; -import { format, isDataFormat, keccak256, toChecksumAddress , isContractInitOptions } from 'web3-utils'; +import { + format, + isDataFormat, + keccak256, + toChecksumAddress, + isContractInitOptions, +} from 'web3-utils'; import { isNullish, validator, @@ -113,7 +121,7 @@ type ContractBoundMethod< Abi extends AbiFunctionFragment, Method extends ContractMethod = ContractMethod, > = ( - ...args: Method['Inputs'] extends undefined|unknown ? any[] : Method['Inputs'] + ...args: Method['Inputs'] extends undefined | unknown ? any[] : Method['Inputs'] ) => Method['Abi']['stateMutability'] extends 'payable' | 'pure' ? PayableMethodObject : NonPayableMethodObject; @@ -148,6 +156,16 @@ export type ContractMethodsInterface = { // eslint-disable-next-line @typescript-eslint/no-explicit-any } & { [key: string]: ContractBoundMethod }; +export type ContractMethodSend = Web3PromiEvent< + FormatType, + SendTransactionEvents +>; +export type ContractDeploySend = Web3PromiEvent< + // eslint-disable-next-line no-use-before-define + Contract, + SendTransactionEvents +>; + /** * @hidden * The event object can be accessed from `myContract.events.myEvent`. @@ -768,12 +786,7 @@ export class Contract const deployData = _input ?? _data; return { arguments: args, - send: ( - options?: PayableTxOptions, - ): Web3PromiEvent< - Contract, - SendTransactionEvents - > => { + send: (options?: PayableTxOptions): ContractDeploySend => { const modifiedOptions = { ...options }; // eslint-disable-next-line @typescript-eslint/no-unsafe-return @@ -1101,7 +1114,7 @@ export class Contract block, ), - send: (options?: PayableTxOptions | NonPayableTxOptions) => + send: (options?: PayableTxOptions | NonPayableTxOptions): ContractMethodSend => this._contractMethodSend(methodAbi, abiParams, internalErrorsAbis, options), estimateGas: async ( diff --git a/packages/web3/CHANGELOG.md b/packages/web3/CHANGELOG.md index 7557dcb0ff0..685ed153fb4 100644 --- a/packages/web3/CHANGELOG.md +++ b/packages/web3/CHANGELOG.md @@ -197,4 +197,8 @@ Documentation: - Added EIP-6963 utility function `requestEIP6963Providers` for multi provider discovery ( other details are in root changelog ) -## [Unreleased] \ No newline at end of file +## [Unreleased] + +### Changed + +- Types `ContractDeploySend`, `ContractMethodSend`, `Web3PromiEvent` was exported (#6883) diff --git a/packages/web3/src/index.ts b/packages/web3/src/index.ts index 0fcc8a1dd4a..45d625b6e48 100644 --- a/packages/web3/src/index.ts +++ b/packages/web3/src/index.ts @@ -333,9 +333,9 @@ export default Web3; * Named exports for all objects which are the default-exported-object in their packages */ export { Web3 }; -export { Web3Context, Web3PluginBase, Web3EthPluginBase } from 'web3-core'; +export { Web3Context, Web3PluginBase, Web3EthPluginBase, Web3PromiEvent } from 'web3-core'; export { Web3Eth } from 'web3-eth'; -export { Contract } from 'web3-eth-contract'; +export { Contract, ContractDeploySend, ContractMethodSend } from 'web3-eth-contract'; export { Iban } from 'web3-eth-iban'; export { Personal } from 'web3-eth-personal'; export { Net } from 'web3-net';