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.

player_test.gno

1.17 Kb · 42 lines
 1package flag
 2
 3import (
 4	"chain"
 5	"testing"
 6)
 7
 8func TestPlayerUser(t *testing.T) {
 9	user := testing.MakeRealm(ash, "", testing.OriginRealm())
10	got, err := Player(user)
11	if err != nil || got != ash {
12		t.Fatalf("Player(user) = %s, %v", got, err)
13	}
14}
15
16func TestPlayerNamespace(t *testing.T) {
17	path := "gno.land/r/" + string(briar) + "/solutions/rack"
18	code := testing.MakeRealm(chain.PackageAddress(path), path, testing.OriginRealm())
19	got, err := Player(code)
20	if err != nil || got != briar {
21		t.Fatalf("Player(code) = %s, %v", got, err)
22	}
23}
24
25func TestPlayerRejectsNamedNamespace(t *testing.T) {
26	for _, path := range []string{"gno.land/r/moul/home", "gno.land/r/x", "gno.land/p/" + string(ash) + "/lib"} {
27		code := testing.MakeRealm(chain.PackageAddress(path), path, testing.OriginRealm())
28		if _, err := Player(code); err != ErrNoPlayer {
29			t.Errorf("Player(%q) err = %v, want ErrNoPlayer", path, err)
30		}
31	}
32}
33
34func TestMustPlayerPanics(t *testing.T) {
35	defer func() {
36		if recover() == nil {
37			t.Fatal("MustPlayer should panic for an unknown namespace")
38		}
39	}()
40	path := "gno.land/r/moul/home"
41	MustPlayer(testing.MakeRealm(chain.PackageAddress(path), path, testing.OriginRealm()))
42}