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

chore: In gnoclient, separate out SignTx and BroadcastTxCommit #2641

Merged
Show file tree
Hide file tree
Changes from 6 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
58 changes: 55 additions & 3 deletions gno.land/pkg/gnoclient/client_test.go
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ func TestCallSingle(t *testing.T) {
res, err := client.Call(cfg, msg...)
assert.NoError(t, err)
require.NotNil(t, res)
assert.Equal(t, string(res.DeliverTx.Data), "it works!")
expected := "it works!"
assert.Equal(t, string(res.DeliverTx.Data), expected)

res, err = callSigningSeparately(t, client, cfg, msg...)
assert.NoError(t, err)
require.NotNil(t, res)
assert.Equal(t, string(res.DeliverTx.Data), expected)
}

func TestCallMultiple(t *testing.T) {
Expand Down Expand Up @@ -177,6 +183,10 @@ func TestCallMultiple(t *testing.T) {
res, err := client.Call(cfg, msg...)
assert.NoError(t, err)
assert.NotNil(t, res)

res, err = callSigningSeparately(t, client, cfg, msg...)
assert.NoError(t, err)
assert.NotNil(t, res)
}

func TestCallErrors(t *testing.T) {
Expand Down Expand Up @@ -617,7 +627,13 @@ func main() {
res, err := client.Run(cfg, msg)
assert.NoError(t, err)
require.NotNil(t, res)
assert.Equal(t, "hi gnoclient!\n", string(res.DeliverTx.Data))
expected := "hi gnoclient!\n"
assert.Equal(t, expected, string(res.DeliverTx.Data))

res, err = runSigningSeparately(t, client, cfg, msg)
assert.NoError(t, err)
require.NotNil(t, res)
assert.Equal(t, expected, string(res.DeliverTx.Data))
}

func TestRunMultiple(t *testing.T) {
Expand Down Expand Up @@ -696,7 +712,13 @@ func main() {
res, err := client.Run(cfg, msg1, msg2)
assert.NoError(t, err)
require.NotNil(t, res)
assert.Equal(t, "hi gnoclient!\nhi gnoclient!\n", string(res.DeliverTx.Data))
expected := "hi gnoclient!\nhi gnoclient!\n"
assert.Equal(t, expected, string(res.DeliverTx.Data))

res, err = runSigningSeparately(t, client, cfg, msg1, msg2)
assert.NoError(t, err)
require.NotNil(t, res)
assert.Equal(t, expected, string(res.DeliverTx.Data))
}

func TestRunErrors(t *testing.T) {
Expand Down Expand Up @@ -1266,3 +1288,33 @@ func TestLatestBlockHeightErrors(t *testing.T) {
})
}
}

// The same as client.Call, but test signing separately
func callSigningSeparately(t *testing.T, client Client, cfg BaseTxCfg, msgs ...MsgCall) (*ctypes.ResultBroadcastTxCommit, error) {
t.Helper()
tx, err := client.MakeCallTx(cfg, msgs...)
assert.NoError(t, err)
require.NotNil(t, tx)
signedTx, err := client.SignTx(*tx, cfg.AccountNumber, cfg.SequenceNumber)
assert.NoError(t, err)
require.NotNil(t, signedTx)
res, err := client.BroadcastTxCommit(signedTx)
assert.NoError(t, err)
require.NotNil(t, res)
return res, nil
}

// The same as client.Run, but test signing separately
func runSigningSeparately(t *testing.T, client Client, cfg BaseTxCfg, msgs ...MsgRun) (*ctypes.ResultBroadcastTxCommit, error) {
t.Helper()
tx, err := client.MakeRunTx(cfg, msgs...)
assert.NoError(t, err)
require.NotNil(t, tx)
signedTx, err := client.SignTx(*tx, cfg.AccountNumber, cfg.SequenceNumber)
assert.NoError(t, err)
require.NotNil(t, signedTx)
res, err := client.BroadcastTxCommit(signedTx)
assert.NoError(t, err)
require.NotNil(t, res)
return res, nil
}
Loading
Loading