Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(examples): use std.GetChainDomain() #3293

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/gno.land/p/moul/helplink/helplink.gno
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
package helplink

import (
"std"
"strings"

"gno.land/p/moul/txlink"
)

const chainDomain = "gno.land" // XXX: std.ChainDomain (#2911)

// Func returns a markdown link for the specific function with optional
// key-value arguments, for the current realm.
func Func(title string, fn string, args ...string) string {
Expand Down Expand Up @@ -51,6 +50,7 @@ func (r Realm) prefix() string {

// local realm -> /realm
realm := string(r)
chainDomain := std.GetChainDomain()
if strings.Contains(realm, chainDomain) {
return strings.TrimPrefix(realm, chainDomain)
}
Expand Down
12 changes: 6 additions & 6 deletions examples/gno.land/p/moul/helplink/helplink_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestFunc(t *testing.T) {
realm Realm
}{
{"Example", "foo", []string{"bar", "1", "baz", "2"}, "[Example]($help&func=foo&bar=1&baz=2)", ""},
{"Realm Example", "foo", []string{"bar", "1", "baz", "2"}, "[Realm Example](/r/lorem/ipsum$help&func=foo&bar=1&baz=2)", "gno.land/r/lorem/ipsum"},
{"Realm Example", "foo", []string{"bar", "1", "baz", "2"}, "[Realm Example](/r/lorem/ipsum$help&func=foo&bar=1&baz=2)", "tests.gno.land/r/lorem/ipsum"},
{"Single Arg", "testFunc", []string{"key", "value"}, "[Single Arg]($help&func=testFunc&key=value)", ""},
{"No Args", "noArgsFunc", []string{}, "[No Args]($help&func=noArgsFunc)", ""},
{"Odd Args", "oddArgsFunc", []string{"key"}, "[Odd Args]($help&func=oddArgsFunc)", ""},
Expand All @@ -40,10 +40,10 @@ func TestFuncURL(t *testing.T) {
{"testFunc", []string{"key", "value"}, "$help&func=testFunc&key=value", ""},
{"noArgsFunc", []string{}, "$help&func=noArgsFunc", ""},
{"oddArgsFunc", []string{"key"}, "$help&func=oddArgsFunc", ""},
{"foo", []string{"bar", "1", "baz", "2"}, "/r/lorem/ipsum$help&func=foo&bar=1&baz=2", "gno.land/r/lorem/ipsum"},
{"testFunc", []string{"key", "value"}, "/r/lorem/ipsum$help&func=testFunc&key=value", "gno.land/r/lorem/ipsum"},
{"noArgsFunc", []string{}, "/r/lorem/ipsum$help&func=noArgsFunc", "gno.land/r/lorem/ipsum"},
{"oddArgsFunc", []string{"key"}, "/r/lorem/ipsum$help&func=oddArgsFunc", "gno.land/r/lorem/ipsum"},
{"foo", []string{"bar", "1", "baz", "2"}, "/r/lorem/ipsum$help&func=foo&bar=1&baz=2", "tests.gno.land/r/lorem/ipsum"},
{"testFunc", []string{"key", "value"}, "/r/lorem/ipsum$help&func=testFunc&key=value", "tests.gno.land/r/lorem/ipsum"},
{"noArgsFunc", []string{}, "/r/lorem/ipsum$help&func=noArgsFunc", "tests.gno.land/r/lorem/ipsum"},
{"oddArgsFunc", []string{"key"}, "/r/lorem/ipsum$help&func=oddArgsFunc", "tests.gno.land/r/lorem/ipsum"},
{"foo", []string{"bar", "1", "baz", "2"}, "https://gno.world/r/lorem/ipsum$help&func=foo&bar=1&baz=2", "gno.world/r/lorem/ipsum"},
{"testFunc", []string{"key", "value"}, "https://gno.world/r/lorem/ipsum$help&func=testFunc&key=value", "gno.world/r/lorem/ipsum"},
{"noArgsFunc", []string{}, "https://gno.world/r/lorem/ipsum$help&func=noArgsFunc", "gno.world/r/lorem/ipsum"},
Expand All @@ -65,7 +65,7 @@ func TestHome(t *testing.T) {
want string
}{
{"", "$help"},
{"gno.land/r/lorem/ipsum", "/r/lorem/ipsum$help"},
{"tests.gno.land/r/lorem/ipsum", "/r/lorem/ipsum$help"},
{"gno.world/r/lorem/ipsum", "https://gno.world/r/lorem/ipsum$help"},
}

Expand Down
3 changes: 1 addition & 2 deletions examples/gno.land/p/moul/realmpath/realmpath.gno
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import (
"strings"
)

const chainDomain = "gno.land" // XXX: std.ChainDomain (#2911)

// Request represents a parsed request.
type Request struct {
Path string // The path of the request
Expand Down Expand Up @@ -81,6 +79,7 @@ func (r *Request) String() string {
}

// Rebuild the path using the realm and path parts
chainDomain := std.GetChainDomain()
relativePkgPath := strings.TrimPrefix(r.Realm, chainDomain) // Trim the chain domain prefix
reconstructedPath := relativePkgPath + ":" + strings.Join(r.PathParts(), "/")

Expand Down
6 changes: 3 additions & 3 deletions examples/gno.land/p/moul/realmpath/realmpath_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestExample(t *testing.T) {
std.TestSetRealm(std.NewCodeRealm("gno.land/r/lorem/ipsum"))
std.TestSetRealm(std.NewCodeRealm("tests.gno.land/r/lorem/ipsum"))

// initial parsing
path := "hello/world?foo=bar&baz=foobar"
Expand All @@ -32,7 +32,7 @@ func TestExample(t *testing.T) {
}

func TestParse(t *testing.T) {
std.TestSetRealm(std.NewCodeRealm("gno.land/r/lorem/ipsum"))
std.TestSetRealm(std.NewCodeRealm("tests.gno.land/r/lorem/ipsum"))

tests := []struct {
rawPath string
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestParse(t *testing.T) {
},
{
rawPath: "custom/realm?foo=bar&baz=foobar",
realm: "gno.land/r/foo/bar",
realm: "tests.gno.land/r/foo/bar",
expectedPath: "custom/realm",
expectedQuery: url.Values{
"foo": []string{"bar"},
Expand Down
4 changes: 2 additions & 2 deletions examples/gno.land/p/moul/txlink/txlink.gno
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"strings"
)

const chainDomain = "gno.land" // XXX: std.ChainDomain (#2911)

// Call returns a URL for the specified function with optional key-value
// arguments, for the current realm.
func Call(fn string, args ...string) string {
Expand All @@ -32,6 +30,8 @@ type Realm string

// prefix returns the URL prefix for the realm.
func (r Realm) prefix() string {
chainDomain := std.GetChainDomain()

// relative
if r == "" {
curPath := std.CurrentRealm().PkgPath()
Expand Down
18 changes: 13 additions & 5 deletions examples/gno.land/p/moul/txlink/txlink_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,30 @@ func TestCall(t *testing.T) {
want string
realm Realm
}{
// relative
{"foo", []string{"bar", "1", "baz", "2"}, "$help&func=foo&bar=1&baz=2", ""},
{"testFunc", []string{"key", "value"}, "$help&func=testFunc&key=value", ""},
{"noArgsFunc", []string{}, "$help&func=noArgsFunc", ""},
{"oddArgsFunc", []string{"key"}, "$help&func=oddArgsFunc", ""},
{"foo", []string{"bar", "1", "baz", "2"}, "/r/lorem/ipsum$help&func=foo&bar=1&baz=2", "gno.land/r/lorem/ipsum"},
{"testFunc", []string{"key", "value"}, "/r/lorem/ipsum$help&func=testFunc&key=value", "gno.land/r/lorem/ipsum"},
{"noArgsFunc", []string{}, "/r/lorem/ipsum$help&func=noArgsFunc", "gno.land/r/lorem/ipsum"},
{"oddArgsFunc", []string{"key"}, "/r/lorem/ipsum$help&func=oddArgsFunc", "gno.land/r/lorem/ipsum"},
// gno.land
{"foo", []string{"bar", "1", "baz", "2"}, "https://gno.land/r/lorem/ipsum$help&func=foo&bar=1&baz=2", "gno.land/r/lorem/ipsum"},
{"testFunc", []string{"key", "value"}, "https://gno.land/r/lorem/ipsum$help&func=testFunc&key=value", "gno.land/r/lorem/ipsum"},
{"noArgsFunc", []string{}, "https://gno.land/r/lorem/ipsum$help&func=noArgsFunc", "gno.land/r/lorem/ipsum"},
{"oddArgsFunc", []string{"key"}, "https://gno.land/r/lorem/ipsum$help&func=oddArgsFunc", "gno.land/r/lorem/ipsum"},
// gno.land
{"foo", []string{"bar", "1", "baz", "2"}, "/r/lorem/ipsum$help&func=foo&bar=1&baz=2", "tests.gno.land/r/lorem/ipsum"},
{"testFunc", []string{"key", "value"}, "/r/lorem/ipsum$help&func=testFunc&key=value", "tests.gno.land/r/lorem/ipsum"},
{"noArgsFunc", []string{}, "/r/lorem/ipsum$help&func=noArgsFunc", "tests.gno.land/r/lorem/ipsum"},
{"oddArgsFunc", []string{"key"}, "/r/lorem/ipsum$help&func=oddArgsFunc", "tests.gno.land/r/lorem/ipsum"},
// gno.world
{"foo", []string{"bar", "1", "baz", "2"}, "https://gno.world/r/lorem/ipsum$help&func=foo&bar=1&baz=2", "gno.world/r/lorem/ipsum"},
{"testFunc", []string{"key", "value"}, "https://gno.world/r/lorem/ipsum$help&func=testFunc&key=value", "gno.world/r/lorem/ipsum"},
{"noArgsFunc", []string{}, "https://gno.world/r/lorem/ipsum$help&func=noArgsFunc", "gno.world/r/lorem/ipsum"},
{"oddArgsFunc", []string{"key"}, "https://gno.world/r/lorem/ipsum$help&func=oddArgsFunc", "gno.world/r/lorem/ipsum"},
}

for _, tt := range tests {
title := tt.fn
title := string(tt.realm) + "-" + tt.fn
t.Run(title, func(t *testing.T) {
got := tt.realm.Call(tt.fn, tt.args...)
urequire.Equal(t, tt.want, got)
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/gov/dao/v2/prop1_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func main() {
//
// ### Actions
//
// #### [[Vote YES](/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=YES)] - [[Vote NO](/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=NO)] - [[Vote ABSTAIN](/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=ABSTAIN)]
// #### [[Vote YES](gno.land/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=YES)] - [[Vote NO](gno.land/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=NO)] - [[Vote ABSTAIN](gno.land/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=ABSTAIN)]
//
//
// --
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/gov/dao/v2/prop2_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func main() {
//
// ### Actions
//
// #### [[Vote YES](/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=YES)] - [[Vote NO](/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=NO)] - [[Vote ABSTAIN](/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=ABSTAIN)]
// #### [[Vote YES](gno.land/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=YES)] - [[Vote NO](gno.land/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=NO)] - [[Vote ABSTAIN](gno.land/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=ABSTAIN)]
//
//
// --
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/gov/dao/v2/prop3_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func main() {
//
// ### Actions
//
// #### [[Vote YES](/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=YES)] - [[Vote NO](/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=NO)] - [[Vote ABSTAIN](/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=ABSTAIN)]
// #### [[Vote YES](gno.land/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=YES)] - [[Vote NO](gno.land/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=NO)] - [[Vote ABSTAIN](gno.land/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=ABSTAIN)]
//
//
// --
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/gov/dao/v2/prop4_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func main() {
//
// ### Actions
//
// #### [[Vote YES](/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=YES)] - [[Vote NO](/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=NO)] - [[Vote ABSTAIN](/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=ABSTAIN)]
// #### [[Vote YES](gno.land/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=YES)] - [[Vote NO](gno.land/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=NO)] - [[Vote ABSTAIN](gno.land/r/gov/dao/v2$help&func=VoteOnProposal&id=0&option=ABSTAIN)]
//
//
// --
Expand Down
Loading