-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
feat(x/accounts): use router service from env #20003
Changes from all commits
dc130eb
9d1d193
da19302
8b00811
ca1be85
b4d12c1
d5f61f7
1b82624
966a745
6527b05
febc15f
cf2d7d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,18 @@ | ||
package accounts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification The removed mock functions Analysis chainConfirm that the elimination of redundant mock functions does not affect other test functionalities or dependencies within the test suite. Scripts ExecutedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for any references to eliminated mock functions in the test files to ensure they are not used elsewhere.
rg --type go --files-with-matches --glob '*_test.go' 'mock'
Length of output: 3896 Script: #!/bin/bash
# First, identify the specific mock functions that were removed from x/accounts/keeper_test.go
git diff origin/main...HEAD -- x/accounts/keeper_test.go | grep -P '^\-.*mock.*\('
# Then, check if these specific mock functions are referenced in other test files
rg --type go --files-with-matches --glob '*_test.go' 'specific_mock_function_name_here'
Length of output: 673 Script: #!/bin/bash
# Search for references to 'mockQuery' and 'mockExec' in the test files to ensure they are not used elsewhere.
rg --type go --files-with-matches --glob '*_test.go' 'mockQuery|mockExec'
Length of output: 137 |
||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/cosmos/gogoproto/types" | ||
"github.com/stretchr/testify/require" | ||
"google.golang.org/protobuf/proto" | ||
|
||
bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" | ||
basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" | ||
"cosmossdk.io/collections" | ||
"cosmossdk.io/x/accounts/accountstd" | ||
"cosmossdk.io/x/accounts/internal/implementation" | ||
) | ||
|
||
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.(*bankv1beta1.QueryBalanceRequest) | ||
require.True(t, ok) | ||
_, ok = resp.(*bankv1beta1.QueryBalanceResponse) | ||
require.True(t, ok) | ||
return nil | ||
}) | ||
|
||
t.Run("ok", func(t *testing.T) { | ||
sender := []byte("sender") | ||
|
@@ -52,7 +41,6 @@ func TestKeeper_Init(t *testing.T) { | |
|
||
func TestKeeper_Execute(t *testing.T) { | ||
m, ctx := newKeeper(t, accountstd.AddAccount("test", NewTestAccount)) | ||
m.queryRouter = mockQuery(func(ctx context.Context, req, resp implementation.ProtoMsg) error { return nil }) | ||
|
||
// create account | ||
sender := []byte("sender") | ||
|
@@ -71,35 +59,14 @@ 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.(*bankv1beta1.MsgSend) | ||
require.True(t, ok) | ||
require.Equal(t, concrete.ToAddress, "recipient") | ||
_, ok = msgResp.(*bankv1beta1.MsgSendResponse) | ||
require.True(t, ok) | ||
return nil | ||
}) | ||
|
||
m.msgRouter = mockExec(func(ctx context.Context, msg, msgResp implementation.ProtoMsg) error { | ||
concrete, ok := msg.(*bankv1beta1.MsgSend) | ||
require.True(t, ok) | ||
require.Equal(t, concrete.FromAddress, string(accAddr)) | ||
_, ok = msgResp.(*bankv1beta1.MsgSendResponse) | ||
require.True(t, ok) | ||
|
||
resp, err := m.Execute(ctx, accAddr, sender, &types.Int64Value{Value: 1000}, nil) | ||
require.NoError(t, err) | ||
require.True(t, implementation.Equal(&types.Empty{}, resp)) | ||
return nil | ||
}) | ||
resp, err := m.Execute(ctx, accAddr, sender, &types.Int64Value{Value: 1000}, nil) | ||
require.NoError(t, err) | ||
require.True(t, implementation.Equal(&types.Empty{}, resp)) | ||
}) | ||
} | ||
|
||
func TestKeeper_Query(t *testing.T) { | ||
m, ctx := newKeeper(t, accountstd.AddAccount("test", NewTestAccount)) | ||
m.queryRouter = mockQuery(func(ctx context.Context, req, resp implementation.ProtoMsg) error { | ||
return nil | ||
}) | ||
|
||
// create account | ||
sender := []byte("sender") | ||
|
@@ -118,21 +85,6 @@ func TestKeeper_Query(t *testing.T) { | |
}) | ||
|
||
t.Run("query module", func(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.(*bankv1beta1.QueryBalanceRequest) | ||
require.True(t, ok) | ||
require.Equal(t, string(accAddr), concrete.Address) | ||
require.Equal(t, concrete.Denom, "atom") | ||
copyResp := &bankv1beta1.QueryBalanceResponse{Balance: &basev1beta1.Coin{ | ||
Denom: "atom", | ||
Amount: "1000", | ||
}} | ||
proto.Merge(resp.(proto.Message), copyResp) | ||
return nil | ||
}) | ||
|
||
resp, err := m.Query(ctx, accAddr, &types.StringValue{Value: "atom"}) | ||
require.NoError(t, err) | ||
require.True(t, implementation.Equal(&types.Int64Value{Value: 1000}, resp)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider providing more details or a timeline in the TODO comment.
Would you like assistance in defining a more detailed plan or creating a tracking issue for this TODO?