Skip to content

fix(gnovm): use OpCall to run deferred statements #2597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/banktest/z_1_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ func main() {
}

// Error:
// cannot send "101000000ugnot", limit "100000000ugnot" exceeded with "" already spent
// panic: cannot send "101000000ugnot", limit "100000000ugnot" exceeded with "" already spent
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/banktest/z_3_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ func main() {
}

// Error:
// can only send coins from realm that created banker "g1tnpdmvrmtgql8fmxgsq9rwtst5hsxahk3f05dk", not "g1dv3435088tlrgggf745kaud0ptrkc9v42k8llz"
// panic: can only send coins from realm that created banker "g1tnpdmvrmtgql8fmxgsq9rwtst5hsxahk3f05dk", not "g1dv3435088tlrgggf745kaud0ptrkc9v42k8llz"
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_0_a_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ func main() {
}

// Error:
// unauthorized
// panic: unauthorized
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_0_c_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ func main() {
}

// Error:
// board not exist
// panic: board not exist
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_0_d_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ func main() {
}

// Error:
// thread not exist
// panic: thread not exist
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_0_e_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ func main() {
}

// Error:
// board not exist
// panic: board not exist
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_10_a_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ func main() {
}

// Error:
// invalid non-user call
// panic: invalid non-user call
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_10_b_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ func main() {
}

// Error:
// invalid non-user call
// panic: invalid non-user call
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_11_a_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ func main() {
}

// Error:
// invalid non-user call
// panic: invalid non-user call
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_11_b_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ func main() {
}

// Error:
// invalid non-user call
// panic: invalid non-user call
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_11_c_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ func main() {
}

// Error:
// invalid non-user call
// panic: invalid non-user call
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_12_a_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ func main() {
}

// Error:
// please register, otherwise minimum fee 100000000 is required if anonymous
// panic: please register, otherwise minimum fee 100000000 is required if anonymous
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_12_b_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ func main() {
}

// Error:
// src board not exist
// panic: src board not exist
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_12_c_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ func main() {
}

// Error:
// thread not exist
// panic: thread not exist
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_12_d_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ func main() {
}

// Error:
// dst board not exist
// panic: dst board not exist
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_5_b_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ func main() {
}

// Error:
// please register, otherwise minimum fee 100000000 is required if anonymous
// panic: please register, otherwise minimum fee 100000000 is required if anonymous
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_5_d_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ func main() {
}

// Error:
// please register, otherwise minimum fee 100000000 is required if anonymous
// panic: please register, otherwise minimum fee 100000000 is required if anonymous
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_9_a_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ func main() {
}

// Error:
// src board not exist
// panic: src board not exist
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_9_b_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ func main() {
}

// Error:
// dst board not exist
// panic: dst board not exist
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/disperse/z_2_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ func main() {
}

// Error:
// disperse: mismatch between coins sent and params called
// panic: disperse: mismatch between coins sent and params called
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/groups/z_0_a_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ func main() {
}

// Error:
// user not found
// panic: user not found
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/groups/z_1_b_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ func main() {
}

// Error:
// group id (2) does not exists
// panic: group id (2) does not exists
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/groups/z_1_c_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ func main() {
}

// Error:
// user not found
// panic: user not found
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/groups/z_2_b_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ func main() {
}

// Error:
// r/gnoland/users: non-user call
// panic: r/gnoland/users: non-user call
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/groups/z_2_d_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ func main() {
}

// Error:
// r/gnoland/users: non-user call
// panic: r/gnoland/users: non-user call
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/groups/z_2_f_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ func main() {
}

// Error:
// group id (20) does not exists
// panic: group id (20) does not exists
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/groups/z_2_g_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ func main() {
}

// Error:
// unauthorized to delete group
// panic: unauthorized to delete group
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/nft/z_1_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ func main() {
}

// Error:
// unauthorized
// panic: unauthorized
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/nft/z_4_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ func main() {
}

// Error:
// unauthorized
// panic: unauthorized
4 changes: 4 additions & 0 deletions examples/gno.land/r/demo/tests/tests.gno
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func CurrentRealmPath() string {
return std.CurrentRealm().PkgPath()
}

func PrintCurrentRealmPath() {
println(CurrentRealmPath())
}

var initOriginCaller = std.OriginCaller()

func InitOriginCaller() std.Address {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,6 @@ func main() {
// }
// ],
// "pkg_path": "gno.land/r/gov/dao/v2",
// "func": "ExecuteProposal"
// "func": "EmitProposalExecuted"
// }
// ]
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,6 @@ func main() {
// }
// ],
// "pkg_path": "gno.land/r/gov/dao/v2",
// "func": "ExecuteProposal"
// "func": "EmitProposalExecuted"
// }
// ]
2 changes: 1 addition & 1 deletion examples/gno.land/r/gov/dao/v2/prop1_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,6 @@ func main() {
// }
// ],
// "pkg_path": "gno.land/r/gov/dao/v2",
// "func": "ExecuteProposal"
// "func": "EmitProposalExecuted"
// }
// ]
2 changes: 1 addition & 1 deletion examples/gno.land/r/gov/dao/v2/prop2_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,6 @@ func main() {
// }
// ],
// "pkg_path": "gno.land/r/gov/dao/v2",
// "func": "ExecuteProposal"
// "func": "EmitProposalExecuted"
// }
// ]
2 changes: 1 addition & 1 deletion examples/gno.land/r/gov/dao/v2/prop3_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,6 @@ func main() {
// }
// ],
// "pkg_path": "gno.land/r/gov/dao/v2",
// "func": "ExecuteProposal"
// "func": "EmitProposalExecuted"
// }
// ]
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ func main() {
}

// Error:
// no realm has been registered
// panic: no realm has been registered
1 change: 1 addition & 0 deletions gno.land/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ _test.gnoland:; go test $(GOTEST_FLAGS) ./cmd/gnoland
_test.gnoweb:; go test $(GOTEST_FLAGS) ./cmd/gnoweb
_test.gnokey:; go test $(GOTEST_FLAGS) ./cmd/gnokey
_test.pkgs:; go test $(GOTEST_FLAGS) ./pkg/...
_test.pkgs.integ:; go test $(GOTEST_FLAGS) ./pkg/Integration
_test.pkgs.sync:; UPDATE_SCRIPTS=true go test $(GOTEST_FLAGS) ./pkg/...
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ stdout OK!
stdout 'GAS WANTED: 2000000'
stdout 'GAS USED: [0-9]+'
stdout 'HEIGHT: [0-9]+'
stdout 'EVENTS: \[{\"type\":\"ForLoopEvent\",\"attrs\":\[{\"key\":\"iteration\",\"value\":\"0\"},{\"key\":\"key\",\"value\":\"value\"}\],\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"\"},{\"type\":\"ForLoopEvent\",\"attrs\":\[{\"key\":\"iteration\",\"value\":\"1\"},{\"key\":\"key\",\"value\":\"value\"}\],\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"\"},{\"type\":\"ForLoopEvent\",\"attrs\":\[{\"key\":\"iteration\",\"value\":\"2\"},{\"key\":\"key\",\"value\":\"value\"}\],\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"\"},{\"type\":\"ForLoopCompletionEvent\",\"attrs\":\[{\"key\":\"count\",\"value\":\"3\"}\],\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"forLoopEmitExample\"},{\"type\":\"CallbackEvent\",\"attrs\":\[{\"key\":\"key1\",\"value\":\"value1\"},{\"key\":\"key2\",\"value\":\"value2\"}\],\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"\"},{\"type\":\"CallbackCompletionEvent\",\"attrs\":\[{\"key\":\"key\",\"value\":\"value\"}\],\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"callbackEmitExample\"},{\"type\":\"DeferEvent\",\"attrs\":\[{\"key\":\"key1\",\"value\":\"value1\"},{\"key\":\"key2\",\"value\":\"value2\"}\],\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"deferEmitExample\"}\]'
stdout 'EVENTS: \[{\"type\":\"ForLoopEvent\",\"attrs\":\[{\"key\":\"iteration\",\"value\":\"0\"},{\"key\":\"key\",\"value\":\"value\"}\],\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"\"},{\"type\":\"ForLoopEvent\",\"attrs\":\[{\"key\":\"iteration\",\"value\":\"1\"},{\"key\":\"key\",\"value\":\"value\"}\],\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"\"},{\"type\":\"ForLoopEvent\",\"attrs\":\[{\"key\":\"iteration\",\"value\":\"2\"},{\"key\":\"key\",\"value\":\"value\"}\],\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"\"},{\"type\":\"ForLoopCompletionEvent\",\"attrs\":\[{\"key\":\"count\",\"value\":\"3\"}\],\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"\"},{\"type\":\"CallbackEvent\",\"attrs\":\[{\"key\":\"key1\",\"value\":\"value1\"},{\"key\":\"key2\",\"value\":\"value2\"}\],\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"\"},{\"type\":\"CallbackCompletionEvent\",\"attrs\":\[{\"key\":\"key\",\"value\":\"value\"}\],\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"\"},{\"type\":\"DeferEvent\",\"attrs\":\[{\"key\":\"key1\",\"value\":\"value1\"},{\"key\":\"key2\",\"value\":\"value2\"}\],\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"\"}\]'
stdout 'TX HASH: '

-- edcl.gno --
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ stdout 'OK!'
# execute Transfer for invalid address
# This is expected to fail at the transaction simulation stage.
! gnokey maketx call -pkgpath gno.land/r/demo/foo20 -func Transfer -args g1ubwj0apf60hd90txhnh855fkac34rxlsvua0aa -args 1 -gas-fee 1000000ugnot -gas-wanted 10_000_000 -simulate only -broadcast -chainid=tendermint_test test1
stderr '"gnokey" error: --= Error =--\nData: invalid address'
stderr '"gnokey" error: --= Error =--\nData: panic: invalid address'
4 changes: 2 additions & 2 deletions gno.land/pkg/integration/testdata/params.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ stdout 'data: "-31337"'

# It is impossible to call std.SetParamXXX with a param key in the <prefix>:<key> format (e.g. "bank:p:lockTransfer") because it is an invalid key.
! gnokey maketx call -pkgpath gno.land/r/myrealm -func SetLockTransfer -args ugnot -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1
stderr 'Data: invalid param key: bank:p:lockTransfer'
stderr 'Data: panic: invalid param key: bank:p:lockTransfer'

# <prefix>.<key> is invalid (e.g., "bank.lockTransfer")
! gnokey maketx call -pkgpath gno.land/r/myrealm -func SetInvalidString -args ugnot -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1
stderr 'Data: invalid param key: bank:p:lockTransfer'
stderr 'Data: panic: invalid param key: bank:p:lockTransfer'

# <key_name>.<type> (e.g., "bank_lockTransfer") is a valid name.
gnokey maketx call -pkgpath gno.land/r/myrealm -func SetValidString -args ugnot -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1
Expand Down
4 changes: 2 additions & 2 deletions gno.land/pkg/sdk/vm/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func TestVmHandlerQuery_Eval(t *testing.T) {
// errors
{input: []byte(`gno.land/r/hello.doesnotexist`), expectedErrorMatch: `^/:0:0: name doesnotexist not declared:`}, // multiline error
{input: []byte(`gno.land/r/doesnotexist.Foo`), expectedErrorMatch: `^invalid package path$`},
{input: []byte(`gno.land/r/hello.Panic()`), expectedErrorMatch: `^foo$`},
{input: []byte(`gno.land/r/hello.sl[6]`), expectedErrorMatch: `^slice index out of bounds: 6 \(len=5\)$`},
{input: []byte(`gno.land/r/hello.Panic()`), expectedErrorMatch: `^panic: foo$`},
{input: []byte(`gno.land/r/hello.sl[6]`), expectedErrorMatch: `^slice index out of bounds: 6 \(len=5\) [] false $`},
{input: []byte(`gno.land/r/hello.func(){ for {} }()`), expectedErrorMatch: `out of gas in location: CPUCycles`},
}

Expand Down
1 change: 0 additions & 1 deletion gnovm/cmd/benchops/opcode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func TestLoadOpcodesPackage(t *testing.T) {
"OpLand",
"OpPanic",
"OpTypeSwitch",
"OpCallDeferNativeBody",
"OpRange",
"OpForLoop",
"OpTypes",
Expand Down
2 changes: 1 addition & 1 deletion gnovm/cmd/gno/testdata/test/error_correct.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ func main() {
}

// Error:
// oups
// panic: oups
2 changes: 1 addition & 1 deletion gnovm/cmd/gno/testdata/test/error_incorrect.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
stderr '=== RUN file/x_filetest.gno'
stderr 'Error diff:'
stderr '-xxx'
stderr '\+oups'
stderr '\+panic: oups'

-- x_filetest.gno --
package main
Expand Down
2 changes: 1 addition & 1 deletion gnovm/cmd/gno/testdata/test/error_sync.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ func main() {
}

// Error:
// oups
// panic: oups
2 changes: 1 addition & 1 deletion gnovm/cmd/gno/testdata/test/failing_filetest.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
! gno test -v .

stderr '=== RUN file/failing_filetest.gno'
stderr 'unexpected panic: beep boop'
stderr 'unexpected panic: panic: beep boop'

-- failing.gno --
package failing
Expand Down
1 change: 0 additions & 1 deletion gnovm/cmd/gno/testdata/test/panic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
! gno test .

! stdout .+
stderr '--- FAIL: TestPanic'
stderr 'panic: hello world'
stderr 'FAIL'

Expand Down
2 changes: 1 addition & 1 deletion gnovm/cmd/gno/testdata/test/recover.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ func TestBadRecoverSkip(t *testing.T) {

t.Skip("skipped")
panic("bad panic!")
}
}
2 changes: 1 addition & 1 deletion gnovm/cmd/gno/testdata/test/skip.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ func TestSkip(t *testing.T) {
t.Log("Hey")
t.Skip("I'm on strike!")
t.Log("so this shouldn't print")
}
}
8 changes: 0 additions & 8 deletions gnovm/pkg/benchops/gno/opcodes/opcode.gno
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ OpEval, (const (0 int))
OpIndex1, (array[(0 int)] [1]int)
OpReturnToBlock, [FRAME FUNC:OpDefer RECV:(undefined) (0 args) 1/0/0/0/1 LASTPKG:main LASTRLM:Realm(nil)]
OpReturnCallDefers
OpCallDeferNativeBody, len
OpReturnCallDefers
OpExec, bodyStmt[0/0/-2]=(init)
OpBody, a<VPBlock(2,1)>[(const (0 int))]++
Expand Down Expand Up @@ -770,13 +769,6 @@ func OpTypeSwitch() {
}
}

func OpCallDeferNativeBody() {
a := [1]int{0}
defer func() {
len(a)
}()
}

/*
OpEval, [(const (1 int))](const-type int){(const (1 int))}
OpEval, [(const (1 int))](const-type int)
Expand Down
3 changes: 2 additions & 1 deletion gnovm/pkg/gnolang/debugger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ func TestDebug(t *testing.T) {
{in: "up xxx", out: `"xxx": invalid syntax`},
{in: "b 37\nc\np b\n", out: "(3 int)"},
{in: "b 27\nc\np b\n", out: `("!zero" string)`},
{in: "b 22\nc\np t.A[3]\n", out: "Command failed: &{(\"slice index out of bounds: 3 (len=3)\" string) <nil> }"},
// m.Exception
{in: "b 22\nc\np t.A[3]\n", out: "Command failed: &{(\"slice index out of bounds: 3 (len=3)\" string) [] false }"},
{in: "b 43\nc\nc\nc\np i\ndetach\n", out: "(1 int)"},
{in: "b 37\nc\nnext\n", out: "=> 39:"},
{in: "b 40\nc\nnext\n", out: "=> 41:"},
Expand Down
Loading
Loading