-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add rundler instance definition (#9)
* feat: add rundler instance definition * chore: tweaks * fix: types --------- Co-authored-by: jxom <[email protected]>
- Loading branch information
Showing
14 changed files
with
808 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,12 @@ jobs: | |
- name: Set up Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
|
||
- name: Set up Rundler | ||
uses: jaxxstorm/[email protected] | ||
with: | ||
repo: alchemyplatform/rundler | ||
platform: linux | ||
|
||
- name: Set up Docker | ||
uses: docker-practice/actions-setup-docker@master | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,6 @@ coverage | |
node_modules | ||
tsconfig.*.tsbuildinfo | ||
tsconfig.tsbuildinfo | ||
|
||
.tool-versions | ||
bin |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ test('exports', () => { | |
[ | ||
"alto", | ||
"anvil", | ||
"rundler", | ||
"stackup", | ||
] | ||
`) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { type AltoParameters, alto } from '../instances/alto.js' | ||
export { type AnvilParameters, anvil } from '../instances/anvil.js' | ||
export { type StackupParameters, stackup } from '../instances/stackup.js' | ||
export { alto, type AltoParameters } from '../instances/alto.js' | ||
export { anvil, type AnvilParameters } from '../instances/anvil.js' | ||
export { rundler, type RundlerParameters } from '../instances/rundler.js' | ||
export { stackup, type StackupParameters } from '../instances/stackup.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { afterEach, expect, test } from 'vitest' | ||
import type { Instance } from '../instance.js' | ||
import { type RundlerParameters, rundler } from './rundler.js' | ||
|
||
const instances: Instance[] = [] | ||
|
||
const defineInstance = (parameters: RundlerParameters = {}) => { | ||
const instance = rundler(parameters) | ||
instances.push(instance) | ||
return instance | ||
} | ||
|
||
afterEach(async () => { | ||
for (const instance of instances) await instance.stop() | ||
}) | ||
|
||
test('default', async () => { | ||
const messages: string[] = [] | ||
const stdouts: string[] = [] | ||
|
||
const instance = defineInstance() | ||
|
||
instance.on('message', (m) => messages.push(m)) | ||
instance.on('stdout', (m) => stdouts.push(m)) | ||
|
||
expect(instance.messages.get()).toMatchInlineSnapshot('[]') | ||
|
||
await instance.start() | ||
expect(instance.status).toEqual('started') | ||
|
||
expect(messages.join('')).toBeDefined() | ||
expect(stdouts.join('')).toBeDefined() | ||
expect(instance.messages.get().join('')).toBeDefined() | ||
|
||
await instance.stop() | ||
expect(instance.status).toEqual('stopped') | ||
|
||
expect(messages.join('')).toBeDefined() | ||
expect(stdouts.join('')).toBeDefined() | ||
expect(instance.messages.get()).toMatchInlineSnapshot('[]') | ||
}) | ||
|
||
test('behavior: instance errored (duplicate ports)', async () => { | ||
const instance_1 = defineInstance({ | ||
rpc: { | ||
port: 1337, | ||
}, | ||
}) | ||
const instance_2 = defineInstance({ | ||
rpc: { | ||
port: 1337, | ||
}, | ||
}) | ||
|
||
await instance_1.start() | ||
await expect(() => | ||
instance_2.start(), | ||
).rejects.toThrowErrorMatchingInlineSnapshot( | ||
`[Error: Failed to start process "rundler": exited]`, | ||
) | ||
}) | ||
|
||
test('behavior: start and stop multiple times', async () => { | ||
const instance = defineInstance() | ||
|
||
await instance.start() | ||
await instance.stop() | ||
await instance.start() | ||
await instance.stop() | ||
await instance.start() | ||
await instance.stop() | ||
await instance.start() | ||
await instance.stop() | ||
}) | ||
|
||
test('behavior: can subscribe to stderr', async () => { | ||
const messages: string[] = [] | ||
|
||
const instance_1 = defineInstance({ | ||
rpc: { | ||
port: 1338, | ||
}, | ||
}) | ||
const instance_2 = defineInstance({ | ||
rpc: { | ||
port: 1338, | ||
}, | ||
}) | ||
|
||
await instance_1.start() | ||
instance_2.on('stderr', (message) => messages.push(message)) | ||
await expect(() => | ||
instance_2.start(), | ||
).rejects.toThrowErrorMatchingInlineSnapshot( | ||
`[Error: Failed to start process "rundler": exited]`, | ||
) | ||
}) | ||
|
||
test('behavior: exit', async () => { | ||
const instance = defineInstance() | ||
|
||
let exitCode: number | null | undefined = undefined | ||
instance.on('exit', (code) => { | ||
exitCode = code | ||
}) | ||
|
||
await instance.start() | ||
expect(instance.status).toEqual('started') | ||
|
||
instance._internal.process.kill() | ||
|
||
await new Promise<void>((res) => setTimeout(res, 100)) | ||
expect(instance.status).toEqual('stopped') | ||
expect(typeof exitCode !== 'undefined').toBeTruthy() | ||
}) |
Oops, something went wrong.