From 8ef62a93a8cc3be3f56a3455d47fc4d587d3c05a Mon Sep 17 00:00:00 2001 From: violet Date: Wed, 10 Apr 2024 17:01:19 -0400 Subject: [PATCH] Fix v7: check transactions succeed after they're included in a block --- chain/cosmos/chain_node.go | 13 +++++++++++++ examples/cosmos/chain_miscellaneous_test.go | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/chain/cosmos/chain_node.go b/chain/cosmos/chain_node.go index 750717d19..8d04c339a 100644 --- a/chain/cosmos/chain_node.go +++ b/chain/cosmos/chain_node.go @@ -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 } diff --git a/examples/cosmos/chain_miscellaneous_test.go b/examples/cosmos/chain_miscellaneous_test.go index 99c47f085..065f72ce4 100644 --- a/examples/cosmos/chain_miscellaneous_test.go +++ b/examples/cosmos/chain_miscellaneous_test.go @@ -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 { @@ -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 == "" {