forked from aeternity/aepp-sdk-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.js
More file actions
117 lines (109 loc) · 3.79 KB
/
Copy pathnode.js
File metadata and controls
117 lines (109 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* ISC License (ISC)
* Copyright (c) 2018 aeternity developers
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
import Node from '../../es/node'
import { url, internalUrl } from './'
import { describe, it, before } from 'mocha'
import { expect } from 'chai'
import * as R from 'ramda'
import { NodePool } from '../../es/node-pool'
describe('Node client', function () {
let client
before(async function () {
client = await Node({ url, internalUrl })
})
it('determines remote version', () => {
expect(client.version).to.be.a('string')
expect(client.revision).to.be.a('string')
})
it('loads operations', () => {
['postTransaction', 'getCurrentKeyBlock']
.map(method => expect(client.api[method]).to.be.a('function'))
})
it('gets key blocks by height for the first 3 blocks', () => {
expect(client.api.getKeyBlockByHeight).to.be.a('function')
return Promise.all(
R.range(1, 3).map(async i => {
const result = await client.api.getKeyBlockByHeight(i)
expect(result.height, i).to.equal(i)
})
)
})
describe('Node Pool', () => {
it('throw error on invalid node object', async () => {
const node = await NodePool()
expect(() => node.addNode('test', {})).to.throw(Error)
expect(() => node.addNode('test', 1)).to.throw(Error)
expect(() => node.addNode('test', null)).to.throw(Error)
try {
node.addNode('test', {})
} catch (e) {
e.message.should.be.equal('Invalid node instance object')
}
})
it('Throw error on get network without node ', async () => {
const node = await NodePool()
try {
node.getNetworkId()
} catch (e) {
e.message.should.be.equal('networkId is not provided')
}
})
it('Throw error on using API without node', async () => {
const node = await NodePool()
try {
node.api.someAPIfn()
} catch (e) {
e.message.should.be.equal('You can\'t use Node API. Node is not connected or not defined!')
}
})
it('Can change Node', async () => {
const nodes = await NodePool({
nodes: [
{ name: 'first', instance: await Node({ url, internalUrl }) },
{ name: 'second', instance: client }
]
})
const activeNode = nodes.getNodeInfo()
activeNode.name.should.be.equal('first')
nodes.selectNode('second')
const secondNodeInfo = nodes.getNodeInfo()
secondNodeInfo.name.should.be.equal('second')
})
it('Fail on undefined node', async () => {
const nodes = await NodePool({
nodes: [
{ name: 'first', instance: await Node({ url, internalUrl }) },
{ name: 'second', instance: client }
]
})
try {
nodes.selectNode('asdasd')
} catch (e) {
e.message.should.be.equal('Node with name asdasd not in pool')
}
})
it('Can get list of nodes', async () => {
const nodes = await NodePool({
nodes: [
{ name: 'first', instance: client }
]
})
const nodesList = nodes.getNodesInPool()
nodesList.length.should.be.equal(1)
})
})
})