2021-01-02 15:41:12 -08:00
|
|
|
const assert = require('assert')
|
|
|
|
|
const axios = require('axios')
|
|
|
|
|
const BCHJS = require('../../src/bch-js')
|
2020-07-27 21:32:51 -07:00
|
|
|
const bchjs = new BCHJS()
|
2021-01-02 15:41:12 -08:00
|
|
|
const sinon = require('sinon')
|
2020-07-27 21:32:51 -07:00
|
|
|
|
2021-01-02 15:41:12 -08:00
|
|
|
describe('#Control', () => {
|
2021-02-11 19:22:25 -08:00
|
|
|
let sandbox
|
|
|
|
|
beforeEach(() => (sandbox = sinon.createSandbox()))
|
|
|
|
|
afterEach(() => sandbox.restore())
|
2020-07-27 21:32:51 -07:00
|
|
|
|
2021-02-11 19:22:25 -08:00
|
|
|
describe('#getNetworkInfo', () => {
|
2021-01-02 15:41:12 -08:00
|
|
|
it('should get info', done => {
|
2020-07-27 21:32:51 -07:00
|
|
|
const data = {
|
|
|
|
|
version: 170000,
|
|
|
|
|
protocolversion: 70015,
|
|
|
|
|
blocks: 527813,
|
|
|
|
|
timeoffset: 0,
|
|
|
|
|
connections: 21,
|
2021-01-02 15:41:12 -08:00
|
|
|
proxy: '',
|
2020-07-27 21:32:51 -07:00
|
|
|
difficulty: 581086703759.5878,
|
|
|
|
|
testnet: false,
|
|
|
|
|
paytxfee: 0,
|
|
|
|
|
relayfee: 0.00001,
|
2021-01-02 15:41:12 -08:00
|
|
|
errors: ''
|
2020-07-27 21:32:51 -07:00
|
|
|
}
|
2021-01-02 16:39:44 -08:00
|
|
|
const resolved = new Promise(resolve => resolve({ data: data }))
|
2021-01-02 15:41:12 -08:00
|
|
|
sandbox.stub(axios, 'get').returns(resolved)
|
2020-07-27 21:32:51 -07:00
|
|
|
|
|
|
|
|
bchjs.Control.getNetworkInfo()
|
|
|
|
|
.then(result => {
|
2021-01-02 16:39:44 -08:00
|
|
|
assert.deepStrictEqual(data, result)
|
2020-07-27 21:32:51 -07:00
|
|
|
})
|
|
|
|
|
.then(done, done)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-01-02 15:41:12 -08:00
|
|
|
describe('#getMemoryInfo', () => {
|
|
|
|
|
it('should get memory info', done => {
|
2020-07-27 21:32:51 -07:00
|
|
|
const data = {
|
|
|
|
|
locked: {
|
|
|
|
|
used: 0,
|
|
|
|
|
free: 65536,
|
|
|
|
|
total: 65536,
|
|
|
|
|
locked: 65536,
|
|
|
|
|
chunks_used: 0,
|
|
|
|
|
chunks_free: 1
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-02 16:39:44 -08:00
|
|
|
const resolved = new Promise(resolve => resolve({ data: data }))
|
2021-01-02 15:41:12 -08:00
|
|
|
sandbox.stub(axios, 'get').returns(resolved)
|
2020-07-27 21:32:51 -07:00
|
|
|
|
|
|
|
|
bchjs.Control.getMemoryInfo()
|
|
|
|
|
.then(result => {
|
2021-01-02 16:39:44 -08:00
|
|
|
assert.deepStrictEqual(data, result)
|
2020-07-27 21:32:51 -07:00
|
|
|
})
|
|
|
|
|
.then(done, done)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|