|
@ -2,15 +2,15 @@ import { IChart, IConfig } from '@mrblenny/react-flow-chart'; |
|
|
import { LightningNodeMapping } from 'store/models/lightning'; |
|
|
import { LightningNodeMapping } from 'store/models/lightning'; |
|
|
import { Network } from 'types'; |
|
|
import { Network } from 'types'; |
|
|
import { defaultStateChannel, defaultStateInfo, getNetwork } from 'utils/tests'; |
|
|
import { defaultStateChannel, defaultStateInfo, getNetwork } from 'utils/tests'; |
|
|
import { initChartFromNetwork, snap, updateChartFromLnd } from './chart'; |
|
|
import { initChartFromNetwork, snap, updateChartFromNodes } from './chart'; |
|
|
|
|
|
|
|
|
describe('Chart Util', () => { |
|
|
describe('Chart Util', () => { |
|
|
let network: Network; |
|
|
let network: Network; |
|
|
let chart: IChart; |
|
|
let chart: IChart; |
|
|
let lndData: LightningNodeMapping; |
|
|
let nodesData: LightningNodeMapping; |
|
|
|
|
|
|
|
|
const addChannel = (node: string, remotePubkey: string, pending?: boolean) => { |
|
|
const addChannel = (node: string, remotePubkey: string, pending?: boolean) => { |
|
|
const { channels } = lndData[node]; |
|
|
const { channels } = nodesData[node]; |
|
|
if (channels) { |
|
|
if (channels) { |
|
|
channels.push( |
|
|
channels.push( |
|
|
defaultStateChannel({ |
|
|
defaultStateChannel({ |
|
@ -30,13 +30,13 @@ describe('Chart Util', () => { |
|
|
beforeEach(() => { |
|
|
beforeEach(() => { |
|
|
network = getNetwork(); |
|
|
network = getNetwork(); |
|
|
chart = initChartFromNetwork(network); |
|
|
chart = initChartFromNetwork(network); |
|
|
lndData = { |
|
|
nodesData = { |
|
|
[network.nodes.lightning[0].name]: { |
|
|
[network.nodes.lightning[0].name]: { |
|
|
info: defaultStateInfo({ pubkey: 'lnd1pubkey' }), |
|
|
info: defaultStateInfo({ pubkey: 'ln1pubkey' }), |
|
|
channels: [], |
|
|
channels: [], |
|
|
}, |
|
|
}, |
|
|
[network.nodes.lightning[1].name]: { |
|
|
[network.nodes.lightning[1].name]: { |
|
|
info: defaultStateInfo({ pubkey: 'lnd2pubkey' }), |
|
|
info: defaultStateInfo({ pubkey: 'ln2pubkey' }), |
|
|
channels: [], |
|
|
channels: [], |
|
|
}, |
|
|
}, |
|
|
}; |
|
|
}; |
|
@ -61,8 +61,8 @@ describe('Chart Util', () => { |
|
|
|
|
|
|
|
|
describe('updateChartFromNetwork', () => { |
|
|
describe('updateChartFromNetwork', () => { |
|
|
it('should create link for an open channel', () => { |
|
|
it('should create link for an open channel', () => { |
|
|
addChannel('alice', 'lnd2pubkey'); |
|
|
addChannel('alice', 'ln2pubkey'); |
|
|
const result = updateChartFromLnd(chart, lndData); |
|
|
const result = updateChartFromNodes(chart, nodesData); |
|
|
expect(result.links['xxxxxxxxxx:0']).toBeDefined(); |
|
|
expect(result.links['xxxxxxxxxx:0']).toBeDefined(); |
|
|
const link = result.links['xxxxxxxxxx:0']; |
|
|
const link = result.links['xxxxxxxxxx:0']; |
|
|
expect(link.from.nodeId).toBe('alice'); |
|
|
expect(link.from.nodeId).toBe('alice'); |
|
@ -73,8 +73,8 @@ describe('Chart Util', () => { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should create link for a pending channel', () => { |
|
|
it('should create link for a pending channel', () => { |
|
|
addChannel('alice', 'lnd2pubkey', true); |
|
|
addChannel('alice', 'ln2pubkey', true); |
|
|
const result = updateChartFromLnd(chart, lndData); |
|
|
const result = updateChartFromNodes(chart, nodesData); |
|
|
expect(result.links['xxxxxxxxxx:0']).toBeDefined(); |
|
|
expect(result.links['xxxxxxxxxx:0']).toBeDefined(); |
|
|
const link = result.links['xxxxxxxxxx:0']; |
|
|
const link = result.links['xxxxxxxxxx:0']; |
|
|
expect(link.from.nodeId).toBe('alice'); |
|
|
expect(link.from.nodeId).toBe('alice'); |
|
@ -85,28 +85,28 @@ describe('Chart Util', () => { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should remove links for channels that do not exist', () => { |
|
|
it('should remove links for channels that do not exist', () => { |
|
|
addChannel('alice', 'lnd2pubkey'); |
|
|
addChannel('alice', 'ln2pubkey'); |
|
|
const result = updateChartFromLnd(chart, lndData); |
|
|
const result = updateChartFromNodes(chart, nodesData); |
|
|
expect(result.links['xxxxxxxxxx:0']).toBeTruthy(); |
|
|
expect(result.links['xxxxxxxxxx:0']).toBeTruthy(); |
|
|
// remove the channel
|
|
|
// remove the channel
|
|
|
const node = lndData['alice']; |
|
|
const node = nodesData['alice']; |
|
|
if (node.channels) node.channels = []; |
|
|
if (node.channels) node.channels = []; |
|
|
const result2 = updateChartFromLnd(result, lndData); |
|
|
const result2 = updateChartFromNodes(result, nodesData); |
|
|
expect(result2.links['xxxxxxxxxx:0']).toBeUndefined(); |
|
|
expect(result2.links['xxxxxxxxxx:0']).toBeUndefined(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should make no changes if channels is undefined', () => { |
|
|
it('should make no changes if channels is undefined', () => { |
|
|
lndData['alice'].channels = undefined; |
|
|
nodesData['alice'].channels = undefined; |
|
|
lndData['bob'].channels = undefined; |
|
|
nodesData['bob'].channels = undefined; |
|
|
const result = updateChartFromLnd(chart, lndData); |
|
|
const result = updateChartFromNodes(chart, nodesData); |
|
|
expect(result).toEqual(chart); |
|
|
expect(result).toEqual(chart); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should point link right to left', () => { |
|
|
it('should point link right to left', () => { |
|
|
chart.nodes['alice'].position.x = 200; |
|
|
chart.nodes['alice'].position.x = 200; |
|
|
chart.nodes['bob'].position.x = 100; |
|
|
chart.nodes['bob'].position.x = 100; |
|
|
addChannel('alice', 'lnd2pubkey'); |
|
|
addChannel('alice', 'ln2pubkey'); |
|
|
const result = updateChartFromLnd(chart, lndData); |
|
|
const result = updateChartFromNodes(chart, nodesData); |
|
|
const link = result.links['xxxxxxxxxx:0']; |
|
|
const link = result.links['xxxxxxxxxx:0']; |
|
|
expect(link.properties.direction).toEqual('rtl'); |
|
|
expect(link.properties.direction).toEqual('rtl'); |
|
|
}); |
|
|
}); |
|
@ -114,8 +114,8 @@ describe('Chart Util', () => { |
|
|
it('should update the node sizes', () => { |
|
|
it('should update the node sizes', () => { |
|
|
chart.nodes['alice'].size = { width: 100, height: 20 }; |
|
|
chart.nodes['alice'].size = { width: 100, height: 20 }; |
|
|
chart.nodes['bob'].size = undefined; |
|
|
chart.nodes['bob'].size = undefined; |
|
|
addChannel('alice', 'lnd2pubkey'); |
|
|
addChannel('alice', 'ln2pubkey'); |
|
|
const result = updateChartFromLnd(chart, lndData); |
|
|
const result = updateChartFromNodes(chart, nodesData); |
|
|
let size = result.nodes['alice'].size; |
|
|
let size = result.nodes['alice'].size; |
|
|
expect(size).toBeDefined(); |
|
|
expect(size).toBeDefined(); |
|
|
if (size) expect(size.height).toBe(60); |
|
|
if (size) expect(size.height).toBe(60); |
|
|