z_ended_filetest.gno
5.03 Kb · 190 lines
1// PKGPATH: gno.land/r/demo/main
2
3// The reveal that knocks a gnome out tells the other player the match is over. A
4// player who accepts their own challenge gets no Turn or Ended, since each would name
5// the caller; only the board hears of that match.
6package main
7
8import (
9 "crypto/sha256"
10 "encoding/hex"
11 "testing"
12
13 "gno.land/p/nt/testutils/v0"
14 "gno.land/r/nym-gfanton001/gnomepit/arena/v0"
15)
16
17const (
18 deckA = "Pickaxe Flurry,Kneecap,Sling Stone,Dodge Roll,Chalk Dust,Double Tap,Momentum,Undermine"
19 deckB = "Stone Guard,Bulwark,Hammer Blow,Cobble Throw,Spiked Shield,Anvil Stomp,Feint,Avalanche"
20 saltA = "0101010101010101010101010101010101010101010101010101010101010101"
21 salt1 = "1111111111111111111111111111111111111111111111111111111111111111"
22 salt2 = "2222222222222222222222222222222222222222222222222222222222222222"
23 picks = "Pick,Pick,Pick"
24)
25
26func seal(salt, text string) string {
27 b, _ := hex.DecodeString(salt)
28 sum := sha256.Sum256(append(b, text...))
29 return hex.EncodeToString(sum[:])
30}
31
32func main(cur realm) {
33 alice := testutils.TestAddress("alice")
34 bob := testutils.TestAddress("bob")
35
36 testing.SetRealm(testing.NewUserRealm(alice))
37 solo := arena.Challenge(cross(cur), "Pickers", seal(saltA, deckA), seal(salt1, picks), "box1", "")
38 arena.Accept(cross(cur), solo, "Ironhide", deckB, "Pick,Anvil Stomp")
39 arena.Reveal(cross(cur), solo, deckA, saltA, picks, salt1, seal(salt2, picks), "box2")
40 arena.Play(cross(cur), solo, "Hammer Blow,Cobble Throw")
41 arena.Reveal(cross(cur), solo, "", "", picks, salt2, "", "")
42 println(arena.Match(solo).Result)
43
44 id := arena.Challenge(cross(cur), "Pickers", seal(saltA, deckA), seal(salt1, picks), "box1", "")
45 testing.SetRealm(testing.NewUserRealm(bob))
46 arena.Accept(cross(cur), id, "Ironhide", deckB, "Pick,Anvil Stomp")
47 testing.SetRealm(testing.NewUserRealm(alice))
48 arena.Reveal(cross(cur), id, deckA, saltA, picks, salt1, seal(salt2, picks), "box2")
49 testing.SetRealm(testing.NewUserRealm(bob))
50 arena.Play(cross(cur), id, "Hammer Blow,Cobble Throw")
51 testing.SetRealm(testing.NewUserRealm(alice))
52 arena.Reveal(cross(cur), id, "", "", picks, salt2, "", "")
53 println(arena.Match(id).Result)
54}
55
56// Output:
57// b
58// b
59
60// Events:
61// [
62// {
63// "type": "Board",
64// "attrs": [
65// {
66// "key": "match",
67// "value": "1"
68// },
69// {
70// "key": "text",
71// "value": "Pickers posted a challenge."
72// }
73// ],
74// "pkg_path": "gno.land/r/nym-gfanton001/gnomepit/arena/v0"
75// },
76// {
77// "type": "Board",
78// "attrs": [
79// {
80// "key": "match",
81// "value": "1"
82// },
83// {
84// "key": "text",
85// "value": "Challenge 1 was taken."
86// }
87// ],
88// "pkg_path": "gno.land/r/nym-gfanton001/gnomepit/arena/v0"
89// },
90// {
91// "type": "Board",
92// "attrs": [
93// {
94// "key": "match",
95// "value": "2"
96// },
97// {
98// "key": "text",
99// "value": "Pickers posted a challenge."
100// }
101// ],
102// "pkg_path": "gno.land/r/nym-gfanton001/gnomepit/arena/v0"
103// },
104// {
105// "type": "Board",
106// "attrs": [
107// {
108// "key": "match",
109// "value": "2"
110// },
111// {
112// "key": "text",
113// "value": "Challenge 2 was taken."
114// }
115// ],
116// "pkg_path": "gno.land/r/nym-gfanton001/gnomepit/arena/v0"
117// },
118// {
119// "type": "Turn",
120// "attrs": [
121// {
122// "key": "to",
123// "value": "g1v9kxjcm9ta047h6lta047h6lta047h6lzd40gh"
124// },
125// {
126// "key": "match",
127// "value": "2"
128// },
129// {
130// "key": "text",
131// "value": "Ironhide accepted your challenge. Your move within 24 hours."
132// }
133// ],
134// "pkg_path": "gno.land/r/nym-gfanton001/gnomepit/arena/v0"
135// },
136// {
137// "type": "Turn",
138// "attrs": [
139// {
140// "key": "to",
141// "value": "g1vfhkyh6lta047h6lta047h6lta047h6l03vdhu"
142// },
143// {
144// "key": "match",
145// "value": "2"
146// },
147// {
148// "key": "text",
149// "value": "Round 1 is over: you 12 HP, them 12. Your move within 24 hours."
150// }
151// ],
152// "pkg_path": "gno.land/r/nym-gfanton001/gnomepit/arena/v0"
153// },
154// {
155// "type": "Turn",
156// "attrs": [
157// {
158// "key": "to",
159// "value": "g1v9kxjcm9ta047h6lta047h6lta047h6lzd40gh"
160// },
161// {
162// "key": "match",
163// "value": "2"
164// },
165// {
166// "key": "text",
167// "value": "Ironhide played round 2. Your move within 24 hours."
168// }
169// ],
170// "pkg_path": "gno.land/r/nym-gfanton001/gnomepit/arena/v0"
171// },
172// {
173// "type": "Ended",
174// "attrs": [
175// {
176// "key": "to",
177// "value": "g1vfhkyh6lta047h6lta047h6lta047h6l03vdhu"
178// },
179// {
180// "key": "match",
181// "value": "2"
182// },
183// {
184// "key": "text",
185// "value": "You won by knockout."
186// }
187// ],
188// "pkg_path": "gno.land/r/nym-gfanton001/gnomepit/arena/v0"
189// }
190// ]