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: improve error message output in integration tests #1349

Merged
merged 6 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 7 additions & 5 deletions tm2/pkg/crypto/keys/client/addpkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
}
qres, err := queryHandler(qopts)
if err != nil {
return errors.Wrap(err, "query account")
return fmt.Errorf("unable to query account: %w", err)

Check warning on line 168 in tm2/pkg/crypto/keys/client/addpkg.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/addpkg.go#L168

Added line #L168 was not covered by tests
}
var qret struct{ BaseAccount std.BaseAccount }
err = amino.UnmarshalJSON(qres.Response.Data, &qret)
Expand Down Expand Up @@ -195,7 +195,7 @@

signedTx, err := SignHandler(sopts)
if err != nil {
return errors.Wrap(err, "sign tx")
return fmt.Errorf("unable to sign tx: %w", err)

Check warning on line 198 in tm2/pkg/crypto/keys/client/addpkg.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/addpkg.go#L198

Added line #L198 was not covered by tests
thehowl marked this conversation as resolved.
Show resolved Hide resolved
}

// broadcast signed tx
Expand All @@ -205,13 +205,15 @@
}
bres, err := broadcastHandler(bopts)
if err != nil {
return errors.Wrap(err, "broadcast tx")
return fmt.Errorf("unable to broadcast tx: %w", err)

Check warning on line 208 in tm2/pkg/crypto/keys/client/addpkg.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/addpkg.go#L208

Added line #L208 was not covered by tests
}
if bres.CheckTx.IsErr() {
return errors.Wrap(bres.CheckTx.Error, "check transaction failed: log:%s", bres.CheckTx.Log)
io.ErrPrintfln("response log: %s", bres.CheckTx.Log)
return fmt.Errorf("unable to check transaction: %w", bres.CheckTx.Error)

Check warning on line 212 in tm2/pkg/crypto/keys/client/addpkg.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/addpkg.go#L211-L212

Added lines #L211 - L212 were not covered by tests
}
if bres.DeliverTx.IsErr() {
return errors.Wrap(bres.DeliverTx.Error, "deliver transaction failed: log:%s", bres.DeliverTx.Log)
io.ErrPrintfln("response log: %s", bres.DeliverTx.Log)
return fmt.Errorf("unable to deliver transaction: %w", bres.DeliverTx.Error)

Check warning on line 216 in tm2/pkg/crypto/keys/client/addpkg.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/addpkg.go#L215-L216

Added lines #L215 - L216 were not covered by tests
}
io.Println(string(bres.DeliverTx.Data))
io.Println("OK!")
Expand Down
19 changes: 11 additions & 8 deletions tm2/pkg/crypto/keys/client/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import (
"context"
"flag"
"fmt"
"os"

"github.com/gnolang/gno/tm2/pkg/amino"
Expand Down Expand Up @@ -58,12 +59,12 @@

jsonbz, err := os.ReadFile(filename)
if err != nil {
return errors.Wrap(err, "reading tx document file "+filename)
return fmt.Errorf("unable to read tx document file %q: %w", filename, err)

Check warning on line 62 in tm2/pkg/crypto/keys/client/broadcast.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/broadcast.go#L62

Added line #L62 was not covered by tests
}
var tx std.Tx
err = amino.UnmarshalJSON(jsonbz, &tx)
if err != nil {
return errors.Wrap(err, "unmarshaling tx json bytes")
return fmt.Errorf("unable tounmarshal tx json: %w", err)

Check warning on line 67 in tm2/pkg/crypto/keys/client/broadcast.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/broadcast.go#L67

Added line #L67 was not covered by tests
}
cfg.tx = &tx

Expand All @@ -73,9 +74,11 @@
}

if res.CheckTx.IsErr() {
return errors.New("transaction failed %#v\nlog %s", res, res.CheckTx.Log)
io.ErrPrintln(res.CheckTx.Log)
return fmt.Errorf("unable to check transaction: %w", res.CheckTx.Error)

Check warning on line 78 in tm2/pkg/crypto/keys/client/broadcast.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/broadcast.go#L77-L78

Added lines #L77 - L78 were not covered by tests
} else if res.DeliverTx.IsErr() {
return errors.New("transaction failed %#v\nlog %s", res, res.DeliverTx.Log)
io.ErrPrintln(res.DeliverTx.Log)
return fmt.Errorf("unable to deliver transaction: %w", res.DeliverTx.Error)

Check warning on line 81 in tm2/pkg/crypto/keys/client/broadcast.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/broadcast.go#L80-L81

Added lines #L80 - L81 were not covered by tests
} else {
io.Println(string(res.DeliverTx.Data))
io.Println("OK!")
Expand All @@ -97,7 +100,7 @@

bz, err := amino.Marshal(cfg.tx)
if err != nil {
return nil, errors.Wrap(err, "remarshaling tx binary bytes")
return nil, fmt.Errorf("unable to remarshaling tx binary: %w", err)

Check warning on line 103 in tm2/pkg/crypto/keys/client/broadcast.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/broadcast.go#L103

Added line #L103 was not covered by tests
}

cli := client.NewHTTP(remote, "/websocket")
Expand All @@ -108,7 +111,7 @@

bres, err := cli.BroadcastTxCommit(bz)
if err != nil {
return nil, errors.Wrap(err, "broadcasting bytes")
return nil, fmt.Errorf("unable to broadcast: %w", err)

Check warning on line 114 in tm2/pkg/crypto/keys/client/broadcast.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/broadcast.go#L114

Added line #L114 was not covered by tests
}

return bres, nil
Expand All @@ -117,13 +120,13 @@
func simulateTx(cli client.ABCIClient, tx []byte) (*ctypes.ResultBroadcastTxCommit, error) {
bres, err := cli.ABCIQuery(".app/simulate", tx)
if err != nil {
return nil, errors.Wrap(err, "simulate tx")
return nil, fmt.Errorf("unable to simulate tx: %w", err)

Check warning on line 123 in tm2/pkg/crypto/keys/client/broadcast.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/broadcast.go#L123

Added line #L123 was not covered by tests
}

var result abci.ResponseDeliverTx
err = amino.Unmarshal(bres.Response.Value, &result)
if err != nil {
return nil, errors.Wrap(err, "unmarshaling simulate result")
return nil, fmt.Errorf("unable to unmarshal simulate result: %w", err)

Check warning on line 129 in tm2/pkg/crypto/keys/client/broadcast.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/broadcast.go#L129

Added line #L129 was not covered by tests
}

return &ctypes.ResultBroadcastTxCommit{
Expand Down
4 changes: 2 additions & 2 deletions tm2/pkg/crypto/keys/client/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@
// Parse send amount.
send, err := std.ParseCoins(cfg.send)
if err != nil {
return errors.Wrap(err, "parsing send coins")
return fmt.Errorf("unable to parse send coins: %w", err)

Check warning on line 108 in tm2/pkg/crypto/keys/client/call.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/call.go#L108

Added line #L108 was not covered by tests
}

// parse gas wanted & fee.
gaswanted := cfg.rootCfg.gasWanted
gasfee, err := std.ParseCoin(cfg.rootCfg.gasFee)
if err != nil {
return errors.Wrap(err, "parsing gas fee coin")
return fmt.Errorf("unable to parse gas fee coin: %w", err)

Check warning on line 115 in tm2/pkg/crypto/keys/client/call.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/call.go#L115

Added line #L115 was not covered by tests
}

// construct msg & tx and marshal.
Expand Down
2 changes: 1 addition & 1 deletion tm2/pkg/crypto/keys/client/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
return err
}
if len(inputEntropy) < 43 {
return fmt.Errorf("256-bits is 43 characters in Base-64, and 100 in Base-6. You entered %v, and probably want more", len(inputEntropy))
return fmt.Errorf("256-bits is 43 characters in Base-64, and 100 in Base-6. You entered %d, and probably want more", len(inputEntropy))

Check warning on line 64 in tm2/pkg/crypto/keys/client/generate.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/generate.go#L64

Added line #L64 was not covered by tests
}
conf, err := io.GetConfirmation(
fmt.Sprintf("Input length: %d", len(inputEntropy)),
Expand Down
6 changes: 3 additions & 3 deletions tm2/pkg/crypto/keys/client/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import (
"context"
"flag"
"fmt"

"github.com/gnolang/gno/tm2/pkg/bft/rpc/client"
ctypes "github.com/gnolang/gno/tm2/pkg/bft/rpc/core/types"
Expand Down Expand Up @@ -75,8 +76,7 @@
}

if qres.Response.Error != nil {
io.Printf("Log: %s\n",
qres.Response.Log)
io.ErrPrintfln("response log: %s", qres.Response.Log)

Check warning on line 79 in tm2/pkg/crypto/keys/client/query.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/query.go#L79

Added line #L79 was not covered by tests
return qres.Response.Error
}

Expand Down Expand Up @@ -105,7 +105,7 @@
qres, err := cli.ABCIQueryWithOptions(
cfg.path, data, opts2)
if err != nil {
return nil, errors.Wrap(err, "querying")
return nil, fmt.Errorf("unable to query: %w", err)

Check warning on line 108 in tm2/pkg/crypto/keys/client/query.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/query.go#L108

Added line #L108 was not covered by tests
}

return qres, nil
Expand Down
4 changes: 2 additions & 2 deletions tm2/pkg/crypto/keys/client/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@
// Parse send amount.
send, err := std.ParseCoins(cfg.send)
if err != nil {
return errors.Wrap(err, "parsing send coins")
return fmt.Errorf("unable to parse send coin: %w", err)

Check warning on line 98 in tm2/pkg/crypto/keys/client/send.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/send.go#L98

Added line #L98 was not covered by tests
}

// parse gas wanted & fee.
gaswanted := cfg.rootCfg.gasWanted
gasfee, err := std.ParseCoin(cfg.rootCfg.gasFee)
if err != nil {
return errors.Wrap(err, "parsing gas fee coin")
return fmt.Errorf("unable to parse gas fee coin: %w", err)

Check warning on line 105 in tm2/pkg/crypto/keys/client/send.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/send.go#L105

Added line #L105 was not covered by tests
}

// construct msg & tx and marshal.
Expand Down
Loading