Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use api module #19825

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions x/accounts/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (

"github.com/cosmos/gogoproto/types"

bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1"
"cosmossdk.io/collections"
"cosmossdk.io/math"
"cosmossdk.io/x/accounts/accountstd"
"cosmossdk.io/x/accounts/internal/implementation"
banktypes "cosmossdk.io/x/bank/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand All @@ -30,7 +30,7 @@ type TestAccount struct {
func (t TestAccount) RegisterInitHandler(builder *implementation.InitBuilder) {
implementation.RegisterInitHandler(builder, func(ctx context.Context, _ *types.Empty) (*types.Empty, error) {
// we also force a module call here to test things work as expected.
_, err := implementation.QueryModule[banktypes.QueryBalanceResponse](ctx, &banktypes.QueryBalanceRequest{
_, err := implementation.QueryModule[bankv1beta1.QueryBalanceResponse](ctx, &bankv1beta1.QueryBalanceRequest{
Address: string(implementation.Whoami(ctx)),
Denom: "atom",
})
Expand All @@ -54,7 +54,7 @@ func (t TestAccount) RegisterExecuteHandlers(builder *implementation.ExecuteBuil

// this is for intermodule comms testing, we simulate a bank send
implementation.RegisterExecuteHandler(builder, func(ctx context.Context, req *types.Int64Value) (*types.Empty, error) {
resp, err := implementation.ExecModule[banktypes.MsgSendResponse](ctx, &banktypes.MsgSend{
resp, err := implementation.ExecModule[bankv1beta1.MsgSendResponse](ctx, &bankv1beta1.MsgSend{
FromAddress: string(implementation.Whoami(ctx)),
ToAddress: "recipient",
Amount: []sdk.Coin{
Expand Down Expand Up @@ -92,7 +92,7 @@ func (t TestAccount) RegisterQueryHandlers(builder *implementation.QueryBuilder)
// test intermodule comms, we simulate someone is sending the account a request for the accounts balance
// of a given denom.
implementation.RegisterQueryHandler(builder, func(ctx context.Context, req *types.StringValue) (*types.Int64Value, error) {
resp, err := implementation.QueryModule[banktypes.QueryBalanceResponse](ctx, &banktypes.QueryBalanceRequest{
resp, err := implementation.QueryModule[bankv1beta1.QueryBalanceResponse](ctx, &bankv1beta1.QueryBalanceRequest{
Address: string(implementation.Whoami(ctx)),
Denom: req.Value,
})
Expand Down
6 changes: 3 additions & 3 deletions x/accounts/coin_transfer.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package accounts

import (
bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1"
"cosmossdk.io/core/address"
"cosmossdk.io/x/accounts/internal/implementation"
banktypes "cosmossdk.io/x/bank/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand All @@ -24,10 +24,10 @@ func defaultCoinsTransferMsgFunc(addrCdc address.Codec) coinsTransferMsgFunc {
return nil, nil, err
}

return &banktypes.MsgSend{
return &bankv1beta1.MsgSend{
FromAddress: fromAddr,
ToAddress: toAddr,
Amount: coins,
}, new(banktypes.MsgSendResponse), nil
}, new(bankv1beta1.MsgSendResponse), nil
}
}
3 changes: 1 addition & 2 deletions x/accounts/defaults/lockup/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ require (
cosmossdk.io/core v0.12.1-0.20231114100755-569e3ff6a0d7
cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91
cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91
cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000
github.com/cosmos/cosmos-sdk v0.51.0
github.com/cosmos/gogoproto v1.4.11
)

require (
cosmossdk.io/api v0.7.3 // indirect
cosmossdk.io/api v0.7.3
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
Expand Down
23 changes: 16 additions & 7 deletions x/accounts/defaults/lockup/protov2_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package lockup
import (
"github.com/cosmos/gogoproto/proto"

banktypes "cosmossdk.io/x/bank/types"
stakingtypes "cosmossdk.io/x/staking/types"
bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1"
v1beta1 "cosmossdk.io/api/cosmos/base/v1beta1"
stakingv1beta1 "cosmossdk.io/api/cosmos/staking/v1beta1"

sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand All @@ -14,25 +15,33 @@ import (
type ProtoMsg = proto.Message

func makeMsgSend(fromAddr, toAddr string, coins sdk.Coins) ProtoMsg {
return &banktypes.MsgSend{
return &bankv1beta1.MsgSend{
FromAddress: fromAddr,
ToAddress: toAddr,
Amount: coins,
}
}

func makeMsgDelegate(delegatorAddr, validatorAddr string, amount sdk.Coin) ProtoMsg {
return &stakingtypes.MsgDelegate{
v2Coin := v1beta1.Coin{
Denom: amount.Denom,
Amount: amount.Amount,
}
return &stakingv1beta1.MsgDelegate{
DelegatorAddress: delegatorAddr,
ValidatorAddress: validatorAddr,
Amount: amount,
Amount: v2Coin,
}
}

func makeMsgUndelegate(delegatorAddr, validatorAddr string, amount sdk.Coin) ProtoMsg {
return &stakingtypes.MsgUndelegate{
v2Coin := v1beta1.Coin{
Denom: amount.Denom,
Amount: amount.Amount,
}
return &stakingv1beta1.MsgUndelegate{
DelegatorAddress: delegatorAddr,
ValidatorAddress: validatorAddr,
Amount: amount,
Amount: v2Coin,
}
}
2 changes: 1 addition & 1 deletion x/accounts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/log v1.3.1
cosmossdk.io/math v1.3.0
cosmossdk.io/x/bank v0.0.0-00010101000000-000000000000
cosmossdk.io/x/tx v0.13.1
github.com/cosmos/cosmos-sdk v0.51.0
github.com/cosmos/gogoproto v1.4.11
Expand All @@ -27,6 +26,7 @@ require (
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/store v1.0.2 // indirect
cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000 // indirect
cosmossdk.io/x/bank v0.0.0-00010101000000-000000000000 // indirect
cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
Expand Down
19 changes: 9 additions & 10 deletions x/accounts/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ import (
"github.com/golang/protobuf/proto" // nolint: staticcheck // needed because gogoproto.Merge does not work consistently.
"github.com/stretchr/testify/require"

bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1"
basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1"
"cosmossdk.io/collections"
"cosmossdk.io/math"
"cosmossdk.io/x/accounts/accountstd"
"cosmossdk.io/x/accounts/internal/implementation"
banktypes "cosmossdk.io/x/bank/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)

func TestKeeper_Init(t *testing.T) {
m, ctx := newKeeper(t, accountstd.AddAccount("test", NewTestAccount))
m.queryRouter = mockQuery(func(ctx context.Context, req, resp implementation.ProtoMsg) error {
_, ok := req.(*banktypes.QueryBalanceRequest)
_, ok := req.(*bankv1beta1.QueryBalanceRequest)
require.True(t, ok)
_, ok = resp.(*banktypes.QueryBalanceResponse)
_, ok = resp.(*bankv1beta1.QueryBalanceResponse)
require.True(t, ok)
return nil
})
Expand Down Expand Up @@ -74,16 +73,16 @@ func TestKeeper_Execute(t *testing.T) {

t.Run("exec module", func(t *testing.T) {
m.msgRouter = mockExec(func(ctx context.Context, msg, msgResp implementation.ProtoMsg) error {
concrete, ok := msg.(*banktypes.MsgSend)
concrete, ok := msg.(*bankv1beta1.MsgSend)
require.True(t, ok)
require.Equal(t, concrete.ToAddress, "recipient")
_, ok = msgResp.(*banktypes.MsgSendResponse)
_, ok = msgResp.(*bankv1beta1.MsgSendResponse)
require.True(t, ok)
return nil
})

m.signerProvider = mockSigner(func(msg implementation.ProtoMsg) ([]byte, error) {
require.Equal(t, msg.(*banktypes.MsgSend).FromAddress, string(accAddr))
require.Equal(t, msg.(*bankv1beta1.MsgSend).FromAddress, string(accAddr))
return accAddr, nil
})

Expand Down Expand Up @@ -119,11 +118,11 @@ func TestKeeper_Query(t *testing.T) {
// we inject the module query function, which accepts only a specific type of message
// we force the response
m.queryRouter = mockQuery(func(ctx context.Context, req, resp implementation.ProtoMsg) error {
concrete, ok := req.(*banktypes.QueryBalanceRequest)
concrete, ok := req.(*bankv1beta1.QueryBalanceRequest)
require.True(t, ok)
require.Equal(t, string(accAddr), concrete.Address)
require.Equal(t, concrete.Denom, "atom")
copyResp := &banktypes.QueryBalanceResponse{Balance: &sdk.Coin{
copyResp := &bankv1beta1.QueryBalanceResponse{Balance: &basev1beta1.Coin{
Denom: "atom",
Amount: math.NewInt(1000),
}}
Expand Down
6 changes: 3 additions & 3 deletions x/accounts/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import (
gogotypes "github.com/cosmos/gogoproto/types"
"github.com/stretchr/testify/require"

bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1"
"cosmossdk.io/x/accounts/accountstd"
"cosmossdk.io/x/accounts/internal/implementation"
v1 "cosmossdk.io/x/accounts/v1"
banktypes "cosmossdk.io/x/bank/types"
)

func TestMsgServer(t *testing.T) {
k, ctx := newKeeper(t, accountstd.AddAccount("test", NewTestAccount))
k.queryRouter = mockQuery(func(ctx context.Context, req, resp implementation.ProtoMsg) error {
_, ok := req.(*banktypes.QueryBalanceRequest)
_, ok := req.(*bankv1beta1.QueryBalanceRequest)
require.True(t, ok)
proto.Merge(resp, &banktypes.QueryBalanceResponse{})
proto.Merge(resp, &bankv1beta1.QueryBalanceResponse{})
return nil
})

Expand Down
Loading