@bitfinex/bfx-facs-grc 1.2.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bitfinex/bfx-facs-grc",
3
- "version": "1.2.1",
3
+ "version": "2.0.0",
4
4
  "private": false,
5
5
  "description": "Bitfinex Grenache Facility",
6
6
  "author": {
@@ -12,20 +12,20 @@
12
12
  "bitfinex"
13
13
  ],
14
14
  "scripts": {
15
- "lint": "standard",
16
- "lint:fix": "standard --fix",
15
+ "lint": "bfx-lint-js",
16
+ "lint:fix": "bfx-lint-js --fix",
17
17
  "test": "npm run lint && npm run unit",
18
- "unit": "mocha"
18
+ "unit": "brittle-node test/**/*.test.js"
19
19
  },
20
20
  "dependencies": {
21
- "@bitfinex/bfx-facs-base": "git+https://github.com/bitfinexcom/bfx-facs-base.git",
22
- "@bitfinex/lib-js-util-base": "git+https://github.com/bitfinexcom/lib-js-util-base#v2.0.2",
23
- "async": "3.2.6",
24
- "grenache-nodejs-http": "1.0.2",
25
- "grenache-nodejs-link": "1.0.2"
21
+ "@bitfinex/bfx-facs-base": "git+https://github.com/bitfinexcom/bfx-facs-base.git#v2.0.0",
22
+ "@bitfinex/lib-js-util-base": "git+https://github.com/bitfinexcom/lib-js-util-base.git#v3.0.0",
23
+ "async": "^3.2.6",
24
+ "grenache-nodejs-http": "2.0.0",
25
+ "grenache-nodejs-link": "2.0.0"
26
26
  },
27
27
  "engines": {
28
- "node": ">=16.0"
28
+ "node": ">=22.0"
29
29
  },
30
30
  "license": "Apache-2.0",
31
31
  "repository": {
@@ -39,8 +39,8 @@
39
39
  }
40
40
  ],
41
41
  "devDependencies": {
42
- "@bitfinex/bfx-svc-test-helper": "git+https://github.com/bitfinexcom/bfx-svc-test-helper.git",
43
- "mocha": "11.2.2",
44
- "standard": "17.1.2"
42
+ "@bitfinex/bfx-svc-test-helper": "git+https://github.com/bitfinexcom/bfx-svc-test-helper.git#v2.0.0",
43
+ "@bitfinex/lint-js": "^1.1.0",
44
+ "brittle": "^4.5.0"
45
45
  }
46
46
  }
package/test/map.test.js CHANGED
@@ -1,13 +1,9 @@
1
- /* eslint-env mocha */
2
-
3
1
  'use strict'
4
2
 
5
- const assert = require('assert')
3
+ const test = require('brittle')
6
4
  const { promisify } = require('util')
7
-
8
5
  const createGrapes = require('@bitfinex/bfx-svc-test-helper/grapes')
9
6
  const createFxGrenache = require('@bitfinex/bfx-svc-test-helper/fauxgrenache')
10
-
11
7
  const Fac = require('..')
12
8
 
13
9
  const stubs = {
@@ -31,124 +27,142 @@ fac.conf = { grape: 'http://127.0.0.1:30001', transport: 'http' }
31
27
 
32
28
  let fxg1
33
29
  let fxg2
34
- describe('RPC integration: map', () => {
35
- before(async function () {
36
- this.timeout(20000)
37
30
 
38
- grapes.onAnnounce()
31
+ const testCase = (testBlock) => async (t) => {
32
+ try {
33
+ await before()
39
34
 
40
- await grapes.start()
41
- fxg1 = createFxGrenache(stubs, grapes, { port: 1557 })
42
- fxg2 = createFxGrenache(stubs, grapes, { port: 1558 })
43
- await fxg1.start()
44
- await fxg2.start()
35
+ await testBlock(t)
36
+ } finally {
37
+ await after()
38
+ }
39
+ }
45
40
 
46
- const start = promisify(fac.start).bind(fac)
47
- await start()
48
- })
41
+ const before = async () => {
42
+ grapes.onAnnounce()
49
43
 
50
- after(async function () {
51
- this.timeout(5000)
44
+ await grapes.start()
45
+ fxg1 = createFxGrenache(stubs, grapes, { port: 1557 })
46
+ fxg2 = createFxGrenache(stubs, grapes, { port: 1558 })
47
+ await fxg1.start()
48
+ await fxg2.start()
52
49
 
53
- await grapes.stop()
54
- await fxg1.stop()
55
- await fxg2.stop()
56
- fac.stop()
57
- })
50
+ const start = promisify(fac.start).bind(fac)
51
+ await start()
52
+ }
53
+
54
+ const after = async () => {
55
+ await grapes.stop()
56
+ await fxg1.stop()
57
+ await fxg2.stop()
58
+ fac.stop()
59
+ }
58
60
 
59
- describe('callback', () => {
60
- it('options defaults', done => {
61
- fac.map('rest:util:net', 'getIpInfo', ['8.8.8.8'], (_err, res) => {
62
- assert.deepStrictEqual([
63
- ['8.8.8.8', { country: 'US', region: 'CA' }],
64
- ['8.8.8.8', { country: 'US', region: 'CA' }]
65
- ], res)
66
- done()
61
+ test('RPC integration: map', testCase(async (t) => {
62
+ await t.test('callback', async (t) => {
63
+ t.test('options defaults', async (t) => {
64
+ await new Promise(resolve => {
65
+ fac.map('rest:util:net', 'getIpInfo', ['8.8.8.8'], (_err, res) => {
66
+ t.alike([
67
+ ['8.8.8.8', { country: 'US', region: 'CA' }],
68
+ ['8.8.8.8', { country: 'US', region: 'CA' }]
69
+ ], res)
70
+ resolve()
71
+ })
67
72
  })
68
73
  })
69
74
 
70
- it('success', done => {
71
- fac.map('rest:util:net', 'getIpInfo', ['8.8.8.8'], {}, (_err, res) => {
72
- assert.deepStrictEqual([
73
- ['8.8.8.8', { country: 'US', region: 'CA' }],
74
- ['8.8.8.8', { country: 'US', region: 'CA' }]
75
- ], res)
76
- done()
75
+ await t.test('success', async (t) => {
76
+ await new Promise(resolve => {
77
+ fac.map('rest:util:net', 'getIpInfo', ['8.8.8.8'], {}, (_err, res) => {
78
+ t.alike([
79
+ ['8.8.8.8', { country: 'US', region: 'CA' }],
80
+ ['8.8.8.8', { country: 'US', region: 'CA' }]
81
+ ], res)
82
+ resolve()
83
+ })
77
84
  })
78
85
  })
79
86
 
80
- it('lookup error', done => {
81
- fac.map('foo:test:net', 'getIpInfo', [], {}, (err, res) => {
82
- assert.strictEqual(err.message, 'ERR_GRAPE_LOOKUP_EMPTY')
83
- done()
87
+ await t.test('lookup error', async (t) => {
88
+ await new Promise(resolve => {
89
+ fac.map('foo:test:net', 'getIpInfo', [], {}, (err) => {
90
+ t.is(err.message, 'ERR_GRAPE_LOOKUP_EMPTY')
91
+ resolve()
92
+ })
84
93
  })
85
94
  })
86
95
 
87
- it('double cb error', done => {
96
+ await t.test('double cb error', async (t) => {
88
97
  const originalPeer = fac.peer
89
98
  const originalConsoleError = console.error
90
99
 
91
- let errorArgs
92
- console.error = (...args) => {
93
- if (errorArgs) {
94
- done(new Error('Should have been called once'))
100
+ await new Promise((resolve, reject) => {
101
+ let errorArgs
102
+ console.error = (...args) => {
103
+ if (errorArgs) {
104
+ reject(new Error('Should have been called once'))
105
+ }
106
+ errorArgs = args
95
107
  }
96
- errorArgs = args
97
- }
98
108
 
99
- fac.peer = {
100
- map (service, args, opts, cb) {
101
- cb()
102
- cb()
103
- fac.peer = originalPeer
104
- console.error = originalConsoleError
105
- assert.strictEqual(errorArgs[0], 'ERR_DOUBLE_CB')
106
- assert.strictEqual(errorArgs[1], 'rest:util:net')
107
- assert.strictEqual(errorArgs[2], 'getIpInfo')
108
- done()
109
+ fac.peer = {
110
+ map (service, args, opts, cb) {
111
+ cb()
112
+ cb()
113
+ fac.peer = originalPeer
114
+ console.error = originalConsoleError
115
+ t.is(errorArgs[0], 'ERR_DOUBLE_CB')
116
+ t.is(errorArgs[1], 'rest:util:net')
117
+ t.is(errorArgs[2], 'getIpInfo')
118
+ }
109
119
  }
110
- }
111
-
112
- fac.map('rest:util:net', 'getIpInfo', [], {}, () => {
113
- assert.strictEqual(errorArgs, undefined)
120
+ fac.map('rest:util:net', 'getIpInfo', [], {}, () => {
121
+ t.is(errorArgs, undefined)
122
+ resolve()
123
+ })
114
124
  })
115
125
  })
116
126
 
117
- it('invalid args', done => {
118
- fac.map('rest:util:net', 'getIpInfo', {}, {}, (err, res) => {
119
- assert.strictEqual(err.message, 'ERR_GRC_REQ_ARGS_INVALID')
120
- done()
127
+ await t.test('invalid args', async (t) => {
128
+ await new Promise(resolve => {
129
+ fac.map('rest:util:net', 'getIpInfo', {}, {}, (err) => {
130
+ t.is(err.message, 'ERR_GRC_REQ_ARGS_INVALID')
131
+ resolve()
132
+ })
121
133
  })
122
134
  })
123
135
 
124
- it('invalid action', done => {
125
- fac.map('rest:util:net', {}, [], {}, (err, res) => {
126
- assert.strictEqual(err.message, 'ERR_GRC_REQ_ACTION_INVALID')
127
- done()
136
+ await t.test('invalid action', async (t) => {
137
+ await new Promise(resolve => {
138
+ fac.map('rest:util:net', {}, [], {}, (err) => {
139
+ t.is(err.message, 'ERR_GRC_REQ_ACTION_INVALID')
140
+ resolve()
141
+ })
128
142
  })
129
143
  })
130
144
  })
131
145
 
132
- describe('promise', () => {
133
- it('success', async () => {
146
+ await t.test('promise', async (t) => {
147
+ await t.test('success', async (t) => {
134
148
  const res = await fac.map('rest:util:net', 'getIpInfo', ['8.8.8.8'], {})
135
- assert.deepStrictEqual([
149
+ t.alike([
136
150
  ['8.8.8.8', { country: 'US', region: 'CA' }],
137
151
  ['8.8.8.8', { country: 'US', region: 'CA' }]
138
152
  ], res)
139
153
  })
140
154
 
141
- it('lookup error', async () => {
155
+ await t.test('lookup error', async () => {
142
156
  try {
143
157
  await fac.map('foo:test:net', 'getIpInfo', [], {})
144
158
  } catch (e) {
145
- assert.strictEqual(e.message, 'ERR_GRAPE_LOOKUP_EMPTY')
159
+ t.is(e.message, 'ERR_GRAPE_LOOKUP_EMPTY')
146
160
  return
147
161
  }
148
162
  throw new Error('Should have thrown')
149
163
  })
150
164
 
151
- it('double cb error', async () => {
165
+ await t.test('double cb error', async () => {
152
166
  const originalPeer = fac.peer
153
167
  const originalConsoleError = console.error
154
168
 
@@ -156,9 +170,9 @@ describe('RPC integration: map', () => {
156
170
  map (service, args, opts, cb) {
157
171
  cb()
158
172
  cb()
159
- assert.strictEqual(errorArgs[0], 'ERR_DOUBLE_CB')
160
- assert.strictEqual(errorArgs[1], 'rest:util:net')
161
- assert.strictEqual(errorArgs[2], 'getIpInfo')
173
+ t.is(errorArgs[0], 'ERR_DOUBLE_CB')
174
+ t.is(errorArgs[1], 'rest:util:net')
175
+ t.is(errorArgs[2], 'getIpInfo')
162
176
  fac.peer = originalPeer
163
177
  console.error = originalConsoleError
164
178
  }
@@ -175,24 +189,24 @@ describe('RPC integration: map', () => {
175
189
  await fac.map('rest:util:net', 'getIpInfo', [], {})
176
190
  })
177
191
 
178
- it('invalid args', async () => {
192
+ await t.test('invalid args', async () => {
179
193
  try {
180
194
  await fac.map('rest:util:net', 'getIpInfo', {}, {})
181
195
  } catch (e) {
182
- assert.strictEqual(e.message, 'ERR_GRC_REQ_ARGS_INVALID')
196
+ t.is(e.message, 'ERR_GRC_REQ_ARGS_INVALID')
183
197
  return
184
198
  }
185
199
  throw new Error('Should have thrown')
186
200
  })
187
201
 
188
- it('invalid action', async () => {
202
+ await t.test('invalid action', async () => {
189
203
  try {
190
204
  await fac.map('rest:util:net', {}, [], {})
191
205
  } catch (e) {
192
- assert.strictEqual(e.message, 'ERR_GRC_REQ_ACTION_INVALID')
206
+ t.is(e.message, 'ERR_GRC_REQ_ACTION_INVALID')
193
207
  return
194
208
  }
195
209
  throw new Error('Should have thrown')
196
210
  })
197
211
  })
198
- })
212
+ }))
package/test/req.test.js CHANGED
@@ -1,13 +1,9 @@
1
- /* eslint-env mocha */
2
-
3
1
  'use strict'
4
2
 
5
- const assert = require('assert')
3
+ const test = require('brittle')
6
4
  const { promisify } = require('util')
7
-
8
5
  const createGrapes = require('@bitfinex/bfx-svc-test-helper/grapes')
9
6
  const createFxGrenache = require('@bitfinex/bfx-svc-test-helper/fauxgrenache')
10
-
11
7
  const Fac = require('..')
12
8
 
13
9
  const stubs = {
@@ -31,110 +27,128 @@ fac.tick = () => {}
31
27
  fac.conf = { grape: 'http://127.0.0.1:30001', transport: 'http' }
32
28
 
33
29
  let fxg
34
- describe('RPC integration: req', () => {
35
- before(async function () {
36
- this.timeout(20000)
37
30
 
38
- await grapes.start()
39
- fxg = createFxGrenache(stubs, grapes)
40
- await fxg.start()
31
+ const testCase = (testBlock) => async (t) => {
32
+ try {
33
+ await before()
41
34
 
42
- const start = promisify(fac.start).bind(fac)
43
- await start()
44
- })
35
+ await testBlock(t)
36
+ } finally {
37
+ await after()
38
+ }
39
+ }
45
40
 
46
- after(async function () {
47
- this.timeout(5000)
41
+ const before = async () => {
42
+ await grapes.start()
43
+ fxg = createFxGrenache(stubs, grapes)
44
+ await fxg.start()
48
45
 
49
- await grapes.stop()
50
- await fxg.stop()
51
- fac.stop()
52
- })
46
+ const start = promisify(fac.start).bind(fac)
47
+ await start()
48
+ }
49
+
50
+ const after = async () => {
51
+ await grapes.stop()
52
+ await fxg.stop()
53
+ fac.stop()
54
+ }
53
55
 
54
- describe('callback', () => {
55
- it('options defaults', done => {
56
- fac.req('rest:util:net', 'getIpInfo', ['8.8.8.8'], (_err, res) => {
57
- assert.deepStrictEqual(['8.8.8.8', { country: 'US', region: 'CA' }], res)
58
- done()
56
+ test('RPC integration: req', testCase(async (t) => {
57
+ await t.test('callback', async (t) => {
58
+ await t.test('options defaults', async (t) => {
59
+ await new Promise(resolve => {
60
+ fac.req('rest:util:net', 'getIpInfo', ['8.8.8.8'], (_err, res) => {
61
+ t.alike(['8.8.8.8', { country: 'US', region: 'CA' }], res)
62
+ resolve()
63
+ })
59
64
  })
60
65
  })
61
66
 
62
- it('success', done => {
63
- fac.req('rest:util:net', 'getIpInfo', ['8.8.8.8'], {}, (_err, res) => {
64
- assert.deepStrictEqual(['8.8.8.8', { country: 'US', region: 'CA' }], res)
65
- done()
67
+ await t.test('success', async (t) => {
68
+ await new Promise(resolve => {
69
+ fac.req('rest:util:net', 'getIpInfo', ['8.8.8.8'], {}, (_err, res) => {
70
+ t.alike(['8.8.8.8', { country: 'US', region: 'CA' }], res)
71
+ resolve()
72
+ })
66
73
  })
67
74
  })
68
75
 
69
- it('lookup error', done => {
70
- fac.req('foo:test:net', 'getIpInfo', ['8.8.8.8'], {}, (err) => {
71
- assert.strictEqual(err.message, 'ERR_GRAPE_LOOKUP_EMPTY')
72
- done()
76
+ await t.test('lookup error', async (t) => {
77
+ await new Promise(resolve => {
78
+ fac.req('foo:test:net', 'getIpInfo', ['8.8.8.8'], {}, (err) => {
79
+ t.is(err.message, 'ERR_GRAPE_LOOKUP_EMPTY')
80
+ resolve()
81
+ })
73
82
  })
74
83
  })
75
84
 
76
- it('double cb error', done => {
85
+ await t.test('double cb error', async (t) => {
77
86
  const originalPeer = fac.peer
78
87
  const originalConsoleError = console.error
79
88
 
80
- let errorArgs
81
- console.error = (...args) => {
82
- if (errorArgs) {
83
- done(new Error('Should have been called once'))
89
+ await new Promise((resolve, reject) => {
90
+ let errorArgs
91
+ console.error = (...args) => {
92
+ if (errorArgs) {
93
+ reject(new Error('Should have been called once'))
94
+ }
95
+ errorArgs = args
84
96
  }
85
- errorArgs = args
86
- }
87
-
88
- fac.peer = {
89
- request (service, args, opts, cb) {
90
- cb()
91
- cb()
92
- fac.peer = originalPeer
93
- console.error = originalConsoleError
94
- assert.strictEqual(errorArgs[0], 'ERR_DOUBLE_CB')
95
- assert.strictEqual(errorArgs[1], 'rest:util:net')
96
- assert.strictEqual(errorArgs[2], 'getIpInfo')
97
- done()
97
+ fac.peer = {
98
+ request (service, args, opts, cb) {
99
+ cb()
100
+ cb()
101
+ fac.peer = originalPeer
102
+ console.error = originalConsoleError
103
+ t.is(errorArgs[0], 'ERR_DOUBLE_CB')
104
+ t.is(errorArgs[1], 'rest:util:net')
105
+ t.is(errorArgs[2], 'getIpInfo')
106
+ }
98
107
  }
99
- }
100
108
 
101
- fac.req('rest:util:net', 'getIpInfo', [], {}, () => {
102
- assert.strictEqual(errorArgs, undefined)
109
+ fac.req('rest:util:net', 'getIpInfo', [], {}, () => {
110
+ t.is(errorArgs, undefined)
111
+ resolve()
112
+ })
103
113
  })
104
114
  })
105
115
 
106
- it('invalid args', done => {
107
- fac.req('rest:util:net', 'getIpInfo', {}, {}, (err, res) => {
108
- assert.strictEqual(err.message, 'ERR_GRC_REQ_ARGS_INVALID')
109
- done()
116
+ await t.test('invalid args', async (t) => {
117
+ await new Promise(resolve => {
118
+ fac.req('rest:util:net', 'getIpInfo', {}, {}, (err) => {
119
+ t.is(err.message, 'ERR_GRC_REQ_ARGS_INVALID')
120
+ resolve()
121
+ })
110
122
  })
111
123
  })
112
124
 
113
- it('invalid action', done => {
114
- fac.req('rest:util:net', {}, [], {}, (err, res) => {
115
- assert.strictEqual(err.message, 'ERR_GRC_REQ_ACTION_INVALID')
116
- done()
125
+ await t.test('invalid action', async (t) => {
126
+ await new Promise(resolve => {
127
+ fac.req('rest:util:net', {}, [], {}, (err) => {
128
+ t.is(err.message, 'ERR_GRC_REQ_ACTION_INVALID')
129
+ resolve()
130
+ })
117
131
  })
118
132
  })
119
133
  })
120
134
 
121
- describe('promise', () => {
122
- it('success', async () => {
135
+ await t.test('promise', async (t) => {
136
+ await t.test('success', async (t) => {
123
137
  const res = await fac.req('rest:util:net', 'getIpInfo', ['8.8.8.8'], {})
124
- assert.deepStrictEqual(['8.8.8.8', { country: 'US', region: 'CA' }], res)
138
+ t.alike(['8.8.8.8', { country: 'US', region: 'CA' }], res)
125
139
  })
126
140
 
127
- it('lookup error', async () => {
141
+ await t.test('lookup error', async (t) => {
128
142
  try {
129
143
  await fac.req('foo:test:net', 'getIpInfo', [], {})
130
144
  } catch (e) {
131
- assert.strictEqual(e.message, 'ERR_GRAPE_LOOKUP_EMPTY')
145
+ t.is(e.message, 'ERR_GRAPE_LOOKUP_EMPTY')
132
146
  return
133
147
  }
134
148
  throw new Error('Should have thrown')
135
149
  })
136
150
 
137
- it('double cb error', async () => {
151
+ await t.test('double cb error', async (t) => {
138
152
  const originalPeer = fac.peer
139
153
  const originalConsoleError = console.error
140
154
 
@@ -142,9 +156,9 @@ describe('RPC integration: req', () => {
142
156
  request (service, args, opts, cb) {
143
157
  cb()
144
158
  cb()
145
- assert.strictEqual(errorArgs[0], 'ERR_DOUBLE_CB')
146
- assert.strictEqual(errorArgs[1], 'rest:util:net')
147
- assert.strictEqual(errorArgs[2], 'getIpInfo')
159
+ t.is(errorArgs[0], 'ERR_DOUBLE_CB')
160
+ t.is(errorArgs[1], 'rest:util:net')
161
+ t.is(errorArgs[2], 'getIpInfo')
148
162
  fac.peer = originalPeer
149
163
  console.error = originalConsoleError
150
164
  }
@@ -161,24 +175,24 @@ describe('RPC integration: req', () => {
161
175
  await fac.req('rest:util:net', 'getIpInfo', [], {})
162
176
  })
163
177
 
164
- it('invalid args', async () => {
178
+ await t.test('invalid args', async (t) => {
165
179
  try {
166
180
  await fac.req('rest:util:net', 'getIpInfo', {}, {})
167
181
  } catch (e) {
168
- assert.strictEqual(e.message, 'ERR_GRC_REQ_ARGS_INVALID')
182
+ t.is(e.message, 'ERR_GRC_REQ_ARGS_INVALID')
169
183
  return
170
184
  }
171
185
  throw new Error('Should have thrown')
172
186
  })
173
187
 
174
- it('invalid action', async () => {
188
+ await t.test('invalid action', async (t) => {
175
189
  try {
176
190
  await fac.req('rest:util:net', {}, [], {})
177
191
  } catch (e) {
178
- assert.strictEqual(e.message, 'ERR_GRC_REQ_ACTION_INVALID')
192
+ t.is(e.message, 'ERR_GRC_REQ_ACTION_INVALID')
179
193
  return
180
194
  }
181
195
  throw new Error('Should have thrown')
182
196
  })
183
197
  })
184
- })
198
+ }))