This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathpeers.test.js
116 lines (92 loc) · 3.84 KB
/
peers.test.js
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
import { expect } from 'chai';
import { spy, stub, match } from 'sinon';
import Lisk from 'lisk-js';
import actionTypes from '../constants/actions';
import netHashes from '../constants/netHashes';
import { activePeerSet, activePeerUpdate } from './peers';
describe.skip('actions: peers', () => {
const passphrase = 'wagon stock borrow episode laundry kitten salute link globe zero feed marble';
const nethash = '198f2b61a8eb95fbeed58b8216780b68f697f26b849acf00c8c93bb9b24f783d';
const nethashApi = new Lisk.APIClient(['http://localhost:4000'], nethash, {});
describe('activePeerUpdate', () => {
it('should create an action to update the active peer', () => {
const data = {
online: true,
};
const expectedAction = {
data,
type: actionTypes.activePeerUpdate,
};
expect(activePeerUpdate(data)).to.be.deep.equal(expectedAction);
});
});
describe('activePeerSet', () => {
let dispatch;
let getNetHash;
beforeEach(() => {
dispatch = spy();
const node = nethashApi.node;
getNetHash = stub(node, 'getConstants');
});
afterEach(() => {
getNetHash.restore();
});
it('creates active peer config', () => {
getNetHash.returnsPromise();
const data = {
passphrase,
network: {
name: 'Custom Node',
custom: true,
address: 'http://localhost:4000',
testnet: true,
nethash,
},
};
activePeerSet(data)(dispatch);
getNetHash.resolves({ data: { nethash } });
expect(dispatch).to.have.been.calledOnce();
});
it('dispatch activePeerSet action also when address http missing', () => {
const network = { address: 'localhost:8000' };
activePeerSet({ passphrase, network })(dispatch);
expect(dispatch).to.have.been.calledWith(match.hasNested('data.activePeer.options.address', 'localhost:8000'));
});
it('dispatch activePeerSet with testnet config set to true when the network is a custom node and nethash is testnet', () => {
getNetHash.returnsPromise();
const network = {
address: 'http://localhost:4000',
custom: true,
};
activePeerSet({ passphrase, network })(dispatch);
getNetHash.resolves({ data: { nethash: netHashes.testnet } });
expect(dispatch).to.have.been.calledWith(match.hasNested('data.activePeer.testnet', true));
});
it('dispatch activePeerSet with testnet config set to false when the network is a custom node and nethash is testnet', () => {
getNetHash.returnsPromise();
const network = {
address: 'http://localhost:4000',
custom: true,
};
activePeerSet({ passphrase, network })(dispatch);
getNetHash.resolves({ data: { nethash: 'some other nethash' } });
expect(dispatch).to.have.been.calledWith(match.hasNested('data.activePeer.testnet', false));
});
it('dispatch activePeerSet action even if network is undefined', () => {
activePeerSet({ passphrase })(dispatch);
expect(dispatch).to.have.been.calledWith();
});
it('dispatch activePeerSet action even if network.address is undefined', () => {
activePeerSet({ passphrase, network: {} })(dispatch);
expect(dispatch).to.have.been.calledWith();
});
it('should set to testnet if not defined in config but port is 7000', () => {
const network7000 = { address: 'http://127.0.0.1:7000', nethash };
const network4000 = { address: 'http://127.0.0.1:4000', nethash };
activePeerSet({ passphrase, network: network7000 })(dispatch);
expect(dispatch).to.have.been.calledWith(match.hasNested('data.activePeer.options.testnet', true));
activePeerSet({ passphrase, network: network4000 })(dispatch);
expect(dispatch).to.have.been.calledWith(match.hasNested('data.activePeer.options.testnet', false));
});
});
});