Go to file
Mark Rushakoff e7097b1468
test: add cmdtest package (#15251)
## Description

This PR introduces the `cmdtest` package, offering a lightweight wrapper around cobra commands to simplify testing CLI utilities.

I backfilled tests for the `version` command, which was an example of a very simple test setup; and for the `export` command, which was more involved due to the server and client context requirements.

I did notice that there are some existing tests for some utilities, but the `cmdtest` package follows a simple pattern that has been easy to use successfully in [the relayer](https://github.com/cosmos/relayer/blob/main/internal/relayertest/system.go) and in other projects outside the Cosmos ecosystem.

While filling in these tests, I started removing uses of `cmd.Print`, as that is the root cause of issues like #8498, #7964, #15167, and possibly others. Internal to cobra, the print family of methods write to `cmd.OutOrStderr()` -- meaning that if the authors call `cmd.SetOutput()` before executing the command, the output will be written to stdout as expected; otherwise it will go to stderr. I don't understand why that would be the default behavior, but it is probably too late to change from cobra's side.

Instead of `cmd.Print`, we prefer to `fmt.Fprint(cmd.OutOrStdout())` or `fmt.Fprint(cmd.ErrOrStderr())` as appropriate, giving an unambiguous destination for output. And the new tests collect those outputs in plain `bytes.Buffer` values so that we can assert their content appropriately.

In the longer term, I would like to deprecate and eventually remove the `testutil` package's `ApplyMockIO` method and its `BufferWriter` and `BufferReader` types, as they are unnecessary indirection when a simpler solution exists. But that can wait until `cmdtest` has propagated through the codebase more.

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] ~~provided a link to the relevant issue or specification~~
- [x] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed all author checklist items have been addressed
- [ ] confirmed that this PR does not change production code
2023-03-06 19:40:24 +00:00
.github build(deps): Bump bufbuild/buf-setup-action from 1.14.0 to 1.15.0 (#15225) 2023-03-01 17:11:11 +00:00
.vscode feat: add vscode e2e config (#13851) 2022-11-14 11:26:28 +01:00
api chore: make proto-gen due to dep update (#15268) 2023-03-06 10:54:50 +01:00
baseapp refactor(log): associate test logger with testing.T instance (#15261) 2023-03-03 20:26:45 +00:00
client refactor(log): require destination in calls to NewLogger (#15262) 2023-03-06 19:05:49 +00:00
codec refactor(collections): move codecs to separate package and add int keys. (#15001) 2023-02-19 13:06:53 +00:00
collections feat(collections): add NewSchemaBuilderFromAccessor function (#15271) 2023-03-06 17:07:17 +00:00
contrib refactor(x/tx): Move textual,aminojson to signing (#15278) 2023-03-06 18:17:24 +00:00
core build(deps): Bump github.com/prometheus/common from 0.40.0 to 0.41.0 (#15229) 2023-03-01 17:59:14 +00:00
crypto fix(crypto/keyring): disallow non-owner reads of keyhash (#15258) 2023-03-03 16:25:22 +00:00
depinject chore: bump cometbft to v0.37.0-rc3 (#15220) 2023-03-01 16:30:41 +01:00
docs docs: add swagger ui in docs (#15241) 2023-03-02 12:40:26 +00:00
errors chore: bump cometbft to v0.37.0-rc3 (#15220) 2023-03-01 16:30:41 +01:00
fuzz chore: use sdkmath in misc packages (#14606) 2023-01-16 12:48:32 +00:00
internal refactor: create go.mod for store (#14746) 2023-01-25 13:31:56 +00:00
log refactor(log): require destination in calls to NewLogger (#15262) 2023-03-06 19:05:49 +00:00
math chore: bump cometbft to v0.37.0-rc3 (#15220) 2023-03-01 16:30:41 +01:00
orm refactor(log): require destination in calls to NewLogger (#15262) 2023-03-06 19:05:49 +00:00
proto chore: improve UGPRADING.md (#15236) 2023-03-02 11:43:19 +01:00
runtime feat: Implement RegisterServices for CoreAPI in module manager (#15133) 2023-03-02 14:22:20 -03:00
scripts feat!: use cosmossdk.io/log logger (#15011) 2023-02-27 21:36:22 +00:00
server test: add cmdtest package (#15251) 2023-03-06 19:40:24 +00:00
simapp refactor(log): require destination in calls to NewLogger (#15262) 2023-03-06 19:05:49 +00:00
std fix: register evidence regression (#10595) 2021-12-14 14:25:31 +00:00
store refactor(log): require destination in calls to NewLogger (#15262) 2023-03-06 19:05:49 +00:00
telemetry fix: all: fix resource leaks found by staticmajor (#13394) 2022-10-06 20:11:40 +00:00
tests refactor(log): require destination in calls to NewLogger (#15262) 2023-03-06 19:05:49 +00:00
testutil test: add cmdtest package (#15251) 2023-03-06 19:40:24 +00:00
tools refactor(log): require destination in calls to NewLogger (#15262) 2023-03-06 19:05:49 +00:00
types feat: Implement RegisterServices for CoreAPI in module manager (#15133) 2023-03-02 14:22:20 -03:00
version test: add cmdtest package (#15251) 2023-03-06 19:40:24 +00:00
x refactor(log): require destination in calls to NewLogger (#15262) 2023-03-06 19:05:49 +00:00
.clang-format chore: improve proto formatting (#12656) 2022-07-21 10:56:31 +00:00
.dockerignore Add basic Dockerfile to build all binaries and export gaiad 2018-04-10 12:39:47 +02:00
.gitattributes Merge PR #6426: Migrate API Server 2020-06-15 13:39:09 -04:00
.gitignore feat(depinject): send logging to file instead of stderr (#14825) 2023-01-27 21:10:55 +01:00
.gitpod.yml Create .gitpod.yml (#12662) 2022-08-15 15:18:30 +02:00
.golangci.yml fix: correct path required proto testdata (#14991) 2023-02-11 16:59:16 +00:00
.goreleaser.yml ci: fix release notes not populated by goreleaser 2022-08-13 20:41:27 +02:00
.markdownlint.json docs: Code blocks in SDK docs are broken (#11189) 2022-02-14 23:39:35 +01:00
.markdownlintignore docs: Improve markdownlint configuration (#11104) 2022-02-10 12:07:01 +00:00
.mergify.yml chore: update .mergify.yml #13841 2022-11-11 18:49:36 +00:00
buf.work.yaml refactor: migrate to cosmos/gogoproto (#13070) 2022-09-08 17:27:48 +00:00
CHANGELOG.md feat(x/bank): update keeper interface to include GetAllDenomMetaData (#15265) 2023-03-05 20:22:24 +00:00
CODE_OF_CONDUCT.md Update CODE_OF_CONDUCT.md (#7381) 2020-09-28 11:28:30 +02:00
CODING_GUIDELINES.md feat: migrate to docusaurus (#13471) 2022-10-10 14:01:53 +00:00
CONTRIBUTING.md docs: set buf commit for v0.47.x (#14675) 2023-01-20 12:43:53 +00:00
docker-compose.yml build: add remote debugging with delve (#10587) 2021-12-01 12:44:54 +00:00
Dockerfile build(deps): bump Go to v1.20 on SDK, simapp and standalone modules (#14979) 2023-02-09 11:56:07 -05:00
go.mod refactor(log): require destination in calls to NewLogger (#15262) 2023-03-06 19:05:49 +00:00
go.sum refactor(log): require destination in calls to NewLogger (#15262) 2023-03-06 19:05:49 +00:00
go.work.example build(deps): bump Go to v1.20 on SDK, simapp and standalone modules (#14979) 2023-02-09 11:56:07 -05:00
LICENSE chore: update license copyright (#12542) 2022-07-13 10:19:10 +00:00
Makefile chore: bump cometbft to v0.37.0-rc3 (#15220) 2023-03-01 16:30:41 +01:00
README.md build(deps): bump Go to v1.20 on SDK, simapp and standalone modules (#14979) 2023-02-09 11:56:07 -05:00
RELEASE_PROCESS.md docs: update tasks list for release branch (#15025) 2023-02-14 05:40:47 -08:00
ROADMAP.md chore: update roadmap with completed items (#15263) 2023-03-05 00:29:47 +01:00
SECURITY.md refactor!: migrate Cosmos SDK to CometBFT (#14897) 2023-02-05 14:51:33 +01:00
sonar-project.properties ci: make sonarcloud more quiet (#14585) 2023-01-12 10:24:56 +00:00
UPGRADING.md chore: improve UGPRADING.md (#15236) 2023-03-02 11:43:19 +01:00

Cosmos SDK

banner

The Cosmos SDK is a framework for building blockchain applications. CometBFT (BFT Consensus) and the Cosmos SDK are written in the Go programming language. Cosmos SDK is used to build Gaia, the implementation of the Cosmos Hub.

WARNING: The Cosmos SDK has mostly stabilized, but we are still making some breaking changes.

Note: Requires Go 1.20+

Quick Start

To learn how the Cosmos SDK works from a high-level perspective, see the Cosmos SDK High-Level Intro.

If you want to get started quickly and learn how to build on top of Cosmos SDK, visit Cosmos SDK Tutorials. You can also fork the tutorial's repository to get started building your own Cosmos SDK application.

For more information, see the Cosmos SDK Documentation.

Contributing

See CONTRIBUTING.md for details on how to contribute and participate in our dev calls. If you want to follow the updates or learn more about the latest design then join our Discord.

Tools and Frameworks

The Cosmos ecosystem is vast. Awesome Cosmos is a community-curated list of notable frameworks, modules and tools.

Cosmos Hub Mainnet

The Cosmos Hub application, gaia, has its own cosmos/gaia repository. Go there to join the Cosmos Hub mainnet and more.

Inter-Blockchain Communication (IBC)

The IBC module for the Cosmos SDK has its own cosmos/ibc-go repository. Go there to build and integrate with the IBC module.

Ignite CLI

Ignite CLI is the all-in-one platform to build, launch, and maintain any crypto application on a sovereign and secured blockchain. If you are building a new app or a new module, use Ignite CLI to get started and speed up development.

Disambiguation

This Cosmos SDK project is not related to the React-Cosmos project (yet). Many thanks to Evan Coury and Ovidiu (@skidding) for this Github organization name. As per our agreement, this disambiguation notice will stay here.