Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VM/genesis: Fix small genesis API inconsistency #2886

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/genesis/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { GenesisState } from '@ethereumjs/util'
* @param: chainId of the network
* @returns genesisState of the chain
*/
export function getGenesis(chainId: number): GenesisState | null {
export function getGenesis(chainId: number): GenesisState | undefined {
// Use require statements here in favor of import statements
// to load json files on demand
// (high memory usage by large mainnet.json genesis state file)
Expand All @@ -24,6 +24,6 @@ export function getGenesis(chainId: number): GenesisState | null {
return sepoliaGenesis

default:
return null
return undefined
}
}
4 changes: 2 additions & 2 deletions packages/genesis/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ describe('genesis test', () => {
for (const chainId of chainIds) {
const name = chainToName[chainId as unknown as Chain]

assert.ok(getGenesis(Number(chainId)) !== null, `${name} genesis found`)
assert.ok(getGenesis(Number(chainId)) !== undefined, `${name} genesis found`)
}

assert.ok(getGenesis(2) === null, `genesis for chainId 2 not found`)
assert.ok(getGenesis(2) === undefined, `genesis for chainId 2 not found`)
})
})
19 changes: 19 additions & 0 deletions packages/vm/test/api/genesis.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Blockchain } from '@ethereumjs/blockchain'
import { Chain } from '@ethereumjs/common'
import { getGenesis } from '@ethereumjs/genesis'
import { assert, describe, it } from 'vitest'

import { VM } from '../../src/index.js'

describe('genesis', () => {
it('should initialize with predefined genesis states', async () => {
const f = async () => {
const genesisState = getGenesis(Chain.Mainnet)

const blockchain = await Blockchain.create({ genesisState })
await VM.create({ blockchain, genesisState })
}

assert.doesNotThrow(f, 'should allow for initialization with genesis from genesis package')
})
})
Loading