Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('automatically enables sequencing if seqAudit is true in constructor', (done) => {
const wss = new MockWSv2Server()
const ws = createTestWSv2Instance({
seqAudit: true
})
wss._onClientMessage = (ws, msgJSON) => {
const msg = JSON.parse(msgJSON)
if (msg.event === 'conf' && msg.flags === 65536) {
wss.close()
done()
}
}
ws.open()
})
it('keeps orders up to date', (done) => {
const wss = new MockWSv2Server({ listen: true })
const ws = createTestWSv2Instance()
ws.on('open', ws.auth.bind(ws))
ws.once('auth', () => {
const o = new Order({
gid: null,
cid: 0,
type: 'EXCHANGE LIMIT',
price: 100,
amount: 1,
symbol: 'tBTCUSD'
}, ws)
o.registerListeners()
o.submit().then(() => {
it('_handleInfoEvent: closes & emits error if not on api v2', (done) => {
const wss = new MockWSv2Server()
const ws = createTestWSv2Instance()
let seen = 0
const d = () => {
wss.close()
done()
}
ws.once('open', () => {
ws.on('error', () => { if (++seen === 2) { d() } })
ws.on('close', () => { if (++seen === 2) { d() } })
ws._handleInfoEvent({ version: 3 })
})
ws.open()
it('tracks channel refs to auto sub/unsub', (done) => {
const ws = createTestWSv2Instance()
const wss = new MockWSv2Server()
let subs = 0
let unsubs = 0
wss.on('message', (ws, msg) => {
if (msg.event === 'subscribe' && msg.channel === 'trades') {
subs++
ws.send(JSON.stringify({
event: 'subscribed',
chanId: 42,
channel: 'trades',
symbol: msg.symbol
}))
} else if (msg.event === 'unsubscribe' && msg.chanId === 42) {
unsubs++
ws.send(JSON.stringify({
event: 'unsubscribed',
it('updateOrder: sends order changeset packet through', (done) => {
const wss = new MockWSv2Server()
const wsSingle = createTestWSv2Instance()
wsSingle.open()
wsSingle.on('open', wsSingle.auth.bind(wsSingle))
wsSingle.once('auth', () => {
const o = new Order({
id: Date.now(),
type: 'EXCHANGE LIMIT',
price: 100,
amount: 1,
symbol: 'tBTCUSD'
}, wsSingle)
wsSingle._ws.send = (msgJSON) => {
const msg = JSON.parse(msgJSON)
assert.strictEqual(msg[0], 0)
it(`${name}: fetches expected data`, (done) => {
const srv = new MockRESTv2Server({ listen: true })
const r = getTestREST2()
const nn = n++
srv.setResponse(dataKey, [nn])
args.push((err, res) => {
if (err) {
return srv.close().then(() => done(err)).catch(done)
}
assert.deepEqual(res, [nn])
srv.close().then(done).catch(done)
})
r[name].apply(r, args)
})