From c24cb2dd6454a3e06fb3a04ee7c92c975d9be33b Mon Sep 17 00:00:00 2001 From: n3wbie Date: Fri, 3 May 2024 19:49:00 +0900 Subject: [PATCH 01/11] fix: multi-msg overwrites previous event(s) --- tm2/pkg/sdk/baseapp.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tm2/pkg/sdk/baseapp.go b/tm2/pkg/sdk/baseapp.go index 1801a0af35f..e40a02af969 100644 --- a/tm2/pkg/sdk/baseapp.go +++ b/tm2/pkg/sdk/baseapp.go @@ -652,11 +652,9 @@ func (app *BaseApp) runMsgs(ctx Context, msgs []Msg, mode RunTxMode) (result Res // Each message result's Data must be length prefixed in order to separate // each result. data = append(data, msgResult.Data...) - events = append(events, msgResult.Events...) - defer func() { - events = append(events, ctx.EventLogger().Events()...) - result.Events = events - }() + events = append(events, ctx.EventLogger().Events()...) + result.Events = events + // TODO append msgevent from ctx. XXX XXX // stop execution and return on first failed message From 0741acbee5f40dc8d101d5fc402e26004e815da0 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Tue, 7 May 2024 10:40:33 +0900 Subject: [PATCH 02/11] revert: append msgResult.Events --- tm2/pkg/sdk/baseapp.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tm2/pkg/sdk/baseapp.go b/tm2/pkg/sdk/baseapp.go index e40a02af969..b9cf96dafad 100644 --- a/tm2/pkg/sdk/baseapp.go +++ b/tm2/pkg/sdk/baseapp.go @@ -652,11 +652,10 @@ func (app *BaseApp) runMsgs(ctx Context, msgs []Msg, mode RunTxMode) (result Res // Each message result's Data must be length prefixed in order to separate // each result. data = append(data, msgResult.Data...) + events = append(events, msgResult.Events...) events = append(events, ctx.EventLogger().Events()...) result.Events = events - // TODO append msgevent from ctx. XXX XXX - // stop execution and return on first failed message if !msgResult.IsOK() { msgLogs = append(msgLogs, From 0ae0ac01aac44cf621eb8d98c50938187b4d45c9 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Tue, 7 May 2024 11:23:50 +0900 Subject: [PATCH 03/11] feat: append ctx events from outside of loop --- tm2/pkg/sdk/baseapp.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tm2/pkg/sdk/baseapp.go b/tm2/pkg/sdk/baseapp.go index b9cf96dafad..f7c7f5c73b0 100644 --- a/tm2/pkg/sdk/baseapp.go +++ b/tm2/pkg/sdk/baseapp.go @@ -624,6 +624,8 @@ func (app *BaseApp) getContextForTx(mode RunTxMode, txBytes []byte) (ctx Context // / runMsgs iterates through all the messages and executes them. func (app *BaseApp) runMsgs(ctx Context, msgs []Msg, mode RunTxMode) (result Result) { + ctx = ctx.WithEventLogger(NewEventLogger()) + msgLogs := make([]string, 0, len(msgs)) data := make([]byte, 0, len(msgs)) @@ -641,20 +643,17 @@ func (app *BaseApp) runMsgs(ctx Context, msgs []Msg, mode RunTxMode) (result Res } var msgResult Result - ctx = ctx.WithEventLogger(NewEventLogger()) // run the message! // skip actual execution for CheckTx mode if mode != RunTxModeCheck { - msgResult = handler.Process(ctx, msg) + msgResult = handler.Process(ctx, msg) // ctx event logger being updated in handler } // Each message result's Data must be length prefixed in order to separate // each result. data = append(data, msgResult.Data...) events = append(events, msgResult.Events...) - events = append(events, ctx.EventLogger().Events()...) - result.Events = events // stop execution and return on first failed message if !msgResult.IsOK() { @@ -669,12 +668,13 @@ func (app *BaseApp) runMsgs(ctx Context, msgs []Msg, mode RunTxMode) (result Res fmt.Sprintf("msg:%d,success:%v,log:%s,events:%v", i, true, msgResult.Log, events)) } + events = append(events, ctx.EventLogger().Events()...) result.Error = ABCIError(err) result.Data = data + result.Events = events result.Log = strings.Join(msgLogs, "\n") result.GasUsed = ctx.GasMeter().GasConsumed() - result.Events = events return result } From 7b5da677358eea21ad0d7db2c143ef19906df9d7 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Thu, 16 May 2024 18:16:29 +0900 Subject: [PATCH 04/11] test: add test cases --- examples/gno.land/r/demo/event/event.gno | 9 ++++ examples/gno.land/r/demo/event/gno.mod | 1 + gno.land/pkg/gnoclient/integration_test.go | 60 ++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 examples/gno.land/r/demo/event/event.gno create mode 100644 examples/gno.land/r/demo/event/gno.mod diff --git a/examples/gno.land/r/demo/event/event.gno b/examples/gno.land/r/demo/event/event.gno new file mode 100644 index 00000000000..9e5de540734 --- /dev/null +++ b/examples/gno.land/r/demo/event/event.gno @@ -0,0 +1,9 @@ +package event + +import ( + "std" +) + +func Emit(value string) { + std.Emit("TAG", "key", value) +} diff --git a/examples/gno.land/r/demo/event/gno.mod b/examples/gno.land/r/demo/event/gno.mod new file mode 100644 index 00000000000..64987d43d79 --- /dev/null +++ b/examples/gno.land/r/demo/event/gno.mod @@ -0,0 +1 @@ +module gno.land/r/demo/event diff --git a/gno.land/pkg/gnoclient/integration_test.go b/gno.land/pkg/gnoclient/integration_test.go index bd8079517d8..6672162b1c5 100644 --- a/gno.land/pkg/gnoclient/integration_test.go +++ b/gno.land/pkg/gnoclient/integration_test.go @@ -1,6 +1,7 @@ package gnoclient import ( + "fmt" "testing" "github.com/gnolang/gno/gnovm/pkg/gnolang" @@ -113,6 +114,65 @@ func TestCallMultiple_Integration(t *testing.T) { assert.Equal(t, expected, got) } +func TestCallMultipleEvent_Integration(t *testing.T) { + // Set up in-memory node + config, _ := integration.TestingNodeConfig(t, gnoenv.RootDir()) + node, remoteAddr := integration.TestingInMemoryNode(t, log.NewNoopLogger(), config) + defer node.Stop() + + // Init Signer & RPCClient + signer := newInMemorySigner(t, "tendermint_test") + rpcClient, err := rpcclient.NewHTTPClient(remoteAddr) + require.NoError(t, err) + + // Setup Client + client := Client{ + Signer: signer, + RPCClient: rpcClient, + } + + // Make Tx config + baseCfg := BaseTxCfg{ + GasFee: "10000ugnot", + GasWanted: 8000000, + AccountNumber: 0, + SequenceNumber: 0, + Memo: "", + } + + // Make Msg configs + msg1 := MsgCall{ + PkgPath: "gno.land/r/demo/event", + FuncName: "Emit", + Args: []string{"first_value"}, + Send: "", + } + + // Same call, different argument + msg2 := MsgCall{ + PkgPath: "gno.land/r/demo/event", + FuncName: "Emit", + Args: []string{"second_value"}, + Send: "", + } + + // Execute call + res, err := client.Call(baseCfg, msg1, msg2) + assert.Nil(t, err) + + // check response from block_results to get event + blockRes, err := client.BlockResult(res.Height) + assert.Nil(t, err) + + // XXX: better comparison ? + event0 := fmt.Sprintf("%v", blockRes.Results.DeliverTxs[0].Events[0]) + assert.Equal(t, event0, "{TAG gno.land/r/demo/event Emit [{key first_value}]}") + + event1 := fmt.Sprintf("%v", blockRes.Results.DeliverTxs[0].Events[1]) + assert.Equal(t, event1, "{TAG gno.land/r/demo/event Emit [{key second_value}]}") + +} + func TestSendSingle_Integration(t *testing.T) { // Set up in-memory node config, _ := integration.TestingNodeConfig(t, gnoenv.RootDir()) From dd0e6e0bd5a23979e2a74a1fe1d05a05f8355eed Mon Sep 17 00:00:00 2001 From: n3wbie Date: Thu, 16 May 2024 18:46:09 +0900 Subject: [PATCH 05/11] fix: lint --- gno.land/pkg/gnoclient/integration_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/gno.land/pkg/gnoclient/integration_test.go b/gno.land/pkg/gnoclient/integration_test.go index 6672162b1c5..d73d875b9d3 100644 --- a/gno.land/pkg/gnoclient/integration_test.go +++ b/gno.land/pkg/gnoclient/integration_test.go @@ -170,7 +170,6 @@ func TestCallMultipleEvent_Integration(t *testing.T) { event1 := fmt.Sprintf("%v", blockRes.Results.DeliverTxs[0].Events[1]) assert.Equal(t, event1, "{TAG gno.land/r/demo/event Emit [{key second_value}]}") - } func TestSendSingle_Integration(t *testing.T) { From 42a95ff7032568d912da8ebec0e46077cde634a2 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Wed, 22 May 2024 20:35:39 +0900 Subject: [PATCH 06/11] test: more strict condition --- gno.land/pkg/gnoclient/integration_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gno.land/pkg/gnoclient/integration_test.go b/gno.land/pkg/gnoclient/integration_test.go index d73d875b9d3..4c98c01ff54 100644 --- a/gno.land/pkg/gnoclient/integration_test.go +++ b/gno.land/pkg/gnoclient/integration_test.go @@ -164,6 +164,12 @@ func TestCallMultipleEvent_Integration(t *testing.T) { blockRes, err := client.BlockResult(res.Height) assert.Nil(t, err) + // only one tx in the block + assert.Len(t, blockRes.Results.DeliverTxs, 1) + + // only two event in the tx + assert.Len(t, blockRes.Results.DeliverTxs[0].Events, 2) + // XXX: better comparison ? event0 := fmt.Sprintf("%v", blockRes.Results.DeliverTxs[0].Events[0]) assert.Equal(t, event0, "{TAG gno.land/r/demo/event Emit [{key first_value}]}") @@ -264,12 +270,12 @@ func TestSendMultiple_Integration(t *testing.T) { // Execute send res, err := client.Send(baseCfg, msg1, msg2) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "", string(res.DeliverTx.Data)) // Get the new account balance account, _, err := client.QueryAccount(toAddress) - assert.Nil(t, err) + assert.NoError(t, err) expected := std.Coins{{"ugnot", int64(amount1 + amount2)}} got := account.GetCoins() From 6c292a27c55dec8bd6534bc64e86af79d29ba487 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Fri, 24 May 2024 00:57:16 +0900 Subject: [PATCH 07/11] fix: ci fail --- gnovm/stdlibs/stdshim/stdshim.gno | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gnovm/stdlibs/stdshim/stdshim.gno b/gnovm/stdlibs/stdshim/stdshim.gno index efffea59dae..34449f96dd7 100644 --- a/gnovm/stdlibs/stdshim/stdshim.gno +++ b/gnovm/stdlibs/stdshim/stdshim.gno @@ -79,3 +79,7 @@ func DecodeBech32(addr Address) (prefix string, bytes [20]byte, ok bool) { func DerivePkgAddr(pkgPath string) (addr Address) { panic(shimWarn) } + +func Emit(tag, key, value string) { + panic(shimWarn) +} From 8f0b19eacf585ab6d554b79525d7268328b0ec00 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Fri, 24 May 2024 15:34:32 +0900 Subject: [PATCH 08/11] test: multi-msg testing in txtar --- .../gnoland/testdata/event_multi_msg.txtar | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 gno.land/cmd/gnoland/testdata/event_multi_msg.txtar diff --git a/gno.land/cmd/gnoland/testdata/event_multi_msg.txtar b/gno.land/cmd/gnoland/testdata/event_multi_msg.txtar new file mode 100644 index 00000000000..727bd0ccab3 --- /dev/null +++ b/gno.land/cmd/gnoland/testdata/event_multi_msg.txtar @@ -0,0 +1,43 @@ +# load the package from $WORK directory +loadpkg gno.land/r/demo/simple_event $WORK/event + +# start a new node +gnoland start + +## test1 account should be available on default +gnokey query auth/accounts/${USER_ADDR_test1} +stdout 'height: 0' +stdout 'data: {' +stdout ' "BaseAccount": {' +stdout ' "address": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",' +stdout ' "coins": "[0-9]*ugnot",' # dynamic +stdout ' "public_key": null,' +stdout ' "account_number": "0",' +stdout ' "sequence": "0"' +stdout ' }' +stdout '}' +! stderr '.+' # empty + + +## sign +gnokey sign -tx-path $WORK/multi/multi_msg.tx -chainid=tendermint_test -account-number 0 -account-sequence 0 test1 +stdout 'Tx successfully signed and saved to ' + +## broadcast +gnokey broadcast $WORK/multi/multi_msg.tx -quiet=false +## not stdout ?? + +-- event/simple_event.gno -- +package simple_event + +import ( + "std" +) + +func Event(value string) { + std.Emit("TAG", "KEY", value) +} + +-- multi/multi_msg.tx -- +{"msg":[{"@type":"/vm.m_call","caller":"g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5","send":"","pkg_path":"gno.land/r/demo/simple_event","func":"Event","args":["value11"]},{"@type":"/vm.m_call","caller":"g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5","send":"","pkg_path":"gno.land/r/demo/simple_event","func":"Event","args":["value22"]}],"fee":{"gas_wanted":"2000000","gas_fee":"1000000ugnot"},"signatures":null,"memo":""} + From ca812b4ff1e234f85720a2760f56596a1023e117 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Fri, 24 May 2024 15:56:40 +0900 Subject: [PATCH 09/11] test: fix broadcast stdout --- .../gnoland/testdata/event_multi_msg.txtar | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/event_multi_msg.txtar b/gno.land/cmd/gnoland/testdata/event_multi_msg.txtar index 727bd0ccab3..86d9ad7b0f1 100644 --- a/gno.land/cmd/gnoland/testdata/event_multi_msg.txtar +++ b/gno.land/cmd/gnoland/testdata/event_multi_msg.txtar @@ -1,31 +1,18 @@ # load the package from $WORK directory loadpkg gno.land/r/demo/simple_event $WORK/event -# start a new node -gnoland start - -## test1 account should be available on default -gnokey query auth/accounts/${USER_ADDR_test1} -stdout 'height: 0' -stdout 'data: {' -stdout ' "BaseAccount": {' -stdout ' "address": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",' -stdout ' "coins": "[0-9]*ugnot",' # dynamic -stdout ' "public_key": null,' -stdout ' "account_number": "0",' -stdout ' "sequence": "0"' -stdout ' }' -stdout '}' -! stderr '.+' # empty - - ## sign gnokey sign -tx-path $WORK/multi/multi_msg.tx -chainid=tendermint_test -account-number 0 -account-sequence 0 test1 stdout 'Tx successfully signed and saved to ' + +# start a new node +gnoland start + + ## broadcast gnokey broadcast $WORK/multi/multi_msg.tx -quiet=false -## not stdout ?? +stdout OK! -- event/simple_event.gno -- package simple_event From 0fc305361dcbc367d0a259230b9e0652eda43f39 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Fri, 24 May 2024 16:06:23 +0900 Subject: [PATCH 10/11] chore --- .../gnoland/testdata/event_multi_msg.txtar | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/event_multi_msg.txtar b/gno.land/cmd/gnoland/testdata/event_multi_msg.txtar index 86d9ad7b0f1..7275a8cb954 100644 --- a/gno.land/cmd/gnoland/testdata/event_multi_msg.txtar +++ b/gno.land/cmd/gnoland/testdata/event_multi_msg.txtar @@ -1,18 +1,31 @@ # load the package from $WORK directory loadpkg gno.land/r/demo/simple_event $WORK/event -## sign -gnokey sign -tx-path $WORK/multi/multi_msg.tx -chainid=tendermint_test -account-number 0 -account-sequence 0 test1 -stdout 'Tx successfully signed and saved to ' - - # start a new node gnoland start +## test1 account should be available on default +gnokey query auth/accounts/${USER_ADDR_test1} +stdout 'height: 0' +stdout 'data: {' +stdout ' "BaseAccount": {' +stdout ' "address": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",' +stdout ' "coins": "[0-9]*ugnot",' # dynamic +stdout ' "public_key": null,' +stdout ' "account_number": "0",' +stdout ' "sequence": "0"' +stdout ' }' +stdout '}' +! stderr '.+' # empty + + +## sign +gnokey sign -tx-path $WORK/multi/multi_msg.tx -chainid=tendermint_test -account-number 0 -account-sequence 0 test1 +stdout 'Tx successfully signed and saved to ' ## broadcast gnokey broadcast $WORK/multi/multi_msg.tx -quiet=false -stdout OK! + -- event/simple_event.gno -- package simple_event From c990b49ad3ae1b2fbb31e9ffe760a3cc8965bed9 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Fri, 24 May 2024 22:40:56 +0900 Subject: [PATCH 11/11] test: remove wrong purpose tests --- gno.land/pkg/gnoclient/integration_test.go | 65 ---------------------- 1 file changed, 65 deletions(-) diff --git a/gno.land/pkg/gnoclient/integration_test.go b/gno.land/pkg/gnoclient/integration_test.go index 4c98c01ff54..9bcba7997ae 100644 --- a/gno.land/pkg/gnoclient/integration_test.go +++ b/gno.land/pkg/gnoclient/integration_test.go @@ -1,7 +1,6 @@ package gnoclient import ( - "fmt" "testing" "github.com/gnolang/gno/gnovm/pkg/gnolang" @@ -114,70 +113,6 @@ func TestCallMultiple_Integration(t *testing.T) { assert.Equal(t, expected, got) } -func TestCallMultipleEvent_Integration(t *testing.T) { - // Set up in-memory node - config, _ := integration.TestingNodeConfig(t, gnoenv.RootDir()) - node, remoteAddr := integration.TestingInMemoryNode(t, log.NewNoopLogger(), config) - defer node.Stop() - - // Init Signer & RPCClient - signer := newInMemorySigner(t, "tendermint_test") - rpcClient, err := rpcclient.NewHTTPClient(remoteAddr) - require.NoError(t, err) - - // Setup Client - client := Client{ - Signer: signer, - RPCClient: rpcClient, - } - - // Make Tx config - baseCfg := BaseTxCfg{ - GasFee: "10000ugnot", - GasWanted: 8000000, - AccountNumber: 0, - SequenceNumber: 0, - Memo: "", - } - - // Make Msg configs - msg1 := MsgCall{ - PkgPath: "gno.land/r/demo/event", - FuncName: "Emit", - Args: []string{"first_value"}, - Send: "", - } - - // Same call, different argument - msg2 := MsgCall{ - PkgPath: "gno.land/r/demo/event", - FuncName: "Emit", - Args: []string{"second_value"}, - Send: "", - } - - // Execute call - res, err := client.Call(baseCfg, msg1, msg2) - assert.Nil(t, err) - - // check response from block_results to get event - blockRes, err := client.BlockResult(res.Height) - assert.Nil(t, err) - - // only one tx in the block - assert.Len(t, blockRes.Results.DeliverTxs, 1) - - // only two event in the tx - assert.Len(t, blockRes.Results.DeliverTxs[0].Events, 2) - - // XXX: better comparison ? - event0 := fmt.Sprintf("%v", blockRes.Results.DeliverTxs[0].Events[0]) - assert.Equal(t, event0, "{TAG gno.land/r/demo/event Emit [{key first_value}]}") - - event1 := fmt.Sprintf("%v", blockRes.Results.DeliverTxs[0].Events[1]) - assert.Equal(t, event1, "{TAG gno.land/r/demo/event Emit [{key second_value}]}") -} - func TestSendSingle_Integration(t *testing.T) { // Set up in-memory node config, _ := integration.TestingNodeConfig(t, gnoenv.RootDir())