JimmyMow
6 years ago
committed by
GitHub
13 changed files with 147 additions and 88 deletions
@ -1,14 +1,21 @@ |
|||||
import { status } from 'grpc' |
import { status } from 'grpc' |
||||
|
import { mainLog } from '../../utils/log' |
||||
|
|
||||
export default function subscribeToChannelGraph(mainWindow, lnd, log) { |
export default function subscribeToChannelGraph() { |
||||
const call = lnd.subscribeChannelGraph({}) |
const call = this.lnd.subscribeChannelGraph({}) |
||||
|
|
||||
call.on('data', channelGraphData => mainWindow.send('channelGraphData', { channelGraphData })) |
call.on('data', channelGraphData => { |
||||
call.on('end', () => log.info('end')) |
if (this.mainWindow) { |
||||
call.on('error', error => error.code !== status.CANCELLED && log.error(error)) |
this.mainWindow.send('channelGraphData', { channelGraphData }) |
||||
call.on('status', channelGraphStatus => |
} |
||||
mainWindow.send('channelGraphStatus', { channelGraphStatus }) |
}) |
||||
) |
call.on('end', () => mainLog.info('end')) |
||||
|
call.on('error', error => error.code !== status.CANCELLED && mainLog.error(error)) |
||||
|
call.on('status', channelGraphStatus => { |
||||
|
if (this.mainWindow) { |
||||
|
this.mainWindow.send('channelGraphStatus', { channelGraphStatus }) |
||||
|
} |
||||
|
}) |
||||
|
|
||||
return call |
return call |
||||
} |
} |
||||
|
@ -1,15 +1,18 @@ |
|||||
import { status } from 'grpc' |
import { status } from 'grpc' |
||||
|
import { mainLog } from '../../utils/log' |
||||
|
|
||||
export default function subscribeToInvoices(mainWindow, lnd, log) { |
export default function subscribeToInvoices() { |
||||
const call = lnd.subscribeInvoices({}) |
const call = this.lnd.subscribeInvoices({}) |
||||
|
|
||||
call.on('data', invoice => { |
call.on('data', invoice => { |
||||
log.info('INVOICE:', invoice) |
mainLog.info('INVOICE:', invoice) |
||||
mainWindow.send('invoiceUpdate', { invoice }) |
if (this.mainWindow) { |
||||
|
this.mainWindow.send('invoiceUpdate', { invoice }) |
||||
|
} |
||||
}) |
}) |
||||
call.on('end', () => log.info('end')) |
call.on('end', () => mainLog.info('end')) |
||||
call.on('error', error => error.code !== status.CANCELLED && log.error(error)) |
call.on('error', error => error.code !== status.CANCELLED && mainLog.error(error)) |
||||
call.on('status', status => log.info('INVOICE STATUS:', status)) |
call.on('status', status => mainLog.info('INVOICE STATUS:', status)) |
||||
|
|
||||
return call |
return call |
||||
} |
} |
||||
|
@ -1,15 +1,18 @@ |
|||||
import { status } from 'grpc' |
import { status } from 'grpc' |
||||
|
import { mainLog } from '../../utils/log' |
||||
|
|
||||
export default function subscribeToTransactions(mainWindow, lnd, log) { |
export default function subscribeToTransactions() { |
||||
const call = lnd.subscribeTransactions({}) |
const call = this.lnd.subscribeTransactions({}) |
||||
|
|
||||
call.on('data', transaction => { |
call.on('data', transaction => { |
||||
log.info('TRANSACTION:', transaction) |
mainLog.info('TRANSACTION:', transaction) |
||||
mainWindow.send('newTransaction', { transaction }) |
if (this.mainWindow) { |
||||
|
this.mainWindow.send('newTransaction', { transaction }) |
||||
|
} |
||||
}) |
}) |
||||
call.on('end', () => log.info('end')) |
call.on('end', () => mainLog.info('end')) |
||||
call.on('error', error => error.code !== status.CANCELLED && log.error(error)) |
call.on('error', error => error.code !== status.CANCELLED && mainLog.error(error)) |
||||
call.on('status', status => log.info('TRANSACTION STATUS: ', status)) |
call.on('status', status => mainLog.info('TRANSACTION STATUS: ', status)) |
||||
|
|
||||
return call |
return call |
||||
} |
} |
||||
|
@ -0,0 +1,13 @@ |
|||||
|
const { normalize } = require('path') |
||||
|
|
||||
|
module.exports = { |
||||
|
require: jest.fn(), |
||||
|
match: jest.fn(), |
||||
|
app: { |
||||
|
getPath: name => normalize(`/tmp/zap-test/${name}`), |
||||
|
getAppPath: () => normalize('/tmp/zap-test') |
||||
|
}, |
||||
|
remote: jest.fn(), |
||||
|
dialog: jest.fn(), |
||||
|
BrowserWindow: jest.fn() |
||||
|
} |
@ -0,0 +1,53 @@ |
|||||
|
import { BrowserWindow } from 'electron' |
||||
|
import Lightning from 'lib/lnd/lightning' |
||||
|
|
||||
|
jest.mock('electron-store') |
||||
|
jest.mock('lib/lnd/subscribe/transactions') |
||||
|
jest.mock('lib/lnd/subscribe/invoices') |
||||
|
jest.mock('lib/lnd/subscribe/channelgraph') |
||||
|
|
||||
|
describe('Lightning', function() { |
||||
|
describe('Constructor', () => { |
||||
|
beforeAll(() => (this.lightning = new Lightning())) |
||||
|
|
||||
|
describe('initial values', () => { |
||||
|
it('should set the "mainWindow" property to null', () => { |
||||
|
expect(this.lightning.mainWindow).toBeNull() |
||||
|
}) |
||||
|
it('should set the "lnd" property to null', () => { |
||||
|
expect(this.lightning.lnd).toBeNull() |
||||
|
}) |
||||
|
it('should initialise the "subscriptions" object with null values', () => { |
||||
|
expect(this.lightning.subscriptions).toMatchObject({ |
||||
|
channelGraph: null, |
||||
|
invoices: null, |
||||
|
transactions: null |
||||
|
}) |
||||
|
}) |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
|
describe('subscribe()', () => { |
||||
|
beforeAll(() => { |
||||
|
this.window = new BrowserWindow({}) |
||||
|
this.lightning = new Lightning() |
||||
|
this.lightning.subscribe(this.window) |
||||
|
}) |
||||
|
|
||||
|
it('should assign the window to the "mainWindow" property', () => { |
||||
|
expect(this.lightning.mainWindow).toBe(this.window) |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
|
describe('unsubscribe()', () => { |
||||
|
beforeAll(() => { |
||||
|
this.lightning = new Lightning() |
||||
|
this.lightning.mainWindow = new BrowserWindow({}) |
||||
|
this.lightning.unsubscribe() |
||||
|
}) |
||||
|
|
||||
|
it('should unassign the "mainWindow" property', () => { |
||||
|
expect(this.lightning.mainWindow).toBeNull() |
||||
|
}) |
||||
|
}) |
||||
|
}) |
Loading…
Reference in new issue