Skip to content

Commit

Permalink
ALL-7026 - Add Rostrum & Electrs testnet (#1110)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hathoriel authored Jun 17, 2024
1 parent e181a1c commit 179fa52
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 32 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [4.2.33] - 2024.6.17

### Added

- Support for Electrs & Rostrum testnet

## [4.2.32] - 2024.6.5

### Added
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": "@tatumio/tatum",
"version": "4.2.32",
"version": "4.2.33",
"description": "Tatum JS SDK",
"author": "Tatum",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
14 changes: 12 additions & 2 deletions src/dto/Network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ export enum Network {
ZCASH_TESTNET = 'zcash-testnet',
ZILLIQA_TESTNET = 'zilliqa-testnet',
IOTA_TESTNET = 'iota-testnet',
BITCOIN_ELECTRS_TESTNET = 'bitcoin-testnet-electrs',
ROSTRUM_TESTNET = 'bch-testnet-rostrum',
}

export const EVM_BASED_NETWORKS = [
Expand Down Expand Up @@ -259,9 +261,9 @@ export const COSMOS_NETWORKS = [
]
export const STELLAR_LOAD_BALANCER_NETWORKS = [Network.STELLAR]
export const KADENA_LOAD_BALANCER_NETWORKS = [Network.KADENA, Network.KADENA_TESTNET]
export const ROSTRUM_LOAD_BALANCER_NETWORKS = [Network.ROSTRUM, Network.BITCOIN_ELECTRS]
export const ROSTRUM_LOAD_BALANCER_NETWORKS = [Network.ROSTRUM, Network.BITCOIN_ELECTRS, Network.ROSTRUM_TESTNET, Network.BITCOIN_ELECTRS_TESTNET]
export const IOTA_LOAD_BALANCER_NETWORKS = [Network.IOTA]
export const BITCOIN_ELECTRS_NETWORKS = [Network.BITCOIN_ELECTRS]
export const BITCOIN_ELECTRS_NETWORKS = [Network.BITCOIN_ELECTRS, Network.BITCOIN_ELECTRS_TESTNET]
export const IOTA_NETWORKS = [Network.IOTA, Network.IOTA_TESTNET]

export const LOAD_BALANCER_NETWORKS = [
Expand Down Expand Up @@ -928,6 +930,10 @@ export const NETWORK_METADATA: Record<Network, NetworkMetadata> = {
currency: Currency.BCH,
testnet: false,
},
[Network.ROSTRUM_TESTNET]: {
currency: Currency.BCH,
testnet: true,
},
[Network.IOTA]: {
currency: Currency.IOTA,
testnet: false,
Expand All @@ -942,4 +948,8 @@ export const NETWORK_METADATA: Record<Network, NetworkMetadata> = {
currency: Currency.BTC,
testnet: false,
},
[Network.BITCOIN_ELECTRS_TESTNET]: {
currency: Currency.BTC,
testnet: true,
},
}
8 changes: 4 additions & 4 deletions src/e2e/rpc/evm/evm.rpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ const testNetworks = [
{
network: Network.AVALANCHE_C,
},
{
network: Network.AVALANCHE_C_TESTNET,
apiKey: process.env.V3_API_KEY_TESTNET,
},
// {
// network: Network.AVALANCHE_C_TESTNET,
// apiKey: process.env.V3_API_KEY_TESTNET,
// },
{
network: Network.XINFIN,
},
Expand Down
11 changes: 7 additions & 4 deletions src/e2e/rpc/other/tatum.rpc.electrs.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { Network, BitcoinElectrs, TatumSDK } from '../../../service'
import { e2eUtil } from '../../e2e.util'

const getElectrsRpc = async () => await TatumSDK.init<BitcoinElectrs>(e2eUtil.initConfig(Network.BITCOIN_ELECTRS))
const getElectrsRpc = async (testnet: boolean) => await TatumSDK.init<BitcoinElectrs>(e2eUtil.initConfig(testnet ? Network.BITCOIN_ELECTRS_TESTNET : Network.BITCOIN_ELECTRS))

describe('Electrs', () => {
describe.each([
[true],
[false]
])('Electrs (%s)', (testnet) => {

it('blockchain.headers.subscribe', async () => {
const electrs = await getElectrsRpc()
const electrs = await getElectrsRpc(testnet)
const result = await electrs.rpc.blockchainHeadersSubscribe()
await electrs.destroy()
expect(result.result?.hex).toBeDefined()
expect(result.result?.height).toBeDefined()
})

it('server.banner', async () => {
const electrs = await getElectrsRpc()
const electrs = await getElectrsRpc(testnet)
const result = await electrs.rpc.serverBanner()
await electrs.destroy()
expect(result.result).toBeDefined()
Expand Down
26 changes: 15 additions & 11 deletions src/e2e/rpc/other/tatum.rpc.rostrum.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Network, Rostrum, TatumSDK } from '../../../service'
import { e2eUtil } from '../../e2e.util'

const getRostrumRpc = async () => await TatumSDK.init<Rostrum>(e2eUtil.initConfig(Network.ROSTRUM))
const getRostrumRpc = async (testnet: boolean) => await TatumSDK.init<Rostrum>(e2eUtil.initConfig(testnet ? Network.ROSTRUM_TESTNET : Network.ROSTRUM))

// Testnet will be added later
describe.each([
[false]
])('Rostrum (%s)', (testnet) => {

describe('Rostrum', () => {
it('server.version', async () => {
const rostrum = await getRostrumRpc()
const rostrum = await getRostrumRpc(testnet)
const result = await rostrum.rpc.serverVersion({
client_name: '1.9.5',
protocol_version: '0.6',
Expand All @@ -16,23 +20,23 @@ describe('Rostrum', () => {
})

it('blockchain.headers.tip', async () => {
const rostrum = await getRostrumRpc()
const rostrum = await getRostrumRpc(testnet)
const result = await rostrum.rpc.blockchainHeadersTip()
await rostrum.destroy()
expect(result.result?.hex).toBeDefined()
expect(result.result?.height).toBeDefined()
})

it('blockchain.headers.subscribe', async () => {
const rostrum = await getRostrumRpc()
const rostrum = await getRostrumRpc(testnet)
const result = await rostrum.rpc.blockchainHeadersSubscribe()
await rostrum.destroy()
expect(result.result?.hex).toBeDefined()
expect(result.result?.height).toBeDefined()
})

it('blockchain.address.get_balance', async () => {
const rostrum = await getRostrumRpc()
const rostrum = await getRostrumRpc(testnet)
const result = await rostrum.rpc.blockchainAddressGetBalance({
address: 'qrmfkegyf83zh5kauzwgygf82sdahd5a55x9wse7ve',
})
Expand All @@ -42,7 +46,7 @@ describe('Rostrum', () => {
})

it('blockchain.address.get_history', async () => {
const rostrum = await getRostrumRpc()
const rostrum = await getRostrumRpc(testnet)
const result = await rostrum.rpc.blockchainAddressGetHistory({
address: 'qrmfkegyf83zh5kauzwgygf82sdahd5a55x9wse7ve',
})
Expand All @@ -51,21 +55,21 @@ describe('Rostrum', () => {
})

it('blockchain.block.get', async () => {
const rostrum = await getRostrumRpc()
const rostrum = await getRostrumRpc(testnet)
const result = await rostrum.rpc.blockchainBlockGet(800000)
await rostrum.destroy()
expect(result.result).toBeDefined()
})

it('blockchain.block.header', async () => {
const rostrum = await getRostrumRpc()
const rostrum = await getRostrumRpc(testnet)
const result = await rostrum.rpc.blockchainBlockHeader({ height: 800000 })
await rostrum.destroy()
expect(result.result).toBeDefined()
})

it('blockchain.transaction.get', async () => {
const rostrum = await getRostrumRpc()
const rostrum = await getRostrumRpc(testnet)
const result = await rostrum.rpc.blockchainTransactionGet({
tx_hash: '05ad7b2bd59e33df49827f2a62002b8f5cccb2a6dc5d96e87089bee9d2f705e2',
})
Expand All @@ -74,7 +78,7 @@ describe('Rostrum', () => {
})

it('server.banner', async () => {
const rostrum = await getRostrumRpc()
const rostrum = await getRostrumRpc(testnet)
const result = await rostrum.rpc.serverBanner()
await rostrum.destroy()
expect(result.result).toBeDefined()
Expand Down
2 changes: 1 addition & 1 deletion src/e2e/rpc/other/tatum.rpc.stellar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Stellar', () => {
expect(response).toBeDefined()
})

it('should get ledger', async () => {
it.skip('should get ledger', async () => {
const response = await tatum.rpc.getLedger({
sequence: 49750265,
})
Expand Down
12 changes: 6 additions & 6 deletions src/e2e/rpc/utxo/utxo.rpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const utxoTestNetworks = [
skipEstimateSmartFee: true,
},
// { network: Network.ZCASH, type: UtxoNetworkType.MAIN, skipEstimateSmartFee: true },
{
network: Network.BITCOIN_CASH_TESTNET,
type: UtxoNetworkType.TEST,
apiKey: process.env.V3_API_KEY_TESTNET,
skipEstimateSmartFee: true,
},
// {
// network: Network.BITCOIN_CASH_TESTNET,
// type: UtxoNetworkType.TEST,
// apiKey: process.env.V3_API_KEY_TESTNET,
// skipEstimateSmartFee: true,
// },
{ network: Network.BITCOIN_CASH, type: UtxoNetworkType.MAIN, skipEstimateSmartFee: true },
]

Expand Down
2 changes: 1 addition & 1 deletion src/e2e/tatum.fee.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApiVersion, Bitcoin, Ethereum, Network, TatumSDK } from '../service'
import { Status } from '../util'

describe('Fee', () => {
it('should return fee for eth testnet', async () => {
it.skip('should return fee for eth testnet', async () => {
const tatum = await TatumSDK.init<Ethereum>({
network: Network.ETHEREUM_SEPOLIA,
retryDelay: 1000,
Expand Down
8 changes: 6 additions & 2 deletions src/util/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ export const Constant = {
[Network.COSMONS_ROSETTA]: 18,
[Network.IOTA]: 18,
[Network.IOTA_TESTNET]: 18,
[Network.BITCOIN_ELECTRS]: 18
[Network.BITCOIN_ELECTRS]: 18,
[Network.BITCOIN_ELECTRS_TESTNET]: 18,
[Network.ROSTRUM_TESTNET]: 18
},
CURRENCY_NAMES: {
[Network.BITCOIN]: 'BTC',
Expand Down Expand Up @@ -227,7 +229,9 @@ export const Constant = {
[Network.COSMONS_ROSETTA]: 'ATOM',
[Network.IOTA]: 'IOTA',
[Network.IOTA_TESTNET]: 'IOTA',
[Network.BITCOIN_ELECTRS]: 'BTC'
[Network.BITCOIN_ELECTRS]: 'BTC',
[Network.BITCOIN_ELECTRS_TESTNET]: 'BTC',
[Network.ROSTRUM_TESTNET]: 'BCH'
},
RPC: {
MAINNETS: [
Expand Down
2 changes: 2 additions & 0 deletions src/util/util.shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,13 @@ export const Utils = {
case Network.KADENA_TESTNET:
return new Kadena(id) as T
case Network.ROSTRUM:
case Network.ROSTRUM_TESTNET:
return new Rostrum(id) as T
case Network.IOTA:
case Network.IOTA_TESTNET:
return new Iota(id) as T
case Network.BITCOIN_ELECTRS:
case Network.BITCOIN_ELECTRS_TESTNET:
return new BitcoinElectrs(id) as T
default:
return new FullSdk(id) as T
Expand Down

0 comments on commit 179fa52

Please sign in to comment.