Skip to content

Commit

Permalink
devp2p/vm: ensure examples do not process.exit
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Aug 13, 2024
1 parent 0686310 commit 67b8fcb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/devp2p/examples/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ for (const bootnode of BOOTNODES) {
}

setTimeout(() => {
process.exit()
throw new Error('Test timed out')
}, TIMEOUT)
5 changes: 0 additions & 5 deletions packages/vm/examples/run-blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,3 @@ async function putBlocks(blockchain: Blockchain, common: Common, data: typeof te
}

main()
.then(() => process.exit(0))
.catch((err) => {
console.error(err)
process.exit(1)
})
5 changes: 0 additions & 5 deletions packages/vm/examples/run-solidity-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,3 @@ async function main() {
}

main()
.then(() => process.exit(0))
.catch((err) => {
console.error(err)
process.exit(1)
})
1 change: 1 addition & 0 deletions packages/vm/examples/vmWithGenesisState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const main = async () => {
const account = await vm.stateManager.getAccount(
createAddressFromString('0x000d836201318ec6899a67540690382780743280'),
)
console.log(account)
console.log(
`This balance for account 0x000d836201318ec6899a67540690382780743280 in this chain's genesis state is ${Number(
account?.balance,
Expand Down
21 changes: 10 additions & 11 deletions scripts/examples-runner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readdirSync } from 'fs'
import { extname, join } from 'path'
import { readdir } from 'fs'

const pkg = process.argv[3]
if (!pkg) {
Expand All @@ -9,17 +9,16 @@ if (!pkg) {
const examplesPath = `../packages/${pkg}/examples/`
const path = join(__dirname, examplesPath)

readdir(path, async (err, files) => {
if (err) {
throw new Error('Error loading examples directory: ' + err.message)
}

const getTsFiles = (fileName: string): Promise<NodeModule> | undefined => {
if (extname(fileName) === '.cts' || extname(fileName) === '.ts') {
return import(examplesPath + fileName)
}
const getTsFiles = (fileName: string): Promise<NodeModule> | undefined => {
if (extname(fileName) === '.cts' || extname(fileName) === '.ts') {
return import(examplesPath + fileName)
}
}

const main = async () => {
const files = readdirSync(path)
const importedFiles = files.map(getTsFiles).filter((file) => file)
await Promise.all(importedFiles)
})
}

main()

0 comments on commit 67b8fcb

Please sign in to comment.