From 9c5b56b44eb7f368aa93ba24e030caaebf9307e1 Mon Sep 17 00:00:00 2001 From: Omar Sy Date: Sat, 21 Dec 2024 02:00:12 +0100 Subject: [PATCH 1/8] refactor(std): replace IsOriginCall with PrevRealm().IsUser() for EOA checks --- docs/reference/stdlibs/std/chain.md | 12 -- .../gno.land/r/demo/banktest/z_0_filetest.gno | 3 + .../gno.land/r/demo/banktest/z_1_filetest.gno | 3 + .../gno.land/r/demo/banktest/z_2_filetest.gno | 3 + .../gno.land/r/demo/banktest/z_3_filetest.gno | 1 - examples/gno.land/r/demo/boards/public.gno | 12 +- .../gno.land/r/demo/boards/z_0_a_filetest.gno | 5 + .../gno.land/r/demo/boards/z_0_b_filetest.gno | 5 + .../gno.land/r/demo/boards/z_0_c_filetest.gno | 5 + .../gno.land/r/demo/boards/z_0_d_filetest.gno | 5 + .../gno.land/r/demo/boards/z_0_e_filetest.gno | 5 + .../gno.land/r/demo/boards/z_0_filetest.gno | 5 + .../r/demo/boards/z_10_a_filetest.gno | 6 + .../r/demo/boards/z_10_b_filetest.gno | 6 + .../r/demo/boards/z_10_c_filetest.gno | 6 + .../gno.land/r/demo/boards/z_10_filetest.gno | 6 + .../r/demo/boards/z_11_a_filetest.gno | 6 + .../r/demo/boards/z_11_b_filetest.gno | 6 + .../r/demo/boards/z_11_c_filetest.gno | 6 + .../r/demo/boards/z_11_d_filetest.gno | 6 + .../gno.land/r/demo/boards/z_11_filetest.gno | 6 + .../r/demo/boards/z_12_a_filetest.gno | 2 + .../r/demo/boards/z_12_b_filetest.gno | 5 + .../r/demo/boards/z_12_c_filetest.gno | 5 + .../r/demo/boards/z_12_d_filetest.gno | 5 + .../gno.land/r/demo/boards/z_12_filetest.gno | 7 + .../gno.land/r/demo/boards/z_1_filetest.gno | 5 + .../gno.land/r/demo/boards/z_2_filetest.gno | 4 + .../gno.land/r/demo/boards/z_3_filetest.gno | 6 + .../gno.land/r/demo/boards/z_4_filetest.gno | 6 + .../gno.land/r/demo/boards/z_5_b_filetest.gno | 2 + .../gno.land/r/demo/boards/z_5_c_filetest.gno | 2 + .../gno.land/r/demo/boards/z_5_d_filetest.gno | 2 + .../gno.land/r/demo/boards/z_5_filetest.gno | 6 + .../gno.land/r/demo/boards/z_6_filetest.gno | 6 + .../gno.land/r/demo/boards/z_7_filetest.gno | 5 + .../gno.land/r/demo/boards/z_8_filetest.gno | 6 + .../gno.land/r/demo/boards/z_9_a_filetest.gno | 5 + .../gno.land/r/demo/boards/z_9_b_filetest.gno | 5 + .../gno.land/r/demo/boards/z_9_filetest.gno | 4 + .../gno.land/r/demo/groups/z_0_a_filetest.gno | 5 + .../gno.land/r/demo/groups/z_0_b_filetest.gno | 5 + .../gno.land/r/demo/groups/z_0_c_filetest.gno | 5 + .../gno.land/r/demo/groups/z_1_a_filetest.gno | 4 +- .../gno.land/r/demo/groups/z_1_b_filetest.gno | 5 + .../gno.land/r/demo/groups/z_1_c_filetest.gno | 2 + .../gno.land/r/demo/groups/z_2_a_filetest.gno | 4 +- .../gno.land/r/demo/groups/z_2_b_filetest.gno | 5 + .../gno.land/r/demo/groups/z_2_d_filetest.gno | 2 + .../gno.land/r/demo/groups/z_2_e_filetest.gno | 5 + .../gno.land/r/demo/groups/z_2_f_filetest.gno | 5 + .../gno.land/r/demo/groups/z_2_g_filetest.gno | 3 + .../r/demo/tests/subtests/subtests.gno | 2 +- examples/gno.land/r/demo/tests/tests.gno | 2 +- examples/gno.land/r/demo/tests/tests_test.gno | 31 +-- .../gno.land/r/demo/users/z_0_b_filetest.gno | 5 + .../gno.land/r/demo/users/z_0_filetest.gno | 3 + .../gno.land/r/demo/users/z_10_filetest.gno | 5 +- .../gno.land/r/demo/users/z_11_filetest.gno | 4 +- .../gno.land/r/demo/users/z_11b_filetest.gno | 4 +- .../gno.land/r/demo/users/z_12_filetest.gno | 4 + .../gno.land/r/demo/users/z_1_filetest.gno | 6 + .../gno.land/r/demo/users/z_2_filetest.gno | 4 +- .../gno.land/r/demo/users/z_3_filetest.gno | 4 +- .../gno.land/r/demo/users/z_4_filetest.gno | 4 +- .../gno.land/r/demo/users/z_5_filetest.gno | 11 +- .../gno.land/r/demo/users/z_6_filetest.gno | 6 +- .../gno.land/r/demo/users/z_7_filetest.gno | 4 +- .../gno.land/r/demo/users/z_7b_filetest.gno | 4 +- .../gno.land/r/demo/users/z_8_filetest.gno | 4 +- .../gno.land/r/demo/users/z_9_filetest.gno | 4 +- .../transpile/valid_transpile_file.txtar | 4 +- gnovm/pkg/transpiler/transpiler_test.go | 14 +- gnovm/stdlibs/generated.go | 32 --- gnovm/stdlibs/std/native.gno | 15 +- gnovm/stdlibs/std/native.go | 16 -- gnovm/stdlibs/std/native_test.go | 194 ------------------ gnovm/tests/files/std5.gno | 4 +- gnovm/tests/files/std8.gno | 4 +- gnovm/tests/files/std9.gno | 2 +- gnovm/tests/files/zrealm_natbind0.gno | 4 +- gnovm/tests/stdlibs/generated.go | 32 --- gnovm/tests/stdlibs/std/std.gno | 2 - gnovm/tests/stdlibs/std/std.go | 32 --- 84 files changed, 341 insertions(+), 381 deletions(-) delete mode 100644 gnovm/stdlibs/std/native_test.go 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 From d9f9dfe754e09c3be1d75e769ca022ac188d8449 Mon Sep 17 00:00:00 2001 From: Omar Sy Date: Thu, 26 Dec 2024 21:48:54 +0100 Subject: [PATCH 2/8] test: update assert origin call test --- .../testdata/assertorigincall.txtar | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/gno.land/pkg/integration/testdata/assertorigincall.txtar b/gno.land/pkg/integration/testdata/assertorigincall.txtar index 2c4a27f9d06..430d39a9a0e 100644 --- a/gno.land/pkg/integration/testdata/assertorigincall.txtar +++ b/gno.land/pkg/integration/testdata/assertorigincall.txtar @@ -3,7 +3,7 @@ # # | Num | Msg Type | Call from | Entry Point | Result | # |-----|:--------:|:-------------------:|:----------------------:|:------:| -# | 1 | MsgCall | wallet direct | myrealm.A() | PANIC | +# | 1 | MsgCall | wallet direct | myrealm.A() | pass | # | 2 | | | myrealm.B() | pass | # | 3 | | | myrealm.C() | pass | # | 4 | | through /r/foo | myrealm.A() | PANIC | @@ -12,17 +12,17 @@ # | 7 | | through /p/demo/bar | bar.A() | PANIC | # | 8 | | | bar.B() | pass | # | 9 | | | bar.C() | PANIC | -# | 10 | MsgRun | wallet direct | myrealm.A() | PANIC | +# | 10 | MsgRun | wallet direct | myrealm.A() | pass | # | 11 | | | myrealm.B() | pass | -# | 12 | | | myrealm.C() | PANIC | +# | 12 | | | myrealm.C() | pass | # | 13 | | through /r/foo | myrealm.A() | PANIC | # | 14 | | | myrealm.B() | pass | # | 15 | | | myrealm.C() | PANIC | -# | 16 | | through /p/demo/bar | bar.A() | PANIC | +# | 16 | | through /p/demo/bar | bar.A() | pass | # | 17 | | | bar.B() | pass | # | 18 | | | bar.C() | PANIC | # | 19 | MsgCall | wallet direct | std.AssertOriginCall() | pass | -# | 20 | MsgRun | wallet direct | std.AssertOriginCall() | PANIC | +# | 20 | MsgRun | wallet direct | std.AssertOriginCall() | pass | # Init ## set up and start a new node @@ -34,9 +34,9 @@ gnoland start # The PANIC is expected to fail at the transaction simulation stage, which is why we set gas-wanted to 1. # Test cases -## 1. MsgCall -> myrlm.A: PANIC -! gnokey maketx call -pkgpath gno.land/r/myrlm -func A -gas-fee 100000ugnot -gas-wanted 1 -broadcast -chainid tendermint_test test1 -stderr 'invalid non-origin call' +## 1. MsgCall -> myrlm.A: PASS +gnokey maketx call -pkgpath gno.land/r/myrlm -func A -gas-fee 100000ugnot -gas-wanted 1000000 -broadcast -chainid tendermint_test test1 +stdout 'OK!' ## 2. MsgCall -> myrlm.B: PASS gnokey maketx call -pkgpath gno.land/r/myrlm -func B -gas-fee 100000ugnot -gas-wanted 150000 -broadcast -chainid tendermint_test test1 @@ -71,17 +71,17 @@ stderr 'invalid non-origin call' ## ! gnokey maketx call -pkgpath gno.land/p/demo/bar -func C -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 ## stderr 'invalid non-origin call' -## 10. MsgRun -> run.main -> myrlm.A: PANIC -! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmA.gno -stderr 'invalid non-origin call' +## 10. MsgRun -> run.main -> myrlm.A: PASS +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmA.gno +stdout 'OK!' ## 11. MsgRun -> run.main -> myrlm.B: PASS gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmB.gno stdout 'OK!' -## 12. MsgRun -> run.main -> myrlm.C: PANIC -! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmC.gno -stderr 'invalid non-origin call' +## 12. MsgRun -> run.main -> myrlm.C: PASS +## gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmC.gno +stdout 'OK!' ## 13. MsgRun -> run.main -> foo.A: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/fooA.gno @@ -95,26 +95,26 @@ stdout 'OK!' ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/fooC.gno stderr 'invalid non-origin call' -## 16. MsgRun -> run.main -> bar.A: PANIC -! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/barA.gno -stderr 'invalid non-origin call' +## 16. MsgRun -> run.main -> bar.A: PASS +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/barA.gno +stdout 'OK!' ## 17. MsgRun -> run.main -> bar.B: PASS gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/barB.gno stdout 'OK!' -## 18. MsgRun -> run.main -> bar.C: PANIC -! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/barC.gno -stderr 'invalid non-origin call' +## 18. MsgRun -> run.main -> bar.C: PASS +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/barC.gno +stdout 'OK!' ## remove testcase 19 due to maketx call forced to call a realm -## 19. MsgCall -> std.AssertOriginCall: pass +## 19. MsgCall -> std.AssertOriginCall: PASS ## gnokey maketx call -pkgpath std -func AssertOriginCall -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 ## stdout 'OK!' -## 20. MsgRun -> std.AssertOriginCall: PANIC -! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno -stderr 'invalid non-origin call' +## 20. MsgRun -> std.AssertOriginCall: PASS +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno +stdout 'OK!' -- r/myrlm/rlm.gno -- From 5163144ac576fc1d8c3ea26924483356e2ec07af Mon Sep 17 00:00:00 2001 From: Omar Sy Date: Thu, 26 Dec 2024 21:55:04 +0100 Subject: [PATCH 3/8] fix(std): correct comment in AssertOriginCall function --- gnovm/stdlibs/std/native.gno | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index 493ade7800e..0d7ffbd1250 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -3,7 +3,7 @@ package std // 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 doesn't panic every time when the transaction is broadcasted via +// It also panic every time when the transaction is broadcasted via // MsgRun. func AssertOriginCall() { if !PrevRealm().IsUser() { From d55c5a0e7508258b65385c57764034dc45fbf918 Mon Sep 17 00:00:00 2001 From: Omar Sy Date: Sat, 18 Jan 2025 22:58:50 +0100 Subject: [PATCH 4/8] feat(std): add isMsgRun function and update AssertOriginCall to handle MsgRun cases --- .../testdata/assertorigincall.txtar | 38 +++++++++---------- gnovm/stdlibs/generated.go | 20 ++++++++++ gnovm/stdlibs/std/native.gno | 4 +- gnovm/stdlibs/std/native.go | 9 +++++ gnovm/tests/files/std5.gno | 2 +- gnovm/tests/files/std8.gno | 2 +- gnovm/tests/stdlibs/std/std.gno | 6 +++ 7 files changed, 58 insertions(+), 23 deletions(-) diff --git a/gno.land/pkg/integration/testdata/assertorigincall.txtar b/gno.land/pkg/integration/testdata/assertorigincall.txtar index cde977ff245..bf7ebe544d5 100644 --- a/gno.land/pkg/integration/testdata/assertorigincall.txtar +++ b/gno.land/pkg/integration/testdata/assertorigincall.txtar @@ -12,17 +12,17 @@ # | 7 | | through /p/demo/bar | bar.A() | PANIC | # | 8 | | | bar.B() | pass | # | 9 | | | bar.C() | PANIC | -# | 10 | MsgRun | wallet direct | myrealm.A() | pass | +# | 10 | MsgRun | wallet direct | myrealm.A() | PANIC | # | 11 | | | myrealm.B() | pass | -# | 12 | | | myrealm.C() | pass | +# | 12 | | | myrealm.C() | PANIC | # | 13 | | through /r/foo | myrealm.A() | PANIC | # | 14 | | | myrealm.B() | pass | # | 15 | | | myrealm.C() | PANIC | -# | 16 | | through /p/demo/bar | bar.A() | pass | +# | 16 | | through /p/demo/bar | bar.A() | PANIC | # | 17 | | | bar.B() | pass | # | 18 | | | bar.C() | PANIC | # | 19 | MsgCall | wallet direct | std.AssertOriginCall() | pass | -# | 20 | MsgRun | wallet direct | std.AssertOriginCall() | pass | +# | 20 | MsgRun | wallet direct | std.AssertOriginCall() | PANIC | # Init ## set up and start a new node @@ -71,17 +71,17 @@ stderr 'invalid non-origin call' ## ! gnokey maketx call -pkgpath gno.land/p/demo/bar -func C -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 ## stderr 'invalid non-origin call' -## 10. MsgRun -> run.main -> myrlm.A: PASS -gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmA.gno -stdout 'OK!' +## 10. MsgRun -> run.main -> myrlm.A: PANIC +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmA.gno +## stderr 'invalid non-origin call' ## 11. MsgRun -> run.main -> myrlm.B: PASS gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmB.gno stdout 'OK!' -## 12. MsgRun -> run.main -> myrlm.C: PASS -## gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmC.gno -stdout 'OK!' +## 12. MsgRun -> run.main -> myrlm.C: PANIC +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmC.gno +stderr 'invalid non-origin call' ## 13. MsgRun -> run.main -> foo.A: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/fooA.gno @@ -95,26 +95,26 @@ stdout 'OK!' ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/fooC.gno stderr 'invalid non-origin call' -## 16. MsgRun -> run.main -> bar.A: PASS -gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/barA.gno -stdout 'OK!' +## 16. MsgRun -> run.main -> bar.A: PANIC +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/barA.gno +stderr 'invalid non-origin call' ## 17. MsgRun -> run.main -> bar.B: PASS gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/barB.gno stdout 'OK!' -## 18. MsgRun -> run.main -> bar.C: PASS -gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/barC.gno -stdout 'OK!' +## 18. MsgRun -> run.main -> bar.C: PANIC +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/barC.gno +stderr 'invalid non-origin call' ## remove testcase 19 due to maketx call forced to call a realm ## 19. MsgCall -> std.AssertOriginCall: PASS ## gnokey maketx call -pkgpath std -func AssertOriginCall -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 ## stdout 'OK!' -## 20. MsgRun -> std.AssertOriginCall: PASS -gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno -stdout 'OK!' +## 20. MsgRun -> std.AssertOriginCall: PANIC +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno +stderr 'invalid non-origin call' -- r/myrlm/rlm.gno -- diff --git a/gnovm/stdlibs/generated.go b/gnovm/stdlibs/generated.go index b536aa15424..d9e0c495c83 100644 --- a/gnovm/stdlibs/generated.go +++ b/gnovm/stdlibs/generated.go @@ -620,6 +620,26 @@ var nativeFuncs = [...]NativeFunc{ ) }, }, + { + "std", + "isMsgRun", + []gno.FieldTypeExpr{}, + []gno.FieldTypeExpr{ + {Name: gno.N("r0"), Type: gno.X("bool")}, + }, + true, + func(m *gno.Machine) { + r0 := libs_std.X_isMsgRun( + m, + ) + + m.PushValue(gno.Go2GnoValue( + m.Alloc, + m.Store, + reflect.ValueOf(&r0).Elem(), + )) + }, + }, { "std", "setParamString", diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index eb0df5bd344..34da2b7226e 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -6,11 +6,10 @@ package std // It also panic every time when the transaction is broadcasted via // MsgRun. func AssertOriginCall() { - if !PrevRealm().IsUser() { + if !PrevRealm().IsUser() || isMsgRun() { panic("invalid non-origin call") } } - func GetChainID() string // injected func GetChainDomain() string // injected func GetHeight() int64 // injected @@ -53,3 +52,4 @@ func origPkgAddr() string func callerAt(n int) string func getRealm(height int) (address string, pkgPath string) func assertCallerIsRealm() +func isMsgRun() bool diff --git a/gnovm/stdlibs/std/native.go b/gnovm/stdlibs/std/native.go index f60d1cbe1ff..c79c8e2d5a8 100644 --- a/gnovm/stdlibs/std/native.go +++ b/gnovm/stdlibs/std/native.go @@ -14,6 +14,15 @@ func GetChainDomain(m *gno.Machine) string { return GetContext(m).ChainDomain } +func X_isMsgRun(m *gno.Machine) bool { + n := m.NumFrames() + if n == 0 { + return false + } + + return m.Frames[0].LastPackage.PkgPath != "main" +} + func GetHeight(m *gno.Machine) int64 { return GetContext(m).Height } diff --git a/gnovm/tests/files/std5.gno b/gnovm/tests/files/std5.gno index fb0903f3740..a33ed111f8f 100644 --- a/gnovm/tests/files/std5.gno +++ b/gnovm/tests/files/std5.gno @@ -16,7 +16,7 @@ func main() { // callerAt(n) // gonative:std.callerAt // std.GetCallerAt(2) -// std/native.gno:46 +// std/native.gno:45 // main() // main/files/std5.gno:10 diff --git a/gnovm/tests/files/std8.gno b/gnovm/tests/files/std8.gno index 8398e4caa2a..11efb6bc65d 100644 --- a/gnovm/tests/files/std8.gno +++ b/gnovm/tests/files/std8.gno @@ -26,7 +26,7 @@ func main() { // callerAt(n) // gonative:std.callerAt // std.GetCallerAt(4) -// std/native.gno:46 +// std/native.gno:45 // fn() // main/files/std8.gno:16 // testutils.WrapCall(inner) diff --git a/gnovm/tests/stdlibs/std/std.gno b/gnovm/tests/stdlibs/std/std.gno index a8695e149a6..c96e5f00de5 100644 --- a/gnovm/tests/stdlibs/std/std.gno +++ b/gnovm/tests/stdlibs/std/std.gno @@ -5,6 +5,12 @@ func TestSkipHeights(count int64) // injected func TestSetOrigCaller(addr Address) { testSetOrigCaller(string(addr)) } func TestSetOrigPkgAddr(addr Address) { testSetOrigPkgAddr(string(addr)) } +func AssertOriginCall() { + if !PrevRealm().IsUser() { + panic("invalid non-origin call") + } +} + // TestSetRealm sets the realm for the current frame. // After calling TestSetRealm, calling CurrentRealm() in the test function will yield the value of // rlm, while if a realm function is called, using PrevRealm() will yield rlm. From 5d1c3e8db79c5ada5b35578597952802d4d75c7e Mon Sep 17 00:00:00 2001 From: Omar Sy Date: Mon, 20 Jan 2025 21:43:40 +0100 Subject: [PATCH 5/8] revert change --- .../gno.land/r/demo/banktest/z_0_filetest.gno | 3 - .../gno.land/r/demo/banktest/z_1_filetest.gno | 3 - .../gno.land/r/demo/banktest/z_2_filetest.gno | 3 - .../gno.land/r/demo/groups/z_0_a_filetest.gno | 5 - .../gno.land/r/demo/groups/z_0_b_filetest.gno | 5 - .../gno.land/r/demo/groups/z_0_c_filetest.gno | 5 - .../gno.land/r/demo/groups/z_1_a_filetest.gno | 4 +- .../gno.land/r/demo/groups/z_1_b_filetest.gno | 5 - .../gno.land/r/demo/groups/z_1_c_filetest.gno | 2 - .../gno.land/r/demo/groups/z_2_a_filetest.gno | 4 +- .../gno.land/r/demo/groups/z_2_b_filetest.gno | 5 - .../gno.land/r/demo/groups/z_2_d_filetest.gno | 2 - .../gno.land/r/demo/groups/z_2_e_filetest.gno | 5 - .../gno.land/r/demo/groups/z_2_f_filetest.gno | 5 - .../gno.land/r/demo/groups/z_2_g_filetest.gno | 3 - .../gno.land/r/demo/users/z_0_b_filetest.gno | 5 - .../gno.land/r/demo/users/z_0_filetest.gno | 3 - .../gno.land/r/demo/users/z_10_filetest.gno | 5 +- .../gno.land/r/demo/users/z_11_filetest.gno | 4 +- .../gno.land/r/demo/users/z_11b_filetest.gno | 4 +- .../gno.land/r/demo/users/z_12_filetest.gno | 4 - .../gno.land/r/demo/users/z_1_filetest.gno | 6 - .../gno.land/r/demo/users/z_2_filetest.gno | 4 +- .../gno.land/r/demo/users/z_3_filetest.gno | 4 +- .../gno.land/r/demo/users/z_4_filetest.gno | 4 +- .../gno.land/r/demo/users/z_5_filetest.gno | 8 +- .../gno.land/r/demo/users/z_6_filetest.gno | 6 +- .../gno.land/r/demo/users/z_7_filetest.gno | 4 +- .../gno.land/r/demo/users/z_7b_filetest.gno | 4 +- .../gno.land/r/demo/users/z_8_filetest.gno | 4 +- .../gno.land/r/demo/users/z_9_filetest.gno | 4 +- .../testdata/assertorigincall.txtar | 66 +----- gnovm/stdlibs/generated.go | 32 ++- gnovm/stdlibs/std/native.gno | 7 +- gnovm/stdlibs/std/native.go | 13 +- gnovm/stdlibs/std/native_test.go | 194 ++++++++++++++++++ gnovm/tests/files/std5.gno | 2 +- gnovm/tests/files/std8.gno | 2 +- gnovm/tests/files/std9.gno | 2 +- gnovm/tests/stdlibs/generated.go | 12 ++ gnovm/tests/stdlibs/std/std.gno | 7 +- gnovm/tests/stdlibs/std/std.go | 32 +++ 42 files changed, 292 insertions(+), 209 deletions(-) create mode 100644 gnovm/stdlibs/std/native_test.go 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 5cf750dfeb9..5a8c8d70a48 100644 --- a/examples/gno.land/r/demo/banktest/z_0_filetest.gno +++ b/examples/gno.land/r/demo/banktest/z_0_filetest.gno @@ -10,7 +10,6 @@ package bank1 import ( "std" - "gno.land/p/demo/testutils" "gno.land/r/demo/banktest" ) @@ -30,8 +29,6 @@ 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 f2cd6f33ca9..39682d26330 100644 --- a/examples/gno.land/r/demo/banktest/z_1_filetest.gno +++ b/examples/gno.land/r/demo/banktest/z_1_filetest.gno @@ -8,7 +8,6 @@ package bank1 import ( "std" - "gno.land/p/demo/testutils" "gno.land/r/demo/banktest" ) @@ -19,8 +18,6 @@ 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 8511371823c..e839f60354a 100644 --- a/examples/gno.land/r/demo/banktest/z_2_filetest.gno +++ b/examples/gno.land/r/demo/banktest/z_2_filetest.gno @@ -8,7 +8,6 @@ package bank1 import ( "std" - "gno.land/p/demo/testutils" "gno.land/r/demo/banktest" ) @@ -27,8 +26,6 @@ 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/groups/z_0_a_filetest.gno b/examples/gno.land/r/demo/groups/z_0_a_filetest.gno index fa27b89e43f..49ebb5219ec 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,17 +2,12 @@ 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 951e3c1c31c..6d328825dd6 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,9 +2,6 @@ package groups_test import ( - "std" - - "gno.land/p/demo/testutils" "gno.land/r/demo/groups" "gno.land/r/demo/users" ) @@ -12,8 +9,6 @@ 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 f6c7d8b15f0..60600e38b78 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,9 +4,6 @@ package groups_test // SEND: 200000000ugnot import ( - "std" - - "gno.land/p/demo/testutils" "gno.land/r/demo/groups" "gno.land/r/demo/users" ) @@ -14,8 +11,6 @@ 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 0044bff871f..71da1b966ec 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,9 +16,7 @@ var gid groups.GroupID const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := testutils.TestAddress("caller") - std.TestSetRealm(std.NewUserRealm(caller)) - std.TestSetOrigCaller(caller) + caller := std.GetOrigCaller() // main 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 e2aad8d0432..31a036d4e41 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,9 +4,6 @@ package groups_test // SEND: 200000000ugnot import ( - "std" - - "gno.land/p/demo/testutils" "gno.land/r/demo/groups" "gno.land/r/demo/users" ) @@ -14,8 +11,6 @@ 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 d6269f22160..6eaabb07cdf 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,8 +13,6 @@ 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 64540ff396c..0c482e1b52f 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,9 +16,7 @@ var gid groups.GroupID const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := testutils.TestAddress("caller") - std.TestSetRealm(std.NewUserRealm(caller)) - std.TestSetOrigCaller(caller) + caller := std.GetOrigCaller() // main 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 d6e09d6a404..fd8e485f16f 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,9 +4,6 @@ package groups_test // SEND: 200000000ugnot import ( - "std" - - "gno.land/p/demo/testutils" "gno.land/r/demo/groups" "gno.land/r/demo/users" ) @@ -14,8 +11,6 @@ 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 7aeebbade21..3caa726cbd3 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,8 +14,6 @@ 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 81da8059496..ff38acf45a4 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,9 +4,6 @@ package groups_test // SEND: 200000000ugnot import ( - "std" - - "gno.land/p/demo/testutils" "gno.land/r/demo/groups" "gno.land/r/demo/users" ) @@ -14,8 +11,6 @@ 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 5d7ee304ac7..4fddb768e08 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,9 +4,6 @@ package groups_test // SEND: 200000000ugnot import ( - "std" - - "gno.land/p/demo/testutils" "gno.land/r/demo/groups" "gno.land/r/demo/users" ) @@ -14,8 +11,6 @@ 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 6faf70d0064..6230b110c74 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,9 +14,6 @@ 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/users/z_0_b_filetest.gno b/examples/gno.land/r/demo/users/z_0_b_filetest.gno index 2d94596730d..c33edc32985 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,15 +3,10 @@ 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 5b0e3108660..cbb2e9209f4 100644 --- a/examples/gno.land/r/demo/users/z_0_filetest.gno +++ b/examples/gno.land/r/demo/users/z_0_filetest.gno @@ -3,13 +3,10 @@ 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 fc5d0b200da..afeecffcc42 100644 --- a/examples/gno.land/r/demo/users/z_10_filetest.gno +++ b/examples/gno.land/r/demo/users/z_10_filetest.gno @@ -11,9 +11,7 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func init() { - caller := testutils.TestAddress("caller") - std.TestSetRealm(std.NewUserRealm(caller)) - std.TestSetOrigCaller(caller) + caller := std.GetOrigCaller() // main test2 := testutils.TestAddress("test2") // as admin, invite gnouser and test2 std.TestSetOrigCaller(admin) @@ -26,7 +24,6 @@ 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 6d7bb0f6ef6..212dc169007 100644 --- a/examples/gno.land/r/demo/users/z_11_filetest.gno +++ b/examples/gno.land/r/demo/users/z_11_filetest.gno @@ -5,16 +5,14 @@ package main import ( "std" - "gno.land/p/demo/testutils" "gno.land/r/demo/users" ) const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := testutils.TestAddress("caller") - std.TestSetRealm(std.NewUserRealm(caller)) std.TestSetOrigCaller(admin) + caller := std.GetOrigCaller() // main users.AdminAddRestrictedName("superrestricted") // test restricted name 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 b34a83bfc3b..6041f4b7113 100644 --- a/examples/gno.land/r/demo/users/z_11b_filetest.gno +++ b/examples/gno.land/r/demo/users/z_11b_filetest.gno @@ -5,16 +5,14 @@ package main import ( "std" - "gno.land/p/demo/testutils" "gno.land/r/demo/users" ) const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := testutils.TestAddress("caller") - std.TestSetRealm(std.NewUserRealm(caller)) std.TestSetOrigCaller(admin) + caller := std.GetOrigCaller() // main // add restricted name users.AdminAddRestrictedName("superrestricted") // grant invite to caller 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 6e5f659e938..0fb7d27bd34 100644 --- a/examples/gno.land/r/demo/users/z_12_filetest.gno +++ b/examples/gno.land/r/demo/users/z_12_filetest.gno @@ -3,16 +3,12 @@ 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 430488d96ee..504a0c7c3f9 100644 --- a/examples/gno.land/r/demo/users/z_1_filetest.gno +++ b/examples/gno.land/r/demo/users/z_1_filetest.gno @@ -3,16 +3,10 @@ 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 60b2002ee70..c1b92790f8b 100644 --- a/examples/gno.land/r/demo/users/z_2_filetest.gno +++ b/examples/gno.land/r/demo/users/z_2_filetest.gno @@ -12,9 +12,7 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := testutils.TestAddress("caller") - std.TestSetRealm(std.NewUserRealm(caller)) - std.TestSetOrigCaller(caller) + caller := std.GetOrigCaller() // main 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 f454b4c00fb..5402235e03d 100644 --- a/examples/gno.land/r/demo/users/z_3_filetest.gno +++ b/examples/gno.land/r/demo/users/z_3_filetest.gno @@ -12,9 +12,7 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := testutils.TestAddress("caller") - std.TestSetRealm(std.NewUserRealm(caller)) - std.TestSetOrigCaller(caller) + caller := std.GetOrigCaller() // main 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 749f44ce6c6..613fadf9625 100644 --- a/examples/gno.land/r/demo/users/z_4_filetest.gno +++ b/examples/gno.land/r/demo/users/z_4_filetest.gno @@ -12,9 +12,7 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := testutils.TestAddress("caller") - std.TestSetRealm(std.NewUserRealm(caller)) - std.TestSetOrigCaller(caller) + caller := std.GetOrigCaller() // main 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 47aac3bb2af..9080b509b8e 100644 --- a/examples/gno.land/r/demo/users/z_5_filetest.gno +++ b/examples/gno.land/r/demo/users/z_5_filetest.gno @@ -12,9 +12,7 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := testutils.TestAddress("caller") - std.TestSetRealm(std.NewUserRealm(caller)) - std.TestSetOrigCaller(caller) + caller := std.GetOrigCaller() // main users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser std.TestSetOrigCaller(admin) @@ -63,7 +61,7 @@ func main() { // ======================================== // ## user gnouser // -// * address = g1vdskcmr9wf047h6lta047h6lta047h6lq5m7fe +// * address = g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm // * 9 invites // // my profile @@ -73,7 +71,7 @@ func main() { // // * address = g1w3jhxap3ta047h6lta047h6lta047h6l4mfnm7 // * 0 invites -// * invited by g1vdskcmr9wf047h6lta047h6lta047h6lq5m7fe +// * invited by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm // // 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 ac19a49b615..e6a63d83358 100644 --- a/examples/gno.land/r/demo/users/z_6_filetest.gno +++ b/examples/gno.land/r/demo/users/z_6_filetest.gno @@ -3,15 +3,13 @@ package main import ( "std" - "gno.land/p/demo/testutils" "gno.land/r/demo/users" ) const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := testutils.TestAddress("caller") - std.TestSetRealm(std.NewUserRealm(admin)) + caller := std.GetOrigCaller() // main // as admin, grant invites to unregistered user. std.TestSetOrigCaller(admin) users.GrantInvites(caller.String() + ":1") @@ -19,4 +17,4 @@ func main() { } // Error: -// invalid user g1vdskcmr9wf047h6lta047h6lta047h6lq5m7fe +// invalid user g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm 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 bac1f6df744..1d3c9e3a917 100644 --- a/examples/gno.land/r/demo/users/z_7_filetest.gno +++ b/examples/gno.land/r/demo/users/z_7_filetest.gno @@ -12,9 +12,7 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := testutils.TestAddress("caller") - std.TestSetRealm(std.NewUserRealm(caller)) - std.TestSetOrigCaller(caller) + caller := std.GetOrigCaller() // main 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 f549531717c..09c15bb135d 100644 --- a/examples/gno.land/r/demo/users/z_7b_filetest.gno +++ b/examples/gno.land/r/demo/users/z_7b_filetest.gno @@ -12,9 +12,7 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := testutils.TestAddress("caller") - std.TestSetRealm(std.NewUserRealm(caller)) - std.TestSetOrigCaller(caller) + caller := std.GetOrigCaller() // main 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 d2e94c62554..78fada74a71 100644 --- a/examples/gno.land/r/demo/users/z_8_filetest.gno +++ b/examples/gno.land/r/demo/users/z_8_filetest.gno @@ -12,9 +12,7 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := testutils.TestAddress("caller") - std.TestSetRealm(std.NewUserRealm(caller)) - std.TestSetOrigCaller(caller) + caller := std.GetOrigCaller() // main 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 d2895f0b729..c73c685aebd 100644 --- a/examples/gno.land/r/demo/users/z_9_filetest.gno +++ b/examples/gno.land/r/demo/users/z_9_filetest.gno @@ -10,9 +10,7 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := testutils.TestAddress("caller") - std.TestSetRealm(std.NewUserRealm(caller)) - std.TestSetOrigCaller(caller) + caller := std.GetOrigCaller() // main test2 := testutils.TestAddress("test2") // as admin, invite gnouser and test2 std.TestSetOrigCaller(admin) diff --git a/gno.land/pkg/integration/testdata/assertorigincall.txtar b/gno.land/pkg/integration/testdata/assertorigincall.txtar index bf7ebe544d5..52235af2e0e 100644 --- a/gno.land/pkg/integration/testdata/assertorigincall.txtar +++ b/gno.land/pkg/integration/testdata/assertorigincall.txtar @@ -3,7 +3,7 @@ # # | Num | Msg Type | Call from | Entry Point | Result | # |-----|:--------:|:-------------------:|:----------------------:|:------:| -# | 1 | MsgCall | wallet direct | myrealm.A() | pass | +# | 1 | MsgCall | wallet direct | myrealm.A() | PANIC | # | 2 | | | myrealm.B() | pass | # | 3 | | | myrealm.C() | pass | # | 4 | | through /r/foo | myrealm.A() | PANIC | @@ -23,80 +23,67 @@ # | 18 | | | bar.C() | PANIC | # | 19 | MsgCall | wallet direct | std.AssertOriginCall() | pass | # | 20 | MsgRun | wallet direct | std.AssertOriginCall() | PANIC | - # Init ## set up and start a new node loadpkg gno.land/r/myrlm $WORK/r/myrlm loadpkg gno.land/r/foo $WORK/r/foo loadpkg gno.land/p/demo/bar $WORK/p/demo/bar gnoland start - # The PANIC is expected to fail at the transaction simulation stage, which is why we set gas-wanted to 1. # Test cases -## 1. MsgCall -> myrlm.A: PASS -gnokey maketx call -pkgpath gno.land/r/myrlm -func A -gas-fee 100000ugnot -gas-wanted 1000000 -broadcast -chainid tendermint_test test1 -stdout 'OK!' +## 1. MsgCall -> myrlm.A: PANIC +! gnokey maketx call -pkgpath gno.land/r/myrlm -func A -gas-fee 100000ugnot -gas-wanted 1 -broadcast -chainid tendermint_test test1 +stderr 'invalid non-origin call' ## 2. MsgCall -> myrlm.B: PASS gnokey maketx call -pkgpath gno.land/r/myrlm -func B -gas-fee 100000ugnot -gas-wanted 150000 -broadcast -chainid tendermint_test test1 stdout 'OK!' - ## 3. MsgCall -> myrlm.C: PASS gnokey maketx call -pkgpath gno.land/r/myrlm -func C -gas-fee 100000ugnot -gas-wanted 1500000 -broadcast -chainid tendermint_test test1 stdout 'OK!' - ## 4. MsgCall -> r/foo.A -> myrlm.A: PANIC ! gnokey maketx call -pkgpath gno.land/r/foo -func A -gas-fee 100000ugnot -gas-wanted 1 -broadcast -chainid tendermint_test test1 stderr 'invalid non-origin call' - ## 5. MsgCall -> r/foo.B -> myrlm.B: PASS gnokey maketx call -pkgpath gno.land/r/foo -func B -gas-fee 100000ugnot -gas-wanted 200000 -broadcast -chainid tendermint_test test1 stdout 'OK!' - ## 6. MsgCall -> r/foo.C -> myrlm.C: PANIC ! gnokey maketx call -pkgpath gno.land/r/foo -func C -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 stderr 'invalid non-origin call' - ## remove due to update to maketx call can only call realm (case 7,8,9) ## 7. MsgCall -> p/demo/bar.A: PANIC ## ! gnokey maketx call -pkgpath gno.land/p/demo/bar -func A -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 ## stderr 'invalid non-origin call' - ## 8. MsgCall -> p/demo/bar.B: PASS ## gnokey maketx call -pkgpath gno.land/p/demo/bar -func B -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 ## stdout 'OK!' - ## 9. MsgCall -> p/demo/bar.C: PANIC ## ! gnokey maketx call -pkgpath gno.land/p/demo/bar -func C -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 ## stderr 'invalid non-origin call' ## 10. MsgRun -> run.main -> myrlm.A: PANIC -! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmA.gno -## stderr 'invalid non-origin call' +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmA.gno +stderr 'invalid non-origin call' ## 11. MsgRun -> run.main -> myrlm.B: PASS gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmB.gno stdout 'OK!' - ## 12. MsgRun -> run.main -> myrlm.C: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmC.gno stderr 'invalid non-origin call' - ## 13. MsgRun -> run.main -> foo.A: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/fooA.gno stderr 'invalid non-origin call' - ## 14. MsgRun -> run.main -> foo.B: PASS gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooB.gno stdout 'OK!' - ## 15. MsgRun -> run.main -> foo.C: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/fooC.gno stderr 'invalid non-origin call' ## 16. MsgRun -> run.main -> bar.A: PANIC -! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/barA.gno +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/barA.gno stderr 'invalid non-origin call' ## 17. MsgRun -> run.main -> bar.B: PASS @@ -104,62 +91,49 @@ gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid stdout 'OK!' ## 18. MsgRun -> run.main -> bar.C: PANIC -! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/barC.gno +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/barC.gno stderr 'invalid non-origin call' ## remove testcase 19 due to maketx call forced to call a realm -## 19. MsgCall -> std.AssertOriginCall: PASS +## 19. MsgCall -> std.AssertOriginCall: pass ## gnokey maketx call -pkgpath std -func AssertOriginCall -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 ## stdout 'OK!' ## 20. MsgRun -> std.AssertOriginCall: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno stderr 'invalid non-origin call' - - -- r/myrlm/rlm.gno -- package myrlm - import "std" - func A() { C() } - func B() { if false { C() } } - func C() { std.AssertOriginCall() } -- r/foo/foo.gno -- package foo - import "gno.land/r/myrlm" - func A() { myrlm.A() } - func B() { myrlm.B() } - func C() { myrlm.C() } -- p/demo/bar/bar.gno -- package bar - import "std" - func A() { C() } - func B() { if false { C() @@ -170,81 +144,61 @@ func C() { } -- run/myrlmA.gno -- package main - import myrlm "gno.land/r/myrlm" - func main() { myrlm.A() } -- run/myrlmB.gno -- package main - import "gno.land/r/myrlm" - func main() { myrlm.B() } -- run/myrlmC.gno -- package main - import "gno.land/r/myrlm" - func main() { myrlm.C() } -- run/fooA.gno -- package main - import "gno.land/r/foo" - func main() { foo.A() } -- run/fooB.gno -- package main - import "gno.land/r/foo" - func main() { foo.B() } -- run/fooC.gno -- package main - import "gno.land/r/foo" - func main() { foo.C() } -- run/barA.gno -- package main - import "gno.land/p/demo/bar" - func main() { bar.A() } -- run/barB.gno -- package main - import "gno.land/p/demo/bar" - func main() { bar.B() } -- run/barC.gno -- package main - import "gno.land/p/demo/bar" - func main() { bar.C() } -- run/baz.gno -- package main - import "std" - func main() { std.AssertOriginCall() -} +} \ No newline at end of file diff --git a/gnovm/stdlibs/generated.go b/gnovm/stdlibs/generated.go index d9e0c495c83..12c55d5ffa0 100644 --- a/gnovm/stdlibs/generated.go +++ b/gnovm/stdlibs/generated.go @@ -416,6 +416,18 @@ var nativeFuncs = [...]NativeFunc{ p0, p1) }, }, + { + "std", + "AssertOriginCall", + []gno.FieldTypeExpr{}, + []gno.FieldTypeExpr{}, + true, + func(m *gno.Machine) { + libs_std.AssertOriginCall( + m, + ) + }, + }, { "std", "GetChainID", @@ -620,26 +632,6 @@ var nativeFuncs = [...]NativeFunc{ ) }, }, - { - "std", - "isMsgRun", - []gno.FieldTypeExpr{}, - []gno.FieldTypeExpr{ - {Name: gno.N("r0"), Type: gno.X("bool")}, - }, - true, - func(m *gno.Machine) { - r0 := libs_std.X_isMsgRun( - m, - ) - - m.PushValue(gno.Go2GnoValue( - m.Alloc, - m.Store, - reflect.ValueOf(&r0).Elem(), - )) - }, - }, { "std", "setParamString", diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index 34da2b7226e..2d3bc625a59 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -5,11 +5,7 @@ package std // is invoked by another method (even from the same realm or package). // It also panic every time when the transaction is broadcasted via // MsgRun. -func AssertOriginCall() { - if !PrevRealm().IsUser() || isMsgRun() { - panic("invalid non-origin call") - } -} +func AssertOriginCall() // injected func GetChainID() string // injected func GetChainDomain() string // injected func GetHeight() int64 // injected @@ -52,4 +48,3 @@ func origPkgAddr() string func callerAt(n int) string func getRealm(height int) (address string, pkgPath string) func assertCallerIsRealm() -func isMsgRun() bool diff --git a/gnovm/stdlibs/std/native.go b/gnovm/stdlibs/std/native.go index c79c8e2d5a8..60f9f000c49 100644 --- a/gnovm/stdlibs/std/native.go +++ b/gnovm/stdlibs/std/native.go @@ -14,13 +14,20 @@ func GetChainDomain(m *gno.Machine) string { return GetContext(m).ChainDomain } -func X_isMsgRun(m *gno.Machine) bool { +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 } - - return m.Frames[0].LastPackage.PkgPath != "main" + firstPkg := m.Frames[0].LastPackage + isMsgCall := firstPkg != nil && firstPkg.PkgPath == "main" + return n <= 2 && isMsgCall } func GetHeight(m *gno.Machine) int64 { diff --git a/gnovm/stdlibs/std/native_test.go b/gnovm/stdlibs/std/native_test.go new file mode 100644 index 00000000000..acbd22055d6 --- /dev/null +++ b/gnovm/stdlibs/std/native_test.go @@ -0,0 +1,194 @@ +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 a33ed111f8f..1f1d013c3df 100644 --- a/gnovm/tests/files/std5.gno +++ b/gnovm/tests/files/std5.gno @@ -16,7 +16,7 @@ func main() { // callerAt(n) // gonative:std.callerAt // std.GetCallerAt(2) -// std/native.gno:45 +// std/native.gno:41 // main() // main/files/std5.gno:10 diff --git a/gnovm/tests/files/std8.gno b/gnovm/tests/files/std8.gno index 11efb6bc65d..3d0e4a7085e 100644 --- a/gnovm/tests/files/std8.gno +++ b/gnovm/tests/files/std8.gno @@ -26,7 +26,7 @@ func main() { // callerAt(n) // gonative:std.callerAt // std.GetCallerAt(4) -// std/native.gno:45 +// std/native.gno:41 // fn() // main/files/std8.gno:16 // testutils.WrapCall(inner) diff --git a/gnovm/tests/files/std9.gno b/gnovm/tests/files/std9.gno index 2f9f848ec5d..95ccfb2c8a4 100644 --- a/gnovm/tests/files/std9.gno +++ b/gnovm/tests/files/std9.gno @@ -11,4 +11,4 @@ func main() { } // Output: -// undefined +// invalid non-origin call diff --git a/gnovm/tests/stdlibs/generated.go b/gnovm/tests/stdlibs/generated.go index 14575fad4ab..51b15d77eef 100644 --- a/gnovm/tests/stdlibs/generated.go +++ b/gnovm/tests/stdlibs/generated.go @@ -31,6 +31,18 @@ func (n *NativeFunc) HasMachineParam() bool { } var nativeFuncs = [...]NativeFunc{ + { + "std", + "AssertOriginCall", + []gno.FieldTypeExpr{}, + []gno.FieldTypeExpr{}, + true, + func(m *gno.Machine) { + testlibs_std.AssertOriginCall( + m, + ) + }, + }, { "std", "TestSkipHeights", diff --git a/gnovm/tests/stdlibs/std/std.gno b/gnovm/tests/stdlibs/std/std.gno index c96e5f00de5..c30071313fe 100644 --- a/gnovm/tests/stdlibs/std/std.gno +++ b/gnovm/tests/stdlibs/std/std.gno @@ -1,16 +1,11 @@ package std +func AssertOriginCall() // injected func TestSkipHeights(count int64) // injected func TestSetOrigCaller(addr Address) { testSetOrigCaller(string(addr)) } func TestSetOrigPkgAddr(addr Address) { testSetOrigPkgAddr(string(addr)) } -func AssertOriginCall() { - if !PrevRealm().IsUser() { - panic("invalid non-origin call") - } -} - // TestSetRealm sets the realm for the current frame. // After calling TestSetRealm, calling CurrentRealm() in the test function will yield the value of // rlm, while if a realm function is called, using PrevRealm() will yield rlm. diff --git a/gnovm/tests/stdlibs/std/std.go b/gnovm/tests/stdlibs/std/std.go index f9b4a3bea81..eac51c5fb0e 100644 --- a/gnovm/tests/stdlibs/std/std.go +++ b/gnovm/tests/stdlibs/std/std.go @@ -2,6 +2,7 @@ package std import ( "fmt" + "strings" gno "github.com/gnolang/gno/gnovm/pkg/gnolang" "github.com/gnolang/gno/gnovm/stdlibs/std" @@ -24,12 +25,43 @@ 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 From 648555d929182d1b19cfe230cec7ea2978109bb2 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Tue, 21 Jan 2025 13:26:45 +0100 Subject: [PATCH 6/8] revert changes on assertorigincall --- .../testdata/assertorigincall.txtar | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/gno.land/pkg/integration/testdata/assertorigincall.txtar b/gno.land/pkg/integration/testdata/assertorigincall.txtar index 52235af2e0e..2c5da25c0aa 100644 --- a/gno.land/pkg/integration/testdata/assertorigincall.txtar +++ b/gno.land/pkg/integration/testdata/assertorigincall.txtar @@ -23,12 +23,14 @@ # | 18 | | | bar.C() | PANIC | # | 19 | MsgCall | wallet direct | std.AssertOriginCall() | pass | # | 20 | MsgRun | wallet direct | std.AssertOriginCall() | PANIC | + # Init ## set up and start a new node loadpkg gno.land/r/myrlm $WORK/r/myrlm loadpkg gno.land/r/foo $WORK/r/foo loadpkg gno.land/p/demo/bar $WORK/p/demo/bar gnoland start + # The PANIC is expected to fail at the transaction simulation stage, which is why we set gas-wanted to 1. # Test cases @@ -39,25 +41,32 @@ stderr 'invalid non-origin call' ## 2. MsgCall -> myrlm.B: PASS gnokey maketx call -pkgpath gno.land/r/myrlm -func B -gas-fee 100000ugnot -gas-wanted 150000 -broadcast -chainid tendermint_test test1 stdout 'OK!' + ## 3. MsgCall -> myrlm.C: PASS gnokey maketx call -pkgpath gno.land/r/myrlm -func C -gas-fee 100000ugnot -gas-wanted 1500000 -broadcast -chainid tendermint_test test1 stdout 'OK!' + ## 4. MsgCall -> r/foo.A -> myrlm.A: PANIC ! gnokey maketx call -pkgpath gno.land/r/foo -func A -gas-fee 100000ugnot -gas-wanted 1 -broadcast -chainid tendermint_test test1 stderr 'invalid non-origin call' + ## 5. MsgCall -> r/foo.B -> myrlm.B: PASS gnokey maketx call -pkgpath gno.land/r/foo -func B -gas-fee 100000ugnot -gas-wanted 200000 -broadcast -chainid tendermint_test test1 stdout 'OK!' + ## 6. MsgCall -> r/foo.C -> myrlm.C: PANIC ! gnokey maketx call -pkgpath gno.land/r/foo -func C -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 stderr 'invalid non-origin call' + ## remove due to update to maketx call can only call realm (case 7,8,9) ## 7. MsgCall -> p/demo/bar.A: PANIC ## ! gnokey maketx call -pkgpath gno.land/p/demo/bar -func A -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 ## stderr 'invalid non-origin call' + ## 8. MsgCall -> p/demo/bar.B: PASS ## gnokey maketx call -pkgpath gno.land/p/demo/bar -func B -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 ## stdout 'OK!' + ## 9. MsgCall -> p/demo/bar.C: PANIC ## ! gnokey maketx call -pkgpath gno.land/p/demo/bar -func C -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 ## stderr 'invalid non-origin call' @@ -69,15 +78,19 @@ stderr 'invalid non-origin call' ## 11. MsgRun -> run.main -> myrlm.B: PASS gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmB.gno stdout 'OK!' + ## 12. MsgRun -> run.main -> myrlm.C: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmC.gno stderr 'invalid non-origin call' + ## 13. MsgRun -> run.main -> foo.A: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/fooA.gno stderr 'invalid non-origin call' + ## 14. MsgRun -> run.main -> foo.B: PASS gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooB.gno stdout 'OK!' + ## 15. MsgRun -> run.main -> foo.C: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5500000 -broadcast -chainid tendermint_test test1 $WORK/run/fooC.gno stderr 'invalid non-origin call' @@ -102,38 +115,51 @@ stderr 'invalid non-origin call' ## 20. MsgRun -> std.AssertOriginCall: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 10000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno stderr 'invalid non-origin call' + + -- r/myrlm/rlm.gno -- package myrlm + import "std" + func A() { C() } + func B() { if false { C() } } + func C() { std.AssertOriginCall() } -- r/foo/foo.gno -- package foo + import "gno.land/r/myrlm" + func A() { myrlm.A() } + func B() { myrlm.B() } + func C() { myrlm.C() } -- p/demo/bar/bar.gno -- package bar + import "std" + func A() { C() } + func B() { if false { C() @@ -144,61 +170,81 @@ func C() { } -- run/myrlmA.gno -- package main + import myrlm "gno.land/r/myrlm" + func main() { myrlm.A() } -- run/myrlmB.gno -- package main + import "gno.land/r/myrlm" + func main() { myrlm.B() } -- run/myrlmC.gno -- package main + import "gno.land/r/myrlm" + func main() { myrlm.C() } -- run/fooA.gno -- package main + import "gno.land/r/foo" + func main() { foo.A() } -- run/fooB.gno -- package main + import "gno.land/r/foo" + func main() { foo.B() } -- run/fooC.gno -- package main + import "gno.land/r/foo" + func main() { foo.C() } -- run/barA.gno -- package main + import "gno.land/p/demo/bar" + func main() { bar.A() } -- run/barB.gno -- package main + import "gno.land/p/demo/bar" + func main() { bar.B() } -- run/barC.gno -- package main + import "gno.land/p/demo/bar" + func main() { bar.C() } -- run/baz.gno -- package main + import "std" + func main() { std.AssertOriginCall() -} \ No newline at end of file +} From ace790af3da9740ca522db3e10e7f228f64af836 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Tue, 21 Jan 2025 13:30:24 +0100 Subject: [PATCH 7/8] to previous state --- gnovm/stdlibs/std/native.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gnovm/stdlibs/std/native.go b/gnovm/stdlibs/std/native.go index 60f9f000c49..68f4542f689 100644 --- a/gnovm/stdlibs/std/native.go +++ b/gnovm/stdlibs/std/native.go @@ -6,14 +6,6 @@ import ( "github.com/gnolang/gno/tm2/pkg/std" ) -func GetChainID(m *gno.Machine) string { - return GetContext(m).ChainID -} - -func GetChainDomain(m *gno.Machine) string { - return GetContext(m).ChainDomain -} - func AssertOriginCall(m *gno.Machine) { if !isOriginCall(m) { m.Panic(typedString("invalid non-origin call")) @@ -30,6 +22,14 @@ func isOriginCall(m *gno.Machine) bool { return n <= 2 && isMsgCall } +func GetChainID(m *gno.Machine) string { + return GetContext(m).ChainID +} + +func GetChainDomain(m *gno.Machine) string { + return GetContext(m).ChainDomain +} + func GetHeight(m *gno.Machine) int64 { return GetContext(m).Height } From 9fa3676e78e774fac3c989a0e3b007fecc24f83f Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Tue, 21 Jan 2025 13:32:24 +0100 Subject: [PATCH 8/8] fixup godoc --- gnovm/stdlibs/std/native.gno | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index 2d3bc625a59..2baa1f92f48 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -1,7 +1,7 @@ package std // 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 +// MsgCall. It panics for for other cases, like if the calling method // is invoked by another method (even from the same realm or package). // It also panic every time when the transaction is broadcasted via // MsgRun.