diff --git a/docs/reference/stdlibs/std/chain.md b/docs/reference/stdlibs/std/chain.md index 6a1da6483fd..f3b2c6be0b8 100644 --- a/docs/reference/stdlibs/std/chain.md +++ b/docs/reference/stdlibs/std/chain.md @@ -4,18 +4,6 @@ id: chain # Chain-related -## IsOriginCall -```go -func IsOriginCall() bool -``` -Checks if the caller of the function is an EOA. Returns **true** if caller is an EOA, **false** otherwise. - -#### Usage -```go -if !std.IsOriginCall() {...} -``` ---- - ## AssertOriginCall ```go func AssertOriginCall() diff --git a/examples/gno.land/r/demo/banktest/z_0_filetest.gno b/examples/gno.land/r/demo/banktest/z_0_filetest.gno index 5a8c8d70a48..5cf750dfeb9 100644 --- a/examples/gno.land/r/demo/banktest/z_0_filetest.gno +++ b/examples/gno.land/r/demo/banktest/z_0_filetest.gno @@ -10,6 +10,7 @@ package bank1 import ( "std" + "gno.land/p/demo/testutils" "gno.land/r/demo/banktest" ) @@ -29,6 +30,8 @@ func main() { // simulate a Deposit call. use Send + OrigSend to simulate -send. banker.SendCoins(mainaddr, banktestAddr, std.Coins{{"ugnot", 100_000_000}}) std.TestSetOrigSend(std.Coins{{"ugnot", 100_000_000}}, nil) + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) res := banktest.Deposit("ugnot", 50_000_000) println("Deposit():", res) diff --git a/examples/gno.land/r/demo/banktest/z_1_filetest.gno b/examples/gno.land/r/demo/banktest/z_1_filetest.gno index 39682d26330..f2cd6f33ca9 100644 --- a/examples/gno.land/r/demo/banktest/z_1_filetest.gno +++ b/examples/gno.land/r/demo/banktest/z_1_filetest.gno @@ -8,6 +8,7 @@ package bank1 import ( "std" + "gno.land/p/demo/testutils" "gno.land/r/demo/banktest" ) @@ -18,6 +19,8 @@ func main() { std.TestSetOrigPkgAddr(banktestAddr) std.TestIssueCoins(banktestAddr, std.Coins{{"ugnot", 100000000}}) std.TestSetOrigSend(std.Coins{{"ugnot", 100000000}}, nil) + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) res := banktest.Deposit("ugnot", 101000000) println(res) } diff --git a/examples/gno.land/r/demo/banktest/z_2_filetest.gno b/examples/gno.land/r/demo/banktest/z_2_filetest.gno index e839f60354a..8511371823c 100644 --- a/examples/gno.land/r/demo/banktest/z_2_filetest.gno +++ b/examples/gno.land/r/demo/banktest/z_2_filetest.gno @@ -8,6 +8,7 @@ package bank1 import ( "std" + "gno.land/p/demo/testutils" "gno.land/r/demo/banktest" ) @@ -26,6 +27,8 @@ func main() { std.TestSetOrigPkgAddr(banktestAddr) std.TestIssueCoins(banktestAddr, std.Coins{{"ugnot", 100000000}}) std.TestSetOrigSend(std.Coins{{"ugnot", 100000000}}, nil) + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) res := banktest.Deposit("ugnot", 55000000) println("Deposit():", res) diff --git a/examples/gno.land/r/demo/banktest/z_3_filetest.gno b/examples/gno.land/r/demo/banktest/z_3_filetest.gno index 7b6758c3e4f..7bf2aea4f38 100644 --- a/examples/gno.land/r/demo/banktest/z_3_filetest.gno +++ b/examples/gno.land/r/demo/banktest/z_3_filetest.gno @@ -18,7 +18,6 @@ func main() { banker := std.GetBanker(std.BankerTypeRealmSend) send := std.Coins{{"ugnot", 123}} banker.SendCoins(banktestAddr, mainaddr, send) - } // Error: diff --git a/examples/gno.land/r/demo/boards/public.gno b/examples/gno.land/r/demo/boards/public.gno index 1d26126fcb2..db545446641 100644 --- a/examples/gno.land/r/demo/boards/public.gno +++ b/examples/gno.land/r/demo/boards/public.gno @@ -17,7 +17,7 @@ func GetBoardIDFromName(name string) (BoardID, bool) { } func CreateBoard(name string) BoardID { - if !(std.IsOriginCall() || std.PrevRealm().IsUser()) { + if !std.PrevRealm().IsUser() { panic("invalid non-user call") } bid := incGetBoardID() @@ -43,7 +43,7 @@ func checkAnonFee() bool { } func CreateThread(bid BoardID, title string, body string) PostID { - if !(std.IsOriginCall() || std.PrevRealm().IsUser()) { + if !std.PrevRealm().IsUser() { panic("invalid non-user call") } caller := std.GetOrigCaller() @@ -61,7 +61,7 @@ func CreateThread(bid BoardID, title string, body string) PostID { } func CreateReply(bid BoardID, threadid, postid PostID, body string) PostID { - if !(std.IsOriginCall() || std.PrevRealm().IsUser()) { + if !std.PrevRealm().IsUser() { panic("invalid non-user call") } caller := std.GetOrigCaller() @@ -91,7 +91,7 @@ func CreateReply(bid BoardID, threadid, postid PostID, body string) PostID { // If dstBoard is private, does not ping back. // If board specified by bid is private, panics. func CreateRepost(bid BoardID, postid PostID, title string, body string, dstBoardID BoardID) PostID { - if !(std.IsOriginCall() || std.PrevRealm().IsUser()) { + if !std.PrevRealm().IsUser() { panic("invalid non-user call") } caller := std.GetOrigCaller() @@ -121,7 +121,7 @@ func CreateRepost(bid BoardID, postid PostID, title string, body string, dstBoar } func DeletePost(bid BoardID, threadid, postid PostID, reason string) { - if !(std.IsOriginCall() || std.PrevRealm().IsUser()) { + if !std.PrevRealm().IsUser() { panic("invalid non-user call") } caller := std.GetOrigCaller() @@ -153,7 +153,7 @@ func DeletePost(bid BoardID, threadid, postid PostID, reason string) { } func EditPost(bid BoardID, threadid, postid PostID, title, body string) { - if !(std.IsOriginCall() || std.PrevRealm().IsUser()) { + if !std.PrevRealm().IsUser() { panic("invalid non-user call") } caller := std.GetOrigCaller() diff --git a/examples/gno.land/r/demo/boards/z_0_a_filetest.gno b/examples/gno.land/r/demo/boards/z_0_a_filetest.gno index 5e8ff520a54..297231970a5 100644 --- a/examples/gno.land/r/demo/boards/z_0_a_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_0_a_filetest.gno @@ -2,12 +2,17 @@ package boards_test import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" ) var bid boards.BoardID func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) bid = boards.CreateBoard("test_board") boards.CreateThread(bid, "First Post (title)", "Body of the first post. (body)") pid := boards.CreateThread(bid, "Second Post (title)", "Body of the second post. (body)") diff --git a/examples/gno.land/r/demo/boards/z_0_b_filetest.gno b/examples/gno.land/r/demo/boards/z_0_b_filetest.gno index 9bcbe9ffafa..4830161ac71 100644 --- a/examples/gno.land/r/demo/boards/z_0_b_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_0_b_filetest.gno @@ -4,6 +4,9 @@ package boards_test // SEND: 19900000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -11,6 +14,8 @@ import ( var bid boards.BoardID func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") } diff --git a/examples/gno.land/r/demo/boards/z_0_c_filetest.gno b/examples/gno.land/r/demo/boards/z_0_c_filetest.gno index 99fd339aed8..d0b0930240d 100644 --- a/examples/gno.land/r/demo/boards/z_0_c_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_0_c_filetest.gno @@ -4,6 +4,9 @@ package boards_test // SEND: 200000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -11,6 +14,8 @@ import ( var bid boards.BoardID func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") boards.CreateThread(1, "First Post (title)", "Body of the first post. (body)") } diff --git a/examples/gno.land/r/demo/boards/z_0_d_filetest.gno b/examples/gno.land/r/demo/boards/z_0_d_filetest.gno index c77e60e3f3a..7e21f83febd 100644 --- a/examples/gno.land/r/demo/boards/z_0_d_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_0_d_filetest.gno @@ -4,6 +4,9 @@ package boards_test // SEND: 200000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -11,6 +14,8 @@ import ( var bid boards.BoardID func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") boards.CreateReply(bid, 0, 0, "Reply of the second post") diff --git a/examples/gno.land/r/demo/boards/z_0_e_filetest.gno b/examples/gno.land/r/demo/boards/z_0_e_filetest.gno index 6db036e87ba..bdf6d63727b 100644 --- a/examples/gno.land/r/demo/boards/z_0_e_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_0_e_filetest.gno @@ -4,6 +4,9 @@ package boards_test // SEND: 200000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -11,6 +14,8 @@ import ( var bid boards.BoardID func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") boards.CreateReply(bid, 0, 0, "Reply of the second post") } diff --git a/examples/gno.land/r/demo/boards/z_0_filetest.gno b/examples/gno.land/r/demo/boards/z_0_filetest.gno index a649895cb01..977c00e84a6 100644 --- a/examples/gno.land/r/demo/boards/z_0_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_0_filetest.gno @@ -4,6 +4,9 @@ package boards_test // SEND: 20000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -11,6 +14,8 @@ import ( var bid boards.BoardID func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") diff --git a/examples/gno.land/r/demo/boards/z_10_a_filetest.gno b/examples/gno.land/r/demo/boards/z_10_a_filetest.gno index ad57283bfcf..fc04555bf39 100644 --- a/examples/gno.land/r/demo/boards/z_10_a_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_10_a_filetest.gno @@ -4,8 +4,10 @@ package boards_test // SEND: 200000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -16,6 +18,8 @@ var ( ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") @@ -23,6 +27,8 @@ func init() { } func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) // boardId 2 not exist boards.DeletePost(2, pid, pid, "") diff --git a/examples/gno.land/r/demo/boards/z_10_b_filetest.gno b/examples/gno.land/r/demo/boards/z_10_b_filetest.gno index cf8a332174f..2353268ef54 100644 --- a/examples/gno.land/r/demo/boards/z_10_b_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_10_b_filetest.gno @@ -4,8 +4,10 @@ package boards_test // SEND: 200000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -16,6 +18,8 @@ var ( ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") @@ -25,6 +29,8 @@ func init() { func main() { println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) // pid of 2 not exist + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) boards.DeletePost(bid, 2, 2, "") println("----------------------------------------------------") println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) diff --git a/examples/gno.land/r/demo/boards/z_10_c_filetest.gno b/examples/gno.land/r/demo/boards/z_10_c_filetest.gno index 7dd460500d6..c735213b09c 100644 --- a/examples/gno.land/r/demo/boards/z_10_c_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_10_c_filetest.gno @@ -4,8 +4,10 @@ package boards_test // SEND: 200000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -17,6 +19,8 @@ var ( ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") @@ -26,6 +30,8 @@ func init() { func main() { println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) boards.DeletePost(bid, pid, rid, "") println("----------------------------------------------------") println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) diff --git a/examples/gno.land/r/demo/boards/z_10_filetest.gno b/examples/gno.land/r/demo/boards/z_10_filetest.gno index 8a6d11c79cf..e9324cec555 100644 --- a/examples/gno.land/r/demo/boards/z_10_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_10_filetest.gno @@ -4,8 +4,10 @@ package boards_test // SEND: 200000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -16,6 +18,8 @@ var ( ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") @@ -23,6 +27,8 @@ func init() { } func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) boards.DeletePost(bid, pid, pid, "") println("----------------------------------------------------") diff --git a/examples/gno.land/r/demo/boards/z_11_a_filetest.gno b/examples/gno.land/r/demo/boards/z_11_a_filetest.gno index d7dc7b90782..b891e395fe6 100644 --- a/examples/gno.land/r/demo/boards/z_11_a_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_11_a_filetest.gno @@ -4,8 +4,10 @@ package boards_test // SEND: 200000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -16,6 +18,8 @@ var ( ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") @@ -25,6 +29,8 @@ func init() { func main() { println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) // board 2 not exist + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) boards.EditPost(2, pid, pid, "Edited: First Post in (title)", "Edited: Body of the first post. (body)") println("----------------------------------------------------") println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) diff --git a/examples/gno.land/r/demo/boards/z_11_b_filetest.gno b/examples/gno.land/r/demo/boards/z_11_b_filetest.gno index 3aa28095502..9322ac191c5 100644 --- a/examples/gno.land/r/demo/boards/z_11_b_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_11_b_filetest.gno @@ -4,8 +4,10 @@ package boards_test // SEND: 200000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -16,6 +18,8 @@ var ( ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") @@ -25,6 +29,8 @@ func init() { func main() { println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) // thread 2 not exist + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) boards.EditPost(bid, 2, pid, "Edited: First Post in (title)", "Edited: Body of the first post. (body)") println("----------------------------------------------------") println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) diff --git a/examples/gno.land/r/demo/boards/z_11_c_filetest.gno b/examples/gno.land/r/demo/boards/z_11_c_filetest.gno index df764303562..de4f828c1ca 100644 --- a/examples/gno.land/r/demo/boards/z_11_c_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_11_c_filetest.gno @@ -4,8 +4,10 @@ package boards_test // SEND: 200000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -16,6 +18,8 @@ var ( ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") @@ -25,6 +29,8 @@ func init() { func main() { println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) // post 2 not exist + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) boards.EditPost(bid, pid, 2, "Edited: First Post in (title)", "Edited: Body of the first post. (body)") println("----------------------------------------------------") println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) diff --git a/examples/gno.land/r/demo/boards/z_11_d_filetest.gno b/examples/gno.land/r/demo/boards/z_11_d_filetest.gno index f64b4c84bba..b5619f86c5b 100644 --- a/examples/gno.land/r/demo/boards/z_11_d_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_11_d_filetest.gno @@ -4,8 +4,10 @@ package boards_test // SEND: 200000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -17,6 +19,8 @@ var ( ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") @@ -26,6 +30,8 @@ func init() { func main() { println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) boards.EditPost(bid, pid, rid, "", "Edited: First reply of the First post\n") println("----------------------------------------------------") println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) diff --git a/examples/gno.land/r/demo/boards/z_11_filetest.gno b/examples/gno.land/r/demo/boards/z_11_filetest.gno index 3f56293b3bd..1a013d5db22 100644 --- a/examples/gno.land/r/demo/boards/z_11_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_11_filetest.gno @@ -4,8 +4,10 @@ package boards_test // SEND: 200000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -16,6 +18,8 @@ var ( ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") @@ -24,6 +28,8 @@ func init() { func main() { println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) boards.EditPost(bid, pid, pid, "Edited: First Post in (title)", "Edited: Body of the first post. (body)") println("----------------------------------------------------") println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) diff --git a/examples/gno.land/r/demo/boards/z_12_a_filetest.gno b/examples/gno.land/r/demo/boards/z_12_a_filetest.gno index 909be880efa..380e9bc09e0 100644 --- a/examples/gno.land/r/demo/boards/z_12_a_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_12_a_filetest.gno @@ -12,6 +12,8 @@ import ( ) func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") // create a post via registered user bid1 := boards.CreateBoard("test_board1") diff --git a/examples/gno.land/r/demo/boards/z_12_b_filetest.gno b/examples/gno.land/r/demo/boards/z_12_b_filetest.gno index 6b2166895c0..553108df9b3 100644 --- a/examples/gno.land/r/demo/boards/z_12_b_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_12_b_filetest.gno @@ -4,11 +4,16 @@ package boards_test // SEND: 200000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid1 := boards.CreateBoard("test_board1") pid := boards.CreateThread(bid1, "First Post (title)", "Body of the first post. (body)") diff --git a/examples/gno.land/r/demo/boards/z_12_c_filetest.gno b/examples/gno.land/r/demo/boards/z_12_c_filetest.gno index 7397c487d7d..3b2e7ec04c0 100644 --- a/examples/gno.land/r/demo/boards/z_12_c_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_12_c_filetest.gno @@ -4,11 +4,16 @@ package boards_test // SEND: 200000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid1 := boards.CreateBoard("test_board1") boards.CreateThread(bid1, "First Post (title)", "Body of the first post. (body)") diff --git a/examples/gno.land/r/demo/boards/z_12_d_filetest.gno b/examples/gno.land/r/demo/boards/z_12_d_filetest.gno index 37b6473f7ac..20818b05c0f 100644 --- a/examples/gno.land/r/demo/boards/z_12_d_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_12_d_filetest.gno @@ -4,11 +4,16 @@ package boards_test // SEND: 200000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid1 := boards.CreateBoard("test_board1") pid := boards.CreateThread(bid1, "First Post (title)", "Body of the first post. (body)") diff --git a/examples/gno.land/r/demo/boards/z_12_filetest.gno b/examples/gno.land/r/demo/boards/z_12_filetest.gno index ac4adf6ee7b..fe7b58e9348 100644 --- a/examples/gno.land/r/demo/boards/z_12_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_12_filetest.gno @@ -4,6 +4,9 @@ package boards_test // SEND: 200000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -15,6 +18,8 @@ var ( ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid1 = boards.CreateBoard("test_board1") @@ -23,6 +28,8 @@ func init() { } func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) rid := boards.CreateRepost(bid1, pid, "", "Check this out", bid2) println(rid) println(boards.Render("test_board2")) diff --git a/examples/gno.land/r/demo/boards/z_1_filetest.gno b/examples/gno.land/r/demo/boards/z_1_filetest.gno index 4d46c81b83d..6db254c661d 100644 --- a/examples/gno.land/r/demo/boards/z_1_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_1_filetest.gno @@ -4,6 +4,9 @@ package boards_test // SEND: 200000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -11,6 +14,8 @@ import ( var board *boards.Board func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") _ = boards.CreateBoard("test_board_1") diff --git a/examples/gno.land/r/demo/boards/z_2_filetest.gno b/examples/gno.land/r/demo/boards/z_2_filetest.gno index 31b39644b24..0457a0b6b42 100644 --- a/examples/gno.land/r/demo/boards/z_2_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_2_filetest.gno @@ -4,8 +4,10 @@ package boards_test // SEND: 200000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -16,6 +18,8 @@ var ( ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") diff --git a/examples/gno.land/r/demo/boards/z_3_filetest.gno b/examples/gno.land/r/demo/boards/z_3_filetest.gno index 0b2a2df2f91..cffeb9bc29e 100644 --- a/examples/gno.land/r/demo/boards/z_3_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_3_filetest.gno @@ -4,8 +4,10 @@ package boards_test // SEND: 200000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -16,6 +18,8 @@ var ( ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") @@ -24,6 +28,8 @@ func init() { } func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) rid := boards.CreateReply(bid, pid, pid, "Reply of the second post") println(rid) println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) 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 c6cf6397b3a..c7b0223f012 100644 --- a/examples/gno.land/r/demo/boards/z_4_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_4_filetest.gno @@ -4,8 +4,10 @@ package boards_test // SEND: 200000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -16,6 +18,8 @@ var ( ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") @@ -26,6 +30,8 @@ func init() { } func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) rid2 := boards.CreateReply(bid, pid, pid, "Second reply of the second post") println(rid2) println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) diff --git a/examples/gno.land/r/demo/boards/z_5_b_filetest.gno b/examples/gno.land/r/demo/boards/z_5_b_filetest.gno index e79da5c3677..0ad15ca2600 100644 --- a/examples/gno.land/r/demo/boards/z_5_b_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_5_b_filetest.gno @@ -14,6 +14,8 @@ import ( const admin = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") // create board via registered user bid := boards.CreateBoard("test_board") diff --git a/examples/gno.land/r/demo/boards/z_5_c_filetest.gno b/examples/gno.land/r/demo/boards/z_5_c_filetest.gno index 723e6a10204..3817595fb98 100644 --- a/examples/gno.land/r/demo/boards/z_5_c_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_5_c_filetest.gno @@ -14,6 +14,8 @@ import ( const admin = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") // create board via registered user bid := boards.CreateBoard("test_board") diff --git a/examples/gno.land/r/demo/boards/z_5_d_filetest.gno b/examples/gno.land/r/demo/boards/z_5_d_filetest.gno index 54cfe49eec6..33175efd4f2 100644 --- a/examples/gno.land/r/demo/boards/z_5_d_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_5_d_filetest.gno @@ -14,6 +14,8 @@ import ( const admin = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") // create board via registered user bid := boards.CreateBoard("test_board") diff --git a/examples/gno.land/r/demo/boards/z_5_filetest.gno b/examples/gno.land/r/demo/boards/z_5_filetest.gno index 712af483891..c5f33c497fd 100644 --- a/examples/gno.land/r/demo/boards/z_5_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_5_filetest.gno @@ -4,8 +4,10 @@ package boards_test // SEND: 200000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -16,6 +18,8 @@ var ( ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") @@ -25,6 +29,8 @@ func init() { } func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) rid2 := boards.CreateReply(bid, pid, pid, "Second reply of the second post\n") println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) } diff --git a/examples/gno.land/r/demo/boards/z_6_filetest.gno b/examples/gno.land/r/demo/boards/z_6_filetest.gno index ec40cf5f8e9..98bef7091b4 100644 --- a/examples/gno.land/r/demo/boards/z_6_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_6_filetest.gno @@ -4,8 +4,10 @@ package boards_test // SEND: 200000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -17,6 +19,8 @@ var ( ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") @@ -26,6 +30,8 @@ func init() { } func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) boards.CreateReply(bid, pid, pid, "Second reply of the second post\n") boards.CreateReply(bid, pid, rid, "First reply of the first reply\n") println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) diff --git a/examples/gno.land/r/demo/boards/z_7_filetest.gno b/examples/gno.land/r/demo/boards/z_7_filetest.gno index 353b84f6d87..d587447b193 100644 --- a/examples/gno.land/r/demo/boards/z_7_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_7_filetest.gno @@ -4,11 +4,16 @@ package boards_test // SEND: 200000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) // register users.Register("", "gnouser", "my profile") diff --git a/examples/gno.land/r/demo/boards/z_8_filetest.gno b/examples/gno.land/r/demo/boards/z_8_filetest.gno index 4896dfcfccf..33edb30a391 100644 --- a/examples/gno.land/r/demo/boards/z_8_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_8_filetest.gno @@ -4,8 +4,10 @@ package boards_test // SEND: 200000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -17,6 +19,8 @@ var ( ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") @@ -26,6 +30,8 @@ func init() { } func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) boards.CreateReply(bid, pid, pid, "Second reply of the second post\n") rid2 := boards.CreateReply(bid, pid, rid, "First reply of the first reply\n") println(boards.Render("test_board/" + strconv.Itoa(int(pid)) + "/" + strconv.Itoa(int(rid2)))) diff --git a/examples/gno.land/r/demo/boards/z_9_a_filetest.gno b/examples/gno.land/r/demo/boards/z_9_a_filetest.gno index 8d07ba0e710..79f68f20200 100644 --- a/examples/gno.land/r/demo/boards/z_9_a_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_9_a_filetest.gno @@ -4,6 +4,9 @@ package boards_test // SEND: 200000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -11,6 +14,8 @@ import ( var dstBoard boards.BoardID func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") dstBoard = boards.CreateBoard("dst_board") diff --git a/examples/gno.land/r/demo/boards/z_9_b_filetest.gno b/examples/gno.land/r/demo/boards/z_9_b_filetest.gno index 68daf770b4f..703557cf476 100644 --- a/examples/gno.land/r/demo/boards/z_9_b_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_9_b_filetest.gno @@ -4,6 +4,9 @@ package boards_test // SEND: 200000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -14,6 +17,8 @@ var ( ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") srcBoard = boards.CreateBoard("first_board") diff --git a/examples/gno.land/r/demo/boards/z_9_filetest.gno b/examples/gno.land/r/demo/boards/z_9_filetest.gno index ca37e306bda..d7f8adeda30 100644 --- a/examples/gno.land/r/demo/boards/z_9_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_9_filetest.gno @@ -4,8 +4,10 @@ package boards_test // SEND: 200000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -17,6 +19,8 @@ var ( ) func init() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") firstBoard = boards.CreateBoard("first_board") diff --git a/examples/gno.land/r/demo/groups/z_0_a_filetest.gno b/examples/gno.land/r/demo/groups/z_0_a_filetest.gno index 49ebb5219ec..fa27b89e43f 100644 --- a/examples/gno.land/r/demo/groups/z_0_a_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_0_a_filetest.gno @@ -2,12 +2,17 @@ package groups_test import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/groups" ) var gid groups.GroupID func main() { + test := testutils.TestAddress("test") + std.TestSetRealm(std.NewUserRealm(test)) gid = groups.CreateGroup("test_group") println(gid) println(groups.Render("")) diff --git a/examples/gno.land/r/demo/groups/z_0_b_filetest.gno b/examples/gno.land/r/demo/groups/z_0_b_filetest.gno index 6d328825dd6..951e3c1c31c 100644 --- a/examples/gno.land/r/demo/groups/z_0_b_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_0_b_filetest.gno @@ -2,6 +2,9 @@ package groups_test import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/groups" "gno.land/r/demo/users" ) @@ -9,6 +12,8 @@ import ( var gid groups.GroupID func main() { + test := testutils.TestAddress("test") + std.TestSetRealm(std.NewUserRealm(test)) users.Register("", "gnouser", "my profile") gid = groups.CreateGroup("test_group") println(gid) diff --git a/examples/gno.land/r/demo/groups/z_0_c_filetest.gno b/examples/gno.land/r/demo/groups/z_0_c_filetest.gno index 60600e38b78..f6c7d8b15f0 100644 --- a/examples/gno.land/r/demo/groups/z_0_c_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_0_c_filetest.gno @@ -4,6 +4,9 @@ package groups_test // SEND: 200000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/groups" "gno.land/r/demo/users" ) @@ -11,6 +14,8 @@ import ( var gid groups.GroupID func main() { + test := testutils.TestAddress("test") + std.TestSetRealm(std.NewUserRealm(test)) users.Register("", "gnouser", "my profile") gid = groups.CreateGroup("test_group") println(gid) diff --git a/examples/gno.land/r/demo/groups/z_1_a_filetest.gno b/examples/gno.land/r/demo/groups/z_1_a_filetest.gno index 71da1b966ec..0044bff871f 100644 --- a/examples/gno.land/r/demo/groups/z_1_a_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_1_a_filetest.gno @@ -16,7 +16,9 @@ var gid groups.GroupID const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) + std.TestSetOrigCaller(caller) users.Register("", "gnouser0", "my profile 1") std.TestSetOrigCaller(admin) diff --git a/examples/gno.land/r/demo/groups/z_1_b_filetest.gno b/examples/gno.land/r/demo/groups/z_1_b_filetest.gno index 31a036d4e41..e2aad8d0432 100644 --- a/examples/gno.land/r/demo/groups/z_1_b_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_1_b_filetest.gno @@ -4,6 +4,9 @@ package groups_test // SEND: 200000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/groups" "gno.land/r/demo/users" ) @@ -11,6 +14,8 @@ import ( var gid groups.GroupID func main() { + test := testutils.TestAddress("test") + std.TestSetRealm(std.NewUserRealm(test)) users.Register("", "gnouser", "my profile") gid = groups.CreateGroup("test_group") println(gid) diff --git a/examples/gno.land/r/demo/groups/z_1_c_filetest.gno b/examples/gno.land/r/demo/groups/z_1_c_filetest.gno index 6eaabb07cdf..d6269f22160 100644 --- a/examples/gno.land/r/demo/groups/z_1_c_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_1_c_filetest.gno @@ -13,6 +13,8 @@ import ( var gid groups.GroupID func main() { + test := testutils.TestAddress("test") + std.TestSetRealm(std.NewUserRealm(test)) gid = groups.CreateGroup("test_group") println(gid) diff --git a/examples/gno.land/r/demo/groups/z_2_a_filetest.gno b/examples/gno.land/r/demo/groups/z_2_a_filetest.gno index 0c482e1b52f..64540ff396c 100644 --- a/examples/gno.land/r/demo/groups/z_2_a_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_2_a_filetest.gno @@ -16,7 +16,9 @@ var gid groups.GroupID const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) + std.TestSetOrigCaller(caller) users.Register("", "gnouser0", "my profile 1") std.TestSetOrigCaller(admin) diff --git a/examples/gno.land/r/demo/groups/z_2_b_filetest.gno b/examples/gno.land/r/demo/groups/z_2_b_filetest.gno index fd8e485f16f..d6e09d6a404 100644 --- a/examples/gno.land/r/demo/groups/z_2_b_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_2_b_filetest.gno @@ -4,6 +4,9 @@ package groups_test // SEND: 200000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/groups" "gno.land/r/demo/users" ) @@ -11,6 +14,8 @@ import ( var gid groups.GroupID func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") gid = groups.CreateGroup("test_group") println(gid) diff --git a/examples/gno.land/r/demo/groups/z_2_d_filetest.gno b/examples/gno.land/r/demo/groups/z_2_d_filetest.gno index 3caa726cbd3..7aeebbade21 100644 --- a/examples/gno.land/r/demo/groups/z_2_d_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_2_d_filetest.gno @@ -14,6 +14,8 @@ import ( var gid groups.GroupID func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") gid = groups.CreateGroup("test_group") println(gid) diff --git a/examples/gno.land/r/demo/groups/z_2_e_filetest.gno b/examples/gno.land/r/demo/groups/z_2_e_filetest.gno index ff38acf45a4..81da8059496 100644 --- a/examples/gno.land/r/demo/groups/z_2_e_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_2_e_filetest.gno @@ -4,6 +4,9 @@ package groups_test // SEND: 200000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/groups" "gno.land/r/demo/users" ) @@ -11,6 +14,8 @@ import ( var gid groups.GroupID func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") gid = groups.CreateGroup("test_group") println(gid) diff --git a/examples/gno.land/r/demo/groups/z_2_f_filetest.gno b/examples/gno.land/r/demo/groups/z_2_f_filetest.gno index 4fddb768e08..5d7ee304ac7 100644 --- a/examples/gno.land/r/demo/groups/z_2_f_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_2_f_filetest.gno @@ -4,6 +4,9 @@ package groups_test // SEND: 200000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/groups" "gno.land/r/demo/users" ) @@ -11,6 +14,8 @@ import ( var gid groups.GroupID func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") gid = groups.CreateGroup("test_group") println(gid) diff --git a/examples/gno.land/r/demo/groups/z_2_g_filetest.gno b/examples/gno.land/r/demo/groups/z_2_g_filetest.gno index 6230b110c74..6faf70d0064 100644 --- a/examples/gno.land/r/demo/groups/z_2_g_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_2_g_filetest.gno @@ -14,6 +14,9 @@ import ( var gid groups.GroupID func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) + std.TestSetOrigCaller(caller) users.Register("", "gnouser", "my profile") gid = groups.CreateGroup("test_group") println(gid) diff --git a/examples/gno.land/r/demo/tests/subtests/subtests.gno b/examples/gno.land/r/demo/tests/subtests/subtests.gno index 6bf43cba5eb..5043c704017 100644 --- a/examples/gno.land/r/demo/tests/subtests/subtests.gno +++ b/examples/gno.land/r/demo/tests/subtests/subtests.gno @@ -21,5 +21,5 @@ func CallAssertOriginCall() { } func CallIsOriginCall() bool { - return std.IsOriginCall() + return std.PrevRealm().IsUser() } diff --git a/examples/gno.land/r/demo/tests/tests.gno b/examples/gno.land/r/demo/tests/tests.gno index e7fde94ea08..cdeea62de66 100644 --- a/examples/gno.land/r/demo/tests/tests.gno +++ b/examples/gno.land/r/demo/tests/tests.gno @@ -32,7 +32,7 @@ func CallAssertOriginCall() { } func CallIsOriginCall() bool { - return std.IsOriginCall() + return std.PrevRealm().IsUser() } func CallSubtestsAssertOriginCall() { diff --git a/examples/gno.land/r/demo/tests/tests_test.gno b/examples/gno.land/r/demo/tests/tests_test.gno index ccbc6b91265..fa3872744c8 100644 --- a/examples/gno.land/r/demo/tests/tests_test.gno +++ b/examples/gno.land/r/demo/tests/tests_test.gno @@ -1,17 +1,23 @@ -package tests +package tests_test import ( "std" "testing" + + "gno.land/p/demo/testutils" + "gno.land/r/demo/tests" ) func TestAssertOriginCall(t *testing.T) { // CallAssertOriginCall(): no panic - CallAssertOriginCall() - if !CallIsOriginCall() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) + tests.CallAssertOriginCall() + if !tests.CallIsOriginCall() { t.Errorf("expected IsOriginCall=true but got false") } + std.TestSetRealm(std.NewCodeRealm("gno.land/r/demo/tests")) // CallAssertOriginCall() from a block: panic expectedReason := "invalid non-origin call" func() { @@ -23,10 +29,10 @@ func TestAssertOriginCall(t *testing.T) { }() // if called inside a function literal, this is no longer an origin call // because there's one additional frame (the function literal block). - if CallIsOriginCall() { + if tests.CallIsOriginCall() { t.Errorf("expected IsOriginCall=false but got true") } - CallAssertOriginCall() + tests.CallAssertOriginCall() }() // CallSubtestsAssertOriginCall(): panic @@ -36,23 +42,24 @@ func TestAssertOriginCall(t *testing.T) { t.Errorf("expected panic with '%v', got '%v'", expectedReason, r) } }() - if CallSubtestsIsOriginCall() { + if tests.CallSubtestsIsOriginCall() { t.Errorf("expected IsOriginCall=false but got true") } - CallSubtestsAssertOriginCall() + tests.CallSubtestsAssertOriginCall() } func TestPrevRealm(t *testing.T) { var ( - user1Addr = std.DerivePkgAddr("user1.gno") + firstRealm = std.DerivePkgAddr("gno.land/r/demo/tests_test") rTestsAddr = std.DerivePkgAddr("gno.land/r/demo/tests") ) - // When a single realm in the frames, PrevRealm returns the user - if addr := GetPrevRealm().Addr(); addr != user1Addr { - t.Errorf("want GetPrevRealm().Addr==%s, got %s", user1Addr, addr) + // When only one realm in the frames, PrevRealm returns the same realm + if addr := tests.GetPrevRealm().Addr(); addr != firstRealm { + println(tests.GetPrevRealm()) + t.Errorf("want GetPrevRealm().Addr==%s, got %s", firstRealm, addr) } // When 2 or more realms in the frames, PrevRealm returns the second to last - if addr := GetRSubtestsPrevRealm().Addr(); addr != rTestsAddr { + if addr := tests.GetRSubtestsPrevRealm().Addr(); addr != rTestsAddr { t.Errorf("want GetRSubtestsPrevRealm().Addr==%s, got %s", rTestsAddr, addr) } } diff --git a/examples/gno.land/r/demo/users/z_0_b_filetest.gno b/examples/gno.land/r/demo/users/z_0_b_filetest.gno index c33edc32985..2d94596730d 100644 --- a/examples/gno.land/r/demo/users/z_0_b_filetest.gno +++ b/examples/gno.land/r/demo/users/z_0_b_filetest.gno @@ -3,10 +3,15 @@ package main // SEND: 19900000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/users" ) func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "gnouser", "my profile") println("done") } diff --git a/examples/gno.land/r/demo/users/z_0_filetest.gno b/examples/gno.land/r/demo/users/z_0_filetest.gno index cbb2e9209f4..5b0e3108660 100644 --- a/examples/gno.land/r/demo/users/z_0_filetest.gno +++ b/examples/gno.land/r/demo/users/z_0_filetest.gno @@ -3,10 +3,13 @@ package main import ( "std" + "gno.land/p/demo/testutils" "gno.land/r/demo/users" ) func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) std.TestSetOrigSend(std.Coins{std.NewCoin("dontcare", 1)}, nil) users.Register("", "gnouser", "my profile") println("done") diff --git a/examples/gno.land/r/demo/users/z_10_filetest.gno b/examples/gno.land/r/demo/users/z_10_filetest.gno index afeecffcc42..fc5d0b200da 100644 --- a/examples/gno.land/r/demo/users/z_10_filetest.gno +++ b/examples/gno.land/r/demo/users/z_10_filetest.gno @@ -11,7 +11,9 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func init() { - caller := std.GetOrigCaller() // main + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) + std.TestSetOrigCaller(caller) test2 := testutils.TestAddress("test2") // as admin, invite gnouser and test2 std.TestSetOrigCaller(admin) @@ -24,6 +26,7 @@ func init() { func main() { // register as test2 test2 := testutils.TestAddress("test2") + std.TestSetRealm(std.NewUserRealm(test2)) std.TestSetOrigCaller(test2) users.Register(admin, "test222", "my profile 2") println("done") diff --git a/examples/gno.land/r/demo/users/z_11_filetest.gno b/examples/gno.land/r/demo/users/z_11_filetest.gno index 27c7e9813da..6d7bb0f6ef6 100644 --- a/examples/gno.land/r/demo/users/z_11_filetest.gno +++ b/examples/gno.land/r/demo/users/z_11_filetest.gno @@ -5,13 +5,15 @@ package main import ( "std" + "gno.land/p/demo/testutils" "gno.land/r/demo/users" ) const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) std.TestSetOrigCaller(admin) users.AdminAddRestrictedName("superrestricted") diff --git a/examples/gno.land/r/demo/users/z_11b_filetest.gno b/examples/gno.land/r/demo/users/z_11b_filetest.gno index be508963911..b34a83bfc3b 100644 --- a/examples/gno.land/r/demo/users/z_11b_filetest.gno +++ b/examples/gno.land/r/demo/users/z_11b_filetest.gno @@ -5,13 +5,15 @@ package main import ( "std" + "gno.land/p/demo/testutils" "gno.land/r/demo/users" ) const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) std.TestSetOrigCaller(admin) // add restricted name users.AdminAddRestrictedName("superrestricted") diff --git a/examples/gno.land/r/demo/users/z_12_filetest.gno b/examples/gno.land/r/demo/users/z_12_filetest.gno index 0fb7d27bd34..6e5f659e938 100644 --- a/examples/gno.land/r/demo/users/z_12_filetest.gno +++ b/examples/gno.land/r/demo/users/z_12_filetest.gno @@ -3,12 +3,16 @@ package main // SEND: 200000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/users" ) func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) users.Register("", "alicia", "my profile") { diff --git a/examples/gno.land/r/demo/users/z_1_filetest.gno b/examples/gno.land/r/demo/users/z_1_filetest.gno index 504a0c7c3f9..430488d96ee 100644 --- a/examples/gno.land/r/demo/users/z_1_filetest.gno +++ b/examples/gno.land/r/demo/users/z_1_filetest.gno @@ -3,10 +3,16 @@ package main // SEND: 200000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/users" ) func main() { + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) + users.Register("", "gnouser", "my profile") println("done") } diff --git a/examples/gno.land/r/demo/users/z_2_filetest.gno b/examples/gno.land/r/demo/users/z_2_filetest.gno index c1b92790f8b..60b2002ee70 100644 --- a/examples/gno.land/r/demo/users/z_2_filetest.gno +++ b/examples/gno.land/r/demo/users/z_2_filetest.gno @@ -12,7 +12,9 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) + std.TestSetOrigCaller(caller) users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser std.TestSetOrigCaller(admin) diff --git a/examples/gno.land/r/demo/users/z_3_filetest.gno b/examples/gno.land/r/demo/users/z_3_filetest.gno index 5402235e03d..f454b4c00fb 100644 --- a/examples/gno.land/r/demo/users/z_3_filetest.gno +++ b/examples/gno.land/r/demo/users/z_3_filetest.gno @@ -12,7 +12,9 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) + std.TestSetOrigCaller(caller) users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser std.TestSetOrigCaller(admin) diff --git a/examples/gno.land/r/demo/users/z_4_filetest.gno b/examples/gno.land/r/demo/users/z_4_filetest.gno index 613fadf9625..749f44ce6c6 100644 --- a/examples/gno.land/r/demo/users/z_4_filetest.gno +++ b/examples/gno.land/r/demo/users/z_4_filetest.gno @@ -12,7 +12,9 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) + std.TestSetOrigCaller(caller) users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser std.TestSetOrigCaller(admin) diff --git a/examples/gno.land/r/demo/users/z_5_filetest.gno b/examples/gno.land/r/demo/users/z_5_filetest.gno index 6465cc9c378..47aac3bb2af 100644 --- a/examples/gno.land/r/demo/users/z_5_filetest.gno +++ b/examples/gno.land/r/demo/users/z_5_filetest.gno @@ -12,18 +12,23 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) + std.TestSetOrigCaller(caller) users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser std.TestSetOrigCaller(admin) + std.TestSetRealm(std.NewUserRealm(admin)) users.GrantInvites(caller.String() + ":1") // switch back to caller std.TestSetOrigCaller(caller) + std.TestSetRealm(std.NewUserRealm(caller)) // invite another addr test1 := testutils.TestAddress("test1") users.Invite(test1.String()) // switch to test1 std.TestSetOrigCaller(test1) + std.TestSetRealm(std.NewUserRealm(test1)) std.TestSetOrigSend(std.Coins{{"dontcare", 1}}, nil) users.Register(caller, "satoshi", "my other profile") println(users.Render("")) @@ -58,7 +63,7 @@ func main() { // ======================================== // ## user gnouser // -// * address = g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm +// * address = g1vdskcmr9wf047h6lta047h6lta047h6lq5m7fe // * 9 invites // // my profile @@ -68,7 +73,7 @@ func main() { // // * address = g1w3jhxap3ta047h6lta047h6lta047h6l4mfnm7 // * 0 invites -// * invited by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm +// * invited by g1vdskcmr9wf047h6lta047h6lta047h6lq5m7fe // // my other profile // diff --git a/examples/gno.land/r/demo/users/z_6_filetest.gno b/examples/gno.land/r/demo/users/z_6_filetest.gno index 919088088a2..ac19a49b615 100644 --- a/examples/gno.land/r/demo/users/z_6_filetest.gno +++ b/examples/gno.land/r/demo/users/z_6_filetest.gno @@ -3,13 +3,15 @@ package main import ( "std" + "gno.land/p/demo/testutils" "gno.land/r/demo/users" ) const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(admin)) // as admin, grant invites to unregistered user. std.TestSetOrigCaller(admin) users.GrantInvites(caller.String() + ":1") @@ -17,4 +19,4 @@ func main() { } // Error: -// invalid user g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm +// invalid user g1vdskcmr9wf047h6lta047h6lta047h6lq5m7fe diff --git a/examples/gno.land/r/demo/users/z_7_filetest.gno b/examples/gno.land/r/demo/users/z_7_filetest.gno index 1d3c9e3a917..bac1f6df744 100644 --- a/examples/gno.land/r/demo/users/z_7_filetest.gno +++ b/examples/gno.land/r/demo/users/z_7_filetest.gno @@ -12,7 +12,9 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) + std.TestSetOrigCaller(caller) users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser std.TestSetOrigCaller(admin) diff --git a/examples/gno.land/r/demo/users/z_7b_filetest.gno b/examples/gno.land/r/demo/users/z_7b_filetest.gno index 09c15bb135d..f549531717c 100644 --- a/examples/gno.land/r/demo/users/z_7b_filetest.gno +++ b/examples/gno.land/r/demo/users/z_7b_filetest.gno @@ -12,7 +12,9 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) + std.TestSetOrigCaller(caller) users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser std.TestSetOrigCaller(admin) diff --git a/examples/gno.land/r/demo/users/z_8_filetest.gno b/examples/gno.land/r/demo/users/z_8_filetest.gno index 78fada74a71..d2e94c62554 100644 --- a/examples/gno.land/r/demo/users/z_8_filetest.gno +++ b/examples/gno.land/r/demo/users/z_8_filetest.gno @@ -12,7 +12,9 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) + std.TestSetOrigCaller(caller) users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser std.TestSetOrigCaller(admin) diff --git a/examples/gno.land/r/demo/users/z_9_filetest.gno b/examples/gno.land/r/demo/users/z_9_filetest.gno index c73c685aebd..d2895f0b729 100644 --- a/examples/gno.land/r/demo/users/z_9_filetest.gno +++ b/examples/gno.land/r/demo/users/z_9_filetest.gno @@ -10,7 +10,9 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := testutils.TestAddress("caller") + std.TestSetRealm(std.NewUserRealm(caller)) + std.TestSetOrigCaller(caller) test2 := testutils.TestAddress("test2") // as admin, invite gnouser and test2 std.TestSetOrigCaller(admin) diff --git a/gnovm/cmd/gno/testdata/transpile/valid_transpile_file.txtar b/gnovm/cmd/gno/testdata/transpile/valid_transpile_file.txtar index 86cc6f12f7a..b79e7f9a0bc 100644 --- a/gnovm/cmd/gno/testdata/transpile/valid_transpile_file.txtar +++ b/gnovm/cmd/gno/testdata/transpile/valid_transpile_file.txtar @@ -36,7 +36,7 @@ package main import "std" func hello() { - std.AssertOriginCall() + std.GetChainID() } -- main.gno.gen.go.golden -- @@ -61,5 +61,5 @@ package main import "github.com/gnolang/gno/gnovm/stdlibs/std" func hello() { - std.AssertOriginCall(nil) + std.GetChainID(nil) } diff --git a/gnovm/pkg/transpiler/transpiler_test.go b/gnovm/pkg/transpiler/transpiler_test.go index 2a0707f7f79..63b77e49446 100644 --- a/gnovm/pkg/transpiler/transpiler_test.go +++ b/gnovm/pkg/transpiler/transpiler_test.go @@ -344,13 +344,13 @@ func Float32bits(i float32) uint32 func testfunc() { println(Float32bits(3.14159)) - std.AssertOriginCall() + std.GetChainID() } func otherFunc() { std := 1 // This is (incorrectly) changed for now. - std.AssertOriginCall() + std.GetChainID() } `, expectedOutput: ` @@ -363,13 +363,13 @@ import "github.com/gnolang/gno/gnovm/stdlibs/std" func testfunc() { println(Float32bits(3.14159)) - std.AssertOriginCall(nil) + std.GetChainID(nil) } func otherFunc() { std := 1 // This is (incorrectly) changed for now. - std.AssertOriginCall(nil) + std.GetChainID(nil) } `, expectedImports: []*ast.ImportSpec{ @@ -388,11 +388,11 @@ func otherFunc() { source: ` package std -func AssertOriginCall() +func GetChainID() func origCaller() string func testfunc() { - AssertOriginCall() + GetChainID() println(origCaller()) } `, @@ -403,7 +403,7 @@ func testfunc() { package std func testfunc() { - AssertOriginCall(nil) + GetChainID(nil) println(X_origCaller(nil)) } `, diff --git a/gnovm/stdlibs/generated.go b/gnovm/stdlibs/generated.go index 67b492a34b2..90ef55a5315 100644 --- a/gnovm/stdlibs/generated.go +++ b/gnovm/stdlibs/generated.go @@ -416,38 +416,6 @@ var nativeFuncs = [...]NativeFunc{ p0, p1) }, }, - { - "std", - "AssertOriginCall", - []gno.FieldTypeExpr{}, - []gno.FieldTypeExpr{}, - true, - func(m *gno.Machine) { - libs_std.AssertOriginCall( - m, - ) - }, - }, - { - "std", - "IsOriginCall", - []gno.FieldTypeExpr{}, - []gno.FieldTypeExpr{ - {Name: gno.N("r0"), Type: gno.X("bool")}, - }, - true, - func(m *gno.Machine) { - r0 := libs_std.IsOriginCall( - m, - ) - - m.PushValue(gno.Go2GnoValue( - m.Alloc, - m.Store, - reflect.ValueOf(&r0).Elem(), - )) - }, - }, { "std", "GetChainID", diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index 0dcde1148e1..493ade7800e 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -1,14 +1,15 @@ package std -// AssertOriginCall panics if [IsOriginCall] returns false. -func AssertOriginCall() // injected - -// IsOriginCall returns true only if the calling method is invoked via a direct -// MsgCall. It returns false for all other cases, like if the calling method +// AssertOriginCall panics if the calling method is not invoked via a direct +// MsgCall. It doesn't panic for any other cases, like if the calling method // is invoked by another method (even from the same realm or package). -// It also returns false every time when the transaction is broadcasted via +// It also doesn't panic every time when the transaction is broadcasted via // MsgRun. -func IsOriginCall() bool // injected +func AssertOriginCall() { + if !PrevRealm().IsUser() { + panic("invalid non-origin call") + } +} func GetChainID() string // injected func GetChainDomain() string // injected diff --git a/gnovm/stdlibs/std/native.go b/gnovm/stdlibs/std/native.go index fb181d9be31..b32d29c0010 100644 --- a/gnovm/stdlibs/std/native.go +++ b/gnovm/stdlibs/std/native.go @@ -7,22 +7,6 @@ import ( "github.com/gnolang/gno/tm2/pkg/std" ) -func AssertOriginCall(m *gno.Machine) { - if !IsOriginCall(m) { - m.Panic(typedString("invalid non-origin call")) - } -} - -func IsOriginCall(m *gno.Machine) bool { - n := m.NumFrames() - if n == 0 { - return false - } - firstPkg := m.Frames[0].LastPackage - isMsgCall := firstPkg != nil && firstPkg.PkgPath == "main" - return n <= 2 && isMsgCall -} - func GetChainID(m *gno.Machine) string { return GetContext(m).ChainID } diff --git a/gnovm/stdlibs/std/native_test.go b/gnovm/stdlibs/std/native_test.go deleted file mode 100644 index 851785575d7..00000000000 --- a/gnovm/stdlibs/std/native_test.go +++ /dev/null @@ -1,194 +0,0 @@ -package std - -import ( - "testing" - - "github.com/stretchr/testify/assert" - - gno "github.com/gnolang/gno/gnovm/pkg/gnolang" - "github.com/gnolang/gno/tm2/pkg/crypto" -) - -func TestPrevRealmIsOrigin(t *testing.T) { - var ( - user = gno.DerivePkgAddr("user1.gno").Bech32() - ctx = ExecContext{ - OrigCaller: user, - } - msgCallFrame = &gno.Frame{LastPackage: &gno.PackageValue{PkgPath: "main"}} - msgRunFrame = &gno.Frame{LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/g1337/run"}} - ) - tests := []struct { - name string - machine *gno.Machine - expectedAddr crypto.Bech32Address - expectedPkgPath string - expectedIsOriginCall bool - }{ - { - name: "no frames", - machine: &gno.Machine{ - Context: ctx, - Frames: []*gno.Frame{}, - }, - expectedAddr: user, - expectedPkgPath: "", - expectedIsOriginCall: false, - }, - { - name: "one frame w/o LastPackage", - machine: &gno.Machine{ - Context: ctx, - Frames: []*gno.Frame{ - {LastPackage: nil}, - }, - }, - expectedAddr: user, - expectedPkgPath: "", - expectedIsOriginCall: false, - }, - { - name: "one package frame", - machine: &gno.Machine{ - Context: ctx, - Frames: []*gno.Frame{ - {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, - }, - }, - expectedAddr: user, - expectedPkgPath: "", - expectedIsOriginCall: false, - }, - { - name: "one realm frame", - machine: &gno.Machine{ - Context: ctx, - Frames: []*gno.Frame{ - {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, - }, - }, - expectedAddr: user, - expectedPkgPath: "", - expectedIsOriginCall: false, - }, - { - name: "one msgCall frame", - machine: &gno.Machine{ - Context: ctx, - Frames: []*gno.Frame{ - msgCallFrame, - }, - }, - expectedAddr: user, - expectedPkgPath: "", - expectedIsOriginCall: true, - }, - { - name: "one msgRun frame", - machine: &gno.Machine{ - Context: ctx, - Frames: []*gno.Frame{ - msgRunFrame, - }, - }, - expectedAddr: user, - expectedPkgPath: "", - expectedIsOriginCall: false, - }, - { - name: "one package frame and one msgCall frame", - machine: &gno.Machine{ - Context: ctx, - Frames: []*gno.Frame{ - msgCallFrame, - {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, - }, - }, - expectedAddr: user, - expectedPkgPath: "", - expectedIsOriginCall: true, - }, - { - name: "one realm frame and one msgCall frame", - machine: &gno.Machine{ - Context: ctx, - Frames: []*gno.Frame{ - msgCallFrame, - {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, - }, - }, - expectedAddr: user, - expectedPkgPath: "", - expectedIsOriginCall: true, - }, - { - name: "one package frame and one msgRun frame", - machine: &gno.Machine{ - Context: ctx, - Frames: []*gno.Frame{ - msgRunFrame, - {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, - }, - }, - expectedAddr: user, - expectedPkgPath: "", - expectedIsOriginCall: false, - }, - { - name: "one realm frame and one msgRun frame", - machine: &gno.Machine{ - Context: ctx, - Frames: []*gno.Frame{ - msgRunFrame, - {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, - }, - }, - expectedAddr: user, - expectedPkgPath: "", - expectedIsOriginCall: false, - }, - { - name: "multiple frames with one realm", - machine: &gno.Machine{ - Context: ctx, - Frames: []*gno.Frame{ - {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, - {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, - {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, - }, - }, - expectedAddr: user, - expectedPkgPath: "", - expectedIsOriginCall: false, - }, - { - name: "multiple frames with multiple realms", - machine: &gno.Machine{ - Context: ctx, - Frames: []*gno.Frame{ - {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/zzz"}}, - {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/zzz"}}, - {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/yyy"}}, - {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/yyy"}}, - {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, - {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, - }, - }, - expectedAddr: gno.DerivePkgAddr("gno.land/r/yyy").Bech32(), - expectedPkgPath: "gno.land/r/yyy", - expectedIsOriginCall: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - assert := assert.New(t) - - addr, pkgPath := X_getRealm(tt.machine, 1) - isOrigin := IsOriginCall(tt.machine) - - assert.Equal(string(tt.expectedAddr), addr) - assert.Equal(tt.expectedPkgPath, pkgPath) - assert.Equal(tt.expectedIsOriginCall, isOrigin) - }) - } -} diff --git a/gnovm/tests/files/std5.gno b/gnovm/tests/files/std5.gno index e339d7a6364..926fb87f95b 100644 --- a/gnovm/tests/files/std5.gno +++ b/gnovm/tests/files/std5.gno @@ -13,10 +13,10 @@ func main() { // Stacktrace: // panic: frame not found -// callerAt(n) +// callerAt(n) // gonative:std.callerAt // std.GetCallerAt(2) -// std/native.gno:45 +// std/native.gno:46 // main() // main/files/std5.gno:10 diff --git a/gnovm/tests/files/std8.gno b/gnovm/tests/files/std8.gno index ee717bf16be..0bba25a0eb9 100644 --- a/gnovm/tests/files/std8.gno +++ b/gnovm/tests/files/std8.gno @@ -23,10 +23,10 @@ func main() { // Stacktrace: // panic: frame not found -// callerAt(n) +// callerAt(n) // gonative:std.callerAt // std.GetCallerAt(4) -// std/native.gno:45 +// std/native.gno:46 // fn() // main/files/std8.gno:16 // testutils.WrapCall(inner) diff --git a/gnovm/tests/files/std9.gno b/gnovm/tests/files/std9.gno index 95ccfb2c8a4..2f9f848ec5d 100644 --- a/gnovm/tests/files/std9.gno +++ b/gnovm/tests/files/std9.gno @@ -11,4 +11,4 @@ func main() { } // Output: -// invalid non-origin call +// undefined diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index 8e5f641e734..3b7e2b5217e 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -69,7 +69,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "a7f5397443359ea76c50be82c77f1f893a060925:9" +// "ObjectID": "a7f5397443359ea76c50be82c77f1f893a060925:8" // }, // "FileName": "native.gno", // "IsMethod": false, @@ -83,7 +83,7 @@ func main() { // "Location": { // "Column": "1", // "File": "native.gno", -// "Line": "13", +// "Line": "14", // "PkgPath": "std" // } // }, diff --git a/gnovm/tests/stdlibs/generated.go b/gnovm/tests/stdlibs/generated.go index db5ecdec05d..14575fad4ab 100644 --- a/gnovm/tests/stdlibs/generated.go +++ b/gnovm/tests/stdlibs/generated.go @@ -31,38 +31,6 @@ func (n *NativeFunc) HasMachineParam() bool { } var nativeFuncs = [...]NativeFunc{ - { - "std", - "AssertOriginCall", - []gno.FieldTypeExpr{}, - []gno.FieldTypeExpr{}, - true, - func(m *gno.Machine) { - testlibs_std.AssertOriginCall( - m, - ) - }, - }, - { - "std", - "IsOriginCall", - []gno.FieldTypeExpr{}, - []gno.FieldTypeExpr{ - {Name: gno.N("r0"), Type: gno.X("bool")}, - }, - true, - func(m *gno.Machine) { - r0 := testlibs_std.IsOriginCall( - m, - ) - - m.PushValue(gno.Go2GnoValue( - m.Alloc, - m.Store, - reflect.ValueOf(&r0).Elem(), - )) - }, - }, { "std", "TestSkipHeights", diff --git a/gnovm/tests/stdlibs/std/std.gno b/gnovm/tests/stdlibs/std/std.gno index dcb5a64dbb3..a8695e149a6 100644 --- a/gnovm/tests/stdlibs/std/std.gno +++ b/gnovm/tests/stdlibs/std/std.gno @@ -1,7 +1,5 @@ package std -func AssertOriginCall() // injected -func IsOriginCall() bool // injected func TestSkipHeights(count int64) // injected func TestSetOrigCaller(addr Address) { testSetOrigCaller(string(addr)) } diff --git a/gnovm/tests/stdlibs/std/std.go b/gnovm/tests/stdlibs/std/std.go index 675194b252f..f9b4a3bea81 100644 --- a/gnovm/tests/stdlibs/std/std.go +++ b/gnovm/tests/stdlibs/std/std.go @@ -2,7 +2,6 @@ package std import ( "fmt" - "strings" gno "github.com/gnolang/gno/gnovm/pkg/gnolang" "github.com/gnolang/gno/gnovm/stdlibs/std" @@ -25,43 +24,12 @@ type RealmOverride struct { PkgPath string } -func AssertOriginCall(m *gno.Machine) { - if !IsOriginCall(m) { - m.Panic(typedString("invalid non-origin call")) - } -} - func typedString(s gno.StringValue) gno.TypedValue { tv := gno.TypedValue{T: gno.StringType} tv.SetString(s) return tv } -func IsOriginCall(m *gno.Machine) bool { - tname := m.Frames[0].Func.Name - switch tname { - case "main": // test is a _filetest - // 0. main - // 1. $RealmFuncName - // 2. std.IsOriginCall - return len(m.Frames) == 3 - case "RunTest": // test is a _test - // 0. testing.RunTest - // 1. tRunner - // 2. $TestFuncName - // 3. $RealmFuncName - // 4. std.IsOriginCall - return len(m.Frames) == 5 - } - // support init() in _filetest - // XXX do we need to distinguish from 'runtest'/_test? - // XXX pretty hacky even if not. - if strings.HasPrefix(string(tname), "init.") { - return len(m.Frames) == 3 - } - panic("unable to determine if test is a _test or a _filetest") -} - func TestSkipHeights(m *gno.Machine, count int64) { ctx := m.Context.(*TestExecContext) ctx.Height += count