Skip to content

Commit

Permalink
ALL-4863: doge getblock verbose should be boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
rostislavjadavan committed Feb 16, 2024
1 parent 765ccb3 commit d78b44c
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
coverage
*.log
.env
jest-junit.xml
9 changes: 8 additions & 1 deletion src/dto/rpc/UtxoBasedRpcSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
import { JsonRpcResponse } from '../JsonRpcResponse.dto'
import { AbstractRpcInterface } from './AbstractJsonRpcInterface'

export interface UtxoBasedCommonRpcSuite extends UtxoBasedRpcSuite {
getBlock(hashOrHeight: string, verbose?: 0 | 1 | 2): Promise<JsonRpcResponse<any>>
}

export interface DogeRpcSuite extends UtxoBasedRpcSuite {
getBlock(hashOrHeight: string, verbose?: boolean): Promise<JsonRpcResponse<any>>
}

export interface UtxoBasedRpcSuite extends UtxoBasedRpcInterface, AbstractRpcInterface {}

export interface UtxoBasedRpcInterface {
// blockchain methods
getBestBlockHash(): Promise<JsonRpcResponse<string>>
getBlock(hashOrHeight: string, verbose?: 0 | 1 | 2): Promise<JsonRpcResponse<any>>
getBlockChainInfo(): Promise<JsonRpcResponse<any>>
getBlockCount(): Promise<JsonRpcResponse<number>>
getBlockHash(height: number): Promise<JsonRpcResponse<string>>
Expand Down
20 changes: 20 additions & 0 deletions src/e2e/rpc/utxo/tatum.rpc.btc.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Bitcoin, Network } from '../../../service'
import { UtxoE2eUtils, UtxoNetworkType } from './utxo.e2e.utils'

describe('Bitcoin', () => {
describe('mainnet', () => {
it('getblock', async () => {
const tatum = await UtxoE2eUtils.initTatum<Bitcoin>({
network: Network.BITCOIN,
type: UtxoNetworkType.MAIN,
})
const hash: string = '000000000000000000018d552ccb3928f02753dd5b2abe41d593db58c29a4e3f'
const response = await tatum.rpc.getBlock(hash, 0)

expect(response).toBeDefined()
expect(typeof response.result).toBe('string')

await tatum.destroy()
})
})
})
28 changes: 27 additions & 1 deletion src/e2e/rpc/utxo/tatum.rpc.doge.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Network } from '../../../service'
import { Dogecoin, Network } from '../../../service'
import { UtxoE2eUtils, UtxoNetworkType } from './utxo.e2e.utils'

describe('Doge', () => {
Expand All @@ -20,5 +20,31 @@ describe('Doge', () => {
expect(result.result).not.toBeNull()
await tatum.destroy()
})
it('getblock', async () => {
const tatum = await UtxoE2eUtils.initTatum<Dogecoin>({
network: Network.DOGECOIN,
type: UtxoNetworkType.MAIN,
})
const hash: string = '4cddee0cb7cc1e7a5d6a099285461e0470b2af8078dae35d5ac77e7c57bbc997'
const response1 = await tatum.rpc.getBlock(hash, true)

expect(response1).toBeDefined()
expect(response1.result).toStrictEqual(
expect.objectContaining({
hash,
version: 6422788,
height: 5092153,
size: 998443,
merkleroot: '8918a6f70a0ca3c9b4f745c86a7aa3a3d67d18b9c658eacb571c13d7fed0c7a7',
chainwork: '000000000000000000000000000000000000000000000f2239716b279a602583',
}),
)

const response2 = await tatum.rpc.getBlock(hash, false)
expect(response2).toBeDefined()
expect(typeof response2.result).toBe('string')

await tatum.destroy()
})
})
})
25 changes: 21 additions & 4 deletions src/service/tatum/tatum.utxo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Container } from 'typedi'
import { UtxoBasedRpcSuite, UtxoBasedRpcSuiteEstimateFee } from '../../dto'
import {
DogeRpcSuite,
UtxoBasedCommonRpcSuite,
UtxoBasedRpcSuite,
UtxoBasedRpcSuiteEstimateFee,
} from '../../dto'
import { CONFIG, Utils } from '../../util'
import { Address } from '../address'
import { FeeUtxo } from '../fee'
Expand Down Expand Up @@ -46,9 +51,17 @@ export abstract class FullUtxo extends NotificationUtxo {
}
}

export class Bitcoin extends FullUtxo {}
export class Litecoin extends FullUtxo {}
export class Dogecoin extends FullUtxo {}
export abstract class FullCommonUtxo extends FullUtxo {
rpc: UtxoBasedCommonRpcSuite

constructor(id: string) {
super(id)
this.rpc = Utils.getRpc<UtxoBasedCommonRpcSuite>(id, Container.of(id).get(CONFIG))
}
}

export class Bitcoin extends FullCommonUtxo {}
export class Litecoin extends FullCommonUtxo {}
export class BitcoinCash extends NotificationUtxo {
rpc: UtxoBasedRpcSuiteEstimateFee

Expand All @@ -58,3 +71,7 @@ export class BitcoinCash extends NotificationUtxo {
}
}
export class ZCash extends BaseUtxo {}

export class Dogecoin extends FullUtxo {
rpc: DogeRpcSuite
}

0 comments on commit d78b44c

Please sign in to comment.