Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CU-86dt261uc - Adjust NWM to use ETH RPC when running TESTNET (Temp fix while we migrate to BitQuery v2) #42

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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') {
melanke marked this conversation as resolved.
Show resolved Hide resolved
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(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a good practice to use process.env directly in the code. Consider using a config file or a configuration service to manage environment variables.

{ 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'
melanke marked this conversation as resolved.
Show resolved Hide resolved
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'
melanke marked this conversation as resolved.
Show resolved Hide resolved
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 = '-'
melanke marked this conversation as resolved.
Show resolved Hide resolved
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'
melanke marked this conversation as resolved.
Show resolved Hide resolved
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'
melanke marked this conversation as resolved.
Show resolved Hide resolved
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 })
melanke marked this conversation as resolved.
Show resolved Hide resolved

describe('RpcBDSEthereum', () => {
it('Should be able to get transaction', async () => {
const hash = '0x48eac645fac2280d7ac89a319372d7a38d52516f8b3003574bfaaed31b471ff3'
melanke marked this conversation as resolved.
Show resolved Hide resolved
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 = '-'
melanke marked this conversation as resolved.
Show resolved Hide resolved
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'
melanke marked this conversation as resolved.
Show resolved Hide resolved
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
Loading