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.
Files changed (114) hide show
  1. package/{LICENSE → LICENSE.md} +1 -1
  2. package/README.md +46 -163
  3. package/{_lib/instance.d.ts → dist/Instance.d.ts} +28 -25
  4. package/dist/Instance.d.ts.map +1 -0
  5. package/{_lib/instance.js → dist/Instance.js} +9 -4
  6. package/dist/Instance.js.map +1 -0
  7. package/{_lib/pool.d.ts → dist/Pool.d.ts} +15 -13
  8. package/dist/Pool.d.ts.map +1 -0
  9. package/{_lib/pool.js → dist/Pool.js} +3 -3
  10. package/dist/Pool.js.map +1 -0
  11. package/{_lib/server.d.ts → dist/Server.d.ts} +7 -10
  12. package/dist/Server.d.ts.map +1 -0
  13. package/{_lib/server.js → dist/Server.js} +8 -9
  14. package/dist/Server.js.map +1 -0
  15. package/dist/index.d.ts +4 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +4 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/instances/alto.d.ts +452 -0
  20. package/dist/instances/alto.d.ts.map +1 -0
  21. package/{_lib → dist}/instances/alto.js +4 -4
  22. package/dist/instances/alto.js.map +1 -0
  23. package/dist/instances/anvil.d.ts +458 -0
  24. package/dist/instances/anvil.d.ts.map +1 -0
  25. package/{_lib → dist}/instances/anvil.js +4 -4
  26. package/dist/instances/anvil.js.map +1 -0
  27. package/dist/instances/tempo.d.ts +189 -0
  28. package/dist/instances/tempo.d.ts.map +1 -0
  29. package/dist/instances/tempo.js +200 -0
  30. package/dist/instances/tempo.js.map +1 -0
  31. package/{_lib → dist/internal}/utils.d.ts +5 -5
  32. package/dist/internal/utils.d.ts.map +1 -0
  33. package/{_lib → dist/internal}/utils.js +37 -7
  34. package/dist/internal/utils.js.map +1 -0
  35. package/{_lib → dist}/processes/execa.d.ts +11 -10
  36. package/dist/processes/execa.d.ts.map +1 -0
  37. package/{_lib → dist}/processes/execa.js +1 -1
  38. package/dist/processes/execa.js.map +1 -0
  39. package/package.json +17 -16
  40. package/{instance.test.ts → src/Instance.test.ts} +12 -12
  41. package/{instance.ts → src/Instance.ts} +51 -42
  42. package/{pool.test.ts → src/Pool.test.ts} +41 -55
  43. package/{pool.ts → src/Pool.ts} +21 -19
  44. package/{server.test.ts → src/Server.test.ts} +26 -149
  45. package/{server.ts → src/Server.ts} +9 -11
  46. package/src/index.ts +3 -0
  47. package/{instances → src/instances}/alto.test.ts +8 -11
  48. package/src/instances/alto.ts +289 -0
  49. package/{instances → src/instances}/anvil.test.ts +5 -6
  50. package/src/instances/anvil.ts +306 -0
  51. package/{instances/silius.test.ts → src/instances/tempo.test.ts} +20 -44
  52. package/src/instances/tempo.ts +322 -0
  53. package/{utils.test.ts → src/internal/utils.test.ts} +20 -6
  54. package/{utils.ts → src/internal/utils.ts} +47 -17
  55. package/{processes → src/processes}/execa.test.ts +6 -11
  56. package/{processes → src/processes}/execa.ts +19 -15
  57. package/src/processes/index.ts +1 -0
  58. package/CHANGELOG.md +0 -154
  59. package/_lib/exports/index.d.ts +0 -5
  60. package/_lib/exports/index.d.ts.map +0 -1
  61. package/_lib/exports/index.js +0 -5
  62. package/_lib/exports/index.js.map +0 -1
  63. package/_lib/exports/instances.d.ts +0 -7
  64. package/_lib/exports/instances.d.ts.map +0 -1
  65. package/_lib/exports/instances.js +0 -7
  66. package/_lib/exports/instances.js.map +0 -1
  67. package/_lib/exports/processes.d.ts +0 -2
  68. package/_lib/exports/processes.d.ts.map +0 -1
  69. package/_lib/exports/processes.js +0 -2
  70. package/_lib/exports/processes.js.map +0 -1
  71. package/_lib/instance.d.ts.map +0 -1
  72. package/_lib/instance.js.map +0 -1
  73. package/_lib/instances/alto.d.ts +0 -449
  74. package/_lib/instances/alto.d.ts.map +0 -1
  75. package/_lib/instances/alto.js.map +0 -1
  76. package/_lib/instances/anvil.d.ts +0 -455
  77. package/_lib/instances/anvil.d.ts.map +0 -1
  78. package/_lib/instances/anvil.js.map +0 -1
  79. package/_lib/instances/rundler.d.ts +0 -604
  80. package/_lib/instances/rundler.d.ts.map +0 -1
  81. package/_lib/instances/rundler.js +0 -86
  82. package/_lib/instances/rundler.js.map +0 -1
  83. package/_lib/instances/silius.d.ts +0 -224
  84. package/_lib/instances/silius.d.ts.map +0 -1
  85. package/_lib/instances/silius.js +0 -117
  86. package/_lib/instances/silius.js.map +0 -1
  87. package/_lib/instances/stackup.d.ts +0 -86
  88. package/_lib/instances/stackup.d.ts.map +0 -1
  89. package/_lib/instances/stackup.js +0 -89
  90. package/_lib/instances/stackup.js.map +0 -1
  91. package/_lib/pool.d.ts.map +0 -1
  92. package/_lib/pool.js.map +0 -1
  93. package/_lib/processes/execa.d.ts.map +0 -1
  94. package/_lib/processes/execa.js.map +0 -1
  95. package/_lib/server.d.ts.map +0 -1
  96. package/_lib/server.js.map +0 -1
  97. package/_lib/utils.d.ts.map +0 -1
  98. package/_lib/utils.js.map +0 -1
  99. package/exports/index.test.ts +0 -16
  100. package/exports/index.ts +0 -29
  101. package/exports/instances.test.ts +0 -15
  102. package/exports/instances.ts +0 -13
  103. package/exports/processes.test.ts +0 -10
  104. package/exports/processes.ts +0 -8
  105. package/instances/alto.ts +0 -280
  106. package/instances/anvil.ts +0 -304
  107. package/instances/package.json +0 -5
  108. package/instances/rundler.test.ts +0 -111
  109. package/instances/rundler.ts +0 -451
  110. package/instances/silius.ts +0 -347
  111. package/instances/stackup.test.ts +0 -106
  112. package/instances/stackup.ts +0 -162
  113. package/processes/package.json +0 -5
  114. package/tsconfig.build.tsbuildinfo +0 -1
@@ -0,0 +1,306 @@
1
+ import * as Instance from '../Instance.js'
2
+ import { toArgs } from '../internal/utils.js'
3
+ import { execa } from '../processes/execa.js'
4
+
5
+ /**
6
+ * Defines an Anvil instance.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const instance = Instance.anvil({ forkRpcUrl: 'https://cloudflare-eth.com', port: 8546 })
11
+ * await instance.start()
12
+ * // ...
13
+ * await instance.stop()
14
+ * ```
15
+ */
16
+ export const anvil = Instance.define((parameters?: anvil.Parameters) => {
17
+ const { binary = 'anvil', ...args } = parameters || {}
18
+
19
+ const name = 'anvil'
20
+ const process = execa({ name })
21
+
22
+ return {
23
+ _internal: {
24
+ args,
25
+ get process() {
26
+ return process._internal.process
27
+ },
28
+ },
29
+ host: args.host ?? 'localhost',
30
+ name,
31
+ port: args.port ?? 8545,
32
+ async start({ port = args.port }, options) {
33
+ return await process.start(
34
+ ($) =>
35
+ $({
36
+ env: {
37
+ FOUNDRY_DISABLE_NIGHTLY_WARNING: 'true',
38
+ },
39
+ })`${binary} ${toArgs({ ...args, port })}`,
40
+ {
41
+ ...options,
42
+ // Resolve when the process is listening via a "Listening on" message.
43
+ resolver({ process, reject, resolve }) {
44
+ process.stdout.on('data', (data) => {
45
+ const message = data.toString()
46
+ if (message.includes('Listening on')) resolve()
47
+ })
48
+ process.stderr.on('data', (data) => {
49
+ const message = data.toString()
50
+ if (message.includes('Warning')) return
51
+ reject(message)
52
+ })
53
+ },
54
+ },
55
+ )
56
+ },
57
+ async stop() {
58
+ await process.stop()
59
+ },
60
+ }
61
+ })
62
+
63
+ export declare namespace anvil {
64
+ export type Parameters = {
65
+ /**
66
+ * Number of dev accounts to generate and configure.
67
+ *
68
+ * @defaultValue 10
69
+ */
70
+ accounts?: number | undefined
71
+ /**
72
+ * Set the Access-Control-Allow-Origin response header (CORS).
73
+ *
74
+ * @defaultValue *
75
+ */
76
+ allowOrigin?: string | undefined
77
+ /**
78
+ * Enable autoImpersonate on startup
79
+ */
80
+ autoImpersonate?: boolean | undefined
81
+ /**
82
+ * The balance of every dev account in Ether.
83
+ *
84
+ * @defaultValue 10000
85
+ */
86
+ balance?: number | bigint | undefined
87
+ /**
88
+ * The base fee in a block.
89
+ */
90
+ blockBaseFeePerGas?: number | bigint | undefined
91
+ /**
92
+ * Block time in seconds for interval mining.
93
+ */
94
+ blockTime?: number | undefined
95
+ /**
96
+ * Path or alias to the Anvil binary.
97
+ */
98
+ binary?: string | undefined
99
+ /**
100
+ * The chain id.
101
+ */
102
+ chainId?: number | undefined
103
+ /**
104
+ * EIP-170: Contract code size limit in bytes. Useful to increase this because of tests.
105
+ *
106
+ * @defaultValue 0x6000 (~25kb)
107
+ */
108
+ codeSizeLimit?: number | undefined
109
+ /**
110
+ * Sets the number of assumed available compute units per second for this fork provider.
111
+ *
112
+ * @defaultValue 350
113
+ * @see https://github.com/alchemyplatform/alchemy-docs/blob/master/documentation/compute-units.md#rate-limits-cups
114
+ */
115
+ computeUnitsPerSecond?: number | undefined
116
+ /**
117
+ * Writes output of `anvil` as json to user-specified file.
118
+ */
119
+ configOut?: string | undefined
120
+ /**
121
+ * Sets the derivation path of the child key to be derived.
122
+ *
123
+ * @defaultValue m/44'/60'/0'/0/
124
+ */
125
+ derivationPath?: string | undefined
126
+ /**
127
+ * Disable the `call.gas_limit <= block.gas_limit` constraint.
128
+ */
129
+ disableBlockGasLimit?: boolean | undefined
130
+ /**
131
+ * Dump the state of chain on exit to the given file. If the value is a directory, the state will be
132
+ * written to `<VALUE>/state.json`.
133
+ */
134
+ dumpState?: string | undefined
135
+ /**
136
+ * Fetch state over a remote endpoint instead of starting from an empty state.
137
+ *
138
+ * If you want to fetch state from a specific block number, add a block number like `http://localhost:8545@1400000`
139
+ * or use the `forkBlockNumber` option.
140
+ */
141
+ forkUrl?: string | undefined
142
+ /**
143
+ * Fetch state from a specific block number over a remote endpoint.
144
+ *
145
+ * Requires `forkUrl` to be set.
146
+ */
147
+ forkBlockNumber?: number | bigint | undefined
148
+ /**
149
+ * Specify chain id to skip fetching it from remote endpoint. This enables offline-start mode.
150
+ *
151
+ * You still must pass both `forkUrl` and `forkBlockNumber`, and already have your required state cached
152
+ * on disk, anything missing locally would be fetched from the remote.
153
+ */
154
+ forkChainId?: number | undefined
155
+ /**
156
+ * Specify headers to send along with any request to the remote JSON-RPC server in forking mode.
157
+ *
158
+ * e.g. "User-Agent: test-agent"
159
+ *
160
+ * Requires `forkUrl` to be set.
161
+ */
162
+ forkHeader?: Record<string, string> | undefined
163
+ /**
164
+ * Initial retry backoff on encountering errors.
165
+ */
166
+ forkRetryBackoff?: number | undefined
167
+ /**
168
+ * The block gas limit.
169
+ */
170
+ gasLimit?: number | bigint | undefined
171
+ /**
172
+ * The gas price.
173
+ */
174
+ gasPrice?: number | bigint | undefined
175
+ /**
176
+ * The EVM hardfork to use.
177
+ */
178
+ hardfork?:
179
+ | 'Frontier'
180
+ | 'Homestead'
181
+ | 'Dao'
182
+ | 'Tangerine'
183
+ | 'SpuriousDragon'
184
+ | 'Byzantium'
185
+ | 'Constantinople'
186
+ | 'Petersburg'
187
+ | 'Istanbul'
188
+ | 'Muirglacier'
189
+ | 'Berlin'
190
+ | 'London'
191
+ | 'ArrowGlacier'
192
+ | 'GrayGlacier'
193
+ | 'Paris'
194
+ | 'Shanghai'
195
+ | 'Cancun'
196
+ | 'Prague'
197
+ | 'Latest'
198
+ | undefined
199
+ /**
200
+ * The host the server will listen on.
201
+ */
202
+ host?: string | undefined
203
+ /**
204
+ * Initialize the genesis block with the given `genesis.json` file.
205
+ */
206
+ init?: string | undefined
207
+ /**
208
+ * Launch an ipc server at the given path or default path = `/tmp/anvil.ipc`.
209
+ */
210
+ ipc?: string | undefined
211
+ /**
212
+ * Initialize the chain from a previously saved state snapshot.
213
+ */
214
+ loadState?: string | undefined
215
+ /**
216
+ * BIP39 mnemonic phrase used for generating accounts.
217
+ */
218
+ mnemonic?: string | undefined
219
+ /**
220
+ * Automatically generates a BIP39 mnemonic phrase, and derives accounts from it.
221
+ */
222
+ mnemonicRandom?: boolean | undefined
223
+ /**
224
+ * Disable CORS.
225
+ */
226
+ noCors?: boolean | undefined
227
+ /**
228
+ * Disable auto and interval mining, and mine on demand instead.
229
+ */
230
+ noMining?: boolean | undefined
231
+ /**
232
+ * Disables rate limiting for this node's provider.
233
+ *
234
+ * @defaultValue false
235
+ * @see https://github.com/alchemyplatform/alchemy-docs/blob/master/documentation/compute-units.md#rate-limits-cups
236
+ */
237
+ noRateLimit?: boolean | undefined
238
+ /**
239
+ * Explicitly disables the use of RPC caching.
240
+ *
241
+ * All storage slots are read entirely from the endpoint.
242
+ */
243
+ noStorageCaching?: boolean | undefined
244
+ /**
245
+ * How transactions are sorted in the mempool.
246
+ *
247
+ * @defaultValue fees
248
+ */
249
+ order?: string | undefined
250
+ /**
251
+ * Run an Optimism chain.
252
+ */
253
+ optimism?: boolean | undefined
254
+ /**
255
+ * Port number to listen on.
256
+ *
257
+ * @defaultValue 8545
258
+ */
259
+ port?: number | undefined
260
+ /**
261
+ * Don't keep full chain history. If a number argument is specified, at most this number of states is kept in memory.
262
+ */
263
+ pruneHistory?: number | undefined | boolean
264
+ /**
265
+ * Number of retry requests for spurious networks (timed out requests).
266
+ *
267
+ * @defaultValue 5
268
+ */
269
+ retries?: number | undefined
270
+ /**
271
+ * Don't print anything on startup and don't print logs.
272
+ */
273
+ silent?: boolean | undefined
274
+ /**
275
+ * Slots in an epoch.
276
+ */
277
+ slotsInAnEpoch?: number | undefined
278
+ /**
279
+ * Enable steps tracing used for debug calls returning geth-style traces.
280
+ */
281
+ stepsTracing?: boolean | undefined
282
+ /**
283
+ * Interval in seconds at which the status is to be dumped to disk.
284
+ */
285
+ stateInterval?: number | undefined
286
+ /**
287
+ * This is an alias for both `loadState` and `dumpState`. It initializes the chain with the state stored at the
288
+ * file, if it exists, and dumps the chain's state on exit
289
+ */
290
+ state?: string | undefined
291
+ /**
292
+ * Timeout in ms for requests sent to remote JSON-RPC server in forking mode.
293
+ *
294
+ * @defaultValue 45000
295
+ */
296
+ timeout?: number | undefined
297
+ /**
298
+ * The timestamp of the genesis block.
299
+ */
300
+ timestamp?: number | bigint | undefined
301
+ /**
302
+ * Number of blocks with transactions to keep in memory.
303
+ */
304
+ transactionBlockKeeper?: number | undefined
305
+ }
306
+ }
@@ -1,26 +1,17 @@
1
1
  import getPort from 'get-port'
2
- import { afterEach, beforeAll, expect, test } from 'vitest'
2
+ import { Instance } from 'prool'
3
+ import { afterEach, expect, test } from 'vitest'
3
4
 
4
- import { siliusOptions } from '../../test/utils.js'
5
- import type { Instance } from '../instance.js'
6
- import { anvil } from './anvil.js'
7
- import { silius } from './silius.js'
8
-
9
- const instances: Instance[] = []
5
+ const instances: Instance.Instance[] = []
10
6
 
11
7
  const port = await getPort()
12
8
 
13
- const defineInstance = (parameters?: Partial<{}>) => {
14
- const instance = silius({
15
- ...siliusOptions({ port, pool: false }),
16
- ...parameters,
17
- })
9
+ const defineInstance = (parameters: Instance.tempo.Parameters = {}) => {
10
+ const instance = Instance.tempo({ port, ...parameters })
18
11
  instances.push(instance)
19
12
  return instance
20
13
  }
21
14
 
22
- beforeAll(() => anvil({ port }).start())
23
-
24
15
  afterEach(async () => {
25
16
  for (const instance of instances) await instance.stop().catch(() => {})
26
17
  })
@@ -52,15 +43,11 @@ test('default', async () => {
52
43
  })
53
44
 
54
45
  test('behavior: instance errored (duplicate ports)', async () => {
55
- const instance_1 = defineInstance({
56
- port: 1337,
57
- })
58
- const instance_2 = defineInstance({
59
- port: 1337,
60
- })
46
+ const instance_1 = defineInstance({ port: 8546 })
47
+ const instance_2 = defineInstance({ port: 8546 })
61
48
 
62
49
  await instance_1.start()
63
- await expect(() => instance_2.start()).rejects.toThrowError()
50
+ await expect(() => instance_2.start()).rejects.toThrowError('Failed to start')
64
51
  })
65
52
 
66
53
  test('behavior: start and stop multiple times', async () => {
@@ -76,33 +63,22 @@ test('behavior: start and stop multiple times', async () => {
76
63
  await instance.stop()
77
64
  })
78
65
 
79
- test('behavior: can subscribe to stderr', async () => {
66
+ test('behavior: can subscribe to stdout', async () => {
80
67
  const messages: string[] = []
81
-
82
- const instance_1 = defineInstance({ port: 1338 })
83
- const instance_2 = defineInstance({ port: 1338 })
84
-
85
- await instance_1.start()
86
- instance_2.on('stderr', (message) => messages.push(message))
87
- await expect(instance_2.start()).rejects.toThrowError()
88
- })
89
-
90
- test('behavior: exit', async () => {
91
68
  const instance = defineInstance()
92
- const { promise, resolve } = Promise.withResolvers<void>()
93
-
94
- let exitCode: number | null | undefined = undefined
95
- instance.on('exit', (code) => {
96
- exitCode = code
97
- resolve()
98
- })
69
+ instance.on('stdout', (message) => messages.push(message))
99
70
 
100
71
  await instance.start()
101
- expect(instance.status).toEqual('started')
72
+ expect(messages.length).toBeGreaterThanOrEqual(1)
73
+ })
102
74
 
103
- instance._internal.process.kill()
75
+ test('behavior: can subscribe to stderr', async () => {
76
+ const messages: string[] = []
104
77
 
105
- await promise
106
- expect(instance.status).toEqual('stopped')
107
- expect(typeof exitCode !== 'undefined').toBeTruthy()
78
+ const instance_1 = defineInstance({ port: 8546 })
79
+ const instance_2 = defineInstance({ port: 8546 })
80
+
81
+ await instance_1.start()
82
+ instance_2.on('stderr', (message) => messages.push(message))
83
+ await expect(instance_2.start()).rejects.toThrow('Failed to start')
108
84
  })