diff --git a/packages/jellyfish-api-core/__tests__/category/net/getNodeAddresses.test.ts b/packages/jellyfish-api-core/__tests__/category/net/getNodeAddresses.test.ts new file mode 100644 index 0000000000..741f067ea2 --- /dev/null +++ b/packages/jellyfish-api-core/__tests__/category/net/getNodeAddresses.test.ts @@ -0,0 +1,48 @@ +import { TestingGroup } from '@defichain/jellyfish-testing' + +describe('Network', () => { + const tGroup = TestingGroup.create(9) + + beforeAll(async () => { + await tGroup.start({ + startFlags: [ + { + name: 'regtest', + value: 0 + }, + { + name: 'testnet', + value: 1 + }, + { + name: 'rpcport', + value: 19554 + } + ] + }) + }) + + afterAll(async () => { + await tGroup.stop() + }) + + it('should be empty if no available nodes', async () => { + const res = await tGroup.get(0).rpc.net.getNodeAddresses(1) + expect(res).toMatchObject([]) + }) + + it('should have available nodes', async () => { + await tGroup.link() + await new Promise((resolve) => { + setTimeout(() => resolve(0), 30000) + }) // give enough time to find new nodes + + const res = await tGroup.get(0).rpc.net.getNodeAddresses(1) + expect(res).toMatchObject([{ + time: expect.any(Number), + services: expect.any(Number), + address: expect.any(String), + port: expect.any(Number) + }]) + }) +}) diff --git a/packages/jellyfish-api-core/src/category/net.ts b/packages/jellyfish-api-core/src/category/net.ts index 61f4105b2e..40bba4a771 100644 --- a/packages/jellyfish-api-core/src/category/net.ts +++ b/packages/jellyfish-api-core/src/category/net.ts @@ -55,6 +55,16 @@ export class Net { async setNetworkActive (state: boolean): Promise { return await this.client.call('setnetworkactive', [state], 'number') } + + /** + * Return known addresses which can potentially be used to find new nodes in the network. + * + * @param [count] Number of entries to return + * @return {Promise} + */ + async getNodeAddresses (count?: number): Promise { + return await this.client.call('getnodeaddresses', [count], 'number') + } } export interface PeerInfo { @@ -109,6 +119,13 @@ export interface NetworkInfo { warnings: string } +export interface AddressInfo { + time: number + services: number + address: string + port: number +} + export interface Network { name: string limited: boolean