-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79309a8
commit 49bfd8b
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
packages/jellyfish-api-core/__tests__/category/net.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { RegTestContainer, MasterNodeRegTestContainer } from '@defichain/testcontainers' | ||
import { ContainerAdapterClient } from '../container_adapter_client' | ||
|
||
describe('non 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 getConnectionCount', async () => { | ||
const count = await client.net.getConnectionCount() | ||
expect(count).toBeGreaterThanOrEqual(0) | ||
}) | ||
}) | ||
|
||
describe('masternode', () => { | ||
const container = new MasterNodeRegTestContainer() | ||
const client = new ContainerAdapterClient(container) | ||
|
||
beforeAll(async () => { | ||
await container.start() | ||
await container.waitForReady() | ||
await container.waitForWalletCoinbaseMaturity() | ||
}) | ||
|
||
afterAll(async () => { | ||
await container.stop() | ||
}) | ||
|
||
it('should getConnectionCount', async () => { | ||
const count = await client.net.getConnectionCount() | ||
expect(count).toBeGreaterThanOrEqual(0) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ApiClient } from '../.' | ||
|
||
/** | ||
* Net RPCs for DeFi Blockchain | ||
*/ | ||
export class Net { | ||
private readonly client: ApiClient | ||
|
||
constructor (client: ApiClient) { | ||
this.client = client | ||
} | ||
|
||
/** | ||
* Returns the number of connections to other nodes. | ||
* | ||
* @return {Promise<string>} | ||
*/ | ||
async getConnectionCount (): Promise<string> { | ||
return await this.client.call('getconnectioncount', [], 'number') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
id: net | ||
title: Net API | ||
sidebar_label: Net API | ||
slug: /jellyfish/api/net | ||
--- | ||
|
||
```js | ||
import {Client} from '@defichain/jellyfish' | ||
const client = new Client() | ||
|
||
// Using client.net. | ||
const something = await client.net.method() | ||
``` | ||
|
||
## getConnectionCount | ||
|
||
Returns the number of connections to other nodes. | ||
|
||
```ts title="client.net.getConnectionCount()" | ||
interface net { | ||
getConnectionCount (): Promise<string> | ||
} | ||
``` |