Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Move stream functionality from BaseProvider to new StreamProvider #209

Merged
merged 20 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/build-test-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ jobs:
- name: Validate changelog
if: ${{ !startsWith(github.ref, 'release/') }}
run: yarn auto-changelog validate
- name: Require clean working directory
shell: bash
run: |
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
fi
all-jobs-pass:
name: All jobs pass
runs-on: ubuntu-20.04
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ The Ethereum provider object injected by MetaMask into various environments.
Contains a lot of implementation details specific to MetaMask, and is probably
not suitable for out-of-the-box use with other wallets.

The `BaseProvider` implements the Ethereum JavaScript provider specification, [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193). `MetamaskInpageProvider` implements [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and legacy interfaces.
The `BaseProvider` implements the Ethereum JavaScript provider specification ([EIP-1193]), but must be modified by a sub-class in order to function.
`StreamProvider` is such a sub-class, which synchronizes its state and marshals JSON-RPC messages via a duplex stream.
`MetamaskInpageProvider` further extends `StreamProvider` to support legacy provider interfaces in addition to [EIP-1193], and is used to instantiate the object injected by MetaMask into web pages as `window.ethereum`.

## Usage

Expand Down Expand Up @@ -65,3 +67,5 @@ The project follows the same release process as the other libraries in the MetaM
6. Once approved, the PR is squashed & merged
7. The commit on the base branch is tagged
8. The tag can be published as needed

[eip-1193]: https://eips.ethereum.org/EIPS/eip-1193
34 changes: 18 additions & 16 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,30 @@ const baseConfig = {
// original implementations, between each test. It does not affect mocked
// modules.
restoreMocks: true,
testTimeout: 2500,
};

module.exports = {
collectCoverage: true,
collectCoverageFrom: [
'<rootDir>/**/src/**/*.ts',
'!<rootDir>/**/src/**/*.test.ts',
],
coverageReporters: ['html', 'json-summary', 'text'],
coveragePathIgnorePatterns: ['/node_modules/', '/mocks/', '/test/'],
coverageThreshold: {
global: {
branches: 55.61,
functions: 52.81,
lines: 58.33,
statements: 58.63,
},
},
projects: [
{
...baseConfig,
displayName: 'BaseProvider',
displayName: 'StreamProvider',
testEnvironment: 'node',
testMatch: ['**/BaseProvider.test.ts'],
testMatch: ['**/StreamProvider.test.ts', '**/utils.test.ts'],
},
{
...baseConfig,
Expand All @@ -30,18 +44,6 @@ module.exports = {
setupFilesAfterEnv: ['./jest.setup.js'],
},
],
collectCoverage: true,
collectCoverageFrom: ['./src/**.ts'],
coverageReporters: ['text', 'html'],
coveragePathIgnorePatterns: ['/node_modules/', '/mocks/'],
// TODO: Require coverage when we're closer to home.
// coverageThreshold: {
// global: {
// branches: 100,
// functions: 100,
// lines: 100,
// statements: 100,
// },
// },
silent: true,
testTimeout: 2500,
};
2 changes: 1 addition & 1 deletion mocks/DuplexStream.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Duplex } from 'stream';

export default class DuplexStream extends Duplex {
export class MockDuplexStream extends Duplex {
constructor() {
super({
objectMode: true,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"scripts": {
"setup": "yarn install && yarn allow-scripts",
"build": "mkdir -p dist && rm -rf dist/* && tsc --project .",
"test": "jest",
"test": "jest && jest-it-up",
"test:watch": "yarn test --watch",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' --single-quote --ignore-path .gitignore",
Expand Down Expand Up @@ -76,6 +76,7 @@
"eslint-plugin-prettier": "^3.4.0",
"jest": "^26.6.3",
"jest-chrome": "^0.7.1",
"jest-it-up": "^2.0.2",
"prettier": "^2.3.1",
"ts-jest": "^26.5.6",
"typescript": "^4.3.5"
Expand Down
Loading