Skip to content

Commit

Permalink
Fix v7: check transactions succeed after they're included in a block (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fastfadingviolets authored Apr 24, 2024
1 parent 07af56f commit a3d5c18
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,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
11 changes: 11 additions & 0 deletions examples/cosmos/chain_miscellaneous_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func CosmosChainTestMiscellaneous(t *testing.T, name, version string) {
testFailedCWExecute(ctx, t, chain, users)
testAddingNode(ctx, t, chain)
testGetGovernanceAddress(ctx, t, chain)
testTXFailsOnBlockInclusion(ctx, t, chain, users)
}

func wasmEncoding() *testutil.TestEncodingConfig {
Expand Down Expand Up @@ -429,6 +430,16 @@ func testGetGovernanceAddress(ctx context.Context, t *testing.T, chain *cosmos.C
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 a3d5c18

Please sign in to comment.