generated from web3/web3.js-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from web3/feat/4337-methods
feat: 4337 function
- Loading branch information
Showing
28 changed files
with
15,736 additions
and
1,035 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
lib | ||
dist | ||
jest.config.js | ||
webpack.config.js | ||
.eslintrc.js | ||
cypress | ||
cypress.config.js | ||
test/black_box |
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 @@ | ||
name: Run Tests | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, ready_for_review] | ||
|
||
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 16 | ||
|
||
- name: Install Dependencies | ||
run: yarn | ||
|
||
- name: Lint | ||
run: yarn lint | ||
|
||
- name: Build | ||
run: yarn build | ||
|
||
- name: Unit Tests | ||
run: yarn test | ||
|
||
- name: End-to-End Tests (Firefox) | ||
run: yarn test:e2e:firefox | ||
|
||
- name: Generate Coverage Report | ||
run: yarn test:coverage |
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,2 +1,13 @@ | ||
# General | ||
.DS_Store | ||
*.swp | ||
*.orig | ||
node_modules | ||
lib | ||
lib | ||
.env | ||
# Logs | ||
*.log | ||
.coverage | ||
# IDE directories | ||
.idea | ||
tmp |
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,11 +1,36 @@ | ||
Web3.js EIP4337 Plugin | ||
=========== | ||
# Web3.js EIP4337 Plugin | ||
|
||
This plugin is developed and maintained by [Blocto](https://blocto.io/) . | ||
|
||
This is a [web3.js](https://github.com/web3/web3.js) `4.x` plugin for Account Abstraction functionality. | ||
|
||
## Run the tests | ||
|
||
1. Clone the repo | ||
2. Run `yarn` to install dependencies | ||
- If you receive the following warning, please remove the file `package-lock.json` and make sure to run `yarn` to install dependencies instead of `npm i`: | ||
|
||
```console | ||
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json. | ||
``` | ||
|
||
3. Run the tests: | ||
- `yarn test:unit`: Runs the mocked tests that do not make a network request using the [Jest](https://jestjs.io/) framework | ||
- End-to-end tests: Runs Webpack bundled tests that make a network request to the RPC provider `https://rpc.ankr.com/eth` and returns an actual response from `MainnetPriceFeeds.LinkEth` smart contract using the [Cypress](https://www.cypress.io/) framework | ||
- `yarn test:e2e:chrome`: Runs the tests using Chrome | ||
- `yarn test:e2e:electron`: Runs the tests using Electron | ||
- `yarn test:e2e:firefox`: Runs the tests using Firefox | ||
- Black box tests: Uses a published version of the plugin from [Verdaccio](https://verdaccio.org/) to run tests that make a network request to the RPC provider `https://rpc.ankr.com/eth` and returns an actual response from `MainnetPriceFeeds.LinkEth` smart contract using the [Jest](https://jestjs.io/) framework | ||
- NOTE The black box tests are setup to run within Github actions environment, but can be ran locally. The [black_box_test_helpers.sh](https://github.com/ChainSafe/web3.js-plugin-chainlink/blob/master/scripts/black_box_test_helpers.sh) script can be used to: | ||
- `start`: Start Verdaccio using a Docker container | ||
- `stop`: Kill the Docker container | ||
- `startBackgroundAndPublish`: Starts a headless Docker container and publishes the plugin package | ||
- `runTests`: `cd`s into the `test/black_box` directory, installs the black box package dependencies, and runs `yarn test` which will use Jest to run the tests | ||
- In addition to the `black_box_test_helpers.sh` script, the black box tests can be ran using the following `package.json` scripts: | ||
1. `yarn pre-black-box`: Calls `startBackgroundAndPublish` from the `black_box_test_helpers.sh` script | ||
2. `yarn test:black-box`: Calls `yarn pre-black-box` and `runTests` from the from the `black_box_test_helpers.sh` script | ||
3. `yarn post-black-box`: Calls `stop` from the `black_box_test_helpers.sh` script | ||
|
||
License | ||
------- | ||
## License | ||
|
||
[MIT](https://choosealicense.com/licenses/mit/) |
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,15 @@ | ||
const config = { | ||
screenshotOnRunFailure: false, | ||
video: false, | ||
e2e: { | ||
// We've imported your old cypress plugins here. | ||
// You may want to clean this up later by importing these. | ||
setupNodeEvents(on, config) { | ||
return require('./cypress/plugins/index.js')(on, config); | ||
}, | ||
specPattern: 'test/e2e/**/**/*.test.ts', | ||
excludeSpecPattern: ['test/black_box/**'], | ||
}, | ||
}; | ||
|
||
module.exports = config; |
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,25 @@ | ||
/// <reference types="cypress" /> | ||
// *********************************************************** | ||
// This example plugins/index.js can be used to load plugins | ||
// | ||
// You can change the location of this file or turn off loading | ||
// the plugins file with the 'pluginsFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/plugins-guide | ||
// *********************************************************** | ||
|
||
// This function is called when a project is opened or re-opened (e.g. due to | ||
// the project's config changing) | ||
|
||
const webpackPreprocessor = require('@cypress/webpack-preprocessor'); | ||
const webpackOptions = require('../webpack.config.js'); | ||
|
||
/** | ||
* @type {Cypress.PluginConfig} | ||
*/ | ||
// eslint-disable-next-line no-unused-vars | ||
module.exports = (on, config) => { | ||
on('file:preprocessor', webpackPreprocessor({ webpackOptions })); | ||
return config; | ||
}; |
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,43 @@ | ||
// *********************************************************** | ||
// This example support/index.js is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') | ||
|
||
import 'cypress-jest-adapter'; | ||
|
||
// Enable the hook to match Jest | ||
global.beforeAll = global.before; | ||
global.afterAll = global.after; | ||
|
||
// In e2e tests we just need to use jest mocking API | ||
global.jest = { | ||
fn: global.cy.stub, | ||
spyOn: global.cy.spy, | ||
}; | ||
|
||
global.it = it; | ||
global.test = it; | ||
global.it.each = data => (describe, test) => { | ||
const prs = []; | ||
for (const d of data) { | ||
if (Array.isArray(d)) { | ||
prs.push(global.it(describe, test.bind(undefined, ...d))); | ||
} else { | ||
prs.push(global.it(describe, test.bind(undefined, d))); | ||
} | ||
} | ||
return Promise.all(prs); | ||
}; |
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,6 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"types": ["cypress"] | ||
} | ||
} |
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,26 @@ | ||
const webpack = require('webpack'); | ||
|
||
module.exports = { | ||
mode: 'development', | ||
resolve: { | ||
extensions: ['.ts', '.js'], | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.ts$/, | ||
exclude: [/node_modules/], | ||
use: [ | ||
{ | ||
loader: 'ts-loader', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
plugins: [ | ||
new webpack.ProvidePlugin({ | ||
process: 'process/browser', | ||
}), | ||
], | ||
}; |
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 |
---|---|---|
|
@@ -11,30 +11,46 @@ | |
"scripts": { | ||
"lint": "eslint '{src,test}/**/*.ts'", | ||
"build": "tsc --project tsconfig.build.json", | ||
"test": "jest --config=./test/jest.config.js" | ||
"test": "jest --config=./test/unit/jest.config.js", | ||
"pre-black-box": "./scripts/black_box_test_helpers.sh startBackgroundAndPublish", | ||
"test:black-box": "yarn pre-black-box && ./scripts/black_box_test_helpers.sh runTests", | ||
"test:coverage": "jest --config=./test/unit/jest.config.js --coverage=true --coverage-reporters=text", | ||
"test:e2e:chrome": "cypress run --headless --browser chrome", | ||
"test:e2e:firefox": "cypress run --headless --browser firefox", | ||
"test:e2e:electron": "cypress run --headless --browser electron", | ||
"test:all": "yarn && yarn build && yarn test && yarn run test:e2e:firefox && yarn run test:black-box" | ||
}, | ||
"contributors": [ | ||
], | ||
"contributors": [], | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "[email protected]:web3/web3.js-plugin-eip4337.git" | ||
}, | ||
"dependencies": { | ||
}, | ||
"devDependencies": { | ||
"@blocto/sdk": "^0.7.2", | ||
"@chainsafe/eslint-config": "^2.0.0", | ||
"@cypress/webpack-preprocessor": "^5.15.5", | ||
"@types/jest": "^29.5.2", | ||
"@types/node": "^20.2.6", | ||
"cypress": "^12.3.0", | ||
"cypress-jest-adapter": "^0.1.1", | ||
"eslint": "8", | ||
"jest": "^29.5.0", | ||
"jest-extended": "^4.0.0", | ||
"npm-auth-to-token": "^1.0.0", | ||
"process": "^0.11.10", | ||
"ts-jest": "^29.1.0", | ||
"ts-loader": "^9.4.1", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.1.3", | ||
"web3": "^4.1.1" | ||
"web3": "^4.2.0", | ||
"web3-eth-abi": "^4.1.3", | ||
"web3-utils": "^4.0.7", | ||
"web3-validator": "^2.0.3", | ||
"webpack": "^5.75.0", | ||
"webpack-cli": "^5.0.1" | ||
}, | ||
"peerDependencies": { | ||
"web3": ">= 4.1.1" | ||
"web3": ">= 4.2.0" | ||
} | ||
} |
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,81 @@ | ||
#!/usr/bin/env bash | ||
|
||
ORIGARGS=("$@") | ||
|
||
helpFunction() { | ||
echo "Usage: $0 [start|stop|startBackgroundAndPublish|runTests] [background]" | ||
exit 1 # Exit script after printing help | ||
} | ||
|
||
start() { | ||
. scripts/env.sh | ||
if [[ ${ORIGARGS[1]} == "background" ]]; then | ||
startBackground | ||
else | ||
echo "Starting verdaccio..." | ||
docker run -it --rm --name verdaccio -p 4873:4873 verdaccio/verdaccio | ||
fi | ||
} | ||
|
||
startBackground() { | ||
echo "Starting verdaccio in background..." | ||
docker run -d --rm --name verdaccio -p 4873:4873 verdaccio/verdaccio | ||
} | ||
|
||
stop() { | ||
echo "Stopping verdaccio ..." | ||
docker ps -q --filter ancestor="verdaccio/verdaccio" | xargs -r docker stop | ||
} | ||
|
||
createVerdaccioNPMUser() { | ||
curl -XPUT \ | ||
-H "Content-type: application/json" \ | ||
-d '{ "name": "test", "password": "test" }' \ | ||
'http://localhost:4873/-/user/org.couchdb.user:test' | ||
} | ||
|
||
loginNPMUser() { | ||
npx npm-auth-to-token \ | ||
-u test \ | ||
-p test \ | ||
-e [email protected] \ | ||
-r http://localhost:4873 | ||
} | ||
|
||
yarnPublish() { | ||
yarn publish \ | ||
--new-version 1.0.0 \ | ||
--no-git-tag-version \ | ||
--tag blackbox \ | ||
--registry http://localhost:4873 | ||
} | ||
|
||
publish() { | ||
echo "Publishing to verdaccio ..." | ||
|
||
npx wait-port -t 60000 4873 | ||
|
||
createVerdaccioNPMUser | ||
loginNPMUser | ||
yarn build | ||
yarnPublish | ||
} | ||
|
||
startBackgroundAndPublish() { | ||
startBackground && publish | ||
} | ||
|
||
runTests() { | ||
cd test/black_box | ||
yarn --update-checksums | ||
yarn install | ||
yarn test | ||
} | ||
|
||
case $1 in | ||
start) start ;; | ||
stop) stop ;; | ||
startBackgroundAndPublish) startBackgroundAndPublish ;; | ||
runTests) runTests ;; | ||
*) helpFunction ;; # Print helpFunction in case parameter is non-existent | ||
esac |
Oops, something went wrong.