cosmos-sdk/x/accounts/query_server_test.go
testinginprod d3b30e946d
feat(accounts): implement account abstraction execution (#18499)
Co-authored-by: unknown unknown <unknown@unknown>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2023-12-04 11:41:59 +00:00

60 lines
1.4 KiB
Go

package accounts
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/wrapperspb"
"cosmossdk.io/x/accounts/accountstd"
v1 "cosmossdk.io/x/accounts/v1"
)
func TestQueryServer(t *testing.T) {
k, ctx := newKeeper(t, accountstd.AddAccount("test", NewTestAccount))
k.queryRouter = mockQuery(func(ctx context.Context, req, resp proto.Message) error {
return nil
})
ms := NewMsgServer(k)
qs := NewQueryServer(k)
// create
initMsg, err := proto.Marshal(&emptypb.Empty{})
require.NoError(t, err)
initResp, err := ms.Init(ctx, &v1.MsgInit{
Sender: "sender",
AccountType: "test",
Message: initMsg,
})
require.NoError(t, err)
// query
req := &wrapperspb.UInt64Value{Value: 10}
anypbReq, err := anypb.New(req)
require.NoError(t, err)
anypbReqBytes, err := proto.Marshal(anypbReq)
require.NoError(t, err)
queryResp, err := qs.AccountQuery(ctx, &v1.AccountQueryRequest{
Target: initResp.AccountAddress,
Request: anypbReqBytes,
})
require.NoError(t, err)
respAnyPB := &anypb.Any{}
err = proto.Unmarshal(queryResp.Response, respAnyPB)
require.NoError(t, err)
resp, err := respAnyPB.UnmarshalNew()
require.NoError(t, err)
require.Equal(t, "10", resp.(*wrapperspb.StringValue).Value)
}