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(v7)!: check transactions succeed after they're included in a block #1087

Merged
merged 1 commit into from
Apr 24, 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
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
Loading