Skip to content

HyperBEAM

HperBEAM class can start and manage a HyperBEAM node from within JS code for testing.

You should first install HyperBEAM on your local machine by following the official docs.

Basic Usage

import { HyperBEAM } from "wao/test"
import { describe, it, before, after } from "node:test"
 
describe("HyperBEAM", function () {
  let hbeam
  before(async () => {
	hbeam = await new HyperBEAM({ 
      port: 10001,
	  wallet: ".wallet.json",
      cwd: "./HyperBEAM", 
      reset: true,
	  bundler: 4001,
	  gateway: 4000,
	  logs: true,
	  shell: true,
	  as: [ "genesis_wasm" ],
	  devices: [ "flat", "structured", "httpsig", "json", "meta" ],
	  faff: [ addr, addr2, addr3 ],
	  simple_pay: true,
	  simple_pay_price: 3,
	  p4_lua: { processor: pid, client: cid },
	  operator: addr
    }).ready()
  })
  after(() => hbeam.kill())
  it("should run", async () => {
    // run some tests
  })
})
 
hbeam.kill()

Parameters

NameDefaultDescription
port10001Port number for the HyperBEAM node
cwd../HyperBEAMnode directory relative to current working directory
wallet.wallet.jsonnode operator jwk location relative to cwd
resetfalseclear storage to start fresh
bundler-bundler service port
gateway-gateway service port
logstrueset false to disable HyperBEAM logs
shelltruefalse to not auto-start rebar3 shell
as[]rocksdb, genesis_wasm, http3
devices-array of preloaded devices, undefined to load everything
faff-array of addresses (likely for funding/faucet)
simple_payfalseenable simple-pay@1.0
simple_pay_price-base price for transactions
p4_lua-{ processor: pid, client: cid }
operator-payment operator address

Environment Variables

If your installation requires environment variables to run rebar3, define then in .env.hyperbeam.

cwd can also be set in .env.hyperbeam to apply globally across all test files.

.env.hyperbeam
CWD=./HyperBEAM
CC=gcc-12
CXX=g++-12
CMAKE_POLICY_VERSION_MINIMUM=3.5

Preloaded Devices

KeyNameModule
metameta@1.0dev_meta
jsonjson@1.0dev_codec_json
flatflat@1.0dev_codec_flat
httpsighttpsig@1.0dev_codec_httpsig
structuredstructured@1.0dev_codec_structured
processprocess@1.0dev_process
messagemessage@1.0dev_message
schedulerscheduler@1.0dev_scheduler
delegated-computedelegated-compute@1.0dev_delegated_compute
genesis-wasmgenesis-wasm@1.0dev_genesis_wasm
lualua@5.3adev_lua
wasiwasi@1.0dev_wasi
wasm-64wasm-64@1.0dev_wasm
json-ifacejson-iface@1.0dev_json_iface
test-devicetest-device@1.0dev_test
patchpatch@1.0dev_patch
pushpush@1.0dev_push
stackstack@1.0dev_stack
multipassmultipass@1.0dev_multipass
fafffaff@1.0dev_faff
p4p4@1.0dev_p4
node-processnode-process@1.0dev_node_process
simple-paysimple-pay@1.0dev_simple_pay
croncron@1.0dev_cron
relayrelay@1.0dev_relay
routerrouter@1.0dev_router
cachecache@1.0dev_cache
local-namelocal-name@1.0dev_local_name
lookuplookup@1.0dev_lookup
namename@1.0dev_name
computecompute@1.0dev_cu
dedupdedup@1.0dev_dedup
manifestmanifest@1.0dev_manifest
monitormonitor@1.0dev_monitor
snpsnp@1.0dev_snp
volumevolume@1.0dev_volume
podapoda@1.0dev_poda
greenzonegreenzone@1.0dev_green_zone
hyperbuddyhyperbuddy@1.0dev_hyperbuddy
ans104ans104@1.0dev_codec_ans104
cachevizcacheviz@1.0dev_cacheviz
waowao@1.0dev_wao

If the device is not listed, you need to define it yourself.

  • device = { name, module }
const hbeam = await new HyperBEAM({
  devices: [
    "flat",
	"structured",
	"httpsig",
	"json",
	"meta",
    { name: "mydev@1.0", module: "dev_mydev" }
  ]
}).ready()

Node Operator Address

You can use HyperBEAM.OPERATOR as a placeholder for the node operator address before instantiation.

const hbeam = await new HyperBEAM({
  operator: HyperBEAM.OPERATOR,
  faff: [ HyperBEAM.OPERATOR, addr2, addr3 ]
}).ready()

HyperBEAM.OPERATOR will be replaced with the actual node operator address on instantiation.

Eunit Testing

You can run Erlang eunit tests from JS.

import assert from "assert"
import { after, describe, it, before, beforeEach } from "node:test"
import HyperBEAM from "../../src/hyperbeam.js"
 
describe("Hyperbeam Eunit", function () {
  let hbeam
  before(async () => {
    hbeam = new HyperBEAM({ reset: true, shell: false }))
  })
  beforeEach(async () => (hb = hbeam.hb))
  
  it("should run a single module test", async () => {
	await hbeam.eunit("dev_message")
  })
  
  it("should run multiple module tests", async () => {
	await hbeam.eunit([ "dev_message", "dev_process", "dev_schduler" ])
  })
  
  it("should run a specific test", async () => {
	await hbeam.eunit("dev_message", "verify_test")
  })
 
  it("should run multiple tests", async () => {
	await hbeam.eunit([
	  "dev_message:verify_test", 
	  "dev_process:persistent_process_test"
    )
  })
})

Reading Local Files

You can read local files under the HyperBEAM cwd directory with the file method.

The following is reading lua scripts and caching them to the HyperBEAM node, then starting another node process on port 10002 with the p4 payment service using the cached Lua scripts.

const process = hbeam.file("scripts/p4-payment-process.lua")
const pid = await hb.cacheScript(process)
const client = hbeam.file("scripts/p4-payment-client.lua")
const cid = await hb.cacheScript(client)
const hbeam2 = await new HyperBEAM({
  port: 10002,
  operator: hb.addr,
  p4_lua: { processor: pid, client: cid },
}).ready()