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

feat(jellyfish-api-core): added net.getVersionInfo() and its respective test getVersionInfo.tes… #1976

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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,75 @@
import { MasterNodeRegTestContainer, RegTestContainer } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../../container_adapter_client'
import { net } from '../../../src'

describe('Version information without masternode', () => {
const container = new RegTestContainer()
const client = new ContainerAdapterClient(container)

beforeAll(async () => {
await container.start()
await container.waitForReady()
})

afterAll(async () => {
await container.stop()
})

it('should getVersionInfo', async () => {
const versionInfo: net.VersionInfo = await client.net.getVersionInfo()
expect(versionInfo).toStrictEqual({
fullVersion: expect.stringContaining('DeFiChain'),
name: 'DeFiChain',
version: expect.any(String),
numericVersion: expect.any(Number),
protoVersion: expect.any(Number),
protoVersionMin: expect.any(Number),
userAgent: expect.stringContaining('DeFiChain'),
rpcVersion: expect.any(String),
rpcVersionMin: expect.any(String),
spv: {
btc: {
version: expect.any(Number),
min: expect.any(Number),
userAgent: expect.any(String)
}
}
})
})
})

describe('Version information with masternode', () => {
const container = new MasterNodeRegTestContainer()
const client = new ContainerAdapterClient(container)

beforeAll(async () => {
await container.start()
await container.waitForReady()
})

afterAll(async () => {
await container.stop()
})

it('should getVersionInfo', async () => {
const versionInfo: net.VersionInfo = await client.net.getVersionInfo()
expect(versionInfo).toStrictEqual({
fullVersion: expect.stringContaining('DeFiChain'),
name: 'DeFiChain',
version: expect.any(String),
numericVersion: expect.any(Number),
protoVersion: expect.any(Number),
protoVersionMin: expect.any(Number),
userAgent: expect.stringContaining('DeFiChain'),
rpcVersion: expect.any(String),
rpcVersionMin: expect.any(String),
spv: {
btc: {
version: expect.any(Number),
min: expect.any(Number),
userAgent: expect.any(String)
}
}
})
})
})
28 changes: 28 additions & 0 deletions packages/jellyfish-api-core/src/category/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ export class Net {
async setNetworkActive (state: boolean): Promise<boolean> {
return await this.client.call('setnetworkactive', [state], 'number')
}

/**
* Returns an object containing various version info about the node
*
* @return {Promise<VersionInfo>}
*/
async getVersionInfo (): Promise<VersionInfo> {
return await this.client.call('getversioninfo', [], 'number')
}
}

export interface PeerInfo {
Expand Down Expand Up @@ -109,6 +118,25 @@ export interface NetworkInfo {
warnings: string
}

export interface VersionInfo {
name: string
version: string
numericVersion: number
fullVersion: string
userAgent: string
protoVersion: number
protoVersionMin: number
rpcVersion: string
rpcVersionMin: string
spv: {
btc: {
userAgent: string
version: number
min: number
}
}
}

export interface Network {
name: string
limited: boolean
Expand Down