Skip to content

Commit

Permalink
[BP: main <- #1087] fix(main)!: check transactions succeed after th…
Browse files Browse the repository at this point in the history
…ey're included in a block (#1095)

* Fix v7: check transactions succeed after they're included in a block (#1087)

(cherry picked from commit a3d5c18)

# Conflicts:
#	examples/cosmos/chain_miscellaneous_test.go

* merge conflicts (incoming)

---------

Co-authored-by: violet <[email protected]>
Co-authored-by: Reece Williams <[email protected]>
Co-authored-by: Reece Williams <[email protected]>
  • Loading branch information
4 people authored Apr 25, 2024
1 parent 3428d39 commit 1a0471e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
13 changes: 13 additions & 0 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,19 @@ func (tn *ChainNode) ExecTx(ctx context.Context, keyName string, command ...stri
if err := testutil.WaitForBlocks(ctx, 2, tn); err != nil {
return "", err
}
// The transaction can at first appear to succeed, but then fail when it's actually included in a block.
stdout, _, err = tn.ExecQuery(ctx, "tx", output.TxHash)
if err != nil {
return "", err
}
output = CosmosTx{}
err = json.Unmarshal([]byte(stdout), &output)
if err != nil {
return "", err
}
if output.Code != 0 {
return output.TxHash, fmt.Errorf("transaction failed with code %d: %s", output.Code, output.RawLog)
}
return output.TxHash, nil
}

Expand Down
21 changes: 20 additions & 1 deletion examples/cosmos/chain_miscellaneous_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ func TestICTestMiscellaneous(t *testing.T) {
testHasCommand(ctx, t, chain)
testTokenFactory(ctx, t, chain, users)
testFailedCWExecute(ctx, t, chain, users)
testAddingNode(ctx, t, chain) // not supported with CometMock
testAddingNode(ctx, t, chain)
testGetGovernanceAddress(ctx, t, chain)
testTXFailsOnBlockInclusion(ctx, t, chain, users)
}

func wasmEncoding() *testutil.TestEncodingConfig {
Expand Down Expand Up @@ -413,6 +415,23 @@ func testTokenFactory(ctx context.Context, t *testing.T, chain *cosmos.CosmosCha

}

func testGetGovernanceAddress(ctx context.Context, t *testing.T, chain *cosmos.CosmosChain) {
govAddr, err := chain.GetGovernanceAddress(ctx)
require.NoError(t, err)
_, err = chain.AccAddressFromBech32(govAddr)
require.NoError(t, err)
}

func testTXFailsOnBlockInclusion(ctx context.Context, t *testing.T, chain *cosmos.CosmosChain, users []ibc.Wallet) {
// this isn't a real validator, but is well formed, so it will only fail once a validator checks the staking transaction
fakeValoper, err := chain.GetNode().KeyBech32(ctx, users[0].KeyName(), "val")
require.NoError(t, err)

_, err = chain.GetNode().ExecTx(ctx, users[0].FormattedAddress(),
"staking", "delegate", fakeValoper, "100"+chain.Config().Denom)
require.Error(t, err)
}

// helpers
func sendTokens(ctx context.Context, chain *cosmos.CosmosChain, from, to ibc.Wallet, token string, amount int64) (ibc.WalletAmount, error) {
if token == "" {
Expand Down

0 comments on commit 1a0471e

Please sign in to comment.