Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

z8_owner_tools_filetest.gno

3.79 Kb · 81 lines
 1// PKGPATH: gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/z8
 2
 3// Owners can describe, retire and upgrade their bots; nobody else can.
 4// Upgrades keep the name, rating and record and must come from a new realm.
 5package z8
 6
 7import (
 8	"testing"
 9
10	"gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena/v2"
11	_ "gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/bots/starter/v2"
12	"gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/testbots/crasher"
13	"gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/testbots/upgrader"
14)
15
16func main(cur realm) {
17	try := func(name string, f func()) { println(name+":", revive(f)) }
18
19	// someone else registers a bot
20	me := cur.Address()
21	testing.SetOriginCaller(address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"))
22	crasher.RegisterHunter(cross(cur), "not-mine")
23
24	// we register ours, then act as their owner, like a wallet would
25	testing.SetOriginCaller(me)
26	crasher.RegisterHunter(cross(cur), "my-hunter")
27	crasher.Register(cross(cur), "my-crasher")
28
29	try("retire someone else's bot", func() { arena.Retire(cross(cur), "not-mine") })
30
31	arena.SetDescription(cross(cur), "my-hunter", "Goes for coins. <b>Attacks</b> [when](x) close!\nNo second line.")
32	info, _ := arena.GetBot("my-hunter")
33	println("description:", info.Description)
34
35	arena.Retire(cross(cur), "my-hunter")
36	try("fight a retired bot", func() { arena.Fight(cross(cur), "my-hunter", "coward") })
37	try("retire twice", func() { arena.Retire(cross(cur), "my-hunter") })
38	arena.Unretire(cross(cur), "my-hunter")
39	println(arena.Fight(cross(cur), "my-hunter", "coward"))
40
41	// my-crasher crashes on turn 10; after the upgrade it plays a full match
42	upgrader.Upgrade(cross(cur), "my-crasher")
43	println(arena.Fight(cross(cur), "brawler", "my-crasher"))
44	info, _ = arena.GetBot("my-crasher")
45	println("version:", info.Version, "played:", info.Played)
46	println("realm:", info.Realm)
47	try("upgrade again from the same realm", func() { upgrader.Upgrade(cross(cur), "my-crasher") })
48	try("upgrade someone else's bot", func() { upgrader.Upgrade(cross(cur), "not-mine") })
49	println(arena.Render("bot/my-crasher"))
50}
51
52// Output:
53// retire someone else's bot: only the owner of not-mine can do this
54// description: Goes for coins. bAttacks/b whenx close No second line.
55// fight a retired bot: my-hunter is retired
56// retire twice: my-hunter is already retired
57// #1 my-hunter 14 - 12 coward, my-hunter wins
58// #2 brawler 1 - 5 my-crasher, my-crasher wins
59// version: 2 played: 1
60// realm: gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/testbots/upgrader
61// upgrade again from the same realm: the new version must live in a new realm
62// upgrade someone else's bot: only the owner of not-mine can upgrade it
63// # my-crasher
64//
65// [Challenge my-crasher](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena/v2$help&func=Fight&a=&b=my-crasher) · [Read its code](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/testbots/upgrader$source)
66//
67// - **Season 1:** Elo 1216, 1-0-0
68// - **All time:** 1 wins, 0 losses (0 by forfeit), 0 draws
69// - **Kind:** realm bot, version 2
70// - **Realm:** `gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/testbots/upgrader`
71// - **Owner:** `g1wtwfayg7gpr0kqw7mnvwqnjjvu6fhun8xrdjal`
72// - **Registered at block:** 123
73// - **Earlier versions:** [v1](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/testbots/crasher$source)
74//
75// ## Matches
76//
77// - [#2 brawler 1 - 5 my-crasher, my-crasher wins](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena/v2:match/2)
78//
79// Owner actions: [describe](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena/v2$help&func=SetDescription&name=my-crasher&text=) · [retire](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena/v2$help&func=Retire&name=my-crasher) · [enter a tournament](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena/v2:tournaments)
80//
81// [Back to the arena](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena/v2)