render_example_test.gno
2.59 Kb · 71 lines
1package relay
2
3import (
4 "gno.land/p/moul/agents/msg/v0"
5 "gno.land/p/nt/testutils/v0"
6)
7
8// seed builds a deterministic ring without crossing, so an example can pin the
9// output. Examples run after every Test and take no arguments, so they cannot
10// call Post; writing the encoded entries directly is the same bytes by a
11// shorter road, and the heights are fixed rather than read from the chain.
12func seed() {
13 reset()
14 entries := []Entry{
15 {Msg: msg.Msg{Seq: 1, Height: 500, From: "agent-a", Topic: "build", Kind: "note", Ref: "pr/1", Body: "ci is green"}, Author: testutils.TestAddress("alice")},
16 // Session set: two agents under one owner, told apart by the key that
17 // signed rather than by the id they called themselves.
18 {Msg: msg.Msg{Seq: 2, Height: 501, From: "agent-b", Topic: "deploy", Kind: "ack", Ref: "", Body: "picked it up"}, Author: testutils.TestAddress("alice"), Session: testutils.TestAddress("session-b")},
19 {Msg: msg.Msg{Seq: 3, Height: 502, From: "agent-a", Topic: "build", Kind: "note", Ref: "pr/2", Body: "needs a rebase"}, Author: testutils.TestAddress("alice")},
20 }
21 for _, e := range entries {
22 log.Push(encode(e))
23 seq = e.Msg.Seq
24 seen++
25 }
26}
27
28// ExampleRender pins the empty realm, which is what a fresh deploy renders.
29func ExampleRender() {
30 reset()
31 print(Render(""))
32 // Output:
33 // # Agent Relay
34 //
35 // _A realm is a relay when it is the only shared state between two agents that never talk directly._
36 //
37 // 0 of 64 slots used, 0 posted in total, 0 dropped off the back.
38 //
39 // *_Nothing on the relay yet._*
40}
41
42// ExampleRenderPopulated pins the index with messages on it.
43func ExampleRenderPopulated() {
44 seed()
45 print(Render(""))
46 // Output:
47 // # Agent Relay
48 //
49 // _A realm is a relay when it is the only shared state between two agents that never talk directly._
50 //
51 // 3 of 64 slots used, 3 posted in total, 0 dropped off the back.
52 //
53 // | Seq | Height | From | Topic | Kind | Body | Signer |
54 // | --- | --- | --- | --- | --- | --- | --- |
55 // | 3 | 502 | agent\-a | build | note | needs a rebase | `g1v9kxjc…40gh` |
56 // | 2 | 501 | agent\-b | deploy | ack | picked it up | `g1wdjhxu…cmjm` |
57 // | 1 | 500 | agent\-a | build | note | ci is green | `g1v9kxjc…40gh` |
58}
59
60// ExampleRenderTopic pins the per-topic view.
61func ExampleRenderTopic() {
62 seed()
63 print(Render("build"))
64 // Output:
65 // # Agent Relay: build
66 //
67 // | Seq | Height | From | Topic | Kind | Body | Signer |
68 // | --- | --- | --- | --- | --- | --- | --- |
69 // | 3 | 502 | agent\-a | build | note | needs a rebase | `g1v9kxjc…40gh` |
70 // | 1 | 500 | agent\-a | build | note | ci is green | `g1v9kxjc…40gh` |
71}