← Recipe: persist and restore state

4. Replace tests/smoke.luau

luastra/state · luastra/host · app.resolve · about 15 minutes
round-trip and rejection test

The test proves valid state restoration and confirms malformed data leaves the current counter unchanged.

When to use it

Replace the generated smoke test so test covers both the successful and rejected restore paths.

Focused example

--!strict

local app = require("app/main")
local State = require("luastra/state")

app.handle("counter.add", "counter/add", "")
assert(app.snapshot().count == 1, "counter action failed")

local snapshot = State.encode(1, { count = "7" })
app.handle("counter.restore", "app", snapshot)
assert(app.snapshot().count == 7, "valid count was not restored")

app.handle("counter.restore", "app", "v=1&count=invalid")
assert(app.snapshot().message == "Stored state is invalid", "invalid count was accepted")
assert(app.snapshot().count == 7, "invalid restore changed current state")

return true

Complete inventory

View all pages in Recipe: persist and restore state
← Previous: 3. Replace src/main.luauNext: 5. Check and run →