PathrockNetwork Gno Explorer
HomeBlocksTransactionsRealmsPackagesValidatorsAnalytics

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/p/leon/ctg/v0

Package
Open in gnoweb ↗

Overview

Kind
Pure package
Name
v0
Namespace
leon / ctg
Files
3 (gnomod.toml)
Exported functions
n/a — not supported for pure packages by the node (vm/qfuncs)
Module
gno.land/p/leon/ctg/v0
gno
0.9

Files (3)

  • gnomod.tomltoml
  • converter.gnogno
  • converter_test.gnogno
converter_test.gnogno
1package ctg23import (4	"testing"5)67func TestConvertKnownAddress(t *testing.T) {8	const (9		cosmosAddr = "cosmos1jg8mtutu9khhfwc4nxmuhcpftf0pajdh6svrgs"10		gnoAddr    = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"11	)12	got, err := ConvertCosmosToGno(cosmosAddr)13	if err != nil {14		t.Fatalf("unexpected error: %v", err)15	}16	if got != gnoAddr {17		t.Fatalf("got %s, want %s", got, gnoAddr)18	}19}2021func TestConvertCosmosToGno(t *testing.T) {22	decoded := []byte{23		0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,24		0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,25		0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,26		0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x00,27	}2829	cosmosAddr := mustEncode("cosmos", decoded)30	wantGno := mustEncode("g", decoded)3132	got, err := ConvertCosmosToGno(cosmosAddr)33	if err != nil {34		t.Fatalf("unexpected error: %v", err)35	}36	if string(got) != wantGno {37		t.Fatalf("got %s, want %s", got, wantGno)38	}3940	// invalid bech3241	if _, err := ConvertCosmosToGno("not-bech32"); err == nil {42		t.Fatalf("expected error for invalid bech32")43	}4445	// wrong prefix46	gAddr := mustEncode("g", decoded)47	if _, err := ConvertCosmosToGno(gAddr); err == nil {48		t.Fatalf("expected error for non-cosmos prefix")49	}50}5152func TestConvertAnyToGno(t *testing.T) {53	payload := []byte{54		0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,55		0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,56		0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,57		0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x00,58	}5960	tests := []struct {61		name    string62		input   string63		want    string64		wantErr bool65	}{66		{67			name:  "cosmos→g",68			input: mustEncode("cosmos", payload),69			want:  mustEncode("g", payload),70		},71		{72			name:  "osmo→g",73			input: mustEncode("osmo", payload),74			want:  mustEncode("g", payload),75		},76		{77			name:    "invalid bech32",78			input:   "xyz123",79			wantErr: true,80		},81	}8283	for _, tc := range tests {84		t.Run(tc.name, func(t *testing.T) {85			got, err := ConvertAnyToGno(tc.input)86			if tc.wantErr {87				if err == nil {88					t.Fatalf("expected error, got nil")89				}90				return91			}92			if err != nil {93				t.Fatalf("unexpected error: %v", err)94			}95			if string(got) != tc.want {96				t.Fatalf("got %s, want %s", got, tc.want)97			}98		})99	}100}101102func TestConvertGnoToAny(t *testing.T) {103	payload := []byte{104		0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,105		0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,106		0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,107		0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x00,108	}109110	gno := address(mustEncode("g", payload))111112	t.Run("g→cosmos", func(t *testing.T) {113		got, err := ConvertGnoToAny("cosmos", gno)114		if err != nil {115			t.Fatalf("unexpected error: %v", err)116		}117		if got != mustEncode("cosmos", payload) {118			t.Fatalf("conversion incorrect: %s", got)119		}120	})121122	t.Run("g→foobar", func(t *testing.T) {123		got, err := ConvertGnoToAny("foobar", gno)124		if err != nil {125			t.Fatalf("unexpected error: %v", err)126		}127		if got != mustEncode("foobar", payload) {128			t.Fatalf("conversion incorrect: %s", got)129		}130	})131132	t.Run("g→osmo", func(t *testing.T) {133		got, err := ConvertGnoToAny("osmo", gno)134		if err != nil {135			t.Fatalf("unexpected error: %v", err)136		}137		if got != mustEncode("osmo", payload) {138			t.Fatalf("conversion incorrect: %s", got)139		}140	})141142	t.Run("wrong source prefix", func(t *testing.T) {143		cosmos := mustEncode("cosmos", payload)144		if _, err := ConvertGnoToAny("g", address(cosmos)); err == nil {145			t.Fatalf("expected error for non-g source prefix")146		}147	})148149	t.Run("invalid bech32", func(t *testing.T) {150		if _, err := ConvertGnoToAny("cosmos", address("nope")); err == nil {151			t.Fatalf("expected error for invalid bech32")152		}153	})154}155

Functions

not supported for pure packages by the node (vm/qfuncs)

Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.