Skip to content

Commit

Permalink
Merge pull request #27 from ChainSafe/1-use-only-web3-as-dependency
Browse files Browse the repository at this point in the history
* Use only web3 as a dependency

* Update web3 to the latest canary version

* Updated README.md
  • Loading branch information
Muhammad-Altabba authored Jun 9, 2023
2 parents d59f013 + d7c9487 commit e09caf8
Show file tree
Hide file tree
Showing 10 changed files with 412 additions and 416 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ yarn add @chainsafe/web3.js-chainlink-plugin

### Installing Version `4.x` of `web3`

When adding the `web3` package to your project, make sure to use version `4.x`. You can append `@4.0.1-rc.2` tag to install RC2 of version 4:
When adding the `web3` package to your project, make sure to use version `4.x`. You can append `@4.0.2-dev.af57eae.0` tag to install the latest version of 4 that this plugin was tested with:

- `npm i -S [email protected].1-rc.2`
- `yarn add [email protected].1-rc.2`
- `npm i -S [email protected].2-dev.af57eae.0`
- `yarn add [email protected].2-dev.af57eae.0`

> **_NOTE_**
> If 4.x was already released, you are good to just use `web3` without appending anything to it.
Expand All @@ -33,7 +33,7 @@ To verify you have the correct `web3` version installed, after adding the packag

```json
"dependencies": {
"web3": "4.0.1-rc.2"
"web3": "4.0.2-dev.af57eae.0"
}
```

Expand Down
17 changes: 6 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@chainsafe/web3.js-chainlink-plugin",
"version": "0.1.0-alpha.0",
"version": "9.9.9",
"description": "A Web3.js 4.x Plugin for Interacting With Chainlink Smart Contracts",
"main": "lib/index.js",
"repository": {
Expand Down Expand Up @@ -31,14 +31,16 @@
"test:e2e:chrome": "npx cypress run --headless --browser chrome",
"test:e2e:firefox": "npx cypress run --headless --browser firefox",
"test:e2e:electron": "npx cypress run --headless --browser electron",
"test:unit": "jest --config=./test/unit/jest.config.js"
"test:unit": "jest --config=./test/unit/jest.config.js",
"test:all": "yarn && yarn build && yarn test && yarn run test:e2e:firefox && yarn run test:black-box"
},
"devDependencies": {
"@babel/core": "^7.20.2",
"@babel/preset-env": "^7.20.2",
"@cypress/webpack-preprocessor": "^5.15.5",
"@types/jest": "^28.1.6",
"@types/node": "^18.7.23",
"@types/ws": "^8.5.4",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"assert": "^2.0.0",
Expand Down Expand Up @@ -68,18 +70,11 @@
"ts-loader": "^9.4.1",
"ts-node": "^10.9.1",
"typescript": "^4.7.4",
"web3": "4.0.1-rc.2",
"web3-core": "4.0.1-rc.2",
"web3-eth": "4.0.1-rc.2",
"web3": "^4.0.2-dev.af57eae.0",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1"
},
"peerDependencies": {
"web3-core": ">= 4.0.1-rc.2 < 5",
"web3-eth": ">= 4.0.1-rc.2 < 5",
"web3-eth-abi": ">= 4.0.1-rc.2 < 5",
"web3-eth-contract": ">= 4.0.1-rc.2 < 5",
"web3-types": ">= 1.0.0-rc.2 < 5",
"web3-validator": ">= 1.0.0-rc.2 < 5"
"web3": ">= 4.0.2-dev.af57eae.0 < 5"
}
}
13 changes: 3 additions & 10 deletions src/chainlink_plugin.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { Web3PluginBase } from 'web3-core';
import { Contract } from 'web3-eth-contract';
import { Address, ContractAbi } from 'web3-types';
import { isAddress } from 'web3-validator';

import { Address, Contract, ContractAbi, Web3PluginBase, validator } from 'web3';
import { AggregatorV3InterfaceABI } from './aggregator_v3_interface_abi';
import { Web3Context } from './reexported_web3_context';
import { GoerliPriceFeeds, MainnetPriceFeeds } from './types';

export class ChainlinkPlugin extends Web3PluginBase {
Expand All @@ -31,7 +26,7 @@ export class ChainlinkPlugin extends Web3PluginBase {
priceFeedAddress: MainnetPriceFeeds | GoerliPriceFeeds | Address,
aggregatorInterfaceAbi: ContractAbi = this.defaultAggregatorInterfaceAbi,
) {
if (!isAddress(priceFeedAddress)) {
if (!validator.isAddress(priceFeedAddress)) {
throw new Error(
`Provided priceFeedAddress is not a valid address: ${priceFeedAddress}`,
);
Expand All @@ -56,10 +51,8 @@ export class ChainlinkPlugin extends Web3PluginBase {
}

// Module Augmentation
declare module './reexported_web3_context' {
declare module 'web3' {
interface Web3Context {
chainlink: ChainlinkPlugin;
}
}

export { Web3Context };
3 changes: 0 additions & 3 deletions src/reexported_web3_context.ts

This file was deleted.

4 changes: 1 addition & 3 deletions test/black_box/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
"devDependencies": {
"jest": "^28.1.3",
"ts-jest": "^28.0.7",
"web3": "^4.0.1-rc.2",
"web3-core": "^4.0.1-rc.2",
"web3-eth": "^4.0.1-rc.2"
"web3": "^4.0.2-dev.af57eae.0"
}
}
10 changes: 8 additions & 2 deletions test/black_box/test/chainlink_plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { core, Web3, Web3Eth } from 'web3';
import { Web3, Web3Context, Web3Eth } from 'web3';

// https://github.com/ChainSafe/web3.js-plugin-chainlink/issues/15
// @ts-ignore
import { ChainlinkPlugin, MainnetPriceFeeds } from '@chainsafe/web3.js-chainlink-plugin';

describe('ChainlinkPlugin Tests', () => {
it('should register ChainlinkPlugin plugin on Web3Context instance', () => {
const web3Context = new core.Web3Context('http://127.0.0.1:8545');
const web3Context = new Web3Context('http://127.0.0.1:8545');
web3Context.registerPlugin(new ChainlinkPlugin());
expect(web3Context.chainlink).toBeDefined();
});

it('should register ChainlinkPlugin plugin on Web3Context instance', () => {
const web3Context = new Web3Context('http://127.0.0.1:8545');
web3Context.registerPlugin(new ChainlinkPlugin());
expect(web3Context.chainlink).toBeDefined();
});
Expand Down
Loading

0 comments on commit e09caf8

Please sign in to comment.