Mainnet AOS (WASM)
To test mainnet AOS processes with WAO, you currently need the WAO HyperBEAM fork.
git clone -b wao-beta3 https://github.com/weavedb/HyperBEAM.git
cd HyperBEAM && rebar3 compileMainnet AOS requires stack@1.0 device with wasi@1.0, json-iface@1.0, wasm-64@1.0, and multipass@1.0. The required http header tags look like the following.
const scheduler = (await hb.g("/~meta@1.0/info")).address
const headers = {
device: "process@1.0",
path: "/schedule",
scheduler,
"Data-Protocol": "ao",
Variant: "ao.TN.1",
"scheduler-location": scheduler,
Authority: scheduler,
"random-seed": seed(16),
Type: "Process",
image: WASM_IMAGE_ID,
"scheduler-device": "scheduler@1.0",
"execution-device": "stack@1.0",
"device-stack": [
"wasi@1.0",
"json-iface@1.0",
"wasm-64@1.0",
"multipass@1.0",
],
"output-prefix": "wasm",
"patch-from": "/results/outbox",
"stack-keys": ["init", "compute", "snapshot", "normalize"],
passes: 2,
}spawnAOS() handles the tag construction and automatically loads the necessary wasm image using wao@1.0 device for you.
messageAOS() schedules a message and return the computed result.
Dryruns are disabled on mainnet AOS processes.
import assert from "assert"
import { describe, it, before, after, beforeEach } from "node:test"
import { HyperBEAM } from "wao/test"
const cwd = "../HyperBEAM" // HyperBEAM directory
const src_data = `
local count = 0
Handlers.add("Add", "Add", function (msg)
count = count + tonumber(msg.Plus)
end)
Handlers.add("Get", "Get", function (msg)
msg.reply({ Data = tostring(count) })
end)`
describe("Hyperbeam Mainnet", function () {
let hbeam, hb
before(async () => {
hbeam = await new HyperBEAM({ cwd, reset: true }).ready()
})
beforeEach(async () => (hb = hbeam.hb))
after(async () => hbeam.kill())
it("should handle counter with Add and Get handlers", async () => {
const { pid } = await hb.spawnAOS()
await hb.messageAOS({ pid, action: "Eval", tags: {}, data: src_data })
await hb.messageAOS({ pid, action: "Add", tags: { Plus: "3" } })
assert.equal(
(await hb.messageAOS({ pid, action: "Get" })).outbox["1"].data,
"3"
)
})
})Using WAO SDK
The AO class with mode: "aos" wraps all the low-level HB methods:
import assert from "assert"
import { describe, it, before, after } from "node:test"
import { HyperBEAM } from "wao/test"
import { AO } from "wao"
const src_data = `
local count = 0
Handlers.add("Add", "Add", function (msg)
count = count + tonumber(msg.Plus)
end)
Handlers.add("Get", "Get", function (msg)
msg.reply({ Data = tostring(count) })
end)`
describe("Mainnet AOS with WAO SDK", function () {
let hbeam, ao
before(async () => {
hbeam = await new HyperBEAM({ reset: true }).ready()
ao = await new AO({ hb: hbeam.url, mode: "aos" }).init(hbeam.jwk)
})
after(async () => hbeam.kill())
it("should deploy and interact", async () => {
const { p } = await ao.deploy({ src_data })
await p.m("Add", { Plus: "3" })
assert.equal(await p.m("Get", false), "3")
})
})Remote Deployment
Deploy to remote push nodes for testing. The SDK auto-detects remote URLs and switches to ANS-104 encoding:
import { AO } from "wao"
import fs from "fs"
const jwk = JSON.parse(fs.readFileSync(".wallet.json", "utf8"))
const ao = await new AO({
hb: "https://push-1.forward.computer",
mode: "aos"
}).init(jwk)
const { p, pid } = await ao.deploy({ src_data })
console.log("Process ID:", pid)
await p.m("Add", { Plus: "3" })
const { out } = await p.msg("Get")
console.log(out) // "3"