From 8bb54b8597ae2527eb660e13aee596102bbec252 Mon Sep 17 00:00:00 2001 From: leohhhn Date: Thu, 1 Feb 2024 19:21:29 +0100 Subject: [PATCH 1/7] add missing arg field --- gno.land/pkg/gnoclient/client_txs.go | 1 + 1 file changed, 1 insertion(+) diff --git a/gno.land/pkg/gnoclient/client_txs.go b/gno.land/pkg/gnoclient/client_txs.go index 9f06217599f..1b791094b86 100644 --- a/gno.land/pkg/gnoclient/client_txs.go +++ b/gno.land/pkg/gnoclient/client_txs.go @@ -78,6 +78,7 @@ func (c *Client) Call(cfg BaseTxCfg, msgs ...MsgCall) (*ctypes.ResultBroadcastTx Caller: c.Signer.Info().GetAddress(), PkgPath: msg.PkgPath, Func: msg.FuncName, + Args: msg.Args, Send: send, }) } From 6a05c165937dfec23bac6422be9d07509f177194 Mon Sep 17 00:00:00 2001 From: leohhhn Date: Thu, 1 Feb 2024 20:04:02 +0100 Subject: [PATCH 2/7] add integration tests --- gno.land/pkg/gnoclient/client_test.go | 2 +- gno.land/pkg/gnoclient/integration_test.go | 125 +++++++++++++++++++++ 2 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 gno.land/pkg/gnoclient/integration_test.go diff --git a/gno.land/pkg/gnoclient/client_test.go b/gno.land/pkg/gnoclient/client_test.go index c7e6b3c6c5b..f5ff9ee3e1d 100644 --- a/gno.land/pkg/gnoclient/client_test.go +++ b/gno.land/pkg/gnoclient/client_test.go @@ -168,7 +168,7 @@ func TestClient_CallMultiple(t *testing.T) { { PkgPath: "gno.land/r/demo/tamagotchi", FuncName: "Feed", - Args: []string{}, + Args: []string{""}, Send: "", }, } diff --git a/gno.land/pkg/gnoclient/integration_test.go b/gno.land/pkg/gnoclient/integration_test.go new file mode 100644 index 00000000000..01e26b81ad3 --- /dev/null +++ b/gno.land/pkg/gnoclient/integration_test.go @@ -0,0 +1,125 @@ +package gnoclient + +import ( + "github.com/gnolang/gno/gno.land/pkg/integration" + "github.com/gnolang/gno/gnovm/pkg/gnoenv" + rpcclient "github.com/gnolang/gno/tm2/pkg/bft/rpc/client" + "github.com/gnolang/gno/tm2/pkg/crypto/keys" + "github.com/gnolang/gno/tm2/pkg/log" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "testing" +) + +func TestClient_Call_Single_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 := rpcclient.NewHTTP(remoteAddr, "/websocket") + + // Setup Client + client := Client{ + Signer: signer, + RPCClient: rpcClient, + } + + // Make Tx config + baseCfg := BaseTxCfg{ + GasFee: "10000ugnot", + GasWanted: 8000000, + AccountNumber: 0, + SequenceNumber: 0, + Memo: "", + } + + // Make Msg config + msg := MsgCall{ + PkgPath: "gno.land/r/demo/deep/very/deep", + FuncName: "Render", + Args: []string{"test argument"}, + Send: "", + } + + // Execute call + res, err := client.Call(baseCfg, msg) + + expected := "(\"hi test argument\" string)" + got := string(res.DeliverTx.Data) + + assert.Nil(t, err) + assert.Equal(t, expected, got) + +} + +func TestClient_Call_Multiple_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 := rpcclient.NewHTTP(remoteAddr, "/websocket") + + // 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/deep/very/deep", + FuncName: "Render", + Args: []string{""}, + Send: "", + } + + msg2 := MsgCall{ + PkgPath: "gno.land/r/demo/deep/very/deep", + FuncName: "Render", + Args: []string{"test argument"}, + Send: "", + } + + expected := "(\"it works!\" string)(\"hi test argument\" string)" + + // Execute call + res, err := client.Call(baseCfg, msg1, msg2) + + got := string(res.DeliverTx.Data) + assert.Nil(t, err) + assert.Equal(t, expected, got) + +} + +func newInMemorySigner(t *testing.T, chainid string) *SignerFromKeybase { + t.Helper() + + mnemonic := integration.DefaultAccount_Seed + name := integration.DefaultAccount_Name + + kb := keys.NewInMemory() + _, err := kb.CreateAccount(name, mnemonic, "", "", uint32(0), uint32(0)) + require.NoError(t, err) + + return &SignerFromKeybase{ + Keybase: kb, // Stores keys in memory or on disk + Account: name, // Account name or bech32 format + Password: "", // Password for encryption + ChainID: chainid, // Chain ID for transaction signing + } +} From 68b208d10cbd4a75ddf89c67e866bbcf2718b745 Mon Sep 17 00:00:00 2001 From: leohhhn Date: Thu, 1 Feb 2024 20:06:09 +0100 Subject: [PATCH 3/7] add comment --- gno.land/pkg/gnoclient/integration_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/gno.land/pkg/gnoclient/integration_test.go b/gno.land/pkg/gnoclient/integration_test.go index 01e26b81ad3..3720e761fee 100644 --- a/gno.land/pkg/gnoclient/integration_test.go +++ b/gno.land/pkg/gnoclient/integration_test.go @@ -88,6 +88,7 @@ func TestClient_Call_Multiple_Integration(t *testing.T) { Send: "", } + // Same call, different argument msg2 := MsgCall{ PkgPath: "gno.land/r/demo/deep/very/deep", FuncName: "Render", From 6bc7697709a4d720e0af8e00c731110a1c4f7f49 Mon Sep 17 00:00:00 2001 From: leohhhn Date: Thu, 1 Feb 2024 20:07:34 +0100 Subject: [PATCH 4/7] add todo comment --- gno.land/pkg/gnoclient/integration_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gno.land/pkg/gnoclient/integration_test.go b/gno.land/pkg/gnoclient/integration_test.go index 3720e761fee..1e11b3d69b4 100644 --- a/gno.land/pkg/gnoclient/integration_test.go +++ b/gno.land/pkg/gnoclient/integration_test.go @@ -107,6 +107,8 @@ func TestClient_Call_Multiple_Integration(t *testing.T) { } +// todo add more integration tests. + func newInMemorySigner(t *testing.T, chainid string) *SignerFromKeybase { t.Helper() From 9c542066d816ef32b2b6e5f8a77713bf8893fc7a Mon Sep 17 00:00:00 2001 From: leohhhn Date: Thu, 1 Feb 2024 20:09:13 +0100 Subject: [PATCH 5/7] remove newline --- 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 1e11b3d69b4..5d38d950083 100644 --- a/gno.land/pkg/gnoclient/integration_test.go +++ b/gno.land/pkg/gnoclient/integration_test.go @@ -104,7 +104,6 @@ func TestClient_Call_Multiple_Integration(t *testing.T) { got := string(res.DeliverTx.Data) assert.Nil(t, err) assert.Equal(t, expected, got) - } // todo add more integration tests. From f557399b21566bbfee3699deac31e0315fdfb6c2 Mon Sep 17 00:00:00 2001 From: leohhhn Date: Thu, 1 Feb 2024 20:09:31 +0100 Subject: [PATCH 6/7] remove newline --- 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 5d38d950083..e7a68256d02 100644 --- a/gno.land/pkg/gnoclient/integration_test.go +++ b/gno.land/pkg/gnoclient/integration_test.go @@ -52,7 +52,6 @@ func TestClient_Call_Single_Integration(t *testing.T) { assert.Nil(t, err) assert.Equal(t, expected, got) - } func TestClient_Call_Multiple_Integration(t *testing.T) { From adc3cdfbcef48d1915a75f2195ff4aab56cce743 Mon Sep 17 00:00:00 2001 From: leohhhn Date: Thu, 1 Feb 2024 20:15:05 +0100 Subject: [PATCH 7/7] make fmt --- gno.land/pkg/gnoclient/integration_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gno.land/pkg/gnoclient/integration_test.go b/gno.land/pkg/gnoclient/integration_test.go index e7a68256d02..4d06aaaf81f 100644 --- a/gno.land/pkg/gnoclient/integration_test.go +++ b/gno.land/pkg/gnoclient/integration_test.go @@ -1,6 +1,8 @@ package gnoclient import ( + "testing" + "github.com/gnolang/gno/gno.land/pkg/integration" "github.com/gnolang/gno/gnovm/pkg/gnoenv" rpcclient "github.com/gnolang/gno/tm2/pkg/bft/rpc/client" @@ -8,7 +10,6 @@ import ( "github.com/gnolang/gno/tm2/pkg/log" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" ) func TestClient_Call_Single_Integration(t *testing.T) {