2022-04-05 07:09:27 +00:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2022-04-20 19:15:52 +00:00
|
|
|
"os"
|
|
|
|
|
2022-09-07 06:36:11 +00:00
|
|
|
"github.com/cerc-io/laconicd/x/nameservice/client/cli"
|
2022-11-15 06:21:14 +00:00
|
|
|
"github.com/cerc-io/laconicd/x/nameservice/helpers"
|
|
|
|
"github.com/cerc-io/laconicd/x/nameservice/keeper"
|
2022-09-07 06:36:11 +00:00
|
|
|
nameservicetypes "github.com/cerc-io/laconicd/x/nameservice/types"
|
2022-04-05 07:09:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) TestGrpcQueryParams() {
|
|
|
|
grpcClient := suite.queryClient
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
msg string
|
|
|
|
req *nameservicetypes.QueryParamsRequest
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"Get Params",
|
|
|
|
&nameservicetypes.QueryParamsRequest{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range testCases {
|
|
|
|
suite.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
|
|
|
resp, _ := grpcClient.Params(context.Background(), test.req)
|
|
|
|
defaultParams := nameservicetypes.DefaultParams()
|
|
|
|
suite.Require().Equal(defaultParams.String(), resp.GetParams().String())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) TestGrpcGetRecordLists() {
|
|
|
|
grpcClient, ctx := suite.queryClient, suite.ctx
|
|
|
|
sr := suite.Require()
|
|
|
|
var recordId string
|
2022-11-15 06:21:14 +00:00
|
|
|
examples := []string{
|
|
|
|
"/../helpers/examples/service_provider_example.yml",
|
|
|
|
"/../helpers/examples/website_registration_example.yml",
|
|
|
|
}
|
2022-04-05 07:09:27 +00:00
|
|
|
testCases := []struct {
|
2022-11-15 06:21:14 +00:00
|
|
|
msg string
|
|
|
|
req *nameservicetypes.QueryListRecordsRequest
|
|
|
|
createRecords bool
|
|
|
|
expErr bool
|
|
|
|
noOfRecords int
|
2022-04-05 07:09:27 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"Empty Records",
|
|
|
|
&nameservicetypes.QueryListRecordsRequest{},
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"List Records",
|
|
|
|
&nameservicetypes.QueryListRecordsRequest{},
|
|
|
|
true,
|
|
|
|
false,
|
2022-11-15 06:21:14 +00:00
|
|
|
2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Filter with type",
|
|
|
|
&nameservicetypes.QueryListRecordsRequest{
|
|
|
|
Attributes: []*nameservicetypes.QueryListRecordsRequest_KeyValueInput{
|
|
|
|
{
|
|
|
|
Key: "type",
|
|
|
|
Value: &nameservicetypes.QueryListRecordsRequest_ValueInput{
|
|
|
|
Type: "string",
|
|
|
|
String_: "WebsiteRegistrationRecord",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
All: true,
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Filter with attributes ServiceProviderRegistration",
|
|
|
|
&nameservicetypes.QueryListRecordsRequest{
|
|
|
|
Attributes: []*nameservicetypes.QueryListRecordsRequest_KeyValueInput{
|
|
|
|
{
|
|
|
|
Key: "x500state_name",
|
|
|
|
Value: &nameservicetypes.QueryListRecordsRequest_ValueInput{
|
|
|
|
Type: "string",
|
|
|
|
String_: "california",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
All: true,
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
false,
|
2022-04-05 07:09:27 +00:00
|
|
|
1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range testCases {
|
|
|
|
suite.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
2022-11-15 06:21:14 +00:00
|
|
|
if test.createRecords {
|
|
|
|
for _, example := range examples {
|
|
|
|
dir, err := os.Getwd()
|
|
|
|
sr.NoError(err)
|
|
|
|
payloadType, err := cli.GetPayloadFromFile(fmt.Sprint(dir, example))
|
|
|
|
sr.NoError(err)
|
|
|
|
payload, err := payloadType.ToPayload()
|
|
|
|
sr.NoError(err)
|
|
|
|
record, err := suite.app.NameServiceKeeper.ProcessSetRecord(ctx, nameservicetypes.MsgSetRecord{
|
|
|
|
BondId: suite.bond.GetId(),
|
|
|
|
Signer: suite.accounts[0].String(),
|
|
|
|
Payload: payload,
|
|
|
|
})
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.NotNil(record.ID)
|
|
|
|
}
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
resp, err := grpcClient.ListRecords(context.Background(), test.req)
|
|
|
|
if test.expErr {
|
|
|
|
suite.Error(err)
|
|
|
|
} else {
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.Equal(test.noOfRecords, len(resp.GetRecords()))
|
2022-11-15 06:21:14 +00:00
|
|
|
if test.createRecords {
|
|
|
|
recordId = resp.GetRecords()[0].GetId()
|
2022-04-05 07:09:27 +00:00
|
|
|
sr.NotZero(resp.GetRecords())
|
2022-11-15 06:21:14 +00:00
|
|
|
sr.Equal(resp.GetRecords()[0].GetBondId(), suite.bond.GetId())
|
|
|
|
|
|
|
|
for _, record := range resp.GetRecords() {
|
|
|
|
bz, err := nameservicetypes.GetJSONBytesFromAny(*record.Attributes)
|
|
|
|
sr.NoError(err)
|
|
|
|
recAttr := helpers.UnMarshalMapFromJSONBytes(bz)
|
|
|
|
for _, attr := range test.req.GetAttributes() {
|
|
|
|
if attr.Key[:4] == "x500" {
|
|
|
|
sr.Equal(keeper.GetAttributeValue(attr.Value), recAttr["x500"].(map[string]interface{})[attr.Key[4:]])
|
|
|
|
} else {
|
|
|
|
sr.Equal(keeper.GetAttributeValue(attr.Value), recAttr[attr.Key])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the records by record id
|
|
|
|
testCases1 := []struct {
|
|
|
|
msg string
|
2022-10-17 11:03:31 +00:00
|
|
|
req *nameservicetypes.QueryRecordByIDRequest
|
2022-04-05 07:09:27 +00:00
|
|
|
createRecord bool
|
|
|
|
expErr bool
|
|
|
|
noOfRecords int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"Invalid Request without record id",
|
2022-10-17 11:03:31 +00:00
|
|
|
&nameservicetypes.QueryRecordByIDRequest{},
|
2022-04-05 07:09:27 +00:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"With Record ID",
|
2022-10-17 11:03:31 +00:00
|
|
|
&nameservicetypes.QueryRecordByIDRequest{
|
2022-04-05 07:09:27 +00:00
|
|
|
Id: recordId,
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range testCases1 {
|
|
|
|
suite.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
|
|
|
resp, err := grpcClient.GetRecord(context.Background(), test.req)
|
|
|
|
if test.expErr {
|
|
|
|
suite.Error(err)
|
|
|
|
} else {
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.NotNil(resp.GetRecord())
|
|
|
|
if test.createRecord {
|
2022-11-15 06:21:14 +00:00
|
|
|
sr.Equal(resp.GetRecord().BondId, suite.bond.GetId())
|
2022-04-05 07:09:27 +00:00
|
|
|
sr.Equal(resp.GetRecord().Id, recordId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the records by record id
|
|
|
|
testCasesByBondID := []struct {
|
|
|
|
msg string
|
2022-10-17 11:03:31 +00:00
|
|
|
req *nameservicetypes.QueryRecordByBondIDRequest
|
2022-04-05 07:09:27 +00:00
|
|
|
createRecord bool
|
|
|
|
expErr bool
|
|
|
|
noOfRecords int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"Invalid Request without bond id",
|
2022-10-17 11:03:31 +00:00
|
|
|
&nameservicetypes.QueryRecordByBondIDRequest{},
|
2022-04-05 07:09:27 +00:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"With Bond ID",
|
2022-10-17 11:03:31 +00:00
|
|
|
&nameservicetypes.QueryRecordByBondIDRequest{
|
2022-11-15 06:21:14 +00:00
|
|
|
Id: suite.bond.GetId(),
|
2022-04-05 07:09:27 +00:00
|
|
|
},
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range testCasesByBondID {
|
|
|
|
suite.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
2022-10-17 11:03:31 +00:00
|
|
|
resp, err := grpcClient.GetRecordByBondID(context.Background(), test.req)
|
2022-04-05 07:09:27 +00:00
|
|
|
if test.expErr {
|
|
|
|
sr.Zero(resp.GetRecords())
|
|
|
|
} else {
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.NotNil(resp.GetRecords())
|
|
|
|
if test.createRecord {
|
|
|
|
sr.NotZero(resp.GetRecords())
|
2022-11-15 06:21:14 +00:00
|
|
|
sr.Equal(resp.GetRecords()[0].GetBondId(), suite.bond.GetId())
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) TestGrpcQueryNameserviceModuleBalance() {
|
|
|
|
grpcClient, ctx := suite.queryClient, suite.ctx
|
|
|
|
sr := suite.Require()
|
2022-11-15 06:21:14 +00:00
|
|
|
examples := []string{
|
|
|
|
"/../helpers/examples/service_provider_example.yml",
|
|
|
|
"/../helpers/examples/website_registration_example.yml",
|
|
|
|
}
|
2022-04-05 07:09:27 +00:00
|
|
|
testCases := []struct {
|
2022-11-15 06:21:14 +00:00
|
|
|
msg string
|
|
|
|
req *nameservicetypes.GetNameServiceModuleBalanceRequest
|
|
|
|
createRecords bool
|
|
|
|
expErr bool
|
|
|
|
noOfRecords int
|
2022-04-05 07:09:27 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"Get Module Balance",
|
|
|
|
&nameservicetypes.GetNameServiceModuleBalanceRequest{},
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range testCases {
|
|
|
|
suite.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
2022-11-15 06:21:14 +00:00
|
|
|
if test.createRecords {
|
2022-04-05 07:09:27 +00:00
|
|
|
dir, err := os.Getwd()
|
|
|
|
sr.NoError(err)
|
2022-11-15 06:21:14 +00:00
|
|
|
for _, example := range examples {
|
|
|
|
payloadType, err := cli.GetPayloadFromFile(fmt.Sprint(dir, example))
|
|
|
|
sr.NoError(err)
|
|
|
|
payload, err := payloadType.ToPayload()
|
|
|
|
sr.NoError(err)
|
|
|
|
record, err := suite.app.NameServiceKeeper.ProcessSetRecord(ctx, nameservicetypes.MsgSetRecord{
|
|
|
|
BondId: suite.bond.GetId(),
|
|
|
|
Signer: suite.accounts[0].String(),
|
|
|
|
Payload: payload,
|
|
|
|
})
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.NotNil(record.ID)
|
|
|
|
}
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
resp, err := grpcClient.GetNameServiceModuleBalance(context.Background(), test.req)
|
|
|
|
if test.expErr {
|
|
|
|
suite.Error(err)
|
|
|
|
} else {
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.Equal(test.noOfRecords, len(resp.GetBalances()))
|
2022-11-15 06:21:14 +00:00
|
|
|
if test.createRecords {
|
2022-04-05 07:09:27 +00:00
|
|
|
balance := resp.GetBalances()[0]
|
|
|
|
sr.Equal(balance.AccountName, nameservicetypes.RecordRentModuleAccountName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) TestGrpcQueryWhoIS() {
|
|
|
|
grpcClient, ctx := suite.queryClient, suite.ctx
|
|
|
|
sr := suite.Require()
|
2022-10-17 06:47:56 +00:00
|
|
|
authorityName := "TestGrpcQueryWhoIS"
|
2022-04-05 07:09:27 +00:00
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
msg string
|
|
|
|
req *nameservicetypes.QueryWhoisRequest
|
|
|
|
createName bool
|
|
|
|
expErr bool
|
|
|
|
noOfRecords int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"Invalid Request without name",
|
|
|
|
&nameservicetypes.QueryWhoisRequest{},
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Success",
|
|
|
|
&nameservicetypes.QueryWhoisRequest{},
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range testCases {
|
|
|
|
suite.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
|
|
|
if test.createName {
|
|
|
|
err := suite.app.NameServiceKeeper.ProcessReserveAuthority(ctx, nameservicetypes.MsgReserveAuthority{
|
|
|
|
Name: authorityName,
|
|
|
|
Signer: suite.accounts[0].String(),
|
|
|
|
Owner: suite.accounts[0].String(),
|
|
|
|
})
|
|
|
|
sr.NoError(err)
|
|
|
|
test.req = &nameservicetypes.QueryWhoisRequest{Name: authorityName}
|
|
|
|
}
|
|
|
|
resp, err := grpcClient.Whois(context.Background(), test.req)
|
|
|
|
if test.expErr {
|
|
|
|
sr.Zero(len(resp.NameAuthority.AuctionId))
|
|
|
|
} else {
|
|
|
|
sr.NoError(err)
|
|
|
|
if test.createName {
|
|
|
|
nameAuth := resp.NameAuthority
|
|
|
|
sr.NotNil(nameAuth)
|
|
|
|
sr.Equal(nameAuth.OwnerAddress, suite.accounts[0].String())
|
|
|
|
sr.Equal(nameservicetypes.AuthorityActive, nameAuth.Status)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|