Skip to content

Commit 412cdcb

Browse files
authored
Merge branch 'main' into evmos/general-ledger-support
2 parents 9d6791f + 518003e commit 412cdcb

File tree

18 files changed

+237
-85
lines changed

18 files changed

+237
-85
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SIMAPP = ./simapp
1212
MOCKS_DIR = $(CURDIR)/tests/mocks
1313
HTTPS_GIT := https://github.com/cosmos/cosmos-sdk.git
1414
DOCKER := $(shell which docker)
15-
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.0.0-rc8
15+
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.7.0
1616
PROJECT_NAME = $(shell git remote get-url origin | xargs basename -s .git)
1717
DOCS_DOMAIN=docs.cosmos.network
1818
# RocksDB is a native dependency, so we don't assume the library is installed.
@@ -389,7 +389,7 @@ devdoc-update:
389389
### Protobuf ###
390390
###############################################################################
391391

392-
protoVer=v0.7
392+
protoVer=v0.8
393393
protoImageName=tendermintdev/sdk-proto-gen:$(protoVer)
394394
containerProtoGen=$(PROJECT_NAME)-proto-gen-$(protoVer)
395395
containerProtoGenAny=$(PROJECT_NAME)-proto-gen-any-$(protoVer)

client/v2/internal/buf.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ deps:
2020
owner: googleapis
2121
repository: googleapis
2222
branch: main
23-
commit: 40f07f5b563941f2b20b991a7aedd53d
23+
commit: 62f35d8aed1149c291d606d958a7ce32

contrib/devtools/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# docker build --pull --rm -f "contrib/devtools/Dockerfile" -t cosmossdk-proto:latest "contrib/devtools"
33
# docker run --rm -v $(pwd):/workspace --workdir /workspace cosmossdk-proto sh ./scripts/protocgen.sh
44

5-
FROM bufbuild/buf:1.1.0 as BUILDER
5+
FROM bufbuild/buf:1.7.0 as BUILDER
66

77
FROM golang:1.19-alpine
88

docs/architecture/adr-059-test-scopes.md

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,28 @@ PROPOSED Partially Implemented
1111
## Abstract
1212

1313
Recent work in the SDK aimed at breaking apart the monolithic root go module has highlighted
14-
shortcomings and inconsistencies in our testing paradigm. This ADR clarifies a common
14+
shortcomings and inconsistencies in our testing paradigm. This ADR clarifies a common
1515
language for talking about test scopes and proposes an ideal state of tests at each scope.
1616

1717
## Context
1818

1919
[ADR-053: Go Module Refactoring](https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-053-go-module-refactoring.md) expresses our desire for an SDK composed of many
2020
independently versioned Go modules, and [ADR-057: App Wiring Part I](https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-057-app-wiring-1.md) offers a methodology
21-
for breaking apart inter-module dependencies through the use of dependency injection. As
21+
for breaking apart inter-module dependencies through the use of dependency injection. As
2222
described in [EPIC: Separate all SDK modules into standalone go modules](https://github.com/cosmos/cosmos-sdk/issues/11899), module
2323
dependencies are particularly complected in the test phase, where simapp is used as
24-
the key test fixture in setting up and running tests. It is clear that the successful
24+
the key test fixture in setting up and running tests. It is clear that the successful
2525
completion of Phases 3 and 4 in that EPIC require the resolution of this dependency problem.
2626

2727
In [EPIC: Unit Testing of Modules via Mocks](https://github.com/cosmos/cosmos-sdk/issues/12398) it was thought this Gordian knot could be
2828
unwound by mocking all dependencies in the test phase for each module, but seeing how these
2929
refactors were complete rewrites of test suites discussions began around the fate of the
30-
existing integration tests. One perspective is that they ought to be thrown out, another is
30+
existing integration tests. One perspective is that they ought to be thrown out, another is
3131
that integration tests have some utility of their own and a place in the SDK's testing story.
3232

3333
Another point of confusion has been the current state of CLI test suites, [x/auth](https://github.com/cosmos/cosmos-sdk/blob/0f7e56c6f9102cda0ca9aba5b6f091dbca976b5a/x/auth/client/testutil/suite.go#L44-L49) for
34-
example. In code these are called integration tests, but in reality function as end to end
35-
tests by starting up a tendermint node and full application. [EPIC: Rewrite and simplify
34+
example. In code these are called integration tests, but in reality function as end to end
35+
tests by starting up a tendermint node and full application. [EPIC: Rewrite and simplify
3636
CLI tests](https://github.com/cosmos/cosmos-sdk/issues/12696) identifies the ideal state of CLI tests using mocks, but does not address the
3737
place end to end tests may have in the SDK.
3838

@@ -43,8 +43,8 @@ ideal state in the SDK.
4343
### Unit tests
4444

4545
Unit tests exercise the code contained in a single module (e.g. `/x/bank`) or package
46-
(e.g. `/client`) in isolation from the rest of the code base. Within this we identify two
47-
levels of unit tests, *illustrative* and *journey*. The definitions below lean heavily on
46+
(e.g. `/client`) in isolation from the rest of the code base. Within this we identify two
47+
levels of unit tests, *illustrative* and *journey*. The definitions below lean heavily on
4848
[The BDD Books - Formulation](https://leanpub.com/bddbooks-formulation) section 1.3.
4949

5050
*Illustrative* tests exercise an atomic part of a module in isolation - in this case we
@@ -65,11 +65,11 @@ supplied to the keeper constructor.
6565

6666
#### Limitations
6767

68-
Certain modules are tightly coupled beyond the test phase. A recent dependency report for
68+
Certain modules are tightly coupled beyond the test phase. A recent dependency report for
6969
`bank -> auth` found 274 total usages of `auth` in `bank`, 50 of which are in
70-
production code and 224 in test. This tight coupling may suggest that either the modules
70+
production code and 224 in test. This tight coupling may suggest that either the modules
7171
should be merged, or refactoring is required to abstract references to the core types tying
72-
the modules together. It could also indicate that these modules should be tested together
72+
the modules together. It could also indicate that these modules should be tested together
7373
in integration tests beyond mocked unit tests.
7474

7575
In some cases setting up a test case for a module with many mocked dependencies can be quite
@@ -82,18 +82,18 @@ Integration tests define and exercise relationships between an arbitrary number
8282
and/or application subsystems.
8383

8484
Wiring for integration tests is provided by `depinject` and some [helper code](https://github.com/cosmos/cosmos-sdk/blob/2bec9d2021918650d3938c3ab242f84289daef80/testutil/sims/app_helpers.go#L95) starts up
85-
a running application. A section of the running application may then be tested. Certain
85+
a running application. A section of the running application may then be tested. Certain
8686
inputs during different phases of the application life cycle are expected to produce
87-
invariant outputs without too much concern for component internals. This type of black box
87+
invariant outputs without too much concern for component internals. This type of black box
8888
testing has a larger scope than unit testing.
8989

9090
Example 1 [client/grpc_query_test/TestGRPCQuery](https://github.com/cosmos/cosmos-sdk/blob/2bec9d2021918650d3938c3ab242f84289daef80/client/grpc_query_test.go#L111-L129) - This test is misplaced in `/client`,
9191
but tests the life cycle of (at least) `runtime` and `bank` as they progress through
92-
startup, genesis and query time. It also exercises the fitness of the client and query
92+
startup, genesis and query time. It also exercises the fitness of the client and query
9393
server without putting bytes on the wire through the use of [QueryServiceTestHelper](https://github.com/cosmos/cosmos-sdk/blob/2bec9d2021918650d3938c3ab242f84289daef80/baseapp/grpcrouter_helpers.go#L31).
9494

9595
Example 2 `x/evidence` Keeper integration tests - Starts up an application composed of [8
96-
modules](https://github.com/cosmos/cosmos-sdk/blob/2bec9d2021918650d3938c3ab242f84289daef80/x/evidence/testutil/app.yaml#L1) with [5 keepers](https://github.com/cosmos/cosmos-sdk/blob/2bec9d2021918650d3938c3ab242f84289daef80/x/evidence/keeper/keeper_test.go#L101-L106) used in the integration test suite. One test in the suite
96+
modules](https://github.com/cosmos/cosmos-sdk/blob/2bec9d2021918650d3938c3ab242f84289daef80/x/evidence/testutil/app.yaml#L1) with [5 keepers](https://github.com/cosmos/cosmos-sdk/blob/2bec9d2021918650d3938c3ab242f84289daef80/x/evidence/keeper/keeper_test.go#L101-L106) used in the integration test suite. One test in the suite
9797
exercises [HandleEquivocationEvidence](https://github.com/cosmos/cosmos-sdk/blob/2bec9d2021918650d3938c3ab242f84289daef80/x/evidence/keeper/infraction_test.go#L42) which contains many interactions with the staking
9898
keeper.
9999

@@ -103,49 +103,49 @@ YAML as above) [statically](https://github.com/cosmos/cosmos-sdk/blob/main/x/nft
103103
#### Limitations
104104

105105
Setting up a particular input state may be more challenging since the application is
106-
starting from a zero state. Some of this may be addressed by good test fixture
107-
abstractions with testing of their own. Tests may also be more brittle, and larger
106+
starting from a zero state. Some of this may be addressed by good test fixture
107+
abstractions with testing of their own. Tests may also be more brittle, and larger
108108
refactors could impact application initialization in unexpected ways with harder to
109-
understand errors. This could also be seen as a benefit, and indeed the SDK's current
109+
understand errors. This could also be seen as a benefit, and indeed the SDK's current
110110
integration tests were helpful in tracking down logic errors during earlier stages
111111
of app-wiring refactors.
112112

113113
### Simulations
114114

115115
Simulations (also called generative testing) are a special case of integration tests where
116116
deterministically random module operations are executed against a running simapp, building
117-
blocks on the chain until a specified height is reached. No *specific* assertions are
117+
blocks on the chain until a specified height is reached. No *specific* assertions are
118118
made for the state transitions resulting from module operations but any error will halt and
119-
fail the simulation. Since `crisis` is included in simapp and the simulation runs
119+
fail the simulation. Since `crisis` is included in simapp and the simulation runs
120120
EndBlockers at the end of each block any module invariant violations will also fail
121121
the simulation.
122122

123123
Modules must implement [AppModuleSimulation.WeightedOperations](https://github.com/cosmos/cosmos-sdk/blob/2bec9d2021918650d3938c3ab242f84289daef80/types/module/simulation.go#L31) to define their
124-
simulation operations. Note that not all modules implement this which may indicate a
124+
simulation operations. Note that not all modules implement this which may indicate a
125125
gap in current simulation test coverage.
126126

127-
Modules not returning simulation operations:
127+
Modules not returning simulation operations:
128128

129-
- `auth`
130-
- `capability`
131-
- `evidence`
132-
- `mint`
133-
- `params`
129+
* `auth`
130+
* `capability`
131+
* `evidence`
132+
* `mint`
133+
* `params`
134134

135135
A separate binary, [runsim](https://github.com/cosmos/tools/tree/master/cmd/runsim), is responsible for kicking off some of these tests and
136136
managing their life cycle.
137137

138138
#### Limitations
139139

140-
- [A success](https://github.com/cosmos/cosmos-sdk/runs/7606931983?check_suite_focus=true) may take a long time to run, 7-10 minutes per simulation in CI.
141-
- [Timeouts](https://github.com/cosmos/cosmos-sdk/runs/7606932295?check_suite_focus=true) sometimes occur on apparent successes without any indication why.
142-
- Useful error messages not provided on [failure](https://github.com/cosmos/cosmos-sdk/runs/7606932548?check_suite_focus=true) from CI, requiring a developer to run
140+
* [A success](https://github.com/cosmos/cosmos-sdk/runs/7606931983?check_suite_focus=true) may take a long time to run, 7-10 minutes per simulation in CI.
141+
* [Timeouts](https://github.com/cosmos/cosmos-sdk/runs/7606932295?check_suite_focus=true) sometimes occur on apparent successes without any indication why.
142+
* Useful error messages not provided on [failure](https://github.com/cosmos/cosmos-sdk/runs/7606932548?check_suite_focus=true) from CI, requiring a developer to run
143143
the simulation locally to reproduce.
144144

145145
### E2E tests
146146

147147
End to end tests exercise the entire system as we understand it in as close an approximation
148-
to a production environment as is practical. Presently these tests are located at
148+
to a production environment as is practical. Presently these tests are located at
149149
[tests/e2e](https://github.com/cosmos/cosmos-sdk/tree/main/tests/e2e) and rely on [testutil/network](https://github.com/cosmos/cosmos-sdk/tree/main/testutil/network) to start up an in-process Tendermint node.
150150

151151
#### Limitations
@@ -164,13 +164,13 @@ The scope of e2e tests has been complected with command line interface testing.
164164
We accept these test scopes and identify the following decisions points for each.
165165

166166
| Scope | App Fixture | Mocks? |
167-
|-------------|-------------|--------|
167+
| ----------- | ----------- | ------ |
168168
| Unit | None | Yes |
169169
| Integration | depinject | Some |
170-
| Simulation | simapp | No |
170+
| Simulation | depinject | No |
171171
| E2E | simapp | No |
172172

173-
#### Unit Tests
173+
### Unit Tests
174174

175175
All modules must have mocked unit test coverage.
176176

@@ -185,11 +185,11 @@ production code.
185185

186186
When module unit test introduction as per [EPIC: Unit testing of modules via mocks](https://github.com/cosmos/cosmos-sdk/issues/12398)
187187
results in a near complete rewrite of an integration test suite the test suite should be
188-
retained and moved to `/tests/integration`. We accept the resulting test logic
188+
retained and moved to `/tests/integration`. We accept the resulting test logic
189189
duplication but recommend improving the unit test suite through the addition of
190190
illustrative tests.
191191

192-
#### Integration Tests
192+
### Integration Tests
193193

194194
All integration tests shall be located in `/tests/integration`, even those which do not
195195
introduce extra module dependencies.
@@ -199,11 +199,11 @@ modules in application startup, i.e. don't depend on simapp.
199199

200200
Integration tests should outnumber e2e tests.
201201

202-
#### Simulations
202+
### Simulations
203203

204-
Simulations shall startup and test simapp directly.
204+
Simulations shall use `depinject`. They are located under `/x/{moduleName}/simulation`.
205205

206-
#### E2E Tests
206+
### E2E Tests
207207

208208
Existing e2e tests shall be migrated to integration tests by removing the dependency on the
209209
test network and in-process Tendermint node to ensure we do not lose test coverage.
@@ -220,31 +220,31 @@ demonstrated in [PR#12706](https://github.com/cosmos/cosmos-sdk/pull/12706).
220220

221221
### Positive
222222

223-
- test coverage is increased
224-
- test organization is improved
225-
- reduced dependency graph size in modules
226-
- simapp removed as a dependency from modules
227-
- inter-module dependencies introduced in test code are removed
228-
- reduced CI run time after transitioning away from in process Tendermint
223+
* test coverage is increased
224+
* test organization is improved
225+
* reduced dependency graph size in modules
226+
* simapp removed as a dependency from modules
227+
* inter-module dependencies introduced in test code are removed
228+
* reduced CI run time after transitioning away from in process Tendermint
229229

230230
### Negative
231231

232-
- some test logic duplication between unit and integration tests during transition
233-
- test written using dockertest DX may be a bit worse
232+
* some test logic duplication between unit and integration tests during transition
233+
* test written using dockertest DX may be a bit worse
234234

235235
### Neutral
236236

237-
- learning curve for BDD style tests
238-
- some discovery required for e2e transition to dockertest
237+
* learning curve for BDD style tests
238+
* some discovery required for e2e transition to dockertest
239239

240240
## Further Discussions
241241

242242
It may be useful if test suites could be run in integration mode (with mocked tendermint) or
243243
with e2e fixtures (with real tendermint and many nodes). Integration fixtures could be used
244244
for quicker runs, e2e fixures could be used for more battle hardening.
245245

246-
A PoC `x/gov` was completed in PR [#12847](https://github.com/cosmos/cosmos-sdk/pull/12847)
247-
is in progress for unit tests demonstrating BDD.
246+
A PoC `x/gov` was completed in PR [#12847](https://github.com/cosmos/cosmos-sdk/pull/12847)
247+
is in progress for unit tests demonstrating BDD [Rejected].
248248
Observing that a strength of BDD specifications is their readability, and a con is the
249249
cognitive load while writing and maintaining, current consensus is to reserve BDD use
250250
for places in the SDK where complex rules and module interactions are demonstrated.

docs/building-chain/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!--
2+
order: false
3+
parent:
4+
order: 5
5+
-->
6+
7+
# Building a Chain
8+
9+
This repository contains documentation on concepts developers need to know in order to build a Cosmos SDK applications.
10+
11+
1. [Overview of `app.go` and how to wire it up](./app-go.md)
12+
2. [Dependency Injection in the SDK](./depinject.md)

docs/building-chain/app-go.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!--
2+
order: 0
3+
-->
4+
5+
# Overview of `app.go` and how to wire it up
6+
7+
This section is intended to provide an overview of the `app.go` file and is still a work in progress.
8+
For now we invite you to read the [tutorials](https://tutorials.cosmos.network) for a deep dive on how to build a chain.
9+
10+
<!--
11+
12+
## `app.go`
13+
14+
Since `v0.47.0` the Cosmos SDK have made easier wiring an `app.go` thanks to dependency injection:
15+
16+
+++ https://github.com/cosmos/cosmos-sdk/blob/main/simapp/app_config.go
17+
18+
+++ https://github.com/cosmos/cosmos-sdk/blob/main/simapp/app.go
19+
20+
## `app_legacy.go`
21+
22+
+++ https://github.com/cosmos/cosmos-sdk/blob/main/simapp/app_legacy.go
23+
24+
-->

docs/building-chain/depinject.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!--
2+
order: 1
3+
-->
4+
5+
# Dependency Injection
6+
7+
This section is intended to provide an overview of the `depinject` package and is still a work in progress.
8+
The SDK uses a dependency injection framework called `depinject` for helping building a chain faster.
9+
10+
## `AppConfig`
11+
12+
* https://pkg.go.dev/cosmossdk.io/core/appconfig
13+
14+
15+
## `depinject`
16+
17+
* https://pkg.go.dev/cosmossdk.io/depinject

docs/building-modules/simulator.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<!--
2+
order: 14
3+
-->
4+
15
# Module Simulation
26

37
## Prerequisites

0 commit comments

Comments
 (0)