Skip to content

Commit

Permalink
ALL-7026 - Add Rostrum & Electrs testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
Hathoriel committed Jun 17, 2024
1 parent 12bc802 commit e5e706d
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 20 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.32] - 2024.6.14

### Added

- Support for Electrs & Rostrum testnet

## [4.2.31] - 2024.6.3

### 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": "@tatumio/tatum",
"version": "4.2.31",
"version": "4.2.32",
"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 @@ -256,9 +258,9 @@ export const CARDANO_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 @@ -923,6 +925,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 @@ -937,4 +943,8 @@ export const NETWORK_METADATA: Record<Network, NetworkMetadata> = {
currency: Currency.BTC,
testnet: false,
},
[Network.BITCOIN_ELECTRS_TESTNET]: {
currency: Currency.BTC,
testnet: true,
},
}
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
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 @@ -844,11 +844,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 e5e706d

Please sign in to comment.