This repository has been 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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test with injected external providers (#5652)
* fix: sending tx with injected provider (#5651) Co-authored-by: Marin Petrunic <[email protected]> * adding a test for using `ganache` provider * enable the jsonrpc `id` to optionally be incremented starting from a number (Inspired by: #5373 (comment) and needed as a work around for blockchainsllc/in3#46) * test with `in3` as a provider & skip `in3` test if it takes too long * increase integration test timeout at web3 package * add a test for using `hardhat` provider * improve how legacy providers, such as hardhat, is used * implement `isPromise` that works in the browsers * refactor external providers tests * update CHANGELOG.md
- Loading branch information
1 parent
30bffb6
commit 21b7649
Showing
23 changed files
with
1,407 additions
and
127 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -36,3 +36,6 @@ tsconfig.tsbuildinfo | |
package-lock.json | ||
|
||
tmp/ | ||
|
||
# Incubed (in3) nodelist | ||
packages/web3/.in3/ |
This file contains 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 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 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
dist | ||
hardhat.config.js | ||
jest.config.js | ||
webpack.config.js | ||
.eslintrc.js |
This file contains 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,3 @@ | ||
// A dummy file to prevent `hardhat` from throwing | ||
// "HardhatError: HH1: You are not inside a Hardhat project." | ||
// Note: Hardhat is just used inside the tests to ensure its compatibility. |
This file contains 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
38 changes: 38 additions & 0 deletions
38
packages/web3/test/integration/external-providers/extremely_simple.test.ts
This file contains 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,38 @@ | ||
/* | ||
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/>. | ||
*/ | ||
|
||
import Web3 from '../../../src/index'; | ||
|
||
describe('compatibility with extremely simple external provider', () => { | ||
it('should accept a simple instance that is compatible with EIP1193', () => { | ||
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(); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
packages/web3/test/integration/external-providers/ganache.test.ts
This file contains 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,35 @@ | ||
/* | ||
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 { performBasicRpcCalls } from './helper'; | ||
|
||
import { getSystemTestMnemonic } from '../../shared_fixtures/system_tests_utils'; | ||
|
||
describe('compatibility with `ganache` provider', () => { | ||
it('should initialize Web3, get accounts & block number and send a transaction', async () => { | ||
const { provider } = ganache.server({ | ||
wallet: { | ||
mnemonic: getSystemTestMnemonic(), | ||
}, | ||
}); | ||
|
||
await performBasicRpcCalls(provider); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
packages/web3/test/integration/external-providers/hardhat.test.ts
This file contains 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,28 @@ | ||
/* | ||
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 hardhat from 'hardhat'; | ||
|
||
import { performBasicRpcCalls } from './helper'; | ||
|
||
describe('compatibility with `hardhat` provider', () => { | ||
it('should initialize Web3, get accounts & block number and send a transaction', async () => { | ||
// use the hardhat provider for web3.js | ||
await performBasicRpcCalls(hardhat.network.provider); | ||
}); | ||
}); |
Oops, something went wrong.