Skip to content

Commit

Permalink
VM/genesis: fix small genesis API inconsistency, add test (#2886)
Browse files Browse the repository at this point in the history
  • Loading branch information
holgerd77 committed Jul 13, 2023
1 parent b039efe commit fc80b2e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
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')
})
})

0 comments on commit fc80b2e

Please sign in to comment.