Skip to content

Commit

Permalink
Merge pull request #42 from CityOfZion/CU-86dt261uc
Browse files Browse the repository at this point in the history
CU-86dt261uc - Adjust NWM to use ETH RPC when running TESTNET (Temp fix while we migrate to BitQuery v2)
  • Loading branch information
melanke authored Mar 25, 2024
2 parents 85881d0 + 8116ee8 commit 06cb6dc
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 128 deletions.
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion packages/bs-ethereum/src/BSEthereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class BSEthereum<BSCustomName extends string = string>
}
this.network = network

if (network.type === 'custom') {
if (network.type !== 'mainnet') {
this.blockchainDataService = new RpcBDSEthereum(network)
} else {
this.blockchainDataService = new BitqueryBDSEthereum(network, this.bitqueryApiKey)
Expand Down
126 changes: 0 additions & 126 deletions packages/bs-ethereum/src/__tests__/BDSEthereum.spec.ts

This file was deleted.

106 changes: 106 additions & 0 deletions packages/bs-ethereum/src/__tests__/BitqueryBDSEthereum.spec.ts
Original file line number Diff line number Diff line change
@@ -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),
},
})
)
})
})
})
62 changes: 62 additions & 0 deletions packages/bs-ethereum/src/__tests__/RpcBDSEthereum.spec.ts
Original file line number Diff line number Diff line change
@@ -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),
},
})
)
})
})
})
2 changes: 1 addition & 1 deletion packages/bs-ethereum/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const NATIVE_ASSETS = commom

export const DEFAULT_URL_BY_NETWORK_TYPE: Record<NetworkType, string> = {
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',
}

Expand Down

0 comments on commit 06cb6dc

Please sign in to comment.