Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const {channels} = await getChannels({lnd: cluster.remote.lnd});
const invoice = await createInvoice({tokens, lnd: cluster.remote.lnd});
await delay(1000);
const sub = subscribeToProbe({
lnd,
destination: cluster.remote_node_public_key,
tokens: invoice.tokens,
});
sub.on('error', () => {});
const [{route}] = await once(sub, 'probing');
// On 0.7.1 confidence is not supported
delete route.confidence;
deepIs(route, {
fee: 1,
fee_mtokens: '1500',
hops: [
{
channel: controlToTargetChan.id,
channel_capacity: controlToTargetChan.capacity,
fee: 1,
fee_mtokens: '1500',
forward: tokens,
forward_mtokens: `${tokens}000`,
public_key: cluster.target_node_public_key,
async function onceAnEvent() {
const ee = new EventEmitter();
process.nextTick(() => {
ee.emit('myevent', 42);
});
const [value] = await once(ee, 'myevent');
strictEqual(value, 42);
strictEqual(ee.listenerCount('error'), 0);
strictEqual(ee.listenerCount('myevent'), 0);
}
async function onceError() {
const ee = new EventEmitter();
const expected = new Error('kaboom');
process.nextTick(() => {
ee.emit('error', expected);
});
const [err] = await once(ee, 'error');
strictEqual(err, expected);
strictEqual(ee.listenerCount('error'), 0);
strictEqual(ee.listenerCount('myevent'), 0);
}
metatests.test('AsyncIterator.throttle', async test => {
const EXPECTED_DEVIATION = 0.2;
const pathThrottleFile = path.join(__dirname, './throttle.js');
const child = fork(pathThrottleFile);
const [{ sum, actualDeviation, ARRAY_SIZE }] = await once(child, 'message');
test.strictSame(sum, ARRAY_SIZE);
test.assert(actualDeviation <= EXPECTED_DEVIATION);
});
it("should detect factorio hanging on shutdown", async function() {
slowTest(this);
log(".start() for hang detection");
await server.start("test.zip");
if (!server._rconReady) {
await events.once(server, 'rcon-ready');
}
server.sendRcon("/c while true do end").catch(() => {});
await new Promise((resolve) => setTimeout(resolve, 300));
log(".stop() for hang detection");
await server.stop();
});
});
withWebView(it, 'can require built-in modules', async (win) => {
const execution = win.webView.executeJavaScript(`
deskgap.asyncNode.require('os').then(function (os) {
return os.invoke('platform').value();
}).then(function (result) {
deskgap.messageUI.send('async-node-result', result);
})
`);
const [, result] = await once(messageNode, 'async-node-result');
expect(result).to.equal(require('os').platform());
await execution;
}, true);
async function dhtBootstrap () {
const node = dht()
await once(node, 'listening')
const { port } = node.address()
return {
port,
bootstrap: [`127.0.0.1:${port}`],
closeDht: () => node.destroy()
}
}
withWebView(it, 'loads the given file', async (win) => {
win.webView.loadFile(path.resolve(__dirname, '..', 'fixtures', 'files', 'web-view-load-file.html'));
await once(messageNode, 'hello-web-view-load-file');
})
});
async function destroysTheStreamWhenThrowing() {
async function* generate() {
throw new Error('kaboom');
}
const stream = Readable.from(generate());
stream.read();
const [err] = await once(stream, 'error');
strictEqual(err.message, 'kaboom');
strictEqual(stream.destroyed, true);
}
const _write = async (stream, chunk) => {
if (!stream.write(chunk)) await once(stream, 'drain')
}