prool 0.0.25 → 0.1.1
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/{LICENSE → LICENSE.md} +1 -1
- package/README.md +46 -163
- package/{_lib/instance.d.ts → dist/Instance.d.ts} +28 -25
- package/dist/Instance.d.ts.map +1 -0
- package/{_lib/instance.js → dist/Instance.js} +9 -4
- package/dist/Instance.js.map +1 -0
- package/{_lib/pool.d.ts → dist/Pool.d.ts} +15 -13
- package/dist/Pool.d.ts.map +1 -0
- package/{_lib/pool.js → dist/Pool.js} +3 -3
- package/dist/Pool.js.map +1 -0
- package/{_lib/server.d.ts → dist/Server.d.ts} +7 -10
- package/dist/Server.d.ts.map +1 -0
- package/{_lib/server.js → dist/Server.js} +8 -9
- package/dist/Server.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/instances/alto.d.ts +452 -0
- package/dist/instances/alto.d.ts.map +1 -0
- package/{_lib → dist}/instances/alto.js +4 -4
- package/dist/instances/alto.js.map +1 -0
- package/dist/instances/anvil.d.ts +458 -0
- package/dist/instances/anvil.d.ts.map +1 -0
- package/{_lib → dist}/instances/anvil.js +4 -4
- package/dist/instances/anvil.js.map +1 -0
- package/dist/instances/tempo.d.ts +189 -0
- package/dist/instances/tempo.d.ts.map +1 -0
- package/dist/instances/tempo.js +200 -0
- package/dist/instances/tempo.js.map +1 -0
- package/{_lib → dist/internal}/utils.d.ts +5 -5
- package/dist/internal/utils.d.ts.map +1 -0
- package/{_lib → dist/internal}/utils.js +37 -7
- package/dist/internal/utils.js.map +1 -0
- package/{_lib → dist}/processes/execa.d.ts +11 -10
- package/dist/processes/execa.d.ts.map +1 -0
- package/{_lib → dist}/processes/execa.js +1 -1
- package/dist/processes/execa.js.map +1 -0
- package/package.json +17 -16
- package/{instance.test.ts → src/Instance.test.ts} +12 -12
- package/{instance.ts → src/Instance.ts} +51 -42
- package/{pool.test.ts → src/Pool.test.ts} +41 -55
- package/{pool.ts → src/Pool.ts} +21 -19
- package/{server.test.ts → src/Server.test.ts} +26 -149
- package/{server.ts → src/Server.ts} +9 -11
- package/src/index.ts +3 -0
- package/{instances → src/instances}/alto.test.ts +8 -11
- package/src/instances/alto.ts +289 -0
- package/{instances → src/instances}/anvil.test.ts +5 -6
- package/src/instances/anvil.ts +306 -0
- package/{instances/silius.test.ts → src/instances/tempo.test.ts} +20 -44
- package/src/instances/tempo.ts +322 -0
- package/{utils.test.ts → src/internal/utils.test.ts} +20 -6
- package/{utils.ts → src/internal/utils.ts} +47 -17
- package/{processes → src/processes}/execa.test.ts +6 -11
- package/{processes → src/processes}/execa.ts +19 -15
- package/src/processes/index.ts +1 -0
- package/CHANGELOG.md +0 -154
- package/_lib/exports/index.d.ts +0 -5
- package/_lib/exports/index.d.ts.map +0 -1
- package/_lib/exports/index.js +0 -5
- package/_lib/exports/index.js.map +0 -1
- package/_lib/exports/instances.d.ts +0 -7
- package/_lib/exports/instances.d.ts.map +0 -1
- package/_lib/exports/instances.js +0 -7
- package/_lib/exports/instances.js.map +0 -1
- package/_lib/exports/processes.d.ts +0 -2
- package/_lib/exports/processes.d.ts.map +0 -1
- package/_lib/exports/processes.js +0 -2
- package/_lib/exports/processes.js.map +0 -1
- package/_lib/instance.d.ts.map +0 -1
- package/_lib/instance.js.map +0 -1
- package/_lib/instances/alto.d.ts +0 -449
- package/_lib/instances/alto.d.ts.map +0 -1
- package/_lib/instances/alto.js.map +0 -1
- package/_lib/instances/anvil.d.ts +0 -455
- package/_lib/instances/anvil.d.ts.map +0 -1
- package/_lib/instances/anvil.js.map +0 -1
- package/_lib/instances/rundler.d.ts +0 -604
- package/_lib/instances/rundler.d.ts.map +0 -1
- package/_lib/instances/rundler.js +0 -86
- package/_lib/instances/rundler.js.map +0 -1
- package/_lib/instances/silius.d.ts +0 -224
- package/_lib/instances/silius.d.ts.map +0 -1
- package/_lib/instances/silius.js +0 -117
- package/_lib/instances/silius.js.map +0 -1
- package/_lib/instances/stackup.d.ts +0 -86
- package/_lib/instances/stackup.d.ts.map +0 -1
- package/_lib/instances/stackup.js +0 -89
- package/_lib/instances/stackup.js.map +0 -1
- package/_lib/pool.d.ts.map +0 -1
- package/_lib/pool.js.map +0 -1
- package/_lib/processes/execa.d.ts.map +0 -1
- package/_lib/processes/execa.js.map +0 -1
- package/_lib/server.d.ts.map +0 -1
- package/_lib/server.js.map +0 -1
- package/_lib/utils.d.ts.map +0 -1
- package/_lib/utils.js.map +0 -1
- package/exports/index.test.ts +0 -16
- package/exports/index.ts +0 -29
- package/exports/instances.test.ts +0 -15
- package/exports/instances.ts +0 -13
- package/exports/processes.test.ts +0 -10
- package/exports/processes.ts +0 -8
- package/instances/alto.ts +0 -280
- package/instances/anvil.ts +0 -304
- package/instances/package.json +0 -5
- package/instances/rundler.test.ts +0 -111
- package/instances/rundler.ts +0 -451
- package/instances/silius.ts +0 -347
- package/instances/stackup.test.ts +0 -106
- package/instances/stackup.ts +0 -162
- package/processes/package.json +0 -5
- package/tsconfig.build.tsbuildinfo +0 -1
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { EventEmitter } from 'eventemitter3'
|
|
2
2
|
|
|
3
|
+
export { alto } from './instances/alto.js'
|
|
4
|
+
export { anvil } from './instances/anvil.js'
|
|
5
|
+
export { tempo, tempoDocker } from './instances/tempo.js'
|
|
6
|
+
|
|
3
7
|
type EventTypes = {
|
|
4
8
|
exit: [code: number | null, signal: NodeJS.Signals | null]
|
|
5
9
|
listening: []
|
|
@@ -8,34 +12,6 @@ type EventTypes = {
|
|
|
8
12
|
stdout: [message: string]
|
|
9
13
|
}
|
|
10
14
|
|
|
11
|
-
export type InstanceStartOptions_internal = {
|
|
12
|
-
emitter: EventEmitter<EventTypes>
|
|
13
|
-
status: Instance['status']
|
|
14
|
-
}
|
|
15
|
-
export type InstanceStopOptions_internal = {
|
|
16
|
-
emitter: EventEmitter<EventTypes>
|
|
17
|
-
status: Instance['status']
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type InstanceStartOptions = {
|
|
21
|
-
/**
|
|
22
|
-
* Port to start the instance on.
|
|
23
|
-
*/
|
|
24
|
-
port?: number | undefined
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type DefineInstanceFn<
|
|
28
|
-
parameters,
|
|
29
|
-
_internal extends object | undefined = object | undefined,
|
|
30
|
-
> = (parameters: parameters) => Pick<Instance, 'host' | 'name' | 'port'> & {
|
|
31
|
-
_internal?: _internal | undefined
|
|
32
|
-
start(
|
|
33
|
-
options: InstanceStartOptions,
|
|
34
|
-
options_internal: InstanceStartOptions_internal,
|
|
35
|
-
): Promise<void>
|
|
36
|
-
stop(options_internal: InstanceStopOptions_internal): Promise<void>
|
|
37
|
-
}
|
|
38
|
-
|
|
39
15
|
export type Instance<
|
|
40
16
|
_internal extends object | undefined = object | undefined,
|
|
41
17
|
> = Pick<
|
|
@@ -111,15 +87,6 @@ export type InstanceOptions = {
|
|
|
111
87
|
timeout?: number
|
|
112
88
|
}
|
|
113
89
|
|
|
114
|
-
export type DefineInstanceReturnType<
|
|
115
|
-
_internal extends object | undefined = object | undefined,
|
|
116
|
-
parameters = undefined,
|
|
117
|
-
> = (
|
|
118
|
-
...parameters: parameters extends undefined
|
|
119
|
-
? [options?: InstanceOptions]
|
|
120
|
-
: [parameters: parameters, options?: InstanceOptions]
|
|
121
|
-
) => Instance<_internal>
|
|
122
|
-
|
|
123
90
|
/**
|
|
124
91
|
* Creates an instance definition.
|
|
125
92
|
*
|
|
@@ -127,7 +94,7 @@ export type DefineInstanceReturnType<
|
|
|
127
94
|
*
|
|
128
95
|
* @example
|
|
129
96
|
* ```ts
|
|
130
|
-
* const foo =
|
|
97
|
+
* const foo = Instance.define((parameters: FooParameters) => {
|
|
131
98
|
* return {
|
|
132
99
|
* name: 'foo',
|
|
133
100
|
* host: 'localhost',
|
|
@@ -142,20 +109,22 @@ export type DefineInstanceReturnType<
|
|
|
142
109
|
* })
|
|
143
110
|
* ```
|
|
144
111
|
*/
|
|
145
|
-
export function
|
|
112
|
+
export function define<
|
|
146
113
|
_internal extends object | undefined,
|
|
147
114
|
parameters = undefined,
|
|
148
115
|
>(
|
|
149
|
-
fn:
|
|
150
|
-
):
|
|
116
|
+
fn: define.DefineFn<parameters, _internal>,
|
|
117
|
+
): define.ReturnType<_internal, parameters> {
|
|
151
118
|
return (...[parametersOrOptions, options_]) => {
|
|
152
119
|
function create(createParameters: Parameters<Instance['create']>[0] = {}) {
|
|
153
120
|
const parameters = parametersOrOptions as parameters
|
|
154
121
|
const options = options_ || parametersOrOptions || {}
|
|
155
122
|
|
|
123
|
+
const instance = fn(parameters)
|
|
156
124
|
const { _internal, host, name, port, start, stop } = {
|
|
157
|
-
...
|
|
125
|
+
...instance,
|
|
158
126
|
...createParameters,
|
|
127
|
+
port: createParameters.port ?? instance.port,
|
|
159
128
|
}
|
|
160
129
|
const { messageBuffer = 20, timeout } = options
|
|
161
130
|
|
|
@@ -308,3 +277,43 @@ export function defineInstance<
|
|
|
308
277
|
return Object.assign(create(), { create })
|
|
309
278
|
}
|
|
310
279
|
}
|
|
280
|
+
|
|
281
|
+
export declare namespace define {
|
|
282
|
+
export type DefineFn<
|
|
283
|
+
parameters,
|
|
284
|
+
_internal extends object | undefined = object | undefined,
|
|
285
|
+
> = (parameters: parameters) => Pick<Instance, 'host' | 'name' | 'port'> & {
|
|
286
|
+
_internal?: _internal | undefined
|
|
287
|
+
start(
|
|
288
|
+
options: InstanceStartOptions,
|
|
289
|
+
options_internal: InstanceStartOptions_internal,
|
|
290
|
+
): Promise<void>
|
|
291
|
+
stop(options_internal: InstanceStopOptions_internal): Promise<void>
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export type ReturnType<
|
|
295
|
+
_internal extends object | undefined = object | undefined,
|
|
296
|
+
parameters = undefined,
|
|
297
|
+
> = (
|
|
298
|
+
...parameters: parameters extends undefined
|
|
299
|
+
? [options?: InstanceOptions]
|
|
300
|
+
: [parameters: parameters, options?: InstanceOptions]
|
|
301
|
+
) => Instance<_internal>
|
|
302
|
+
|
|
303
|
+
export type InstanceStartOptions_internal = {
|
|
304
|
+
emitter: EventEmitter<EventTypes>
|
|
305
|
+
status: Instance['status']
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export type InstanceStopOptions_internal = {
|
|
309
|
+
emitter: EventEmitter<EventTypes>
|
|
310
|
+
status: Instance['status']
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export type InstanceStartOptions = {
|
|
314
|
+
/**
|
|
315
|
+
* Port to start the instance on.
|
|
316
|
+
*/
|
|
317
|
+
port?: number | undefined
|
|
318
|
+
}
|
|
319
|
+
}
|
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import getPort from 'get-port'
|
|
2
|
+
import { Instance, Pool, Server } from 'prool'
|
|
2
3
|
import { afterEach, beforeAll, describe, expect, test } from 'vitest'
|
|
3
4
|
|
|
4
|
-
import { altoOptions
|
|
5
|
-
import { rundler } from './exports/instances.js'
|
|
6
|
-
import { alto } from './instances/alto.js'
|
|
7
|
-
import { anvil } from './instances/anvil.js'
|
|
8
|
-
import { stackup } from './instances/stackup.js'
|
|
9
|
-
import { definePool } from './pool.js'
|
|
10
|
-
import { createServer } from './server.js'
|
|
5
|
+
import { altoOptions } from '../test/utils.js'
|
|
11
6
|
|
|
12
|
-
let pool: ReturnType<typeof
|
|
7
|
+
let pool: ReturnType<typeof Pool.define>
|
|
13
8
|
const port = await getPort()
|
|
14
9
|
|
|
15
10
|
beforeAll(() =>
|
|
16
|
-
|
|
17
|
-
instance: anvil({
|
|
11
|
+
Server.create({
|
|
12
|
+
instance: Instance.anvil({
|
|
18
13
|
chainId: 1,
|
|
19
|
-
forkUrl: process.env
|
|
14
|
+
forkUrl: process.env['VITE_FORK_URL'] ?? 'https://eth.merkle.io',
|
|
20
15
|
}),
|
|
21
16
|
port,
|
|
22
17
|
}).start(),
|
|
@@ -31,19 +26,14 @@ afterEach(async () => {
|
|
|
31
26
|
})
|
|
32
27
|
|
|
33
28
|
describe.each([
|
|
34
|
-
{ instance: anvil({ port: await getPort() }) },
|
|
29
|
+
{ instance: Instance.anvil({ port: await getPort() }) },
|
|
30
|
+
{ instance: Instance.tempo({ port: await getPort() }) },
|
|
35
31
|
{
|
|
36
|
-
instance: alto(altoOptions({ port, pool: true })),
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
instance: stackup(stackupOptions({ port, pool: true })),
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
instance: rundler(rundlerOptions({ port, pool: true })),
|
|
32
|
+
instance: Instance.alto(altoOptions({ port, pool: true })),
|
|
43
33
|
},
|
|
44
34
|
])('instance: $instance.name', ({ instance }) => {
|
|
45
35
|
test('default', async () => {
|
|
46
|
-
pool =
|
|
36
|
+
pool = Pool.define({
|
|
47
37
|
instance,
|
|
48
38
|
})
|
|
49
39
|
|
|
@@ -51,7 +41,7 @@ describe.each([
|
|
|
51
41
|
})
|
|
52
42
|
|
|
53
43
|
test('start', async () => {
|
|
54
|
-
pool =
|
|
44
|
+
pool = Pool.define({
|
|
55
45
|
instance,
|
|
56
46
|
})
|
|
57
47
|
|
|
@@ -72,7 +62,7 @@ describe.each([
|
|
|
72
62
|
|
|
73
63
|
test('callback instance', async () => {
|
|
74
64
|
const keys: (number | string)[] = []
|
|
75
|
-
pool =
|
|
65
|
+
pool = Pool.define({
|
|
76
66
|
instance(key) {
|
|
77
67
|
keys.push(key)
|
|
78
68
|
return instance
|
|
@@ -87,7 +77,7 @@ describe.each([
|
|
|
87
77
|
})
|
|
88
78
|
|
|
89
79
|
test('stop / destroy', async () => {
|
|
90
|
-
pool =
|
|
80
|
+
pool = Pool.define({
|
|
91
81
|
instance,
|
|
92
82
|
})
|
|
93
83
|
|
|
@@ -124,32 +114,28 @@ describe.each([
|
|
|
124
114
|
expect(pool.size).toEqual(0)
|
|
125
115
|
})
|
|
126
116
|
|
|
127
|
-
test(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
expect(instance_1.status).toBe('started')
|
|
147
|
-
},
|
|
148
|
-
{ timeout: 10_000 },
|
|
149
|
-
)
|
|
117
|
+
test('restart', { timeout: 10_000 }, async () => {
|
|
118
|
+
pool = Pool.define({
|
|
119
|
+
instance,
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
const instance_1 = await pool.start(1)
|
|
123
|
+
const instance_2 = await pool.start(2)
|
|
124
|
+
const instance_3 = await pool.start(3)
|
|
125
|
+
|
|
126
|
+
expect(instance_1.status).toBe('started')
|
|
127
|
+
expect(instance_2.status).toBe('started')
|
|
128
|
+
expect(instance_3.status).toBe('started')
|
|
129
|
+
expect(pool.size).toEqual(3)
|
|
130
|
+
|
|
131
|
+
const promise_1 = pool.restart(1)
|
|
132
|
+
expect(instance_1.status).toBe('restarting')
|
|
133
|
+
await promise_1
|
|
134
|
+
expect(instance_1.status).toBe('started')
|
|
135
|
+
})
|
|
150
136
|
|
|
151
137
|
test('start > stop > start', async () => {
|
|
152
|
-
pool =
|
|
138
|
+
pool = Pool.define({
|
|
153
139
|
instance,
|
|
154
140
|
})
|
|
155
141
|
|
|
@@ -164,7 +150,7 @@ describe.each([
|
|
|
164
150
|
})
|
|
165
151
|
|
|
166
152
|
test('stopAll / destroyAll', async () => {
|
|
167
|
-
pool =
|
|
153
|
+
pool = Pool.define({
|
|
168
154
|
instance,
|
|
169
155
|
})
|
|
170
156
|
|
|
@@ -182,7 +168,7 @@ describe.each([
|
|
|
182
168
|
})
|
|
183
169
|
|
|
184
170
|
test('get', async () => {
|
|
185
|
-
pool =
|
|
171
|
+
pool = Pool.define({
|
|
186
172
|
instance,
|
|
187
173
|
})
|
|
188
174
|
|
|
@@ -196,7 +182,7 @@ describe.each([
|
|
|
196
182
|
})
|
|
197
183
|
|
|
198
184
|
test('behavior: start more than once', async () => {
|
|
199
|
-
pool =
|
|
185
|
+
pool = Pool.define({
|
|
200
186
|
instance,
|
|
201
187
|
})
|
|
202
188
|
|
|
@@ -210,7 +196,7 @@ describe.each([
|
|
|
210
196
|
})
|
|
211
197
|
|
|
212
198
|
test('behavior: clear more than once', async () => {
|
|
213
|
-
pool =
|
|
199
|
+
pool = Pool.define({
|
|
214
200
|
instance,
|
|
215
201
|
})
|
|
216
202
|
|
|
@@ -227,7 +213,7 @@ describe.each([
|
|
|
227
213
|
})
|
|
228
214
|
|
|
229
215
|
test('behavior: restart more than once', async () => {
|
|
230
|
-
pool =
|
|
216
|
+
pool = Pool.define({
|
|
231
217
|
instance,
|
|
232
218
|
})
|
|
233
219
|
|
|
@@ -248,7 +234,7 @@ describe.each([
|
|
|
248
234
|
})
|
|
249
235
|
|
|
250
236
|
test('behavior: stop more than once', async () => {
|
|
251
|
-
pool =
|
|
237
|
+
pool = Pool.define({
|
|
252
238
|
instance,
|
|
253
239
|
})
|
|
254
240
|
|
|
@@ -265,7 +251,7 @@ describe.each([
|
|
|
265
251
|
test('error: start more than once on same port', async () => {
|
|
266
252
|
const port = await getPort()
|
|
267
253
|
|
|
268
|
-
pool =
|
|
254
|
+
pool = Pool.define({
|
|
269
255
|
instance,
|
|
270
256
|
})
|
|
271
257
|
|
|
@@ -280,7 +266,7 @@ describe.each([
|
|
|
280
266
|
})
|
|
281
267
|
|
|
282
268
|
test('error: instance limit reached', async () => {
|
|
283
|
-
pool =
|
|
269
|
+
pool = Pool.define({
|
|
284
270
|
instance,
|
|
285
271
|
limit: 2,
|
|
286
272
|
})
|
package/{pool.ts → src/Pool.ts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import getPort from 'get-port'
|
|
2
2
|
|
|
3
|
-
import type { Instance } from './
|
|
3
|
+
import type { Instance } from './Instance.js'
|
|
4
4
|
|
|
5
5
|
type Instance_ = Omit<Instance, 'create'>
|
|
6
6
|
|
|
@@ -14,30 +14,20 @@ export type Pool<key extends number | string = number | string> = Pick<
|
|
|
14
14
|
destroy(key: key): Promise<void>
|
|
15
15
|
destroyAll(): Promise<void>
|
|
16
16
|
restart(key: key): Promise<void>
|
|
17
|
-
start(
|
|
17
|
+
start(
|
|
18
|
+
key: key,
|
|
19
|
+
options?: { port?: number | undefined } | undefined,
|
|
20
|
+
): Promise<Instance_>
|
|
18
21
|
stop(key: key): Promise<void>
|
|
19
22
|
stopAll(): Promise<void>
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
export type DefinePoolParameters<
|
|
23
|
-
key extends number | string = number | string,
|
|
24
|
-
> = {
|
|
25
|
-
/** Instance for the pool. */
|
|
26
|
-
instance: Instance | ((key: key) => Instance)
|
|
27
|
-
/** The maximum number of instances that can be started. */
|
|
28
|
-
limit?: number | number
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export type DefinePoolReturnType<
|
|
32
|
-
key extends number | string = number | string,
|
|
33
|
-
> = Pool<key>
|
|
34
|
-
|
|
35
25
|
/**
|
|
36
26
|
* Defines an instance pool. Instances can be started, cached, and stopped against an identifier.
|
|
37
27
|
*
|
|
38
28
|
* @example
|
|
39
29
|
* ```
|
|
40
|
-
* const pool =
|
|
30
|
+
* const pool = Pool.define({
|
|
41
31
|
* instance: anvil(),
|
|
42
32
|
* })
|
|
43
33
|
*
|
|
@@ -46,9 +36,9 @@ export type DefinePoolReturnType<
|
|
|
46
36
|
* const instance_3 = await pool.start(3)
|
|
47
37
|
* ```
|
|
48
38
|
*/
|
|
49
|
-
export function
|
|
50
|
-
parameters:
|
|
51
|
-
):
|
|
39
|
+
export function define<key extends number | string = number>(
|
|
40
|
+
parameters: define.Parameters<key>,
|
|
41
|
+
): define.ReturnType<key> {
|
|
52
42
|
const { limit } = parameters
|
|
53
43
|
|
|
54
44
|
type Instance_ = Omit<Instance, 'create'>
|
|
@@ -198,3 +188,15 @@ export function definePool<key extends number | string = number>(
|
|
|
198
188
|
values: instances.values.bind(instances),
|
|
199
189
|
}
|
|
200
190
|
}
|
|
191
|
+
|
|
192
|
+
export declare namespace define {
|
|
193
|
+
export type Parameters<key extends number | string = number | string> = {
|
|
194
|
+
/** Instance for the pool. */
|
|
195
|
+
instance: Instance | ((key: key) => Instance)
|
|
196
|
+
/** The maximum number of instances that can be started. */
|
|
197
|
+
limit?: number | undefined
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export type ReturnType<key extends number | string = number | string> =
|
|
201
|
+
Pool<key>
|
|
202
|
+
}
|
|
@@ -1,44 +1,30 @@
|
|
|
1
1
|
import getPort from 'get-port'
|
|
2
|
+
import { Instance, Server } from 'prool'
|
|
2
3
|
import { beforeAll, describe, expect, test } from 'vitest'
|
|
3
4
|
import { type MessageEvent, WebSocket } from 'ws'
|
|
4
|
-
import {
|
|
5
|
-
altoOptions,
|
|
6
|
-
rundlerOptions,
|
|
7
|
-
siliusOptions,
|
|
8
|
-
stackupOptions,
|
|
9
|
-
} from '../test/utils.js'
|
|
10
|
-
import { rundler, silius } from './exports/instances.js'
|
|
11
|
-
import { alto } from './instances/alto.js'
|
|
12
|
-
import { anvil } from './instances/anvil.js'
|
|
13
|
-
import { stackup } from './instances/stackup.js'
|
|
14
|
-
import { createServer } from './server.js'
|
|
5
|
+
import { altoOptions } from '../test/utils.js'
|
|
15
6
|
|
|
16
7
|
const port = await getPort()
|
|
17
8
|
|
|
18
9
|
beforeAll(async () => {
|
|
19
|
-
await
|
|
20
|
-
instance: anvil({
|
|
10
|
+
await Server.create({
|
|
11
|
+
instance: Instance.anvil({
|
|
21
12
|
chainId: 1,
|
|
22
|
-
forkUrl: process.env
|
|
13
|
+
forkUrl: process.env['VITE_FORK_URL'] ?? 'https://eth.merkle.io',
|
|
23
14
|
}),
|
|
24
15
|
port,
|
|
25
16
|
}).start()
|
|
26
17
|
})
|
|
27
18
|
|
|
28
19
|
describe.each([
|
|
29
|
-
{ instance: anvil() },
|
|
20
|
+
{ instance: Instance.anvil({ port: await getPort() }) },
|
|
21
|
+
{ instance: Instance.tempo({ port: await getPort() }) },
|
|
30
22
|
{
|
|
31
|
-
instance: alto(altoOptions({ port, pool: true })),
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
instance: stackup(stackupOptions({ port, pool: true })),
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
instance: rundler(rundlerOptions({ port, pool: true })),
|
|
23
|
+
instance: Instance.alto(altoOptions({ port, pool: true })),
|
|
38
24
|
},
|
|
39
25
|
])('instance: $instance.name', ({ instance }) => {
|
|
40
26
|
test('default', async () => {
|
|
41
|
-
const server =
|
|
27
|
+
const server = Server.create({
|
|
42
28
|
instance,
|
|
43
29
|
})
|
|
44
30
|
expect(server).toBeDefined()
|
|
@@ -59,7 +45,7 @@ describe.each([
|
|
|
59
45
|
})
|
|
60
46
|
|
|
61
47
|
test('args: port', async () => {
|
|
62
|
-
const server =
|
|
48
|
+
const server = Server.create({
|
|
63
49
|
instance,
|
|
64
50
|
port: 3000,
|
|
65
51
|
})
|
|
@@ -71,7 +57,7 @@ describe.each([
|
|
|
71
57
|
})
|
|
72
58
|
|
|
73
59
|
test('args: host', async () => {
|
|
74
|
-
const server =
|
|
60
|
+
const server = Server.create({
|
|
75
61
|
instance,
|
|
76
62
|
host: 'localhost',
|
|
77
63
|
port: 3000,
|
|
@@ -85,7 +71,7 @@ describe.each([
|
|
|
85
71
|
})
|
|
86
72
|
|
|
87
73
|
test('request: /healthcheck', async () => {
|
|
88
|
-
const server =
|
|
74
|
+
const server = Server.create({
|
|
89
75
|
instance,
|
|
90
76
|
})
|
|
91
77
|
|
|
@@ -98,7 +84,7 @@ describe.each([
|
|
|
98
84
|
})
|
|
99
85
|
|
|
100
86
|
test('request: /start + /stop', async () => {
|
|
101
|
-
const server =
|
|
87
|
+
const server = Server.create({
|
|
102
88
|
instance,
|
|
103
89
|
})
|
|
104
90
|
|
|
@@ -127,7 +113,7 @@ describe.each([
|
|
|
127
113
|
})
|
|
128
114
|
|
|
129
115
|
test('request: /restart', async () => {
|
|
130
|
-
const server =
|
|
116
|
+
const server = Server.create({
|
|
131
117
|
instance,
|
|
132
118
|
})
|
|
133
119
|
|
|
@@ -142,8 +128,8 @@ describe.each([
|
|
|
142
128
|
|
|
143
129
|
describe("instance: 'anvil'", () => {
|
|
144
130
|
test('request: /{id}', async () => {
|
|
145
|
-
const server =
|
|
146
|
-
instance: anvil(),
|
|
131
|
+
const server = Server.create({
|
|
132
|
+
instance: Instance.anvil(),
|
|
147
133
|
})
|
|
148
134
|
|
|
149
135
|
const stop = await server.start()
|
|
@@ -253,8 +239,8 @@ describe("instance: 'anvil'", () => {
|
|
|
253
239
|
})
|
|
254
240
|
|
|
255
241
|
test('request: /restart', async () => {
|
|
256
|
-
const server =
|
|
257
|
-
instance: anvil(),
|
|
242
|
+
const server = Server.create({
|
|
243
|
+
instance: Instance.anvil(),
|
|
258
244
|
})
|
|
259
245
|
|
|
260
246
|
const stop = await server.start()
|
|
@@ -323,8 +309,8 @@ describe("instance: 'anvil'", () => {
|
|
|
323
309
|
})
|
|
324
310
|
|
|
325
311
|
test('request: /messages', async () => {
|
|
326
|
-
const server =
|
|
327
|
-
instance: anvil(),
|
|
312
|
+
const server = Server.create({
|
|
313
|
+
instance: Instance.anvil(),
|
|
328
314
|
})
|
|
329
315
|
|
|
330
316
|
const stop = await server.start()
|
|
@@ -352,8 +338,8 @@ describe("instance: 'anvil'", () => {
|
|
|
352
338
|
})
|
|
353
339
|
|
|
354
340
|
test('ws', async () => {
|
|
355
|
-
const server =
|
|
356
|
-
instance: anvil(),
|
|
341
|
+
const server = Server.create({
|
|
342
|
+
instance: Instance.anvil(),
|
|
357
343
|
})
|
|
358
344
|
|
|
359
345
|
const stop = await server.start()
|
|
@@ -380,8 +366,8 @@ describe("instance: 'anvil'", () => {
|
|
|
380
366
|
|
|
381
367
|
describe("instance: 'alto'", () => {
|
|
382
368
|
test('request: /{id}', async () => {
|
|
383
|
-
const server =
|
|
384
|
-
instance: alto(altoOptions({ port, pool: true })),
|
|
369
|
+
const server = Server.create({
|
|
370
|
+
instance: Instance.alto(altoOptions({ port, pool: true })),
|
|
385
371
|
})
|
|
386
372
|
|
|
387
373
|
const stop = await server.start()
|
|
@@ -413,118 +399,9 @@ describe("instance: 'alto'", () => {
|
|
|
413
399
|
})
|
|
414
400
|
})
|
|
415
401
|
|
|
416
|
-
describe("instance: 'stackup'", () => {
|
|
417
|
-
test('request: /{id}', async () => {
|
|
418
|
-
const server = createServer({
|
|
419
|
-
instance: stackup(stackupOptions({ port, pool: true })),
|
|
420
|
-
})
|
|
421
|
-
|
|
422
|
-
const stop = await server.start()
|
|
423
|
-
const { port: port_2 } = server.address()!
|
|
424
|
-
const response = await fetch(`http://localhost:${port_2}/1`, {
|
|
425
|
-
body: JSON.stringify({
|
|
426
|
-
method: 'eth_supportedEntryPoints',
|
|
427
|
-
params: [],
|
|
428
|
-
id: 0,
|
|
429
|
-
jsonrpc: '2.0',
|
|
430
|
-
}),
|
|
431
|
-
headers: {
|
|
432
|
-
'Content-Type': 'application/json',
|
|
433
|
-
},
|
|
434
|
-
method: 'POST',
|
|
435
|
-
})
|
|
436
|
-
expect(response.status).toBe(200)
|
|
437
|
-
expect(await response.json()).toMatchInlineSnapshot(`
|
|
438
|
-
{
|
|
439
|
-
"id": 0,
|
|
440
|
-
"jsonrpc": "2.0",
|
|
441
|
-
"result": [
|
|
442
|
-
"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
|
|
443
|
-
],
|
|
444
|
-
}
|
|
445
|
-
`)
|
|
446
|
-
|
|
447
|
-
await stop()
|
|
448
|
-
})
|
|
449
|
-
})
|
|
450
|
-
|
|
451
|
-
describe("instance: 'rundler'", () => {
|
|
452
|
-
test('request: /{id}', async () => {
|
|
453
|
-
const server = createServer({
|
|
454
|
-
instance: rundler(rundlerOptions({ port, pool: true })),
|
|
455
|
-
})
|
|
456
|
-
|
|
457
|
-
const stop = await server.start()
|
|
458
|
-
const { port: port_2 } = server.address()!
|
|
459
|
-
const response = await fetch(`http://localhost:${port_2}/1`, {
|
|
460
|
-
body: JSON.stringify({
|
|
461
|
-
method: 'eth_supportedEntryPoints',
|
|
462
|
-
params: [],
|
|
463
|
-
id: 0,
|
|
464
|
-
jsonrpc: '2.0',
|
|
465
|
-
}),
|
|
466
|
-
headers: {
|
|
467
|
-
'Content-Type': 'application/json',
|
|
468
|
-
},
|
|
469
|
-
method: 'POST',
|
|
470
|
-
})
|
|
471
|
-
expect(response.status).toBe(200)
|
|
472
|
-
expect(await response.json()).toMatchInlineSnapshot(`
|
|
473
|
-
{
|
|
474
|
-
"id": 0,
|
|
475
|
-
"jsonrpc": "2.0",
|
|
476
|
-
"result": [
|
|
477
|
-
"0x0000000071727De22E5E9d8BAf0edAc6f37da032",
|
|
478
|
-
],
|
|
479
|
-
}
|
|
480
|
-
`)
|
|
481
|
-
|
|
482
|
-
await stop()
|
|
483
|
-
})
|
|
484
|
-
})
|
|
485
|
-
|
|
486
|
-
describe("instance: 'silius'", () => {
|
|
487
|
-
test(
|
|
488
|
-
'request: /{id}',
|
|
489
|
-
async () => {
|
|
490
|
-
const server = createServer({
|
|
491
|
-
instance: silius(siliusOptions({ port, pool: true })),
|
|
492
|
-
})
|
|
493
|
-
|
|
494
|
-
const stop = await server.start()
|
|
495
|
-
const { port: port_2 } = server.address()!
|
|
496
|
-
const response = await fetch(`http://localhost:${port_2}/1`, {
|
|
497
|
-
body: JSON.stringify({
|
|
498
|
-
method: 'eth_supportedEntryPoints',
|
|
499
|
-
params: [],
|
|
500
|
-
id: 0,
|
|
501
|
-
jsonrpc: '2.0',
|
|
502
|
-
}),
|
|
503
|
-
headers: {
|
|
504
|
-
'Content-Type': 'application/json',
|
|
505
|
-
},
|
|
506
|
-
method: 'POST',
|
|
507
|
-
})
|
|
508
|
-
expect(response.status).toBe(200)
|
|
509
|
-
expect(await response.json()).toMatchInlineSnapshot(`
|
|
510
|
-
{
|
|
511
|
-
"id": 0,
|
|
512
|
-
"jsonrpc": "2.0",
|
|
513
|
-
"result": [
|
|
514
|
-
"0x0000000071727De22E5E9d8BAf0edAc6f37da032",
|
|
515
|
-
],
|
|
516
|
-
}
|
|
517
|
-
`)
|
|
518
|
-
|
|
519
|
-
await stop()
|
|
520
|
-
},
|
|
521
|
-
{ timeout: 10_000 },
|
|
522
|
-
)
|
|
523
|
-
})
|
|
524
|
-
|
|
525
402
|
test('404', async () => {
|
|
526
|
-
const server =
|
|
527
|
-
instance: anvil(),
|
|
403
|
+
const server = Server.create({
|
|
404
|
+
instance: Instance.anvil(),
|
|
528
405
|
})
|
|
529
406
|
|
|
530
407
|
const stop = await server.start()
|