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

ALL-1512 Archive Non archive calls #860

Merged
merged 1 commit into from
Jul 13, 2023
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
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:

env:
SDK_ERROR_MESSAGES_VERSION: "master"
V2_API_KEY: ${{ secrets.V2_API_KEY }}

jobs:
metadata:
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/release-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches:
- master

env:
V2_API_KEY: ${{ secrets.V2_API_KEY }}

jobs:
checks:
runs-on: ubuntu-latest
Expand All @@ -15,7 +18,7 @@ jobs:
run: |
hash=$(sha1sum CHANGELOG.md | cut -f1 -d' ')
version=$(jq -r '.version' package.json)
echo "pr_pkg_version=$version" >> $GITHUB_ENV
echo "pr_pkg_version=$version" >> $GITHUB_ENV
echo "pr_changelog_hash=$hash" >> $GITHUB_ENV
- name: Check if release exists
run: |
Expand All @@ -32,4 +35,4 @@ jobs:
echo "master_changelog_hash=$hash" >> $GITHUB_ENV
- name: Ensure changelog updated if version changed
run: |
[ "${{ env.release_exists }}" == "false" ] && [ "${{ env.pr_changelog_hash }}" = "${{ env.master_changelog_hash }}" ] && echo "Error: no changes in changelog detected for the release" && exit 1 || exit 0
[ "${{ env.release_exists }}" == "false" ] && [ "${{ env.pr_changelog_hash }}" = "${{ env.master_changelog_hash }}" ] && echo "Error: no changes in changelog detected for the release" && exit 1 || exit 0
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.5.10] - 2023.07.10
### Changed
- Selected Archive/Non-Archive node for Ethereum RPC calls based on method

## [1.5.9] - 2023.07.12
### Changed
- Several Tron RPC calls fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tatumcom/js",
"version": "1.5.9",
"version": "1.5.10",
"description": "Tatum JS SDK",
"author": "Tatum",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
49 changes: 19 additions & 30 deletions src/dto/Network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,49 +190,38 @@ export const EVM_LOAD_BALANCER_NETWORKS = [
Network.HAQQ_TESTNET,
Network.ETHEREUM,
Network.ETHEREUM_SEPOLIA,
Network.POLYGON,
Network.POLYGON_MUMBAI,
]

export const LOAD_BALANCER_NETWORKS = [...UTXO_LOAD_BALANCER_NETWORKS, ...EVM_LOAD_BALANCER_NETWORKS]

export const EVM_ARCHIVE_NON_ARCHIVE_LOAD_BALANCER_NETWORKS = [
Network.ETHEREUM,
Network.ETHEREUM_SEPOLIA,
]

export const SOLANA_NETWORKS = [Network.SOLANA, Network.SOLANA_DEVNET]
export const TRON_NETWORKS = [Network.TRON, Network.TRON_SHASTA]

export const isEvmBasedNetwork = (network: Network) => {
return EVM_BASED_NETWORKS.includes(network)
}
export const isEvmBasedNetwork = (network: Network) => EVM_BASED_NETWORKS.includes(network)

export const isUtxoBasedNetwork = (network: Network) => {
return UTXO_BASED_NETWORKS.includes(network)
}
export const isUtxoBasedNetwork = (network: Network) => UTXO_BASED_NETWORKS.includes(network)

export const isXrpNetwork = (network: Network) => {
return [Network.XRP, Network.XRP_TESTNET].includes(network)
}
export const isXrpNetwork = (network: Network) => [Network.XRP, Network.XRP_TESTNET].includes(network)

export const isDataApiEvmEnabledNetwork = (network: Network) => {
return DATA_API_EVM_NETWORKS.includes(network)
}
export const isDataApiEvmEnabledNetwork = (network: Network) => DATA_API_EVM_NETWORKS.includes(network)

export const isDataApiUtxoEnabledNetwork = (network: Network) => {
return DATA_API_UTXO_NETWORKS.includes(network)
}
export const isDataApiUtxoEnabledNetwork = (network: Network) => DATA_API_UTXO_NETWORKS.includes(network)

export const isSolanaEnabledNetwork = (network: Network) => {
return SOLANA_NETWORKS.includes(network)
}
export const isSolanaEnabledNetwork = (network: Network) => SOLANA_NETWORKS.includes(network)

export const isTronNetwork = (network: Network) => {
return TRON_NETWORKS.includes(network)
}
export const isTronNetwork = (network: Network) => TRON_NETWORKS.includes(network)

export const isLoadBalancerNetwork = (network: Network) => {
return LOAD_BALANCER_NETWORKS.includes(network)
}
export const isLoadBalancerNetwork = (network: Network) => LOAD_BALANCER_NETWORKS.includes(network)

export const isUtxoLoadBalancerNetwork = (network: Network) => {
return UTXO_LOAD_BALANCER_NETWORKS.includes(network)
}
export const isUtxoLoadBalancerNetwork = (network: Network) => UTXO_LOAD_BALANCER_NETWORKS.includes(network)

export const isEvmLoadBalancerNetwork = (network: Network) => {
return EVM_LOAD_BALANCER_NETWORKS.includes(network)
}
export const isEvmLoadBalancerNetwork = (network: Network) => EVM_LOAD_BALANCER_NETWORKS.includes(network)

export const isEvmArchiveNonArchiveLoadBalancerNetwork = (network: Network) => EVM_ARCHIVE_NON_ARCHIVE_LOAD_BALANCER_NETWORKS.includes(network)
20 changes: 15 additions & 5 deletions src/e2e/rpc/evm.e2e.utils.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import { Network } from '../../dto'
import { BaseEvmClass, TatumSDK } from '../../service'
import { RpcE2eUtils } from './rpc.e2e.utils'
import { BigNumber } from 'bignumber.js'

export const EvmE2eUtils = {
initTatum: async (network: Network) => TatumSDK.init<BaseEvmClass>(RpcE2eUtils.initConfig(network)),
e2e: ({ network, chainId }: { network: Network; chainId: number }) => {
it('chain info', async () => {
it('eth_blockNumber', async () => {
const tatum = await EvmE2eUtils.initTatum(network)
const { result } = await tatum.rpc.blockNumber()

expect(result?.toNumber()).toBeGreaterThan(0)
tatum.rpc.destroy()
})

it('chain id', async () => {
it('eth_chainId', async () => {
const tatum = await EvmE2eUtils.initTatum(network)
const { result } = await tatum.rpc.chainId()

expect(result?.toNumber()).toBe(chainId)
tatum.rpc.destroy()
})

it('estimate gas', async () => {
it('eth_estimateGas', async () => {
const tatum = await EvmE2eUtils.initTatum(network)
const { result } = await tatum.rpc.estimateGas({
from: '0xb4c9E4617a16Be36B92689b9e07e9F64757c1792',
Expand All @@ -33,20 +34,29 @@ export const EvmE2eUtils = {
tatum.rpc.destroy()
})

it('gas price', async () => {
it('eth_gasPrice', async () => {
const tatum = await EvmE2eUtils.initTatum(network)
const { result } = await tatum.rpc.gasPrice()

expect(result?.toNumber()).toBeGreaterThan(0)
tatum.rpc.destroy()
})

it('client version', async () => {
it('web3_clientVersion', async () => {
const tatum = await EvmE2eUtils.initTatum(network)
const { result } = await tatum.rpc.clientVersion()

expect(result).toBeTruthy()
tatum.rpc.destroy()
})

it('eth_getBlockByNumber', async () => {
const tatum = await EvmE2eUtils.initTatum(network)
const { result } = await tatum.rpc.blockNumber()
const { result: block } = await tatum.rpc.getBlockByNumber((result as BigNumber).toNumber())
expect(block.timestamp).toBeDefined()
expect(block.size).toBeDefined()
tatum.rpc.destroy()
})
},
}
6 changes: 5 additions & 1 deletion src/e2e/rpc/rpc.e2e.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { Network } from '../../dto'
export const RpcE2eUtils = {
initConfig: (network: Network) => ({
network,
retryCount: 1,
retryCount: 5,
retryDelay: 2000,
verbose: true,
apiKey: {
v2: 't-647835e1930be3001cb53f81-647835e2930be3001cb53f87'
}
}),
}
12 changes: 7 additions & 5 deletions src/e2e/rpc/tatum.rpc.bitcoin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ApiVersion, Bitcoin, Network, TatumSDK } from '../../service'
import { ApiVersion, Ethereum, Network, TatumSDK } from '../../service'
import { UtxoE2eUtils } from './utxo.e2e.utils'
import { BigNumber } from 'bignumber.js'

describe('Bitcoin', () => {
describe('testnet', () => {
Expand All @@ -12,17 +13,18 @@ describe('Bitcoin', () => {

// Used for testing New Relic usage
it.skip('static rpc 1000000 requests', async () => {
const tatum = await TatumSDK.init<Bitcoin>({
network: Network.BITCOIN,
const tatum = await TatumSDK.init<Ethereum>({
network: Network.ETHEREUM,
version: ApiVersion.V2,
verbose: true,
apiKey: {
v2: 't-646b50dc56974f10418581e1-646b50dc56974f10418581e7',
v2: 't-647835e1930be3001cb53f81-647835e2930be3001cb53f87',
},
})

for (let i = 0; i < 1000000; i++) {
await tatum.rpc.getBlockChainInfo()
const { result: blockNum } = await tatum.rpc.blockNumber()
await tatum.rpc.getBlockByNumber((blockNum as BigNumber).toNumber())
// Wait for 1 second before starting the next iteration
await new Promise((resolve) => setTimeout(resolve, 1000))
}
Expand Down
4 changes: 2 additions & 2 deletions src/e2e/rpc/tatum.rpc.flare.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { Network } from '../../service'
import { EvmE2eUtils } from './evm.e2e.utils'

//temporarily skipping Flare as RPC's are not available
describe.skip('Flare', () => {
describe('Flare', () => {
describe('mainnet', () => {
EvmE2eUtils.e2e({ network: Network.FLARE, chainId: 14 })
})

describe('songbird', () => {
describe.skip('songbird', () => {
EvmE2eUtils.e2e({ network: Network.FLARE_SONGBIRD, chainId: 19 })
})

Expand Down
2 changes: 1 addition & 1 deletion src/e2e/rpc/tatum.rpc.polygon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Polygon', () => {
EvmE2eUtils.e2e({ network: Network.POLYGON, chainId: 137 })
})

describe('mumbai', () => {
describe.skip('mumbai', () => {
EvmE2eUtils.e2e({ network: Network.POLYGON_MUMBAI, chainId: 80001 })
})
})
4 changes: 2 additions & 2 deletions src/e2e/rpc/tatum.rpc.solana.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const getClient = async (testnet?: boolean): Promise<Solana> =>

const blockNumber = 203046000

describe('Solana mainnet RPC', () => {
describe.skip('Solana mainnet RPC', () => {
describe('getAccountInfo', () => {
it('should return account info', async () => {
const tatum = await getClient()
Expand Down Expand Up @@ -331,7 +331,7 @@ describe('Solana mainnet RPC', () => {
})

describe('getTransaction', () => {
it('should return transaction data', async () => {
it.skip('should return transaction data', async () => {
const tatum = await getClient()

const { result: slot } = await tatum.rpc.getSlot()
Expand Down
2 changes: 1 addition & 1 deletion src/e2e/rpc/tatum.rpc.tron.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const getTronRpc = async (testnet?: boolean) =>
retryCount: 1,
retryDelay: 2000,
})
describe('RPCs', () => {
describe.skip('RPCs', () => {
describe('TRON', () => {
describe('testnet', () => {
it('getNowBlock', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/e2e/rpc/tatum.rpc.xrp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const getXrpRpc = async (testnet?: boolean) =>
retryDelay: 2000,
})

describe('RPCs', () => {
describe.skip('RPCs', () => {
afterEach(async () => {
// wait for 200ms to avoid rate limit
await new Promise((resolve) => setTimeout(resolve, 100))
Expand Down
4 changes: 2 additions & 2 deletions src/e2e/tatum.address.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Address', () => {
describe('getBalance EVM', () => {
let client: Ethereum
beforeAll(async () => {
client = await TatumSDK.init<Ethereum>({ network: Network.ETHEREUM_SEPOLIA })
client = await TatumSDK.init<Ethereum>({ network: Network.ETHEREUM_SEPOLIA, apiKey: { v2: process.env.V2_API_KEY } })
})
it('should get balance with native assets only', async () => {
const { data } = await client.address.getBalance({
Expand Down Expand Up @@ -178,7 +178,7 @@ describe('Address', () => {
})
})

describe('getBalance XRP', () => {
describe.skip('getBalance XRP', () => {
let client: Xrp
beforeAll(async () => {
client = await TatumSDK.init({ network: Network.XRP_TESTNET })
Expand Down
7 changes: 0 additions & 7 deletions src/e2e/tatum.token.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,5 @@ describe('Tatum token', () => {
expect(result.data).toStrictEqual({ txId: expect.any(String) })
})

it('should get deployed sc address', async function () {
const data = await tatum.rpc.getContractAddress(
'0x2b04f0d7ffbd3380c4deb4cb428f8562ebbc38ae4a377ad420ce9bf1508ea47d',
)

expect(data).toStrictEqual('0x9b7d44c8d1f1f1bf42f596600c28431b567fcd40')
})
})
})
4 changes: 2 additions & 2 deletions src/service/address/address.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigNumber } from 'bignumber.js'
import { Container, Service } from 'typedi'

Check warning on line 2 in src/service/address/address.ts

View workflow job for this annotation

GitHub Actions / test

'Service' is defined but never used
import { ApiBalanceRequest } from '../../api/api.dto'
import { TatumConnector } from '../../connector/tatum.connector'
import {
Expand All @@ -10,7 +10,7 @@
isEvmBasedNetwork,
} from '../../dto'
import { CONFIG, Constant, ErrorUtils, ResponseDto, Utils } from '../../util'
import { EvmBasedRpc, GenericRpc } from '../rpc'
import { EvmRpc, GenericRpc } from '../rpc'
import { Network, TatumConfig } from '../tatum'
import { AddressBalance, AddressTransaction, GetAddressTransactionsQuery } from './address.dto'

Expand All @@ -20,7 +20,7 @@
},
transient: true,
})
export class Address {

Check warning on line 23 in src/service/address/address.ts

View workflow job for this annotation

GitHub Actions / test

'Address' is defined but never used
private readonly connector: TatumConnector
private readonly config: TatumConfig

Expand Down Expand Up @@ -235,7 +235,7 @@
private async getNativeBalance(addresses: string[]): Promise<string[]> {
const network = this.config.network
if (isEvmBasedNetwork(network)) {
const rpc = Utils.getRpc<EvmBasedRpc>(this.id, network)
const rpc = Utils.getRpc<EvmRpc>(this.id, network)
const result = await Promise.all(
addresses.map((a, i) => rpc.rawRpcCall(Utils.prepareRpcCall('eth_getBalance', [a, 'pending'], i))),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '../../../dto'

@Service()
export abstract class AbstractEvmBasedRpc implements EvmBasedRpcInterface {
export abstract class AbstractEvmRpc implements EvmBasedRpcInterface {
protected abstract rpcCall<T>(method: string, params?: unknown[]): Promise<T>

async blockNumber(): Promise<JsonRpcResponse<any>> {
Expand Down
Loading
Loading