From bed4ba3ac83413c63c002fcd1d5e72f6199c4bc1 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 29 Sep 2022 23:33:28 +0800 Subject: [PATCH 1/6] fix: add close for grpcOnly mode (#13418) --- CHANGELOG.md | 1 + server/start.go | 18 +++++++----------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8b5ca65b4d4..7de6291c85d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -174,6 +174,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (Store) [#13334](https://github.com/cosmos/cosmos-sdk/pull/13334) Call streaming listeners for deliver tx event, it was removed accidentally. * (grpc) [#13352](https://github.com/cosmos/cosmos-sdk/pull/13352) fix grpc query panic that could crash the node. * (snapshot) [#13400](https://github.com/cosmos/cosmos-sdk/pull/13400) Fix snapshot checksum issue in golang 1.19. +* (grpc) [#13418](https://github.com/cosmos/cosmos-sdk/pull/13418) Add close for grpc only mode. ### Deprecated diff --git a/server/start.go b/server/start.go index beb51729b686..1cee1089d130 100644 --- a/server/start.go +++ b/server/start.go @@ -417,13 +417,18 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App if err != nil { return err } - + defer grpcSrv.Stop() if config.GRPCWeb.Enable { grpcWebSrv, err = servergrpc.StartGRPCWeb(grpcSrv, config) if err != nil { ctx.Logger.Error("failed to start grpc-web http server: ", err) return err } + defer func() { + if err := grpcWebSrv.Close(); err != nil { + ctx.Logger.Error("failed to close grpc-web http server: ", err) + } + }() } } @@ -486,7 +491,7 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App } defer func() { - if tmNode.IsRunning() { + if tmNode != nil && tmNode.IsRunning() { _ = tmNode.Stop() } @@ -498,15 +503,6 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App _ = apiSrv.Close() } - if grpcSrv != nil { - grpcSrv.Stop() - if grpcWebSrv != nil { - if err := grpcWebSrv.Close(); err != nil { - ctx.Logger.Error("failed to close grpc-web http server: ", err) - } - } - } - ctx.Logger.Info("exiting...") }() From e5dca073188f9a39347ec38854dbd5e2a685a89f Mon Sep 17 00:00:00 2001 From: Ricardo M <82225676+Larfie@users.noreply.github.com> Date: Fri, 30 Sep 2022 10:33:46 +0100 Subject: [PATCH 2/6] docs: fix spelling mistakes (#13421) --- .../base/store/v1beta1/commit_info.pulsar.go | 2 +- .../base/tendermint/v1beta1/query.pulsar.go | 2 +- .../distribution/v1beta1/genesis.pulsar.go | 4 ++-- .../distribution/v1beta1/query.pulsar.go | 4 ++-- api/cosmos/gov/v1beta1/genesis.pulsar.go | 6 +++--- api/cosmos/group/v1/types.pulsar.go | 18 +++++++++--------- api/tendermint/crypto/proof.pulsar.go | 2 +- .../base/store/v1beta1/commit_info.proto | 2 +- .../cosmos/base/tendermint/v1beta1/query.proto | 2 +- .../cosmos/distribution/v1beta1/genesis.proto | 4 ++-- proto/cosmos/distribution/v1beta1/query.proto | 6 +++--- proto/cosmos/gov/v1beta1/genesis.proto | 6 +++--- proto/cosmos/group/v1/types.proto | 2 +- proto/tendermint/crypto/proof.proto | 2 +- 14 files changed, 31 insertions(+), 31 deletions(-) diff --git a/api/cosmos/base/store/v1beta1/commit_info.pulsar.go b/api/cosmos/base/store/v1beta1/commit_info.pulsar.go index 02bfa7426cba..4e259d858705 100644 --- a/api/cosmos/base/store/v1beta1/commit_info.pulsar.go +++ b/api/cosmos/base/store/v1beta1/commit_info.pulsar.go @@ -1627,7 +1627,7 @@ func (x *StoreInfo) GetCommitId() *CommitID { return nil } -// CommitID defines the committment information when a specific store is +// CommitID defines the commitment information when a specific store is // committed. type CommitID struct { state protoimpl.MessageState diff --git a/api/cosmos/base/tendermint/v1beta1/query.pulsar.go b/api/cosmos/base/tendermint/v1beta1/query.pulsar.go index 9d037fff7d1c..e81922e1118c 100644 --- a/api/cosmos/base/tendermint/v1beta1/query.pulsar.go +++ b/api/cosmos/base/tendermint/v1beta1/query.pulsar.go @@ -11261,7 +11261,7 @@ func (x *ABCIQueryResponse) GetCodespace() string { } // ProofOp defines an operation used for calculating Merkle root. The data could -// be arbitrary format, providing nessecary data for example neighbouring node +// be arbitrary format, providing necessary data for example neighbouring node // hash. // // Note: This type is a duplicate of the ProofOp proto type defined in Tendermint. diff --git a/api/cosmos/distribution/v1beta1/genesis.pulsar.go b/api/cosmos/distribution/v1beta1/genesis.pulsar.go index b8a416f62970..63a1b31088b9 100644 --- a/api/cosmos/distribution/v1beta1/genesis.pulsar.go +++ b/api/cosmos/distribution/v1beta1/genesis.pulsar.go @@ -5373,7 +5373,7 @@ type ValidatorOutstandingRewardsRecord struct { // validator_address is the address of the validator. ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` - // outstanding_rewards represents the oustanding rewards of a validator. + // outstanding_rewards represents the outstanding rewards of a validator. OutstandingRewards []*v1beta1.DecCoin `protobuf:"bytes,2,rep,name=outstanding_rewards,json=outstandingRewards,proto3" json:"outstanding_rewards,omitempty"` } @@ -5623,7 +5623,7 @@ type ValidatorSlashEventRecord struct { // validator_address is the address of the validator. ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` - // height defines the block height at which the slash event occured. + // height defines the block height at which the slash event occurred. Height uint64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"` // period is the period of the slash event. Period uint64 `protobuf:"varint,3,opt,name=period,proto3" json:"period,omitempty"` diff --git a/api/cosmos/distribution/v1beta1/query.pulsar.go b/api/cosmos/distribution/v1beta1/query.pulsar.go index 531bf3194fe5..40a22c3566d4 100644 --- a/api/cosmos/distribution/v1beta1/query.pulsar.go +++ b/api/cosmos/distribution/v1beta1/query.pulsar.go @@ -9546,7 +9546,7 @@ type QueryValidatorDistributionInfoResponse struct { OperatorAddress string `protobuf:"bytes,1,opt,name=operator_address,json=operatorAddress,proto3" json:"operator_address,omitempty"` // self_bond_rewards defines the self delegations rewards. SelfBondRewards []*v1beta1.DecCoin `protobuf:"bytes,2,rep,name=self_bond_rewards,json=selfBondRewards,proto3" json:"self_bond_rewards,omitempty"` - // commission defines the commision the validator received. + // commission defines the commission the validator received. Commission []*v1beta1.DecCoin `protobuf:"bytes,3,rep,name=commission,proto3" json:"commission,omitempty"` } @@ -9711,7 +9711,7 @@ type QueryValidatorCommissionResponse struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // commission defines the commision the validator received. + // commission defines the commission the validator received. Commission *ValidatorAccumulatedCommission `protobuf:"bytes,1,opt,name=commission,proto3" json:"commission,omitempty"` } diff --git a/api/cosmos/gov/v1beta1/genesis.pulsar.go b/api/cosmos/gov/v1beta1/genesis.pulsar.go index c34920f18ae2..f12d7cb9e3fe 100644 --- a/api/cosmos/gov/v1beta1/genesis.pulsar.go +++ b/api/cosmos/gov/v1beta1/genesis.pulsar.go @@ -1095,11 +1095,11 @@ type GenesisState struct { Votes []*Vote `protobuf:"bytes,3,rep,name=votes,proto3" json:"votes,omitempty"` // proposals defines all the proposals present at genesis. Proposals []*Proposal `protobuf:"bytes,4,rep,name=proposals,proto3" json:"proposals,omitempty"` - // params defines all the paramaters of related to deposit. + // params defines all the parameters of related to deposit. DepositParams *DepositParams `protobuf:"bytes,5,opt,name=deposit_params,json=depositParams,proto3" json:"deposit_params,omitempty"` - // params defines all the paramaters of related to voting. + // params defines all the parameters of related to voting. VotingParams *VotingParams `protobuf:"bytes,6,opt,name=voting_params,json=votingParams,proto3" json:"voting_params,omitempty"` - // params defines all the paramaters of related to tally. + // params defines all the parameters of related to tally. TallyParams *TallyParams `protobuf:"bytes,7,opt,name=tally_params,json=tallyParams,proto3" json:"tally_params,omitempty"` } diff --git a/api/cosmos/group/v1/types.pulsar.go b/api/cosmos/group/v1/types.pulsar.go index ac3083c3a891..a33c437d9c4e 100644 --- a/api/cosmos/group/v1/types.pulsar.go +++ b/api/cosmos/group/v1/types.pulsar.go @@ -7533,10 +7533,10 @@ func (x *MemberRequest) GetMetadata() string { // ThresholdDecisionPolicy is a decision policy where a proposal passes when it // satisfies the two following conditions: -// 1. The sum of all `YES` voters' weights is greater or equal than the defined -// `threshold`. -// 2. The voting and execution periods of the proposal respect the parameters -// given by `windows`. +// 1. The sum of all `YES` voters' weights is greater or equal than the defined +// `threshold`. +// 2. The voting and execution periods of the proposal respect the parameters +// given by `windows`. type ThresholdDecisionPolicy struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -7585,10 +7585,10 @@ func (x *ThresholdDecisionPolicy) GetWindows() *DecisionPolicyWindows { // PercentageDecisionPolicy is a decision policy where a proposal passes when // it satisfies the two following conditions: -// 1. The percentage of all `YES` voters' weights out of the total group weight -// is greater or equal than the given `percentage`. -// 2. The voting and execution periods of the proposal respect the parameters -// given by `windows`. +// 1. The percentage of all `YES` voters' weights out of the total group weight +// is greater or equal than the given `percentage`. +// 2. The voting and execution periods of the proposal respect the parameters +// given by `windows`. type PercentageDecisionPolicy struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -7950,7 +7950,7 @@ type Proposal struct { // whichever happens first. FinalTallyResult *TallyResult `protobuf:"bytes,9,opt,name=final_tally_result,json=finalTallyResult,proto3" json:"final_tally_result,omitempty"` // voting_period_end is the timestamp before which voting must be done. - // Unless a successfull MsgExec is called before (to execute a proposal whose + // Unless a successful MsgExec is called before (to execute a proposal whose // tally is successful before the voting period ends), tallying will be done // at this point, and the `final_tally_result`and `status` fields will be // accordingly updated. diff --git a/api/tendermint/crypto/proof.pulsar.go b/api/tendermint/crypto/proof.pulsar.go index a3128844e44e..dfaf424608db 100644 --- a/api/tendermint/crypto/proof.pulsar.go +++ b/api/tendermint/crypto/proof.pulsar.go @@ -2919,7 +2919,7 @@ func (x *DominoOp) GetOutput() string { } // ProofOp defines an operation used for calculating Merkle root -// The data could be arbitrary format, providing nessecary data +// The data could be arbitrary format, providing necessary data // for example neighbouring node hash type ProofOp struct { state protoimpl.MessageState diff --git a/proto/cosmos/base/store/v1beta1/commit_info.proto b/proto/cosmos/base/store/v1beta1/commit_info.proto index 98a33d30e754..b7b6a1972fa3 100644 --- a/proto/cosmos/base/store/v1beta1/commit_info.proto +++ b/proto/cosmos/base/store/v1beta1/commit_info.proto @@ -19,7 +19,7 @@ message StoreInfo { CommitID commit_id = 2 [(gogoproto.nullable) = false]; } -// CommitID defines the committment information when a specific store is +// CommitID defines the commitment information when a specific store is // committed. message CommitID { option (gogoproto.goproto_stringer) = false; diff --git a/proto/cosmos/base/tendermint/v1beta1/query.proto b/proto/cosmos/base/tendermint/v1beta1/query.proto index 3c0733ae6e46..4d513cc39123 100644 --- a/proto/cosmos/base/tendermint/v1beta1/query.proto +++ b/proto/cosmos/base/tendermint/v1beta1/query.proto @@ -189,7 +189,7 @@ message ABCIQueryResponse { } // ProofOp defines an operation used for calculating Merkle root. The data could -// be arbitrary format, providing nessecary data for example neighbouring node +// be arbitrary format, providing necessary data for example neighbouring node // hash. // // Note: This type is a duplicate of the ProofOp proto type defined in Tendermint. diff --git a/proto/cosmos/distribution/v1beta1/genesis.proto b/proto/cosmos/distribution/v1beta1/genesis.proto index 239ba42f61b0..8a6cd68397ad 100644 --- a/proto/cosmos/distribution/v1beta1/genesis.proto +++ b/proto/cosmos/distribution/v1beta1/genesis.proto @@ -31,7 +31,7 @@ message ValidatorOutstandingRewardsRecord { // validator_address is the address of the validator. string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; - // outstanding_rewards represents the oustanding rewards of a validator. + // outstanding_rewards represents the outstanding rewards of a validator. repeated cosmos.base.v1beta1.DecCoin outstanding_rewards = 2 [(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false]; } @@ -99,7 +99,7 @@ message ValidatorSlashEventRecord { // validator_address is the address of the validator. string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; - // height defines the block height at which the slash event occured. + // height defines the block height at which the slash event occurred. uint64 height = 2; // period is the period of the slash event. uint64 period = 3; diff --git a/proto/cosmos/distribution/v1beta1/query.proto b/proto/cosmos/distribution/v1beta1/query.proto index bb10d59b1a87..8ee6f1a697ea 100644 --- a/proto/cosmos/distribution/v1beta1/query.proto +++ b/proto/cosmos/distribution/v1beta1/query.proto @@ -17,7 +17,7 @@ service Query { option (google.api.http).get = "/cosmos/distribution/v1beta1/params"; } - // ValidatorDistributionInfo queries validator commision and self-delegation rewards for validator + // ValidatorDistributionInfo queries validator commission and self-delegation rewards for validator rpc ValidatorDistributionInfo(QueryValidatorDistributionInfoRequest) returns (QueryValidatorDistributionInfoResponse) { option (google.api.http).get = "/cosmos/distribution/v1beta1/validators/{validator_address}"; @@ -93,7 +93,7 @@ message QueryValidatorDistributionInfoResponse { // self_bond_rewards defines the self delegations rewards. repeated cosmos.base.v1beta1.DecCoin self_bond_rewards = 2 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins"]; - // commission defines the commision the validator received. + // commission defines the commission the validator received. repeated cosmos.base.v1beta1.DecCoin commission = 3 [ (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false @@ -123,7 +123,7 @@ message QueryValidatorCommissionRequest { // QueryValidatorCommissionResponse is the response type for the // Query/ValidatorCommission RPC method message QueryValidatorCommissionResponse { - // commission defines the commision the validator received. + // commission defines the commission the validator received. ValidatorAccumulatedCommission commission = 1 [(gogoproto.nullable) = false]; } diff --git a/proto/cosmos/gov/v1beta1/genesis.proto b/proto/cosmos/gov/v1beta1/genesis.proto index be9b07e46726..28cdacb36998 100644 --- a/proto/cosmos/gov/v1beta1/genesis.proto +++ b/proto/cosmos/gov/v1beta1/genesis.proto @@ -17,10 +17,10 @@ message GenesisState { repeated Vote votes = 3 [(gogoproto.castrepeated) = "Votes", (gogoproto.nullable) = false]; // proposals defines all the proposals present at genesis. repeated Proposal proposals = 4 [(gogoproto.castrepeated) = "Proposals", (gogoproto.nullable) = false]; - // params defines all the paramaters of related to deposit. + // params defines all the parameters of related to deposit. DepositParams deposit_params = 5 [(gogoproto.nullable) = false]; - // params defines all the paramaters of related to voting. + // params defines all the parameters of related to voting. VotingParams voting_params = 6 [(gogoproto.nullable) = false]; - // params defines all the paramaters of related to tally. + // params defines all the parameters of related to tally. TallyParams tally_params = 7 [(gogoproto.nullable) = false]; } diff --git a/proto/cosmos/group/v1/types.proto b/proto/cosmos/group/v1/types.proto index 837271542c63..43170be86a11 100644 --- a/proto/cosmos/group/v1/types.proto +++ b/proto/cosmos/group/v1/types.proto @@ -223,7 +223,7 @@ message Proposal { TallyResult final_tally_result = 9 [(gogoproto.nullable) = false]; // voting_period_end is the timestamp before which voting must be done. - // Unless a successfull MsgExec is called before (to execute a proposal whose + // Unless a successful MsgExec is called before (to execute a proposal whose // tally is successful before the voting period ends), tallying will be done // at this point, and the `final_tally_result`and `status` fields will be // accordingly updated. diff --git a/proto/tendermint/crypto/proof.proto b/proto/tendermint/crypto/proof.proto index 975df7685397..7293ae63ee58 100644 --- a/proto/tendermint/crypto/proof.proto +++ b/proto/tendermint/crypto/proof.proto @@ -27,7 +27,7 @@ message DominoOp { } // ProofOp defines an operation used for calculating Merkle root -// The data could be arbitrary format, providing nessecary data +// The data could be arbitrary format, providing necessary data // for example neighbouring node hash message ProofOp { string type = 1; From eb32125f8e7371d93c5ca2637492c28b3fda52b5 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Fri, 30 Sep 2022 06:30:15 -0400 Subject: [PATCH 3/6] chore: improve ABCI 1.0 godocs (#13425) --- baseapp/abci.go | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 39e8bf81c5e4..4f52136fac10 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -232,15 +232,41 @@ func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBloc return res } -// PrepareProposal implements the ability for the application to verify and/or modify transactions in a block proposal. +// PrepareProposal implements the PrepareProposal ABCI method and returns a +// ResponsePrepareProposal object to the client. The PrepareProposal method is +// responsible for allowing the block proposer to perform application-dependent +// work in a block before proposing it. +// +// Transactions can be modified, removed, or added by the application. Since the +// application maintains it's own local mempool, it will ignore the transactions +// provided to it in RequestPrepareProposal. Instead, it will determine which +// transactions to return based on the mempool's semantics and the MaxTxBytes +// provided by the client's request. +// +// Note, there is no need to execute the transactions for validity as they have +// already passed CheckTx. +// +// Ref: https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-060-abci-1.0.md +// Ref: https://github.com/tendermint/tendermint/blob/main/spec/abci/abci%2B%2B_basic_concepts.md func (app *BaseApp) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePrepareProposal { - // treated as a noop until app side mempool is implemented + // TODO: Implement. return abci.ResponsePrepareProposal{Txs: req.Txs} } -// ProcessProposal implements the ability for the application to verify transactions in a block proposal, and decide if they should accept the block or not. +// ProcessProposal implements the ProcessProposal ABCI method and returns a +// ResponseProcessProposal object to the client. The ProcessProposal method is +// responsible for allowing execution of application-dependent work in a proposed +// block. Note, the application defines the exact implementation details of +// ProcessProposal. In general, the application must at the very least ensure +// that all transactions are valid. If all transactions are valid, then we inform +// Tendermint that the Status is ACCEPT. However, the application is also able +// to implement optimizations such as executing the entire proposed block +// immediately. It may even execute the block in parallel. +// +// Ref: https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-060-abci-1.0.md +// Ref: https://github.com/tendermint/tendermint/blob/main/spec/abci/abci%2B%2B_basic_concepts.md func (app *BaseApp) ProcessProposal(req abci.RequestProcessProposal) abci.ResponseProcessProposal { - // accept all proposed blocks until app side mempool is implemented + // TODO: Implement. return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT} } From 87e0017776344cfff17daee9d58f489cec59d96e Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 30 Sep 2022 18:24:07 +0100 Subject: [PATCH 4/6] Update UPGRADING.md (#13428) --- UPGRADING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UPGRADING.md b/UPGRADING.md index dcb9ca887f76..159d3c4136c2 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -101,6 +101,8 @@ Additionally, new packages have been introduced in order to further split the co * `errors` should replace `types/errors` when registering errors or wrapping SDK errors. * `math` contains the `Int` or `Uint` types that are used in the SDK. +* `x/nft` an NFT base module. +* `x/group` a group module allowing to create DAOs, multisig and policies. Greatly composes with `x/authz`. #### `x/authz` From c221d7f1de96ab3b74a8f64dcdd7566dc90ebf66 Mon Sep 17 00:00:00 2001 From: Marko Date: Sun, 2 Oct 2022 15:03:03 +0200 Subject: [PATCH 5/6] chore: minor cleanup of types (#13430) --- CHANGELOG.md | 1 + docs/basics/query-lifecycle.md | 2 - docs/building-modules/module-manager.md | 3 - docs/building-modules/query-services.md | 27 --- testutil/mock/types_router.go | 31 ---- types/errors/abci.go | 26 --- types/kv/list.go | 235 ------------------------ types/module/module.go | 3 - types/queryable.go | 9 - types/router.go | 6 - x/evidence/keeper/keeper_test.go | 3 +- x/feegrant/module/module.go | 5 - 12 files changed, 2 insertions(+), 349 deletions(-) delete mode 100644 types/kv/list.go delete mode 100644 types/queryable.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 7de6291c85d2..3126c32f7043 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -149,6 +149,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/staking) [#12973](https://github.com/cosmos/cosmos-sdk/pull/12973) Removed `stakingkeeper.RandomValidator`. Use `testutil.RandSliceElem(r, sk.GetAllValidators(ctx))` instead. * (x/gov) [13160](https://github.com/cosmos/cosmos-sdk/pull/13160) Remove custom marshaling of proposl and voteoption. * (x/auth) [13411](https://github.com/cosmos/cosmos-sdk/pull/13411) Change account id to use uint64 in `AccountAddressByID` grpc query. +* (types) [13430](https://github.com/cosmos/cosmos-sdk/pull/13430) Remove unused code `ResponseCheckTx` and `ResponseDeliverTx` ### CLI Breaking Changes diff --git a/docs/basics/query-lifecycle.md b/docs/basics/query-lifecycle.md index 5aca3e345374..441bf71f13b4 100644 --- a/docs/basics/query-lifecycle.md +++ b/docs/basics/query-lifecycle.md @@ -115,8 +115,6 @@ Read more about ABCI Clients and Tendermint RPC in the [Tendermint documentation When a query is received by the full-node after it has been relayed from the underlying consensus engine, it is now being handled within an environment that understands application-specific types and has a copy of the state. [`baseapp`](../core/baseapp.md) implements the ABCI [`Query()`](../core/baseapp.md#query) function and handles gRPC queries. The query route is parsed, and it matches the fully-qualified service method name of an existing service method (most likely in one of the modules), then `baseapp` will relay the request to the relevant module. -Apart from gRPC routes, `baseapp` also handles four different types of queries: `app`, `store`, `p2p`, and `custom`. The first three types (`app`, `store`, `p2p`) are purely application-level and thus directly handled by `baseapp` or the stores, but the `custom` query type requires `baseapp` to route the query to a module's [legacy queriers](../building-modules/query-services.md#legacy-queriers). To learn more about these queries, please refer to [this guide](../core/grpc_rest.md#tendermint-rpc). - Since `MyQuery` has a Protobuf fully-qualified service method name from the `staking` module (recall `/cosmos.staking.v1beta1.Query/Delegations`), `baseapp` first parses the path, then uses its own internal `GRPCQueryRouter` to retrieve the corresponding gRPC handler, and routes the query to the module. The gRPC handler is responsible for recognizing this query, retrieving the appropriate values from the application's stores, and returning a response. Read more about query services [here](../building-modules/query-services.md). Once a result is received from the querier, `baseapp` begins the process of returning a response to the user. diff --git a/docs/building-modules/module-manager.md b/docs/building-modules/module-manager.md index 666af7a7930c..f94ba84229a2 100644 --- a/docs/building-modules/module-manager.md +++ b/docs/building-modules/module-manager.md @@ -68,9 +68,6 @@ The `AppModule` interface defines the inter-dependent methods that modules need Let us go through the methods of `AppModule`: * `RegisterInvariants(sdk.InvariantRegistry)`: Registers the [`invariants`](./invariants.md) of the module. If an invariant deviates from its predicted value, the [`InvariantRegistry`](./invariants.md#registry) triggers appropriate logic (most often the chain will be halted). -* `Route()` (deprecated): Returns the route for [`message`s](./messages-and-queries.md#messages) to be routed to the module by [`BaseApp`](../core/baseapp.md#message-routing). -* `QuerierRoute()` (deprecated): Returns the name of the module's query route, for [`queries`](./messages-and-queries.md#queries) to be routes to the module by [`BaseApp`](../core/baseapp.md#query-routing). -* `LegacyQuerierHandler(*codec.LegacyAmino)` (deprecated): Returns a [`querier`](./query-services.md#legacy-queriers) given the query `path`, in order to process the `query`. * `RegisterServices(Configurator)`: Allows a module to register services. * `BeginBlock(sdk.Context, abci.RequestBeginBlock)`: This method gives module developers the option to implement logic that is automatically triggered at the beginning of each block. Implement empty if no logic needs to be triggered at the beginning of each block for this module. * `EndBlock(sdk.Context, abci.RequestEndBlock)`: This method gives module developers the option to implement logic that is automatically triggered at the end of each block. This is also where the module can inform the underlying consensus engine of validator set changes (e.g. the `staking` module). Implement empty if no logic needs to be triggered at the end of each block for this module. diff --git a/docs/building-modules/query-services.md b/docs/building-modules/query-services.md index a0ea91932ca7..7bb9d93c9478 100644 --- a/docs/building-modules/query-services.md +++ b/docs/building-modules/query-services.md @@ -45,33 +45,6 @@ Here's an example implementation for the bank module: +++ https://github.com/cosmos/cosmos-sdk/blob/v0.46.0/x/bank/keeper/grpc_query.go -### Legacy Queriers - -Module legacy `querier`s are typically implemented in a `./keeper/querier.go` file inside the module's folder. The [module manager](./module-manager.md) is used to add the module's `querier`s to the [application's `queryRouter`](../core/baseapp.md#query-routing) via the `NewQuerier()` method. Typically, the manager's `NewQuerier()` method simply calls a `NewQuerier()` method defined in `keeper/querier.go`, which looks like the following: - -```go -func NewQuerier(keeper Keeper) sdk.Querier { - return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { - switch path[0] { - case QueryType1: - return queryType1(ctx, path[1:], req, keeper) - - case QueryType2: - return queryType2(ctx, path[1:], req, keeper) - - default: - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0]) - } - } -} -``` - -This simple switch returns a `querier` function specific to the type of the received `query`. At this point of the [query lifecycle](../basics/query-lifecycle.md), the first element of the `path` (`path[0]`) contains the type of the query. The following elements are either empty or contain arguments needed to process the query. - -The `querier` functions themselves are pretty straightforward. They generally fetch a value or values from the state using the [`keeper`](./keeper.md). Then, they marshall the value(s) using the [`codec`](../core/encoding.md) and return the `[]byte` obtained as result. - -For a deeper look at `querier`s, see this [example implementation of a `querier` function](https://github.com/cosmos/cosmos-sdk/blob/v0.46.0/x/gov/keeper/querier.go) from the bank module. - ## Next {hide} Learn about [`BeginBlocker` and `EndBlocker`](./beginblock-endblock.md) {hide} diff --git a/testutil/mock/types_router.go b/testutil/mock/types_router.go index 74b046c8024c..f64d86161771 100644 --- a/testutil/mock/types_router.go +++ b/testutil/mock/types_router.go @@ -5,9 +5,6 @@ package mock import ( - reflect "reflect" - - types "github.com/cosmos/cosmos-sdk/types" gomock "github.com/golang/mock/gomock" ) @@ -33,31 +30,3 @@ func NewMockQueryRouter(ctrl *gomock.Controller) *MockQueryRouter { func (m *MockQueryRouter) EXPECT() *MockQueryRouterMockRecorder { return m.recorder } - -// AddRoute mocks base method. -func (m *MockQueryRouter) AddRoute(r string, h types.Querier) types.QueryRouter { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "AddRoute", r, h) - ret0, _ := ret[0].(types.QueryRouter) - return ret0 -} - -// AddRoute indicates an expected call of AddRoute. -func (mr *MockQueryRouterMockRecorder) AddRoute(r, h interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddRoute", reflect.TypeOf((*MockQueryRouter)(nil).AddRoute), r, h) -} - -// Route mocks base method. -func (m *MockQueryRouter) Route(path string) types.Querier { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Route", path) - ret0, _ := ret[0].(types.Querier) - return ret0 -} - -// Route indicates an expected call of Route. -func (mr *MockQueryRouterMockRecorder) Route(path interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Route", reflect.TypeOf((*MockQueryRouter)(nil).Route), path) -} diff --git a/types/errors/abci.go b/types/errors/abci.go index 729e3c554085..ccee41aeac39 100644 --- a/types/errors/abci.go +++ b/types/errors/abci.go @@ -4,19 +4,6 @@ import ( abci "github.com/tendermint/tendermint/abci/types" ) -// ResponseCheckTx returns an ABCI ResponseCheckTx object with fields filled in -// from the given error and gas values. -func ResponseCheckTx(err error, gw, gu uint64, debug bool) abci.ResponseCheckTx { - space, code, log := ABCIInfo(err, debug) - return abci.ResponseCheckTx{ - Codespace: space, - Code: code, - Log: log, - GasWanted: int64(gw), - GasUsed: int64(gu), - } -} - // ResponseCheckTxWithEvents returns an ABCI ResponseCheckTx object with fields filled in // from the given error, gas values and events. func ResponseCheckTxWithEvents(err error, gw, gu uint64, events []abci.Event, debug bool) abci.ResponseCheckTx { @@ -31,19 +18,6 @@ func ResponseCheckTxWithEvents(err error, gw, gu uint64, events []abci.Event, de } } -// ResponseDeliverTx returns an ABCI ResponseDeliverTx object with fields filled in -// from the given error and gas values. -func ResponseDeliverTx(err error, gw, gu uint64, debug bool) abci.ResponseDeliverTx { - space, code, log := ABCIInfo(err, debug) - return abci.ResponseDeliverTx{ - Codespace: space, - Code: code, - Log: log, - GasWanted: int64(gw), - GasUsed: int64(gu), - } -} - // ResponseDeliverTxWithEvents returns an ABCI ResponseDeliverTx object with fields filled in // from the given error, gas values and events. func ResponseDeliverTxWithEvents(err error, gw, gu uint64, events []abci.Event, debug bool) abci.ResponseDeliverTx { diff --git a/types/kv/list.go b/types/kv/list.go deleted file mode 100644 index f038ccfa0ec0..000000000000 --- a/types/kv/list.go +++ /dev/null @@ -1,235 +0,0 @@ -package kv - -// This code was copied from pkg.go.dev/container/list, but specially adapted -// for use with kv.Pair to avoid the type assertion CPU expense of using Value with -// an interface, per https://github.com/cosmos/cosmos-sdk/issues/8810 -// -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Element is an element of a linked list. -type Element struct { - // Next and previous pointers in the doubly-linked list of elements. - // To simplify the implementation, internally a list l is implemented - // as a ring, such that &l.root is both the next element of the last - // list element (l.Back()) and the previous element of the first list - // element (l.Front()). - next, prev *Element - - // The list to which this element belongs. - list *List - - // The value stored with this element. - Value *Pair -} - -// Next returns the next list element or nil. -func (e *Element) Next() *Element { - if p := e.next; e.list != nil && p != &e.list.root { - return p - } - return nil -} - -// Prev returns the previous list element or nil. -func (e *Element) Prev() *Element { - if p := e.prev; e.list != nil && p != &e.list.root { - return p - } - return nil -} - -// List represents a doubly linked list. -// The zero value for List is an empty list ready to use. -type List struct { - root Element // sentinel list element, only &root, root.prev, and root.next are used - len int // current list length excluding (this) sentinel element -} - -// Init initializes or clears list l. -func (l *List) Init() *List { - l.root.next = &l.root - l.root.prev = &l.root - l.len = 0 - return l -} - -// NewList returns an initialized list. -func NewList() *List { return new(List).Init() } - -// Len returns the number of elements of list l. -// The complexity is O(1). -func (l *List) Len() int { return l.len } - -// Front returns the first element of list l or nil if the list is empty. -func (l *List) Front() *Element { - if l.len == 0 { - return nil - } - return l.root.next -} - -// Back returns the last element of list l or nil if the list is empty. -func (l *List) Back() *Element { - if l.len == 0 { - return nil - } - return l.root.prev -} - -// lazyInit lazily initializes a zero List value. -func (l *List) lazyInit() { - if l.root.next == nil { - l.Init() - } -} - -// insert inserts e after at, increments l.len, and returns e. -func (l *List) insert(e, at *Element) *Element { - e.prev = at - e.next = at.next - e.prev.next = e - e.next.prev = e - e.list = l - l.len++ - return e -} - -// insertValue is a convenience wrapper for insert(&Element{Value: v}, at). -func (l *List) insertValue(v *Pair, at *Element) *Element { - return l.insert(&Element{Value: v}, at) -} - -// remove removes e from its list, decrements l.len, and returns e. -func (l *List) remove(e *Element) *Element { - e.prev.next = e.next - e.next.prev = e.prev - e.next = nil // avoid memory leaks - e.prev = nil // avoid memory leaks - e.list = nil - l.len-- - return e -} - -// move moves e to next to at and returns e. -func (l *List) move(e, at *Element) *Element { - if e == at { - return e - } - e.prev.next = e.next - e.next.prev = e.prev - - e.prev = at - e.next = at.next - e.prev.next = e - e.next.prev = e - - return e -} - -// Remove removes e from l if e is an element of list l. -// It returns the element value e.Value. -// The element must not be nil. -func (l *List) Remove(e *Element) *Pair { - if e.list == l { - // if e.list == l, l must have been initialized when e was inserted - // in l or l == nil (e is a zero Element) and l.remove will crash - l.remove(e) - } - return e.Value -} - -// PushFront inserts a new element e with value v at the front of list l and returns e. -func (l *List) PushFront(v *Pair) *Element { - l.lazyInit() - return l.insertValue(v, &l.root) -} - -// PushBack inserts a new element e with value v at the back of list l and returns e. -func (l *List) PushBack(v *Pair) *Element { - l.lazyInit() - return l.insertValue(v, l.root.prev) -} - -// InsertBefore inserts a new element e with value v immediately before mark and returns e. -// If mark is not an element of l, the list is not modified. -// The mark must not be nil. -func (l *List) InsertBefore(v *Pair, mark *Element) *Element { - if mark.list != l { - return nil - } - // see comment in List.Remove about initialization of l - return l.insertValue(v, mark.prev) -} - -// InsertAfter inserts a new element e with value v immediately after mark and returns e. -// If mark is not an element of l, the list is not modified. -// The mark must not be nil. -func (l *List) InsertAfter(v *Pair, mark *Element) *Element { - if mark.list != l { - return nil - } - // see comment in List.Remove about initialization of l - return l.insertValue(v, mark) -} - -// MoveToFront moves element e to the front of list l. -// If e is not an element of l, the list is not modified. -// The element must not be nil. -func (l *List) MoveToFront(e *Element) { - if e.list != l || l.root.next == e { - return - } - // see comment in List.Remove about initialization of l - l.move(e, &l.root) -} - -// MoveToBack moves element e to the back of list l. -// If e is not an element of l, the list is not modified. -// The element must not be nil. -func (l *List) MoveToBack(e *Element) { - if e.list != l || l.root.prev == e { - return - } - // see comment in List.Remove about initialization of l - l.move(e, l.root.prev) -} - -// MoveBefore moves element e to its new position before mark. -// If e or mark is not an element of l, or e == mark, the list is not modified. -// The element and mark must not be nil. -func (l *List) MoveBefore(e, mark *Element) { - if e.list != l || e == mark || mark.list != l { - return - } - l.move(e, mark.prev) -} - -// MoveAfter moves element e to its new position after mark. -// If e or mark is not an element of l, or e == mark, the list is not modified. -// The element and mark must not be nil. -func (l *List) MoveAfter(e, mark *Element) { - if e.list != l || e == mark || mark.list != l { - return - } - l.move(e, mark) -} - -// PushBackList inserts a copy of another list at the back of list l. -// The lists l and other may be the same. They must not be nil. -func (l *List) PushBackList(other *List) { - l.lazyInit() - for i, e := other.Len(), other.Front(); i > 0; i, e = i-1, e.Next() { - l.insertValue(e.Value, l.root.prev) - } -} - -// PushFrontList inserts a copy of another list at the front of list l. -// The lists l and other may be the same. They must not be nil. -func (l *List) PushFrontList(other *List) { - l.lazyInit() - for i, e := other.Len(), other.Back(); i > 0; i, e = i-1, e.Prev() { - l.insertValue(e.Value, &l.root) - } -} diff --git a/types/module/module.go b/types/module/module.go index b03bb4c4f7c7..2955fcbbd0cd 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -195,9 +195,6 @@ func (GenesisOnlyAppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} // QuerierRoute returns an empty module querier route func (GenesisOnlyAppModule) QuerierRoute() string { return "" } -// LegacyQuerierHandler returns an empty module querier -func (gam GenesisOnlyAppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier { return nil } - // RegisterServices registers all services. func (gam GenesisOnlyAppModule) RegisterServices(Configurator) {} diff --git a/types/queryable.go b/types/queryable.go deleted file mode 100644 index f89965906af8..000000000000 --- a/types/queryable.go +++ /dev/null @@ -1,9 +0,0 @@ -package types - -import ( - abci "github.com/tendermint/tendermint/abci/types" -) - -// Querier defines a function type that a module querier must implement to handle -// custom client queries. -type Querier = func(ctx Context, path []string, req abci.RequestQuery) ([]byte, error) diff --git a/types/router.go b/types/router.go index b8a1da2ae742..07e81f646dcb 100644 --- a/types/router.go +++ b/types/router.go @@ -25,9 +25,3 @@ var ( // characters only. IsNumeric = regexp.MustCompile(`^[0-9]+$`).MatchString ) - -// QueryRouter provides queryables for each query path. -type QueryRouter interface { - AddRoute(r string, h Querier) QueryRouter - Route(path string) Querier -} diff --git a/x/evidence/keeper/keeper_test.go b/x/evidence/keeper/keeper_test.go index 8f6ea80087fc..4bbc9932fd78 100644 --- a/x/evidence/keeper/keeper_test.go +++ b/x/evidence/keeper/keeper_test.go @@ -72,8 +72,7 @@ func testEquivocationHandler(_ interface{}) types.Handler { type KeeperTestSuite struct { suite.Suite - ctx sdk.Context - querier sdk.Querier + ctx sdk.Context evidenceKeeper keeper.Keeper bankKeeper *evidencetestutil.MockBankKeeper diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 766173e1e9f2..6e1ed2e2fbb7 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -69,11 +69,6 @@ func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { feegrant.RegisterInterfaces(registry) } -// LegacyQuerierHandler returns the feegrant module sdk.Querier. -func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { - return nil -} - // DefaultGenesis returns default genesis state as raw bytes for the feegrant // module. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { From 80ce491734778239098f4b5010ed697239c8b36f Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Sun, 2 Oct 2022 16:42:52 +0200 Subject: [PATCH 6/6] refactor: move `x/{moduleName}/test{ModuleName}` to `x/{moduleName}/testutil` (#13427) * refactor: move `x/{moduleName}/test{ModuleName}` to `x/{moduleName}/testutil` * updates * updates --- CHANGELOG.md | 2 + tests/integration/bank/keeper/keeper_test.go | 3 - .../distribution/keeper/allocation_test.go | 8 +-- .../distribution/keeper/delegation_test.go | 20 +++---- .../distribution/keeper/grpc_query_test.go | 6 +- .../slashing/keeper/keeper_test.go | 24 +++----- .../integration/staking/keeper/common_test.go | 6 +- .../staking/keeper/delegation_test.go | 8 +-- .../integration/staking/keeper/keeper_test.go | 18 ------ .../integration/staking/keeper/params_test.go | 27 +++++++++ .../integration/staking/keeper/slash_test.go | 18 +++--- .../staking/keeper/validator_test.go | 56 +++++++++---------- x/auth/client/testutil/suite.go | 9 +-- x/evidence/keeper/infraction_test.go | 6 +- x/slashing/abci_test.go | 4 +- x/slashing/keeper/genesis_test.go | 6 +- x/slashing/keeper/grpc_query_test.go | 4 +- x/slashing/keeper/keeper_test.go | 8 +-- x/slashing/keeper/signing_info_test.go | 4 +- .../{testslashing => testutil}/params.go | 2 +- x/staking/bench_test.go | 4 +- x/staking/genesis_test.go | 4 +- x/staking/keeper/delegation_test.go | 32 +++++------ x/staking/keeper/grpc_query_test.go | 4 +- x/staking/keeper/historical_info_test.go | 16 +++--- x/staking/keeper/slash_test.go | 6 +- x/staking/keeper/validator_test.go | 22 ++++---- x/staking/migrations/v2/store_test.go | 12 ++-- x/staking/simulation/operations_test.go | 5 +- .../helper.go => testutil/helpers.go} | 2 +- x/staking/{teststaking => testutil}/tm.go | 2 +- .../{teststaking => testutil}/validator.go | 2 +- x/staking/types/validator_test.go | 8 +-- 33 files changed, 175 insertions(+), 183 deletions(-) create mode 100644 tests/integration/staking/keeper/params_test.go rename x/slashing/{testslashing => testutil}/params.go (94%) rename x/staking/{teststaking/helper.go => testutil/helpers.go} (99%) rename x/staking/{teststaking => testutil}/tm.go (98%) rename x/staking/{teststaking => testutil}/validator.go (96%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3126c32f7043..3af4efbbd88c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,6 +108,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* (x/slashing) [#13427](https://github.com/cosmos/cosmos-sdk/pull/13427) Move `x/slashing/testslashing` to `x/slashing/testutil` for consistency with other modules. +* (x/staking) [#13427](https://github.com/cosmos/cosmos-sdk/pull/13427) Move `x/staking/teststaking` to `x/staking/testutil` for consistency with other modules. * (simapp) [#13402](https://github.com/cosmos/cosmos-sdk/pull/13402) Move simulation flags to `x/simulation/client/cli`. * (simapp) [#13402](https://github.com/cosmos/cosmos-sdk/pull/13402) Move simulation helpers functions (`SetupSimulation`, `SimulationOperations`, `CheckExportSimulation`, `PrintStats`, `GetSimulationLog`) to `testutil/sims`. * (simapp) [#13402](https://github.com/cosmos/cosmos-sdk/pull/13402) Move `testutil/rest` package to `testutil`. diff --git a/tests/integration/bank/keeper/keeper_test.go b/tests/integration/bank/keeper/keeper_test.go index dac872d0ae49..d201da41e6e5 100644 --- a/tests/integration/bank/keeper/keeper_test.go +++ b/tests/integration/bank/keeper/keeper_test.go @@ -138,9 +138,6 @@ func (suite *IntegrationTestSuite) SetupTest() { suite.ctx = app.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()}) suite.fetchStoreKey = app.UnsafeFindStoreKey - // suite.Require().NoError(suite.accountKeeper.SetParams(suite.ctx, authtypes.DefaultParams())) - suite.Require().NoError(suite.bankKeeper.SetParams(suite.ctx, types.DefaultParams())) - queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, interfaceRegistry) types.RegisterQueryServer(queryHelper, suite.bankKeeper) queryClient := types.NewQueryClient(queryHelper) diff --git a/tests/integration/distribution/keeper/allocation_test.go b/tests/integration/distribution/keeper/allocation_test.go index 057935fc0bb1..82bd0a3ada7d 100644 --- a/tests/integration/distribution/keeper/allocation_test.go +++ b/tests/integration/distribution/keeper/allocation_test.go @@ -18,7 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/distribution/testutil" disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + stakingtestutil "github.com/cosmos/cosmos-sdk/x/staking/testutil" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -40,7 +40,7 @@ func TestAllocateTokensToValidatorWithCommission(t *testing.T) { addrs := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 3, sdk.NewInt(1234)) valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs) - tstaking := teststaking.NewHelper(t, ctx, stakingKeeper) + tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper) // create validator with 50% commission tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), math.LegacyNewDec(0)) @@ -86,7 +86,7 @@ func TestAllocateTokensToManyValidators(t *testing.T) { addrs := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 2, sdk.NewInt(1234)) valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs) - tstaking := teststaking.NewHelper(t, ctx, stakingKeeper) + tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper) // create validator with 50% commission tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), math.LegacyNewDec(0)) @@ -179,7 +179,7 @@ func TestAllocateTokensTruncation(t *testing.T) { addrs := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 3, sdk.NewInt(1234)) valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs) - tstaking := teststaking.NewHelper(t, ctx, stakingKeeper) + tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper) // create validator with 10% commission tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), math.LegacyNewDec(0)) diff --git a/tests/integration/distribution/keeper/delegation_test.go b/tests/integration/distribution/keeper/delegation_test.go index 0bb991158114..eab6e933cc0c 100644 --- a/tests/integration/distribution/keeper/delegation_test.go +++ b/tests/integration/distribution/keeper/delegation_test.go @@ -16,7 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/distribution/testutil" "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + stakingtestutil "github.com/cosmos/cosmos-sdk/x/staking/testutil" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -38,7 +38,7 @@ func TestCalculateRewardsBasic(t *testing.T) { distrKeeper.DeleteAllValidatorHistoricalRewards(ctx) - tstaking := teststaking.NewHelper(t, ctx, stakingKeeper) + tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper) addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 2, sdk.NewInt(1000)) valAddrs := simtestutil.ConvertAddrsToValAddrs(addr) @@ -107,7 +107,7 @@ func TestCalculateRewardsAfterSlash(t *testing.T) { addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 2, sdk.NewInt(100000000)) valAddrs := simtestutil.ConvertAddrsToValAddrs(addr) - tstaking := teststaking.NewHelper(t, ctx, stakingKeeper) + tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper) // create validator with 50% commission tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), math.LegacyNewDec(0)) @@ -180,7 +180,7 @@ func TestCalculateRewardsAfterManySlashes(t *testing.T) { ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - tstaking := teststaking.NewHelper(t, ctx, stakingKeeper) + tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper) addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 2, sdk.NewInt(100000000)) valAddrs := simtestutil.ConvertAddrsToValAddrs(addr) @@ -267,7 +267,7 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) { ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - tstaking := teststaking.NewHelper(t, ctx, stakingKeeper) + tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper) addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 2, sdk.NewInt(100000000)) valAddrs := simtestutil.ConvertAddrsToValAddrs(addr) @@ -350,7 +350,7 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) { balanceTokens := stakingKeeper.TokensFromConsensusPower(ctx, balancePower) addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 1, sdk.NewInt(1000000000)) valAddrs := simtestutil.ConvertAddrsToValAddrs(addr) - tstaking := teststaking.NewHelper(t, ctx, stakingKeeper) + tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper) // set module account coins distrAcc := distrKeeper.GetDistributionAccount(ctx) @@ -431,7 +431,7 @@ func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) { addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 1, sdk.NewInt(1000000000)) valAddrs := simtestutil.ConvertAddrsToValAddrs(addr) - tstaking := teststaking.NewHelper(t, ctx, stakingKeeper) + tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper) // create validator with 50% commission valPower := int64(100) @@ -509,7 +509,7 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) { ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - tstaking := teststaking.NewHelper(t, ctx, stakingKeeper) + tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper) addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 2, sdk.NewInt(1000000000)) valAddrs := simtestutil.ConvertAddrsToValAddrs(addr) @@ -599,7 +599,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { distrKeeper.DeleteAllValidatorHistoricalRewards(ctx) - tstaking := teststaking.NewHelper(t, ctx, stakingKeeper) + tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper) addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 2, sdk.NewInt(1000000000)) valAddrs := simtestutil.ConvertAddrsToValAddrs(addr) initial := int64(20) @@ -758,7 +758,7 @@ func Test100PercentCommissionReward(t *testing.T) { ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - tstaking := teststaking.NewHelper(t, ctx, stakingKeeper) + tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper) addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 2, sdk.NewInt(1000000000)) valAddrs := simtestutil.ConvertAddrsToValAddrs(addr) initial := int64(20) diff --git a/tests/integration/distribution/keeper/grpc_query_test.go b/tests/integration/distribution/keeper/grpc_query_test.go index aa4c09c1ecf8..bd5105540f0d 100644 --- a/tests/integration/distribution/keeper/grpc_query_test.go +++ b/tests/integration/distribution/keeper/grpc_query_test.go @@ -21,7 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + stakingtestutil "github.com/cosmos/cosmos-sdk/x/staking/testutil" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -60,8 +60,6 @@ func (suite *KeeperTestSuite) SetupTest() { suite.addrs = simtestutil.AddTestAddrs(suite.bankKeeper, suite.stakingKeeper, ctx, 2, sdk.NewInt(1000000000)) suite.valAddrs = simtestutil.ConvertAddrsToValAddrs(suite.addrs) - - suite.NoError(suite.distrKeeper.SetParams(suite.ctx, types.DefaultParams())) suite.msgServer = keeper.NewMsgServerImpl(suite.distrKeeper) } @@ -362,7 +360,7 @@ func (suite *KeeperTestSuite) TestGRPCValidatorSlashes() { func (suite *KeeperTestSuite) TestGRPCDelegationRewards() { ctx, addrs, valAddrs := suite.ctx, suite.addrs, suite.valAddrs - tstaking := teststaking.NewHelper(suite.T(), ctx, suite.stakingKeeper) + tstaking := stakingtestutil.NewHelper(suite.T(), ctx, suite.stakingKeeper) tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), math.LegacyNewDec(0)) tstaking.CreateValidator(valAddrs[0], valConsPk0, sdk.NewInt(100), true) diff --git a/tests/integration/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go index bbd703818aa4..28a49a647e8d 100644 --- a/tests/integration/slashing/keeper/keeper_test.go +++ b/tests/integration/slashing/keeper/keeper_test.go @@ -10,19 +10,16 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/testslashing" "github.com/cosmos/cosmos-sdk/x/slashing/testutil" "github.com/cosmos/cosmos-sdk/x/staking" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtestutil "github.com/cosmos/cosmos-sdk/x/staking/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -57,10 +54,8 @@ func (s *KeeperTestSuite) SetupTest() { ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - s.accountKeeper.SetParams(ctx, authtypes.DefaultParams()) - s.bankKeeper.SetParams(ctx, banktypes.DefaultParams()) - s.slashingKeeper.SetParams(ctx, testslashing.TestParams()) - + // TestParams set the SignedBlocksWindow to 1000 and MaxMissedBlocksPerWindow to 500 + s.slashingKeeper.SetParams(ctx, testutil.TestParams()) addrDels := simtestutil.AddTestAddrsIncremental(s.bankKeeper, s.stakingKeeper, ctx, 5, s.stakingKeeper.TokensFromConsensusPower(ctx, 200)) info1 := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[0]), int64(4), int64(3), @@ -91,7 +86,7 @@ func (s *KeeperTestSuite) TestUnJailNotBonded() { addrDels := simtestutil.AddTestAddrsIncremental(s.bankKeeper, s.stakingKeeper, ctx, 6, s.stakingKeeper.TokensFromConsensusPower(ctx, 200)) valAddrs := simtestutil.ConvertAddrsToValAddrs(addrDels) pks := simtestutil.CreateTestPubKeys(6) - tstaking := teststaking.NewHelper(s.T(), ctx, s.stakingKeeper) + tstaking := stakingtestutil.NewHelper(s.T(), ctx, s.stakingKeeper) // create max (5) validators all with the same power for i := uint32(0); i < p.MaxValidators; i++ { @@ -153,7 +148,7 @@ func (s *KeeperTestSuite) TestHandleNewValidator() { valAddrs := simtestutil.ConvertAddrsToValAddrs(addrDels) pks := simtestutil.CreateTestPubKeys(1) addr, val := valAddrs[0], pks[0] - tstaking := teststaking.NewHelper(s.T(), ctx, s.stakingKeeper) + tstaking := stakingtestutil.NewHelper(s.T(), ctx, s.stakingKeeper) ctx = ctx.WithBlockHeight(s.slashingKeeper.SignedBlocksWindow(ctx) + 1) // Validator created @@ -192,7 +187,6 @@ func (s *KeeperTestSuite) TestHandleNewValidator() { // Ensure that they're only slashed once func (s *KeeperTestSuite) TestHandleAlreadyJailed() { // initial setup - ctx := s.ctx addrDels := simtestutil.AddTestAddrsIncremental(s.bankKeeper, s.stakingKeeper, ctx, 1, s.stakingKeeper.TokensFromConsensusPower(ctx, 200)) @@ -200,7 +194,7 @@ func (s *KeeperTestSuite) TestHandleAlreadyJailed() { pks := simtestutil.CreateTestPubKeys(1) addr, val := valAddrs[0], pks[0] power := int64(100) - tstaking := teststaking.NewHelper(s.T(), ctx, s.stakingKeeper) + tstaking := stakingtestutil.NewHelper(s.T(), ctx, s.stakingKeeper) amt := tstaking.CreateValidatorWithValPower(addr, val, power, true) @@ -244,11 +238,7 @@ func (s *KeeperTestSuite) TestHandleAlreadyJailed() { // the start height of the signing info is reset correctly func (s *KeeperTestSuite) TestValidatorDippingInAndOut() { // initial setup - // TestParams set the SignedBlocksWindow to 1000 and MaxMissedBlocksPerWindow to 500 - ctx := s.ctx - s.slashingKeeper.SetParams(ctx, testslashing.TestParams()) - params := s.stakingKeeper.GetParams(ctx) params.MaxValidators = 1 s.stakingKeeper.SetParams(ctx, params) @@ -259,7 +249,7 @@ func (s *KeeperTestSuite) TestValidatorDippingInAndOut() { addr, val := pks[0].Address(), pks[0] consAddr := sdk.ConsAddress(addr) - tstaking := teststaking.NewHelper(s.T(), ctx, s.stakingKeeper) + tstaking := stakingtestutil.NewHelper(s.T(), ctx, s.stakingKeeper) valAddr := sdk.ValAddress(addr) tstaking.CreateValidatorWithValPower(valAddr, val, power, true) diff --git a/tests/integration/staking/keeper/common_test.go b/tests/integration/staking/keeper/common_test.go index 39e1cbab111a..16b05a8e3662 100644 --- a/tests/integration/staking/keeper/common_test.go +++ b/tests/integration/staking/keeper/common_test.go @@ -15,7 +15,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + "github.com/cosmos/cosmos-sdk/x/staking/testutil" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -67,8 +67,8 @@ func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) - val1 := teststaking.NewValidator(t, valAddrs[0], pks[0]) - val2 := teststaking.NewValidator(t, valAddrs[1], pks[1]) + val1 := testutil.NewValidator(t, valAddrs[0], pks[0]) + val2 := testutil.NewValidator(t, valAddrs[1], pks[1]) vals := []types.Validator{val1, val2} app.StakingKeeper.SetValidator(ctx, val1) diff --git a/tests/integration/staking/keeper/delegation_test.go b/tests/integration/staking/keeper/delegation_test.go index f73bafa5ca06..384e949149f1 100644 --- a/tests/integration/staking/keeper/delegation_test.go +++ b/tests/integration/staking/keeper/delegation_test.go @@ -10,9 +10,9 @@ import ( "cosmossdk.io/simapp" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/testutil" + banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil" "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + "github.com/cosmos/cosmos-sdk/x/staking/testutil" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -27,11 +27,11 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) { bondDenom := app.StakingKeeper.BondDenom(ctx) notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx) - require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, startTokens)))) + require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, startTokens)))) app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) // create a validator and a delegator to that validator - validator := teststaking.NewValidator(t, addrVals[0], PKs[0]) + validator := testutil.NewValidator(t, addrVals[0], PKs[0]) validator, issuedShares := validator.AddTokensFromDel(startTokens) require.Equal(t, startTokens, issuedShares.RoundInt()) diff --git a/tests/integration/staking/keeper/keeper_test.go b/tests/integration/staking/keeper/keeper_test.go index 53f075452853..655b0ba49c3c 100644 --- a/tests/integration/staking/keeper/keeper_test.go +++ b/tests/integration/staking/keeper/keeper_test.go @@ -3,7 +3,6 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -54,23 +53,6 @@ func (suite *IntegrationTestSuite) SetupTest() { suite.app, suite.ctx, suite.queryClient, suite.addrs, suite.vals = app, ctx, queryClient, addrs, validators } -func TestParams(t *testing.T) { - app := simapp.Setup(t, false) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - - expParams := types.DefaultParams() - - // check that the empty keeper loads the default - resParams := app.StakingKeeper.GetParams(ctx) - require.True(t, expParams.Equal(resParams)) - - // modify a params, save, and retrieve - expParams.MaxValidators = 777 - app.StakingKeeper.SetParams(ctx, expParams) - resParams = app.StakingKeeper.GetParams(ctx) - require.True(t, expParams.Equal(resParams)) -} - func TestIntegrationTestSuite(t *testing.T) { suite.Run(t, new(IntegrationTestSuite)) } diff --git a/tests/integration/staking/keeper/params_test.go b/tests/integration/staking/keeper/params_test.go new file mode 100644 index 000000000000..2faf7a3131d9 --- /dev/null +++ b/tests/integration/staking/keeper/params_test.go @@ -0,0 +1,27 @@ +package keeper + +import ( + "testing" + + "cosmossdk.io/simapp" + "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/stretchr/testify/require" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" +) + +func TestParams(t *testing.T) { + app := simapp.Setup(t, false) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + + expParams := types.DefaultParams() + + // check that the empty keeper loads the default + resParams := app.StakingKeeper.GetParams(ctx) + require.True(t, expParams.Equal(resParams)) + + // modify a params, save, and retrieve + expParams.MaxValidators = 777 + app.StakingKeeper.SetParams(ctx, expParams) + resParams = app.StakingKeeper.GetParams(ctx) + require.True(t, expParams.Equal(resParams)) +} diff --git a/tests/integration/staking/keeper/slash_test.go b/tests/integration/staking/keeper/slash_test.go index 7d9c26a81ebd..271851c270f9 100644 --- a/tests/integration/staking/keeper/slash_test.go +++ b/tests/integration/staking/keeper/slash_test.go @@ -11,9 +11,9 @@ import ( "cosmossdk.io/simapp" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/testutil" + banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil" "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + "github.com/cosmos/cosmos-sdk/x/staking/testutil" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -27,7 +27,7 @@ func bootstrapSlashTest(t *testing.T, power int64) (*simapp.SimApp, sdk.Context, totalSupply := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), amt.MulRaw(int64(len(addrDels))))) notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx) - require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), totalSupply)) + require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), totalSupply)) app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) @@ -37,10 +37,10 @@ func bootstrapSlashTest(t *testing.T, power int64) (*simapp.SimApp, sdk.Context, // set bonded pool balance app.AccountKeeper.SetModuleAccount(ctx, bondedPool) - require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), bondedCoins)) + require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), bondedCoins)) for i := int64(0); i < numVals; i++ { - validator := teststaking.NewValidator(t, addrVals[i], PKs[i]) + validator := testutil.NewValidator(t, addrVals[i], PKs[i]) validator, _ = validator.AddTokensFromDel(amt) validator = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, true) app.StakingKeeper.SetValidatorByConsAddr(ctx, validator) @@ -103,7 +103,7 @@ func TestSlashRedelegation(t *testing.T) { bondedPool := app.StakingKeeper.GetBondedPool(ctx) balances := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()) - require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), startCoins)) + require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), startCoins)) app.AccountKeeper.SetModuleAccount(ctx, bondedPool) // set a redelegation with an expiration timestamp beyond which the @@ -370,7 +370,7 @@ func TestSlashWithRedelegation(t *testing.T) { notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx) rdCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, rdTokens.MulRaw(2))) - require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), rdCoins)) + require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), rdCoins)) app.AccountKeeper.SetModuleAccount(ctx, bondedPool) @@ -531,8 +531,8 @@ func TestSlashBoth(t *testing.T) { bondedPool := app.StakingKeeper.GetBondedPool(ctx) notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx) - require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), bondedCoins)) - require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), notBondedCoins)) + require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), bondedCoins)) + require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), notBondedCoins)) app.AccountKeeper.SetModuleAccount(ctx, bondedPool) app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) diff --git a/tests/integration/staking/keeper/validator_test.go b/tests/integration/staking/keeper/validator_test.go index 5190e4135666..04b3a7fb38cb 100644 --- a/tests/integration/staking/keeper/validator_test.go +++ b/tests/integration/staking/keeper/validator_test.go @@ -13,10 +13,10 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/testutil" + banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + "github.com/cosmos/cosmos-sdk/x/staking/testutil" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -38,7 +38,7 @@ func bootstrapValidatorTest(t testing.TB, power int64, numAddrs int) (*simapp.Si // set bonded pool supply app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) - require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), totalSupply)) + require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), totalSupply)) // unbond genesis validator delegations delegations := app.StakingKeeper.GetAllDelegations(ctx) @@ -60,7 +60,7 @@ func initValidators(t testing.TB, power int64, numAddrs int, powers []int64) (*s vs := make([]types.Validator, len(powers)) for i, power := range powers { - vs[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), pks[i]) + vs[i] = testutil.NewValidator(t, sdk.ValAddress(addrs[i]), pks[i]) tokens := app.StakingKeeper.TokensFromConsensusPower(ctx, power) vs[i], _ = vs[i].AddTokensFromDel(tokens) } @@ -83,8 +83,8 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) { app.StakingKeeper.SetParams(ctx, params) // create a random pool - require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 1234))))) - require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 10000))))) + require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 1234))))) + require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 10000))))) app.AccountKeeper.SetModuleAccount(ctx, bondedPool) app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) @@ -133,12 +133,12 @@ func TestSlashToZeroPowerRemoved(t *testing.T) { app, ctx, _, addrVals := bootstrapValidatorTest(t, 100, 20) // add a validator - validator := teststaking.NewValidator(t, addrVals[0], PKs[0]) + validator := testutil.NewValidator(t, addrVals[0], PKs[0]) valTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 100) bondedPool := app.StakingKeeper.GetBondedPool(ctx) - require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), valTokens)))) + require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), valTokens)))) app.AccountKeeper.SetModuleAccount(ctx, bondedPool) @@ -173,7 +173,7 @@ func TestGetValidatorSortingUnmixed(t *testing.T) { n := len(amts) var validators [5]types.Validator for i, amt := range amts { - validators[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i]) + validators[i] = testutil.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i]) validators[i].Status = types.Bonded validators[i].Tokens = amt validators[i].DelegatorShares = sdk.NewDecFromInt(amt) @@ -245,8 +245,8 @@ func TestGetValidatorSortingMixed(t *testing.T) { bondedPool := app.StakingKeeper.GetBondedPool(ctx) notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx) - require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 501))))) - require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 0))))) + require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 501))))) + require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 0))))) app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) app.AccountKeeper.SetModuleAccount(ctx, bondedPool) @@ -267,7 +267,7 @@ func TestGetValidatorSortingMixed(t *testing.T) { var validators [5]types.Validator for i, amt := range amts { - validators[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i]) + validators[i] = testutil.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i]) validators[i].DelegatorShares = sdk.NewDecFromInt(amt) validators[i].Status = types.Bonded validators[i].Tokens = amt @@ -321,7 +321,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) { validators[i], _ = validators[i].AddTokensFromDel(tokens) notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx) - require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(params.BondDenom, tokens)))) + require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(params.BondDenom, tokens)))) app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) validators[i] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[i], true) } @@ -340,7 +340,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) { newTokens := sdk.NewCoins() - require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), newTokens)) + require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), newTokens)) app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) // test that the two largest validators are @@ -372,7 +372,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) { notBondedPool = app.StakingKeeper.GetNotBondedPool(ctx) newTokens = sdk.NewCoins(sdk.NewCoin(params.BondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 1))) - require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), newTokens)) + require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), newTokens)) app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) validators[3] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[3], true) @@ -387,7 +387,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) { validators[3], _ = validators[3].RemoveDelShares(math.LegacyNewDec(201)) bondedPool := app.StakingKeeper.GetBondedPool(ctx) - require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(params.BondDenom, rmTokens)))) + require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(params.BondDenom, rmTokens)))) app.AccountKeeper.SetModuleAccount(ctx, bondedPool) validators[3] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[3], true) @@ -401,7 +401,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) { validators[3], _ = validators[3].AddTokensFromDel(sdk.NewInt(200)) notBondedPool = app.StakingKeeper.GetNotBondedPool(ctx) - require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(params.BondDenom, sdk.NewInt(200))))) + require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(params.BondDenom, sdk.NewInt(200))))) app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) validators[3] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[3], true) @@ -423,9 +423,9 @@ func TestValidatorBondHeight(t *testing.T) { // initialize some validators into the state var validators [3]types.Validator - validators[0] = teststaking.NewValidator(t, sdk.ValAddress(PKs[0].Address().Bytes()), PKs[0]) - validators[1] = teststaking.NewValidator(t, sdk.ValAddress(addrs[1]), PKs[1]) - validators[2] = teststaking.NewValidator(t, sdk.ValAddress(addrs[2]), PKs[2]) + validators[0] = testutil.NewValidator(t, sdk.ValAddress(PKs[0].Address().Bytes()), PKs[0]) + validators[1] = testutil.NewValidator(t, sdk.ValAddress(addrs[1]), PKs[1]) + validators[2] = testutil.NewValidator(t, sdk.ValAddress(addrs[2]), PKs[2]) tokens0 := app.StakingKeeper.TokensFromConsensusPower(ctx, 200) tokens1 := app.StakingKeeper.TokensFromConsensusPower(ctx, 100) @@ -471,7 +471,7 @@ func TestFullValidatorSetPowerChange(t *testing.T) { powers := []int64{0, 100, 400, 400, 200} var validators [5]types.Validator for i, power := range powers { - validators[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i]) + validators[i] = testutil.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i]) tokens := app.StakingKeeper.TokensFromConsensusPower(ctx, power) validators[i], _ = validators[i].AddTokensFromDel(tokens) keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[i], true) @@ -511,7 +511,7 @@ func TestApplyAndReturnValidatorSetUpdatesAllNone(t *testing.T) { valPubKey := PKs[i+1] valAddr := sdk.ValAddress(valPubKey.Address().Bytes()) - validators[i] = teststaking.NewValidator(t, valAddr, valPubKey) + validators[i] = testutil.NewValidator(t, valAddr, valPubKey) tokens := app.StakingKeeper.TokensFromConsensusPower(ctx, power) validators[i], _ = validators[i].AddTokensFromDel(tokens) } @@ -537,7 +537,7 @@ func TestApplyAndReturnValidatorSetUpdatesIdentical(t *testing.T) { powers := []int64{10, 20} var validators [2]types.Validator for i, power := range powers { - validators[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i]) + validators[i] = testutil.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i]) tokens := app.StakingKeeper.TokensFromConsensusPower(ctx, power) validators[i], _ = validators[i].AddTokensFromDel(tokens) @@ -560,7 +560,7 @@ func TestApplyAndReturnValidatorSetUpdatesSingleValueChange(t *testing.T) { powers := []int64{10, 20} var validators [2]types.Validator for i, power := range powers { - validators[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i]) + validators[i] = testutil.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i]) tokens := app.StakingKeeper.TokensFromConsensusPower(ctx, power) validators[i], _ = validators[i].AddTokensFromDel(tokens) @@ -645,7 +645,7 @@ func TestApplyAndReturnValidatorSetUpdatesWithCliffValidator(t *testing.T) { powers := []int64{10, 20, 5} var validators [5]types.Validator for i, power := range powers { - validators[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i]) + validators[i] = testutil.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i]) tokens := app.StakingKeeper.TokensFromConsensusPower(ctx, power) validators[i], _ = validators[i].AddTokensFromDel(tokens) } @@ -687,7 +687,7 @@ func TestApplyAndReturnValidatorSetUpdatesNewValidator(t *testing.T) { valPubKey := PKs[i+1] valAddr := sdk.ValAddress(valPubKey.Address().Bytes()) - validators[i] = teststaking.NewValidator(t, valAddr, valPubKey) + validators[i] = testutil.NewValidator(t, valAddr, valPubKey) tokens := app.StakingKeeper.TokensFromConsensusPower(ctx, power) validators[i], _ = validators[i].AddTokensFromDel(tokens) @@ -721,7 +721,7 @@ func TestApplyAndReturnValidatorSetUpdatesNewValidator(t *testing.T) { valAddr := sdk.ValAddress(valPubKey.Address().Bytes()) amt := sdk.NewInt(100) - validator := teststaking.NewValidator(t, valAddr, valPubKey) + validator := testutil.NewValidator(t, valAddr, valPubKey) validator, _ = validator.AddTokensFromDel(amt) app.StakingKeeper.SetValidator(ctx, validator) @@ -734,7 +734,7 @@ func TestApplyAndReturnValidatorSetUpdatesNewValidator(t *testing.T) { valPubKey = PKs[len(validators)+2] valAddr = sdk.ValAddress(valPubKey.Address().Bytes()) - validator = teststaking.NewValidator(t, valAddr, valPubKey) + validator = testutil.NewValidator(t, valAddr, valPubKey) tokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 500) validator, _ = validator.AddTokensFromDel(tokens) app.StakingKeeper.SetValidator(ctx, validator) diff --git a/x/auth/client/testutil/suite.go b/x/auth/client/testutil/suite.go index b4620fe4f7cc..7834a6506faf 100644 --- a/x/auth/client/testutil/suite.go +++ b/x/auth/client/testutil/suite.go @@ -80,7 +80,6 @@ func (s *IntegrationTestSuite) SetupSuite() { multi := kmultisig.NewLegacyAminoPubKey(2, []cryptotypes.PubKey{pub1, pub2}) _, err = kb.SaveMultisig("multi", multi) s.Require().NoError(err) - s.Require().NoError(s.network.WaitForNextBlock()) } @@ -830,6 +829,7 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() { res, err = TxValidateSignaturesExec(val1.ClientCtx, signedTxFile.Name()) s.Require().NoError(err) s.Require().True(strings.Contains(res.String(), "[OK]")) + s.Require().NoError(s.network.WaitForNextBlock()) // Ensure foo has right amount of funds resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address) @@ -844,14 +844,12 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() { // Does not work in offline mode _, err = TxBroadcastExec(val1.ClientCtx, signedTxFile.Name(), "--offline") s.Require().EqualError(err, "cannot broadcast tx during offline mode") - s.Require().NoError(s.network.WaitForNextBlock()) // Broadcast correct transaction. val1.ClientCtx.BroadcastMode = flags.BroadcastSync _, err = TxBroadcastExec(val1.ClientCtx, signedTxFile.Name()) s.Require().NoError(err) - s.Require().NoError(s.network.WaitForNextBlock()) // Ensure destiny account state @@ -891,7 +889,6 @@ func (s *IntegrationTestSuite) TestCLIMultisignInsufficientCosigners() { ), ) s.Require().NoError(err) - s.Require().NoError(s.network.WaitForNextBlock()) // Generate multisig transaction. @@ -998,7 +995,6 @@ func (s *IntegrationTestSuite) TestCLIMultisignSortSignatures() { sdk.NewCoins(sendTokens), ) s.Require().NoError(err) - s.Require().NoError(s.network.WaitForNextBlock()) resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, addr) @@ -1131,7 +1127,6 @@ func (s *IntegrationTestSuite) TestCLIMultisign() { val1, addr, sdk.NewCoins(sendTokens), ) - s.Require().NoError(s.network.WaitForNextBlock()) s.Require().NoError(err) s.Require().NoError(s.network.WaitForNextBlock()) @@ -1884,6 +1879,8 @@ func (s *IntegrationTestSuite) TestAuxToFeeWithTips() { genTxFile.Name(), tc.feePayerArgs..., ) + s.Require().NoError(s.network.WaitForNextBlock()) + switch { case tc.expectErrBroadCast: require.Error(err) diff --git a/x/evidence/keeper/infraction_test.go b/x/evidence/keeper/infraction_test.go index 8cd9ddbe7702..96fc36cfeeeb 100644 --- a/x/evidence/keeper/infraction_test.go +++ b/x/evidence/keeper/infraction_test.go @@ -16,7 +16,7 @@ import ( slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + stakingtestutil "github.com/cosmos/cosmos-sdk/x/staking/testutil" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -68,7 +68,7 @@ func (suite *InfractionTestSuite) TestHandleDoubleSign() { power := int64(100) stakingParams := suite.stakingKeeper.GetParams(ctx) operatorAddr, val := valAddresses[0], pubkeys[0] - tstaking := teststaking.NewHelper(suite.T(), ctx, suite.stakingKeeper) + tstaking := stakingtestutil.NewHelper(suite.T(), ctx, suite.stakingKeeper) selfDelegation := tstaking.CreateValidatorWithValPower(operatorAddr, val, power, true) @@ -134,7 +134,7 @@ func (suite *InfractionTestSuite) TestHandleDoubleSign_TooOld() { power := int64(100) stakingParams := suite.stakingKeeper.GetParams(ctx) operatorAddr, val := valAddresses[0], pubkeys[0] - tstaking := teststaking.NewHelper(suite.T(), ctx, suite.stakingKeeper) + tstaking := stakingtestutil.NewHelper(suite.T(), ctx, suite.stakingKeeper) amt := tstaking.CreateValidatorWithValPower(operatorAddr, val, power, true) diff --git a/x/slashing/abci_test.go b/x/slashing/abci_test.go index 6add22132fa8..a74d7bc4c1cc 100644 --- a/x/slashing/abci_test.go +++ b/x/slashing/abci_test.go @@ -17,7 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/slashing/testutil" "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + stakingtestutil "github.com/cosmos/cosmos-sdk/x/staking/testutil" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -41,7 +41,7 @@ func TestBeginBlocker(t *testing.T) { pks := simtestutil.CreateTestPubKeys(1) simtestutil.AddTestAddrsFromPubKeys(bankKeeper, stakingKeeper, ctx, pks, stakingKeeper.TokensFromConsensusPower(ctx, 200)) addr, pk := sdk.ValAddress(pks[0].Address()), pks[0] - tstaking := teststaking.NewHelper(t, ctx, stakingKeeper) + tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper) // bond the validator power := int64(100) diff --git a/x/slashing/keeper/genesis_test.go b/x/slashing/keeper/genesis_test.go index 2b882c1bba45..5aea8f4204e5 100644 --- a/x/slashing/keeper/genesis_test.go +++ b/x/slashing/keeper/genesis_test.go @@ -6,7 +6,7 @@ import ( "github.com/golang/mock/gomock" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/testslashing" + "github.com/cosmos/cosmos-sdk/x/slashing/testutil" "github.com/cosmos/cosmos-sdk/x/slashing/types" ) @@ -14,7 +14,7 @@ func (s *KeeperTestSuite) TestExportAndInitGenesis() { ctx, keeper := s.ctx, s.slashingKeeper require := s.Require() - keeper.SetParams(ctx, testslashing.TestParams()) + keeper.SetParams(ctx, testutil.TestParams()) consAddr1 := sdk.ConsAddress(sdk.AccAddress([]byte("addr1_______________"))) consAddr2 := sdk.ConsAddress(sdk.AccAddress([]byte("addr2_______________"))) @@ -28,7 +28,7 @@ func (s *KeeperTestSuite) TestExportAndInitGenesis() { keeper.SetValidatorSigningInfo(ctx, consAddr2, info2) genesisState := keeper.ExportGenesis(ctx) - require.Equal(genesisState.Params, testslashing.TestParams()) + require.Equal(genesisState.Params, testutil.TestParams()) require.Len(genesisState.SigningInfos, 2) require.Equal(genesisState.SigningInfos[0].ValidatorSigningInfo, info1) diff --git a/x/slashing/keeper/grpc_query_test.go b/x/slashing/keeper/grpc_query_test.go index d11d4c9dbb01..20f111439d68 100644 --- a/x/slashing/keeper/grpc_query_test.go +++ b/x/slashing/keeper/grpc_query_test.go @@ -6,7 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/cosmos/cosmos-sdk/x/slashing/testslashing" + "github.com/cosmos/cosmos-sdk/x/slashing/testutil" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" ) @@ -17,7 +17,7 @@ func (s *KeeperTestSuite) TestGRPCQueryParams() { paramsResp, err := queryClient.Params(gocontext.Background(), &slashingtypes.QueryParamsRequest{}) require.NoError(err) - require.Equal(testslashing.TestParams(), paramsResp.Params) + require.Equal(testutil.TestParams(), paramsResp.Params) } func (s *KeeperTestSuite) TestGRPCSigningInfo() { diff --git a/x/slashing/keeper/keeper_test.go b/x/slashing/keeper/keeper_test.go index f951beec6f6c..2d68306183a8 100644 --- a/x/slashing/keeper/keeper_test.go +++ b/x/slashing/keeper/keeper_test.go @@ -11,11 +11,11 @@ import ( tmtime "github.com/tendermint/tendermint/types/time" "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/testutil" + sdktestutil "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/cosmos/cosmos-sdk/x/slashing/testslashing" + "github.com/cosmos/cosmos-sdk/x/slashing/testutil" slashingtestutil "github.com/cosmos/cosmos-sdk/x/slashing/testutil" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" @@ -38,7 +38,7 @@ type KeeperTestSuite struct { func (s *KeeperTestSuite) SetupTest() { key := sdk.NewKVStoreKey(slashingtypes.StoreKey) - testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + testCtx := sdktestutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) encCfg := moduletestutil.MakeTestEncodingConfig() @@ -55,7 +55,7 @@ func (s *KeeperTestSuite) SetupTest() { sdk.AccAddress(crypto.AddressHash([]byte(govtypes.ModuleName))).String(), ) // set test params - s.slashingKeeper.SetParams(ctx, testslashing.TestParams()) + s.slashingKeeper.SetParams(ctx, testutil.TestParams()) slashingtypes.RegisterInterfaces(encCfg.InterfaceRegistry) queryHelper := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry) diff --git a/x/slashing/keeper/signing_info_test.go b/x/slashing/keeper/signing_info_test.go index cfef7104b825..f33fbf34b53d 100644 --- a/x/slashing/keeper/signing_info_test.go +++ b/x/slashing/keeper/signing_info_test.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/testslashing" + "github.com/cosmos/cosmos-sdk/x/slashing/testutil" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" ) @@ -57,7 +57,7 @@ func (s *KeeperTestSuite) TestValidatorMissedBlockBitArray() { ctx, keeper := s.ctx, s.slashingKeeper require := s.Require() - params := testslashing.TestParams() + params := testutil.TestParams() params.SignedBlocksWindow = 100 require.NoError(keeper.SetParams(ctx, params)) diff --git a/x/slashing/testslashing/params.go b/x/slashing/testutil/params.go similarity index 94% rename from x/slashing/testslashing/params.go rename to x/slashing/testutil/params.go index dac3f23c5c5e..a6961744d789 100644 --- a/x/slashing/testslashing/params.go +++ b/x/slashing/testutil/params.go @@ -1,4 +1,4 @@ -package testslashing +package testutil import ( "github.com/cosmos/cosmos-sdk/x/slashing/types" diff --git a/x/staking/bench_test.go b/x/staking/bench_test.go index c92b4cacdba3..26f533e2e132 100644 --- a/x/staking/bench_test.go +++ b/x/staking/bench_test.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + "github.com/cosmos/cosmos-sdk/x/staking/testutil" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -30,7 +30,7 @@ func benchmarkValidateGenesis(b *testing.B, n int) { addressL, pubKeyL := makeRandomAddressesAndPublicKeys(n) for i := 0; i < n; i++ { addr, pubKey := addressL[i], pubKeyL[i] - validator := teststaking.NewValidator(b, addr, pubKey) + validator := testutil.NewValidator(b, addr, pubKey) ni := int64(i + 1) validator.Tokens = sdk.NewInt(ni) validator.DelegatorShares = math.LegacyNewDec(ni) diff --git a/x/staking/genesis_test.go b/x/staking/genesis_test.go index fbbaf3363442..8e33db0e3717 100644 --- a/x/staking/genesis_test.go +++ b/x/staking/genesis_test.go @@ -9,14 +9,14 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + "github.com/cosmos/cosmos-sdk/x/staking/testutil" "github.com/cosmos/cosmos-sdk/x/staking/types" ) func TestValidateGenesis(t *testing.T) { genValidators1 := make([]types.Validator, 1, 5) pk := ed25519.GenPrivKey().PubKey() - genValidators1[0] = teststaking.NewValidator(t, sdk.ValAddress(pk.Address()), pk) + genValidators1[0] = testutil.NewValidator(t, sdk.ValAddress(pk.Address()), pk) genValidators1[0].Tokens = math.OneInt() genValidators1[0].DelegatorShares = math.LegacyOneDec() diff --git a/x/staking/keeper/delegation_test.go b/x/staking/keeper/delegation_test.go index 669818b3b34f..7847255b4034 100644 --- a/x/staking/keeper/delegation_test.go +++ b/x/staking/keeper/delegation_test.go @@ -9,7 +9,7 @@ import ( simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + "github.com/cosmos/cosmos-sdk/x/staking/testutil" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -31,7 +31,7 @@ func (s *KeeperTestSuite) TestDelegation() { amts := []math.Int{sdk.NewInt(9), sdk.NewInt(8), sdk.NewInt(7)} var validators [3]stakingtypes.Validator for i, amt := range amts { - validators[i] = teststaking.NewValidator(s.T(), valAddrs[i], PKs[i]) + validators[i] = testutil.NewValidator(s.T(), valAddrs[i], PKs[i]) validators[i], _ = validators[i].AddTokensFromDel(amt) validators[i] = stakingkeeper.TestingUpdateValidator(keeper, ctx, validators[i], true) @@ -196,7 +196,7 @@ func (s *KeeperTestSuite) TestUnbondDelegation() { delAddrs, valAddrs := createValAddrs(1) startTokens := keeper.TokensFromConsensusPower(ctx, 10) - validator := teststaking.NewValidator(s.T(), valAddrs[0], PKs[0]) + validator := testutil.NewValidator(s.T(), valAddrs[0], PKs[0]) validator, issuedShares := validator.AddTokensFromDel(startTokens) require.Equal(startTokens, issuedShares.RoundInt()) @@ -233,7 +233,7 @@ func (s *KeeperTestSuite) TestUndelegateSelfDelegationBelowMinSelfDelegation() { delTokens := keeper.TokensFromConsensusPower(ctx, 10) // create a validator with a self-delegation - validator := teststaking.NewValidator(s.T(), addrVals[0], PKs[0]) + validator := testutil.NewValidator(s.T(), addrVals[0], PKs[0]) validator.MinSelfDelegation = delTokens validator, issuedShares := validator.AddTokensFromDel(delTokens) @@ -281,7 +281,7 @@ func (s *KeeperTestSuite) TestUndelegateFromUnbondingValidator() { addrDels, addrVals := createValAddrs(2) // create a validator with a self-delegation - validator := teststaking.NewValidator(s.T(), addrVals[0], PKs[0]) + validator := testutil.NewValidator(s.T(), addrVals[0], PKs[0]) keeper.SetValidatorByConsAddr(ctx, validator) validator, issuedShares := validator.AddTokensFromDel(delTokens) @@ -353,7 +353,7 @@ func (s *KeeperTestSuite) TestUndelegateFromUnbondedValidator() { addrDels, addrVals := createValAddrs(2) // create a validator with a self-delegation - validator := teststaking.NewValidator(s.T(), addrVals[0], PKs[0]) + validator := testutil.NewValidator(s.T(), addrVals[0], PKs[0]) keeper.SetValidatorByConsAddr(ctx, validator) valTokens := keeper.TokensFromConsensusPower(ctx, 10) @@ -426,7 +426,7 @@ func (s *KeeperTestSuite) TestUnbondingAllDelegationFromValidator() { addrDels, addrVals := createValAddrs(2) // create a validator with a self-delegation - validator := teststaking.NewValidator(s.T(), addrVals[0], PKs[0]) + validator := testutil.NewValidator(s.T(), addrVals[0], PKs[0]) keeper.SetValidatorByConsAddr(ctx, validator) valTokens := keeper.TokensFromConsensusPower(ctx, 10) @@ -581,7 +581,7 @@ func (s *KeeperTestSuite) TestRedelegateToSameValidator() { valTokens := keeper.TokensFromConsensusPower(ctx, 10) // create a validator with a self-delegation - validator := teststaking.NewValidator(s.T(), addrVals[0], PKs[0]) + validator := testutil.NewValidator(s.T(), addrVals[0], PKs[0]) validator, issuedShares := validator.AddTokensFromDel(valTokens) require.Equal(valTokens, issuedShares.RoundInt()) @@ -604,7 +604,7 @@ func (s *KeeperTestSuite) TestRedelegationMaxEntries() { _, addrVals := createValAddrs(2) // create a validator with a self-delegation - validator := teststaking.NewValidator(s.T(), addrVals[0], PKs[0]) + validator := testutil.NewValidator(s.T(), addrVals[0], PKs[0]) valTokens := keeper.TokensFromConsensusPower(ctx, 10) validator, issuedShares := validator.AddTokensFromDel(valTokens) require.Equal(valTokens, issuedShares.RoundInt()) @@ -616,7 +616,7 @@ func (s *KeeperTestSuite) TestRedelegationMaxEntries() { keeper.SetDelegation(ctx, selfDelegation) // create a second validator - validator2 := teststaking.NewValidator(s.T(), addrVals[1], PKs[1]) + validator2 := testutil.NewValidator(s.T(), addrVals[1], PKs[1]) validator2, issuedShares = validator2.AddTokensFromDel(valTokens) require.Equal(valTokens, issuedShares.RoundInt()) @@ -655,7 +655,7 @@ func (s *KeeperTestSuite) TestRedelegateSelfDelegation() { addrDels, addrVals := createValAddrs(2) // create a validator with a self-delegation - validator := teststaking.NewValidator(s.T(), addrVals[0], PKs[0]) + validator := testutil.NewValidator(s.T(), addrVals[0], PKs[0]) keeper.SetValidatorByConsAddr(ctx, validator) valTokens := keeper.TokensFromConsensusPower(ctx, 10) @@ -670,7 +670,7 @@ func (s *KeeperTestSuite) TestRedelegateSelfDelegation() { keeper.SetDelegation(ctx, selfDelegation) // create a second validator - validator2 := teststaking.NewValidator(s.T(), addrVals[1], PKs[1]) + validator2 := testutil.NewValidator(s.T(), addrVals[1], PKs[1]) validator2, issuedShares = validator2.AddTokensFromDel(valTokens) require.Equal(valTokens, issuedShares.RoundInt()) s.bankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), stakingtypes.NotBondedPoolName, stakingtypes.BondedPoolName, gomock.Any()) @@ -706,7 +706,7 @@ func (s *KeeperTestSuite) TestRedelegateFromUnbondingValidator() { addrDels, addrVals := createValAddrs(2) // create a validator with a self-delegation - validator := teststaking.NewValidator(s.T(), addrVals[0], PKs[0]) + validator := testutil.NewValidator(s.T(), addrVals[0], PKs[0]) keeper.SetValidatorByConsAddr(ctx, validator) valTokens := keeper.TokensFromConsensusPower(ctx, 10) @@ -728,7 +728,7 @@ func (s *KeeperTestSuite) TestRedelegateFromUnbondingValidator() { keeper.SetDelegation(ctx, delegation) // create a second validator - validator2 := teststaking.NewValidator(s.T(), addrVals[1], PKs[1]) + validator2 := testutil.NewValidator(s.T(), addrVals[1], PKs[1]) validator2, issuedShares = validator2.AddTokensFromDel(valTokens) require.Equal(valTokens, issuedShares.RoundInt()) s.bankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), stakingtypes.NotBondedPoolName, stakingtypes.BondedPoolName, gomock.Any()) @@ -785,7 +785,7 @@ func (s *KeeperTestSuite) TestRedelegateFromUnbondedValidator() { addrDels, addrVals := createValAddrs(2) // create a validator with a self-delegation - validator := teststaking.NewValidator(s.T(), addrVals[0], PKs[0]) + validator := testutil.NewValidator(s.T(), addrVals[0], PKs[0]) keeper.SetValidatorByConsAddr(ctx, validator) valTokens := keeper.TokensFromConsensusPower(ctx, 10) @@ -807,7 +807,7 @@ func (s *KeeperTestSuite) TestRedelegateFromUnbondedValidator() { keeper.SetDelegation(ctx, delegation) // create a second validator - validator2 := teststaking.NewValidator(s.T(), addrVals[1], PKs[1]) + validator2 := testutil.NewValidator(s.T(), addrVals[1], PKs[1]) validator2, issuedShares = validator2.AddTokensFromDel(valTokens) require.Equal(valTokens, issuedShares.RoundInt()) s.bankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), stakingtypes.NotBondedPoolName, stakingtypes.BondedPoolName, gomock.Any()) diff --git a/x/staking/keeper/grpc_query_test.go b/x/staking/keeper/grpc_query_test.go index 5f43dc33a340..407c0cc10d11 100644 --- a/x/staking/keeper/grpc_query_test.go +++ b/x/staking/keeper/grpc_query_test.go @@ -5,7 +5,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + "github.com/cosmos/cosmos-sdk/x/staking/testutil" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -13,7 +13,7 @@ func (s *KeeperTestSuite) TestGRPCQueryValidator() { ctx, keeper, queryClient := s.ctx, s.stakingKeeper, s.queryClient require := s.Require() - validator := teststaking.NewValidator(s.T(), sdk.ValAddress(PKs[0].Address().Bytes()), PKs[0]) + validator := testutil.NewValidator(s.T(), sdk.ValAddress(PKs[0].Address().Bytes()), PKs[0]) keeper.SetValidator(ctx, validator) var req *types.QueryValidatorRequest testCases := []struct { diff --git a/x/staking/keeper/historical_info_test.go b/x/staking/keeper/historical_info_test.go index 8756817fea53..c10b10973ea6 100644 --- a/x/staking/keeper/historical_info_test.go +++ b/x/staking/keeper/historical_info_test.go @@ -4,7 +4,7 @@ import ( "cosmossdk.io/math" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + "github.com/cosmos/cosmos-sdk/x/staking/testutil" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -28,7 +28,7 @@ func (s *KeeperTestSuite) TestHistoricalInfo() { validators := make([]stakingtypes.Validator, len(addrVals)) for i, valAddr := range addrVals { - validators[i] = teststaking.NewValidator(s.T(), valAddr, PKs[i]) + validators[i] = testutil.NewValidator(s.T(), valAddr, PKs[i]) } hi := stakingtypes.NewHistoricalInfo(ctx.BlockHeader(), validators, keeper.PowerReduction(ctx)) @@ -68,8 +68,8 @@ func (s *KeeperTestSuite) TestTrackHistoricalInfo() { Height: 5, } valSet := []stakingtypes.Validator{ - teststaking.NewValidator(s.T(), addrVals[0], PKs[0]), - teststaking.NewValidator(s.T(), addrVals[1], PKs[1]), + testutil.NewValidator(s.T(), addrVals[0], PKs[0]), + testutil.NewValidator(s.T(), addrVals[1], PKs[1]), } hi4 := stakingtypes.NewHistoricalInfo(h4, valSet, keeper.PowerReduction(ctx)) hi5 := stakingtypes.NewHistoricalInfo(h5, valSet, keeper.PowerReduction(ctx)) @@ -83,12 +83,12 @@ func (s *KeeperTestSuite) TestTrackHistoricalInfo() { require.Equal(hi5, recv) // Set bonded validators in keeper - val1 := teststaking.NewValidator(s.T(), addrVals[2], PKs[2]) + val1 := testutil.NewValidator(s.T(), addrVals[2], PKs[2]) val1.Status = stakingtypes.Bonded // when not bonded, consensus power is Zero val1.Tokens = keeper.TokensFromConsensusPower(ctx, 10) keeper.SetValidator(ctx, val1) keeper.SetLastValidatorPower(ctx, val1.GetOperator(), 10) - val2 := teststaking.NewValidator(s.T(), addrVals[3], PKs[3]) + val2 := testutil.NewValidator(s.T(), addrVals[3], PKs[3]) val1.Status = stakingtypes.Bonded val2.Tokens = keeper.TokensFromConsensusPower(ctx, 80) keeper.SetValidator(ctx, val2) @@ -131,8 +131,8 @@ func (s *KeeperTestSuite) TestGetAllHistoricalInfo() { _, addrVals := createValAddrs(50) valSet := []stakingtypes.Validator{ - teststaking.NewValidator(s.T(), addrVals[0], PKs[0]), - teststaking.NewValidator(s.T(), addrVals[1], PKs[1]), + testutil.NewValidator(s.T(), addrVals[0], PKs[0]), + testutil.NewValidator(s.T(), addrVals[1], PKs[1]), } header1 := tmproto.Header{ChainID: "HelloChain", Height: 10} diff --git a/x/staking/keeper/slash_test.go b/x/staking/keeper/slash_test.go index 273256fb42ee..b1f6d8c873c3 100644 --- a/x/staking/keeper/slash_test.go +++ b/x/staking/keeper/slash_test.go @@ -2,7 +2,7 @@ package keeper_test import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + "github.com/cosmos/cosmos-sdk/x/staking/testutil" ) // tests Jail, Unjail @@ -12,7 +12,7 @@ func (s *KeeperTestSuite) TestRevocation() { valAddr := sdk.ValAddress(PKs[0].Address().Bytes()) consAddr := sdk.ConsAddress(PKs[0].Address()) - validator := teststaking.NewValidator(s.T(), valAddr, PKs[0]) + validator := testutil.NewValidator(s.T(), valAddr, PKs[0]) // initial state keeper.SetValidator(ctx, validator) @@ -40,7 +40,7 @@ func (s *KeeperTestSuite) TestSlashAtFutureHeight() { require := s.Require() consAddr := sdk.ConsAddress(PKs[0].Address()) - validator := teststaking.NewValidator(s.T(), sdk.ValAddress(PKs[0].Address().Bytes()), PKs[0]) + validator := testutil.NewValidator(s.T(), sdk.ValAddress(PKs[0].Address().Bytes()), PKs[0]) keeper.SetValidator(ctx, validator) err := keeper.SetValidatorByConsAddr(ctx, validator) require.NoError(err) diff --git a/x/staking/keeper/validator_test.go b/x/staking/keeper/validator_test.go index b639360f450b..9e67a98458fa 100644 --- a/x/staking/keeper/validator_test.go +++ b/x/staking/keeper/validator_test.go @@ -9,7 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + "github.com/cosmos/cosmos-sdk/x/staking/testutil" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" abci "github.com/tendermint/tendermint/abci/types" ) @@ -32,7 +32,7 @@ func (s *KeeperTestSuite) TestValidator() { valTokens := keeper.TokensFromConsensusPower(ctx, 10) // test how the validator is set from a purely unbonbed pool - validator := teststaking.NewValidator(s.T(), valAddr, valPubKey) + validator := testutil.NewValidator(s.T(), valAddr, valPubKey) validator, _ = validator.AddTokensFromDel(valTokens) require.Equal(stakingtypes.Unbonded, validator.Status) require.Equal(valTokens, validator.Tokens) @@ -90,7 +90,7 @@ func (s *KeeperTestSuite) TestValidatorBasics() { var validators [3]stakingtypes.Validator powers := []int64{9, 8, 7} for i, power := range powers { - validators[i] = teststaking.NewValidator(s.T(), sdk.ValAddress(PKs[i].Address().Bytes()), PKs[i]) + validators[i] = testutil.NewValidator(s.T(), sdk.ValAddress(PKs[i].Address().Bytes()), PKs[i]) validators[i].Status = stakingtypes.Unbonded validators[i].Tokens = math.ZeroInt() tokens := keeper.TokensFromConsensusPower(ctx, power) @@ -189,7 +189,7 @@ func (s *KeeperTestSuite) TestUpdateValidatorByPowerIndex() { valTokens := keeper.TokensFromConsensusPower(ctx, 100) // add a validator - validator := teststaking.NewValidator(s.T(), valAddr, PKs[0]) + validator := testutil.NewValidator(s.T(), valAddr, PKs[0]) validator, delSharesCreated := validator.AddTokensFromDel(valTokens) require.Equal(stakingtypes.Unbonded, validator.Status) require.Equal(valTokens, validator.Tokens) @@ -231,7 +231,7 @@ func (s *KeeperTestSuite) TestApplyAndReturnValidatorSetUpdatesPowerDecrease() { var validators [2]stakingtypes.Validator for i, power := range powers { - validators[i] = teststaking.NewValidator(s.T(), sdk.ValAddress(PKs[i].Address().Bytes()), PKs[i]) + validators[i] = testutil.NewValidator(s.T(), sdk.ValAddress(PKs[i].Address().Bytes()), PKs[i]) tokens := keeper.TokensFromConsensusPower(ctx, power) validators[i], _ = validators[i].AddTokensFromDel(tokens) @@ -282,8 +282,8 @@ func (s *KeeperTestSuite) TestUpdateValidatorCommission() { ) commission2 := stakingtypes.NewCommission(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(3, 1), sdk.NewDecWithPrec(1, 1)) - val1 := teststaking.NewValidator(s.T(), sdk.ValAddress(PKs[0].Address().Bytes()), PKs[0]) - val2 := teststaking.NewValidator(s.T(), sdk.ValAddress(PKs[1].Address().Bytes()), PKs[1]) + val1 := testutil.NewValidator(s.T(), sdk.ValAddress(PKs[0].Address().Bytes()), PKs[0]) + val2 := testutil.NewValidator(s.T(), sdk.ValAddress(PKs[1].Address().Bytes()), PKs[1]) val1, _ = val1.SetInitialCommission(commission1) val2, _ = val2.SetInitialCommission(commission2) @@ -339,7 +339,7 @@ func (s *KeeperTestSuite) TestValidatorToken() { addTokens := keeper.TokensFromConsensusPower(ctx, 10) delTokens := keeper.TokensFromConsensusPower(ctx, 5) - validator := teststaking.NewValidator(s.T(), valAddr, valPubKey) + validator := testutil.NewValidator(s.T(), valAddr, valPubKey) validator, _ = keeper.AddValidatorTokensAndShares(ctx, validator, addTokens) require.Equal(addTokens, validator.Tokens) validator, _ = keeper.GetValidator(ctx, valAddr) @@ -361,7 +361,7 @@ func (s *KeeperTestSuite) TestUnbondingValidator() { valPubKey := PKs[0] valAddr := sdk.ValAddress(valPubKey.Address().Bytes()) - validator := teststaking.NewValidator(s.T(), valAddr, valPubKey) + validator := testutil.NewValidator(s.T(), valAddr, valPubKey) addTokens := keeper.TokensFromConsensusPower(ctx, 10) // set unbonding validator @@ -375,7 +375,7 @@ func (s *KeeperTestSuite) TestUnbondingValidator() { // add another unbonding validator valAddr1 := sdk.ValAddress(PKs[1].Address().Bytes()) - validator1 := teststaking.NewValidator(s.T(), valAddr1, PKs[1]) + validator1 := testutil.NewValidator(s.T(), valAddr1, PKs[1]) validator1.UnbondingHeight = endHeight validator1.UnbondingTime = endTime keeper.InsertUnbondingValidatorQueue(ctx, validator1) @@ -408,7 +408,7 @@ func (s *KeeperTestSuite) TestUnbondingValidator() { require.False(found) keeper.SetUnbondingValidatorsQueue(ctx, endTime, endHeight, []string{valAddr.String()}) - validator = teststaking.NewValidator(s.T(), valAddr, valPubKey) + validator = testutil.NewValidator(s.T(), valAddr, valPubKey) validator, _ = validator.AddTokensFromDel(addTokens) validator.Status = stakingtypes.Unbonding keeper.SetValidator(ctx, validator) diff --git a/x/staking/migrations/v2/store_test.go b/x/staking/migrations/v2/store_test.go index 488b8343f807..9aabb1e041a0 100644 --- a/x/staking/migrations/v2/store_test.go +++ b/x/staking/migrations/v2/store_test.go @@ -7,24 +7,24 @@ import ( "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/testutil" + sdktestuil "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/staking/migrations/v1" - "github.com/cosmos/cosmos-sdk/x/staking/migrations/v2" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + v1 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v1" + v2 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v2" + "github.com/cosmos/cosmos-sdk/x/staking/testutil" "github.com/cosmos/cosmos-sdk/x/staking/types" ) func TestStoreMigration(t *testing.T) { stakingKey := sdk.NewKVStoreKey("staking") tStakingKey := sdk.NewTransientStoreKey("transient_test") - ctx := testutil.DefaultContext(stakingKey, tStakingKey) + ctx := sdktestuil.DefaultContext(stakingKey, tStakingKey) store := ctx.KVStore(stakingKey) _, pk1, addr1 := testdata.KeyTestPubAddr() valAddr1 := sdk.ValAddress(addr1) - val := teststaking.NewValidator(t, valAddr1, pk1) + val := testutil.NewValidator(t, valAddr1, pk1) _, pk1, addr2 := testdata.KeyTestPubAddr() valAddr2 := sdk.ValAddress(addr2) _, _, addr3 := testdata.KeyTestPubAddr() diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index bf9b4fa2a40c..301ece47d7b0 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -19,12 +19,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking/simulation" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + "github.com/cosmos/cosmos-sdk/x/staking/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil" - "github.com/cosmos/cosmos-sdk/x/staking/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -367,7 +366,7 @@ func (s *SimTestSuite) getTestingValidator(ctx sdk.Context, commission types.Com account := s.accounts[n] valPubKey := account.PubKey valAddr := sdk.ValAddress(account.PubKey.Address().Bytes()) - validator := teststaking.NewValidator(s.T(), valAddr, valPubKey) + validator := testutil.NewValidator(s.T(), valAddr, valPubKey) validator, err := validator.SetInitialCommission(commission) s.Require().NoError(err) diff --git a/x/staking/teststaking/helper.go b/x/staking/testutil/helpers.go similarity index 99% rename from x/staking/teststaking/helper.go rename to x/staking/testutil/helpers.go index f7aaf4c35e81..7aeb9934b6c4 100644 --- a/x/staking/teststaking/helper.go +++ b/x/staking/testutil/helpers.go @@ -1,4 +1,4 @@ -package teststaking +package testutil import ( "context" diff --git a/x/staking/teststaking/tm.go b/x/staking/testutil/tm.go similarity index 98% rename from x/staking/teststaking/tm.go rename to x/staking/testutil/tm.go index 2d1ee1beee89..d856218c28ff 100644 --- a/x/staking/teststaking/tm.go +++ b/x/staking/testutil/tm.go @@ -1,4 +1,4 @@ -package teststaking +package testutil import ( "cosmossdk.io/math" diff --git a/x/staking/teststaking/validator.go b/x/staking/testutil/validator.go similarity index 96% rename from x/staking/teststaking/validator.go rename to x/staking/testutil/validator.go index 71459581f0e6..216d2fa31f44 100644 --- a/x/staking/teststaking/validator.go +++ b/x/staking/testutil/validator.go @@ -1,4 +1,4 @@ -package teststaking +package testutil import ( "testing" diff --git a/x/staking/types/validator_test.go b/x/staking/types/validator_test.go index 8d04a37ac1d3..dfe1eddb1fbe 100644 --- a/x/staking/types/validator_test.go +++ b/x/staking/types/validator_test.go @@ -15,7 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + "github.com/cosmos/cosmos-sdk/x/staking/testutil" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -290,7 +290,7 @@ func TestValidatorsSortTendermint(t *testing.T) { valz := types.Validators(vals) // create expected tendermint validators by converting to tendermint then sorting - expectedVals, err := teststaking.ToTmValidators(valz, sdk.DefaultPowerReduction) + expectedVals, err := testutil.ToTmValidators(valz, sdk.DefaultPowerReduction) require.NoError(t, err) sort.Sort(tmtypes.ValidatorsByVotingPower(expectedVals)) @@ -298,7 +298,7 @@ func TestValidatorsSortTendermint(t *testing.T) { sort.SliceStable(valz, func(i, j int) bool { return types.ValidatorsByVotingPower(valz).Less(i, j, sdk.DefaultPowerReduction) }) - actualVals, err := teststaking.ToTmValidators(valz, sdk.DefaultPowerReduction) + actualVals, err := testutil.ToTmValidators(valz, sdk.DefaultPowerReduction) require.NoError(t, err) require.Equal(t, expectedVals, actualVals, "sorting in SDK is not the same as sorting in Tendermint") @@ -318,7 +318,7 @@ func TestValidatorToTm(t *testing.T) { require.NoError(t, err) expected[i] = tmtypes.NewValidator(tmPk, val.ConsensusPower(sdk.DefaultPowerReduction)) } - vs, err := teststaking.ToTmValidators(vals, sdk.DefaultPowerReduction) + vs, err := testutil.ToTmValidators(vals, sdk.DefaultPowerReduction) require.NoError(t, err) require.Equal(t, expected, vs) }