From a28b9e7160cc44568a82534f4b0558c1d88d167c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nina=20/=20=E1=83=9C=E1=83=98=E1=83=9C=E1=83=90?= Date: Fri, 16 Aug 2024 14:15:37 +0200 Subject: [PATCH] refactor: signer to use txstatus (#3767) ## Overview Fixes #3366 Opens - https://github.com/celestiaorg/celestia-core/issues/1453 and https://github.com/celestiaorg/celestia-core/issues/1454 --- app/test/big_blob_test.go | 3 +- app/test/prepare_proposal_context_test.go | 8 ++- app/test/square_size_test.go | 8 ++- app/test/std_sdk_test.go | 8 ++- pkg/user/tx_client.go | 85 +++++++++++++++-------- pkg/user/tx_client_test.go | 59 +++++++++++----- test/txsim/account.go | 2 +- x/blobstream/integration_test.go | 8 ++- x/signal/legacy_test.go | 19 +++-- 9 files changed, 143 insertions(+), 57 deletions(-) diff --git a/app/test/big_blob_test.go b/app/test/big_blob_test.go index 41934c6379..ad219c2e3d 100644 --- a/app/test/big_blob_test.go +++ b/app/test/big_blob_test.go @@ -83,7 +83,8 @@ func (s *BigBlobSuite) TestErrBlobsTooLarge() { res, err := txClient.SubmitPayForBlob(subCtx, []*share.Blob{tc.blob}, user.SetGasLimitAndGasPrice(1e9, appconsts.DefaultMinGasPrice)) require.Error(t, err) require.NotNil(t, res) - require.Equal(t, tc.want, res.Code, res.Logs) + // FIXME: assert RawLog once TxStatus supports it. + require.Equal(t, tc.want, res.Code) }) } } diff --git a/app/test/prepare_proposal_context_test.go b/app/test/prepare_proposal_context_test.go index dbec6798b3..7eb14bf9a8 100644 --- a/app/test/prepare_proposal_context_test.go +++ b/app/test/prepare_proposal_context_test.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" + sdktx "github.com/cosmos/cosmos-sdk/types/tx" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/stretchr/testify/assert" @@ -80,8 +81,13 @@ func TestTimeInPrepareProposalContext(t *testing.T) { msgs, _ := tt.msgFunc() res, err := txClient.SubmitTx(cctx.GoContext(), msgs, user.SetGasLimit(1000000), user.SetFee(2000)) require.NoError(t, err) + // FIXME: Temporary way of querying the raw log. + // TxStatus will natively support this in the future. + serviceClient := sdktx.NewServiceClient(cctx.GRPCClient) + getTxResp, err := serviceClient.GetTx(cctx.GoContext(), &sdktx.GetTxRequest{Hash: res.TxHash}) + require.NoError(t, err) require.NotNil(t, res) - assert.Equal(t, abci.CodeTypeOK, res.Code, res.RawLog) + assert.Equal(t, abci.CodeTypeOK, res.Code, getTxResp.TxResponse.RawLog) }) } } diff --git a/app/test/square_size_test.go b/app/test/square_size_test.go index e8082b17f5..653f4b4ae4 100644 --- a/app/test/square_size_test.go +++ b/app/test/square_size_test.go @@ -17,6 +17,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/testnode" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" sdk "github.com/cosmos/cosmos-sdk/types" + sdktx "github.com/cosmos/cosmos-sdk/types/tx" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" oldgov "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/params/types/proposal" @@ -173,7 +174,12 @@ func (s *SquareSizeIntegrationTest) setBlockSizeParams(t *testing.T, squareSize, res, err := txClient.SubmitTx(s.cctx.GoContext(), []sdk.Msg{msg}, blobfactory.DefaultTxOpts()...) require.NoError(t, err) - require.Equal(t, res.Code, abci.CodeTypeOK, res.RawLog) + // FIXME: Temporary way of querying the raw log. + // TxStatus will natively support this in the future. + serviceClient := sdktx.NewServiceClient(s.cctx.GRPCClient) + getTxResp, err := serviceClient.GetTx(s.cctx.GoContext(), &sdktx.GetTxRequest{Hash: res.TxHash}) + require.NoError(t, err) + require.Equal(t, res.Code, abci.CodeTypeOK, getTxResp.TxResponse.RawLog) require.NoError(t, s.cctx.WaitForNextBlock()) diff --git a/app/test/std_sdk_test.go b/app/test/std_sdk_test.go index 1ef3766e8a..ca4b401768 100644 --- a/app/test/std_sdk_test.go +++ b/app/test/std_sdk_test.go @@ -21,6 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil/mock" sdk "github.com/cosmos/cosmos-sdk/types" + sdktx "github.com/cosmos/cosmos-sdk/types/tx" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" @@ -325,8 +326,13 @@ func (s *StandardSDKIntegrationTestSuite) TestStandardSDK() { } else { require.NoError(t, err) } + // FIXME: Temporary way of querying the raw log. + // TxStatus will natively support this in the future. + serviceClient := sdktx.NewServiceClient(s.cctx.GRPCClient) + getTxResp, err := serviceClient.GetTx(s.cctx.GoContext(), &sdktx.GetTxRequest{Hash: res.TxHash}) + require.NoError(t, err) require.NotNil(t, res) - assert.Equal(t, tt.expectedCode, res.Code, res.RawLog) + assert.Equal(t, tt.expectedCode, res.Code, getTxResp.TxResponse.RawLog) }) } } diff --git a/pkg/user/tx_client.go b/pkg/user/tx_client.go index 0d14128421..75863f1293 100644 --- a/pkg/user/tx_client.go +++ b/pkg/user/tx_client.go @@ -27,6 +27,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/app" "github.com/celestiaorg/celestia-app/v3/app/encoding" apperrors "github.com/celestiaorg/celestia-app/v3/app/errors" + "github.com/celestiaorg/celestia-app/v3/app/grpc/tx" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/x/blob/types" "github.com/celestiaorg/celestia-app/v3/x/minfee" @@ -39,6 +40,14 @@ const ( type Option func(client *TxClient) +// TxResponse is a response from the chain after +// a transaction has been submitted. +type TxResponse struct { + Height int64 + TxHash string + Code uint32 +} + // WithGasMultiplier is a functional option allows to configure the gas multiplier. func WithGasMultiplier(multiplier float64) Option { return func(c *TxClient) { @@ -200,19 +209,25 @@ func SetupTxClient( // SubmitPayForBlob forms a transaction from the provided blobs, signs it, and submits it to the chain. // TxOptions may be provided to set the fee and gas limit. -func (client *TxClient) SubmitPayForBlob(ctx context.Context, blobs []*share.Blob, opts ...TxOption) (*sdktypes.TxResponse, error) { +func (client *TxClient) SubmitPayForBlob(ctx context.Context, blobs []*share.Blob, opts ...TxOption) (*TxResponse, error) { resp, err := client.BroadcastPayForBlob(ctx, blobs, opts...) - if err != nil { - return resp, err + if err != nil && resp != nil { + return &TxResponse{Code: resp.Code, TxHash: resp.TxHash}, fmt.Errorf("failed to broadcast pay for blob: %v", err) + } else if err != nil { + return &TxResponse{}, fmt.Errorf("failed to broadcast pay for blob: %v", err) } return client.ConfirmTx(ctx, resp.TxHash) } -func (client *TxClient) SubmitPayForBlobWithAccount(ctx context.Context, account string, blobs []*share.Blob, opts ...TxOption) (*sdktypes.TxResponse, error) { +// SubmitPayForBlobWithAccount forms a transaction from the provided blobs, signs it with the provided account, and submits it to the chain. +// TxOptions may be provided to set the fee and gas limit. +func (client *TxClient) SubmitPayForBlobWithAccount(ctx context.Context, account string, blobs []*share.Blob, opts ...TxOption) (*TxResponse, error) { resp, err := client.BroadcastPayForBlobWithAccount(ctx, account, blobs, opts...) - if err != nil { - return resp, err + if err != nil && resp != nil { + return &TxResponse{Code: resp.Code, TxHash: resp.TxHash}, fmt.Errorf("failed to broadcast pay for blob with account: %v", err) + } else if err != nil { + return &TxResponse{}, fmt.Errorf("failed to broadcast pay for blob with account: %v", err) } return client.ConfirmTx(ctx, resp.TxHash) @@ -253,10 +268,12 @@ func (client *TxClient) BroadcastPayForBlobWithAccount(ctx context.Context, acco // SubmitTx forms a transaction from the provided messages, signs it, and submits it to the chain. TxOptions // may be provided to set the fee and gas limit. -func (client *TxClient) SubmitTx(ctx context.Context, msgs []sdktypes.Msg, opts ...TxOption) (*sdktypes.TxResponse, error) { +func (client *TxClient) SubmitTx(ctx context.Context, msgs []sdktypes.Msg, opts ...TxOption) (*TxResponse, error) { resp, err := client.BroadcastTx(ctx, msgs, opts...) - if err != nil { - return resp, err + if err != nil && resp != nil { + return &TxResponse{Code: resp.Code, TxHash: resp.TxHash}, fmt.Errorf("failed to broadcast tx: %v", err) + } else if err != nil { + return &TxResponse{}, fmt.Errorf("failed to broadcast tx: %v", err) } return client.ConfirmTx(ctx, resp.TxHash) @@ -414,32 +431,44 @@ func (client *TxClient) retryBroadcastingTx(ctx context.Context, txBytes []byte) // ConfirmTx periodically pings the provided node for the commitment of a transaction by its // hash. It will continually loop until the context is cancelled, the tx is found or an error // is encountered. -func (client *TxClient) ConfirmTx(ctx context.Context, txHash string) (*sdktypes.TxResponse, error) { - txClient := sdktx.NewServiceClient(client.grpc) +func (client *TxClient) ConfirmTx(ctx context.Context, txHash string) (*TxResponse, error) { + txClient := tx.NewTxClient(client.grpc) pollTicker := time.NewTicker(client.pollTime) defer pollTicker.Stop() for { - resp, err := txClient.GetTx(ctx, &sdktx.GetTxRequest{Hash: txHash}) - if err == nil { - if resp.TxResponse.Code != 0 { - return resp.TxResponse, fmt.Errorf("tx was included but failed with code %d: %s", resp.TxResponse.Code, resp.TxResponse.RawLog) - } - return resp.TxResponse, nil - } - // FIXME: this is a relatively brittle of working out whether to retry or not. The tx might be not found for other - // reasons. It may have been removed from the mempool at a later point. We should build an endpoint that gives the - // signer more information on the status of their transaction and then update the logic here - if !strings.Contains(err.Error(), "not found") { - return &sdktypes.TxResponse{}, err + resp, err := txClient.TxStatus(ctx, &tx.TxStatusRequest{TxId: txHash}) + if err != nil { + return &TxResponse{}, err } - // Wait for the next round. - select { - case <-ctx.Done(): - return &sdktypes.TxResponse{}, ctx.Err() - case <-pollTicker.C: + if err == nil && resp != nil { + switch resp.Status { + // FIXME: replace hardcoded status with constants + case "PENDING": + // Continue polling if the transaction is still pending + select { + case <-ctx.Done(): + return &TxResponse{}, ctx.Err() + case <-pollTicker.C: + continue + } + case "COMMITTED": + txResponse := &TxResponse{ + Height: resp.Height, + TxHash: txHash, + Code: resp.ExecutionCode, + } + if resp.ExecutionCode != 0 { + return txResponse, fmt.Errorf("tx was included but failed with code %d: %s", resp.ExecutionCode, resp.Status) + } + return txResponse, nil + case "EVICTED": + return &TxResponse{}, fmt.Errorf("tx: %s was evicted from the mempool", txHash) + default: + return &TxResponse{}, fmt.Errorf("unknown tx: %s", txHash) + } } } } diff --git a/pkg/user/tx_client_test.go b/pkg/user/tx_client_test.go index 0c4821b2c4..1dcfc16822 100644 --- a/pkg/user/tx_client_test.go +++ b/pkg/user/tx_client_test.go @@ -6,6 +6,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" + sdktx "github.com/cosmos/cosmos-sdk/types/tx" bank "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" @@ -30,9 +31,10 @@ func TestTxClientTestSuite(t *testing.T) { type TxClientTestSuite struct { suite.Suite - ctx testnode.Context - encCfg encoding.Config - txClient *user.TxClient + ctx testnode.Context + encCfg encoding.Config + txClient *user.TxClient + serviceClient sdktx.ServiceClient } func (suite *TxClientTestSuite) SetupSuite() { @@ -45,6 +47,9 @@ func (suite *TxClientTestSuite) SetupSuite() { suite.Require().NoError(err) suite.txClient, err = user.SetupTxClient(suite.ctx.GoContext(), suite.ctx.Keyring, suite.ctx.GRPCClient, suite.encCfg, user.WithGasMultiplier(1.2)) suite.Require().NoError(err) + // FIXME: Temporary way of querying the raw log. + // TxStatus will natively support this in the future. + suite.serviceClient = sdktx.NewServiceClient(suite.ctx.GRPCClient) } func (suite *TxClientTestSuite) TestSubmitPayForBlob() { @@ -57,8 +62,10 @@ func (suite *TxClientTestSuite) TestSubmitPayForBlob() { t.Run("submit blob without provided fee and gas limit", func(t *testing.T) { resp, err := suite.txClient.SubmitPayForBlob(subCtx, blobs) require.NoError(t, err) + getTxResp, err := suite.serviceClient.GetTx(subCtx, &sdktx.GetTxRequest{Hash: resp.TxHash}) + require.NoError(t, err) require.EqualValues(t, 0, resp.Code) - require.Greater(t, resp.GasWanted, int64(0)) + require.Greater(t, getTxResp.TxResponse.GasWanted, int64(0)) }) t.Run("submit blob with provided fee and gas limit", func(t *testing.T) { @@ -66,15 +73,19 @@ func (suite *TxClientTestSuite) TestSubmitPayForBlob() { gas := user.SetGasLimit(1e6) resp, err := suite.txClient.SubmitPayForBlob(subCtx, blobs, fee, gas) require.NoError(t, err) + getTxResp, err := suite.serviceClient.GetTx(subCtx, &sdktx.GetTxRequest{Hash: resp.TxHash}) + require.NoError(t, err) require.EqualValues(t, 0, resp.Code) - require.EqualValues(t, resp.GasWanted, 1e6) + require.EqualValues(t, getTxResp.TxResponse.GasWanted, 1e6) }) t.Run("submit blob with different account", func(t *testing.T) { resp, err := suite.txClient.SubmitPayForBlobWithAccount(subCtx, "c", blobs, user.SetFee(1e6), user.SetGasLimit(1e6)) require.NoError(t, err) + getTxResp, err := suite.serviceClient.GetTx(subCtx, &sdktx.GetTxRequest{Hash: resp.TxHash}) + require.NoError(t, err) require.EqualValues(t, 0, resp.Code) - require.EqualValues(t, resp.GasWanted, 1e6) + require.EqualValues(t, getTxResp.TxResponse.GasWanted, 1e6) }) t.Run("try submit a blob with an account that doesn't exist", func(t *testing.T) { @@ -96,14 +107,18 @@ func (suite *TxClientTestSuite) TestSubmitTx() { resp, err := suite.txClient.SubmitTx(suite.ctx.GoContext(), []sdk.Msg{msg}) require.NoError(t, err) require.Equal(t, abci.CodeTypeOK, resp.Code) - require.Greater(t, resp.GasWanted, int64(0)) + getTxResp, err := suite.serviceClient.GetTx(suite.ctx.GoContext(), &sdktx.GetTxRequest{Hash: resp.TxHash}) + require.NoError(t, err) + require.Greater(t, getTxResp.TxResponse.GasWanted, int64(0)) }) t.Run("submit tx with provided gas limit", func(t *testing.T) { resp, err := suite.txClient.SubmitTx(suite.ctx.GoContext(), []sdk.Msg{msg}, gasLimitOption) require.NoError(t, err) require.Equal(t, abci.CodeTypeOK, resp.Code) - require.EqualValues(t, gasLimit, resp.GasWanted) + getTxResp, err := suite.serviceClient.GetTx(suite.ctx.GoContext(), &sdktx.GetTxRequest{Hash: resp.TxHash}) + require.NoError(t, err) + require.EqualValues(t, int64(gasLimit), getTxResp.TxResponse.GasWanted) }) t.Run("submit tx with provided fee", func(t *testing.T) { @@ -116,7 +131,9 @@ func (suite *TxClientTestSuite) TestSubmitTx() { resp, err := suite.txClient.SubmitTx(suite.ctx.GoContext(), []sdk.Msg{msg}, feeOption, gasLimitOption) require.NoError(t, err) require.Equal(t, abci.CodeTypeOK, resp.Code) - require.EqualValues(t, gasLimit, resp.GasWanted) + getTxResp, err := suite.serviceClient.GetTx(suite.ctx.GoContext(), &sdktx.GetTxRequest{Hash: resp.TxHash}) + require.NoError(t, err) + require.EqualValues(t, int64(gasLimit), getTxResp.TxResponse.GasWanted) }) t.Run("submit tx with a different account", func(t *testing.T) { @@ -145,7 +162,12 @@ func (suite *TxClientTestSuite) TestConfirmTx() { t.Run("deadline exceeded when the context times out", func(t *testing.T) { ctx, cancel := context.WithTimeout(suite.ctx.GoContext(), time.Second) defer cancel() - _, err := suite.txClient.ConfirmTx(ctx, "E32BD15CAF57AF15D17B0D63CF4E63A9835DD1CEBB059C335C79586BC3013728") + + msg := bank.NewMsgSend(suite.txClient.DefaultAddress(), testnode.RandomAddress().(sdk.AccAddress), sdk.NewCoins(sdk.NewInt64Coin(app.BondDenom, 10))) + resp, err := suite.txClient.BroadcastTx(ctx, []sdk.Msg{msg}) + require.NoError(t, err) + + _, err = suite.txClient.ConfirmTx(ctx, resp.TxHash) require.Error(t, err) require.Contains(t, err.Error(), context.DeadlineExceeded.Error()) }) @@ -153,8 +175,8 @@ func (suite *TxClientTestSuite) TestConfirmTx() { t.Run("should error when tx is not found", func(t *testing.T) { ctx, cancel := context.WithTimeout(suite.ctx.GoContext(), 5*time.Second) defer cancel() - _, err := suite.txClient.ConfirmTx(ctx, "not found tx") - require.Error(t, err) + _, err := suite.txClient.ConfirmTx(ctx, "E32BD15CAF57AF15D17B0D63CF4E63A9835DD1CEBB059C335C79586BC3013728") + require.Contains(t, err.Error(), "unknown tx: E32BD15CAF57AF15D17B0D63CF4E63A9835DD1CEBB059C335C79586BC3013728") }) t.Run("should success when tx is found immediately", func(t *testing.T) { @@ -165,9 +187,9 @@ func (suite *TxClientTestSuite) TestConfirmTx() { require.NotNil(t, resp) ctx, cancel := context.WithTimeout(suite.ctx.GoContext(), 30*time.Second) defer cancel() - resp, err = suite.txClient.ConfirmTx(ctx, resp.TxHash) + confirmTxResp, err := suite.txClient.ConfirmTx(ctx, resp.TxHash) require.NoError(t, err) - require.Equal(t, abci.CodeTypeOK, resp.Code) + require.Equal(t, abci.CodeTypeOK, confirmTxResp.Code) }) t.Run("should error when tx is found with a non-zero error code", func(t *testing.T) { @@ -178,9 +200,9 @@ func (suite *TxClientTestSuite) TestConfirmTx() { resp, err := suite.txClient.BroadcastTx(suite.ctx.GoContext(), []sdk.Msg{msg}, fee, gas) require.NoError(t, err) require.NotNil(t, resp) - resp, err = suite.txClient.ConfirmTx(suite.ctx.GoContext(), resp.TxHash) + confirmTxResp, err := suite.txClient.ConfirmTx(suite.ctx.GoContext(), resp.TxHash) require.Error(t, err) - require.NotEqual(t, abci.CodeTypeOK, resp.Code) + require.NotEqual(t, abci.CodeTypeOK, confirmTxResp.Code) }) } @@ -221,8 +243,11 @@ func (suite *TxClientTestSuite) TestGasConsumption() { amountDeducted := balanceBefore - balanceAfter - utiaToSend require.Equal(t, int64(fee), amountDeducted) + res, err := suite.serviceClient.GetTx(suite.ctx.GoContext(), &sdktx.GetTxRequest{Hash: resp.TxHash}) + require.NoError(t, err) + // verify that the amount deducted does not depend on the actual gas used. - gasUsedBasedDeduction := resp.GasUsed * gasPrice + gasUsedBasedDeduction := res.TxResponse.GasUsed * gasPrice require.NotEqual(t, gasUsedBasedDeduction, amountDeducted) // The gas used based deduction should be less than the fee because the fee is 1 TIA. require.Less(t, gasUsedBasedDeduction, int64(fee)) diff --git a/test/txsim/account.go b/test/txsim/account.go index e01264c68d..9796f60b04 100644 --- a/test/txsim/account.go +++ b/test/txsim/account.go @@ -240,7 +240,7 @@ func (am *AccountManager) Submit(ctx context.Context, op Operation) error { } var ( - res *types.TxResponse + res *user.TxResponse err error ) if len(op.Blobs) > 0 { diff --git a/x/blobstream/integration_test.go b/x/blobstream/integration_test.go index 08a96ecd56..9aaa91709d 100644 --- a/x/blobstream/integration_test.go +++ b/x/blobstream/integration_test.go @@ -11,6 +11,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/testnode" blobstreamtypes "github.com/celestiaorg/celestia-app/v3/x/blobstream/types" sdk "github.com/cosmos/cosmos-sdk/types" + sdktx "github.com/cosmos/cosmos-sdk/types/tx" staking "github.com/cosmos/cosmos-sdk/x/staking/types" gethcommon "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" @@ -89,8 +90,13 @@ func (s *BlobstreamIntegrationSuite) TestBlobstream() { } else { require.Error(t, err) } + // FIXME: Temporary way of querying the raw log. + // TxStatus will natively support this in the future. + serviceClient := sdktx.NewServiceClient(s.cctx.GRPCClient) + getTxResp, err := serviceClient.GetTx(s.cctx.GoContext(), &sdktx.GetTxRequest{Hash: res.TxHash}) + require.NoError(t, err) require.NotNil(t, res) - require.Equal(t, tt.expectedTxCode, res.Code, res.RawLog) + require.Equal(t, tt.expectedTxCode, res.Code, getTxResp.TxResponse.RawLog) }) } } diff --git a/x/signal/legacy_test.go b/x/signal/legacy_test.go index 3c202cd50f..2516c66dc8 100644 --- a/x/signal/legacy_test.go +++ b/x/signal/legacy_test.go @@ -14,6 +14,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/testnode" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" + sdktx "github.com/cosmos/cosmos-sdk/types/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" v1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" @@ -54,6 +55,7 @@ type LegacyUpgradeTestSuite struct { mut sync.Mutex accountCounter int + serviceClient sdktx.ServiceClient } // SetupSuite inits a standard chain, with the only exception being a @@ -91,6 +93,9 @@ func (s *LegacyUpgradeTestSuite) SetupSuite() { // Set the gov module address s.govModuleAddress = acc.GetAddress().String() + // FIXME: Temporary way of querying the raw log. + // TxStatus will natively support this in the future. + s.serviceClient = sdktx.NewServiceClient(s.cctx.GRPCClient) } func (s *LegacyUpgradeTestSuite) unusedAccount() string { @@ -127,7 +132,7 @@ func (s *LegacyUpgradeTestSuite) TestLegacyGovUpgradeFailure() { res, err := signer.SubmitTx(subCtx, []sdk.Msg{msg}, blobfactory.DefaultTxOpts()...) require.Error(t, err) // As the type is not registered, the message will fail with unable to resolve type URL - require.EqualValues(t, 2, res.Code, res.RawLog) + require.EqualValues(t, 2, res.Code) } // TestNewGovUpgradeFailure verifies that a transaction with a @@ -156,7 +161,7 @@ func (s *LegacyUpgradeTestSuite) TestNewGovUpgradeFailure() { res, err := signer.SubmitTx(subCtx, []sdk.Msg{msg}, blobfactory.DefaultTxOpts()...) require.Error(t, err) // As the type is not registered, the message will fail with unable to resolve type URL - require.EqualValues(t, 2, res.Code, res.RawLog) + require.EqualValues(t, 2, res.Code) } func (s *LegacyUpgradeTestSuite) TestIBCUpgradeFailure() { @@ -178,14 +183,16 @@ func (s *LegacyUpgradeTestSuite) TestIBCUpgradeFailure() { require.NoError(t, err) // submit the transaction and wait a block for it to be included - signer, err := testnode.NewTxClientFromContext(s.cctx) + txClient, err := testnode.NewTxClientFromContext(s.cctx) require.NoError(t, err) subCtx, cancel := context.WithTimeout(s.cctx.GoContext(), time.Minute) defer cancel() - res, err := signer.SubmitTx(subCtx, []sdk.Msg{msg}, blobfactory.DefaultTxOpts()...) + res, err := txClient.SubmitTx(subCtx, []sdk.Msg{msg}, blobfactory.DefaultTxOpts()...) require.Error(t, err) - require.EqualValues(t, 9, res.Code, res.RawLog) // we're only submitting the tx, so we expect everything to work - assert.Contains(t, res.RawLog, "ibc upgrade proposal not supported") + getTxResp, err := s.serviceClient.GetTx(subCtx, &sdktx.GetTxRequest{Hash: res.TxHash}) + require.NoError(t, err) + require.EqualValues(t, 9, res.Code, getTxResp.TxResponse.RawLog) // we're only submitting the tx, so we expect everything to work + assert.Contains(t, getTxResp.TxResponse.RawLog, "ibc upgrade proposal not supported") } func getAddress(account string, kr keyring.Keyring) sdk.AccAddress {