Skip to content

Commit

Permalink
refactor(bank): add go module (#18279)
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Oct 27, 2023
1 parent ab2a725 commit 21e69ba
Show file tree
Hide file tree
Showing 214 changed files with 2,367 additions and 828 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1129,3 +1129,34 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: x/authz/

test-x-bank:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: "1.21"
check-latest: true
cache: true
cache-dependency-path: x/bank/go.sum
- uses: technote-space/get-diff-action@v6.1.2
id: git_diff
with:
PATTERNS: |
x/bank/**/*.go
x/bank/go.mod
x/bank/go.sum
- name: tests
if: env.GIT_DIFF
run: |
cd x/bank
go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb_build' ./...
- name: sonarcloud
if: ${{ env.GIT_DIFF && !github.event.pull_request.draft && env.SONAR_TOKEN != null }}
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: x/bank/
20 changes: 13 additions & 7 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,29 @@ Most of Cosmos SDK modules have migrated to [collections](https://docs.cosmos.ne
Many functions have been removed due to this changes as the API can be smaller thanks to collections.
For modules that have migrated, verify you are checking against `collections.ErrNotFound` when applicable.

#### `x/group`
#### `x/authz`

Group was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/group`
Authz was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/authz`

#### `x/gov`
#### `x/bank`

Gov was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/gov`
Bank was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/bank`

#### `x/distribution`

Distribution was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/distribution`

The existing chains using x/distribution module needs to add the new x/protocolpool module.

#### `x/group`

Group was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/group`

#### `x/gov`

Gov was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/gov`


#### `x/slashing`

Slashing was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/slashing`
Expand All @@ -80,9 +89,6 @@ Slashing was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/sl

Staking was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/staking`

#### `x/authz`

Authz was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/authz`

#### `x/params`

Expand Down
7 changes: 3 additions & 4 deletions api/cosmos/bank/module/v1/module.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions baseapp/block_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"cosmossdk.io/log"
sdkmath "cosmossdk.io/math"
store "cosmossdk.io/store/types"
bankkeeper "cosmossdk.io/x/bank/keeper"
banktypes "cosmossdk.io/x/bank/types"

baseapptestutil "github.com/cosmos/cosmos-sdk/baseapp/testutil"
"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -31,8 +33,6 @@ import (
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
)

Expand Down
4 changes: 2 additions & 2 deletions baseapp/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"
_ "cosmossdk.io/x/bank"
banktypes "cosmossdk.io/x/bank/types"
_ "cosmossdk.io/x/staking"

"github.com/cosmos/cosmos-sdk/baseapp"
Expand All @@ -46,8 +48,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/signing"
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
_ "github.com/cosmos/cosmos-sdk/x/bank"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
_ "github.com/cosmos/cosmos-sdk/x/consensus"
_ "github.com/cosmos/cosmos-sdk/x/mint"
)
Expand Down
3 changes: 2 additions & 1 deletion client/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"

"cosmossdk.io/x/bank/types"

"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank/types"
)

type fuzzSuite struct {
Expand Down
4 changes: 2 additions & 2 deletions client/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"cosmossdk.io/depinject"
"cosmossdk.io/log"
"cosmossdk.io/math"
bankkeeper "cosmossdk.io/x/bank/keeper"
"cosmossdk.io/x/bank/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -25,8 +27,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/testutil"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/cosmos/cosmos-sdk/x/bank/types"
)

type IntegrationTestSuite struct {
Expand Down
3 changes: 2 additions & 1 deletion client/rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"

banktypes "cosmossdk.io/x/bank/types"

"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/types/address"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)

type IntegrationTestSuite struct {
Expand Down
3 changes: 2 additions & 1 deletion client/tx/aux_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"github.com/stretchr/testify/require"

"cosmossdk.io/x/bank"

"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand All @@ -14,7 +16,6 @@ import (
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
typestx "github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/bank"
)

func TestAuxTxBuilder(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion client/tx/legacy_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package tx_test

import (
banktypes "cosmossdk.io/x/bank/types"

"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion client/tx/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/grpc"

banktypes "cosmossdk.io/x/bank/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -24,7 +26,6 @@ import (
ante "github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)

func newTestTxConfig() (client.TxConfig, codec.Codec) {
Expand Down
4 changes: 2 additions & 2 deletions client/v2/autocli/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import (
reflectionv2alpha1 "cosmossdk.io/api/cosmos/base/reflection/v2alpha1"
"cosmossdk.io/client/v2/autocli/flag"
"cosmossdk.io/client/v2/internal/testpb"
"cosmossdk.io/x/bank"
banktypes "cosmossdk.io/x/bank/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
sdkkeyring "github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/bank"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)

type fixture struct {
Expand Down
15 changes: 8 additions & 7 deletions client/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
cosmossdk.io/api v0.7.2
cosmossdk.io/core v0.12.0
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/x/bank v0.0.0-00010101000000-000000000000
cosmossdk.io/x/tx v0.11.0
github.com/cockroachdb/errors v1.11.1
github.com/cosmos/cosmos-proto v1.0.0-beta.3
Expand Down Expand Up @@ -158,10 +159,10 @@ require (

replace github.com/cosmos/cosmos-sdk => ./../../

replace cosmossdk.io/x/gov => ./../../x/gov

replace cosmossdk.io/x/distribution => ./../../x/distribution

replace cosmossdk.io/x/slashing => ./../../x/slashing

replace cosmossdk.io/x/staking => ./../../x/staking
replace (
cosmossdk.io/x/bank => ./../../x/bank
cosmossdk.io/x/distribution => ./../../x/distribution
cosmossdk.io/x/gov => ./../../x/gov
cosmossdk.io/x/slashing => ./../../x/slashing
cosmossdk.io/x/staking => ./../../x/staking
)
2 changes: 1 addition & 1 deletion codec/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
"google.golang.org/protobuf/types/dynamicpb"

bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1"
banktypes "cosmossdk.io/x/bank/types"

codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)

type bankSendWrapper struct {
Expand Down
2 changes: 1 addition & 1 deletion codec/proto_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import (
bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1"
basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1"
sdkmath "cosmossdk.io/math"
banktypes "cosmossdk.io/x/bank/types"
"cosmossdk.io/x/tx/signing"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)

func createTestInterfaceRegistry() types.InterfaceRegistry {
Expand Down
1 change: 1 addition & 0 deletions contrib/images/simd-env/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ COPY x/distribution/go.mod x/distribution/go.sum /work/x/distribution/
COPY x/slashing/go.mod x/slashing/go.sum /work/x/slashing/
COPY x/staking/go.mod x/staking/go.sum /work/x/staking/
COPY x/authz/go.mod x/authz/go.sum /work/x/authz/
COPY x/bank/go.mod x/bank/go.sum /work/x/bank/
RUN go mod download

COPY ./ /work
Expand Down
2 changes: 1 addition & 1 deletion depinject/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Provider functions serve as the basis for the dependency tree. They are analysed

`depinject` supports the use of interface types as inputs to provider functions, which helps decouple dependencies between modules. This approach is particularly useful for managing complex systems with multiple modules, such as the Cosmos SDK, where dependencies need to be flexible and maintainable.

For example, `x/bank` expects an [AccountKeeper](https://pkg.go.dev/github.com/cosmos/cosmos-sdk/x/bank/types#AccountKeeper) interface as [input to ProvideModule](https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/x/bank/module.go#L208-L260). `SimApp` uses the implementation in `x/auth`, but the modular design allows for easy changes to the implementation if needed.
For example, `x/bank` expects an [AccountKeeper](https://pkg.go.dev/cosmossdk.io/x/bank/types#AccountKeeper) interface as [input to ProvideModule](https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/x/bank/module.go#L208-L260). `SimApp` uses the implementation in `x/auth`, but the modular design allows for easy changes to the implementation if needed.

Consider the following example:

Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/adr-057-app-wiring.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ import (
// Each go package which registers a module must be imported just for side-effects
// so that module implementations are registered.
_ "github.com/cosmos/cosmos-sdk/x/auth/module"
_ "github.com/cosmos/cosmos-sdk/x/bank/module"
_ "cosmossdk.io/x/bank/module"
_ "cosmossdk.io/x/staking/module"
"github.com/cosmos/cosmos-sdk/core/app"
)
Expand Down
4 changes: 2 additions & 2 deletions docs/user/run-node/02-interact-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
banktypes "cosmossdk.io/x/bank/types"
)

func queryState() error {
Expand Down Expand Up @@ -194,7 +194,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
banktypes "cosmossdk.io/x/bank/types"
)

func queryState() error {
Expand Down
2 changes: 1 addition & 1 deletion docs/user/run-node/03-txs.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/client/tx_config.go#L3

```go
import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
banktypes "cosmossdk.io/x/bank/types"
)

func sendTx() error {
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
cosmossdk.io/log v1.2.1
cosmossdk.io/math v1.1.3-rc.1
cosmossdk.io/store v1.0.0-rc.0
cosmossdk.io/x/bank v0.0.0-00010101000000-000000000000
cosmossdk.io/x/distribution v0.0.0-20230925135524-a1bc045b3190
cosmossdk.io/x/gov v0.0.0-20230925135524-a1bc045b3190
cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000
Expand Down Expand Up @@ -169,15 +170,14 @@ require (
// )
// TODO remove after all modules have their own go.mods
replace (
cosmossdk.io/x/bank => ./x/bank
cosmossdk.io/x/distribution => ./x/distribution
cosmossdk.io/x/gov => ./x/gov
cosmossdk.io/x/protocolpool => ./x/protocolpool
cosmossdk.io/x/slashing => ./x/slashing
cosmossdk.io/x/staking => ./x/staking
)

replace cosmossdk.io/x/gov => ./x/gov

replace cosmossdk.io/x/distribution => ./x/distribution

// Below are the long-lived replace of the Cosmos SDK
replace (
// use cosmos fork of keyring
Expand Down
1 change: 1 addition & 0 deletions go.work.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use (
./tools/hubl
./x/accounts
./x/authz
./x/bank
./x/circuit
./x/distribution
./x/evidence
Expand Down

0 comments on commit 21e69ba

Please sign in to comment.