diff --git a/cmd/gnodev/test_test.go b/cmd/gnodev/test_test.go index a5cad7a321f..903bc9ebd89 100644 --- a/cmd/gnodev/test_test.go +++ b/cmd/gnodev/test_test.go @@ -97,6 +97,9 @@ func TestTest(t *testing.T) { args: []string{"test", "--verbose", "--run", ".*/hi", "../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", stderrShouldContain: "ok ./../../examples/gno.land/p/demo/ufmt", + }, { + args: []string{"test", "../../tests/integ/origin-call"}, + stderrShouldContain: "ok ./../../tests/integ/origin-call", }, { args: []string{"test", "--verbose", "--run", ".*/NoExists", "../../examples/gno.land/p/demo/ufmt"}, stderrShouldContain: "ok ./../../examples/gno.land/p/demo/ufmt", 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 872d01dd793..4adca63992b 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,16 @@ package boards_test import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" ) var bid boards.BoardID func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) 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 9ada8abd0c0..32d3c8f9383 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: 199000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -11,6 +14,7 @@ import ( var bid boards.BoardID func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) 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 36b7bcfda04..8875a9fa104 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,7 @@ import ( var bid boards.BoardID func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) 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 2e9e3f1436f..0533dc20005 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,7 @@ import ( var bid boards.BoardID func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) 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 a06713fcbe3..d0d339eca9f 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,7 @@ import ( var bid boards.BoardID func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) 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 5c3fc7b204e..317a9c31325 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: 200000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -11,6 +14,7 @@ import ( var bid boards.BoardID func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) 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 8ec2e45421a..140fd97bc0d 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,7 @@ var ( ) func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") 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 0981d85a57f..6d7a71f29c0 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: 2000000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -16,6 +18,7 @@ var ( ) func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") 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 f161c8cedee..67899fb4904 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,7 @@ var ( ) func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") 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 7a24efe09ca..1e0f9bbf92e 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,7 @@ var ( ) func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") 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 fd62a884efa..9a07a25245c 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: 2000000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -16,6 +18,7 @@ var ( ) func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") 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 63907146f82..098946a4048 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: 2000000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -16,6 +18,7 @@ var ( ) func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") 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 ba40fa39021..01ebef303b2 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: 2000000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -16,6 +18,7 @@ var ( ) func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") 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 a519d4f6a94..8e72ca93999 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: 2000000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -17,6 +19,7 @@ var ( ) func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") 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 2d96d46dc98..7f29fff9b30 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: 2000000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -16,6 +18,7 @@ var ( ) func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") 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 b5c7bb863e1..c463d99484b 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,7 @@ import ( var board *boards.Board func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) 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 1e0b55a3952..d01674f75fa 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,7 @@ var ( ) func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) 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 f4160e16126..c9d331630dc 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,7 @@ var ( ) func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") 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 df6f58726bb..ac78d8c3a96 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,7 @@ var ( ) func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") @@ -458,7 +461,7 @@ func main() { // }, // "V": { // "@type": "/gno.StringValue", -// "value": "g1arjyc64rpthwn8zhxtzjvearm5scy43y7vm985" +// "value": "g1w3jhxazlta047h6lta047h6lta047h6lwmjv0n" // } // }, // { @@ -837,7 +840,7 @@ func main() { // }, // "V": { // "@type": "/gno.StringValue", -// "value": "g1arjyc64rpthwn8zhxtzjvearm5scy43y7vm985" +// "value": "g1w3jhxazlta047h6lta047h6lta047h6lwmjv0n" // } // }, // { @@ -847,7 +850,7 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "04bcdca23188f0e1b9a57b36c4bb33ed3cd72446", +// "Hash": "205f2a839a0ec5a5fb335cacca1cf87b1c2f5268", // "ObjectID": "f6dbf411da22e67d74cd7ddba6a76cd7e14a4822:82" // } // }, 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 105c7f19ef7..008cd0aed4f 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,7 @@ import ( const admin = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") func main() { + std.TestSetOrigCaller(testutils.TestAddress("test")) 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 e372b7cc430..61b0a1bd3c4 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,7 @@ import ( const admin = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") func main() { + std.TestSetOrigCaller(testutils.TestAddress("test")) 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 e54ac578dc1..d587ac8a648 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,7 @@ import ( const admin = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") func main() { + std.TestSetOrigCaller(testutils.TestAddress("test")) 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 421d9440785..ce9fdd8ccea 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,7 @@ var ( ) func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") 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 2a392808d30..3550a10798f 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,7 @@ var ( ) func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") 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 1294f72c1be..af414c503c0 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,15 @@ package boards_test // SEND: 2000000000ugnot import ( + "std" + + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) // 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 5ba0b34ad30..b33166c28e3 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: 2000000000ugnot import ( + "std" "strconv" + "gno.land/p/demo/testutils" "gno.land/r/demo/boards" "gno.land/r/demo/users" ) @@ -17,6 +19,7 @@ var ( ) func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) users.Register("", "gnouser", "my profile") bid = boards.CreateBoard("test_board") 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 9ba9786c519..efcb944789a 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,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" ) @@ -13,6 +15,7 @@ import ( var dstBoard boards.BoardID func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) 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 4d53f60f10f..505f45a81f2 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,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,7 @@ var ( ) func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) 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 66f8950732b..85dcf554cb3 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,7 @@ var ( ) func init() { + std.TestSetOrigCaller(testutils.TestAddress("test")) users.Register("", "gnouser", "my profile") firstBoard = boards.CreateBoard("first_board") diff --git a/stdlibs/stdlibs.go b/stdlibs/stdlibs.go index bc8689d3b30..f64c6e955cb 100644 --- a/stdlibs/stdlibs.go +++ b/stdlibs/stdlibs.go @@ -125,7 +125,7 @@ func InjectPackage(store gno.Store, pn *gno.PackageNode) { ctx := m.Context.(ExecContext) isOrigin := ctx.Msg != nil && len(ctx.Msg.GetSigners()) > 0 if !isOrigin { - panic("invalid non-origin call") + m.Panic(typedString("invalid non-origin call")) } }, ) diff --git a/tests/file.go b/tests/file.go index f7801902c5a..33afbe38ebb 100644 --- a/tests/file.go +++ b/tests/file.go @@ -15,7 +15,6 @@ import ( "github.com/gnolang/gno/pkgs/crypto" gno "github.com/gnolang/gno/pkgs/gnolang" osm "github.com/gnolang/gno/pkgs/os" - "github.com/gnolang/gno/pkgs/sdk/testutils" "github.com/gnolang/gno/pkgs/std" "github.com/gnolang/gno/stdlibs" ) @@ -42,7 +41,7 @@ func testMachineCustom(store gno.Store, pkgPath string, stdout io.Writer, maxAll ChainID: "dev", Height: 123, Timestamp: 1234567890, - Msg: testutils.NewTestMsg(caller), + Msg: nil, OrigCaller: caller.Bech32(), OrigPkgAddr: pkgAddr.Bech32(), OrigSend: send, diff --git a/tests/imports.go b/tests/imports.go index 236ca939cf9..aeaf0382e7f 100644 --- a/tests/imports.go +++ b/tests/imports.go @@ -43,6 +43,7 @@ import ( dbm "github.com/gnolang/gno/pkgs/db" gno "github.com/gnolang/gno/pkgs/gnolang" osm "github.com/gnolang/gno/pkgs/os" + "github.com/gnolang/gno/pkgs/sdk/testutils" "github.com/gnolang/gno/pkgs/std" "github.com/gnolang/gno/pkgs/store/dbadapter" "github.com/gnolang/gno/pkgs/store/iavl" @@ -516,6 +517,8 @@ func testPackageInjector(store gno.Store, pn *gno.PackageNode) { // overwrite context ctx := m.Context.(stdlibs.ExecContext) ctx.OrigCaller = crypto.Bech32Address(addr) + // Define new message with addr as signer + ctx.Msg = testutils.NewTestMsg(crypto.MustAddressFromString(addr)) m.Context = ctx }, ) @@ -531,6 +534,8 @@ func testPackageInjector(store gno.Store, pn *gno.PackageNode) { // overwrite context ctx := m.Context.(stdlibs.ExecContext) ctx.OrigPkgAddr = addr + // Define new message with addr as signer + ctx.Msg = testutils.NewTestMsg(crypto.MustAddressFromString(arg0.GetString())) m.Context = ctx }, ) diff --git a/tests/integ/origin-call/origincall.gno b/tests/integ/origin-call/origincall.gno new file mode 100644 index 00000000000..fc7a09aa2a0 --- /dev/null +++ b/tests/integ/origin-call/origincall.gno @@ -0,0 +1 @@ +package origincall diff --git a/tests/integ/origin-call/origincall_filetest.gno b/tests/integ/origin-call/origincall_filetest.gno new file mode 100644 index 00000000000..b1ea6633cf7 --- /dev/null +++ b/tests/integ/origin-call/origincall_filetest.gno @@ -0,0 +1,35 @@ +package main + +import ( + "std" + "testing" + + "gno.land/p/demo/testutils" +) + +func main() { + test() + std.TestSetOrigCaller(testutils.TestAddress("user")) + test() +} + +func test() { + if std.IsOriginCall() { + println("IsOriginCall: true") + } else { + println("IsOriginCall: false") + } + defer func() { + if r := recover(); r != nil { + println("AssertOriginCall: panic:", r.(string)) + } + }() + std.AssertOriginCall() + println("AssertOriginCall: no panic") +} + +// Output: +// IsOriginCall: false +// AssertOriginCall: panic: invalid non-origin call +// IsOriginCall: true +// AssertOriginCall: no panic diff --git a/tests/integ/origin-call/origincall_test.gno b/tests/integ/origin-call/origincall_test.gno new file mode 100644 index 00000000000..41b5cde5619 --- /dev/null +++ b/tests/integ/origin-call/origincall_test.gno @@ -0,0 +1,38 @@ +package origincall + +import ( + "std" + "testing" + + "gno.land/p/demo/testutils" +) + +func TestOriginCall(t *testing.T) { + requirePanic(t, func() { + std.AssertOriginCall() + }, "invalid non-origin call") + // NOTE(tb): it's deceptively not possible to have a test for AssertOriginCall + // and an other test for IsOriginCall because the context is shared between + // tests (e.g. if std.TestSetOrigCaller is called in a test, this affects also + // the following test). + if b := std.IsOriginCall(); b { + t.Errorf("expect isOriginCall false, got true") + } + + std.TestSetOrigCaller(testutils.TestAddress("user")) + + std.AssertOriginCall() + if b := std.IsOriginCall(); !b { + t.Errorf("expect isOriginCall true, got false") + } +} + +func requirePanic(t *testing.T, f func(), expRecover string) { + defer func() { + r := recover() + if r == nil || r.(string) != expRecover { + t.Fatalf("expected panic with '%v', got '%v'", expRecover, r) + } + }() + f() +}