diff --git a/jest.config.js b/jest.config.js index 228cf2b..45ca8dc 100644 --- a/jest.config.js +++ b/jest.config.js @@ -20,6 +20,7 @@ const config = { "lcov" ], testTimeout: 60000, + setupFiles: ['/jest.setup.js'] }; export default config; \ No newline at end of file diff --git a/jest.setup.js b/jest.setup.js new file mode 100644 index 0000000..921ad01 --- /dev/null +++ b/jest.setup.js @@ -0,0 +1 @@ +require('dotenv').config(); \ No newline at end of file diff --git a/package.json b/package.json index 95000f7..bf192c4 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "@apollo/client": "3.5.10", "@ethersproject/providers": "^5.7.2", "@types/jest": "^29.5.12", - "dotenv": "^16.4.5", "ethers": "^5.5.4", "graphql": "^16.8.2", "node-fetch": "^2.6.1", @@ -36,6 +35,7 @@ "devDependencies": { "@types/node": "^16.18.62", "@types/node-fetch": "^2.6.11", + "dotenv": "^16.4.5", "jest": "^29.7.0", "jest-config": "^29.7.0", "jest-coverage-badges": "^1.1.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4767779..86fd250 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,9 +17,6 @@ importers: '@types/jest': specifier: ^29.5.12 version: 29.5.12 - dotenv: - specifier: ^16.4.5 - version: 16.4.5 ethers: specifier: ^5.5.4 version: 5.7.2 @@ -39,6 +36,9 @@ importers: '@types/node-fetch': specifier: ^2.6.11 version: 2.6.11 + dotenv: + specifier: ^16.4.5 + version: 16.4.5 jest: specifier: ^29.7.0 version: 29.7.0(@types/node@16.18.90) diff --git a/src/graphql.service.ts b/src/graphql.service.ts index a9552e3..290703a 100644 --- a/src/graphql.service.ts +++ b/src/graphql.service.ts @@ -19,7 +19,7 @@ if (!fetchLib) { export class GraphQLService { private readonly apikey = process.env.REACT_APP_THE_GRAPH_API_KEY - private readonly uri = `https://gateway-arbitrum.network.thegraph.com/api/${this.apikey}/subgraphs/id` + private readonly uri = `https://gateway.thegraph.com/api/${this.apikey}/subgraphs/id` private withSubgraphId(subgraphId: string) { return `${this.uri}/${subgraphId}` @@ -67,11 +67,10 @@ export class GraphQLService { // Boba BNB 56288: { [EGraphQLService.LightBridge]: { - gql: 'https://graphql.bnb.boba.network/subgraphs/name/boba-bnb-l2/', - local: '', + gql: this.withSubgraphId('C3ShFVy1GV81GUb9u3Zw1rSQ7oJjegSF3LswvvYa3XgD'), }, [EGraphQLService.AnchorageBridge]: { - gql: 'https://graphql.bnb.boba.network/subgraphs/name/anchorage-bridging-boba-bnb', + gql: this.withSubgraphId('BmJU8RagxZSKoxwYFVScC7TaJZj9PHGvukXiJhES882a'), }, }, // BSC @@ -94,11 +93,11 @@ export class GraphQLService { // Boba BNB testnet 9728: { [EGraphQLService.LightBridge]: { - gql: 'https://graphql.testnet.bnb.boba.network/subgraphs/name/boba-bnb-l2-testnet/', + gql: this.withSubgraphId('HnbxKbpVhKeAWQ6jGUZ64wsjcsnEtyyVqU6QMiAsyPR7'), local: 'http://127.0.0.1:8002/subgraphs/name/boba/Bridges', }, [EGraphQLService.AnchorageBridge]: { - gql: 'https://graphql.testnet.bnb.boba.network/subgraphs/name/anchorage-bridging-boba-bnb-testnet/', + gql: this.withSubgraphId('46zszHi762PDutPntNcsLSDvms4eufEugwb26DkVCyzW'), }, }, // Arbitrum Sepolia @@ -131,10 +130,10 @@ export class GraphQLService { // Boba Sepolia 28882: { [EGraphQLService.AnchorageBridge]: { - gql: 'https://graphql.sepolia.boba.network/subgraphs/name/anchorage-bridging-sepolia', + gql: this.withSubgraphId('AKb9A3KPkMtwm9TPMtUxKH75yZXHyrY5PCwwCcmzQpMj'), }, [EGraphQLService.LightBridge]: { - gql: 'https://graphql.sepolia.boba.network/subgraphs/name/light-bridge-boba-sepolia', + gql: this.withSubgraphId('CdmAWxs3LDCnm4jekfcdPxaLsFynuZ3XgeuM7AcdU3xr'), local: '', }, }, diff --git a/tests/integration/anchorage.spec.ts b/tests/integration/anchorage.spec.ts index cd7ebb1..9e6c355 100644 --- a/tests/integration/anchorage.spec.ts +++ b/tests/integration/anchorage.spec.ts @@ -1,102 +1,220 @@ import {anchorageGraphQLService} from "../../src"; import {JsonRpcProvider} from "@ethersproject/providers"; -describe('Anchorage: Integration Test', function () { - it('should find: WithdrawalInitialized Events', async () => { - const res = await anchorageGraphQLService - .findWithdrawalsInitiated( - "0x3256bd6fc8b5fa48db95914d0df314465f3f7879", - 288) +const l2NetworkMap = [ + { + fromAddress: "0x3256bd6fc8b5fa48db95914d0df314465f3f7879", + chainId: 288, + networkName: 'Boba ETH', + isBnb: false, + withdrawalHash: "0x15fd4589111a601b83ce513c508ceb0fb6dbafa5b4f5b42f24bc793eebc67e72", + blocks: ["3210114"] + }, + { + fromAddress: "0x78b4507e3303caa40d20c23316e2f5795857ab85", + chainId: 56288, + networkName: 'Boba BNB', + isBnb: true, + blocks: [], + withdrawalHash: '' + }, + { + fromAddress: "0x81654daa2e297a140ca01f12367a4d9c9fc2bf51", + chainId: 28882, + networkName: 'Boba Sepolia', + isBnb: false, + withdrawalHash: "0xf641739d3dbb873ec526178b01d6162143a981488d0333f314b19533e1e1864b", + blocks: ["3876531"] + }, + { + fromAddress: "0x9703d3b2521f3de2d56831f3df9490cbb1487428", + chainId: 9728, + networkName: 'Boba BNB Testnet', + isBnb: true, + withdrawalHash: "0x02769bf89904174f8a4bf3da22b7c8dad6dccd5683ac4350874317f69be25b18", + blocks: ["715312"] + }, +] - // console.log(res); - expect(res[0].__typename).toEqual('WithdrawalInitiated') - expect(res[0].transactionHash_).toBeDefined(); - expect(res[0].block_number).toBeDefined(); - expect(res[0].timestamp_).toBeDefined(); - }); - it('should find: WithdrawalsInitiatedBnb Events', async () => { - const res = await anchorageGraphQLService - .findWithdrawalsInitiatedBnb( - "0x77151218e325b201addd457a5940d823b3daa2cd", - 9728) - expect(res[0].__typename).toEqual('ETHBridgeInitiated') - expect(res[0].transactionHash_).not.toBeDefined(); - expect(res[0].block_number).toBeDefined(); - expect(res[0].timestamp_).toBeDefined(); - }); - it('should find: WithdrawalProven Events', async () => { - const res = await anchorageGraphQLService - .findWithdrawalsProven( - ["0x5af94d274be0e1a51f32e056deaa3d9dcd6749af3507a9f457985271d971474a"], - 1) +const l1NetworkMap = [ + { + fromAddress: "0x3256bd6fc8b5fa48db95914d0df314465f3f7879", + chainId: 1, + networkName: 'ETH Mainnet', + withdrawalHash: ["0xf9ee30fb9e9da3b68ed392927bf7fdfc07239c2ac91cde3b30296b326ddf2333"] + }, + { + fromAddress: "0x9703d3b2521f3de2d56831f3df9490cbb1487428", + chainId: 11155111, + networkName: 'Sepolia', + withdrawalHash: ["0x93af1218baa50ff136e9b231360ad727828add096d6035eeae64416194706b11"] + }, + { + fromAddress: "0x9703d3b2521f3de2d56831f3df9490cbb1487428", + chainId: 97, + networkName: 'BNB Testnet', + withdrawalHash: ["0x0a41cc0067341b3cf425c14183ffce33d1f1c454587d949b1ee00d9fffd2d243"] + }, +] - expect(res[0].__typename).toEqual('WithdrawalProven') - expect(res[0].transactionHash_).toBeDefined(); - expect(res[0].withdrawalHash).toEqual('0x5af94d274be0e1a51f32e056deaa3d9dcd6749af3507a9f457985271d971474a'); - }); - it('should find: WithdrawalFinalized Events', async () => { - const res = await anchorageGraphQLService - .findWithdrawalsFinalized( - ["0xf9ee30fb9e9da3b68ed392927bf7fdfc07239c2ac91cde3b30296b326ddf2333", "0x10b3b0f1b2d20017e1c1036e1f57a7f0876c62dbf93a2bbeea8010a3fcffe4b2"], - 1) +const depositNeworkMap = [ + { + fromAddress: "0xd134a7d9485c1aac0cbf82718cf6d6e3fd130945", + name: "Mainnet L1 => L2", + config: { + L1: { + chainId: 1, + name: "ETH Mainnet" + }, + L2: { + chainId: 288, + name: "Boba ETH" + } + } + }, + { + fromAddress: "0xcba34cb1524a00cda30de92e373261f76abd5014", + name: "Sepolia L1 => L2", + config: { + L1: { + chainId: 11155111, + name: "ETH Sepolia" + }, + L2: { + chainId: 28882, + name: "Boba ETH Sepolia" + } + } + }, + { + fromAddress: "0x9703d3b2521f3de2d56831f3df9490cbb1487428", + name: "BNB Testnet L1 => L2", + config: { + L1: { + chainId: 97, + name: "BNB Testnet" + }, + L2: { + chainId: 9728, + name: "Boba BNB Testnet" + } + } + } +] + +describe('Anchorage Service: Integration Test', function () { + + describe('should find: DepositFinalized txs', () => { + depositNeworkMap.forEach((info) => { + it(`${info.name}`, async () => { + const res = await anchorageGraphQLService.queryDepositTransactions( + new JsonRpcProvider("https://boba-ethereum.gateway.tenderly.co"), + info.fromAddress, + info.config + ) - expect(res[0].__typename).toEqual('WithdrawalFinalized') - expect(res[0].transactionHash_).toBeDefined(); - expect(res[0].block_number).toBeDefined(); - expect(res[0].timestamp_).toBeDefined(); - expect(res[0].withdrawalHash).toEqual('0xf9ee30fb9e9da3b68ed392927bf7fdfc07239c2ac91cde3b30296b326ddf2333'); - }); - it('should find: MessagePassed Events via WithdrawalHash', async () => { - const res = await anchorageGraphQLService.findWithdrawalMessagedPassed( - '0x15fd4589111a601b83ce513c508ceb0fb6dbafa5b4f5b42f24bc793eebc67e72', - 288) + expect(res[0].originChainId).toBeDefined(); + expect(res[0].destinationChainId).toBeDefined(); + expect(res[0].from).toEqual(info.fromAddress); + expect(res[0].to).toEqual(info.fromAddress); + expect(res[0].action.status).toEqual("succeeded"); + }); + }) + }) - expect(res[0].__typename).toEqual("MessagePassed"); - expect(res[0].transactionHash_).toEqual("0x00182e7e904c2a1947c372c21cd1e0efde36badfa249552869861c588c5facf9") - expect(res[0].timestamp_).toEqual("1717425069") - }); - it('should find: MessagePassed Events via Block range', async () => { - const res = await anchorageGraphQLService.findWithdrawalMessagesPassed( - [ - "3210114", - "3210116" - ], 288) - expect(res[0].__typename).toEqual("MessagePassed"); - expect(res[0].transactionHash_).toEqual("0x00182e7e904c2a1947c372c21cd1e0efde36badfa249552869861c588c5facf9") - expect(res[0].timestamp_).toEqual("1717425069") - }); - it('should find: DepositTransactions', async () => { - const res = await anchorageGraphQLService.findWithdrawalMessagesPassed( - [ - "3210114", - "3210116" - ], 288) + describe('should find WithdrawalsInitiated events', () => { + l2NetworkMap.forEach((info) => { + test(`${info.networkName}`, async () => { + const res = await anchorageGraphQLService + .findWithdrawalsInitiated( + info.fromAddress, + info.chainId) + expect(res[0].__typename).toEqual('WithdrawalInitiated') + expect(res[0].transactionHash_).toBeDefined(); + expect(res[0].block_number).toBeDefined(); + expect(res[0].timestamp_).toBeDefined(); + }) + }) + }) - expect(res[0].__typename).toEqual("MessagePassed"); - expect(res[0].transactionHash_).toEqual("0x00182e7e904c2a1947c372c21cd1e0efde36badfa249552869861c588c5facf9") - expect(res[0].timestamp_).toEqual("1717425069") - }); - it('should find: DepositTransactions, map them and return the transactions', async () => { - const res = await anchorageGraphQLService.queryDepositTransactions( - new JsonRpcProvider("https://boba-ethereum.gateway.tenderly.co"), - "0xd134a7d9485c1aac0cbf82718cf6d6e3fd130945", - { - L1: { - chainId: 1, - name: "name" - }, - L2: { - chainId: 288, - name: "name" - } + describe('should find WithdrawalsInitiatedBnb events', () => { + l2NetworkMap.forEach((info) => { + if (!info.isBnb) { + return; } - ) + if (info.chainId === 56288) { + // skip incase of mainnet bnb as anchorage yet to be release on bnb mainnet. + return; + } + test(`${info.networkName}`, async () => { + const res = await anchorageGraphQLService + .findWithdrawalsInitiatedBnb( + info.fromAddress, + info.chainId) + const ethRes = res.find((d: any) => d.__typename === "ETHBridgeInitiated") + const ercRes = res.find((d: any) => d.__typename === "ERC20BridgeInitiated") + expect(ethRes.__typename).toEqual('ETHBridgeInitiated') + expect(ethRes.block_number).toBeDefined(); + expect(ethRes.timestamp_).toBeDefined(); + expect(ercRes.__typename).toEqual('ERC20BridgeInitiated') + expect(ercRes.transactionHash_).toBeDefined(); + expect(ercRes.block_number).toBeDefined(); + expect(ercRes.timestamp_).toBeDefined(); + }) + }) + }) + + describe('should find MessagePassed Events', () => { + l2NetworkMap.forEach((info) => { + if (info.chainId === 56288) { + // skip incase of mainnet bnb as anchorage yet to be release on bnb mainnet. + return; + } + test(`${info.networkName} using WithdrawalHash`, async () => { + const res = await anchorageGraphQLService.findWithdrawalMessagedPassed( + info.withdrawalHash, + info.chainId) + expect(res[0].__typename).toEqual("MessagePassed"); + expect(res[0].transactionHash_).toBeDefined() + expect(res[0].timestamp_).toBeDefined() + expect(res[0].block_number).toBeDefined() + }) + test(`${info.networkName} using block number`, async () => { + const res = await anchorageGraphQLService.findWithdrawalMessagesPassed( + info.blocks, + info.chainId) + expect(res[0].__typename).toEqual("MessagePassed"); + expect(res[0].transactionHash_).toBeDefined() + expect(res[0].timestamp_).toBeDefined() + expect(res[0].block_number).toBeDefined() + }) + }) + }) + + describe('should find: WithdrawalProven Events', () => { + l1NetworkMap.forEach((info) => { + it(`${info.networkName}`, async () => { + const res = await anchorageGraphQLService + .findWithdrawalsProven(info.withdrawalHash, info.chainId) + + expect(res[0].__typename).toEqual('WithdrawalProven') + expect(res[0].transactionHash_).toBeDefined(); + expect(res[0].withdrawalHash).toEqual(info.withdrawalHash[0]); + }); + }) + }) + describe('should find: WithdrawalFinalized Events', () => { + l1NetworkMap.forEach((info) => { + it(`${info.networkName}`, async () => { + const res = await anchorageGraphQLService + .findWithdrawalsFinalized(info.withdrawalHash, info.chainId) - expect(res[0].originChainId).toEqual(1); - expect(res[0].destinationChainId).toEqual(288); - expect(res[0].from).toEqual("0xd134a7d9485c1aac0cbf82718cf6d6e3fd130945"); - expect(res[0].to).toEqual("0xd134a7d9485c1aac0cbf82718cf6d6e3fd130945"); - expect(res[0].action.status).toEqual("succeeded"); - }); + expect(res[0].__typename).toEqual('WithdrawalFinalized') + expect(res[0].transactionHash_).toBeDefined(); + expect(res[0].withdrawalHash).toEqual(info.withdrawalHash[0]); + expect(res[0].success).toBeTruthy(); + }); + }) + }) }); \ No newline at end of file diff --git a/tests/integration/dao.spec.ts b/tests/integration/dao.spec.ts deleted file mode 100644 index 3b10ce4..0000000 --- a/tests/integration/dao.spec.ts +++ /dev/null @@ -1,5 +0,0 @@ -describe('DAO: Integration tests', function () { - it('should find: DAO proposals', function () { - - }); -}); \ No newline at end of file diff --git a/tests/unit/utils.spec.ts b/tests/unit/utils.spec.ts index 1e8a395..e870666 100644 --- a/tests/unit/utils.spec.ts +++ b/tests/unit/utils.spec.ts @@ -1,4 +1,4 @@ -const {filterLatestGroupedSupportedTokens} = require("../../src/utils"); +const { filterLatestGroupedSupportedTokens } = require("../../src/utils"); describe('GraphQL Utils', () => { it('should return the latest supported events only', () => {