Skip to content

Legacynet AOS on HyperBEAM

Currently, testing legacynet aos processes works much better without HyperBEAM.

You can check out Legacynet AOS guide to test with legacy AO units.

Legacynet AOS on HyperBEAM uses genesis-wasm@1.0 device and an external CU for computation. The standalone WAO server works as a local CU.

spawnLegacy, schedule, and computeLegacy manages the process for you.

import assert from "assert"
import { describe, it, before, after, beforeEach } from "node:test"
import { HyperBEAM } from "wao"
 
const cwd = "../HyperBEAM" // HyperBEAM directory
 
const lua = `
local count = 0
Handlers.add("Inc", "Inc", function (msg)
  count = count + 1
  msg.reply({ Data = "Count: "..tostring(count) })
end)
 
Handlers.add("Get", "Get", function (msg)
  msg.reply({ Data = "Count: "..tostring(count) })
end)`
 
describe("Hyperbeam Legacynet", function () {
  let hbeam, hb
  before(async () => {
    hbeam = await new HyperBEAM({
      cwd,
      reset: true,
      as: ["genesis_wasm"],
    }).ready()
  })
 
  beforeEach(async () => (hb = hbeam.hb))
  after(async () => hbeam.kill())
 
  it("should run a legacynet AOS process with a local CU", async () => {
    const { pid } = await hb.spawnLegacy()
    const { slot } = await hb.schedule({
      pid,
      data: lua,
      tags: { Action: "Eval" },
    })
    const res = await hb.computeLegacy({ pid, slot })
    
    let i = 0
    while (i < 10) {
      const { slot } = await hb.schedule({
        pid,
        tags: { Action: "Inc" },
      })
      const res2 = await hb.computeLegacy({ pid, slot })
      assert.equal(res2.Messages[0].Data, `Count: ${++i}`)
    }
    
    const res3 = await ao.hb.dryrun({ pid, action: "Get" })
    assert.equal(res3.Messages[0].Data, `Count: ${i}`)
 
    const res4 = await hb.messages({ pid, from: 0 })
    assert.equal(res4.edges.length, i + 2)
  })
})