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

fix: add missing args field to gnoclient Call #1616

Merged
merged 7 commits into from
Feb 2, 2024
Merged
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
2 changes: 1 addition & 1 deletion gno.land/pkg/gnoclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestClient_CallMultiple(t *testing.T) {
{
PkgPath: "gno.land/r/demo/tamagotchi",
FuncName: "Feed",
Args: []string{},
Args: []string{""},
Send: "",
},
}
Expand Down
1 change: 1 addition & 0 deletions gno.land/pkg/gnoclient/client_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
Expand Down
127 changes: 127 additions & 0 deletions gno.land/pkg/gnoclient/integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
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"
"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"
)

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: "",
}

// Same call, different argument
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)
}

// todo add more integration tests.

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
}
}
Loading