github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/r/demo/tests/z0_filetest.gno (about) 1 package main 2 3 import ( 4 "gno.land/r/demo/tests" 5 ) 6 7 func main() { 8 println("IsOriginCall:", tests.IsOriginCall()) 9 tests.AssertOriginCall() 10 println("AssertOriginCall doesn't panic when called directly") 11 12 func() { 13 // if called inside a function literal, this is no longer an origin call 14 // because there's one additional frame (the function literal). 15 println("IsOriginCall:", tests.IsOriginCall()) 16 defer func() { 17 r := recover() 18 println("AssertOriginCall panics if when called inside a function literal:", r) 19 }() 20 tests.AssertOriginCall() 21 }() 22 } 23 24 // Output: 25 // IsOriginCall: true 26 // AssertOriginCall doesn't panic when called directly 27 // IsOriginCall: false 28 // AssertOriginCall panics if when called inside a function literal: invalid non-origin call