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.

report_test.gno

4.28 Kb · 107 lines
  1package arena
  2
  3import (
  4	"testing"
  5
  6	"gno.land/p/nym-gfanton001/gnomepit/engine/v0"
  7	"gno.land/p/nt/uassert/v0"
  8	"gno.land/p/nt/urequire/v0"
  9	"gno.land/r/nym-gfanton001/gnomepit/standings/v0"
 10)
 11
 12// checkReported checks that the standings realm holds one result more than before, from this
 13// arena, for alice as Pickers against bob as Ironhide, ending in result. The standings realm
 14// keeps its state across tests, which reset cannot reach.
 15func checkReported(t *testing.T, before int, result string) {
 16	t.Helper()
 17	urequire.Equal(t, before+1, standings.ResultCount())
 18	page := standings.Results(before, 1)
 19	urequire.Equal(t, 1, len(page))
 20	r := page[0]
 21	uassert.Equal(t, "gno.land/r/nym-gfanton001/gnomepit/arena/v0", r.Writer)
 22	uassert.Equal(t, alice.String(), r.Challenger)
 23	uassert.Equal(t, bob.String(), r.Acceptor)
 24	uassert.Equal(t, "Pickers", r.ChallengerClan)
 25	uassert.Equal(t, "Ironhide", r.AcceptorClan)
 26	uassert.Equal(t, result, r.Result)
 27}
 28
 29func TestEndingsReport(cur realm, t *testing.T) {
 30	// The worked match ends on HP with the challenger's last Reveal.
 31	reset()
 32	before := standings.ResultCount()
 33	a1, b1 := "Chalk Dust,Double Tap", "Hammer Blow,Spiked Shield"
 34	testing.SetRealm(testing.NewUserRealm(alice))
 35	id := Challenge(cross(cur), "Pickers", sealOf(saltA, deckA), sealOf(salt1, a1), boxOf("box1"), "")
 36	testing.SetRealm(testing.NewUserRealm(bob))
 37	Accept(cross(cur), id, "Ironhide", deckB, b1)
 38	testing.SetRealm(testing.NewUserRealm(alice))
 39	Reveal(cross(cur), id, deckA, saltA, a1, salt1, sealOf(salt2, picks), boxOf("box2"))
 40	testing.SetRealm(testing.NewUserRealm(bob))
 41	Play(cross(cur), id, braces)
 42	testing.SetRealm(testing.NewUserRealm(alice))
 43	Reveal(cross(cur), id, "", "", picks, salt2, sealOf(salt3, picks), boxOf("box3"))
 44	testing.SetRealm(testing.NewUserRealm(bob))
 45	Play(cross(cur), id, braces)
 46	testing.SetRealm(testing.NewUserRealm(alice))
 47	Reveal(cross(cur), id, "", "", picks, salt3, "", "")
 48	uassert.Equal(t, "hp", Match(id).Reason)
 49	checkReported(t, before, Match(id).Result)
 50
 51	// A knockout ends it with the second Reveal.
 52	reset()
 53	before = standings.ResultCount()
 54	testing.SetRealm(testing.NewUserRealm(alice))
 55	id = Challenge(cross(cur), "Pickers", sealOf(saltA, deckA), sealOf(salt1, picks), boxOf("box1"), "")
 56	testing.SetRealm(testing.NewUserRealm(bob))
 57	Accept(cross(cur), id, "Ironhide", deckB, "Pick,Anvil Stomp")
 58	testing.SetRealm(testing.NewUserRealm(alice))
 59	Reveal(cross(cur), id, deckA, saltA, picks, salt1, sealOf(salt2, picks), boxOf("box2"))
 60	testing.SetRealm(testing.NewUserRealm(bob))
 61	Play(cross(cur), id, "Hammer Blow,Cobble Throw")
 62	testing.SetRealm(testing.NewUserRealm(alice))
 63	Reveal(cross(cur), id, "", "", picks, salt2, "", "")
 64	uassert.Equal(t, "knockout", Match(id).Reason)
 65	checkReported(t, before, "b")
 66
 67	// A resignation.
 68	reset()
 69	before = standings.ResultCount()
 70	testing.SetRealm(testing.NewUserRealm(alice))
 71	id = Challenge(cross(cur), "Pickers", sealOf(saltA, deckA), sealOf(salt1, picks), boxOf("box1"), "")
 72	testing.SetRealm(testing.NewUserRealm(bob))
 73	Accept(cross(cur), id, "Ironhide", deckB, braces)
 74	Resign(cross(cur), id)
 75	checkReported(t, before, "a")
 76
 77	// A forfeit claimed by a third wallet.
 78	reset()
 79	before = standings.ResultCount()
 80	testing.SetRealm(testing.NewUserRealm(alice))
 81	id = Challenge(cross(cur), "Pickers", sealOf(saltA, deckA), sealOf(salt1, picks), boxOf("box1"), "")
 82	testing.SetRealm(testing.NewUserRealm(bob))
 83	Accept(cross(cur), id, "Ironhide", deckB, braces)
 84	testing.SkipHeights(day + 1)
 85	testing.SetRealm(testing.NewUserRealm(carol))
 86	ClaimForfeit(cross(cur), id)
 87	checkReported(t, before, "b")
 88}
 89
 90func TestSelfAcceptedMatchUnreported(cur realm, t *testing.T) {
 91	reset()
 92	before := standings.ResultCount()
 93	testing.SetRealm(testing.NewUserRealm(alice))
 94	id := Challenge(cross(cur), "Pickers", sealOf(saltA, deckA), sealOf(salt1, picks), boxOf("box1"), "")
 95	Accept(cross(cur), id, "Ironhide", deckB, braces)
 96	Resign(cross(cur), id)
 97	uassert.Equal(t, "ended", Match(id).Phase)
 98	uassert.Equal(t, before, standings.ResultCount(), "a self-match is never reported")
 99}
100
101// TestEveryClanNamePassesTheStore checks that the standings realm takes every clan name: one
102// it refuses would abort every ending.
103func TestEveryClanNamePassesTheStore(t *testing.T) {
104	for _, c := range engine.ProofOfConcept().Clans {
105		uassert.True(t, len(c.Name) >= 1 && len(c.Name) <= 32, c.Name)
106	}
107}