ethereumjs-monorepo icon indicating copy to clipboard operation
ethereumjs-monorepo copied to clipboard

VM: State/Blockchain Test Runs with Bun fail

Open holgerd77 opened this issue 1 year ago • 6 comments

Running the VM state/blockchain tests with Bun currently fails (see #3219 for additional context). The error message is pretty generic, so it is likely generally worth looking into this.

"Pure" test run with tsx can be done with:

tsx ./test/tester --stack-size=1500 --state

(from the VM package folder)

Running with Bun can be triggered with:

bun run ./test/tester/index.ts --stack-size=1500 --state

This gives the following breakage after a couple of successful test proceedings:

grafik

So: pretty basic error (ignore the red whiggle underlinings, just some formatting).

As mentioned above, likely worth to give this a look, maybe this gives some additional insights.

holgerd77 avatar Jan 09 '24 09:01 holgerd77

I can take a look at this by tomorrow afternoon the latest? 😃👍

jochem-brouwer avatar Jan 09 '24 12:01 jochem-brouwer

I can take a look at this by tomorrow afternoon the latest? 😃👍

@jochem-brouwer Sounds good, that would be nice! 👍

holgerd77 avatar Jan 10 '24 08:01 holgerd77

First note here: the error messages point to the esm build output, not to the original ts source code (which is not so nice :sweat_smile: - but might be for performance reasons)

jochem-brouwer avatar Jan 10 '24 17:01 jochem-brouwer

Test results by using bun run ./test/tester/index.ts --stack-size=1500 --state --test=create2InitCodeSizeLimit

In evm.ts add this:

    await this.journal.putAccount(message.to, toAccount)
    ;(<any>Address).abcde = 123
    console.log((<any>Address).abcde)
    await this.stateManager.clearContractStorage(message.to)

    const newContractEvent = {
      address: message.to,
      code: message.code,
    }

This adds this abcde to the Address constructor

In statemanager.ts add:

  /**
   * Clears all storage entries for the account corresponding to `address`.
   * @param address - Address to clear the storage of
   */
  async clearContractStorage(address: Address): Promise<void> {
    console.log((<any>Address).abcde)

This will print:

123
undefined

So it looks like somehow Bun is importing the same constructors from two different files :thinking:

Not sure how to proceed here though.

Note: if this is tested using tsx it will output 123 both in state manager and in evm.

jochem-brouwer avatar Jan 10 '24 18:01 jochem-brouwer

It seems that VM and EVM run on CJS (so also their imports), but StateManager (as imported in the general state tests runner), runs on ESM :thinking:

jochem-brouwer avatar Jan 10 '24 18:01 jochem-brouwer

Short update: tested this with bun v1.0.26 (release from early February 2024) and the bug still persists.

holgerd77 avatar Feb 15 '24 10:02 holgerd77