diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 93e2d1f..22fc322 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,7 +10,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: - node-version: '14' + node-version: '18.x' - name: Cache node modules uses: actions/cache@v2 env: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 09fd977..5b321a4 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -12,7 +12,7 @@ jobs: # Setup .npmrc file to publish to npm - uses: actions/setup-node@v2 with: - node-version: '16.x' + node-version: '18.x' registry-url: 'https://registry.npmjs.org' - run: npm install diff --git a/.github/workflows/test-rpc-availability.yml b/.github/workflows/test-rpc-availability.yml new file mode 100644 index 0000000..5413d66 --- /dev/null +++ b/.github/workflows/test-rpc-availability.yml @@ -0,0 +1,41 @@ +name: Test RPC Availability + +on: + push: + branches: + - '*' # Matches all branches + schedule: + # Runs at 05:00 UTC every day + - cron: '0 5 * * *' + +jobs: + daily-job: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '18.x' + - name: Cache node modules + uses: actions/cache@v2 + env: + cache-name: cache-node-modules + with: + # npm cache files are stored in `~/.npm` on Linux/macOS + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + - name: npm install + run: | + npm install + - name: npm run build + run: | + npm run build + - name: Run Tests + run: | + yarn test:rpcs + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1afb2d0..f4c0a11 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: - node-version: '14' + node-version: '18.x' - name: Cache node modules uses: actions/cache@v2 env: diff --git a/dist/esm/index.js b/dist/esm/index.js index 08f26a5..ec840d3 100644 --- a/dist/esm/index.js +++ b/dist/esm/index.js @@ -91,9 +91,9 @@ var ethereum = { if(address) { return `https://etherscan.io/address/${address}` } }, endpoints: [ // make sure provider supports batch size of 50 batch requests! - 'https://eth.rpc.blxrbdn.com', 'https://eth.llamarpc.com', - 'https://ethereum.publicnode.com' + 'https://ethereum.publicnode.com', + 'https://ethereum.rpc.subquery.network/public' ], tokens: [ // only major tokens {"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", "symbol": "ETH", "name": "Ether", "decimals": 18, "logo": currencyLogo$5, "type": "NATIVE"}, @@ -366,7 +366,8 @@ var avalanche = { }, endpoints: [ // make sure provider supports batch size of 50 batch requests! 'https://avalanche-c-chain-rpc.publicnode.com', - 'https://endpoints.omniatech.io/v1/avax/mainnet/public' + 'https://avalanche-c-chain.publicnode.com', + 'https://avalanche-api.flare.network/ext/bc/C/rpc', ], tokens: [ // only major tokens {"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", "symbol": "AVAX", "name": "Avalanche", "decimals": 18, "logo": currencyLogo$1, "type": "NATIVE"}, @@ -572,8 +573,7 @@ var worldchain = { }, endpoints: [ // make sure provider supports batch size of 50 batch requests! 'https://worldchain-mainnet.g.alchemy.com/public', - 'https://480.rpc.thirdweb.com', - 'https://worldchain-mainnet.blastapi.io/1b1a6314-79bf-4afe-b48b-c943fca35292' + 'https://480.rpc.thirdweb.com' ], tokens: [ // only major tokens {"address": "0x2cFc85d8E48F8EAB294be644d9E25C3030863003", "symbol": "WLD", "name": "Worldcoin", "decimals": 18, "logo": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/optimism/assets/0xdC6fF44d5d932Cbd77B52E5612Ba0529DC6226F1/logo.png", "type": "20"}, diff --git a/dist/umd/index.js b/dist/umd/index.js index d62fd68..561d476 100644 --- a/dist/umd/index.js +++ b/dist/umd/index.js @@ -97,9 +97,9 @@ if(address) { return `https://etherscan.io/address/${address}` } }, endpoints: [ // make sure provider supports batch size of 50 batch requests! - 'https://eth.rpc.blxrbdn.com', 'https://eth.llamarpc.com', - 'https://ethereum.publicnode.com' + 'https://ethereum.publicnode.com', + 'https://ethereum.rpc.subquery.network/public' ], tokens: [ // only major tokens {"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", "symbol": "ETH", "name": "Ether", "decimals": 18, "logo": currencyLogo$5, "type": "NATIVE"}, @@ -372,7 +372,8 @@ }, endpoints: [ // make sure provider supports batch size of 50 batch requests! 'https://avalanche-c-chain-rpc.publicnode.com', - 'https://endpoints.omniatech.io/v1/avax/mainnet/public' + 'https://avalanche-c-chain.publicnode.com', + 'https://avalanche-api.flare.network/ext/bc/C/rpc', ], tokens: [ // only major tokens {"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", "symbol": "AVAX", "name": "Avalanche", "decimals": 18, "logo": currencyLogo$1, "type": "NATIVE"}, @@ -578,8 +579,7 @@ }, endpoints: [ // make sure provider supports batch size of 50 batch requests! 'https://worldchain-mainnet.g.alchemy.com/public', - 'https://480.rpc.thirdweb.com', - 'https://worldchain-mainnet.blastapi.io/1b1a6314-79bf-4afe-b48b-c943fca35292' + 'https://480.rpc.thirdweb.com' ], tokens: [ // only major tokens {"address": "0x2cFc85d8E48F8EAB294be644d9E25C3030863003", "symbol": "WLD", "name": "Worldcoin", "decimals": 18, "logo": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/optimism/assets/0xdC6fF44d5d932Cbd77B52E5612Ba0529DC6226F1/logo.png", "type": "20"}, diff --git a/package.json b/package.json index 1b20a6a..66d4629 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-blockchains", "moduleName": "Web3Blockchains", - "version": "9.7.2", + "version": "9.7.3", "description": "JavaScript library containing aggregated information and abstractions for web3 blockchains.", "main": "dist/umd/index.js", "module": "dist/esm/index.js", @@ -15,7 +15,8 @@ "lint:fix": "eslint \"src/**/*.{js,jsx,ts,tsx}\" --fix", "dev": "rollup -c rollup.dev.config.js -w", "test:units": "yarn build && npx jest --no-cache", - "test": "yarn test:units" + "test": "yarn test:units", + "test:rpcs": "npx jest --no-cache test.rpc.availability.spec.js" }, "repository": "git@github.com:DePayFi/web3-blockchains.git", "keywords": [ @@ -32,7 +33,7 @@ "dependencies": {}, "peerDependencies": {}, "engines": { - "node": ">=10" + "node": ">=18" }, "devDependencies": { "@babel/core": "^7.12.9", @@ -43,6 +44,7 @@ "@rollup/plugin-sucrase": "^3.1.0", "babel-loader": "^8.2.2", "babel-preset-env": "^1.7.0", + "cross-fetch": "^4.0.0", "eslint": "^7.15.0", "eslint-plugin-import": "^2.22.1", "eslint-webpack-plugin": "^3.0.1", diff --git a/src/blockchains/avalanche.js b/src/blockchains/avalanche.js index e3897e9..eeea190 100644 --- a/src/blockchains/avalanche.js +++ b/src/blockchains/avalanche.js @@ -35,7 +35,8 @@ export default { }, endpoints: [ // make sure provider supports batch size of 50 batch requests! 'https://avalanche-c-chain-rpc.publicnode.com', - 'https://endpoints.omniatech.io/v1/avax/mainnet/public' + 'https://avalanche-c-chain.publicnode.com', + 'https://avalanche-api.flare.network/ext/bc/C/rpc', ], tokens: [ // only major tokens {"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", "symbol": "AVAX", "name": "Avalanche", "decimals": 18, "logo": currencyLogo, "type": "NATIVE"}, diff --git a/src/blockchains/ethereum.js b/src/blockchains/ethereum.js index 59f229f..74d8788 100644 --- a/src/blockchains/ethereum.js +++ b/src/blockchains/ethereum.js @@ -35,9 +35,9 @@ export default { if(address) { return `https://etherscan.io/address/${address}` } }, endpoints: [ // make sure provider supports batch size of 50 batch requests! - 'https://eth.rpc.blxrbdn.com', 'https://eth.llamarpc.com', - 'https://ethereum.publicnode.com' + 'https://ethereum.publicnode.com', + 'https://ethereum.rpc.subquery.network/public' ], tokens: [ // only major tokens {"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", "symbol": "ETH", "name": "Ether", "decimals": 18, "logo": currencyLogo, "type": "NATIVE"}, diff --git a/src/blockchains/worldchain.js b/src/blockchains/worldchain.js index 33df44e..97b4d0d 100644 --- a/src/blockchains/worldchain.js +++ b/src/blockchains/worldchain.js @@ -35,8 +35,7 @@ export default { }, endpoints: [ // make sure provider supports batch size of 50 batch requests! 'https://worldchain-mainnet.g.alchemy.com/public', - 'https://480.rpc.thirdweb.com', - 'https://worldchain-mainnet.blastapi.io/1b1a6314-79bf-4afe-b48b-c943fca35292' + 'https://480.rpc.thirdweb.com' ], tokens: [ // only major tokens {"address": "0x2cFc85d8E48F8EAB294be644d9E25C3030863003", "symbol": "WLD", "name": "Worldcoin", "decimals": 18, "logo": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/optimism/assets/0xdC6fF44d5d932Cbd77B52E5612Ba0529DC6226F1/logo.png", "type": "20"}, diff --git a/tests/setup.js b/tests/setup.js index abf6292..15c5824 100644 --- a/tests/setup.js +++ b/tests/setup.js @@ -1 +1,3 @@ import 'regenerator-runtime/runtime' + +global.fetch = require('cross-fetch') diff --git a/tests/units/test.rpc.availability.spec.js b/tests/units/test.rpc.availability.spec.js new file mode 100644 index 0000000..0f506fa --- /dev/null +++ b/tests/units/test.rpc.availability.spec.js @@ -0,0 +1,55 @@ +import Blockchains from 'src'; + +describe('test RPC availability', () => { + + Blockchains.all.filter((blockchain)=>!['solana'].includes(blockchain.name)).forEach((blockchain)=>{ + + describe(blockchain.label, ()=>{ + + blockchain.endpoints.forEach((endpoint)=>{ + + it(`${endpoint} works with up to 50 subrequests`, async()=>{ + + let response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify( + Array.from({ length: 50 }, (_, index)=> index+1).map((index)=> { + return( + { + "jsonrpc": "2.0", + "id": index, + "method": "eth_call", + "params": [ + { + "to":"0x1f98431c8ad98523631ae4a59f267346ea31f984", + "data":"0x1698ee82000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000064" + } ,"latest" + ] + } + ) + }) + ) + }) + + if (!response.ok) { + throw new Error('Network response was not ok') + } + + let json = await response.json() + await Promise.all(json.map((item)=>{ + return new Promise((resolve, reject)=>{ + if(item.result && !item.error){ + resolve() + } else { + reject('ERROR FOUND') + } + }) + })) + }) + }) + }) + }) +}) diff --git a/yarn.lock b/yarn.lock index 65ae0d2..cc8119f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2029,6 +2029,13 @@ core-js@^2.4.0: resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.12.tgz#d9333dfa7b065e347cc5682219d6f690859cc2ec" integrity sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ== +cross-fetch@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-4.0.0.tgz#f037aef1580bb3a1a35164ea2a848ba81b445983" + integrity sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g== + dependencies: + node-fetch "^2.6.12" + cross-spawn@^7.0.2: version "7.0.3" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" @@ -3250,6 +3257,13 @@ natural-compare@^1.4.0: resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc= +node-fetch@^2.6.12: + version "2.7.0" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d" + integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A== + dependencies: + whatwg-url "^5.0.0" + node-modules-regexp@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/node-modules-regexp/-/node-modules-regexp-1.0.0.tgz#8d9dbe28964a4ac5712e9131642107c71e90ec40" @@ -4024,6 +4038,11 @@ tr46@^3.0.0: dependencies: punycode "^2.1.1" +tr46@~0.0.3: + version "0.0.3" + resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" + integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw== + ts-interface-checker@^0.1.9: version "0.1.13" resolved "https://registry.yarnpkg.com/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz#784fd3d679722bc103b1b4b8030bcddb5db2a699" @@ -4134,6 +4153,11 @@ w3c-xmlserializer@^3.0.0: dependencies: xml-name-validator "^4.0.0" +webidl-conversions@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" + integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ== + webidl-conversions@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-7.0.0.tgz#256b4e1882be7debbf01d05f0aa2039778ea080a" @@ -4167,6 +4191,14 @@ whatwg-url@^11.0.0: tr46 "^3.0.0" webidl-conversions "^7.0.0" +whatwg-url@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d" + integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw== + dependencies: + tr46 "~0.0.3" + webidl-conversions "^3.0.0" + which-boxed-primitive@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz#13757bc89b209b049fe5d86430e21cf40a89a8e6"