diff --git a/examples/gno.land/r/matijamarjanovic/tokenhub/tokenhub.gno b/examples/gno.land/r/matijamarjanovic/tokenhub/tokenhub.gno index 374b5e4a5df..41fd7a11fb7 100644 --- a/examples/gno.land/r/matijamarjanovic/tokenhub/tokenhub.gno +++ b/examples/gno.land/r/matijamarjanovic/tokenhub/tokenhub.gno @@ -91,11 +91,11 @@ func RegisterGRC1155Token(mtGetter grc1155.MultiTokenGetter, tokenID string) err } func GetMyBalancesAll() string { - return getBalances(std.GetOrigCaller()) + return getBalances(string(std.PrevRealm().Addr())) } func GetMyBalances() string { - return getNonZeroBalances(std.GetOrigCaller()) + return getNonZeroBalances(string(std.PrevRealm().Addr())) } func GetGRC20(key string) grc20.TokenGetter { @@ -138,22 +138,6 @@ func MustGetGRC1155(key string) GRC1155TokenInfo { return info } -func GetBalancesAll(input string) string { - addr := getAddressForUsername(input) - if addr == "" { - panic("invalid address or username: " + input) - } - return getBalances(addr) -} - -func GetBalances(input string) string { - addr := getAddressForUsername(input) - if addr == "" { - panic("invalid address or username: " + input) - } - return getNonZeroBalances(addr) -} - func GetAllNFTs() string { var sb strings.Builder registeredNFTs.Iterate("", "", func(key string, value interface{}) bool { @@ -188,6 +172,12 @@ func GetAllTokens() string { GetAllMultiTokens()) } +func GetAllTokensNoNFTs() string { + return ufmt.Sprintf("%s%s", + GetAllGRC20Tokens(), + GetAllMultiTokens()) +} + func Render(path string) string { var sb strings.Builder sb.WriteString(test) @@ -389,10 +379,13 @@ func Render(path string) string { return sb.String() } -func getBalances(addr std.Address) string { +func getBalances(input string) string { + + addr := getAddressForUsername(input) if addr == "" { - panic("invalid address") + panic("invalid address or username: " + input) } + balances := avl.NewTree() var sb strings.Builder @@ -449,10 +442,12 @@ func getBalances(addr std.Address) string { return sb.String() } -func getNonZeroBalances(addr std.Address) string { +func getNonZeroBalances(input string) string { + addr := getAddressForUsername(input) if addr == "" { - panic("invalid address") + panic("invalid address or username: " + input) } + balances := avl.NewTree() var sb strings.Builder diff --git a/examples/gno.land/r/matijamarjanovic/tokenhub/tokenhub_test.gno b/examples/gno.land/r/matijamarjanovic/tokenhub/tokenhub_test.gno index df65f27751b..7a5340cfbcf 100644 --- a/examples/gno.land/r/matijamarjanovic/tokenhub/tokenhub_test.gno +++ b/examples/gno.land/r/matijamarjanovic/tokenhub/tokenhub_test.gno @@ -30,10 +30,8 @@ func TestTokenRegistration(t *testing.T) { func TestNFTRegistration(t *testing.T) { std.TestSetRealm(std.NewCodeRealm("gno.land/r/matijamarjanovic/home")) - addr := std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y") - nft := grc721.NewBasicNFT("Test NFT", "TNFT") - nft.Mint(addr, grc721.TokenID("1")) + nft.Mint(std.CurrentRealm().Addr(), grc721.TokenID("1")) err := RegisterNFT(nft.Getter(), "test_nft", "1") urequire.NoError(t, err, "Should register NFT without error") @@ -69,22 +67,20 @@ func TestGRC1155Registration(t *testing.T) { func TestBalanceRetrieval(t *testing.T) { std.TestSetRealm(std.NewCodeRealm("gno.land/r/matijamarjanovic/home")) - addr := std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y") - token, ledger := grc20.NewToken("Test Token", "TEST", 6) RegisterToken(token.Getter(), "test_tokenn") - ledger.Mint(addr, 1000) + ledger.Mint(std.CurrentRealm().Addr(), 1000) mt := grc1155.NewBasicGRC1155Token("test-uri") RegisterGRC1155Token(mt.Getter(), "11") - mt.SafeMint(addr, grc1155.TokenID("11"), 5) + mt.SafeMint(std.CurrentRealm().Addr(), grc1155.TokenID("11"), 5) - balances := GetBalancesAll(string(addr)) + balances := GetMyBalancesAll() uassert.True(t, strings.Contains(balances, "Token:gno.land/r/matijamarjanovic/tokenhub.test_tokenn:1000"), "Should show correct GRC20 balance") - uassert.True(t, strings.Contains(balances, "NFT:gno.land/r/matijamarjanovic/home.test_nft.1:1"), "Should show correct NFT balance") //already minted in test register + uassert.True(t, strings.Contains(balances, "NFT:gno.land/r/matijamarjanovic/home.test_nft.1"), "Should show correct NFT balance") //already minted in test register uassert.True(t, strings.Contains(balances, "MultiToken:gno.land/r/matijamarjanovic/home.11:5"), "Should show multi-token balance") - nonZeroBalances := GetBalances(string(addr)) + nonZeroBalances := GetMyBalances() uassert.True(t, strings.Contains(nonZeroBalances, "Token:gno.land/r/matijamarjanovic/tokenhub.test_tokenn:1000"), "Should show non-zero GRC20 balance") } @@ -104,10 +100,6 @@ func TestErrorCases(t *testing.T) { err = RegisterGRC1155Token(mt.Getter(), "1") uassert.True(t, err != nil, "Should not allow duplicate registration") - - uassert.PanicsWithMessage(t, "invalid address or username: invalid", func() { - GetBalances("invalid") - }) } func TestTokenListingFunctions(t *testing.T) {