Skip to content

Commit

Permalink
Merge PR #6195: Add codespace to broadcast(sync/async) response
Browse files Browse the repository at this point in the history
  • Loading branch information
whylee259 authored May 12, 2020
1 parent e01a56e commit d488260
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ functionality that requires an online connection.
* (x/staking) [\#6059](https://github.com/cosmos/cosmos-sdk/pull/6059) Updated `HistoricalEntries` parameter default to 100.
* (x/ibc) [\#5948](https://github.com/cosmos/cosmos-sdk/issues/5948) Add `InitGenesis` and `ExportGenesis` functions for `ibc` module.
* (types) [\#6128](https://github.com/cosmos/cosmos-sdk/pull/6137) Add `String()` method to `GasMeter`.
* (types) [\#6195](https://github.com/cosmos/cosmos-sdk/pull/6195) Add codespace to broadcast(sync/async) response.

## [v0.38.3] - 2020-04-09

Expand Down
15 changes: 9 additions & 6 deletions client/context/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,23 @@ func CheckTendermintError(err error, txBytes []byte) *sdk.TxResponse {
switch {
case strings.Contains(errStr, strings.ToLower(mempool.ErrTxInCache.Error())):
return &sdk.TxResponse{
Code: sdkerrors.ErrTxInMempoolCache.ABCICode(),
TxHash: txHash,
Code: sdkerrors.ErrTxInMempoolCache.ABCICode(),
Codespace: sdkerrors.ErrTxInMempoolCache.Codespace(),
TxHash: txHash,
}

case strings.Contains(errStr, "mempool is full"):
return &sdk.TxResponse{
Code: sdkerrors.ErrMempoolIsFull.ABCICode(),
TxHash: txHash,
Code: sdkerrors.ErrMempoolIsFull.ABCICode(),
Codespace: sdkerrors.ErrMempoolIsFull.Codespace(),
TxHash: txHash,
}

case strings.Contains(errStr, "tx too large"):
return &sdk.TxResponse{
Code: sdkerrors.ErrTxTooLarge.ABCICode(),
TxHash: txHash,
Code: sdkerrors.ErrTxTooLarge.ABCICode(),
Codespace: sdkerrors.ErrTxTooLarge.Codespace(),
TxHash: txHash,
}

default:
Expand Down
1 change: 1 addition & 0 deletions client/context/broadcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func TestBroadcastError(t *testing.T) {
resp, returnedErr := ctx.BroadcastTx(txBytes)
require.NoError(t, returnedErr)
require.Equal(t, code, resp.Code)
require.NotEmpty(t, resp.Codespace)
require.Equal(t, txHash, resp.TxHash)
}
}
Expand Down
11 changes: 6 additions & 5 deletions types/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,12 @@ func NewResponseFormatBroadcastTx(res *ctypes.ResultBroadcastTx) TxResponse {
parsedLogs, _ := ParseABCILogs(res.Log)

return TxResponse{
Code: res.Code,
Data: res.Data.String(),
RawLog: res.Log,
Logs: parsedLogs,
TxHash: res.Hash.String(),
Code: res.Code,
Codespace: res.Codespace,
Data: res.Data.String(),
RawLog: res.Log,
Logs: parsedLogs,
TxHash: res.Hash.String(),
}
}

Expand Down
20 changes: 11 additions & 9 deletions types/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,19 @@ func TestResponseResultTx(t *testing.T) {
require.False(t, want.Empty())

resultBroadcastTx := &ctypes.ResultBroadcastTx{
Code: 1,
Data: []byte("data"),
Log: `[]`,
Hash: bytes.HexBytes([]byte("test")),
Code: 1,
Codespace: "codespace",
Data: []byte("data"),
Log: `[]`,
Hash: bytes.HexBytes([]byte("test")),
}
require.Equal(t, sdk.TxResponse{
Code: 1,
Data: "64617461",
RawLog: `[]`,
Logs: logs,
TxHash: "74657374",
Code: 1,
Codespace: "codespace",
Data: "64617461",
RawLog: `[]`,
Logs: logs,
TxHash: "74657374",
}, sdk.NewResponseFormatBroadcastTx(resultBroadcastTx))
require.Equal(t, sdk.TxResponse{}, sdk.NewResponseFormatBroadcastTx(nil))
}
Expand Down

0 comments on commit d488260

Please sign in to comment.