grpc tests

This commit is contained in:
0xmuralik 2022-11-04 17:16:42 +05:30
parent e75b5eb807
commit e112888754

View File

@ -197,12 +197,16 @@ func (suite *KeeperTestSuite) TestGrpcGetRecordLists() {
func (suite *KeeperTestSuite) TestGrpcQueryNameserviceModuleBalance() { func (suite *KeeperTestSuite) TestGrpcQueryNameserviceModuleBalance() {
grpcClient, ctx := suite.queryClient, suite.ctx grpcClient, ctx := suite.queryClient, suite.ctx
sr := suite.Require() sr := suite.Require()
examples := []string{
"/../helpers/examples/service_provider_example.yml",
"/../helpers/examples/website_registration_example.yml",
}
testCases := []struct { testCases := []struct {
msg string msg string
req *nameservicetypes.GetNameServiceModuleBalanceRequest req *nameservicetypes.GetNameServiceModuleBalanceRequest
createRecord bool createRecords bool
expErr bool expErr bool
noOfRecords int noOfRecords int
}{ }{
{ {
"Get Module Balance", "Get Module Balance",
@ -214,20 +218,22 @@ func (suite *KeeperTestSuite) TestGrpcQueryNameserviceModuleBalance() {
} }
for _, test := range testCases { for _, test := range testCases {
suite.Run(fmt.Sprintf("Case %s ", test.msg), func() { suite.Run(fmt.Sprintf("Case %s ", test.msg), func() {
if test.createRecord { if test.createRecords {
dir, err := os.Getwd() dir, err := os.Getwd()
sr.NoError(err) sr.NoError(err)
payloadType, err := cli.GetPayloadFromFile(dir + "/../helpers/examples/example1.yml") for _, example := range examples {
sr.NoError(err) payloadType, err := cli.GetPayloadFromFile(fmt.Sprint(dir, example))
payload, err := payloadType.ToPayload() sr.NoError(err)
sr.NoError(err) payload, err := payloadType.ToPayload()
record, err := suite.app.NameServiceKeeper.ProcessSetRecord(ctx, nameservicetypes.MsgSetRecord{ sr.NoError(err)
BondId: suite.bond.GetId(), record, err := suite.app.NameServiceKeeper.ProcessSetRecord(ctx, nameservicetypes.MsgSetRecord{
Signer: suite.accounts[0].String(), BondId: suite.bond.GetId(),
Payload: payload, Signer: suite.accounts[0].String(),
}) Payload: payload,
sr.NoError(err) })
sr.NotNil(record.ID) sr.NoError(err)
sr.NotNil(record.ID)
}
} }
resp, err := grpcClient.GetNameServiceModuleBalance(context.Background(), test.req) resp, err := grpcClient.GetNameServiceModuleBalance(context.Background(), test.req)
if test.expErr { if test.expErr {
@ -235,7 +241,7 @@ func (suite *KeeperTestSuite) TestGrpcQueryNameserviceModuleBalance() {
} else { } else {
sr.NoError(err) sr.NoError(err)
sr.Equal(test.noOfRecords, len(resp.GetBalances())) sr.Equal(test.noOfRecords, len(resp.GetBalances()))
if test.createRecord { if test.createRecords {
balance := resp.GetBalances()[0] balance := resp.GetBalances()[0]
sr.Equal(balance.AccountName, nameservicetypes.RecordRentModuleAccountName) sr.Equal(balance.AccountName, nameservicetypes.RecordRentModuleAccountName)
} }