grpc tests

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

View File

@ -197,10 +197,14 @@ 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
}{ }{
@ -214,10 +218,11 @@ 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 {
payloadType, err := cli.GetPayloadFromFile(fmt.Sprint(dir, example))
sr.NoError(err) sr.NoError(err)
payload, err := payloadType.ToPayload() payload, err := payloadType.ToPayload()
sr.NoError(err) sr.NoError(err)
@ -229,13 +234,14 @@ func (suite *KeeperTestSuite) TestGrpcQueryNameserviceModuleBalance() {
sr.NoError(err) sr.NoError(err)
sr.NotNil(record.ID) 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 {
suite.Error(err) suite.Error(err)
} 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)
} }