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

[BP: v7 <- #938] fix: Errors in cosmos Broadcaster are sometimes not propagated to caller #963

Merged
merged 2 commits into from
Feb 19, 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
9 changes: 9 additions & 0 deletions chain/cosmos/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ func (b *Broadcaster) UnmarshalTxResponseBytes(ctx context.Context, bytes []byte
if err := b.chain.cfg.EncodingConfig.Codec.UnmarshalJSON(bytes, &resp); err != nil {
return sdk.TxResponse{}, err
}

// persist nested errors such as ValidateBasic checks.
code := resp.Code
rawLog := resp.RawLog

if code != 0 {
return resp, fmt.Errorf("error in transaction (code: %d): raw_log: %s", code, rawLog)
}

return resp, nil
}

Expand Down
13 changes: 13 additions & 0 deletions examples/cosmos/chain_miscellaneous_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,19 @@ func testBroadcaster(ctx context.Context, t *testing.T, chain *cosmos.CosmosChai
updatedBal2, err := chain.GetBalance(ctx, addr2, chain.Config().Denom)
require.NoError(t, err)
require.Equal(t, math.NewInt(2), updatedBal2)

txResp, err = cosmos.BroadcastTx(
ctx,
b,
users[0],
banktypes.NewMsgMultiSend([]banktypes.Input{
{
Address: addr1,
Coins: c1.Add(c2[0]),
},
}, out),
)
require.Error(t, err)
}

func testQueryCmd(ctx context.Context, t *testing.T, chain *cosmos.CosmosChain) {
Expand Down
Loading
Loading