diff --git a/common/changes/@cityofzion/bs-ethereum/CU-86dt261uc_2024-03-25-16-25.json b/common/changes/@cityofzion/bs-ethereum/CU-86dt261uc_2024-03-25-16-25.json new file mode 100644 index 0000000..aae6b83 --- /dev/null +++ b/common/changes/@cityofzion/bs-ethereum/CU-86dt261uc_2024-03-25-16-25.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@cityofzion/bs-ethereum", + "comment": "Change Goerli to Sepolia and call RPC using testnet instead of Bitquery", + "type": "patch" + } + ], + "packageName": "@cityofzion/bs-ethereum" +} \ No newline at end of file diff --git a/packages/bs-ethereum/src/BSEthereum.ts b/packages/bs-ethereum/src/BSEthereum.ts index f1214f4..0c79607 100644 --- a/packages/bs-ethereum/src/BSEthereum.ts +++ b/packages/bs-ethereum/src/BSEthereum.ts @@ -54,7 +54,7 @@ export class BSEthereum } this.network = network - if (network.type === 'custom') { + if (network.type !== 'mainnet') { this.blockchainDataService = new RpcBDSEthereum(network) } else { this.blockchainDataService = new BitqueryBDSEthereum(network, this.bitqueryApiKey) diff --git a/packages/bs-ethereum/src/__tests__/BDSEthereum.spec.ts b/packages/bs-ethereum/src/__tests__/BDSEthereum.spec.ts deleted file mode 100644 index b5d64fe..0000000 --- a/packages/bs-ethereum/src/__tests__/BDSEthereum.spec.ts +++ /dev/null @@ -1,126 +0,0 @@ -import { BlockchainDataService } from '@cityofzion/blockchain-service' -import { BitqueryBDSEthereum } from '../BitqueryBDSEthereum' -import { RpcBDSEthereum } from '../RpcBDSEthereum' -import { DEFAULT_URL_BY_NETWORK_TYPE } from '../constants' - -const bitqueryBDSEthereum = new BitqueryBDSEthereum( - { type: 'testnet', url: DEFAULT_URL_BY_NETWORK_TYPE.testnet }, - process.env.BITQUERY_API_KEY as string -) -const rpcBDSEthereum = new RpcBDSEthereum({ type: 'testnet', url: DEFAULT_URL_BY_NETWORK_TYPE.testnet }) - -describe('BDSEthereum', () => { - it.each([rpcBDSEthereum, bitqueryBDSEthereum])( - 'Should be able to get transaction - %s', - async (BDSEthereum: BlockchainDataService) => { - const hash = '0x43fa3015d077a13888409cfbd6228df8900abcd5314ff11ea6ce0c49e8b7c94d' - const transaction = await BDSEthereum.getTransaction(hash) - - expect(transaction).toEqual( - expect.objectContaining({ - block: expect.any(Number), - hash, - notifications: [], - time: expect.any(Number), - }) - ) - transaction.transfers.forEach(transfer => { - expect(transfer).toEqual( - expect.objectContaining({ - from: expect.any(String), - to: expect.any(String), - contractHash: expect.any(String), - amount: expect.any(String), - type: expect.any(String), - }) - ) - }) - }, - 10000 - ) - - it.each([bitqueryBDSEthereum])( - 'Should be able to get transactions of address - %s', - async (BDSEthereum: BlockchainDataService) => { - const address = '0x82B5Cd984880C8A821429cFFf89f36D35BaeBE89' - const response = await BDSEthereum.getTransactionsByAddress({ address: address, page: 1 }) - expect(response.totalCount).toBeGreaterThan(0) - response.transactions.forEach(transaction => { - expect(transaction).toEqual( - expect.objectContaining({ - block: expect.any(Number), - hash: expect.any(String), - notifications: [], - time: expect.any(Number), - fee: expect.any(String), - }) - ) - - transaction.transfers.forEach(transfer => { - expect(transfer).toEqual( - expect.objectContaining({ - from: expect.any(String), - to: expect.any(String), - contractHash: expect.any(String), - amount: expect.any(String), - type: expect.any(String), - }) - ) - }) - }) - }, - 10000 - ) - - it.each([bitqueryBDSEthereum, rpcBDSEthereum])( - 'Should be able to get eth info - %s', - async (BDSEthereum: BlockchainDataService) => { - const hash = '-' - const token = await BDSEthereum.getTokenInfo(hash) - - expect(token).toEqual({ - symbol: 'ETH', - name: 'Ethereum', - hash: '-', - decimals: 18, - }) - } - ) - - it.each([bitqueryBDSEthereum])( - 'Should be able to get token info - %s', - async (BDSEthereum: BlockchainDataService) => { - const hash = '0xBA62BCfcAaFc6622853cca2BE6Ac7d845BC0f2Dc' - const token = await BDSEthereum.getTokenInfo(hash) - - expect(token).toEqual({ - hash: '0xba62bcfcaafc6622853cca2be6ac7d845bc0f2dc', - name: 'FaucetToken', - symbol: 'FAU', - decimals: 18, - }) - } - ) - - it.each([bitqueryBDSEthereum, rpcBDSEthereum])( - 'Should be able to get balance - %s', - async (BDSEthereum: BlockchainDataService) => { - const address = '0x82B5Cd984880C8A821429cFFf89f36D35BaeBE89' - const balance = await BDSEthereum.getBalance(address) - - balance.forEach(balance => { - expect(balance).toEqual( - expect.objectContaining({ - amount: expect.any(String), - token: { - hash: expect.any(String), - name: expect.any(String), - symbol: expect.any(String), - decimals: expect.any(Number), - }, - }) - ) - }) - } - ) -}) diff --git a/packages/bs-ethereum/src/__tests__/BitqueryBDSEthereum.spec.ts b/packages/bs-ethereum/src/__tests__/BitqueryBDSEthereum.spec.ts new file mode 100644 index 0000000..38f866d --- /dev/null +++ b/packages/bs-ethereum/src/__tests__/BitqueryBDSEthereum.spec.ts @@ -0,0 +1,106 @@ +import { BitqueryBDSEthereum } from '../BitqueryBDSEthereum' +import { DEFAULT_URL_BY_NETWORK_TYPE } from '../constants' + +const bitqueryBDSEthereum = new BitqueryBDSEthereum( + { type: 'testnet', url: DEFAULT_URL_BY_NETWORK_TYPE.testnet }, + process.env.BITQUERY_API_KEY as string +) + +describe('BitqueryBDSEthereum', () => { + it('Should be able to get transaction - %s', async () => { + const hash = '0x43fa3015d077a13888409cfbd6228df8900abcd5314ff11ea6ce0c49e8b7c94d' + const transaction = await bitqueryBDSEthereum.getTransaction(hash) + + expect(transaction).toEqual( + expect.objectContaining({ + block: expect.any(Number), + hash, + notifications: [], + time: expect.any(Number), + }) + ) + transaction.transfers.forEach(transfer => { + expect(transfer).toEqual( + expect.objectContaining({ + from: expect.any(String), + to: expect.any(String), + contractHash: expect.any(String), + amount: expect.any(String), + type: expect.any(String), + }) + ) + }) + }, 10000) + + it('Should be able to get transactions of address - %s', async () => { + const address = '0x82B5Cd984880C8A821429cFFf89f36D35BaeBE89' + const response = await bitqueryBDSEthereum.getTransactionsByAddress({ address: address, page: 1 }) + expect(response.totalCount).toBeGreaterThan(0) + response.transactions.forEach(transaction => { + expect(transaction).toEqual( + expect.objectContaining({ + block: expect.any(Number), + hash: expect.any(String), + notifications: [], + time: expect.any(Number), + fee: expect.any(String), + }) + ) + + transaction.transfers.forEach(transfer => { + expect(transfer).toEqual( + expect.objectContaining({ + from: expect.any(String), + to: expect.any(String), + contractHash: expect.any(String), + amount: expect.any(String), + type: expect.any(String), + }) + ) + }) + }) + }, 10000) + + it('Should be able to get eth info - %s', async () => { + const hash = '-' + const token = await bitqueryBDSEthereum.getTokenInfo(hash) + + expect(token).toEqual({ + symbol: 'ETH', + name: 'Ethereum', + hash: '-', + decimals: 18, + }) + }) + + it('Should be able to get token info - %s', async () => { + const hash = '0xBA62BCfcAaFc6622853cca2BE6Ac7d845BC0f2Dc' + const token = await bitqueryBDSEthereum.getTokenInfo(hash) + + expect(token).toEqual({ + hash: '0xba62bcfcaafc6622853cca2be6ac7d845bc0f2dc', + name: 'FaucetToken', + symbol: 'FAU', + decimals: 18, + }) + }) + + it('Should be able to get balance - %s', async () => { + const address = '0x82B5Cd984880C8A821429cFFf89f36D35BaeBE89' + const balance = await bitqueryBDSEthereum.getBalance(address) + + balance.forEach(balance => { + expect(balance).toEqual( + expect.objectContaining({ + amount: expect.any(String), + token: { + hash: expect.any(String), + name: expect.any(String), + symbol: expect.any(String), + decimals: expect.any(Number), + }, + }) + ) + }) + }) +}) diff --git a/packages/bs-ethereum/src/__tests__/RpcBDSEthereum.spec.ts b/packages/bs-ethereum/src/__tests__/RpcBDSEthereum.spec.ts new file mode 100644 index 0000000..c76ab3a --- /dev/null +++ b/packages/bs-ethereum/src/__tests__/RpcBDSEthereum.spec.ts @@ -0,0 +1,62 @@ +import { RpcBDSEthereum } from '../RpcBDSEthereum' +import { DEFAULT_URL_BY_NETWORK_TYPE } from '../constants' + +const rpcBDSEthereum = new RpcBDSEthereum({ type: 'testnet', url: DEFAULT_URL_BY_NETWORK_TYPE.testnet }) + +describe('RpcBDSEthereum', () => { + it('Should be able to get transaction', async () => { + const hash = '0x48eac645fac2280d7ac89a319372d7a38d52516f8b3003574bfaaed31b471ff3' + const transaction = await rpcBDSEthereum.getTransaction(hash) + + expect(transaction).toEqual( + expect.objectContaining({ + block: expect.any(Number), + hash, + notifications: [], + time: expect.any(Number), + }) + ) + transaction.transfers.forEach(transfer => { + expect(transfer).toEqual( + expect.objectContaining({ + from: expect.any(String), + to: expect.any(String), + contractHash: expect.any(String), + amount: expect.any(String), + type: expect.any(String), + }) + ) + }) + }) + + it('Should be able to get eth info', async () => { + const hash = '-' + const token = await rpcBDSEthereum.getTokenInfo(hash) + + expect(token).toEqual({ + symbol: 'ETH', + name: 'Ethereum', + hash: '-', + decimals: 18, + }) + }) + + it('Should be able to get balance', async () => { + const address = '0xbA65F285D1F9E0bf76Ab01211547979a3b60011A' + const balance = await rpcBDSEthereum.getBalance(address) + + balance.forEach(balance => { + expect(balance).toEqual( + expect.objectContaining({ + amount: expect.any(String), + token: { + hash: expect.any(String), + name: expect.any(String), + symbol: expect.any(String), + decimals: expect.any(Number), + }, + }) + ) + }) + }) +}) diff --git a/packages/bs-ethereum/src/constants.ts b/packages/bs-ethereum/src/constants.ts index 03fa0c2..e216fc9 100644 --- a/packages/bs-ethereum/src/constants.ts +++ b/packages/bs-ethereum/src/constants.ts @@ -13,7 +13,7 @@ export const NATIVE_ASSETS = commom export const DEFAULT_URL_BY_NETWORK_TYPE: Record = { mainnet: 'https://ethereum-mainnet-rpc.allthatnode.com', - testnet: 'https://ethereum-goerli.publicnode.com', + testnet: 'https://ethereum-sepolia-rpc.publicnode.com', custom: 'http://127.0.0.1:8545', }