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

Generalized Runtime Docs / (First round) Bun Support #3219

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
83 changes: 83 additions & 0 deletions .github/workflows/bun-support.yml
@@ -0,0 +1,83 @@
name: Bun Support
#on:
# schedule:
# - cron: 0 0 * * *
# workflow_dispatch:

on:
push:
branches: [master, develop]
tags: ['*']
pull_request:
types: [opened, reopened, synchronize]
workflow_dispatch:

jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: oven-sh/setup-bun@v1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- uses: oven-sh/setup-bun@v1
- uses: oven-sh/setup-bun@v1
with:
bun-version: 1.0.24

Might want to pin the version so there is no ambiguity if a pr caused a regression or bun version changed it.

Alternatively consider just echoing the bun version in the next step of this test so if you are debugging a workflow you know exactly which version of bun it used


- run: bunx ci --omit=peer

- name: Test Block
run: bunx vitest run test
working-directory: packages/block

- name: Test Blockchain
run: bunx vitest run test
working-directory: packages/blockchain

# Client not working yet in Bun (expected), 2024-01-08
# - name: Test Client
# run: bunx vitest run test
# working-directory: packages/client

- name: Test Common
run: bunx vitest run test
Copy link
Collaborator

@roninjin10 roninjin10 Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is actually using bun. Because vitest is an executable bun should default to using node here. I think you need to pass in the --bun flag to use bun and you might have issues related more to vitest than bun.

Suggested change
run: bunx vitest run test
run: bun run --bun vitest run test

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs on this are here https://bun.sh/docs/cli/run#bun

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that is the "tip of the year"! 🙏 🙂

I was already wondering why things are so smooth. 😂 That is the missing link I needed!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to note that this is not yet working (using bun 1.0.26). Tested with common (counter test with the original version worked), new version just hangs before any output.

Not dropping here for you to debug, might just be our homework to do with the bun updates adjusting our code base. But just to drop the information here.

working-directory: packages/common

- name: Test Devp2p
run: bunx vitest run test
working-directory: packages/devp2p

- name: Test Ethash
run: bunx vitest run test
working-directory: packages/ethash

- name: Test EVM
run: bunx vitest run test
working-directory: packages/evm

- name: Test RLP
run: bunx vitest run test
working-directory: packages/rlp

- name: Test StateManager
run: bunx vitest run test
working-directory: packages/statemanager

- name: Test Trie
run: bunx vitest run test
working-directory: packages/trie

- name: Test Tx
run: bunx vitest run test
working-directory: packages/tx

- name: Test Util
run: bunx vitest run test
working-directory: packages/util

- name: Test VM
run: bunx vitest run test
working-directory: packages/vm

- name: Test Wallet
run: bunx vitest run test
working-directory: packages/wallet
34 changes: 28 additions & 6 deletions packages/block/README.md
Expand Up @@ -21,6 +21,34 @@ npm install @ethereumjs/block

**Note:** If you want to work with `EIP-4844` related functionality, you will have additional manual installation steps for the **KZG setup**, see related section below.

## Runtime Support

### Node.js

The current version of this library supports Node `18` and `20` (recommended). Node.js is the main supported platform which is also used internally for development and testing.

TypeScript examples in the [examples](./examples/) folder can be run using [tsx](https://github.com/privatenumber/tsx) like the following:

```shell
tsx examples/simple.ts
```

### Bun

This library has been tested to run with [Bun](https://bun.sh/) [v1.0](https://bun.sh/blog/bun-v1.0) or higher. Note that Bun is still in very active development and a production usage is not recommended (by the Bun team itself) in many cases.

Example run using Bun:

```shell
bun run examples/simple.ts
```

### Browser

This library targets to run in modern browsers which support the JavaScript [ES2020](https://www.w3schools.com/js/js_2020.asp) feature set. There is a dedicated ESM build provided and imports can be done using the normal ES6 [module import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) syntax.

For browser usage see the dedicated [example](./examples/browser.html) (with usage instructions).

## Usage

### Introduction
Expand Down Expand Up @@ -231,12 +259,6 @@ const block = Block.fromBlockData(
)
```

## Browser

With the breaking release round in Summer 2023 we have added hybrid ESM/CJS builds for all our libraries (see section below) and have eliminated many of the caveats which had previously prevented a frictionless browser usage.

It is now easily possible to run a browser build of one of the EthereumJS libraries within a modern browser using the provided ESM build. For a setup example see [./examples/browser.html](./examples/browser.html).

## API

### Docs
Expand Down
15 changes: 15 additions & 0 deletions packages/block/examples/simple.ts
@@ -0,0 +1,15 @@
import { Block } from '@ethereumjs/block'
import { Chain, Common, Hardfork } from '@ethereumjs/common'
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London })

const block = Block.fromBlockData(
{
header: {
baseFeePerGas: BigInt(10),
gasLimit: BigInt(100),
gasUsed: BigInt(60),
},
},
{ common }
)
console.log(block)