z_turn_filetest.gno
3.34 Kb · 129 lines
1// PKGPATH: gno.land/r/demo/main
2
3// A match's moves each tell the player who moves next, and only them.
4package main
5
6import (
7 "crypto/sha256"
8 "encoding/hex"
9 "testing"
10
11 "gno.land/p/nt/testutils/v0"
12 "gno.land/r/nym-gfanton001/gnomepit/arena/v0"
13)
14
15const (
16 deckA = "Pickaxe Flurry,Kneecap,Sling Stone,Dodge Roll,Chalk Dust,Double Tap,Momentum,Undermine"
17 deckB = "Stone Guard,Bulwark,Hammer Blow,Cobble Throw,Spiked Shield,Anvil Stomp,Feint,Avalanche"
18 saltA = "0101010101010101010101010101010101010101010101010101010101010101"
19 salt1 = "1111111111111111111111111111111111111111111111111111111111111111"
20 salt2 = "2222222222222222222222222222222222222222222222222222222222222222"
21 picks = "Pick,Pick,Pick"
22 braces = "Brace,Brace,Brace"
23)
24
25func seal(salt, text string) string {
26 b, _ := hex.DecodeString(salt)
27 sum := sha256.Sum256(append(b, text...))
28 return hex.EncodeToString(sum[:])
29}
30
31func main(cur realm) {
32 alice := testutils.TestAddress("alice")
33 bob := testutils.TestAddress("bob")
34
35 testing.SetRealm(testing.NewUserRealm(alice))
36 id := arena.Challenge(cross(cur), "Pickers", seal(saltA, deckA), seal(salt1, picks), "box1", "")
37 testing.SetRealm(testing.NewUserRealm(bob))
38 arena.Accept(cross(cur), id, "Ironhide", deckB, braces)
39 testing.SetRealm(testing.NewUserRealm(alice))
40 arena.Reveal(cross(cur), id, deckA, saltA, picks, salt1, seal(salt2, picks), "box2")
41 testing.SetRealm(testing.NewUserRealm(bob))
42 arena.Play(cross(cur), id, braces)
43}
44
45// Events:
46// [
47// {
48// "type": "Board",
49// "attrs": [
50// {
51// "key": "match",
52// "value": "1"
53// },
54// {
55// "key": "text",
56// "value": "Pickers posted a challenge."
57// }
58// ],
59// "pkg_path": "gno.land/r/nym-gfanton001/gnomepit/arena/v0"
60// },
61// {
62// "type": "Board",
63// "attrs": [
64// {
65// "key": "match",
66// "value": "1"
67// },
68// {
69// "key": "text",
70// "value": "Challenge 1 was taken."
71// }
72// ],
73// "pkg_path": "gno.land/r/nym-gfanton001/gnomepit/arena/v0"
74// },
75// {
76// "type": "Turn",
77// "attrs": [
78// {
79// "key": "to",
80// "value": "g1v9kxjcm9ta047h6lta047h6lta047h6lzd40gh"
81// },
82// {
83// "key": "match",
84// "value": "1"
85// },
86// {
87// "key": "text",
88// "value": "Ironhide accepted your challenge. Your move within 24 hours."
89// }
90// ],
91// "pkg_path": "gno.land/r/nym-gfanton001/gnomepit/arena/v0"
92// },
93// {
94// "type": "Turn",
95// "attrs": [
96// {
97// "key": "to",
98// "value": "g1vfhkyh6lta047h6lta047h6lta047h6l03vdhu"
99// },
100// {
101// "key": "match",
102// "value": "1"
103// },
104// {
105// "key": "text",
106// "value": "Round 1 is over: you 15 HP, them 15. Your move within 24 hours."
107// }
108// ],
109// "pkg_path": "gno.land/r/nym-gfanton001/gnomepit/arena/v0"
110// },
111// {
112// "type": "Turn",
113// "attrs": [
114// {
115// "key": "to",
116// "value": "g1v9kxjcm9ta047h6lta047h6lta047h6lzd40gh"
117// },
118// {
119// "key": "match",
120// "value": "1"
121// },
122// {
123// "key": "text",
124// "value": "Ironhide played round 2. Your move within 24 hours."
125// }
126// ],
127// "pkg_path": "gno.land/r/nym-gfanton001/gnomepit/arena/v0"
128// }
129// ]