Skip to content

Commit

Permalink
Merge d3c5763 into 406808a
Browse files Browse the repository at this point in the history
  • Loading branch information
marktanrj authored Oct 27, 2022
2 parents 406808a + d3c5763 commit f21aaab
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/node/CATEGORIES/03-net.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,32 @@ export interface PeerInfo {
}
```

## getNetTotals

Returns information about network traffic, including bytes in, bytes out, and current time.

```ts title="client.net.getNetTotals()"
interface net {
getNetTotals (): Promise<NetTotals>
}

interface NetTotals {
totalbytesrecv: number
totalbytessent: number
timemillis: number
uploadtarget: UploadTarget
}

interface UploadTarget {
timeframe: number
target: number
target_reached: boolean
serve_historical_blocks: boolean
bytes_left_in_cycle: number
time_left_in_cycle: number
}
```

## getNetworkInfo

Returns an object containing various state info regarding P2P networking.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { MasterNodeRegTestContainer, RegTestContainer } from '@defichain/testcontainers/dist/index'
import { net } from '../../../src'
import { ContainerAdapterClient } from '../../container_adapter_client'

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

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

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

it('should getNetTotals', async () => {
const info: net.NetTotals = await client.net.getNetTotals()

expect(info).toStrictEqual({
totalbytesrecv: expect.any(Number),
totalbytessent: expect.any(Number),
timemillis: expect.any(Number),
uploadtarget: {
timeframe: expect.any(Number),
target: expect.any(Number),
target_reached: expect.any(Boolean),
serve_historical_blocks: expect.any(Boolean),
bytes_left_in_cycle: expect.any(Number),
time_left_in_cycle: expect.any(Number)
}
})
})
})

describe('Network on masternode', () => {
const container = new MasterNodeRegTestContainer()
const client = new ContainerAdapterClient(container)

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

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

it('should getNetTotals', async () => {
const info: net.NetTotals = await client.net.getNetTotals()

expect(info).toStrictEqual({
totalbytesrecv: expect.any(Number),
totalbytessent: expect.any(Number),
timemillis: expect.any(Number),
uploadtarget: {
timeframe: expect.any(Number),
target: expect.any(Number),
target_reached: expect.any(Boolean),
serve_historical_blocks: expect.any(Boolean),
bytes_left_in_cycle: expect.any(Number),
time_left_in_cycle: expect.any(Number)
}
})
})
})
25 changes: 25 additions & 0 deletions packages/jellyfish-api-core/src/category/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ export class Net {
return await this.client.call('getpeerinfo', [], 'number')
}

/**
* Returns information about network traffic, including bytes in, bytes out, and current time.
*
* @return {Promise<NetTotals>}
*/
async getNetTotals (): Promise<NetTotals> {
return await this.client.call('getnettotals', [], 'number')
}

/**
* Returns an object containing various state info regarding P2P networking.
*
Expand Down Expand Up @@ -113,3 +122,19 @@ export interface LocalAddress {
port: number
score: number
}

export interface NetTotals {
totalbytesrecv: number
totalbytessent: number
timemillis: number
uploadtarget: UploadTarget
}

export interface UploadTarget {
timeframe: number
target: number
target_reached: boolean
serve_historical_blocks: boolean
bytes_left_in_cycle: number
time_left_in_cycle: number
}

0 comments on commit f21aaab

Please sign in to comment.