From eca0147ef04e1851c802f645a80a0f001707d8d6 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Tue, 12 Dec 2023 12:36:18 +0100 Subject: [PATCH 1/9] feat: split `r/demo/users` --- .../grc/grc1155/basic_grc1155_token_test.gno | 898 +++++++++--------- examples/gno.land/p/demo/grc/grc1155/gno.mod | 1 - .../p/demo/grc/grc721/basic_nft_test.gno | 824 ++++++++-------- examples/gno.land/p/demo/grc/grc721/gno.mod | 1 - examples/gno.land/p/demo/microblog/gno.mod | 2 +- .../gno.land/p/demo/microblog/microblog.gno | 59 +- examples/gno.land/p/demo/users/gno.mod | 1 + .../gno.land/{r => p}/demo/users/types.gno | 10 - examples/gno.land/p/demo/users/users.gno | 31 + examples/gno.land/p/demo/users/users_test.gno | 1 + examples/gno.land/r/demo/boards/misc.gno | 4 +- examples/gno.land/r/demo/foo1155/foo1155.gno | 44 +- examples/gno.land/r/demo/foo1155/gno.mod | 1 + examples/gno.land/r/demo/foo20/foo20.gno | 34 +- examples/gno.land/r/demo/foo20/gno.mod | 1 + examples/gno.land/r/demo/foo721/foo721.gno | 26 +- .../gno.land/r/demo/foo721/foo721_test.gno | 2 +- examples/gno.land/r/demo/foo721/gno.mod | 1 + examples/gno.land/r/demo/groups/misc.gno | 4 +- examples/gno.land/r/demo/microblog/gno.mod | 1 + .../gno.land/r/demo/microblog/microblog.gno | 58 +- examples/gno.land/r/demo/users/gno.mod | 5 +- examples/gno.land/r/demo/users/users.gno | 83 +- 23 files changed, 1052 insertions(+), 1040 deletions(-) create mode 100644 examples/gno.land/p/demo/users/gno.mod rename examples/gno.land/{r => p}/demo/users/types.gno (56%) create mode 100644 examples/gno.land/p/demo/users/users.gno create mode 100644 examples/gno.land/p/demo/users/users_test.gno diff --git a/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno b/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno index 43298cb1136..8a2c7e6bc0a 100644 --- a/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno +++ b/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno @@ -1,451 +1,451 @@ package grc1155 -import ( - "fmt" - "std" - "testing" - - "gno.land/r/demo/users" -) - -const dummyURI = "ipfs://xyz" - -func TestNewBasicGRC1155Token(t *testing.T) { - dummy := NewBasicGRC1155Token(dummyURI) - if dummy == nil { - return t.Errorf("should not be nil") - } -} - -func TestUri(t *testing.T) { - dummy := NewBasicGRC1155Token(dummyURI) - if dummy == nil { - t.Errorf("should not be nil") - } - - uri := dummy.Uri() - if uri != dummyURI { - t.Errorf("expected: (%s), got: (%s)", dummyURI, uri) - } -} - -func TestBalanceOf(t *testing.T) { - dummy := NewBasicGRC1155Token(dummyURI) - if dummy == nil { - t.Errorf("should not be nil") - } - - addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() - addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj").Resolve() - - tid1 := TokenID("1") - tid2 := TokenID("2") - - balanceZeroAddressOfToken1, err := dummy.BalanceOf(zeroAddress, tid1) - if err == nil { - t.Errorf("should result in error") - } - balanceAddr1OfToken1, err := dummy.BalanceOf(addr1, tid1) - if err != nil { - t.Errorf("should not result in error") - } - if balanceAddr1OfToken1 != 0 { - t.Errorf("expected: (%d), got: (%d)", 0, balanceAddr1OfToken1) - } - - dummy.mintBatch(addr1, []TokenID{tid1, tid2}, []uint64{10, 100}) - dummy.mintBatch(addr2, []TokenID{tid1}, []uint64{20}) - - balanceAddr1OfToken1, err = dummy.BalanceOf(addr1, tid1) - if err != nil { - t.Errorf("should not result in error") - } - balanceAddr1OfToken2, err := dummy.BalanceOf(addr1, tid2) - if err != nil { - t.Errorf("should not result in error") - } - balanceAddr2OfToken1, err := dummy.BalanceOf(addr2, tid1) - if err != nil { - t.Errorf("should not result in error") - } - - if balanceAddr1OfToken1 != 10 { - t.Errorf("expected: (%d), got: (%d)", 10, balanceAddr1OfToken1) - } - if balanceAddr1OfToken2 != 100 { - t.Errorf("expected: (%d), got: (%d)", 100, balanceAddr1OfToken2) - } - if balanceAddr2OfToken1 != 20 { - t.Errorf("expected: (%d), got: (%d)", 20, balanceAddr2OfToken1) - } -} - -func TestBalanceOfBatch(t *testing.T) { - dummy := NewBasicGRC1155Token(dummyURI) - if dummy == nil { - t.Errorf("should not be nil") - } - - addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() - addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj").Resolve() - - tid1 := TokenID("1") - tid2 := TokenID("2") - - balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr1, addr2}, []TokenID{tid1, tid2}) - if err != nil { - t.Errorf("should not result in error") - } - - if balanceBatch[0] != 0 { - t.Errorf("expected: (%d), got: (%d)", 0, balanceBatch[0]) - } - if balanceBatch[1] != 0 { - t.Errorf("expected: (%d), got: (%d)", 0, balanceBatch[1]) - } - - dummy.mintBatch(addr1, []TokenID{tid1}, []uint64{10}) - dummy.mintBatch(addr2, []TokenID{tid2}, []uint64{20}) - - balanceBatch, err = dummy.BalanceOfBatch([]std.Address{addr1, addr2}, []TokenID{tid1, tid2}) - if err != nil { - t.Errorf("should not result in error") - } - - if balanceBatch[0] != 10 { - t.Errorf("expected: (%d), got: (%d)", 10, balanceBatch[0]) - } - if balanceBatch[1] != 20 { - t.Errorf("expected: (%d), got: (%d)", 20, balanceBatch[1]) - } -} - -func TestIsApprovedForAll(t *testing.T) { - dummy := NewBasicGRC1155Token(dummyURI) - if dummy == nil { - t.Errorf("should not be nil") - } - - addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() - addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj").Resolve() - - isApprovedForAll := dummy.IsApprovedForAll(addr1, addr2) - if isApprovedForAll != false { - t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) - } -} - -func TestSetApprovalForAll(t *testing.T) { - dummy := NewBasicGRC1155Token(dummyURI) - if dummy == nil { - t.Errorf("should not be nil") - } - - caller := std.GetOrigCaller() - addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() - - isApprovedForAll := dummy.IsApprovedForAll(caller, addr) - if isApprovedForAll != false { - t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) - } - - err := dummy.SetApprovalForAll(addr, true) - if err != nil { - t.Errorf("should not result in error") - } - - isApprovedForAll = dummy.IsApprovedForAll(caller, addr) - if isApprovedForAll != true { - t.Errorf("expected: (%v), got: (%v)", true, isApprovedForAll) - } - - err = dummy.SetApprovalForAll(addr, false) - if err != nil { - t.Errorf("should not result in error") - } - - isApprovedForAll = dummy.IsApprovedForAll(caller, addr) - if isApprovedForAll != false { - t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) - } -} - -func TestSafeTransferFrom(t *testing.T) { - dummy := NewBasicGRC1155Token(dummyURI) - if dummy == nil { - t.Errorf("should not be nil") - } - - caller := std.GetOrigCaller() - addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() - - tid := TokenID("1") - - dummy.mintBatch(caller, []TokenID{tid}, []uint64{100}) - - err := dummy.SafeTransferFrom(caller, zeroAddress, tid, 10) - if err == nil { - t.Errorf("should result in error") - } - - err = dummy.SafeTransferFrom(caller, addr, tid, 160) - if err == nil { - t.Errorf("should result in error") - } - - err = dummy.SafeTransferFrom(caller, addr, tid, 60) - if err != nil { - t.Errorf("should not result in error") - } - - // Check balance of caller after transfer - balanceOfCaller, err := dummy.BalanceOf(caller, tid) - if err != nil { - t.Errorf("should not result in error") - } - if balanceOfCaller != 40 { - t.Errorf("expected: (%d), got: (%d)", 40, balanceOfCaller) - } - - // Check balance of addr after transfer - balanceOfAddr, err := dummy.BalanceOf(addr, tid) - if err != nil { - t.Errorf("should not result in error") - } - if balanceOfAddr != 60 { - t.Errorf("expected: (%d), got: (%d)", 60, balanceOfAddr) - } -} - -func TestSafeBatchTransferFrom(t *testing.T) { - dummy := NewBasicGRC1155Token(dummyURI) - if dummy == nil { - t.Errorf("should not be nil") - } - - caller := std.GetOrigCaller() - addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() - - tid1 := TokenID("1") - tid2 := TokenID("2") - - dummy.mintBatch(caller, []TokenID{tid1, tid2}, []uint64{10, 100}) - - err := dummy.SafeBatchTransferFrom(caller, zeroAddress, []TokenID{tid1, tid2}, []uint64{4, 60}) - if err == nil { - t.Errorf("should result in error") - } - err = dummy.SafeBatchTransferFrom(caller, addr, []TokenID{tid1, tid2}, []uint64{40, 60}) - if err == nil { - t.Errorf("should result in error") - } - err = dummy.SafeBatchTransferFrom(caller, addr, []TokenID{tid1}, []uint64{40, 60}) - if err == nil { - t.Errorf("should result in error") - } - err = dummy.SafeBatchTransferFrom(caller, addr, []TokenID{tid1, tid2}, []uint64{4, 60}) - if err != nil { - t.Errorf("should not result in error") - } - - balanceBatch, err := dummy.BalanceOfBatch([]std.Address{caller, addr, caller, addr}, []TokenID{tid1, tid1, tid2, tid2}) - if err != nil { - t.Errorf("should not result in error") - } - - // Check token1's balance of caller after batch transfer - if balanceBatch[0] != 6 { - t.Errorf("expected: (%d), got: (%d)", 6, balanceBatch[0]) - } - - // Check token1's balance of addr after batch transfer - if balanceBatch[1] != 4 { - t.Errorf("expected: (%d), got: (%d)", 4, balanceBatch[1]) - } - - // Check token2's balance of caller after batch transfer - if balanceBatch[2] != 40 { - t.Errorf("expected: (%d), got: (%d)", 40, balanceBatch[2]) - } - - // Check token2's balance of addr after batch transfer - if balanceBatch[3] != 60 { - t.Errorf("expected: (%d), got: (%d)", 60, balanceBatch[3]) - } -} - -func TestSafeMint(t *testing.T) { - dummy := NewBasicGRC1155Token(dummyURI) - if dummy == nil { - t.Errorf("should not be nil") - } - - addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() - addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj").Resolve() - - tid1 := TokenID("1") - tid2 := TokenID("2") - - err := dummy.SafeMint(zeroAddress, tid1, 100) - if err == nil { - t.Errorf("should result in error") - } - err = dummy.SafeMint(addr1, tid1, 100) - if err != nil { - t.Errorf("should not result in error") - } - err = dummy.SafeMint(addr1, tid2, 200) - if err != nil { - t.Errorf("should not result in error") - } - err = dummy.SafeMint(addr2, tid1, 50) - if err != nil { - t.Errorf("should not result in error") - } - - balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr1, addr2, addr1}, []TokenID{tid1, tid1, tid2}) - if err != nil { - t.Errorf("should not result in error") - } - // Check token1's balance of addr1 after mint - if balanceBatch[0] != 100 { - t.Errorf("expected: (%d), got: (%d)", 100, balanceBatch[0]) - } - // Check token1's balance of addr2 after mint - if balanceBatch[1] != 50 { - t.Errorf("expected: (%d), got: (%d)", 50, balanceBatch[1]) - } - // Check token2's balance of addr1 after mint - if balanceBatch[2] != 200 { - t.Errorf("expected: (%d), got: (%d)", 200, balanceBatch[2]) - } -} - -func TestSafeBatchMint(t *testing.T) { - dummy := NewBasicGRC1155Token(dummyURI) - if dummy == nil { - t.Errorf("should not be nil") - } - - addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() - addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj").Resolve() - - tid1 := TokenID("1") - tid2 := TokenID("2") - - err := dummy.SafeBatchMint(zeroAddress, []TokenID{tid1, tid2}, []uint64{100, 200}) - if err == nil { - t.Errorf("should result in error") - } - err = dummy.SafeBatchMint(addr1, []TokenID{tid1, tid2}, []uint64{100, 200}) - if err != nil { - t.Errorf("should not result in error") - } - err = dummy.SafeBatchMint(addr2, []TokenID{tid1, tid2}, []uint64{300, 400}) - if err != nil { - t.Errorf("should not result in error") - } - - balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr1, addr2, addr1, addr2}, []TokenID{tid1, tid1, tid2, tid2}) - if err != nil { - t.Errorf("should not result in error") - } - // Check token1's balance of addr1 after batch mint - if balanceBatch[0] != 100 { - t.Errorf("expected: (%d), got: (%d)", 100, balanceBatch[0]) - } - // Check token1's balance of addr2 after batch mint - if balanceBatch[1] != 300 { - t.Errorf("expected: (%d), got: (%d)", 300, balanceBatch[1]) - } - // Check token2's balance of addr1 after batch mint - if balanceBatch[2] != 200 { - t.Errorf("expected: (%d), got: (%d)", 200, balanceBatch[2]) - } - // Check token2's balance of addr2 after batch mint - if balanceBatch[3] != 400 { - t.Errorf("expected: (%d), got: (%d)", 400, balanceBatch[3]) - } -} - -func TestBurn(t *testing.T) { - dummy := NewBasicGRC1155Token(dummyURI) - if dummy == nil { - t.Errorf("should not be nil") - } - - addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() - - tid1 := TokenID("1") - tid2 := TokenID("2") - - dummy.mintBatch(addr, []TokenID{tid1, tid2}, []uint64{100, 200}) - err := dummy.Burn(zeroAddress, tid1, 60) - if err == nil { - t.Errorf("should result in error") - } - err = dummy.Burn(addr, tid1, 160) - if err == nil { - t.Errorf("should result in error") - } - err = dummy.Burn(addr, tid1, 60) - if err != nil { - t.Errorf("should not result in error") - } - err = dummy.Burn(addr, tid2, 60) - if err != nil { - t.Errorf("should not result in error") - } - balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr, addr}, []TokenID{tid1, tid2}) - if err != nil { - t.Errorf("should not result in error") - } - - // Check token1's balance of addr after burn - if balanceBatch[0] != 40 { - t.Errorf("expected: (%d), got: (%d)", 40, balanceBatch[0]) - } - // Check token2's balance of addr after burn - if balanceBatch[1] != 140 { - t.Errorf("expected: (%d), got: (%d)", 140, balanceBatch[1]) - } -} - -func TestBatchBurn(t *testing.T) { - dummy := NewBasicGRC1155Token(dummyURI) - if dummy == nil { - t.Errorf("should not be nil") - } - - addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() - - tid1 := TokenID("1") - tid2 := TokenID("2") - - dummy.mintBatch(addr, []TokenID{tid1, tid2}, []uint64{100, 200}) - err := dummy.BatchBurn(zeroAddress, []TokenID{tid1, tid2}, []uint64{60, 60}) - if err == nil { - t.Errorf("should result in error") - } - err = dummy.BatchBurn(addr, []TokenID{tid1, tid2}, []uint64{160, 60}) - if err == nil { - t.Errorf("should result in error") - } - err = dummy.BatchBurn(addr, []TokenID{tid1, tid2}, []uint64{60, 60}) - if err != nil { - t.Errorf("should not result in error") - } - balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr, addr}, []TokenID{tid1, tid2}) - if err != nil { - t.Errorf("should not result in error") - } - - // Check token1's balance of addr after batch burn - if balanceBatch[0] != 40 { - t.Errorf("expected: (%d), got: (%d)", 40, balanceBatch[0]) - } - // Check token2's balance of addr after batch burn - if balanceBatch[1] != 140 { - t.Errorf("expected: (%d), got: (%d)", 140, balanceBatch[1]) - } -} +// import ( +// "fmt" +// "std" +// "testing" + +// "gno.land/p/demo/users" +// ) + +// const dummyURI = "ipfs://xyz" + +// func TestNewBasicGRC1155Token(t *testing.T) { +// dummy := NewBasicGRC1155Token(dummyURI) +// if dummy == nil { +// return t.Errorf("should not be nil") +// } +// } + +// func TestUri(t *testing.T) { +// dummy := NewBasicGRC1155Token(dummyURI) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// uri := dummy.Uri() +// if uri != dummyURI { +// t.Errorf("expected: (%s), got: (%s)", dummyURI, uri) +// } +// } + +// func TestBalanceOf(t *testing.T) { +// dummy := NewBasicGRC1155Token(dummyURI) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() +// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj").Resolve() + +// tid1 := TokenID("1") +// tid2 := TokenID("2") + +// balanceZeroAddressOfToken1, err := dummy.BalanceOf(zeroAddress, tid1) +// if err == nil { +// t.Errorf("should result in error") +// } +// balanceAddr1OfToken1, err := dummy.BalanceOf(addr1, tid1) +// if err != nil { +// t.Errorf("should not result in error") +// } +// if balanceAddr1OfToken1 != 0 { +// t.Errorf("expected: (%d), got: (%d)", 0, balanceAddr1OfToken1) +// } + +// dummy.mintBatch(addr1, []TokenID{tid1, tid2}, []uint64{10, 100}) +// dummy.mintBatch(addr2, []TokenID{tid1}, []uint64{20}) + +// balanceAddr1OfToken1, err = dummy.BalanceOf(addr1, tid1) +// if err != nil { +// t.Errorf("should not result in error") +// } +// balanceAddr1OfToken2, err := dummy.BalanceOf(addr1, tid2) +// if err != nil { +// t.Errorf("should not result in error") +// } +// balanceAddr2OfToken1, err := dummy.BalanceOf(addr2, tid1) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// if balanceAddr1OfToken1 != 10 { +// t.Errorf("expected: (%d), got: (%d)", 10, balanceAddr1OfToken1) +// } +// if balanceAddr1OfToken2 != 100 { +// t.Errorf("expected: (%d), got: (%d)", 100, balanceAddr1OfToken2) +// } +// if balanceAddr2OfToken1 != 20 { +// t.Errorf("expected: (%d), got: (%d)", 20, balanceAddr2OfToken1) +// } +// } + +// func TestBalanceOfBatch(t *testing.T) { +// dummy := NewBasicGRC1155Token(dummyURI) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() +// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj").Resolve() + +// tid1 := TokenID("1") +// tid2 := TokenID("2") + +// balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr1, addr2}, []TokenID{tid1, tid2}) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// if balanceBatch[0] != 0 { +// t.Errorf("expected: (%d), got: (%d)", 0, balanceBatch[0]) +// } +// if balanceBatch[1] != 0 { +// t.Errorf("expected: (%d), got: (%d)", 0, balanceBatch[1]) +// } + +// dummy.mintBatch(addr1, []TokenID{tid1}, []uint64{10}) +// dummy.mintBatch(addr2, []TokenID{tid2}, []uint64{20}) + +// balanceBatch, err = dummy.BalanceOfBatch([]std.Address{addr1, addr2}, []TokenID{tid1, tid2}) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// if balanceBatch[0] != 10 { +// t.Errorf("expected: (%d), got: (%d)", 10, balanceBatch[0]) +// } +// if balanceBatch[1] != 20 { +// t.Errorf("expected: (%d), got: (%d)", 20, balanceBatch[1]) +// } +// } + +// func TestIsApprovedForAll(t *testing.T) { +// dummy := NewBasicGRC1155Token(dummyURI) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() +// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj").Resolve() + +// isApprovedForAll := dummy.IsApprovedForAll(addr1, addr2) +// if isApprovedForAll != false { +// t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) +// } +// } + +// func TestSetApprovalForAll(t *testing.T) { +// dummy := NewBasicGRC1155Token(dummyURI) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// caller := std.GetOrigCaller() +// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() + +// isApprovedForAll := dummy.IsApprovedForAll(caller, addr) +// if isApprovedForAll != false { +// t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) +// } + +// err := dummy.SetApprovalForAll(addr, true) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// isApprovedForAll = dummy.IsApprovedForAll(caller, addr) +// if isApprovedForAll != true { +// t.Errorf("expected: (%v), got: (%v)", true, isApprovedForAll) +// } + +// err = dummy.SetApprovalForAll(addr, false) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// isApprovedForAll = dummy.IsApprovedForAll(caller, addr) +// if isApprovedForAll != false { +// t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) +// } +// } + +// func TestSafeTransferFrom(t *testing.T) { +// dummy := NewBasicGRC1155Token(dummyURI) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// caller := std.GetOrigCaller() +// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() + +// tid := TokenID("1") + +// dummy.mintBatch(caller, []TokenID{tid}, []uint64{100}) + +// err := dummy.SafeTransferFrom(caller, zeroAddress, tid, 10) +// if err == nil { +// t.Errorf("should result in error") +// } + +// err = dummy.SafeTransferFrom(caller, addr, tid, 160) +// if err == nil { +// t.Errorf("should result in error") +// } + +// err = dummy.SafeTransferFrom(caller, addr, tid, 60) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// // Check balance of caller after transfer +// balanceOfCaller, err := dummy.BalanceOf(caller, tid) +// if err != nil { +// t.Errorf("should not result in error") +// } +// if balanceOfCaller != 40 { +// t.Errorf("expected: (%d), got: (%d)", 40, balanceOfCaller) +// } + +// // Check balance of addr after transfer +// balanceOfAddr, err := dummy.BalanceOf(addr, tid) +// if err != nil { +// t.Errorf("should not result in error") +// } +// if balanceOfAddr != 60 { +// t.Errorf("expected: (%d), got: (%d)", 60, balanceOfAddr) +// } +// } + +// func TestSafeBatchTransferFrom(t *testing.T) { +// dummy := NewBasicGRC1155Token(dummyURI) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// caller := std.GetOrigCaller() +// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() + +// tid1 := TokenID("1") +// tid2 := TokenID("2") + +// dummy.mintBatch(caller, []TokenID{tid1, tid2}, []uint64{10, 100}) + +// err := dummy.SafeBatchTransferFrom(caller, zeroAddress, []TokenID{tid1, tid2}, []uint64{4, 60}) +// if err == nil { +// t.Errorf("should result in error") +// } +// err = dummy.SafeBatchTransferFrom(caller, addr, []TokenID{tid1, tid2}, []uint64{40, 60}) +// if err == nil { +// t.Errorf("should result in error") +// } +// err = dummy.SafeBatchTransferFrom(caller, addr, []TokenID{tid1}, []uint64{40, 60}) +// if err == nil { +// t.Errorf("should result in error") +// } +// err = dummy.SafeBatchTransferFrom(caller, addr, []TokenID{tid1, tid2}, []uint64{4, 60}) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// balanceBatch, err := dummy.BalanceOfBatch([]std.Address{caller, addr, caller, addr}, []TokenID{tid1, tid1, tid2, tid2}) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// // Check token1's balance of caller after batch transfer +// if balanceBatch[0] != 6 { +// t.Errorf("expected: (%d), got: (%d)", 6, balanceBatch[0]) +// } + +// // Check token1's balance of addr after batch transfer +// if balanceBatch[1] != 4 { +// t.Errorf("expected: (%d), got: (%d)", 4, balanceBatch[1]) +// } + +// // Check token2's balance of caller after batch transfer +// if balanceBatch[2] != 40 { +// t.Errorf("expected: (%d), got: (%d)", 40, balanceBatch[2]) +// } + +// // Check token2's balance of addr after batch transfer +// if balanceBatch[3] != 60 { +// t.Errorf("expected: (%d), got: (%d)", 60, balanceBatch[3]) +// } +// } + +// func TestSafeMint(t *testing.T) { +// dummy := NewBasicGRC1155Token(dummyURI) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() +// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj").Resolve() + +// tid1 := TokenID("1") +// tid2 := TokenID("2") + +// err := dummy.SafeMint(zeroAddress, tid1, 100) +// if err == nil { +// t.Errorf("should result in error") +// } +// err = dummy.SafeMint(addr1, tid1, 100) +// if err != nil { +// t.Errorf("should not result in error") +// } +// err = dummy.SafeMint(addr1, tid2, 200) +// if err != nil { +// t.Errorf("should not result in error") +// } +// err = dummy.SafeMint(addr2, tid1, 50) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr1, addr2, addr1}, []TokenID{tid1, tid1, tid2}) +// if err != nil { +// t.Errorf("should not result in error") +// } +// // Check token1's balance of addr1 after mint +// if balanceBatch[0] != 100 { +// t.Errorf("expected: (%d), got: (%d)", 100, balanceBatch[0]) +// } +// // Check token1's balance of addr2 after mint +// if balanceBatch[1] != 50 { +// t.Errorf("expected: (%d), got: (%d)", 50, balanceBatch[1]) +// } +// // Check token2's balance of addr1 after mint +// if balanceBatch[2] != 200 { +// t.Errorf("expected: (%d), got: (%d)", 200, balanceBatch[2]) +// } +// } + +// func TestSafeBatchMint(t *testing.T) { +// dummy := NewBasicGRC1155Token(dummyURI) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() +// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj").Resolve() + +// tid1 := TokenID("1") +// tid2 := TokenID("2") + +// err := dummy.SafeBatchMint(zeroAddress, []TokenID{tid1, tid2}, []uint64{100, 200}) +// if err == nil { +// t.Errorf("should result in error") +// } +// err = dummy.SafeBatchMint(addr1, []TokenID{tid1, tid2}, []uint64{100, 200}) +// if err != nil { +// t.Errorf("should not result in error") +// } +// err = dummy.SafeBatchMint(addr2, []TokenID{tid1, tid2}, []uint64{300, 400}) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr1, addr2, addr1, addr2}, []TokenID{tid1, tid1, tid2, tid2}) +// if err != nil { +// t.Errorf("should not result in error") +// } +// // Check token1's balance of addr1 after batch mint +// if balanceBatch[0] != 100 { +// t.Errorf("expected: (%d), got: (%d)", 100, balanceBatch[0]) +// } +// // Check token1's balance of addr2 after batch mint +// if balanceBatch[1] != 300 { +// t.Errorf("expected: (%d), got: (%d)", 300, balanceBatch[1]) +// } +// // Check token2's balance of addr1 after batch mint +// if balanceBatch[2] != 200 { +// t.Errorf("expected: (%d), got: (%d)", 200, balanceBatch[2]) +// } +// // Check token2's balance of addr2 after batch mint +// if balanceBatch[3] != 400 { +// t.Errorf("expected: (%d), got: (%d)", 400, balanceBatch[3]) +// } +// } + +// func TestBurn(t *testing.T) { +// dummy := NewBasicGRC1155Token(dummyURI) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() + +// tid1 := TokenID("1") +// tid2 := TokenID("2") + +// dummy.mintBatch(addr, []TokenID{tid1, tid2}, []uint64{100, 200}) +// err := dummy.Burn(zeroAddress, tid1, 60) +// if err == nil { +// t.Errorf("should result in error") +// } +// err = dummy.Burn(addr, tid1, 160) +// if err == nil { +// t.Errorf("should result in error") +// } +// err = dummy.Burn(addr, tid1, 60) +// if err != nil { +// t.Errorf("should not result in error") +// } +// err = dummy.Burn(addr, tid2, 60) +// if err != nil { +// t.Errorf("should not result in error") +// } +// balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr, addr}, []TokenID{tid1, tid2}) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// // Check token1's balance of addr after burn +// if balanceBatch[0] != 40 { +// t.Errorf("expected: (%d), got: (%d)", 40, balanceBatch[0]) +// } +// // Check token2's balance of addr after burn +// if balanceBatch[1] != 140 { +// t.Errorf("expected: (%d), got: (%d)", 140, balanceBatch[1]) +// } +// } + +// func TestBatchBurn(t *testing.T) { +// dummy := NewBasicGRC1155Token(dummyURI) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() + +// tid1 := TokenID("1") +// tid2 := TokenID("2") + +// dummy.mintBatch(addr, []TokenID{tid1, tid2}, []uint64{100, 200}) +// err := dummy.BatchBurn(zeroAddress, []TokenID{tid1, tid2}, []uint64{60, 60}) +// if err == nil { +// t.Errorf("should result in error") +// } +// err = dummy.BatchBurn(addr, []TokenID{tid1, tid2}, []uint64{160, 60}) +// if err == nil { +// t.Errorf("should result in error") +// } +// err = dummy.BatchBurn(addr, []TokenID{tid1, tid2}, []uint64{60, 60}) +// if err != nil { +// t.Errorf("should not result in error") +// } +// balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr, addr}, []TokenID{tid1, tid2}) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// // Check token1's balance of addr after batch burn +// if balanceBatch[0] != 40 { +// t.Errorf("expected: (%d), got: (%d)", 40, balanceBatch[0]) +// } +// // Check token2's balance of addr after batch burn +// if balanceBatch[1] != 140 { +// t.Errorf("expected: (%d), got: (%d)", 140, balanceBatch[1]) +// } +// } diff --git a/examples/gno.land/p/demo/grc/grc1155/gno.mod b/examples/gno.land/p/demo/grc/grc1155/gno.mod index 0b2b85d8e86..8f3f36019f9 100644 --- a/examples/gno.land/p/demo/grc/grc1155/gno.mod +++ b/examples/gno.land/p/demo/grc/grc1155/gno.mod @@ -3,5 +3,4 @@ module gno.land/p/demo/grc/grc1155 require ( gno.land/p/demo/avl v0.0.0-latest gno.land/p/demo/ufmt v0.0.0-latest - gno.land/r/demo/users v0.0.0-latest ) diff --git a/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno b/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno index 925f1fca44b..50c4ee07aa0 100644 --- a/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno +++ b/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno @@ -1,414 +1,414 @@ package grc721 -import ( - "std" - "testing" - - "gno.land/p/demo/testutils" - "gno.land/r/demo/users" -) - -var ( - dummyNFTName = "DummyNFT" - dummyNFTSymbol = "DNFT" -) - -func TestNewBasicNFT(t *testing.T) { - dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) - if dummy == nil { - t.Errorf("should not be nil") - } -} - -func TestName(t *testing.T) { - dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) - if dummy == nil { - t.Errorf("should not be nil") - } - name := dummy.Name() - if name != dummyNFTName { - t.Errorf("expected: (%s), got: (%s)", dummyNFTName, name) - } -} - -func TestSymbol(t *testing.T) { - dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) - if dummy == nil { - t.Errorf("should not be nil") - } - symbol := dummy.Symbol() - if symbol != dummyNFTSymbol { - t.Errorf("expected: (%s), got: (%s)", dummyNFTSymbol, symbol) - } -} - -func TestTokenCount(t *testing.T) { - dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) - if dummy == nil { - t.Errorf("should not be nil") - } - - count := dummy.TokenCount() - if count != 0 { - t.Errorf("expected: (%d), got: (%d)", 0, count) - } - - dummy.mint("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm", TokenID("1")) - dummy.mint("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm", TokenID("2")) - - count = dummy.TokenCount() - if count != 2 { - t.Errorf("expected: (%d), got: (%d)", 2, count) - } -} - -func TestBalanceOf(t *testing.T) { - dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) - if dummy == nil { - t.Errorf("should not be nil") - } - - addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") - addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") - - balanceAddr1, err := dummy.BalanceOf(addr1.Resolve()) - if err != nil { - t.Errorf("should not result in error") - } - if balanceAddr1 != 0 { - t.Errorf("expected: (%d), got: (%d)", 0, balanceAddr1) - } - - dummy.mint(addr1.Resolve(), TokenID("1")) - dummy.mint(addr1.Resolve(), TokenID("2")) - dummy.mint(addr2.Resolve(), TokenID("3")) - - balanceAddr1, err = dummy.BalanceOf(addr1.Resolve()) - if err != nil { - t.Errorf("should not result in error") - } - balanceAddr2, err := dummy.BalanceOf(addr2.Resolve()) - if err != nil { - t.Errorf("should not result in error") - } - - if balanceAddr1 != 2 { - t.Errorf("expected: (%d), got: (%d)", 2, balanceAddr1) - } - if balanceAddr2 != 1 { - t.Errorf("expected: (%d), got: (%d)", 1, balanceAddr2) - } -} - -func TestOwnerOf(t *testing.T) { - dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) - if dummy == nil { - t.Errorf("should not be nil") - } - - addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") - addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") - - owner, err := dummy.OwnerOf(TokenID("invalid")) - if err == nil { - t.Errorf("should result in error") - } - - dummy.mint(addr1.Resolve(), TokenID("1")) - dummy.mint(addr2.Resolve(), TokenID("2")) - - // Checking for token id "1" - owner, err = dummy.OwnerOf(TokenID("1")) - if err != nil { - t.Errorf("should not result in error") - } - if owner != addr1.Resolve() { - t.Errorf("expected: (%s), got: (%s)", addr1.Resolve().String(), owner.String()) - } - - // Checking for token id "2" - owner, err = dummy.OwnerOf(TokenID("2")) - if err != nil { - t.Errorf("should not result in error") - } - if owner != addr2.Resolve() { - t.Errorf("expected: (%s), got: (%s)", addr2.Resolve().String(), owner.String()) - } -} - -func TestIsApprovedForAll(t *testing.T) { - dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) - if dummy == nil { - t.Errorf("should not be nil") - } - - addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") - addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") - - isApprovedForAll := dummy.IsApprovedForAll(addr1.Resolve(), addr2.Resolve()) - if isApprovedForAll != false { - t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) - } -} - -func TestSetApprovalForAll(t *testing.T) { - dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) - if dummy == nil { - t.Errorf("should not be nil") - } - - caller := std.PrevRealm().Addr() - addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") - - isApprovedForAll := dummy.IsApprovedForAll(caller, addr.Resolve()) - if isApprovedForAll != false { - t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) - } - - err := dummy.SetApprovalForAll(addr.Resolve(), true) - if err != nil { - t.Errorf("should not result in error") - } - - isApprovedForAll = dummy.IsApprovedForAll(caller, addr.Resolve()) - if isApprovedForAll != true { - t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) - } -} - -func TestGetApproved(t *testing.T) { - dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) - if dummy == nil { - t.Errorf("should not be nil") - } - - approvedAddr, err := dummy.GetApproved(TokenID("invalid")) - if err == nil { - t.Errorf("should result in error") - } -} - -func TestApprove(t *testing.T) { - dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) - if dummy == nil { - t.Errorf("should not be nil") - } - - caller := std.PrevRealm().Addr() - addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") - - dummy.mint(caller, TokenID("1")) - - _, err := dummy.GetApproved(TokenID("1")) - if err == nil { - t.Errorf("should result in error") - } - - err = dummy.Approve(addr.Resolve(), TokenID("1")) - if err != nil { - t.Errorf("should not result in error") - } - - approvedAddr, err := dummy.GetApproved(TokenID("1")) - if err != nil { - t.Errorf("should not result in error") - } - if approvedAddr != addr.Resolve() { - t.Errorf("expected: (%s), got: (%s)", addr.Resolve().String(), approvedAddr.String()) - } -} - -func TestTransferFrom(t *testing.T) { - dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) - if dummy == nil { - t.Errorf("should not be nil") - } - - caller := std.PrevRealm().Addr() - addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") - - dummy.mint(caller, TokenID("1")) - dummy.mint(caller, TokenID("2")) - - err := dummy.TransferFrom(caller, addr.Resolve(), TokenID("1")) - if err != nil { - t.Errorf("should not result in error") - } - - // Check balance of caller after transfer - balanceOfCaller, err := dummy.BalanceOf(caller) - if err != nil { - t.Errorf("should not result in error") - } - if balanceOfCaller != 1 { - t.Errorf("expected: (%d), got: (%d)", 1, balanceOfCaller) - } - - // Check balance of addr after transfer - balanceOfAddr, err := dummy.BalanceOf(addr.Resolve()) - if err != nil { - t.Errorf("should not result in error") - } - if balanceOfAddr != 1 { - t.Errorf("expected: (%d), got: (%d)", 1, balanceOfAddr) - } - - // Check Owner of transferred Token id - owner, err := dummy.OwnerOf(TokenID("1")) - if err != nil { - t.Errorf("should not result in error") - } - if owner != addr.Resolve() { - t.Errorf("expected: (%s), got: (%s)", addr.Resolve().String(), owner.String()) - } -} - -func TestSafeTransferFrom(t *testing.T) { - dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) - if dummy == nil { - t.Errorf("should not be nil") - } - - caller := std.PrevRealm().Addr() - addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") - - dummy.mint(caller, TokenID("1")) - dummy.mint(caller, TokenID("2")) - - err := dummy.SafeTransferFrom(caller, addr.Resolve(), TokenID("1")) - if err != nil { - t.Errorf("should not result in error") - } - - // Check balance of caller after transfer - balanceOfCaller, err := dummy.BalanceOf(caller) - if err != nil { - t.Errorf("should not result in error") - } - if balanceOfCaller != 1 { - t.Errorf("expected: (%d), got: (%d)", 1, balanceOfCaller) - } - - // Check balance of addr after transfer - balanceOfAddr, err := dummy.BalanceOf(addr.Resolve()) - if err != nil { - t.Errorf("should not result in error") - } - if balanceOfAddr != 1 { - t.Errorf("expected: (%d), got: (%d)", 1, balanceOfAddr) - } - - // Check Owner of transferred Token id - owner, err := dummy.OwnerOf(TokenID("1")) - if err != nil { - t.Errorf("should not result in error") - } - if owner != addr.Resolve() { - t.Errorf("expected: (%s), got: (%s)", addr.Resolve().String(), owner.String()) - } -} - -func TestMint(t *testing.T) { - dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) - if dummy == nil { - t.Errorf("should not be nil") - } - - addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") - addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") - - err := dummy.Mint(addr1.Resolve(), TokenID("1")) - if err != nil { - t.Errorf("should not result in error") - } - err = dummy.Mint(addr1.Resolve(), TokenID("2")) - if err != nil { - t.Errorf("should not result in error") - } - err = dummy.Mint(addr2.Resolve(), TokenID("3")) - if err != nil { - t.Errorf("should not result in error") - } - - // Try minting duplicate token id - err = dummy.Mint(addr2.Resolve(), TokenID("1")) - if err == nil { - t.Errorf("should result in error") - } - - // Check Owner of Token id - owner, err := dummy.OwnerOf(TokenID("1")) - if err != nil { - t.Errorf("should not result in error") - } - if owner != addr1.Resolve() { - t.Errorf("expected: (%s), got: (%s)", addr1.Resolve().String(), owner.String()) - } -} - -func TestBurn(t *testing.T) { - dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) - if dummy == nil { - t.Errorf("should not be nil") - } - - addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") - - dummy.mint(addr.Resolve(), TokenID("1")) - dummy.mint(addr.Resolve(), TokenID("2")) - - err := dummy.Burn(TokenID("1")) - if err != nil { - t.Errorf("should not result in error") - } - - // Check Owner of Token id - owner, err := dummy.OwnerOf(TokenID("1")) - if err == nil { - t.Errorf("should result in error") - } -} - -func TestSetTokenURI(t *testing.T) { - dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) - if dummy == nil { - t.Errorf("should not be nil") - } - - addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") - addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") - tokenURI := "http://example.com/token" - - std.TestSetOrigCaller(std.Address(addr1)) // addr1 - - dummy.mint(addr1.Resolve(), TokenID("1")) - _, derr := dummy.SetTokenURI(TokenID("1"), TokenURI(tokenURI)) - - if derr != nil { - t.Errorf("Should not result in error ", derr.Error()) - } - - // Test case: Invalid token ID - _, err := dummy.SetTokenURI(TokenID("3"), TokenURI(tokenURI)) - if err != ErrInvalidTokenId { - t.Errorf("Expected error %v, got %v", ErrInvalidTokenId, err) - } - - std.TestSetOrigCaller(std.Address(addr2)) // addr2 - - _, cerr := dummy.SetTokenURI(TokenID("1"), TokenURI(tokenURI)) // addr2 trying to set URI for token 1 - if cerr != ErrCallerIsNotOwner { - t.Errorf("Expected error %v, got %v", ErrCallerIsNotOwner, err) - } - - // Test case: Retrieving TokenURI - std.TestSetOrigCaller(std.Address(addr1)) // addr1 - - dummyTokenURI, err := dummy.TokenURI(TokenID("1")) - if err != nil { - t.Errorf("TokenURI error: %v, ", err.Error()) - } - if dummyTokenURI != tokenURI { - t.Errorf("Expected URI %v, got %v", tokenURI, dummyTokenURI) - } -} +// import ( +// "std" +// "testing" +// +// "gno.land/p/demo/testutils" +// "gno.land/r/demo/users" +// ) + +// var ( +// dummyNFTName = "DummyNFT" +// dummyNFTSymbol = "DNFT" +// ) + +// func TestNewBasicNFT(t *testing.T) { +// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) +// if dummy == nil { +// t.Errorf("should not be nil") +// } +// } + +// func TestName(t *testing.T) { +// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) +// if dummy == nil { +// t.Errorf("should not be nil") +// } +// name := dummy.Name() +// if name != dummyNFTName { +// t.Errorf("expected: (%s), got: (%s)", dummyNFTName, name) +// } +// } + +// func TestSymbol(t *testing.T) { +// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) +// if dummy == nil { +// t.Errorf("should not be nil") +// } +// symbol := dummy.Symbol() +// if symbol != dummyNFTSymbol { +// t.Errorf("expected: (%s), got: (%s)", dummyNFTSymbol, symbol) +// } +// } + +// func TestTokenCount(t *testing.T) { +// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// count := dummy.TokenCount() +// if count != 0 { +// t.Errorf("expected: (%d), got: (%d)", 0, count) +// } + +// dummy.mint("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm", TokenID("1")) +// dummy.mint("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm", TokenID("2")) + +// count = dummy.TokenCount() +// if count != 2 { +// t.Errorf("expected: (%d), got: (%d)", 2, count) +// } +// } + +// func TestBalanceOf(t *testing.T) { +// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") +// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") + +// balanceAddr1, err := dummy.BalanceOf(users.Resolve(addr1)) +// if err != nil { +// t.Errorf("should not result in error") +// } +// if balanceAddr1 != 0 { +// t.Errorf("expected: (%d), got: (%d)", 0, balanceAddr1) +// } + +// dummy.mint(users.Resolve(addr1), TokenID("1")) +// dummy.mint(users.Resolve(addr1), TokenID("2")) +// dummy.mint(users.Resolve(addr2), TokenID("3")) + +// balanceAddr1, err = dummy.BalanceOf(users.Resolve(addr1)) +// if err != nil { +// t.Errorf("should not result in error") +// } +// balanceAddr2, err := dummy.BalanceOf(users.Resolve(addr2)) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// if balanceAddr1 != 2 { +// t.Errorf("expected: (%d), got: (%d)", 2, balanceAddr1) +// } +// if balanceAddr2 != 1 { +// t.Errorf("expected: (%d), got: (%d)", 1, balanceAddr2) +// } +// } + +// func TestOwnerOf(t *testing.T) { +// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") +// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") + +// owner, err := dummy.OwnerOf(TokenID("invalid")) +// if err == nil { +// t.Errorf("should result in error") +// } + +// dummy.mint(users.Resolve(addr1), TokenID("1")) +// dummy.mint(users.Resolve(addr2), TokenID("2")) + +// // Checking for token id "1" +// owner, err = dummy.OwnerOf(TokenID("1")) +// if err != nil { +// t.Errorf("should not result in error") +// } +// if owner != users.Resolve(addr1) { +// t.Errorf("expected: (%s), got: (%s)", users.Resolve(addr1).String(), owner.String()) +// } + +// // Checking for token id "2" +// owner, err = dummy.OwnerOf(TokenID("2")) +// if err != nil { +// t.Errorf("should not result in error") +// } +// if owner != users.Resolve(addr2) { +// t.Errorf("expected: (%s), got: (%s)", users.Resolve(addr2).String(), owner.String()) +// } +// } + +// func TestIsApprovedForAll(t *testing.T) { +// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") +// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") + +// isApprovedForAll := dummy.IsApprovedForAll(users.Resolve(addr1), users.Resolve(addr2)) +// if isApprovedForAll != false { +// t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) +// } +// } + +// func TestSetApprovalForAll(t *testing.T) { +// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// caller := std.PrevRealm().Addr() +// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") + +// isApprovedForAll := dummy.IsApprovedForAll(caller, users.Resolve(addr)) +// if isApprovedForAll != false { +// t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) +// } + +// err := dummy.SetApprovalForAll(users.Resolve(addr), true) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// isApprovedForAll = dummy.IsApprovedForAll(caller, users.Resolve(addr)) +// if isApprovedForAll != true { +// t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) +// } +// } + +// func TestGetApproved(t *testing.T) { +// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// approvedAddr, err := dummy.GetApproved(TokenID("invalid")) +// if err == nil { +// t.Errorf("should result in error") +// } +// } + +// func TestApprove(t *testing.T) { +// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// caller := std.PrevRealm().Addr() +// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") + +// dummy.mint(caller, TokenID("1")) + +// _, err := dummy.GetApproved(TokenID("1")) +// if err == nil { +// t.Errorf("should result in error") +// } + +// err = dummy.Approve(users.Resolve(addr), TokenID("1")) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// approvedAddr, err := dummy.GetApproved(TokenID("1")) +// if err != nil { +// t.Errorf("should not result in error") +// } +// if approvedAddr != users.Resolve(addr) { +// t.Errorf("expected: (%s), got: (%s)", users.Resolve(addr).String(), approvedAddr.String()) +// } +// } + +// func TestTransferFrom(t *testing.T) { +// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// caller := std.PrevRealm().Addr() +// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") + +// dummy.mint(caller, TokenID("1")) +// dummy.mint(caller, TokenID("2")) + +// err := dummy.TransferFrom(caller, users.Resolve(addr), TokenID("1")) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// // Check balance of caller after transfer +// balanceOfCaller, err := dummy.BalanceOf(caller) +// if err != nil { +// t.Errorf("should not result in error") +// } +// if balanceOfCaller != 1 { +// t.Errorf("expected: (%d), got: (%d)", 1, balanceOfCaller) +// } + +// // Check balance of addr after transfer +// balanceOfAddr, err := dummy.BalanceOf(users.Resolve(addr)) +// if err != nil { +// t.Errorf("should not result in error") +// } +// if balanceOfAddr != 1 { +// t.Errorf("expected: (%d), got: (%d)", 1, balanceOfAddr) +// } + +// // Check Owner of transferred Token id +// owner, err := dummy.OwnerOf(TokenID("1")) +// if err != nil { +// t.Errorf("should not result in error") +// } +// if owner != users.Resolve(addr) { +// t.Errorf("expected: (%s), got: (%s)", users.Resolve(addr).String(), owner.String()) +// } +// } + +// func TestSafeTransferFrom(t *testing.T) { +// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// caller := std.PrevRealm().Addr() +// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") + +// dummy.mint(caller, TokenID("1")) +// dummy.mint(caller, TokenID("2")) + +// err := dummy.SafeTransferFrom(caller, users.Resolve(addr), TokenID("1")) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// // Check balance of caller after transfer +// balanceOfCaller, err := dummy.BalanceOf(caller) +// if err != nil { +// t.Errorf("should not result in error") +// } +// if balanceOfCaller != 1 { +// t.Errorf("expected: (%d), got: (%d)", 1, balanceOfCaller) +// } + +// // Check balance of addr after transfer +// balanceOfAddr, err := dummy.BalanceOf(users.Resolve(addr)) +// if err != nil { +// t.Errorf("should not result in error") +// } +// if balanceOfAddr != 1 { +// t.Errorf("expected: (%d), got: (%d)", 1, balanceOfAddr) +// } + +// // Check Owner of transferred Token id +// owner, err := dummy.OwnerOf(TokenID("1")) +// if err != nil { +// t.Errorf("should not result in error") +// } +// if owner != users.Resolve(addr) { +// t.Errorf("expected: (%s), got: (%s)", users.Resolve(addr).String(), owner.String()) +// } +// } + +// func TestMint(t *testing.T) { +// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") +// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") + +// err := dummy.Mint(users.Resolve(addr1), TokenID("1")) +// if err != nil { +// t.Errorf("should not result in error") +// } +// err = dummy.Mint(users.Resolve(addr1), TokenID("2")) +// if err != nil { +// t.Errorf("should not result in error") +// } +// err = dummy.Mint(users.Resolve(addr2), TokenID("3")) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// // Try minting duplicate token id +// err = dummy.Mint(users.Resolve(addr2), TokenID("1")) +// if err == nil { +// t.Errorf("should result in error") +// } + +// // Check Owner of Token id +// owner, err := dummy.OwnerOf(TokenID("1")) +// if err != nil { +// t.Errorf("should not result in error") +// } +// if owner != users.Resolve(addr1) { +// t.Errorf("expected: (%s), got: (%s)", users.Resolve(addr1).String(), owner.String()) +// } +// } + +// func TestBurn(t *testing.T) { +// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") + +// dummy.mint(users.Resolve(addr), TokenID("1")) +// dummy.mint(users.Resolve(addr), TokenID("2")) + +// err := dummy.Burn(TokenID("1")) +// if err != nil { +// t.Errorf("should not result in error") +// } + +// // Check Owner of Token id +// owner, err := dummy.OwnerOf(TokenID("1")) +// if err == nil { +// t.Errorf("should result in error") +// } +// } + +// func TestSetTokenURI(t *testing.T) { +// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) +// if dummy == nil { +// t.Errorf("should not be nil") +// } + +// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") +// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") +// tokenURI := "http://example.com/token" + +// std.TestSetOrigCaller(std.Address(addr1)) // addr1 + +// dummy.mint(addr1.Resolve(), TokenID("1")) +// _, derr := dummy.SetTokenURI(TokenID("1"), TokenURI(tokenURI)) + +// if derr != nil { +// t.Errorf("Should not result in error ", derr.Error()) +// } + +// // Test case: Invalid token ID +// _, err := dummy.SetTokenURI(TokenID("3"), TokenURI(tokenURI)) +// if err != ErrInvalidTokenId { +// t.Errorf("Expected error %v, got %v", ErrInvalidTokenId, err) +// } + +// std.TestSetOrigCaller(std.Address(addr2)) // addr2 + +// _, cerr := dummy.SetTokenURI(TokenID("1"), TokenURI(tokenURI)) // addr2 trying to set URI for token 1 +// if cerr != ErrCallerIsNotOwner { +// t.Errorf("Expected error %v, got %v", ErrCallerIsNotOwner, err) +// } + +// // Test case: Retrieving TokenURI +// std.TestSetOrigCaller(std.Address(addr1)) // addr1 + +// dummyTokenURI, err := dummy.TokenURI(TokenID("1")) +// if err != nil { +// t.Errorf("TokenURI error: %v, ", err.Error()) +// } +// if dummyTokenURI != tokenURI { +// t.Errorf("Expected URI %v, got %v", tokenURI, dummyTokenURI) +// } +// } diff --git a/examples/gno.land/p/demo/grc/grc721/gno.mod b/examples/gno.land/p/demo/grc/grc721/gno.mod index 952e0cb8ee4..061ea2988c3 100644 --- a/examples/gno.land/p/demo/grc/grc721/gno.mod +++ b/examples/gno.land/p/demo/grc/grc721/gno.mod @@ -4,5 +4,4 @@ require ( gno.land/p/demo/avl v0.0.0-latest gno.land/p/demo/testutils v0.0.0-latest gno.land/p/demo/ufmt v0.0.0-latest - gno.land/r/demo/users v0.0.0-latest ) diff --git a/examples/gno.land/p/demo/microblog/gno.mod b/examples/gno.land/p/demo/microblog/gno.mod index 5964679efa6..fe33e1efee9 100644 --- a/examples/gno.land/p/demo/microblog/gno.mod +++ b/examples/gno.land/p/demo/microblog/gno.mod @@ -4,5 +4,5 @@ require ( gno.land/p/demo/avl v0.0.0-latest gno.land/p/demo/testutils v0.0.0-latest gno.land/p/demo/ufmt v0.0.0-latest - gno.land/r/demo/users v0.0.0-latest + gno.land/p/demo/users v0.0.0-latest ) diff --git a/examples/gno.land/p/demo/microblog/microblog.gno b/examples/gno.land/p/demo/microblog/microblog.gno index f12fc6b5ece..5723a8f7f83 100644 --- a/examples/gno.land/p/demo/microblog/microblog.gno +++ b/examples/gno.land/p/demo/microblog/microblog.gno @@ -9,7 +9,7 @@ import ( "gno.land/p/demo/avl" "gno.land/p/demo/ufmt" - "gno.land/r/demo/users" + "gno.land/p/demo/users" ) var ( @@ -48,47 +48,6 @@ func (m *Microblog) GetPages() []*Page { return pages } -func (m *Microblog) RenderHome() string { - output := ufmt.Sprintf("# %s\n\n", m.Title) - output += "# pages\n\n" - - for _, page := range m.GetPages() { - if u := users.GetUserByAddress(page.Author); u != nil { - output += ufmt.Sprintf("- [%s (%s)](%s%s)\n", u.Name(), page.Author.String(), m.Prefix, page.Author.String()) - } else { - output += ufmt.Sprintf("- [%s](%s%s)\n", page.Author.String(), m.Prefix, page.Author.String()) - } - } - - return output -} - -func (m *Microblog) RenderUser(user string) string { - silo, found := m.Pages.Get(user) - if !found { - return StatusNotFound - } - - return (silo.(*Page)).String() -} - -func (m *Microblog) Render(path string) string { - parts := strings.Split(path, "/") - - isHome := path == "" - isUser := len(parts) == 1 - - switch { - case isHome: - return m.RenderHome() - - case isUser: - return m.RenderUser(parts[0]) - } - - return StatusNotFound -} - func (m *Microblog) NewPost(text string) error { author := std.GetOrigCaller() _, found := m.Pages.Get(author.String()) @@ -131,22 +90,6 @@ func (a byLastPosted) Len() int { return len(a) } func (a byLastPosted) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a byLastPosted) Less(i, j int) bool { return a[i].LastPosted.After(a[j].LastPosted) } -func (p *Page) String() string { - o := "" - if u := users.GetUserByAddress(p.Author); u != nil { - o += ufmt.Sprintf("# [%s](/r/demo/users:%s)\n\n", u.Name(), u.Name()) - o += ufmt.Sprintf("%s\n\n", u.Profile()) - } - o += ufmt.Sprintf("## [%s](/r/demo/microblog:%s)\n\n", p.Author, p.Author) - - o += ufmt.Sprintf("joined %s, last updated %s\n\n", p.CreatedAt.Format("2006-02-01"), p.LastPosted.Format("2006-02-01")) - o += "## feed\n\n" - for _, u := range p.GetPosts() { - o += u.String() + "\n\n" - } - return o -} - func (p *Page) NewPost(text string) error { now := time.Now() p.LastPosted = now diff --git a/examples/gno.land/p/demo/users/gno.mod b/examples/gno.land/p/demo/users/gno.mod new file mode 100644 index 00000000000..ad652803fb8 --- /dev/null +++ b/examples/gno.land/p/demo/users/gno.mod @@ -0,0 +1 @@ +module gno.land/p/demo/users diff --git a/examples/gno.land/r/demo/users/types.gno b/examples/gno.land/p/demo/users/types.gno similarity index 56% rename from examples/gno.land/r/demo/users/types.gno rename to examples/gno.land/p/demo/users/types.gno index b5fd6a8f6bf..0e4af4bd6ff 100644 --- a/examples/gno.land/r/demo/users/types.gno +++ b/examples/gno.land/p/demo/users/types.gno @@ -14,13 +14,3 @@ func (aon AddressOrName) GetName() (string, bool) { } return "", false } - -func (aon AddressOrName) Resolve() std.Address { - name, isName := aon.GetName() - if isName { - user := GetUserByName(name) - return user.address - } else { - return std.Address(aon) // TODO check validity - } -} diff --git a/examples/gno.land/p/demo/users/users.gno b/examples/gno.land/p/demo/users/users.gno new file mode 100644 index 00000000000..204eaf19918 --- /dev/null +++ b/examples/gno.land/p/demo/users/users.gno @@ -0,0 +1,31 @@ +package users + +import ( + "std" + "strconv" +) + +//---------------------------------------- +// Types + +type User struct { + Address std.Address + Name string + Profile string + Number int + Invites int + Inviter std.Address +} + +func (u *User) Render() string { + str := "## user " + u.Name + "\n" + + "\n" + + " * address = " + string(u.Address) + "\n" + + " * " + strconv.Itoa(u.Invites) + " invites\n" + if u.Inviter != "" { + str = str + " * invited by " + string(u.Inviter) + "\n" + } + str = str + "\n" + + u.Profile + "\n" + return str +} diff --git a/examples/gno.land/p/demo/users/users_test.gno b/examples/gno.land/p/demo/users/users_test.gno new file mode 100644 index 00000000000..82abcb9fccb --- /dev/null +++ b/examples/gno.land/p/demo/users/users_test.gno @@ -0,0 +1 @@ +package users diff --git a/examples/gno.land/r/demo/boards/misc.gno b/examples/gno.land/r/demo/boards/misc.gno index ccb6af0b6a9..ca036eb4680 100644 --- a/examples/gno.land/r/demo/boards/misc.gno +++ b/examples/gno.land/r/demo/boards/misc.gno @@ -84,13 +84,13 @@ func displayAddressMD(addr std.Address) string { } else { return "[@" + user.Name() + "](/r/demo/users:" + user.Name() + ")" } + return "[@" + user.Name + "](/r/users:" + user.Name + ")" } func usernameOf(addr std.Address) string { user := users.GetUserByAddress(addr) if user == nil { return "" - } else { - return user.Name() } + return user.Name } diff --git a/examples/gno.land/r/demo/foo1155/foo1155.gno b/examples/gno.land/r/demo/foo1155/foo1155.gno index c3fbf389434..2bd3b7a84c0 100644 --- a/examples/gno.land/r/demo/foo1155/foo1155.gno +++ b/examples/gno.land/r/demo/foo1155/foo1155.gno @@ -6,6 +6,8 @@ import ( "gno.land/p/demo/grc/grc1155" "gno.land/p/demo/ufmt" "gno.land/r/demo/users" + + pusers "gno.land/p/demo/users" ) var ( @@ -27,8 +29,8 @@ func mintGRC1155Token(owner std.Address) { // Getters -func BalanceOf(user users.AddressOrName, tid grc1155.TokenID) uint64 { - balance, err := foo.BalanceOf(user.Resolve(), tid) +func BalanceOf(user pusers.AddressOrName, tid grc1155.TokenID) uint64 { + balance, err := foo.BalanceOf(users.Resolve(user), tid) if err != nil { panic(err) } @@ -36,11 +38,11 @@ func BalanceOf(user users.AddressOrName, tid grc1155.TokenID) uint64 { return balance } -func BalanceOfBatch(users []users.AddressOrName, batch []grc1155.TokenID) []uint64 { +func BalanceOfBatch(ul []pusers.AddressOrName, batch []grc1155.TokenID) []uint64 { var usersResolved []std.Address - for i := 0; i < len(users); i++ { - usersResolved[i] = users[i].Resolve() + for i := 0; i < len(ul); i++ { + usersResolved[i] = users.Resolve(ul[i]) } balanceBatch, err := foo.BalanceOfBatch(usersResolved, batch) if err != nil { @@ -50,28 +52,28 @@ func BalanceOfBatch(users []users.AddressOrName, batch []grc1155.TokenID) []uint return balanceBatch } -func IsApprovedForAll(owner, user users.AddressOrName) bool { - return foo.IsApprovedForAll(owner.Resolve(), user.Resolve()) +func IsApprovedForAll(owner, user pusers.AddressOrName) bool { + return foo.IsApprovedForAll(users.Resolve(owner), users.Resolve(user)) } // Setters -func SetApprovalForAll(user users.AddressOrName, approved bool) { - err := foo.SetApprovalForAll(user.Resolve(), approved) +func SetApprovalForAll(user pusers.AddressOrName, approved bool) { + err := foo.SetApprovalForAll(users.Resolve(user), approved) if err != nil { panic(err) } } -func TransferFrom(from, to users.AddressOrName, tid grc1155.TokenID, amount uint64) { - err := foo.SafeTransferFrom(from.Resolve(), to.Resolve(), tid, amount) +func TransferFrom(from, to pusers.AddressOrName, tid grc1155.TokenID, amount uint64) { + err := foo.SafeTransferFrom(users.Resolve(from), users.Resolve(to), tid, amount) if err != nil { panic(err) } } -func BatchTransferFrom(from, to users.AddressOrName, batch []grc1155.TokenID, amounts []uint64) { - err := foo.SafeBatchTransferFrom(from.Resolve(), to.Resolve(), batch, amounts) +func BatchTransferFrom(from, to pusers.AddressOrName, batch []grc1155.TokenID, amounts []uint64) { + err := foo.SafeBatchTransferFrom(users.Resolve(from), users.Resolve(to), batch, amounts) if err != nil { panic(err) } @@ -79,37 +81,37 @@ func BatchTransferFrom(from, to users.AddressOrName, batch []grc1155.TokenID, am // Admin -func Mint(to users.AddressOrName, tid grc1155.TokenID, amount uint64) { +func Mint(to pusers.AddressOrName, tid grc1155.TokenID, amount uint64) { caller := std.GetOrigCaller() assertIsAdmin(caller) - err := foo.SafeMint(to.Resolve(), tid, amount) + err := foo.SafeMint(users.Resolve(to), tid, amount) if err != nil { panic(err) } } -func MintBatch(to users.AddressOrName, batch []grc1155.TokenID, amounts []uint64) { +func MintBatch(to pusers.AddressOrName, batch []grc1155.TokenID, amounts []uint64) { caller := std.GetOrigCaller() assertIsAdmin(caller) - err := foo.SafeBatchMint(to.Resolve(), batch, amounts) + err := foo.SafeBatchMint(users.Resolve(to), batch, amounts) if err != nil { panic(err) } } -func Burn(from users.AddressOrName, tid grc1155.TokenID, amount uint64) { +func Burn(from pusers.AddressOrName, tid grc1155.TokenID, amount uint64) { caller := std.GetOrigCaller() assertIsAdmin(caller) - err := foo.Burn(from.Resolve(), tid, amount) + err := foo.Burn(users.Resolve(from), tid, amount) if err != nil { panic(err) } } -func BurnBatch(from users.AddressOrName, batch []grc1155.TokenID, amounts []uint64) { +func BurnBatch(from pusers.AddressOrName, batch []grc1155.TokenID, amounts []uint64) { caller := std.GetOrigCaller() assertIsAdmin(caller) - err := foo.BatchBurn(from.Resolve(), batch, amounts) + err := foo.BatchBurn(users.Resolve(from), batch, amounts) if err != nil { panic(err) } diff --git a/examples/gno.land/r/demo/foo1155/gno.mod b/examples/gno.land/r/demo/foo1155/gno.mod index 6fdf18a1658..0a405c5b4a2 100644 --- a/examples/gno.land/r/demo/foo1155/gno.mod +++ b/examples/gno.land/r/demo/foo1155/gno.mod @@ -3,5 +3,6 @@ module gno.land/r/demo/foo1155 require ( gno.land/p/demo/grc/grc1155 v0.0.0-latest gno.land/p/demo/ufmt v0.0.0-latest + gno.land/p/demo/users v0.0.0-latest gno.land/r/demo/users v0.0.0-latest ) diff --git a/examples/gno.land/r/demo/foo20/foo20.gno b/examples/gno.land/r/demo/foo20/foo20.gno index 39ab9260d3a..162454800e8 100644 --- a/examples/gno.land/r/demo/foo20/foo20.gno +++ b/examples/gno.land/r/demo/foo20/foo20.gno @@ -7,6 +7,8 @@ import ( "gno.land/p/demo/grc/grc20" "gno.land/p/demo/ufmt" "gno.land/r/demo/users" + + pusers "gno.land/p/demo/users" ) var ( @@ -29,16 +31,16 @@ func TotalSupply() uint64 { return foo.TotalSupply() } -func BalanceOf(owner users.AddressOrName) uint64 { - balance, err := foo.BalanceOf(owner.Resolve()) +func BalanceOf(owner pusers.AddressOrName) uint64 { + balance, err := foo.BalanceOf(users.Resolve(owner)) if err != nil { panic(err) } return balance } -func Allowance(owner, spender users.AddressOrName) uint64 { - allowance, err := foo.Allowance(owner.Resolve(), spender.Resolve()) +func Allowance(owner, spender pusers.AddressOrName) uint64 { + allowance, err := foo.Allowance(users.Resolve(owner), users.Resolve(spender)) if err != nil { panic(err) } @@ -47,25 +49,25 @@ func Allowance(owner, spender users.AddressOrName) uint64 { // setters. -func Transfer(to users.AddressOrName, amount uint64) { +func Transfer(to pusers.AddressOrName, amount uint64) { caller := std.PrevRealm().Addr() - err := foo.Transfer(caller, to.Resolve(), amount) + err := foo.Transfer(caller, users.Resolve(to), amount) if err != nil { panic(err) } } -func Approve(spender users.AddressOrName, amount uint64) { +func Approve(spender pusers.AddressOrName, amount uint64) { caller := std.PrevRealm().Addr() - err := foo.Approve(caller, spender.Resolve(), amount) + err := foo.Approve(caller, users.Resolve(spender), amount) if err != nil { panic(err) } } -func TransferFrom(from, to users.AddressOrName, amount uint64) { +func TransferFrom(from, to pusers.AddressOrName, amount uint64) { caller := std.PrevRealm().Addr() - err := foo.TransferFrom(caller, from.Resolve(), to.Resolve(), amount) + err := foo.TransferFrom(caller, users.Resolve(from), users.Resolve(to), amount) if err != nil { panic(err) } @@ -85,19 +87,19 @@ func Faucet() { // administration. -func Mint(address users.AddressOrName, amount uint64) { +func Mint(address pusers.AddressOrName, amount uint64) { caller := std.PrevRealm().Addr() assertIsAdmin(caller) - err := foo.Mint(address.Resolve(), amount) + err := foo.Mint(users.Resolve(address), amount) if err != nil { panic(err) } } -func Burn(address users.AddressOrName, amount uint64) { +func Burn(address pusers.AddressOrName, amount uint64) { caller := std.PrevRealm().Addr() assertIsAdmin(caller) - err := foo.Burn(address.Resolve(), amount) + err := foo.Burn(users.Resolve(address), amount) if err != nil { panic(err) } @@ -114,8 +116,8 @@ func Render(path string) string { case path == "": return foo.RenderHome() case c == 2 && parts[0] == "balance": - owner := users.AddressOrName(parts[1]) - balance, _ := foo.BalanceOf(owner.Resolve()) + owner := pusers.AddressOrName(parts[1]) + balance, _ := foo.BalanceOf(users.Resolve(owner)) return ufmt.Sprintf("%d\n", balance) default: return "404\n" diff --git a/examples/gno.land/r/demo/foo20/gno.mod b/examples/gno.land/r/demo/foo20/gno.mod index 516690ee66c..96fefcf6163 100644 --- a/examples/gno.land/r/demo/foo20/gno.mod +++ b/examples/gno.land/r/demo/foo20/gno.mod @@ -3,5 +3,6 @@ module gno.land/r/demo/foo20 require ( gno.land/p/demo/grc/grc20 v0.0.0-latest gno.land/p/demo/ufmt v0.0.0-latest + gno.land/p/demo/users v0.0.0-latest gno.land/r/demo/users v0.0.0-latest ) diff --git a/examples/gno.land/r/demo/foo721/foo721.gno b/examples/gno.land/r/demo/foo721/foo721.gno index 45dcd5b4ef3..f7364d4185f 100644 --- a/examples/gno.land/r/demo/foo721/foo721.gno +++ b/examples/gno.land/r/demo/foo721/foo721.gno @@ -6,6 +6,8 @@ import ( "gno.land/p/demo/grc/grc721" "gno.land/p/demo/ufmt" "gno.land/r/demo/users" + + pusers "gno.land/p/demo/users" ) var ( @@ -28,8 +30,8 @@ func mintNNFT(owner std.Address, n uint64) { // Getters -func BalanceOf(user users.AddressOrName) uint64 { - balance, err := foo.BalanceOf(user.Resolve()) +func BalanceOf(user pusers.AddressOrName) uint64 { + balance, err := foo.BalanceOf(users.Resolve(user)) if err != nil { panic(err) } @@ -46,8 +48,8 @@ func OwnerOf(tid grc721.TokenID) std.Address { return owner } -func IsApprovedForAll(owner, user users.AddressOrName) bool { - return foo.IsApprovedForAll(owner.Resolve(), user.Resolve()) +func IsApprovedForAll(owner, user pusers.AddressOrName) bool { + return foo.IsApprovedForAll(users.Resolve(owner), users.Resolve(user)) } func GetApproved(tid grc721.TokenID) std.Address { @@ -61,22 +63,22 @@ func GetApproved(tid grc721.TokenID) std.Address { // Setters -func Approve(user users.AddressOrName, tid grc721.TokenID) { - err := foo.Approve(user.Resolve(), tid) +func Approve(user pusers.AddressOrName, tid grc721.TokenID) { + err := foo.Approve(users.Resolve(user), tid) if err != nil { panic(err) } } -func SetApprovalForAll(user users.AddressOrName, approved bool) { - err := foo.SetApprovalForAll(user.Resolve(), approved) +func SetApprovalForAll(user pusers.AddressOrName, approved bool) { + err := foo.SetApprovalForAll(users.Resolve(user), approved) if err != nil { panic(err) } } -func TransferFrom(from, to users.AddressOrName, tid grc721.TokenID) { - err := foo.TransferFrom(from.Resolve(), to.Resolve(), tid) +func TransferFrom(from, to pusers.AddressOrName, tid grc721.TokenID) { + err := foo.TransferFrom(users.Resolve(from), users.Resolve(to), tid) if err != nil { panic(err) } @@ -84,10 +86,10 @@ func TransferFrom(from, to users.AddressOrName, tid grc721.TokenID) { // Admin -func Mint(to users.AddressOrName, tid grc721.TokenID) { +func Mint(to pusers.AddressOrName, tid grc721.TokenID) { caller := std.PrevRealm().Addr() assertIsAdmin(caller) - err := foo.Mint(to.Resolve(), tid) + err := foo.Mint(users.Resolve(to), tid) if err != nil { panic(err) } diff --git a/examples/gno.land/r/demo/foo721/foo721_test.gno b/examples/gno.land/r/demo/foo721/foo721_test.gno index 8fb5c6d4f94..c43d6677120 100644 --- a/examples/gno.land/r/demo/foo721/foo721_test.gno +++ b/examples/gno.land/r/demo/foo721/foo721_test.gno @@ -18,7 +18,7 @@ func TestFoo721(t *testing.T) { }{ {"BalanceOf(admin)", 10, func() interface{} { return BalanceOf(admin) }}, {"BalanceOf(hariom)", 5, func() interface{} { return BalanceOf(hariom) }}, - {"OwnerOf(0)", admin.Resolve(), func() interface{} { return OwnerOf(grc721.TokenID("0")) }}, + {"OwnerOf(0)", users.Resolve(admin), func() interface{} { return OwnerOf(grc721.TokenID("0")) }}, {"IsApprovedForAll(admin, hariom)", false, func() interface{} { return IsApprovedForAll(admin, hariom) }}, } { t.Run(tc.name, func(t *testing.T) { diff --git a/examples/gno.land/r/demo/foo721/gno.mod b/examples/gno.land/r/demo/foo721/gno.mod index 46c19e6ae55..e013677379d 100644 --- a/examples/gno.land/r/demo/foo721/gno.mod +++ b/examples/gno.land/r/demo/foo721/gno.mod @@ -3,5 +3,6 @@ module gno.land/r/demo/foo721 require ( gno.land/p/demo/grc/grc721 v0.0.0-latest gno.land/p/demo/ufmt v0.0.0-latest + gno.land/p/demo/users v0.0.0-latest gno.land/r/demo/users v0.0.0-latest ) diff --git a/examples/gno.land/r/demo/groups/misc.gno b/examples/gno.land/r/demo/groups/misc.gno index 07543ba4a45..2d578627632 100644 --- a/examples/gno.land/r/demo/groups/misc.gno +++ b/examples/gno.land/r/demo/groups/misc.gno @@ -80,7 +80,7 @@ func displayAddressMD(addr std.Address) string { if user == nil { return "[" + addr.String() + "](/r/users:" + addr.String() + ")" } - return "[@" + user.Name() + "](/r/users:" + user.Name() + ")" + return "[@" + user.Name + "](/r/users:" + user.Name + ")" } func usernameOf(addr std.Address) string { @@ -88,7 +88,7 @@ func usernameOf(addr std.Address) string { if user == nil { panic("user not found") } - return user.Name() + return user.Name } func isValidPermission(perm Permission) bool { diff --git a/examples/gno.land/r/demo/microblog/gno.mod b/examples/gno.land/r/demo/microblog/gno.mod index f496b1008ce..b1f121e6efc 100644 --- a/examples/gno.land/r/demo/microblog/gno.mod +++ b/examples/gno.land/r/demo/microblog/gno.mod @@ -2,5 +2,6 @@ module gno.land/r/demo/microblog require ( gno.land/p/demo/microblog v0.0.0-latest + gno.land/p/demo/ufmt v0.0.0-latest gno.land/r/demo/users v0.0.0-latest ) diff --git a/examples/gno.land/r/demo/microblog/microblog.gno b/examples/gno.land/r/demo/microblog/microblog.gno index f399b3be5d9..1c3cd5e7d68 100644 --- a/examples/gno.land/r/demo/microblog/microblog.gno +++ b/examples/gno.land/r/demo/microblog/microblog.gno @@ -7,8 +7,10 @@ package microblog import ( "std" + "strings" "gno.land/p/demo/microblog" + "gno.land/p/demo/ufmt" "gno.land/r/demo/users" ) @@ -22,9 +24,61 @@ func init() { m = microblog.NewMicroblog(title, prefix) } -// Render calls the microblog renderer +func renderHome() string { + output := ufmt.Sprintf("# %s\n\n", m.Title) + output += "# pages\n\n" + + for _, page := range m.GetPages() { + if u := users.GetUserByAddress(page.Author); u != nil { + output += ufmt.Sprintf("- [%s (%s)](%s%s)\n", u.Name, page.Author.String(), m.Prefix, page.Author.String()) + } else { + output += ufmt.Sprintf("- [%s](%s%s)\n", page.Author.String(), m.Prefix, page.Author.String()) + } + } + + return output +} + +func renderUser(user string) string { + silo, found := m.Pages.Get(user) + if !found { + return "404" // StatusNotFound + } + + return PageToString((silo.(*microblog.Page))) +} + func Render(path string) string { - return m.Render(path) + parts := strings.Split(path, "/") + + isHome := path == "" + isUser := len(parts) == 1 + + switch { + case isHome: + return renderHome() + + case isUser: + return renderUser(parts[0]) + } + + return "404" // StatusNotFound +} + +func PageToString(p *microblog.Page) string { + o := "" + if u := users.GetUserByAddress(p.Author); u != nil { + o += ufmt.Sprintf("# [%s](/r/demo/users:%s)\n\n", u, u) + o += ufmt.Sprintf("%s\n\n", u.Profile) + } + o += ufmt.Sprintf("## [%s](/r/demo/microblog:%s)\n\n", p.Author, p.Author) + + o += ufmt.Sprintf("joined %s, last updated %s\n\n", p.CreatedAt.Format("2006-02-01"), p.LastPosted.Format("2006-02-01")) + o += "## feed\n\n" + for _, u := range p.GetPosts() { + o += u.String() + "\n\n" + } + return o } // NewPost takes a single argument (post markdown) and diff --git a/examples/gno.land/r/demo/users/gno.mod b/examples/gno.land/r/demo/users/gno.mod index edd20eb2721..a2ee2ea86ba 100644 --- a/examples/gno.land/r/demo/users/gno.mod +++ b/examples/gno.land/r/demo/users/gno.mod @@ -1,3 +1,6 @@ module gno.land/r/demo/users -require gno.land/p/demo/avl v0.0.0-latest +require ( + gno.land/p/demo/avl v0.0.0-latest + gno.land/p/demo/users v0.0.0-latest +) diff --git a/examples/gno.land/r/demo/users/users.gno b/examples/gno.land/r/demo/users/users.gno index 5f492f1662f..4fe486a71d0 100644 --- a/examples/gno.land/r/demo/users/users.gno +++ b/examples/gno.land/r/demo/users/users.gno @@ -7,44 +7,16 @@ import ( "strings" "gno.land/p/demo/avl" + "gno.land/p/demo/users" ) -//---------------------------------------- -// Types - -type User struct { - address std.Address - name string - profile string - number int - invites int - inviter std.Address -} - -func (u *User) Render() string { - str := "## user " + u.name + "\n" + - "\n" + - " * address = " + string(u.address) + "\n" + - " * " + strconv.Itoa(u.invites) + " invites\n" - if u.inviter != "" { - str = str + " * invited by " + string(u.inviter) + "\n" - } - str = str + "\n" + - u.profile + "\n" - return str -} - -func (u User) Name() string { return u.name } -func (u User) Profile() string { return u.profile } -func (u User) Address() std.Address { return u.address } - //---------------------------------------- // State var ( admin std.Address = "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj" - name2User avl.Tree // Name -> *User - addr2User avl.Tree // std.Address -> *User + name2User avl.Tree // Name -> *users.User + addr2User avl.Tree // std.Address -> *users.User invites avl.Tree // string(inviter+":"+invited) -> true counter int // user id counter minFee int64 = 200 * 1000000 // minimum gnot must be paid to register. @@ -108,13 +80,13 @@ func Register(inviter std.Address, name string, profile string) { } // register. counter++ - user := &User{ - address: caller, - name: name, - profile: profile, - number: counter, - invites: invites, - inviter: inviter, + user := &users.User{ + Address: caller, + Name: name, + Profile: profile, + Number: counter, + Invites: invites, + Inviter: inviter, } name2User.Set(name, user) addr2User.Set(caller.String(), user) @@ -137,12 +109,12 @@ func Invite(invitee string) { if !ok { panic("user unknown") } - user := userI.(*User) - if user.invites <= 0 { + user := userI.(*users.User) + if user.Invites <= 0 { panic("user has no invite tokens") } - user.invites -= len(lines) - if user.invites < 0 { + user.Invites -= len(lines) + if user.Invites < 0 { panic("user has insufficient invite tokens") } } @@ -204,8 +176,8 @@ func GrantInvites(invites string) { panic("invalid user " + name) } } - user := userI.(*User) - user.invites += invites + user := userI.(*users.User) + user.Invites += invites } } @@ -238,24 +210,24 @@ func SetMaxFeeMultiple(newMaxFeeMult int64) { //---------------------------------------- // Exposed public functions -func GetUserByName(name string) *User { +func GetUserByName(name string) *users.User { userI, ok := name2User.Get(name) if !ok { return nil } - return userI.(*User) + return userI.(*users.User) } -func GetUserByAddress(addr std.Address) *User { +func GetUserByAddress(addr std.Address) *users.User { userI, ok := addr2User.Get(addr.String()) if !ok { return nil } - return userI.(*User) + return userI.(*users.User) } // unlike GetUserByName, input must be "@" prefixed for names. -func GetUserByAddressOrName(input AddressOrName) *User { +func GetUserByAddressOrName(input users.AddressOrName) *users.User { name, isName := input.GetName() if isName { return GetUserByName(name) @@ -263,6 +235,15 @@ func GetUserByAddressOrName(input AddressOrName) *User { return GetUserByAddress(std.Address(input)) } +func Resolve(input users.AddressOrName) std.Address { + name, isName := input.GetName() + if !isName { + return std.Address(input) // TODO check validity + } + user := GetUserByName(name) + return user.Address +} + //---------------------------------------- // Constants @@ -297,8 +278,8 @@ func Render(path string) string { func renderHome() string { doc := "" name2User.Iterate("", "", func(key string, value interface{}) bool { - user := value.(*User) - doc += " * [" + user.name + "](/r/demo/users:" + user.name + ")\n" + user := value.(*users.User) + doc += " * [" + user.Name + "](/r/demo/users:" + user.Name + ")\n" return false }) return doc From 793aa893dfbe8951ef9ef946f8fcaf9a5ba6c041 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Mon, 15 Jan 2024 04:27:06 +0530 Subject: [PATCH 2/9] chore: fixups --- examples/gno.land/p/demo/grc/grc721/gno.mod | 1 - examples/gno.land/p/demo/microblog/gno.mod | 2 -- .../gno.land/p/demo/microblog/microblog.gno | 1 - examples/gno.land/p/demo/users/types.gno | 2 -- examples/gno.land/r/demo/boards/misc.gno | 3 +- .../gno.land/r/demo/boards/z_4_filetest.gno | 7 ----- .../gno.land/r/demo/foo1155/foo1155_test.gno | 2 +- examples/gno.land/r/demo/foo20/foo20_test.gno | 2 +- .../gno.land/r/demo/foo721/foo721_test.gno | 6 ++-- examples/gno.land/r/demo/microblog/gno.mod | 2 ++ .../demo/microblog/microblog_test.gno | 30 +++++++++---------- 11 files changed, 23 insertions(+), 35 deletions(-) rename examples/gno.land/{p => r}/demo/microblog/microblog_test.gno (52%) diff --git a/examples/gno.land/p/demo/grc/grc721/gno.mod b/examples/gno.land/p/demo/grc/grc721/gno.mod index 061ea2988c3..48a5f4e04b6 100644 --- a/examples/gno.land/p/demo/grc/grc721/gno.mod +++ b/examples/gno.land/p/demo/grc/grc721/gno.mod @@ -2,6 +2,5 @@ module gno.land/p/demo/grc/grc721 require ( gno.land/p/demo/avl v0.0.0-latest - gno.land/p/demo/testutils v0.0.0-latest gno.land/p/demo/ufmt v0.0.0-latest ) diff --git a/examples/gno.land/p/demo/microblog/gno.mod b/examples/gno.land/p/demo/microblog/gno.mod index fe33e1efee9..9bbcfa19e31 100644 --- a/examples/gno.land/p/demo/microblog/gno.mod +++ b/examples/gno.land/p/demo/microblog/gno.mod @@ -2,7 +2,5 @@ module gno.land/p/demo/microblog require ( gno.land/p/demo/avl v0.0.0-latest - gno.land/p/demo/testutils v0.0.0-latest gno.land/p/demo/ufmt v0.0.0-latest - gno.land/p/demo/users v0.0.0-latest ) diff --git a/examples/gno.land/p/demo/microblog/microblog.gno b/examples/gno.land/p/demo/microblog/microblog.gno index 5723a8f7f83..f6d6709f20b 100644 --- a/examples/gno.land/p/demo/microblog/microblog.gno +++ b/examples/gno.land/p/demo/microblog/microblog.gno @@ -9,7 +9,6 @@ import ( "gno.land/p/demo/avl" "gno.land/p/demo/ufmt" - "gno.land/p/demo/users" ) var ( diff --git a/examples/gno.land/p/demo/users/types.gno b/examples/gno.land/p/demo/users/types.gno index 0e4af4bd6ff..d28b6a8ee42 100644 --- a/examples/gno.land/p/demo/users/types.gno +++ b/examples/gno.land/p/demo/users/types.gno @@ -1,7 +1,5 @@ package users -import "std" - type AddressOrName string func (aon AddressOrName) IsName() bool { diff --git a/examples/gno.land/r/demo/boards/misc.gno b/examples/gno.land/r/demo/boards/misc.gno index ca036eb4680..bc561ca7d22 100644 --- a/examples/gno.land/r/demo/boards/misc.gno +++ b/examples/gno.land/r/demo/boards/misc.gno @@ -82,9 +82,8 @@ func displayAddressMD(addr std.Address) string { if user == nil { return "[" + addr.String() + "](/r/demo/users:" + addr.String() + ")" } else { - return "[@" + user.Name() + "](/r/demo/users:" + user.Name() + ")" + return "[@" + user.Name + "](/r/demo/users:" + user.Name + ")" } - return "[@" + user.Name + "](/r/users:" + user.Name + ")" } func usernameOf(addr std.Address) string { diff --git a/examples/gno.land/r/demo/boards/z_4_filetest.gno b/examples/gno.land/r/demo/boards/z_4_filetest.gno index 1ae0ac250a4..d408e06b2b1 100644 --- a/examples/gno.land/r/demo/boards/z_4_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_4_filetest.gno @@ -47,7 +47,6 @@ func main() { // Realm: // switchrealm["gno.land/r/demo/users"] -// switchrealm["gno.land/r/demo/users"] // switchrealm["gno.land/r/demo/boards"] // u[f6dbf411da22e67d74cd7ddba6a76cd7e14a4822:101]={ // "Fields": [ @@ -962,11 +961,5 @@ func main() { // switchrealm["gno.land/r/demo/users"] // switchrealm["gno.land/r/demo/users"] // switchrealm["gno.land/r/demo/users"] -// switchrealm["gno.land/r/demo/users"] -// switchrealm["gno.land/r/demo/users"] -// switchrealm["gno.land/r/demo/users"] -// switchrealm["gno.land/r/demo/users"] -// switchrealm["gno.land/r/demo/users"] -// switchrealm["gno.land/r/demo/users"] // switchrealm["gno.land/r/demo/boards"] // switchrealm["gno.land/r/boards_test"] diff --git a/examples/gno.land/r/demo/foo1155/foo1155_test.gno b/examples/gno.land/r/demo/foo1155/foo1155_test.gno index 30663ab2c95..edd17d708fb 100644 --- a/examples/gno.land/r/demo/foo1155/foo1155_test.gno +++ b/examples/gno.land/r/demo/foo1155/foo1155_test.gno @@ -4,7 +4,7 @@ import ( "testing" "gno.land/p/demo/grc/grc1155" - "gno.land/r/demo/users" + "gno.land/p/demo/users" ) func TestFoo721(t *testing.T) { diff --git a/examples/gno.land/r/demo/foo20/foo20_test.gno b/examples/gno.land/r/demo/foo20/foo20_test.gno index 74c7648c2e5..9db0d5f7a6e 100644 --- a/examples/gno.land/r/demo/foo20/foo20_test.gno +++ b/examples/gno.land/r/demo/foo20/foo20_test.gno @@ -4,7 +4,7 @@ import ( "std" "testing" - "gno.land/r/demo/users" + "gno.land/p/demo/users" ) func TestReadOnlyPublicMethods(t *testing.T) { diff --git a/examples/gno.land/r/demo/foo721/foo721_test.gno b/examples/gno.land/r/demo/foo721/foo721_test.gno index c43d6677120..93a7e33f71d 100644 --- a/examples/gno.land/r/demo/foo721/foo721_test.gno +++ b/examples/gno.land/r/demo/foo721/foo721_test.gno @@ -5,11 +5,13 @@ import ( "gno.land/p/demo/grc/grc721" "gno.land/r/demo/users" + + pusers "gno.land/p/demo/users" ) func TestFoo721(t *testing.T) { - admin := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") - hariom := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") + admin := pusers.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") + hariom := pusers.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") for i, tc := range []struct { name string diff --git a/examples/gno.land/r/demo/microblog/gno.mod b/examples/gno.land/r/demo/microblog/gno.mod index b1f121e6efc..3285127b025 100644 --- a/examples/gno.land/r/demo/microblog/gno.mod +++ b/examples/gno.land/r/demo/microblog/gno.mod @@ -1,7 +1,9 @@ module gno.land/r/demo/microblog require ( + gno.land/p/demo/avl v0.0.0-latest gno.land/p/demo/microblog v0.0.0-latest + gno.land/p/demo/testutils v0.0.0-latest gno.land/p/demo/ufmt v0.0.0-latest gno.land/r/demo/users v0.0.0-latest ) diff --git a/examples/gno.land/p/demo/microblog/microblog_test.gno b/examples/gno.land/r/demo/microblog/microblog_test.gno similarity index 52% rename from examples/gno.land/p/demo/microblog/microblog_test.gno rename to examples/gno.land/r/demo/microblog/microblog_test.gno index 6d20b55e5cb..83b20286fee 100644 --- a/examples/gno.land/p/demo/microblog/microblog_test.gno +++ b/examples/gno.land/r/demo/microblog/microblog_test.gno @@ -7,60 +7,58 @@ import ( "testing" "gno.land/p/demo/avl" + "gno.land/p/demo/microblog" "gno.land/p/demo/testutils" ) func TestMicroblog(t *testing.T) { const ( - title string = "test microblog" - prefix string = "/r/test" author1 std.Address = testutils.TestAddress("author1") author2 std.Address = testutils.TestAddress("author2") ) std.TestSetOrigCaller(author1) - d := NewMicroblog(title, prefix) - if d.Render("/wrongpath") != "404" { + if Render("/wrongpath") != "404" { t.Fatalf("rendering not giving 404") } - if d.Render("") == "404" { + if Render("") == "404" { t.Fatalf("rendering / should not give 404") } - if err := d.NewPost("goodbyte, web2"); err != nil { + if err := m.NewPost("goodbyte, web2"); err != nil { t.Fatalf("could not create post") } - if _, err := d.GetPage(author1.String()); err != nil { + if _, err := m.GetPage(author1.String()); err != nil { t.Fatalf("silo should exist") } - if _, err := d.GetPage("no such author"); err == nil { + if _, err := m.GetPage("no such author"); err == nil { t.Fatalf("silo should not exist") } std.TestSetOrigCaller(author2) - if err := d.NewPost("hello, web3"); err != nil { + if err := m.NewPost("hello, web3"); err != nil { t.Fatalf("could not create post") } - if err := d.NewPost("hello again, web3"); err != nil { + if err := m.NewPost("hello again, web3"); err != nil { t.Fatalf("could not create post") } - if err := d.NewPost("hi again,\n web4?"); err != nil { + if err := m.NewPost("hi again,\n web4?"); err != nil { t.Fatalf("could not create post") } println("--- MICROBLOG ---\n\n") - if rendering := d.Render(""); rendering != `# test microblog + if rendering := Render(""); rendering != `# gno-based microblog # pages -- [g1v96hg6r0wgc47h6lta047h6lta047h6lm33tq6](/r/testg1v96hg6r0wgc47h6lta047h6lta047h6lm33tq6) -- [g1v96hg6r0wge97h6lta047h6lta047h6lyz7c00](/r/testg1v96hg6r0wge97h6lta047h6lta047h6lyz7c00) +- [g1v96hg6r0wgc47h6lta047h6lta047h6lm33tq6](/r/demo/microblog:g1v96hg6r0wgc47h6lta047h6lta047h6lm33tq6) +- [g1v96hg6r0wge97h6lta047h6lta047h6lyz7c00](/r/demo/microblog:g1v96hg6r0wge97h6lta047h6lta047h6lyz7c00) ` { t.Fatalf("incorrect rendering /: '%s'", rendering) } - if rendering := strings.TrimSpace(d.Render(author1.String())); rendering != `## [g1v96hg6r0wgc47h6lta047h6lta047h6lm33tq6](/r/demo/microblog:g1v96hg6r0wgc47h6lta047h6lta047h6lm33tq6) + if rendering := strings.TrimSpace(Render(author1.String())); rendering != `## [g1v96hg6r0wgc47h6lta047h6lta047h6lm33tq6](/r/demo/microblog:g1v96hg6r0wgc47h6lta047h6lta047h6lm33tq6) joined 2009-13-02, last updated 2009-13-02 @@ -72,7 +70,7 @@ joined 2009-13-02, last updated 2009-13-02 t.Fatalf("incorrect rendering /: '%s'", rendering) } - if rendering := strings.TrimSpace(d.Render(author2.String())); rendering != `## [g1v96hg6r0wge97h6lta047h6lta047h6lyz7c00](/r/demo/microblog:g1v96hg6r0wge97h6lta047h6lta047h6lyz7c00) + if rendering := strings.TrimSpace(Render(author2.String())); rendering != `## [g1v96hg6r0wge97h6lta047h6lta047h6lyz7c00](/r/demo/microblog:g1v96hg6r0wge97h6lta047h6lta047h6lyz7c00) joined 2009-13-02, last updated 2009-13-02 From d8da934843af4100a132ae82961741e098a6f2db Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Mon, 15 Jan 2024 04:50:52 +0530 Subject: [PATCH 3/9] fix failing `gno.land/test` --- gno.land/pkg/gnoweb/gnoweb_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gno.land/pkg/gnoweb/gnoweb_test.go b/gno.land/pkg/gnoweb/gnoweb_test.go index 61f7244141e..92b770e2aef 100644 --- a/gno.land/pkg/gnoweb/gnoweb_test.go +++ b/gno.land/pkg/gnoweb/gnoweb_test.go @@ -32,7 +32,7 @@ func TestRoutes(t *testing.T) { {"/r/gnoland/blog/admin.gno", ok, "func "}, {"/r/demo/users:administrator", ok, "address"}, {"/r/demo/users", ok, "manfred"}, - {"/r/demo/users/types.gno", ok, "type "}, + {"/r/demo/users/users.gno", ok, "// State"}, {"/r/demo/deep/very/deep", ok, "it works!"}, {"/r/demo/deep/very/deep:bob", ok, "hi bob"}, {"/r/demo/deep/very/deep?help", ok, "exposed"}, From 337ede8f630f19f71e96138dea8591e0f18c44e0 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Mon, 15 Jan 2024 19:02:49 +0530 Subject: [PATCH 4/9] Fix tests --- .../grc/grc1155/basic_grc1155_token_test.gno | 900 +++++++++--------- .../p/demo/grc/grc721/basic_nft_test.gno | 826 ++++++++-------- 2 files changed, 865 insertions(+), 861 deletions(-) diff --git a/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno b/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno index 8a2c7e6bc0a..49af126dc92 100644 --- a/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno +++ b/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno @@ -1,451 +1,453 @@ package grc1155 -// import ( -// "fmt" -// "std" -// "testing" - -// "gno.land/p/demo/users" -// ) - -// const dummyURI = "ipfs://xyz" - -// func TestNewBasicGRC1155Token(t *testing.T) { -// dummy := NewBasicGRC1155Token(dummyURI) -// if dummy == nil { -// return t.Errorf("should not be nil") -// } -// } - -// func TestUri(t *testing.T) { -// dummy := NewBasicGRC1155Token(dummyURI) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// uri := dummy.Uri() -// if uri != dummyURI { -// t.Errorf("expected: (%s), got: (%s)", dummyURI, uri) -// } -// } - -// func TestBalanceOf(t *testing.T) { -// dummy := NewBasicGRC1155Token(dummyURI) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() -// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj").Resolve() - -// tid1 := TokenID("1") -// tid2 := TokenID("2") - -// balanceZeroAddressOfToken1, err := dummy.BalanceOf(zeroAddress, tid1) -// if err == nil { -// t.Errorf("should result in error") -// } -// balanceAddr1OfToken1, err := dummy.BalanceOf(addr1, tid1) -// if err != nil { -// t.Errorf("should not result in error") -// } -// if balanceAddr1OfToken1 != 0 { -// t.Errorf("expected: (%d), got: (%d)", 0, balanceAddr1OfToken1) -// } - -// dummy.mintBatch(addr1, []TokenID{tid1, tid2}, []uint64{10, 100}) -// dummy.mintBatch(addr2, []TokenID{tid1}, []uint64{20}) - -// balanceAddr1OfToken1, err = dummy.BalanceOf(addr1, tid1) -// if err != nil { -// t.Errorf("should not result in error") -// } -// balanceAddr1OfToken2, err := dummy.BalanceOf(addr1, tid2) -// if err != nil { -// t.Errorf("should not result in error") -// } -// balanceAddr2OfToken1, err := dummy.BalanceOf(addr2, tid1) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// if balanceAddr1OfToken1 != 10 { -// t.Errorf("expected: (%d), got: (%d)", 10, balanceAddr1OfToken1) -// } -// if balanceAddr1OfToken2 != 100 { -// t.Errorf("expected: (%d), got: (%d)", 100, balanceAddr1OfToken2) -// } -// if balanceAddr2OfToken1 != 20 { -// t.Errorf("expected: (%d), got: (%d)", 20, balanceAddr2OfToken1) -// } -// } - -// func TestBalanceOfBatch(t *testing.T) { -// dummy := NewBasicGRC1155Token(dummyURI) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() -// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj").Resolve() - -// tid1 := TokenID("1") -// tid2 := TokenID("2") - -// balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr1, addr2}, []TokenID{tid1, tid2}) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// if balanceBatch[0] != 0 { -// t.Errorf("expected: (%d), got: (%d)", 0, balanceBatch[0]) -// } -// if balanceBatch[1] != 0 { -// t.Errorf("expected: (%d), got: (%d)", 0, balanceBatch[1]) -// } - -// dummy.mintBatch(addr1, []TokenID{tid1}, []uint64{10}) -// dummy.mintBatch(addr2, []TokenID{tid2}, []uint64{20}) - -// balanceBatch, err = dummy.BalanceOfBatch([]std.Address{addr1, addr2}, []TokenID{tid1, tid2}) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// if balanceBatch[0] != 10 { -// t.Errorf("expected: (%d), got: (%d)", 10, balanceBatch[0]) -// } -// if balanceBatch[1] != 20 { -// t.Errorf("expected: (%d), got: (%d)", 20, balanceBatch[1]) -// } -// } - -// func TestIsApprovedForAll(t *testing.T) { -// dummy := NewBasicGRC1155Token(dummyURI) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() -// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj").Resolve() - -// isApprovedForAll := dummy.IsApprovedForAll(addr1, addr2) -// if isApprovedForAll != false { -// t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) -// } -// } - -// func TestSetApprovalForAll(t *testing.T) { -// dummy := NewBasicGRC1155Token(dummyURI) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// caller := std.GetOrigCaller() -// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() - -// isApprovedForAll := dummy.IsApprovedForAll(caller, addr) -// if isApprovedForAll != false { -// t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) -// } - -// err := dummy.SetApprovalForAll(addr, true) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// isApprovedForAll = dummy.IsApprovedForAll(caller, addr) -// if isApprovedForAll != true { -// t.Errorf("expected: (%v), got: (%v)", true, isApprovedForAll) -// } - -// err = dummy.SetApprovalForAll(addr, false) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// isApprovedForAll = dummy.IsApprovedForAll(caller, addr) -// if isApprovedForAll != false { -// t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) -// } -// } - -// func TestSafeTransferFrom(t *testing.T) { -// dummy := NewBasicGRC1155Token(dummyURI) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// caller := std.GetOrigCaller() -// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() - -// tid := TokenID("1") - -// dummy.mintBatch(caller, []TokenID{tid}, []uint64{100}) - -// err := dummy.SafeTransferFrom(caller, zeroAddress, tid, 10) -// if err == nil { -// t.Errorf("should result in error") -// } - -// err = dummy.SafeTransferFrom(caller, addr, tid, 160) -// if err == nil { -// t.Errorf("should result in error") -// } - -// err = dummy.SafeTransferFrom(caller, addr, tid, 60) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// // Check balance of caller after transfer -// balanceOfCaller, err := dummy.BalanceOf(caller, tid) -// if err != nil { -// t.Errorf("should not result in error") -// } -// if balanceOfCaller != 40 { -// t.Errorf("expected: (%d), got: (%d)", 40, balanceOfCaller) -// } - -// // Check balance of addr after transfer -// balanceOfAddr, err := dummy.BalanceOf(addr, tid) -// if err != nil { -// t.Errorf("should not result in error") -// } -// if balanceOfAddr != 60 { -// t.Errorf("expected: (%d), got: (%d)", 60, balanceOfAddr) -// } -// } - -// func TestSafeBatchTransferFrom(t *testing.T) { -// dummy := NewBasicGRC1155Token(dummyURI) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// caller := std.GetOrigCaller() -// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() - -// tid1 := TokenID("1") -// tid2 := TokenID("2") - -// dummy.mintBatch(caller, []TokenID{tid1, tid2}, []uint64{10, 100}) - -// err := dummy.SafeBatchTransferFrom(caller, zeroAddress, []TokenID{tid1, tid2}, []uint64{4, 60}) -// if err == nil { -// t.Errorf("should result in error") -// } -// err = dummy.SafeBatchTransferFrom(caller, addr, []TokenID{tid1, tid2}, []uint64{40, 60}) -// if err == nil { -// t.Errorf("should result in error") -// } -// err = dummy.SafeBatchTransferFrom(caller, addr, []TokenID{tid1}, []uint64{40, 60}) -// if err == nil { -// t.Errorf("should result in error") -// } -// err = dummy.SafeBatchTransferFrom(caller, addr, []TokenID{tid1, tid2}, []uint64{4, 60}) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// balanceBatch, err := dummy.BalanceOfBatch([]std.Address{caller, addr, caller, addr}, []TokenID{tid1, tid1, tid2, tid2}) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// // Check token1's balance of caller after batch transfer -// if balanceBatch[0] != 6 { -// t.Errorf("expected: (%d), got: (%d)", 6, balanceBatch[0]) -// } - -// // Check token1's balance of addr after batch transfer -// if balanceBatch[1] != 4 { -// t.Errorf("expected: (%d), got: (%d)", 4, balanceBatch[1]) -// } - -// // Check token2's balance of caller after batch transfer -// if balanceBatch[2] != 40 { -// t.Errorf("expected: (%d), got: (%d)", 40, balanceBatch[2]) -// } - -// // Check token2's balance of addr after batch transfer -// if balanceBatch[3] != 60 { -// t.Errorf("expected: (%d), got: (%d)", 60, balanceBatch[3]) -// } -// } - -// func TestSafeMint(t *testing.T) { -// dummy := NewBasicGRC1155Token(dummyURI) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() -// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj").Resolve() - -// tid1 := TokenID("1") -// tid2 := TokenID("2") - -// err := dummy.SafeMint(zeroAddress, tid1, 100) -// if err == nil { -// t.Errorf("should result in error") -// } -// err = dummy.SafeMint(addr1, tid1, 100) -// if err != nil { -// t.Errorf("should not result in error") -// } -// err = dummy.SafeMint(addr1, tid2, 200) -// if err != nil { -// t.Errorf("should not result in error") -// } -// err = dummy.SafeMint(addr2, tid1, 50) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr1, addr2, addr1}, []TokenID{tid1, tid1, tid2}) -// if err != nil { -// t.Errorf("should not result in error") -// } -// // Check token1's balance of addr1 after mint -// if balanceBatch[0] != 100 { -// t.Errorf("expected: (%d), got: (%d)", 100, balanceBatch[0]) -// } -// // Check token1's balance of addr2 after mint -// if balanceBatch[1] != 50 { -// t.Errorf("expected: (%d), got: (%d)", 50, balanceBatch[1]) -// } -// // Check token2's balance of addr1 after mint -// if balanceBatch[2] != 200 { -// t.Errorf("expected: (%d), got: (%d)", 200, balanceBatch[2]) -// } -// } - -// func TestSafeBatchMint(t *testing.T) { -// dummy := NewBasicGRC1155Token(dummyURI) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() -// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj").Resolve() - -// tid1 := TokenID("1") -// tid2 := TokenID("2") - -// err := dummy.SafeBatchMint(zeroAddress, []TokenID{tid1, tid2}, []uint64{100, 200}) -// if err == nil { -// t.Errorf("should result in error") -// } -// err = dummy.SafeBatchMint(addr1, []TokenID{tid1, tid2}, []uint64{100, 200}) -// if err != nil { -// t.Errorf("should not result in error") -// } -// err = dummy.SafeBatchMint(addr2, []TokenID{tid1, tid2}, []uint64{300, 400}) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr1, addr2, addr1, addr2}, []TokenID{tid1, tid1, tid2, tid2}) -// if err != nil { -// t.Errorf("should not result in error") -// } -// // Check token1's balance of addr1 after batch mint -// if balanceBatch[0] != 100 { -// t.Errorf("expected: (%d), got: (%d)", 100, balanceBatch[0]) -// } -// // Check token1's balance of addr2 after batch mint -// if balanceBatch[1] != 300 { -// t.Errorf("expected: (%d), got: (%d)", 300, balanceBatch[1]) -// } -// // Check token2's balance of addr1 after batch mint -// if balanceBatch[2] != 200 { -// t.Errorf("expected: (%d), got: (%d)", 200, balanceBatch[2]) -// } -// // Check token2's balance of addr2 after batch mint -// if balanceBatch[3] != 400 { -// t.Errorf("expected: (%d), got: (%d)", 400, balanceBatch[3]) -// } -// } - -// func TestBurn(t *testing.T) { -// dummy := NewBasicGRC1155Token(dummyURI) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() - -// tid1 := TokenID("1") -// tid2 := TokenID("2") - -// dummy.mintBatch(addr, []TokenID{tid1, tid2}, []uint64{100, 200}) -// err := dummy.Burn(zeroAddress, tid1, 60) -// if err == nil { -// t.Errorf("should result in error") -// } -// err = dummy.Burn(addr, tid1, 160) -// if err == nil { -// t.Errorf("should result in error") -// } -// err = dummy.Burn(addr, tid1, 60) -// if err != nil { -// t.Errorf("should not result in error") -// } -// err = dummy.Burn(addr, tid2, 60) -// if err != nil { -// t.Errorf("should not result in error") -// } -// balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr, addr}, []TokenID{tid1, tid2}) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// // Check token1's balance of addr after burn -// if balanceBatch[0] != 40 { -// t.Errorf("expected: (%d), got: (%d)", 40, balanceBatch[0]) -// } -// // Check token2's balance of addr after burn -// if balanceBatch[1] != 140 { -// t.Errorf("expected: (%d), got: (%d)", 140, balanceBatch[1]) -// } -// } - -// func TestBatchBurn(t *testing.T) { -// dummy := NewBasicGRC1155Token(dummyURI) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm").Resolve() - -// tid1 := TokenID("1") -// tid2 := TokenID("2") - -// dummy.mintBatch(addr, []TokenID{tid1, tid2}, []uint64{100, 200}) -// err := dummy.BatchBurn(zeroAddress, []TokenID{tid1, tid2}, []uint64{60, 60}) -// if err == nil { -// t.Errorf("should result in error") -// } -// err = dummy.BatchBurn(addr, []TokenID{tid1, tid2}, []uint64{160, 60}) -// if err == nil { -// t.Errorf("should result in error") -// } -// err = dummy.BatchBurn(addr, []TokenID{tid1, tid2}, []uint64{60, 60}) -// if err != nil { -// t.Errorf("should not result in error") -// } -// balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr, addr}, []TokenID{tid1, tid2}) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// // Check token1's balance of addr after batch burn -// if balanceBatch[0] != 40 { -// t.Errorf("expected: (%d), got: (%d)", 40, balanceBatch[0]) -// } -// // Check token2's balance of addr after batch burn -// if balanceBatch[1] != 140 { -// t.Errorf("expected: (%d), got: (%d)", 140, balanceBatch[1]) -// } -// } +import ( + "fmt" + "std" + "testing" + + "gno.land/p/demo/users" + + rusers "gno.land/r/demo/users" // TODO(hariom): move this to realm? +) + +const dummyURI = "ipfs://xyz" + +func TestNewBasicGRC1155Token(t *testing.T) { + dummy := NewBasicGRC1155Token(dummyURI) + if dummy == nil { + return t.Errorf("should not be nil") + } +} + +func TestUri(t *testing.T) { + dummy := NewBasicGRC1155Token(dummyURI) + if dummy == nil { + t.Errorf("should not be nil") + } + + uri := dummy.Uri() + if uri != dummyURI { + t.Errorf("expected: (%s), got: (%s)", dummyURI, uri) + } +} + +func TestBalanceOf(t *testing.T) { + dummy := NewBasicGRC1155Token(dummyURI) + if dummy == nil { + t.Errorf("should not be nil") + } + + addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + + tid1 := TokenID("1") + tid2 := TokenID("2") + + balanceZeroAddressOfToken1, err := dummy.BalanceOf(zeroAddress, tid1) + if err == nil { + t.Errorf("should result in error") + } + balanceAddr1OfToken1, err := dummy.BalanceOf(addr1, tid1) + if err != nil { + t.Errorf("should not result in error") + } + if balanceAddr1OfToken1 != 0 { + t.Errorf("expected: (%d), got: (%d)", 0, balanceAddr1OfToken1) + } + + dummy.mintBatch(addr1, []TokenID{tid1, tid2}, []uint64{10, 100}) + dummy.mintBatch(addr2, []TokenID{tid1}, []uint64{20}) + + balanceAddr1OfToken1, err = dummy.BalanceOf(addr1, tid1) + if err != nil { + t.Errorf("should not result in error") + } + balanceAddr1OfToken2, err := dummy.BalanceOf(addr1, tid2) + if err != nil { + t.Errorf("should not result in error") + } + balanceAddr2OfToken1, err := dummy.BalanceOf(addr2, tid1) + if err != nil { + t.Errorf("should not result in error") + } + + if balanceAddr1OfToken1 != 10 { + t.Errorf("expected: (%d), got: (%d)", 10, balanceAddr1OfToken1) + } + if balanceAddr1OfToken2 != 100 { + t.Errorf("expected: (%d), got: (%d)", 100, balanceAddr1OfToken2) + } + if balanceAddr2OfToken1 != 20 { + t.Errorf("expected: (%d), got: (%d)", 20, balanceAddr2OfToken1) + } +} + +func TestBalanceOfBatch(t *testing.T) { + dummy := NewBasicGRC1155Token(dummyURI) + if dummy == nil { + t.Errorf("should not be nil") + } + + addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + + tid1 := TokenID("1") + tid2 := TokenID("2") + + balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr1, addr2}, []TokenID{tid1, tid2}) + if err != nil { + t.Errorf("should not result in error") + } + + if balanceBatch[0] != 0 { + t.Errorf("expected: (%d), got: (%d)", 0, balanceBatch[0]) + } + if balanceBatch[1] != 0 { + t.Errorf("expected: (%d), got: (%d)", 0, balanceBatch[1]) + } + + dummy.mintBatch(addr1, []TokenID{tid1}, []uint64{10}) + dummy.mintBatch(addr2, []TokenID{tid2}, []uint64{20}) + + balanceBatch, err = dummy.BalanceOfBatch([]std.Address{addr1, addr2}, []TokenID{tid1, tid2}) + if err != nil { + t.Errorf("should not result in error") + } + + if balanceBatch[0] != 10 { + t.Errorf("expected: (%d), got: (%d)", 10, balanceBatch[0]) + } + if balanceBatch[1] != 20 { + t.Errorf("expected: (%d), got: (%d)", 20, balanceBatch[1]) + } +} + +func TestIsApprovedForAll(t *testing.T) { + dummy := NewBasicGRC1155Token(dummyURI) + if dummy == nil { + t.Errorf("should not be nil") + } + + addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + + isApprovedForAll := dummy.IsApprovedForAll(addr1, addr2) + if isApprovedForAll != false { + t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) + } +} + +func TestSetApprovalForAll(t *testing.T) { + dummy := NewBasicGRC1155Token(dummyURI) + if dummy == nil { + t.Errorf("should not be nil") + } + + caller := std.GetOrigCaller() + addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + + isApprovedForAll := dummy.IsApprovedForAll(caller, addr) + if isApprovedForAll != false { + t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) + } + + err := dummy.SetApprovalForAll(addr, true) + if err != nil { + t.Errorf("should not result in error") + } + + isApprovedForAll = dummy.IsApprovedForAll(caller, addr) + if isApprovedForAll != true { + t.Errorf("expected: (%v), got: (%v)", true, isApprovedForAll) + } + + err = dummy.SetApprovalForAll(addr, false) + if err != nil { + t.Errorf("should not result in error") + } + + isApprovedForAll = dummy.IsApprovedForAll(caller, addr) + if isApprovedForAll != false { + t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) + } +} + +func TestSafeTransferFrom(t *testing.T) { + dummy := NewBasicGRC1155Token(dummyURI) + if dummy == nil { + t.Errorf("should not be nil") + } + + caller := std.GetOrigCaller() + addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + + tid := TokenID("1") + + dummy.mintBatch(caller, []TokenID{tid}, []uint64{100}) + + err := dummy.SafeTransferFrom(caller, zeroAddress, tid, 10) + if err == nil { + t.Errorf("should result in error") + } + + err = dummy.SafeTransferFrom(caller, addr, tid, 160) + if err == nil { + t.Errorf("should result in error") + } + + err = dummy.SafeTransferFrom(caller, addr, tid, 60) + if err != nil { + t.Errorf("should not result in error") + } + + // Check balance of caller after transfer + balanceOfCaller, err := dummy.BalanceOf(caller, tid) + if err != nil { + t.Errorf("should not result in error") + } + if balanceOfCaller != 40 { + t.Errorf("expected: (%d), got: (%d)", 40, balanceOfCaller) + } + + // Check balance of addr after transfer + balanceOfAddr, err := dummy.BalanceOf(addr, tid) + if err != nil { + t.Errorf("should not result in error") + } + if balanceOfAddr != 60 { + t.Errorf("expected: (%d), got: (%d)", 60, balanceOfAddr) + } +} + +func TestSafeBatchTransferFrom(t *testing.T) { + dummy := NewBasicGRC1155Token(dummyURI) + if dummy == nil { + t.Errorf("should not be nil") + } + + caller := std.GetOrigCaller() + addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + + tid1 := TokenID("1") + tid2 := TokenID("2") + + dummy.mintBatch(caller, []TokenID{tid1, tid2}, []uint64{10, 100}) + + err := dummy.SafeBatchTransferFrom(caller, zeroAddress, []TokenID{tid1, tid2}, []uint64{4, 60}) + if err == nil { + t.Errorf("should result in error") + } + err = dummy.SafeBatchTransferFrom(caller, addr, []TokenID{tid1, tid2}, []uint64{40, 60}) + if err == nil { + t.Errorf("should result in error") + } + err = dummy.SafeBatchTransferFrom(caller, addr, []TokenID{tid1}, []uint64{40, 60}) + if err == nil { + t.Errorf("should result in error") + } + err = dummy.SafeBatchTransferFrom(caller, addr, []TokenID{tid1, tid2}, []uint64{4, 60}) + if err != nil { + t.Errorf("should not result in error") + } + + balanceBatch, err := dummy.BalanceOfBatch([]std.Address{caller, addr, caller, addr}, []TokenID{tid1, tid1, tid2, tid2}) + if err != nil { + t.Errorf("should not result in error") + } + + // Check token1's balance of caller after batch transfer + if balanceBatch[0] != 6 { + t.Errorf("expected: (%d), got: (%d)", 6, balanceBatch[0]) + } + + // Check token1's balance of addr after batch transfer + if balanceBatch[1] != 4 { + t.Errorf("expected: (%d), got: (%d)", 4, balanceBatch[1]) + } + + // Check token2's balance of caller after batch transfer + if balanceBatch[2] != 40 { + t.Errorf("expected: (%d), got: (%d)", 40, balanceBatch[2]) + } + + // Check token2's balance of addr after batch transfer + if balanceBatch[3] != 60 { + t.Errorf("expected: (%d), got: (%d)", 60, balanceBatch[3]) + } +} + +func TestSafeMint(t *testing.T) { + dummy := NewBasicGRC1155Token(dummyURI) + if dummy == nil { + t.Errorf("should not be nil") + } + + addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + + tid1 := TokenID("1") + tid2 := TokenID("2") + + err := dummy.SafeMint(zeroAddress, tid1, 100) + if err == nil { + t.Errorf("should result in error") + } + err = dummy.SafeMint(addr1, tid1, 100) + if err != nil { + t.Errorf("should not result in error") + } + err = dummy.SafeMint(addr1, tid2, 200) + if err != nil { + t.Errorf("should not result in error") + } + err = dummy.SafeMint(addr2, tid1, 50) + if err != nil { + t.Errorf("should not result in error") + } + + balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr1, addr2, addr1}, []TokenID{tid1, tid1, tid2}) + if err != nil { + t.Errorf("should not result in error") + } + // Check token1's balance of addr1 after mint + if balanceBatch[0] != 100 { + t.Errorf("expected: (%d), got: (%d)", 100, balanceBatch[0]) + } + // Check token1's balance of addr2 after mint + if balanceBatch[1] != 50 { + t.Errorf("expected: (%d), got: (%d)", 50, balanceBatch[1]) + } + // Check token2's balance of addr1 after mint + if balanceBatch[2] != 200 { + t.Errorf("expected: (%d), got: (%d)", 200, balanceBatch[2]) + } +} + +func TestSafeBatchMint(t *testing.T) { + dummy := NewBasicGRC1155Token(dummyURI) + if dummy == nil { + t.Errorf("should not be nil") + } + + addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + + tid1 := TokenID("1") + tid2 := TokenID("2") + + err := dummy.SafeBatchMint(zeroAddress, []TokenID{tid1, tid2}, []uint64{100, 200}) + if err == nil { + t.Errorf("should result in error") + } + err = dummy.SafeBatchMint(addr1, []TokenID{tid1, tid2}, []uint64{100, 200}) + if err != nil { + t.Errorf("should not result in error") + } + err = dummy.SafeBatchMint(addr2, []TokenID{tid1, tid2}, []uint64{300, 400}) + if err != nil { + t.Errorf("should not result in error") + } + + balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr1, addr2, addr1, addr2}, []TokenID{tid1, tid1, tid2, tid2}) + if err != nil { + t.Errorf("should not result in error") + } + // Check token1's balance of addr1 after batch mint + if balanceBatch[0] != 100 { + t.Errorf("expected: (%d), got: (%d)", 100, balanceBatch[0]) + } + // Check token1's balance of addr2 after batch mint + if balanceBatch[1] != 300 { + t.Errorf("expected: (%d), got: (%d)", 300, balanceBatch[1]) + } + // Check token2's balance of addr1 after batch mint + if balanceBatch[2] != 200 { + t.Errorf("expected: (%d), got: (%d)", 200, balanceBatch[2]) + } + // Check token2's balance of addr2 after batch mint + if balanceBatch[3] != 400 { + t.Errorf("expected: (%d), got: (%d)", 400, balanceBatch[3]) + } +} + +func TestBurn(t *testing.T) { + dummy := NewBasicGRC1155Token(dummyURI) + if dummy == nil { + t.Errorf("should not be nil") + } + + addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + + tid1 := TokenID("1") + tid2 := TokenID("2") + + dummy.mintBatch(addr, []TokenID{tid1, tid2}, []uint64{100, 200}) + err := dummy.Burn(zeroAddress, tid1, 60) + if err == nil { + t.Errorf("should result in error") + } + err = dummy.Burn(addr, tid1, 160) + if err == nil { + t.Errorf("should result in error") + } + err = dummy.Burn(addr, tid1, 60) + if err != nil { + t.Errorf("should not result in error") + } + err = dummy.Burn(addr, tid2, 60) + if err != nil { + t.Errorf("should not result in error") + } + balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr, addr}, []TokenID{tid1, tid2}) + if err != nil { + t.Errorf("should not result in error") + } + + // Check token1's balance of addr after burn + if balanceBatch[0] != 40 { + t.Errorf("expected: (%d), got: (%d)", 40, balanceBatch[0]) + } + // Check token2's balance of addr after burn + if balanceBatch[1] != 140 { + t.Errorf("expected: (%d), got: (%d)", 140, balanceBatch[1]) + } +} + +func TestBatchBurn(t *testing.T) { + dummy := NewBasicGRC1155Token(dummyURI) + if dummy == nil { + t.Errorf("should not be nil") + } + + addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + + tid1 := TokenID("1") + tid2 := TokenID("2") + + dummy.mintBatch(addr, []TokenID{tid1, tid2}, []uint64{100, 200}) + err := dummy.BatchBurn(zeroAddress, []TokenID{tid1, tid2}, []uint64{60, 60}) + if err == nil { + t.Errorf("should result in error") + } + err = dummy.BatchBurn(addr, []TokenID{tid1, tid2}, []uint64{160, 60}) + if err == nil { + t.Errorf("should result in error") + } + err = dummy.BatchBurn(addr, []TokenID{tid1, tid2}, []uint64{60, 60}) + if err != nil { + t.Errorf("should not result in error") + } + balanceBatch, err := dummy.BalanceOfBatch([]std.Address{addr, addr}, []TokenID{tid1, tid2}) + if err != nil { + t.Errorf("should not result in error") + } + + // Check token1's balance of addr after batch burn + if balanceBatch[0] != 40 { + t.Errorf("expected: (%d), got: (%d)", 40, balanceBatch[0]) + } + // Check token2's balance of addr after batch burn + if balanceBatch[1] != 140 { + t.Errorf("expected: (%d), got: (%d)", 140, balanceBatch[1]) + } +} diff --git a/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno b/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno index 50c4ee07aa0..b6631e15248 100644 --- a/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno +++ b/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno @@ -1,414 +1,416 @@ package grc721 -// import ( -// "std" -// "testing" -// -// "gno.land/p/demo/testutils" -// "gno.land/r/demo/users" -// ) - -// var ( -// dummyNFTName = "DummyNFT" -// dummyNFTSymbol = "DNFT" -// ) - -// func TestNewBasicNFT(t *testing.T) { -// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) -// if dummy == nil { -// t.Errorf("should not be nil") -// } -// } - -// func TestName(t *testing.T) { -// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) -// if dummy == nil { -// t.Errorf("should not be nil") -// } -// name := dummy.Name() -// if name != dummyNFTName { -// t.Errorf("expected: (%s), got: (%s)", dummyNFTName, name) -// } -// } - -// func TestSymbol(t *testing.T) { -// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) -// if dummy == nil { -// t.Errorf("should not be nil") -// } -// symbol := dummy.Symbol() -// if symbol != dummyNFTSymbol { -// t.Errorf("expected: (%s), got: (%s)", dummyNFTSymbol, symbol) -// } -// } - -// func TestTokenCount(t *testing.T) { -// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// count := dummy.TokenCount() -// if count != 0 { -// t.Errorf("expected: (%d), got: (%d)", 0, count) -// } - -// dummy.mint("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm", TokenID("1")) -// dummy.mint("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm", TokenID("2")) - -// count = dummy.TokenCount() -// if count != 2 { -// t.Errorf("expected: (%d), got: (%d)", 2, count) -// } -// } - -// func TestBalanceOf(t *testing.T) { -// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") -// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") - -// balanceAddr1, err := dummy.BalanceOf(users.Resolve(addr1)) -// if err != nil { -// t.Errorf("should not result in error") -// } -// if balanceAddr1 != 0 { -// t.Errorf("expected: (%d), got: (%d)", 0, balanceAddr1) -// } - -// dummy.mint(users.Resolve(addr1), TokenID("1")) -// dummy.mint(users.Resolve(addr1), TokenID("2")) -// dummy.mint(users.Resolve(addr2), TokenID("3")) - -// balanceAddr1, err = dummy.BalanceOf(users.Resolve(addr1)) -// if err != nil { -// t.Errorf("should not result in error") -// } -// balanceAddr2, err := dummy.BalanceOf(users.Resolve(addr2)) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// if balanceAddr1 != 2 { -// t.Errorf("expected: (%d), got: (%d)", 2, balanceAddr1) -// } -// if balanceAddr2 != 1 { -// t.Errorf("expected: (%d), got: (%d)", 1, balanceAddr2) -// } -// } - -// func TestOwnerOf(t *testing.T) { -// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") -// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") - -// owner, err := dummy.OwnerOf(TokenID("invalid")) -// if err == nil { -// t.Errorf("should result in error") -// } - -// dummy.mint(users.Resolve(addr1), TokenID("1")) -// dummy.mint(users.Resolve(addr2), TokenID("2")) - -// // Checking for token id "1" -// owner, err = dummy.OwnerOf(TokenID("1")) -// if err != nil { -// t.Errorf("should not result in error") -// } -// if owner != users.Resolve(addr1) { -// t.Errorf("expected: (%s), got: (%s)", users.Resolve(addr1).String(), owner.String()) -// } - -// // Checking for token id "2" -// owner, err = dummy.OwnerOf(TokenID("2")) -// if err != nil { -// t.Errorf("should not result in error") -// } -// if owner != users.Resolve(addr2) { -// t.Errorf("expected: (%s), got: (%s)", users.Resolve(addr2).String(), owner.String()) -// } -// } - -// func TestIsApprovedForAll(t *testing.T) { -// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") -// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") - -// isApprovedForAll := dummy.IsApprovedForAll(users.Resolve(addr1), users.Resolve(addr2)) -// if isApprovedForAll != false { -// t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) -// } -// } - -// func TestSetApprovalForAll(t *testing.T) { -// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// caller := std.PrevRealm().Addr() -// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") - -// isApprovedForAll := dummy.IsApprovedForAll(caller, users.Resolve(addr)) -// if isApprovedForAll != false { -// t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) -// } - -// err := dummy.SetApprovalForAll(users.Resolve(addr), true) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// isApprovedForAll = dummy.IsApprovedForAll(caller, users.Resolve(addr)) -// if isApprovedForAll != true { -// t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) -// } -// } - -// func TestGetApproved(t *testing.T) { -// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// approvedAddr, err := dummy.GetApproved(TokenID("invalid")) -// if err == nil { -// t.Errorf("should result in error") -// } -// } - -// func TestApprove(t *testing.T) { -// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// caller := std.PrevRealm().Addr() -// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") - -// dummy.mint(caller, TokenID("1")) - -// _, err := dummy.GetApproved(TokenID("1")) -// if err == nil { -// t.Errorf("should result in error") -// } - -// err = dummy.Approve(users.Resolve(addr), TokenID("1")) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// approvedAddr, err := dummy.GetApproved(TokenID("1")) -// if err != nil { -// t.Errorf("should not result in error") -// } -// if approvedAddr != users.Resolve(addr) { -// t.Errorf("expected: (%s), got: (%s)", users.Resolve(addr).String(), approvedAddr.String()) -// } -// } - -// func TestTransferFrom(t *testing.T) { -// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// caller := std.PrevRealm().Addr() -// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") - -// dummy.mint(caller, TokenID("1")) -// dummy.mint(caller, TokenID("2")) - -// err := dummy.TransferFrom(caller, users.Resolve(addr), TokenID("1")) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// // Check balance of caller after transfer -// balanceOfCaller, err := dummy.BalanceOf(caller) -// if err != nil { -// t.Errorf("should not result in error") -// } -// if balanceOfCaller != 1 { -// t.Errorf("expected: (%d), got: (%d)", 1, balanceOfCaller) -// } - -// // Check balance of addr after transfer -// balanceOfAddr, err := dummy.BalanceOf(users.Resolve(addr)) -// if err != nil { -// t.Errorf("should not result in error") -// } -// if balanceOfAddr != 1 { -// t.Errorf("expected: (%d), got: (%d)", 1, balanceOfAddr) -// } - -// // Check Owner of transferred Token id -// owner, err := dummy.OwnerOf(TokenID("1")) -// if err != nil { -// t.Errorf("should not result in error") -// } -// if owner != users.Resolve(addr) { -// t.Errorf("expected: (%s), got: (%s)", users.Resolve(addr).String(), owner.String()) -// } -// } - -// func TestSafeTransferFrom(t *testing.T) { -// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// caller := std.PrevRealm().Addr() -// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") - -// dummy.mint(caller, TokenID("1")) -// dummy.mint(caller, TokenID("2")) - -// err := dummy.SafeTransferFrom(caller, users.Resolve(addr), TokenID("1")) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// // Check balance of caller after transfer -// balanceOfCaller, err := dummy.BalanceOf(caller) -// if err != nil { -// t.Errorf("should not result in error") -// } -// if balanceOfCaller != 1 { -// t.Errorf("expected: (%d), got: (%d)", 1, balanceOfCaller) -// } - -// // Check balance of addr after transfer -// balanceOfAddr, err := dummy.BalanceOf(users.Resolve(addr)) -// if err != nil { -// t.Errorf("should not result in error") -// } -// if balanceOfAddr != 1 { -// t.Errorf("expected: (%d), got: (%d)", 1, balanceOfAddr) -// } - -// // Check Owner of transferred Token id -// owner, err := dummy.OwnerOf(TokenID("1")) -// if err != nil { -// t.Errorf("should not result in error") -// } -// if owner != users.Resolve(addr) { -// t.Errorf("expected: (%s), got: (%s)", users.Resolve(addr).String(), owner.String()) -// } -// } - -// func TestMint(t *testing.T) { -// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") -// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") - -// err := dummy.Mint(users.Resolve(addr1), TokenID("1")) -// if err != nil { -// t.Errorf("should not result in error") -// } -// err = dummy.Mint(users.Resolve(addr1), TokenID("2")) -// if err != nil { -// t.Errorf("should not result in error") -// } -// err = dummy.Mint(users.Resolve(addr2), TokenID("3")) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// // Try minting duplicate token id -// err = dummy.Mint(users.Resolve(addr2), TokenID("1")) -// if err == nil { -// t.Errorf("should result in error") -// } - -// // Check Owner of Token id -// owner, err := dummy.OwnerOf(TokenID("1")) -// if err != nil { -// t.Errorf("should not result in error") -// } -// if owner != users.Resolve(addr1) { -// t.Errorf("expected: (%s), got: (%s)", users.Resolve(addr1).String(), owner.String()) -// } -// } - -// func TestBurn(t *testing.T) { -// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") - -// dummy.mint(users.Resolve(addr), TokenID("1")) -// dummy.mint(users.Resolve(addr), TokenID("2")) - -// err := dummy.Burn(TokenID("1")) -// if err != nil { -// t.Errorf("should not result in error") -// } - -// // Check Owner of Token id -// owner, err := dummy.OwnerOf(TokenID("1")) -// if err == nil { -// t.Errorf("should result in error") -// } -// } - -// func TestSetTokenURI(t *testing.T) { -// dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) -// if dummy == nil { -// t.Errorf("should not be nil") -// } - -// addr1 := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") -// addr2 := users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") -// tokenURI := "http://example.com/token" - -// std.TestSetOrigCaller(std.Address(addr1)) // addr1 - -// dummy.mint(addr1.Resolve(), TokenID("1")) -// _, derr := dummy.SetTokenURI(TokenID("1"), TokenURI(tokenURI)) - -// if derr != nil { -// t.Errorf("Should not result in error ", derr.Error()) -// } - -// // Test case: Invalid token ID -// _, err := dummy.SetTokenURI(TokenID("3"), TokenURI(tokenURI)) -// if err != ErrInvalidTokenId { -// t.Errorf("Expected error %v, got %v", ErrInvalidTokenId, err) -// } - -// std.TestSetOrigCaller(std.Address(addr2)) // addr2 - -// _, cerr := dummy.SetTokenURI(TokenID("1"), TokenURI(tokenURI)) // addr2 trying to set URI for token 1 -// if cerr != ErrCallerIsNotOwner { -// t.Errorf("Expected error %v, got %v", ErrCallerIsNotOwner, err) -// } - -// // Test case: Retrieving TokenURI -// std.TestSetOrigCaller(std.Address(addr1)) // addr1 - -// dummyTokenURI, err := dummy.TokenURI(TokenID("1")) -// if err != nil { -// t.Errorf("TokenURI error: %v, ", err.Error()) -// } -// if dummyTokenURI != tokenURI { -// t.Errorf("Expected URI %v, got %v", tokenURI, dummyTokenURI) -// } -// } +import ( + "std" + "testing" + + "gno.land/p/demo/testutils" + "gno.land/p/demo/users" + + rusers "gno.land/r/demo/users" // TODO(hariom): move this to realm? +) + +var ( + dummyNFTName = "DummyNFT" + dummyNFTSymbol = "DNFT" +) + +func TestNewBasicNFT(t *testing.T) { + dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) + if dummy == nil { + t.Errorf("should not be nil") + } +} + +func TestName(t *testing.T) { + dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) + if dummy == nil { + t.Errorf("should not be nil") + } + name := dummy.Name() + if name != dummyNFTName { + t.Errorf("expected: (%s), got: (%s)", dummyNFTName, name) + } +} + +func TestSymbol(t *testing.T) { + dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) + if dummy == nil { + t.Errorf("should not be nil") + } + symbol := dummy.Symbol() + if symbol != dummyNFTSymbol { + t.Errorf("expected: (%s), got: (%s)", dummyNFTSymbol, symbol) + } +} + +func TestTokenCount(t *testing.T) { + dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) + if dummy == nil { + t.Errorf("should not be nil") + } + + count := dummy.TokenCount() + if count != 0 { + t.Errorf("expected: (%d), got: (%d)", 0, count) + } + + dummy.mint("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm", TokenID("1")) + dummy.mint("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm", TokenID("2")) + + count = dummy.TokenCount() + if count != 2 { + t.Errorf("expected: (%d), got: (%d)", 2, count) + } +} + +func TestBalanceOf(t *testing.T) { + dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) + if dummy == nil { + t.Errorf("should not be nil") + } + + addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + + balanceAddr1, err := dummy.BalanceOf(addr1) + if err != nil { + t.Errorf("should not result in error") + } + if balanceAddr1 != 0 { + t.Errorf("expected: (%d), got: (%d)", 0, balanceAddr1) + } + + dummy.mint(addr1, TokenID("1")) + dummy.mint(addr1, TokenID("2")) + dummy.mint(addr2, TokenID("3")) + + balanceAddr1, err = dummy.BalanceOf(addr1) + if err != nil { + t.Errorf("should not result in error") + } + balanceAddr2, err := dummy.BalanceOf(addr2) + if err != nil { + t.Errorf("should not result in error") + } + + if balanceAddr1 != 2 { + t.Errorf("expected: (%d), got: (%d)", 2, balanceAddr1) + } + if balanceAddr2 != 1 { + t.Errorf("expected: (%d), got: (%d)", 1, balanceAddr2) + } +} + +func TestOwnerOf(t *testing.T) { + dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) + if dummy == nil { + t.Errorf("should not be nil") + } + + addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + + owner, err := dummy.OwnerOf(TokenID("invalid")) + if err == nil { + t.Errorf("should result in error") + } + + dummy.mint(addr1, TokenID("1")) + dummy.mint(addr2, TokenID("2")) + + // Checking for token id "1" + owner, err = dummy.OwnerOf(TokenID("1")) + if err != nil { + t.Errorf("should not result in error") + } + if owner != addr1 { + t.Errorf("expected: (%s), got: (%s)", addr1.String(), owner.String()) + } + + // Checking for token id "2" + owner, err = dummy.OwnerOf(TokenID("2")) + if err != nil { + t.Errorf("should not result in error") + } + if owner != addr2 { + t.Errorf("expected: (%s), got: (%s)", addr2.String(), owner.String()) + } +} + +func TestIsApprovedForAll(t *testing.T) { + dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) + if dummy == nil { + t.Errorf("should not be nil") + } + + addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + + isApprovedForAll := dummy.IsApprovedForAll(addr1, addr2) + if isApprovedForAll != false { + t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) + } +} + +func TestSetApprovalForAll(t *testing.T) { + dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) + if dummy == nil { + t.Errorf("should not be nil") + } + + caller := std.PrevRealm().Addr() + addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + + isApprovedForAll := dummy.IsApprovedForAll(caller, addr) + if isApprovedForAll != false { + t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) + } + + err := dummy.SetApprovalForAll(addr, true) + if err != nil { + t.Errorf("should not result in error") + } + + isApprovedForAll = dummy.IsApprovedForAll(caller, addr) + if isApprovedForAll != true { + t.Errorf("expected: (%v), got: (%v)", false, isApprovedForAll) + } +} + +func TestGetApproved(t *testing.T) { + dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) + if dummy == nil { + t.Errorf("should not be nil") + } + + approvedAddr, err := dummy.GetApproved(TokenID("invalid")) + if err == nil { + t.Errorf("should result in error") + } +} + +func TestApprove(t *testing.T) { + dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) + if dummy == nil { + t.Errorf("should not be nil") + } + + caller := std.PrevRealm().Addr() + addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + + dummy.mint(caller, TokenID("1")) + + _, err := dummy.GetApproved(TokenID("1")) + if err == nil { + t.Errorf("should result in error") + } + + err = dummy.Approve(addr, TokenID("1")) + if err != nil { + t.Errorf("should not result in error") + } + + approvedAddr, err := dummy.GetApproved(TokenID("1")) + if err != nil { + t.Errorf("should not result in error") + } + if approvedAddr != addr { + t.Errorf("expected: (%s), got: (%s)", addr.String(), approvedAddr.String()) + } +} + +func TestTransferFrom(t *testing.T) { + dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) + if dummy == nil { + t.Errorf("should not be nil") + } + + caller := std.PrevRealm().Addr() + addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + + dummy.mint(caller, TokenID("1")) + dummy.mint(caller, TokenID("2")) + + err := dummy.TransferFrom(caller, addr, TokenID("1")) + if err != nil { + t.Errorf("should not result in error") + } + + // Check balance of caller after transfer + balanceOfCaller, err := dummy.BalanceOf(caller) + if err != nil { + t.Errorf("should not result in error") + } + if balanceOfCaller != 1 { + t.Errorf("expected: (%d), got: (%d)", 1, balanceOfCaller) + } + + // Check balance of addr after transfer + balanceOfAddr, err := dummy.BalanceOf(addr) + if err != nil { + t.Errorf("should not result in error") + } + if balanceOfAddr != 1 { + t.Errorf("expected: (%d), got: (%d)", 1, balanceOfAddr) + } + + // Check Owner of transferred Token id + owner, err := dummy.OwnerOf(TokenID("1")) + if err != nil { + t.Errorf("should not result in error") + } + if owner != addr { + t.Errorf("expected: (%s), got: (%s)", addr.String(), owner.String()) + } +} + +func TestSafeTransferFrom(t *testing.T) { + dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) + if dummy == nil { + t.Errorf("should not be nil") + } + + caller := std.PrevRealm().Addr() + addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + + dummy.mint(caller, TokenID("1")) + dummy.mint(caller, TokenID("2")) + + err := dummy.SafeTransferFrom(caller, addr, TokenID("1")) + if err != nil { + t.Errorf("should not result in error") + } + + // Check balance of caller after transfer + balanceOfCaller, err := dummy.BalanceOf(caller) + if err != nil { + t.Errorf("should not result in error") + } + if balanceOfCaller != 1 { + t.Errorf("expected: (%d), got: (%d)", 1, balanceOfCaller) + } + + // Check balance of addr after transfer + balanceOfAddr, err := dummy.BalanceOf(addr) + if err != nil { + t.Errorf("should not result in error") + } + if balanceOfAddr != 1 { + t.Errorf("expected: (%d), got: (%d)", 1, balanceOfAddr) + } + + // Check Owner of transferred Token id + owner, err := dummy.OwnerOf(TokenID("1")) + if err != nil { + t.Errorf("should not result in error") + } + if owner != addr { + t.Errorf("expected: (%s), got: (%s)", addr.String(), owner.String()) + } +} + +func TestMint(t *testing.T) { + dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) + if dummy == nil { + t.Errorf("should not be nil") + } + + addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + + err := dummy.Mint(addr1, TokenID("1")) + if err != nil { + t.Errorf("should not result in error") + } + err = dummy.Mint(addr1, TokenID("2")) + if err != nil { + t.Errorf("should not result in error") + } + err = dummy.Mint(addr2, TokenID("3")) + if err != nil { + t.Errorf("should not result in error") + } + + // Try minting duplicate token id + err = dummy.Mint(addr2, TokenID("1")) + if err == nil { + t.Errorf("should result in error") + } + + // Check Owner of Token id + owner, err := dummy.OwnerOf(TokenID("1")) + if err != nil { + t.Errorf("should not result in error") + } + if owner != addr1 { + t.Errorf("expected: (%s), got: (%s)", addr1.String(), owner.String()) + } +} + +func TestBurn(t *testing.T) { + dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) + if dummy == nil { + t.Errorf("should not be nil") + } + + addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + + dummy.mint(addr, TokenID("1")) + dummy.mint(addr, TokenID("2")) + + err := dummy.Burn(TokenID("1")) + if err != nil { + t.Errorf("should not result in error") + } + + // Check Owner of Token id + owner, err := dummy.OwnerOf(TokenID("1")) + if err == nil { + t.Errorf("should result in error") + } +} + +func TestSetTokenURI(t *testing.T) { + dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) + if dummy == nil { + t.Errorf("should not be nil") + } + + addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + tokenURI := "http://example.com/token" + + std.TestSetOrigCaller(std.Address(addr1)) // addr1 + + dummy.mint(addr1, TokenID("1")) + _, derr := dummy.SetTokenURI(TokenID("1"), TokenURI(tokenURI)) + + if derr != nil { + t.Errorf("Should not result in error ", derr.Error()) + } + + // Test case: Invalid token ID + _, err := dummy.SetTokenURI(TokenID("3"), TokenURI(tokenURI)) + if err != ErrInvalidTokenId { + t.Errorf("Expected error %v, got %v", ErrInvalidTokenId, err) + } + + std.TestSetOrigCaller(std.Address(addr2)) // addr2 + + _, cerr := dummy.SetTokenURI(TokenID("1"), TokenURI(tokenURI)) // addr2 trying to set URI for token 1 + if cerr != ErrCallerIsNotOwner { + t.Errorf("Expected error %v, got %v", ErrCallerIsNotOwner, err) + } + + // Test case: Retrieving TokenURI + std.TestSetOrigCaller(std.Address(addr1)) // addr1 + + dummyTokenURI, err := dummy.TokenURI(TokenID("1")) + if err != nil { + t.Errorf("TokenURI error: %v, ", err.Error()) + } + if dummyTokenURI != tokenURI { + t.Errorf("Expected URI %v, got %v", tokenURI, dummyTokenURI) + } +} From ecb18dd9753917dd01e2a7c1f8295da088f27905 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Mon, 15 Jan 2024 19:14:28 +0530 Subject: [PATCH 5/9] s/rusers.Resolve()/std.Address() --- .../grc/grc1155/basic_grc1155_token_test.gno | 32 +++++++++---------- .../p/demo/grc/grc721/basic_nft_test.gno | 32 +++++++++---------- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno b/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno index 49af126dc92..85ae2de59ef 100644 --- a/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno +++ b/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno @@ -6,8 +6,6 @@ import ( "testing" "gno.land/p/demo/users" - - rusers "gno.land/r/demo/users" // TODO(hariom): move this to realm? ) const dummyURI = "ipfs://xyz" @@ -37,8 +35,8 @@ func TestBalanceOf(t *testing.T) { t.Errorf("should not be nil") } - addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) tid1 := TokenID("1") tid2 := TokenID("2") @@ -88,8 +86,8 @@ func TestBalanceOfBatch(t *testing.T) { t.Errorf("should not be nil") } - addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) tid1 := TokenID("1") tid2 := TokenID("2") @@ -128,8 +126,8 @@ func TestIsApprovedForAll(t *testing.T) { t.Errorf("should not be nil") } - addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) isApprovedForAll := dummy.IsApprovedForAll(addr1, addr2) if isApprovedForAll != false { @@ -144,7 +142,7 @@ func TestSetApprovalForAll(t *testing.T) { } caller := std.GetOrigCaller() - addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) isApprovedForAll := dummy.IsApprovedForAll(caller, addr) if isApprovedForAll != false { @@ -179,7 +177,7 @@ func TestSafeTransferFrom(t *testing.T) { } caller := std.GetOrigCaller() - addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) tid := TokenID("1") @@ -226,7 +224,7 @@ func TestSafeBatchTransferFrom(t *testing.T) { } caller := std.GetOrigCaller() - addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) tid1 := TokenID("1") tid2 := TokenID("2") @@ -282,8 +280,8 @@ func TestSafeMint(t *testing.T) { t.Errorf("should not be nil") } - addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) tid1 := TokenID("1") tid2 := TokenID("2") @@ -329,8 +327,8 @@ func TestSafeBatchMint(t *testing.T) { t.Errorf("should not be nil") } - addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) tid1 := TokenID("1") tid2 := TokenID("2") @@ -376,7 +374,7 @@ func TestBurn(t *testing.T) { t.Errorf("should not be nil") } - addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) tid1 := TokenID("1") tid2 := TokenID("2") @@ -419,7 +417,7 @@ func TestBatchBurn(t *testing.T) { t.Errorf("should not be nil") } - addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) tid1 := TokenID("1") tid2 := TokenID("2") diff --git a/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno b/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno index b6631e15248..8dc7ba35831 100644 --- a/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno +++ b/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno @@ -6,8 +6,6 @@ import ( "gno.land/p/demo/testutils" "gno.land/p/demo/users" - - rusers "gno.land/r/demo/users" // TODO(hariom): move this to realm? ) var ( @@ -70,8 +68,8 @@ func TestBalanceOf(t *testing.T) { t.Errorf("should not be nil") } - addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) balanceAddr1, err := dummy.BalanceOf(addr1) if err != nil { @@ -108,8 +106,8 @@ func TestOwnerOf(t *testing.T) { t.Errorf("should not be nil") } - addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) owner, err := dummy.OwnerOf(TokenID("invalid")) if err == nil { @@ -144,8 +142,8 @@ func TestIsApprovedForAll(t *testing.T) { t.Errorf("should not be nil") } - addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) isApprovedForAll := dummy.IsApprovedForAll(addr1, addr2) if isApprovedForAll != false { @@ -160,7 +158,7 @@ func TestSetApprovalForAll(t *testing.T) { } caller := std.PrevRealm().Addr() - addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) isApprovedForAll := dummy.IsApprovedForAll(caller, addr) if isApprovedForAll != false { @@ -197,7 +195,7 @@ func TestApprove(t *testing.T) { } caller := std.PrevRealm().Addr() - addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) dummy.mint(caller, TokenID("1")) @@ -227,7 +225,7 @@ func TestTransferFrom(t *testing.T) { } caller := std.PrevRealm().Addr() - addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) dummy.mint(caller, TokenID("1")) dummy.mint(caller, TokenID("2")) @@ -272,7 +270,7 @@ func TestSafeTransferFrom(t *testing.T) { } caller := std.PrevRealm().Addr() - addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) dummy.mint(caller, TokenID("1")) dummy.mint(caller, TokenID("2")) @@ -316,8 +314,8 @@ func TestMint(t *testing.T) { t.Errorf("should not be nil") } - addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) err := dummy.Mint(addr1, TokenID("1")) if err != nil { @@ -354,7 +352,7 @@ func TestBurn(t *testing.T) { t.Errorf("should not be nil") } - addr := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) dummy.mint(addr, TokenID("1")) dummy.mint(addr, TokenID("2")) @@ -377,8 +375,8 @@ func TestSetTokenURI(t *testing.T) { t.Errorf("should not be nil") } - addr1 := rusers.Resolve(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := rusers.Resolve(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) tokenURI := "http://example.com/token" std.TestSetOrigCaller(std.Address(addr1)) // addr1 From 40f29f55b46b73a6fa3e0f95bf1d58958aa77e7f Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Mon, 15 Jan 2024 19:14:49 +0530 Subject: [PATCH 6/9] gno mod tidy --- examples/gno.land/p/demo/grc/grc1155/gno.mod | 1 + examples/gno.land/p/demo/grc/grc721/gno.mod | 2 ++ 2 files changed, 3 insertions(+) diff --git a/examples/gno.land/p/demo/grc/grc1155/gno.mod b/examples/gno.land/p/demo/grc/grc1155/gno.mod index 8f3f36019f9..b8db3675cf0 100644 --- a/examples/gno.land/p/demo/grc/grc1155/gno.mod +++ b/examples/gno.land/p/demo/grc/grc1155/gno.mod @@ -3,4 +3,5 @@ module gno.land/p/demo/grc/grc1155 require ( gno.land/p/demo/avl v0.0.0-latest gno.land/p/demo/ufmt v0.0.0-latest + gno.land/p/demo/users v0.0.0-latest ) diff --git a/examples/gno.land/p/demo/grc/grc721/gno.mod b/examples/gno.land/p/demo/grc/grc721/gno.mod index 48a5f4e04b6..1eada28e4ee 100644 --- a/examples/gno.land/p/demo/grc/grc721/gno.mod +++ b/examples/gno.land/p/demo/grc/grc721/gno.mod @@ -2,5 +2,7 @@ module gno.land/p/demo/grc/grc721 require ( gno.land/p/demo/avl v0.0.0-latest + gno.land/p/demo/testutils v0.0.0-latest gno.land/p/demo/ufmt v0.0.0-latest + gno.land/p/demo/users v0.0.0-latest ) From 9ee009bffb21fb419c17b424719f6c1c98f946d3 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Thu, 15 Feb 2024 18:00:08 +0530 Subject: [PATCH 7/9] remove redundant `users.AddressOrName` casting --- .../grc/grc1155/basic_grc1155_token_test.gno | 30 +++++++++---------- .../p/demo/grc/grc721/basic_nft_test.gno | 30 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno b/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno index 85ae2de59ef..d7abf8e1153 100644 --- a/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno +++ b/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno @@ -35,8 +35,8 @@ func TestBalanceOf(t *testing.T) { t.Errorf("should not be nil") } - addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") + addr2 := std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") tid1 := TokenID("1") tid2 := TokenID("2") @@ -86,8 +86,8 @@ func TestBalanceOfBatch(t *testing.T) { t.Errorf("should not be nil") } - addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") + addr2 := std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") tid1 := TokenID("1") tid2 := TokenID("2") @@ -126,8 +126,8 @@ func TestIsApprovedForAll(t *testing.T) { t.Errorf("should not be nil") } - addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") + addr2 := std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") isApprovedForAll := dummy.IsApprovedForAll(addr1, addr2) if isApprovedForAll != false { @@ -142,7 +142,7 @@ func TestSetApprovalForAll(t *testing.T) { } caller := std.GetOrigCaller() - addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") isApprovedForAll := dummy.IsApprovedForAll(caller, addr) if isApprovedForAll != false { @@ -177,7 +177,7 @@ func TestSafeTransferFrom(t *testing.T) { } caller := std.GetOrigCaller() - addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") tid := TokenID("1") @@ -224,7 +224,7 @@ func TestSafeBatchTransferFrom(t *testing.T) { } caller := std.GetOrigCaller() - addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") tid1 := TokenID("1") tid2 := TokenID("2") @@ -280,8 +280,8 @@ func TestSafeMint(t *testing.T) { t.Errorf("should not be nil") } - addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") + addr2 := std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") tid1 := TokenID("1") tid2 := TokenID("2") @@ -327,8 +327,8 @@ func TestSafeBatchMint(t *testing.T) { t.Errorf("should not be nil") } - addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") + addr2 := std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") tid1 := TokenID("1") tid2 := TokenID("2") @@ -374,7 +374,7 @@ func TestBurn(t *testing.T) { t.Errorf("should not be nil") } - addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") tid1 := TokenID("1") tid2 := TokenID("2") @@ -417,7 +417,7 @@ func TestBatchBurn(t *testing.T) { t.Errorf("should not be nil") } - addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") tid1 := TokenID("1") tid2 := TokenID("2") diff --git a/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno b/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno index 8dc7ba35831..70255c5e9d1 100644 --- a/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno +++ b/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno @@ -68,8 +68,8 @@ func TestBalanceOf(t *testing.T) { t.Errorf("should not be nil") } - addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") + addr2 := std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") balanceAddr1, err := dummy.BalanceOf(addr1) if err != nil { @@ -106,8 +106,8 @@ func TestOwnerOf(t *testing.T) { t.Errorf("should not be nil") } - addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") + addr2 := std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") owner, err := dummy.OwnerOf(TokenID("invalid")) if err == nil { @@ -142,8 +142,8 @@ func TestIsApprovedForAll(t *testing.T) { t.Errorf("should not be nil") } - addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") + addr2 := std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") isApprovedForAll := dummy.IsApprovedForAll(addr1, addr2) if isApprovedForAll != false { @@ -158,7 +158,7 @@ func TestSetApprovalForAll(t *testing.T) { } caller := std.PrevRealm().Addr() - addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") isApprovedForAll := dummy.IsApprovedForAll(caller, addr) if isApprovedForAll != false { @@ -195,7 +195,7 @@ func TestApprove(t *testing.T) { } caller := std.PrevRealm().Addr() - addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") dummy.mint(caller, TokenID("1")) @@ -225,7 +225,7 @@ func TestTransferFrom(t *testing.T) { } caller := std.PrevRealm().Addr() - addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") dummy.mint(caller, TokenID("1")) dummy.mint(caller, TokenID("2")) @@ -270,7 +270,7 @@ func TestSafeTransferFrom(t *testing.T) { } caller := std.PrevRealm().Addr() - addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") dummy.mint(caller, TokenID("1")) dummy.mint(caller, TokenID("2")) @@ -314,8 +314,8 @@ func TestMint(t *testing.T) { t.Errorf("should not be nil") } - addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") + addr2 := std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") err := dummy.Mint(addr1, TokenID("1")) if err != nil { @@ -352,7 +352,7 @@ func TestBurn(t *testing.T) { t.Errorf("should not be nil") } - addr := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) + addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") dummy.mint(addr, TokenID("1")) dummy.mint(addr, TokenID("2")) @@ -375,8 +375,8 @@ func TestSetTokenURI(t *testing.T) { t.Errorf("should not be nil") } - addr1 := std.Address(users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")) - addr2 := std.Address(users.AddressOrName("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")) + addr1 := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") + addr2 := std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") tokenURI := "http://example.com/token" std.TestSetOrigCaller(std.Address(addr1)) // addr1 From 8ea3f371a2be2b606a9840c6c287467159ae3de2 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Thu, 15 Feb 2024 18:55:21 +0530 Subject: [PATCH 8/9] s/Render/String --- examples/gno.land/p/demo/users/users.gno | 2 +- examples/gno.land/r/demo/users/users.gno | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/gno.land/p/demo/users/users.gno b/examples/gno.land/p/demo/users/users.gno index 204eaf19918..3b98e65aaf9 100644 --- a/examples/gno.land/p/demo/users/users.gno +++ b/examples/gno.land/p/demo/users/users.gno @@ -17,7 +17,7 @@ type User struct { Inviter std.Address } -func (u *User) Render() string { +func (u *User) String() string { str := "## user " + u.Name + "\n" + "\n" + " * address = " + string(u.Address) + "\n" + diff --git a/examples/gno.land/r/demo/users/users.gno b/examples/gno.land/r/demo/users/users.gno index 4fe486a71d0..1bf5b55f1f7 100644 --- a/examples/gno.land/r/demo/users/users.gno +++ b/examples/gno.land/r/demo/users/users.gno @@ -265,13 +265,13 @@ func Render(path string) string { // TODO: display basic information about account. return "unknown address " + path } - return user.Render() + return user.String() } else { user := GetUserByName(path) if user == nil { return "unknown username " + path } - return user.Render() + return user.String() } } From c894748e83fd132a51eac1d3d7ba041b3badd36d Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Thu, 29 Feb 2024 20:42:33 +0530 Subject: [PATCH 9/9] `s/String()/Render()` --- examples/gno.land/p/demo/users/users.gno | 2 +- examples/gno.land/r/demo/users/users.gno | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/gno.land/p/demo/users/users.gno b/examples/gno.land/p/demo/users/users.gno index 3b98e65aaf9..204eaf19918 100644 --- a/examples/gno.land/p/demo/users/users.gno +++ b/examples/gno.land/p/demo/users/users.gno @@ -17,7 +17,7 @@ type User struct { Inviter std.Address } -func (u *User) String() string { +func (u *User) Render() string { str := "## user " + u.Name + "\n" + "\n" + " * address = " + string(u.Address) + "\n" + diff --git a/examples/gno.land/r/demo/users/users.gno b/examples/gno.land/r/demo/users/users.gno index 1bf5b55f1f7..4fe486a71d0 100644 --- a/examples/gno.land/r/demo/users/users.gno +++ b/examples/gno.land/r/demo/users/users.gno @@ -265,13 +265,13 @@ func Render(path string) string { // TODO: display basic information about account. return "unknown address " + path } - return user.String() + return user.Render() } else { user := GetUserByName(path) if user == nil { return "unknown username " + path } - return user.String() + return user.Render() } }