Skip to content

Commit

Permalink
#303 Upgrade Cosmos-SDK to v0.47.3
Browse files Browse the repository at this point in the history
- Fix unit tests
- Modify BroadcastTx of grpc integration tests due to cosmos-sdk API changes

Signed-off-by: Abdulbois <[email protected]>
Signed-off-by: Abdulbois <[email protected]>
  • Loading branch information
Abdulbois committed Jan 30, 2024
1 parent e9279cc commit 72d80ab
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
18 changes: 13 additions & 5 deletions integration_tests/utils/grpc_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bufio"
"context"
"errors"
"fmt"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -135,7 +136,7 @@ func (suite *TestSuite) BuildTx(

//nolint:nosnakecase
func (suite *TestSuite) BroadcastTx(txBytes []byte) (*sdk.TxResponse, error) {
var broadcastResp *tx.BroadcastTxResponse
var txResponse *tx.GetTxResponse
var err error

body := tx.BroadcastTxRequest{
Expand All @@ -144,7 +145,7 @@ func (suite *TestSuite) BroadcastTx(txBytes []byte) (*sdk.TxResponse, error) {
}

if suite.Rest {
var _resp tx.BroadcastTxResponse
var _resp tx.GetTxResponse

bodyBytes, err := suite.EncodingConfig.Codec.MarshalJSON(&body)
require.NoError(suite.T, err)
Expand All @@ -153,22 +154,29 @@ func (suite *TestSuite) BroadcastTx(txBytes []byte) (*sdk.TxResponse, error) {
if err != nil {
return nil, err
}

respBytes, err = SendGetRequest(fmt.Sprintf("/cosmos/tx/v1beta1/txs/%s", _resp.GetTxResponse().TxHash))
require.NoError(suite.T, suite.EncodingConfig.Codec.UnmarshalJSON(respBytes, &_resp))
broadcastResp = &_resp
txResponse = &_resp
} else {
grpcConn := suite.GetGRPCConn()
defer grpcConn.Close()

// Broadcast the tx via gRPC. We create a new client for the Protobuf Tx
// service.
txClient := tx.NewServiceClient(grpcConn)
broadcastResp, err = txClient.BroadcastTx(context.Background(), &body)
broadCastResponse, err := txClient.BroadcastTx(context.Background(), &body)
if err != nil {
return nil, err
}

txResponse, err = txClient.GetTx(context.Background(), &tx.GetTxRequest{Hash: broadCastResponse.GetTxResponse().TxHash})
if err != nil {
return nil, err
}
}

resp := broadcastResp.TxResponse
resp := txResponse.TxResponse
if resp.Code != 0 {
err = sdkerrors.ABCIError(resp.Codespace, resp.Code, resp.RawLog)

Expand Down
30 changes: 24 additions & 6 deletions x/model/client/cli/tx_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"testing"

"github.com/cosmos/cosmos-sdk/client/flags"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/stretchr/testify/require"

testconstants "github.com/zigbee-alliance/distributed-compliance-ledger/integration_tests/constants"
testcli "github.com/zigbee-alliance/distributed-compliance-ledger/testutil/cli"
"github.com/zigbee-alliance/distributed-compliance-ledger/testutil/network"
Expand Down Expand Up @@ -65,9 +67,14 @@ func TestCreateModel(t *testing.T) {
}
args = append(args, fields...)
args = append(args, common...)
_, err := testcli.ExecTestCLITxCmd(t, ctx, cli.CmdCreateModel(), args)
txResp, err := testcli.ExecTestCLITxCmd(t, ctx, cli.CmdCreateModel(), args)
require.NoError(t, err)
err = net.WaitForNextBlock()
require.NoError(t, err)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
resp, err := authtx.QueryTx(ctx, txResp.TxHash)
require.NoError(t, err)
require.Contains(t, resp.RawLog, tc.err.Error())
} else {
require.NoError(t, err)
}
Expand Down Expand Up @@ -107,6 +114,8 @@ func TestUpdateModel(t *testing.T) {
args = append(args, common...)
_, err := testcli.ExecTestCLITxCmd(t, ctx, cli.CmdCreateModel(), args)
require.NoError(t, err)
err = net.WaitForNextBlock()
require.NoError(t, err)

fields := []string{
fmt.Sprintf("--%s=%v", cli.FlagProductName, testconstants.ProductName) + "-updated",
Expand Down Expand Up @@ -150,9 +159,12 @@ func TestUpdateModel(t *testing.T) {
}
args = append(args, fields...)
args = append(args, common...)
_, err := testcli.ExecTestCLITxCmd(t, ctx, cli.CmdUpdateModel(), args)
txResp, err := testcli.ExecTestCLITxCmd(t, ctx, cli.CmdUpdateModel(), args)
err = net.WaitForNextBlock()
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
resp, err := authtx.QueryTx(ctx, txResp.TxHash)
require.NoError(t, err)
require.Contains(t, resp.RawLog, tc.err.Error())
} else {
require.NoError(t, err)
}
Expand Down Expand Up @@ -193,6 +205,8 @@ func TestDeleteModel(t *testing.T) {
args = append(args, common...)
_, err := testcli.ExecTestCLITxCmd(t, ctx, cli.CmdCreateModel(), args)
require.NoError(t, err)
err = net.WaitForNextBlock()
require.NoError(t, err)

for _, tc := range []struct {
desc string
Expand Down Expand Up @@ -221,9 +235,13 @@ func TestDeleteModel(t *testing.T) {
fmt.Sprintf("--%s=%v", cli.FlagPid, tc.idPid),
}
args = append(args, common...)
_, err := testcli.ExecTestCLITxCmd(t, ctx, cli.CmdDeleteModel(), args)
txResp, err := testcli.ExecTestCLITxCmd(t, ctx, cli.CmdDeleteModel(), args)
waitErr := net.WaitForNextBlock()
require.NoError(t, waitErr)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
resp, err := authtx.QueryTx(ctx, txResp.TxHash)
require.NoError(t, err)
require.Contains(t, resp.RawLog, tc.err.Error())
} else {
require.NoError(t, err)
}
Expand Down

0 comments on commit 72d80ab

Please sign in to comment.