Skip to content
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

feat(tm2/gnovm): add msg_idx in event to identify #2061

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/gno.land/r/demo/event/event.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package event

import (
"std"
)

func Emit(value string) {
std.Emit("TAG", "key", value)
}
1 change: 1 addition & 0 deletions examples/gno.land/r/demo/event/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/demo/event
4 changes: 2 additions & 2 deletions gno.land/cmd/gnoland/testdata/event.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ stdout OK!
stdout 'GAS WANTED: 2000000'
stdout 'GAS USED: \d+'
stdout 'HEIGHT: \d+'
stdout 'EVENTS: \[{\"type\":\"foo\",\"pkg_path\":\"gno.land\/r\/demo\/ee\",\"func\":\"SubFoo\",\"attrs\":\[{\"key\":\"key1\",\"value\":\"value1\"},{\"key\":\"key2\",\"value\":\"value2\"},{\"key\":\"key3\",\"value\":\"value3\"}\]},{\"type\":\"bar\",\"pkg_path\":\"gno.land\/r\/demo\/ee\",\"func\":\"SubBar\",\"attrs\":\[{\"key\":\"bar\",\"value\":\"baz\"}\]}\]'
stdout 'EVENTS: \[{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/ee\",\"func\":\"SubFoo\",\"type\":\"foo\",\"attrs\":\[{\"key\":\"key1\",\"value\":\"value1\"},{\"key\":\"key2\",\"value\":\"value2\"},{\"key\":\"key3\",\"value\":\"value3\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/ee\",\"func\":\"SubBar\",\"type\":\"bar\",\"attrs\":\[{\"key\":\"bar\",\"value\":\"baz\"}\]}\]'

gnokey maketx call -pkgpath gno.land/r/demo/ee -func Bar -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
stdout OK!
stdout 'GAS WANTED: 2000000'
stdout 'GAS USED: \d+'
stdout 'HEIGHT: \d+'
stdout 'EVENTS: \[{\"type\":\"bar\",\"pkg_path\":\"gno.land\/r\/demo\/ee\",\"func\":\"Bar\",\"attrs\":\[{\"key\":\"foo\",\"value\":\"bar\"}\]}\]'
stdout 'EVENTS: \[{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/ee\",\"func\":\"Bar\",\"type\":\"bar\",\"attrs\":\[{\"key\":\"foo\",\"value\":\"bar\"}\]}\]'

-- ee.gno --
package ee
Expand Down
2 changes: 1 addition & 1 deletion gno.land/cmd/gnoland/testdata/event_callback.txtar
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\":\"foo\",\"pkg_path\":\"gno\.land\/r\/demo\/cbee\",\"func\":\"subFoo\",\"attrs\":\[{\"key\":\"k1\",\"value\":\"v1\"},{\"key\":\"k2\",\"value\":\"v2\"}\]},{\"type\":\"bar\",\"pkg_path\":\"gno\.land\/r\/demo\/cbee\",\"func\":\"subBar\",\"attrs\":\[{\"key\":\"bar\",\"value\":\"baz\"}\]}\]'
stdout 'EVENTS: \[{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/cbee\",\"func\":\"subFoo\",\"type\":\"foo\",\"attrs\":\[{\"key\":\"k1\",\"value\":\"v1\"},{\"key\":\"k2\",\"value\":\"v2\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/cbee\",\"func\":\"subBar\",\"type\":\"bar\",\"attrs\":\[{\"key\":\"bar\",\"value\":\"baz\"}\]}\]'


-- cbee.gno --
Expand Down
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\",\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"\",\"attrs\":\[{\"key\":\"iteration\",\"value\":\"0\"},{\"key\":\"key\",\"value\":\"value\"}\]},{\"type\":\"ForLoopEvent\",\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"\",\"attrs\":\[{\"key\":\"iteration\",\"value\":\"1\"},{\"key\":\"key\",\"value\":\"value\"}\]},{\"type\":\"ForLoopEvent\",\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"\",\"attrs\":\[{\"key\":\"iteration\",\"value\":\"2\"},{\"key\":\"key\",\"value\":\"value\"}\]},{\"type\":\"ForLoopCompletionEvent\",\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"forLoopEmitExample\",\"attrs\":\[{\"key\":\"count\",\"value\":\"3\"}\]},{\"type\":\"CallbackEvent\",\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"\",\"attrs\":\[{\"key\":\"key1\",\"value\":\"value1\"},{\"key\":\"key2\",\"value\":\"value2\"}\]},{\"type\":\"CallbackCompletionEvent\",\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"callbackEmitExample\",\"attrs\":\[{\"key\":\"key\",\"value\":\"value\"}\]},{\"type\":\"DeferEvent\",\"pkg_path\":\"gno.land\/r\/demo\/edcl\",\"func\":\"deferEmitExample\",\"attrs\":\[{\"key\":\"key1\",\"value\":\"value1\"},{\"key\":\"key2\",\"value\":\"value2\"}\]}\]'
stdout 'EVENTS: \[{\"msg_idx\":0,\"pkg_path\":\"gno.land/r/demo/edcl\",\"func\":\"\",\"type\":\"ForLoopEvent\",\"attrs\":\[{\"key\":\"iteration\",\"value\":\"0\"},{\"key\":\"key\",\"value\":\"value\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land/r/demo/edcl\",\"func\":\"\",\"type\":\"ForLoopEvent\",\"attrs\":\[{\"key\":\"iteration\",\"value\":\"1\"},{\"key\":\"key\",\"value\":\"value\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land/r/demo/edcl\",\"func\":\"\",\"type\":\"ForLoopEvent\",\"attrs\":\[{\"key\":\"iteration\",\"value\":\"2\"},{\"key\":\"key\",\"value\":\"value\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land/r/demo/edcl\",\"func\":\"forLoopEmitExample\",\"type\":\"ForLoopCompletionEvent\",\"attrs\":\[{\"key\":\"count\",\"value\":\"3\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land/r/demo/edcl\",\"func\":\"\",\"type\":\"CallbackEvent\",\"attrs\":\[{\"key\":\"key1\",\"value\":\"value1\"},{\"key\":\"key2\",\"value\":\"value2\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land/r/demo/edcl\",\"func\":\"callbackEmitExample\",\"type\":\"CallbackCompletionEvent\",\"attrs\":\[{\"key\":\"key\",\"value\":\"value\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land/r/demo/edcl\",\"func\":\"deferEmitExample\",\"type\":\"DeferEvent\",\"attrs\":\[{\"key\":\"key1\",\"value\":\"value1\"},{\"key\":\"key2\",\"value\":\"value2\"}\]}\]'

-- edcl.gno --

Expand Down
4 changes: 2 additions & 2 deletions gno.land/cmd/gnoland/testdata/event_for_statement.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ stdout OK!
stdout 'GAS WANTED: 2000000'
stdout 'GAS USED: [0-9]+'
stdout 'HEIGHT: [0-9]+'
stdout 'EVENTS: \[{"type":"testing","pkg_path":"gno.land\/r\/demo\/foree","func":"Foo","attrs":\[{"key":"foo","value":"bar"}\]},{"type":"testing","pkg_path":"gno.land\/r\/demo\/foree","func":"Foo","attrs":\[{"key":"foo","value":"bar"}\]},{"type":"testing","pkg_path":"gno.land\/r\/demo\/foree","func":"Foo","attrs":\[{"key":"foo","value":"bar"}\]},{"type":"testing","pkg_path":"gno.land\/r\/demo\/foree","func":"Foo","attrs":\[{"key":"foo","value":"bar"}\]},{"type":"testing","pkg_path":"gno.land\/r\/demo\/foree","func":"Foo","attrs":\[{"key":"foo","value":"bar"}\]},{"type":"testing","pkg_path":"gno.land\/r\/demo\/foree","func":"Foo","attrs":\[{"key":"foo","value":"bar"}\]},{"type":"testing","pkg_path":"gno.land\/r\/demo\/foree","func":"Foo","attrs":\[{"key":"foo","value":"bar"}\]},{"type":"testing","pkg_path":"gno.land\/r\/demo\/foree","func":"Foo","attrs":\[{"key":"foo","value":"bar"}\]},{"type":"testing","pkg_path":"gno.land\/r\/demo\/foree","func":"Foo","attrs":\[{"key":"foo","value":"bar"}\]},{"type":"testing","pkg_path":"gno.land\/r\/demo\/foree","func":"Foo","attrs":\[{"key":"foo","value":"bar"}\]}\]'
stdout 'EVENTS: \[{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/foree\",\"func\":\"Foo\",\"type\":\"testing\",\"attrs\":\[{\"key\":\"foo\",\"value\":\"bar\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/foree\",\"func\":\"Foo\",\"type\":\"testing\",\"attrs\":\[{\"key\":\"foo\",\"value\":\"bar\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/foree\",\"func\":\"Foo\",\"type\":\"testing\",\"attrs\":\[{\"key\":\"foo\",\"value\":\"bar\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/foree\",\"func\":\"Foo\",\"type\":\"testing\",\"attrs\":\[{\"key\":\"foo\",\"value\":\"bar\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/foree\",\"func\":\"Foo\",\"type\":\"testing\",\"attrs\":\[{\"key\":\"foo\",\"value\":\"bar\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/foree\",\"func\":\"Foo\",\"type\":\"testing\",\"attrs\":\[{\"key\":\"foo\",\"value\":\"bar\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/foree\",\"func\":\"Foo\",\"type\":\"testing\",\"attrs\":\[{\"key\":\"foo\",\"value\":\"bar\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/foree\",\"func\":\"Foo\",\"type\":\"testing\",\"attrs\":\[{\"key\":\"foo\",\"value\":\"bar\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/foree\",\"func\":\"Foo\",\"type\":\"testing\",\"attrs\":\[{\"key\":\"foo\",\"value\":\"bar\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/foree\",\"func\":\"Foo\",\"type\":\"testing\",\"attrs\":\[{\"key\":\"foo\",\"value\":\"bar\"}\]}\]'

gnokey maketx call -pkgpath gno.land/r/demo/foree -func Bar -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
stdout OK!
stdout 'GAS WANTED: 2000000'
stdout 'GAS USED: [0-9]+'
stdout 'HEIGHT: [0-9]+'
stdout 'EVENTS: \[{"type":"Foo","pkg_path":"gno.land\/r\/demo\/foree","func":"subFoo","attrs":\[{"key":"k1","value":"v1"},{"key":"k2","value":"v2"}\]},{"type":"Bar","pkg_path":"gno.land\/r\/demo\/foree","func":"subBar","attrs":\[{"key":"bar","value":"baz"}\]},{"type":"Foo","pkg_path":"gno.land\/r\/demo\/foree","func":"subFoo","attrs":\[{"key":"k1","value":"v1"},{"key":"k2","value":"v2"}\]},{"type":"Bar","pkg_path":"gno.land\/r\/demo\/foree","func":"subBar","attrs":\[{"key":"bar","value":"baz"}\]}\]'
stdout 'EVENTS: \[{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/foree\",\"func\":\"subFoo\",\"type\":\"Foo\",\"attrs\":\[{\"key\":\"k1\",\"value\":\"v1\"},{\"key\":\"k2\",\"value\":\"v2\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/foree\",\"func\":\"subBar\",\"type\":\"Bar\",\"attrs\":\[{\"key\":\"bar\",\"value\":\"baz\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/foree\",\"func\":\"subFoo\",\"type\":\"Foo\",\"attrs\":\[{\"key\":\"k1\",\"value\":\"v1\"},{\"key\":\"k2\",\"value\":\"v2\"}]},{\"msg_idx\":0,\"pkg_path\":\"gno.land\/r\/demo\/foree\",\"func\":\"subBar\",\"type\":\"Bar\",\"attrs\":\[{\"key\":\"bar\",\"value\":\"baz\"}\]}\]'


-- foree.gno --
Expand Down
97 changes: 96 additions & 1 deletion gno.land/pkg/gnoclient/client_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,62 @@
return c.signAndBroadcastTxCommit(tx, cfg.AccountNumber, cfg.SequenceNumber)
}

// CallTxSync executes one or more MsgCall calls on the blockchain synchronously
func (c *Client) CallTxSync(cfg BaseTxCfg, msgs ...MsgCall) (*ctypes.ResultBroadcastTx, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should leave this for a separate PR 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

// Validate required client fields.
if err := c.validateSigner(); err != nil {

Check warning on line 120 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L120

Added line #L120 was not covered by tests
return nil, err
}
if err := c.validateRPCClient(); err != nil {

Check warning on line 123 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L123

Added line #L123 was not covered by tests
return nil, err
}

// Validate base transaction config
if err := cfg.validateBaseTxConfig(); err != nil {

Check warning on line 128 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L128

Added line #L128 was not covered by tests
return nil, err
}

// Parse MsgCall slice
vmMsgs := make([]std.Msg, 0, len(msgs))
for _, msg := range msgs {
// Validate MsgCall fields
if err := msg.validateMsgCall(); err != nil {

Check warning on line 136 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L136

Added line #L136 was not covered by tests
return nil, err
}

// Parse send coins
send, err := std.ParseCoins(msg.Send)
if err != nil {

Check warning on line 142 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L142

Added line #L142 was not covered by tests
return nil, err
}

// Unwrap syntax sugar to vm.MsgCall slice
vmMsgs = append(vmMsgs, std.Msg(vm.MsgCall{
Caller: c.Signer.Info().GetAddress(),
PkgPath: msg.PkgPath,
Func: msg.FuncName,
Args: msg.Args,
Send: send,
}))
}

// Parse gas fee
gasFeeCoins, err := std.ParseCoin(cfg.GasFee)
if err != nil {

Check warning on line 158 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L158

Added line #L158 was not covered by tests
return nil, err
}

// Pack transaction
tx := std.Tx{
Msgs: vmMsgs,
Fee: std.NewFee(cfg.GasWanted, gasFeeCoins),
Signatures: nil,
Memo: cfg.Memo,
}

return c.signAndBroadcastTxSync(tx, cfg.AccountNumber, cfg.SequenceNumber)
}

// Run executes one or more MsgRun calls on the blockchain
func (c *Client) Run(cfg BaseTxCfg, msgs ...MsgRun) (*ctypes.ResultBroadcastTxCommit, error) {
// Validate required client fields.
Expand Down Expand Up @@ -297,7 +353,7 @@
func (c *Client) signAndBroadcastTxCommit(tx std.Tx, accountNumber, sequenceNumber uint64) (*ctypes.ResultBroadcastTxCommit, error) {
caller := c.Signer.Info().GetAddress()

if sequenceNumber == 0 || accountNumber == 0 {
if sequenceNumber == 0 && accountNumber == 0 { // needs to be AND condition, if OR condition ≈ one of value will ignored
account, _, err := c.QueryAccount(caller)
if err != nil {
return nil, errors.Wrap(err, "query account")
Expand Down Expand Up @@ -336,4 +392,43 @@
return bres, nil
}

func (c *Client) signAndBroadcastTxSync(tx std.Tx, accountNumber, sequenceNumber uint64) (*ctypes.ResultBroadcastTx, error) {
caller := c.Signer.Info().GetAddress()

if sequenceNumber == 0 && accountNumber == 0 {
account, _, err := c.QueryAccount(caller)
if err != nil {
return nil, errors.Wrap(err, "query account")
}
accountNumber = account.AccountNumber

Check warning on line 403 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L403

Added line #L403 was not covered by tests
sequenceNumber = account.Sequence
}

signCfg := SignCfg{
UnsignedTX: tx,

Check warning on line 408 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L408

Added line #L408 was not covered by tests
SequenceNumber: sequenceNumber,
AccountNumber: accountNumber,
}
signedTx, err := c.Signer.Sign(signCfg)
if err != nil {

Check warning on line 413 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L413

Added line #L413 was not covered by tests
return nil, errors.Wrap(err, "sign")
}

bz, err := amino.Marshal(signedTx)

Check warning on line 417 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L417

Added line #L417 was not covered by tests
if err != nil {
return nil, errors.Wrap(err, "marshaling tx binary bytes")
}

bres, err := c.RPCClient.BroadcastTxSync(bz)
if err != nil {
return nil, errors.Wrap(err, "broadcasting bytes")
}

if bres.Error != nil {
return bres, errors.Wrap(bres.Error, "broadcast transaction failed: log:%s", bres.Log)
}

return bres, nil
}

// TODO: Add more functionality, examples, and unit tests.
182 changes: 182 additions & 0 deletions gno.land/pkg/gnoclient/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package gnoclient

import (
"fmt"
"testing"
"time"

"github.com/gnolang/gno/gnovm/pkg/gnolang"

Expand Down Expand Up @@ -113,6 +115,181 @@ func TestCallMultiple_Integration(t *testing.T) {
assert.Equal(t, expected, got)
}

func TestCall_SingleTx_MultipleMsg_MultipleEvent_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
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, "{0 gno.land/r/demo/event Emit TAG [{key first_value}]}")

event1 := fmt.Sprintf("%v", blockRes.Results.DeliverTxs[0].Events[1])
assert.Equal(t, event1, "{1 gno.land/r/demo/event Emit TAG [{key second_value}]}")
}

func TestCall_MultipleTx_MultipleMsg_MultipleEvent_Integration(t *testing.T) {
// Set up in-memory node
config, _ := integration.TestingNodeConfig(t, gnoenv.RootDir())

// make node slower (same as current master branch)
config.TMConfig.Consensus.TimeoutCommit = 5 * time.Second
config.TMConfig.Consensus.SkipTimeoutCommit = false
config.TMConfig.Consensus.CreateEmptyBlocks = true
config.TMConfig.Consensus.CreateEmptyBlocksInterval = 0 * time.Second

node, remoteAddr := integration.TestingInMemoryNode(t, log.NewNoopLogger(), config)
defer node.Stop()

// Init Signer & RPCClient
signer := newInMemorySigner(t, "tendermint_test")
assert.Equal(t, signer.Account, "test1")

rpcClient, err := rpcclient.NewHTTPClient(remoteAddr)
require.NoError(t, err)

// Setup Client
client := Client{
Signer: signer,
RPCClient: rpcClient,
}
assert.Equal(t, int64(1), client.latestHeight())

// Make Tx config
baseCfg := BaseTxCfg{
GasFee: "10000ugnot",
GasWanted: 8000000,
AccountNumber: 0,
SequenceNumber: 0,
Memo: "",
}

msg1 := MsgCall{
PkgPath: "gno.land/r/demo/event",
FuncName: "Emit",
Args: []string{"test1_1stTx_1stEvent"},
Send: "",
}

msg2 := MsgCall{
PkgPath: "gno.land/r/demo/event",
FuncName: "Emit",
Args: []string{"test1_1stTx_2ndEvent"},
Send: "",
}
_, err = client.CallTxSync(baseCfg, msg1, msg2)
assert.Nil(t, err)
assert.Equal(t, int64(1), client.latestHeight())

msg3 := MsgCall{
PkgPath: "gno.land/r/demo/event",
FuncName: "Emit",
Args: []string{"test1_2ndTx_1stEvent"},
Send: "",
}

msg4 := MsgCall{
PkgPath: "gno.land/r/demo/event",
FuncName: "Emit",
Args: []string{"test1_2ndTx_2ndEvent"},
Send: "",
}

baseCfg.SequenceNumber += 1
_, err = client.CallTxSync(baseCfg, msg3, msg4)
assert.Nil(t, err)
assert.Equal(t, int64(1), client.latestHeight())

// need this dummy ??
toAddres, _ := crypto.AddressFromBech32("g14a0y9a64dugh3l7hneshdxr4w0rfkkww9ls35p")
amount := 10
msg5 := MsgSend{
ToAddress: toAddres,
Send: std.Coin{"ugnot", int64(amount)}.String(),
}
baseCfg.SequenceNumber += 1
res, err := client.Send(baseCfg, msg5)
assert.Nil(t, err)

assert.Equal(t, int64(2), res.Height)
assert.Equal(t, int64(2), client.latestHeight())

latestRes, _ := client.BlockResult(res.Height)
assert.Equal(t, int(3), len(latestRes.Results.DeliverTxs))

beforeRes, _ := client.BlockResult(res.Height - 1)
assert.Equal(t, int(0), len(beforeRes.Results.DeliverTxs))

// 1st TX
tx0 := latestRes.Results.DeliverTxs[0]
assert.Equal(t, int(2), len(tx0.Events))

tx0evt0 := fmt.Sprint(tx0.Events[0])
assert.Equal(t, "{0 gno.land/r/demo/event Emit TAG [{key test1_1stTx_1stEvent}]}", tx0evt0)

tx0evt1 := fmt.Sprint(tx0.Events[1])
assert.Equal(t, "{1 gno.land/r/demo/event Emit TAG [{key test1_1stTx_2ndEvent}]}", tx0evt1)

// 2nd TX
tx1 := latestRes.Results.DeliverTxs[1]
assert.Equal(t, int(2), len(tx1.Events))

tx1evt0 := fmt.Sprint(tx1.Events[0])
assert.Equal(t, "{0 gno.land/r/demo/event Emit TAG [{key test1_2ndTx_1stEvent}]}", tx1evt0)

tx1evt1 := fmt.Sprint(tx1.Events[1])
assert.Equal(t, "{1 gno.land/r/demo/event Emit TAG [{key test1_2ndTx_2ndEvent}]}", tx1evt1)

// 3rd TX == no event
tx2 := latestRes.Results.DeliverTxs[2]
assert.Equal(t, int(0), len(tx2.Events))
}

func TestSendSingle_Integration(t *testing.T) {
// Set up in-memory node
config, _ := integration.TestingNodeConfig(t, gnoenv.RootDir())
Expand Down Expand Up @@ -555,3 +732,8 @@ func newInMemorySigner(t *testing.T, chainid string) *SignerFromKeybase {
ChainID: chainid, // Chain ID for transaction signing
}
}

func (c *Client) latestHeight() int64 {
height, _ := c.LatestBlockHeight()
return height
}
Loading
Loading