Skip to content

Commit

Permalink
update LegacyEthereumProvider; add type-integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat committed Oct 4, 2023
1 parent b759b1a commit 5f9bd1b
Show file tree
Hide file tree
Showing 4 changed files with 427 additions and 3 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@
"superstruct": "^1.0.3"
},
"devDependencies": {
"@ethersproject/providers": "^5.7.2",
"@lavamoat/allow-scripts": "^2.3.1",
"@lavamoat/preinstall-always-fail": "^1.0.0",
"@metamask/auto-changelog": "^3.1.0",
"@metamask/eslint-config": "^12.0.0",
"@metamask/eslint-config-jest": "^12.0.0",
"@metamask/eslint-config-nodejs": "^12.0.0",
"@metamask/eslint-config-typescript": "^12.0.0",
"@metamask/eth-query": "^3.0.1",
"@metamask/safe-event-emitter": "^3.0.0",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.66",
Expand Down
12 changes: 12 additions & 0 deletions src/json-rpc-provider-types.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expectAssignable, expectNotAssignable } from 'tsd';

Check failure on line 1 in src/json-rpc-provider-types.test-d.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (16.x)

'expectNotAssignable' is defined but never used

Check failure on line 1 in src/json-rpc-provider-types.test-d.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

'expectNotAssignable' is defined but never used

Check failure on line 1 in src/json-rpc-provider-types.test-d.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

'expectNotAssignable' is defined but never used
import EthQuery from '@metamask/eth-query';

Check failure on line 2 in src/json-rpc-provider-types.test-d.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (16.x)

`@metamask/eth-query` import should occur before import of `tsd`

Check failure on line 2 in src/json-rpc-provider-types.test-d.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

`@metamask/eth-query` import should occur before import of `tsd`

Check failure on line 2 in src/json-rpc-provider-types.test-d.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

`@metamask/eth-query` import should occur before import of `tsd`
import { Web3Provider } from '@ethersproject/providers';

Check failure on line 3 in src/json-rpc-provider-types.test-d.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (16.x)

`@ethersproject/providers` import should occur before import of `tsd`

Check failure on line 3 in src/json-rpc-provider-types.test-d.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

`@ethersproject/providers` import should occur before import of `tsd`

Check failure on line 3 in src/json-rpc-provider-types.test-d.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

`@ethersproject/providers` import should occur before import of `tsd`

import type {

Check failure on line 5 in src/json-rpc-provider-types.test-d.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (16.x)

Replace `⏎··LegacyEthereumProvider⏎` with `·LegacyEthereumProvider·`

Check failure on line 5 in src/json-rpc-provider-types.test-d.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Replace `⏎··LegacyEthereumProvider⏎` with `·LegacyEthereumProvider·`

Check failure on line 5 in src/json-rpc-provider-types.test-d.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Replace `⏎··LegacyEthereumProvider⏎` with `·LegacyEthereumProvider·`
LegacyEthereumProvider
} from '.';

// Known legacy providers

expectAssignable<LegacyEthereumProvider>(new EthQuery({} as any));
expectAssignable<LegacyEthereumProvider>(new Web3Provider({} as any));
33 changes: 31 additions & 2 deletions src/json-rpc-provider-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,46 @@ export type EIP1993Provider = SafeEventEmitter & {
* [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193). It is not compliant with
* any Ethereum provider standard.
*/
export type LegacyEthereumProvider = {
export type LegacyEthereumProvider = LegacyEthersProvider | LegacyEthJsQueryProvider | LegacyWeb3Provider;

Check failure on line 36 in src/json-rpc-provider-types.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (16.x)

Replace `·LegacyEthersProvider·|·LegacyEthJsQueryProvider` with `⏎··|·LegacyEthersProvider⏎··|·LegacyEthJsQueryProvider⏎·`

Check failure on line 36 in src/json-rpc-provider-types.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Replace `·LegacyEthersProvider·|·LegacyEthJsQueryProvider` with `⏎··|·LegacyEthersProvider⏎··|·LegacyEthJsQueryProvider⏎·`

Check failure on line 36 in src/json-rpc-provider-types.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Replace `·LegacyEthersProvider·|·LegacyEthJsQueryProvider` with `⏎··|·LegacyEthersProvider⏎··|·LegacyEthJsQueryProvider⏎·`

type LegacyWeb3Provider = {
/**
* Send a provider request asynchronously.
*
* @param req - The request to send.
* @param callback - A function that is called upon the success or failure of the request.
*/
sendAsync<Result extends Json = Json>(
send?<Result extends Json = Json>(
req: Partial<JsonRpcRequest>,
callback: SendAsyncCallback<Result>,
): void;
}

Check failure on line 49 in src/json-rpc-provider-types.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (16.x)

Insert `;`

Check failure on line 49 in src/json-rpc-provider-types.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Insert `;`

Check failure on line 49 in src/json-rpc-provider-types.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Insert `;`

type LegacyEthJsQueryProvider = {
/**
* Send a provider request asynchronously. (ethjs-query)
*
* @param req - The request to send.
* @param callback - A function that is called upon the success or failure of the request.
*/
sendAsync?<Result extends Json = Json>(
req: Partial<JsonRpcRequest>,
callback: SendAsyncCallback<Result>,
): void;
};

type LegacyEthersProvider = {
/**
* Send a provider request asynchronously. (ethers v5 Web3Provider)
*
* @param method - The RPC method to call.
* @param params - Array with method parameters.
* @returns - A promise resolving with the result of the RPC call, or rejecting on failure.

Check failure on line 70 in src/json-rpc-provider-types.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (16.x)

There must be no hyphen before @returns description

Check failure on line 70 in src/json-rpc-provider-types.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

There must be no hyphen before @returns description

Check failure on line 70 in src/json-rpc-provider-types.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

There must be no hyphen before @returns description
*/
send?<Result extends Json = Json>(
method: string,
params: any[],
): Promise<Result>;
};

type SendAsyncCallback<Result extends Json> = (
Expand Down
Loading

0 comments on commit 5f9bd1b

Please sign in to comment.