Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Sep 2, 2022
1 parent cfcb9c1 commit 76ee504
Show file tree
Hide file tree
Showing 17 changed files with 289 additions and 109 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#12596](https://github.com/cosmos/cosmos-sdk/pull/12596) Remove all imports of the non-existent gogo/protobuf v1.3.3 to ease downstream use and go workspaces.
* [#12187](https://github.com/cosmos/cosmos-sdk/pull/12187) Add batch operation for x/nft module.
* [#12693](https://github.com/cosmos/cosmos-sdk/pull/12693) Make sure the order of each node is consistent when emitting proto events.
* [#12455](https://github.com/cosmos/cosmos-sdk/pull/12455) Show attempts count in error for signing.
* [#12886](https://github.com/cosmos/cosmos-sdk/pull/12886) Amortize cost of processing cache KV store
* [#12455](https://github.com/cosmos/cosmos-sdk/pull/12455) Show attempts count in error for signing.
* [#12885](https://github.com/cosmos/cosmos-sdk/pull/12885) Amortize cost of processing cache KV store
* [#12953](https://github.com/cosmos/cosmos-sdk/pull/12953) Change the default priority mechanism to be based on gas price.
* [#13048](https://github.com/cosmos/cosmos-sdk/pull/13048) Add handling of AccountNumberStoreKeyPrefix to the x/auth simulation decoder.
* [#13101](https://github.com/cosmos/cosmos-sdk/pull/13101) Remove weights from `simapp/params` and `testutil/sims`. They are now in their respective modules.
Expand Down
20 changes: 18 additions & 2 deletions tests/e2e/crisis/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ package crisis
import (
"fmt"

tmcli "github.com/tendermint/tendermint/libs/cli"

"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/suite"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"github.com/cosmos/cosmos-sdk/x/crisis/client/cli"
)

Expand Down Expand Up @@ -73,7 +77,7 @@ func (s *IntegrationTestSuite) TestNewMsgVerifyInvariantTxCmd() {
true, 0, nil,
},
{
"valid transaction",
"valid traclientCtx.Codec.UnmarshalJSON(out.Bytes(), nsaction",
[]string{
"bank", "total-supply",
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
Expand All @@ -100,8 +104,20 @@ func (s *IntegrationTestSuite) TestNewMsgVerifyInvariantTxCmd() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code)
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
}
})
}
}

func (s *IntegrationTestSuite) checkTxCode(clientCtx client.Context, txHash string, expectedCode uint32) {
s.Require().NoError(s.network.WaitForNextBlock())

cmd := authcli.QueryTxCmd()
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{txHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)})
s.Require().NoError(err)

var response sdk.TxResponse
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().Equal(expectedCode, response.Code, out.String())
}
22 changes: 18 additions & 4 deletions tests/e2e/slashing/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import (
"github.com/stretchr/testify/suite"
tmcli "github.com/tendermint/tendermint/libs/cli"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"github.com/cosmos/cosmos-sdk/x/slashing/client/cli"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
)

type EndToEndTestSuite struct {
Expand All @@ -35,8 +38,7 @@ func (s *EndToEndTestSuite) SetupSuite() {
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
s.Require().NoError(err)

_, err = s.network.WaitForHeight(1)
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())
}

// TearDownSuite performs cleanup logic after all the tests, i.e. once after the
Expand Down Expand Up @@ -159,7 +161,7 @@ func (s *EndToEndTestSuite) TestNewUnjailTxCmd() {
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), // sync mode as there are no funds yet
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
},
false, 0, &sdk.TxResponse{},
false, slashingtypes.ErrValidatorNotJailed.ABCICode(), &sdk.TxResponse{},
},
}

Expand All @@ -178,8 +180,20 @@ func (s *EndToEndTestSuite) TestNewUnjailTxCmd() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
}
})
}
}

func (s *EndToEndTestSuite) checkTxCode(clientCtx client.Context, txHash string, expectedCode uint32) {
s.Require().NoError(s.network.WaitForNextBlock())

cmd := authcli.QueryTxCmd()
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{txHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)})
s.Require().NoError(err)

var response sdk.TxResponse
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().Equal(expectedCode, response.Code, out.String())
}
57 changes: 41 additions & 16 deletions tests/e2e/staking/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/tendermint/tendermint/proto/tendermint/crypto"
"github.com/tendermint/tendermint/rpc/client/http"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
Expand All @@ -23,6 +24,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query"
authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"github.com/cosmos/cosmos-sdk/x/staking/client/cli"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)
Expand All @@ -48,9 +50,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
var err error
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
s.Require().NoError(err)

_, err = s.network.WaitForHeight(1)
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())

unbond, err := sdk.ParseCoinNormalized("10stake")
s.Require().NoError(err)
Expand All @@ -71,24 +71,24 @@ func (s *IntegrationTestSuite) SetupSuite() {
var txRes sdk.TxResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes))
s.Require().Equal(uint32(0), txRes.Code)
_, err = s.network.WaitForHeight(1)
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())

unbondingAmount := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(5))

// unbonding the amount
out, err = MsgUnbondExec(val.ClientCtx, val.Address, val.ValAddress, unbondingAmount)
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes))
s.Require().Equal(uint32(0), txRes.Code)
s.Require().NoError(s.network.WaitForNextBlock())

// unbonding the amount
out, err = MsgUnbondExec(val.ClientCtx, val.Address, val.ValAddress, unbondingAmount)
s.Require().NoError(err)
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes))
s.Require().Equal(uint32(0), txRes.Code)

err = s.network.WaitForNextBlock()
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())
}

func (s *IntegrationTestSuite) TearDownSuite() {
Expand Down Expand Up @@ -121,6 +121,7 @@ func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() {
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
)
require.NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())

testCases := []struct {
name string
Expand Down Expand Up @@ -223,19 +224,27 @@ func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() {
require.NoError(err, "test: %s\noutput: %s", tc.name, out.String())
err = clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType)
require.NoError(err, out.String(), "test: %s, output\n:", tc.name, out.String())
s.Require().NoError(s.network.WaitForNextBlock())

txResp := tc.respType.(*sdk.TxResponse)
require.Equal(tc.expectedCode, txResp.Code,
"test: %s, output\n:", tc.name, out.String())
cmd := authcli.QueryTxCmd()
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{txResp.TxHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)})
s.Require().NoError(err)
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), txResp), out.String())
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())

var hadEvent bool
events := txResp.Logs[0].GetEvents()
for i := 0; i < len(events); i++ {
if events[i].GetType() == "create_validator" {
attributes := events[i].GetAttributes()
require.Equal(attributes[1].Value, "100stake")
hadEvent = true
break
}
}

s.Require().True(hadEvent)
}
})
}
Expand Down Expand Up @@ -1065,7 +1074,7 @@ func (s *IntegrationTestSuite) TestNewEditValidatorCmd() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
}
})
}
Expand All @@ -1091,6 +1100,7 @@ func (s *IntegrationTestSuite) TestNewDelegateCmd() {
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
)
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())

testCases := []struct {
name string
Expand Down Expand Up @@ -1150,7 +1160,7 @@ func (s *IntegrationTestSuite) TestNewDelegateCmd() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
}
})
}
Expand Down Expand Up @@ -1236,7 +1246,7 @@ func (s *IntegrationTestSuite) TestNewRedelegateCmd() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
}
})
}
Expand Down Expand Up @@ -1303,7 +1313,7 @@ func (s *IntegrationTestSuite) TestNewUnbondCmd() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
}
})
}
Expand Down Expand Up @@ -1422,7 +1432,7 @@ func (s *IntegrationTestSuite) TestNewCancelUnbondingDelegationCmd() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
}
})
}
Expand Down Expand Up @@ -1452,6 +1462,7 @@ func (s *IntegrationTestSuite) TestBlockResults() {
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
)
require.NoError(err)
require.NoError(s.network.WaitForNextBlock())

// Use CLI to create a delegation from the new account to validator `val`.
delHeight, err := s.network.LatestHeight()
Expand All @@ -1466,6 +1477,7 @@ func (s *IntegrationTestSuite) TestBlockResults() {
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
})
require.NoError(err)
require.NoError(s.network.WaitForNextBlock())

// Create a HTTP rpc client.
rpcClient, err := http.New(val.RPCAddress, "/websocket")
Expand Down Expand Up @@ -1517,6 +1529,7 @@ func (s *IntegrationTestSuite) TestEditValidatorMoniker() {
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
})
require.NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())

queryCmd := cli.GetCmdQueryValidator()
res, err := clitestutil.ExecTestCLICmd(
Expand All @@ -1537,13 +1550,25 @@ func (s *IntegrationTestSuite) TestEditValidatorMoniker() {
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
})
require.NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())

res, err = clitestutil.ExecTestCLICmd(
val.ClientCtx, queryCmd,
[]string{val.ValAddress.String(), fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
)
require.NoError(err)

require.NoError(val.ClientCtx.Codec.UnmarshalJSON(res.Bytes(), &result))
require.Equal(result.GetMoniker(), moniker)
}

func (s *IntegrationTestSuite) checkTxCode(clientCtx client.Context, txHash string, expectedCode uint32) {
s.Require().NoError(s.network.WaitForNextBlock())

cmd := authcli.QueryTxCmd()
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{txHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)})
s.Require().NoError(err)

var response sdk.TxResponse
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().Equal(expectedCode, response.Code, out.String())
}
3 changes: 0 additions & 3 deletions tests/e2e/tx/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ func (s *IntegrationTestSuite) TestQueryBySig() {

s.Require().NoError(s.network.WaitForNextBlock())

// wait for tx to be included
s.network.WaitForNextBlock()

// get the signature out of the builder
sigs, err := txb.GetTx().GetSignaturesV2()
s.Require().NoError(err)
Expand Down
3 changes: 2 additions & 1 deletion x/auth/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -1551,8 +1551,9 @@ func (s *IntegrationTestSuite) TestSignWithMultiSignersAminoJSON() {
signedTxFile.Name(),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
)

require.NoError(err)
require.NoError(s.network.WaitForNextBlock())

var txRes sdk.TxResponse
require.NoError(val0.ClientCtx.Codec.UnmarshalJSON(res.Bytes(), &txRes))
require.Equal(uint32(0), txRes.Code, txRes.RawLog)
Expand Down
1 change: 1 addition & 0 deletions x/authz/client/testutil/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func (s *IntegrationTestSuite) TestQueryGrantsGRPC() {
fmt.Sprintf("--%s=%d", cli.FlagExpiration, time.Now().Add(time.Minute*time.Duration(120)).Unix()),
})
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())
},
func(g *authz.QueryGrantsResponse) {
s.Require().Len(g.Grants, 2)
Expand Down
2 changes: 2 additions & 0 deletions x/authz/client/testutil/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizations() {
},
)
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())

testCases := []struct {
name string
Expand Down Expand Up @@ -112,6 +113,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorization() {
},
)
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())

testCases := []struct {
name string
Expand Down
Loading

0 comments on commit 76ee504

Please sign in to comment.