Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

chore: merge unstable into master #179

Merged
merged 33 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4de874a
chore: update CI for unstable branch
mpetrunic Sep 22, 2022
00f9857
fix!: casing of MetaMask (#132)
Mrtenz Sep 22, 2022
d18efa4
fix: update ganache, fix test depending on goerli (#144)
mpetrunic Sep 23, 2022
dc9b5fe
fix: selector issues, useless timeouts, reorganise tests (#145)
mpetrunic Sep 29, 2022
c90db41
fix: import token flaky (#149)
mpetrunic Sep 30, 2022
0c5dc17
feat!: update recommended metamask version (#151)
mpetrunic Oct 4, 2022
9ab9b4c
chore: change eslint config to chainsafe shared (#152)
mpetrunic Oct 7, 2022
07775a7
feat: add support for installing metamask flask (#153)
mpetrunic Oct 10, 2022
564aa4b
feat: ability to install snap (#154)
mpetrunic Oct 12, 2022
d1a3ec4
fix: snap install faster, run all tests (#163)
mpetrunic Oct 26, 2022
e7d8435
feat: Add invokeSnap method; update installSnap method parameter; (#159)
Lykhoyda Oct 26, 2022
2661323
feat: add ability to accept dialogs (#138) (#164)
Lykhoyda Nov 2, 2022
c25c66f
feat!: add playwright support (#167)
mpetrunic Nov 9, 2022
4804b88
feat: added notification snap to methods-snap #137 (#166)
Lykhoyda Nov 10, 2022
708c87b
Merge remote-tracking branch 'origin/master' into unstable
mpetrunic Nov 10, 2022
ba9745f
feat: method to bootstrap snap env (#180)
mpetrunic Nov 11, 2022
b01e8d2
chore: node engine requirements (#184)
BeroBurny Nov 14, 2022
d9e4a4c
chore: remove metamask dir (#185)
mpetrunic Nov 15, 2022
a4c2031
fix: remove page param from install snap (#188)
mpetrunic Nov 15, 2022
4171ea4
feat!: replace outdated methods (#189)
mpetrunic Nov 22, 2022
e382c4c
chore: Ci enhancement (#193)
Tbaut Nov 23, 2022
d63f9e4
feat: allow signing typed data (#191)
Tbaut Nov 24, 2022
d9db933
fix: fix prompt clicking flakiness, fix multiple snap key permissions…
mpetrunic Nov 28, 2022
10c116e
feat: snap notifications 137 (#187)
Lykhoyda Nov 28, 2022
ef70dae
chore: Deprecate button clicks for tests (#195)
Tbaut Nov 30, 2022
3ed2f18
chore: Update documentation and Readme (#202)
Tbaut Dec 6, 2022
902b035
chore: Remove local server for dapp (#203)
Tbaut Dec 6, 2022
8574f4f
feat: Simplify `installSnap` and `initSnapEnv` apis (#206)
Tbaut Dec 8, 2022
270eafa
chore: update web3 (#217)
mpetrunic Dec 12, 2022
20c42e5
chore: update metamask version (#209)
Lykhoyda Dec 12, 2022
6082a44
chore: fix timeout for accept dialog (#218)
Lykhoyda Dec 12, 2022
d5c1a80
fix: increase viewport size (#219)
Lykhoyda Dec 14, 2022
1b114a9
fix: viewport typo (#220)
Lykhoyda Dec 15, 2022
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
82 changes: 4 additions & 78 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,5 @@
require("@rushstack/eslint-patch/modern-module-resolution");

module.exports = {
root: true,
env: {
mocha: true,
node: true,
es6: true,
},
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'eslint-plugin-import', 'prettier'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint',
'plugin:prettier/recommended',
],
rules: {
'prettier/prettier': ['error', {}, { usePrettierrc: true }],
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
varsIgnorePattern: '^_',
},
],
'@typescript-eslint/explicit-function-return-type': [
'error',
{
allowExpressions: true,
},
],
'@typescript-eslint/ban-ts-comment': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'error',
'@typescript-eslint/no-use-before-define': 'off',
'prefer-const': 'error',
'no-consecutive-blank-lines': 0,
'no-console': 'error',
'@typescript-eslint/naming-convention': [
'error',
{ selector: 'default', format: ['camelCase'] },
{
selector: ['classProperty', 'parameterProperty', 'objectLiteralProperty', 'classMethod', 'parameter'],
format: ['camelCase'],
leadingUnderscore: 'allow',
},
//variable must be in camel or upper case
{ selector: 'variable', format: ['camelCase', 'UPPER_CASE'], leadingUnderscore: 'allow' },
// {selector: "variable", modifiers: ["global"], format: ["PascalCase", "UPPER_CASE"]},
//classes and types must be in PascalCase
{ selector: ['typeLike', 'enum'], format: ['PascalCase'] },
{ selector: 'enumMember', format: null },
{ selector: 'typeProperty', format: ['PascalCase', 'camelCase'] },
//ignore rules on destructured params
{
selector: 'variable',
modifiers: ['destructured'],
format: null,
},
],
'import/order': [
'error',
{
groups: ['builtin', 'external', 'parent', 'internal', 'sibling'],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
},
},
],
},
overrides: [
{
files: ['**/test/**/*.ts'],
rules: {
'no-console': 'off',
},
},
],
};
extends: "@chainsafe",
}
2 changes: 1 addition & 1 deletion .github/workflows/cron.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Validate compatiblity with metamask"
name: "Validate compatiblity with MetaMask"

on:
schedule:
Expand Down
53 changes: 43 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,66 @@ on:
push:
branches:
- master
- unstable
pull_request:
branches:
- '**'

jobs:
checks:
name: Checks
tests:
name: Tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
mm-version: [mm, flask]
automation: [playwright, puppeteer]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
cache: yarn
node-version: "16"
cache: 'yarn'
- name: Install
run: yarn install --frozen-lockfile
- name: Build
run: yarn run build
run: yarn --prefer-offline --frozen-lockfile
- name: Tests
run: 'xvfb-run --auto-servernum --server-args="-screen 0, 1920x1080x24" yarn run test:${{matrix.automation}}:${{ matrix.mm-version }} --timeout 50000'
- uses: actions/upload-artifact@v3
if: always()
with:
name: debug_screenshots
path: ./*.png
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "16"
cache: 'yarn'
- name: Install deps
run: yarn --prefer-offline --frozen-lockfile
- name: Lint
run: yarn run lint
- name: Tests
run: xvfb-run --auto-servernum yarn run test
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "16"
cache: 'yarn'
- name: Install deps
run: yarn --prefer-offline --frozen-lockfile
- name: Build
run: yarn build

maybe-release:
name: release
runs-on: ubuntu-latest
needs: [checks]
needs: [tests, lint, build]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- uses: google-github-actions/release-please-action@v3 # it will analyze commits and create PR with new version and updated CHANGELOG:md file. On merging it will create github release page with changelog
Expand All @@ -50,7 +83,7 @@ jobs:
registry-url: 'https://registry.npmjs.org'
if: ${{ steps.release.outputs.release_created }}

- run: yarn install --frozen-lockfile
- run: yarn --prefer-offline --frozen-lockfile
if: ${{ steps.release.outputs.release_created }}

- run: yarn build
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
*DS_Store
node_modules
test/server/data.js
build
dist
.vscode/
/metamask
/.metamask
.idea
*.log
test/dapp/data.js
*.png
7 changes: 7 additions & 0 deletions .mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parallel: false
recursive: true
color: true
timeout: 20000
exit: true
spec:
- 'test/**/*.spec.ts'
7 changes: 0 additions & 7 deletions .prettierrc.js

This file was deleted.

83 changes: 71 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,87 @@ $ yarn add @chainsafe/dappeteer
## Usage

```js
import puppeteer from 'puppeteer';
import dappeteer from '@chainsafe/dappeteer';

async function main() {
const [metamask, page] = await dappeteer.bootstrap(puppeteer, { metamaskVersion: 'v10.15.0' });
const { metaMask, browser } = await dappeteer.bootstrap();

// create a new page and visit your dapp
const dappPage = browser.newPage();
await dappPage.goto('http://my-dapp.com');

// you can change the network if you want
await metamask.switchNetwork('ropsten');
await metaMask.switchNetwork('goerli');

// you can import a token
await metamask.addToken({
tokenAddress: '0x4f96fe3b7a6cf9725f59d353f723c1bdb64ca6aa',
symbol: 'KAKI',
});
// do something in your dapp that prompts MetaMask to add a Token
const addTokenButton = await dappPage.$('#add-token');
await addTokenButton.click();
// instruct MetaMask to accept this request
await metaMask.acceptAddToken();

// go to a dapp and do something that prompts MetaMask to confirm a transaction
await page.goto('http://my-dapp.com');
const payButton = await page.$('#pay-with-eth');
// do something that prompts MetaMask to confirm a transaction
const payButton = await dappPage.$('#pay-with-eth');
await payButton.click();

// 🏌
await metamask.confirmTransaction();
await metaMask.confirmTransaction();
}

main();
```

## Usage with Snaps

```js
import dappeteer from '@chainsafe/dappeteer';
import { exec } from "child_process";

async function buildSnap(): Promise<string> {
console.log(`Building my-snap...`);
await new Promise((resolve, reject) => {
exec(`cd ./my-snap && npx mm-snap build`, (error, stdout) => {
if (error) {
reject(error);
return;
}
resolve(stdout);
});
});

return "./my-snap";
}

async function main() {
// you need to have a webpage open to interact with MetaMask, you can also visit a dApp page
const dappPage = browser.newPage();
await dappPage.goto('http://example.org/');

// build your local snap
const builtSnapDir = await buildSnap()

// setup dappateer and install your snap
const { snapId, metaMask, dappPage } = await dappeteer.initSnapEnv({
snapIdOrLocation: builtSnapDir
});

// invoke a method from your snap that promps users with approve/reject dialog
metaMask.snaps.invokeSnap(dappPage, snapId, "my-method")

// instruct MetaMask to accept this request
await metaMask.snaps.acceptDialog();

// get the notification emitter and the promise that will receive the notifications
const emitter = await metaMask.snaps.getNotificationEmitter();
const notificationPromise = emitter.waitForNotification();

// do something that prompts you snap to emit notifications
await metaMask.snaps.invokeSnap(dappPage, snapId, "notify");

// Make sure the notification promise has resolved
await notificationPromise;

// You can now read the snap notifications and run tests against them
const notifications = await metaMask.snaps.getAllNotifications();
}

main();
Expand Down
Loading