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.

z_board_filetest.gno

3.47 Kb · 139 lines
  1// PKGPATH: gno.land/r/demo/main
  2
  3// Posting, taking and withdrawing a challenge each tell every browser that follows the
  4// board, with an event that names no address.
  5package main
  6
  7import (
  8	"crypto/sha256"
  9	"encoding/hex"
 10	"testing"
 11
 12	"gno.land/p/nt/testutils/v0"
 13	"gno.land/r/nym-gfanton001/gnomepit/arena/v0"
 14)
 15
 16const (
 17	deckA = "Pickaxe Flurry,Kneecap,Sling Stone,Dodge Roll,Chalk Dust,Double Tap,Momentum,Undermine"
 18	deckB = "Stone Guard,Bulwark,Hammer Blow,Cobble Throw,Spiked Shield,Anvil Stomp,Feint,Avalanche"
 19	saltA = "0101010101010101010101010101010101010101010101010101010101010101"
 20	salt1 = "1111111111111111111111111111111111111111111111111111111111111111"
 21	picks = "Pick,Pick,Pick"
 22	brace = "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	taken := arena.Challenge(cross(cur), "Pickers", seal(saltA, deckA), seal(salt1, picks), "box1", "")
 37	testing.SetRealm(testing.NewUserRealm(bob))
 38	arena.Accept(cross(cur), taken, "Ironhide", deckB, brace)
 39	testing.SetRealm(testing.NewUserRealm(alice))
 40	withdrawn := arena.Challenge(cross(cur), "Pickers", seal(saltA, deckA), seal(salt1, picks), "box1", "")
 41	arena.Resign(cross(cur), withdrawn)
 42	arena.Resign(cross(cur), taken)
 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": "Board",
 95//     "attrs": [
 96//       {
 97//         "key": "match",
 98//         "value": "2"
 99//       },
100//       {
101//         "key": "text",
102//         "value": "Pickers posted a challenge."
103//       }
104//     ],
105//     "pkg_path": "gno.land/r/nym-gfanton001/gnomepit/arena/v0"
106//   },
107//   {
108//     "type": "Board",
109//     "attrs": [
110//       {
111//         "key": "match",
112//         "value": "2"
113//       },
114//       {
115//         "key": "text",
116//         "value": "Challenge 2 was withdrawn."
117//       }
118//     ],
119//     "pkg_path": "gno.land/r/nym-gfanton001/gnomepit/arena/v0"
120//   },
121//   {
122//     "type": "Ended",
123//     "attrs": [
124//       {
125//         "key": "to",
126//         "value": "g1vfhkyh6lta047h6lta047h6lta047h6l03vdhu"
127//       },
128//       {
129//         "key": "match",
130//         "value": "1"
131//       },
132//       {
133//         "key": "text",
134//         "value": "Your opponent resigned. You won."
135//       }
136//     ],
137//     "pkg_path": "gno.land/r/nym-gfanton001/gnomepit/arena/v0"
138//   }
139// ]