This repository was archived by the owner on Mar 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Test with injected external providers #5652
Merged
Merged
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
653524a
fix: sending tx with injected provider (#5651)
Muhammad-Altabba e593bf6
adding a test for using `ganache` provider
Muhammad-Altabba b3cdf3f
enable the jsonrpc `id` to optionally be incremented starting from a …
Muhammad-Altabba a07e235
test with `in3` as a provider
Muhammad-Altabba c4fbfed
speedup a test at web3 and also increase the timeout
Muhammad-Altabba 8e35b09
increase integration test timeout at web3 package
Muhammad-Altabba 8985aa0
add a test for using `hardhat` provider
Muhammad-Altabba 63d23d7
add `hardhat.config.js` to `.eslintignore`
Muhammad-Altabba aa7e217
skip `in3` test if it takes too long
Muhammad-Altabba 272669f
improve how legacy providers, such as hardhat, is used
Muhammad-Altabba 64990a7
implement `isPromise` that works in the browsers
Muhammad-Altabba eb90dda
comment update at Web3RequestManager
Muhammad-Altabba d1bcce1
update .gitignore to include .in3 local folder
Muhammad-Altabba c608a31
Merge remote-tracking branch 'origin/4.x' into feature/5309/test-inje…
Muhammad-Altabba 5e8c5a4
refactor external providers tests
Muhammad-Altabba 1cf6799
apply yarn lint:fix
Muhammad-Altabba f1448ff
remove unused import
Muhammad-Altabba df15482
update CHANGELOG.md
Muhammad-Altabba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| 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 <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| // eslint-disable-next-line import/no-extraneous-dependencies | ||
| import ganache from 'ganache'; | ||
|
|
||
| import In3Client from 'in3'; | ||
|
|
||
| import { setRequestIdStart } from 'web3-utils'; | ||
|
|
||
| import Web3 from '../../src/index'; | ||
| import { getSystemTestMnemonic } from '../shared_fixtures/system_tests_utils'; | ||
|
|
||
| describe('compatibility with external providers', () => { | ||
| it('should accept a simple EIP1193 provider', () => { | ||
| interface RequestArguments { | ||
| readonly method: string; | ||
| readonly params?: readonly unknown[] | object; | ||
| } | ||
|
|
||
| class Provider { | ||
| // eslint-disable-next-line class-methods-use-this, @typescript-eslint/require-await, @typescript-eslint/no-unused-vars | ||
| public async request(_: RequestArguments): Promise<unknown> { | ||
| return undefined as unknown; | ||
| } | ||
| } | ||
|
|
||
| const testProvider = new Provider(); | ||
| const { provider } = new Web3(testProvider); | ||
| expect(provider).toBeDefined(); | ||
| }); | ||
|
|
||
| it('should accept a `ganache` provider', async () => { | ||
| const { provider } = ganache.server({ | ||
| wallet: { | ||
| mnemonic: getSystemTestMnemonic(), | ||
| }, | ||
| }); | ||
| const web3 = new Web3(provider); | ||
|
|
||
| const accounts = await web3.eth.getAccounts(); | ||
|
|
||
| const tx = web3.eth.sendTransaction({ | ||
| to: accounts[1], | ||
| from: accounts[0], | ||
| value: '1', | ||
| }); | ||
|
|
||
| await expect(tx).resolves.not.toThrow(); | ||
| }); | ||
|
|
||
| it('should accept an `in3` provider', async () => { | ||
| // use the In3Client as Http-Provider for web3.js | ||
| const web3 = new Web3( | ||
| new In3Client({ | ||
| proof: 'standard', | ||
| signatureCount: 1, | ||
| requestCount: 1, | ||
| chainId: 'mainnet', | ||
| }).createWeb3Provider(), | ||
| ); | ||
|
|
||
| // TODO: remove the next line after this issue is closed: https://github.com/blockchainsllc/in3/issues/46 | ||
| setRequestIdStart(0); | ||
|
|
||
| // get the last block number | ||
| const block = await web3.eth.getBlockNumber(); | ||
| expect(typeof block).toBe('bigint'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.