diff --git a/x/cert/client/cli/grpc_rest_test.go b/x/cert/client/cli/grpc_rest_test.go index 2ad1f1aea..c63e22eec 100644 --- a/x/cert/client/cli/grpc_rest_test.go +++ b/x/cert/client/cli/grpc_rest_test.go @@ -2,14 +2,16 @@ package cli_test import ( "context" + "crypto/x509" + "encoding/pem" "fmt" "testing" - "github.com/stretchr/testify/suite" - "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" sdkrest "github.com/cosmos/cosmos-sdk/types/rest" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" types "github.com/akash-network/akash-api/go/node/cert/v1beta3" @@ -70,8 +72,18 @@ func (s *GRPCRestTestSuite) SetupSuite() { out := &types.QueryCertificatesResponse{} err = val.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), out) s.Require().NoError(err) - s.Require().Len(out.Certificates, 1, "Deployment Create Failed") - // s.Require().Equal(val.Address.String(), out.Certificates[0].) + s.Require().Len(out.Certificates, 1, "Certificate Create Failed") + block, rest := pem.Decode(out.Certificates[0].Certificate.Cert) + require.NotNil(s.T(), block) + require.Len(s.T(), rest, 0) + + require.Equal(s.T(), block.Type, types.PemBlkTypeCertificate) + + cert, err := x509.ParseCertificate(block.Bytes) + s.Require().NoError(err) + s.Require().NotNil(cert) + + s.Require().Equal(val.Address.String(), cert.Issuer.CommonName) s.certs = out.Certificates } @@ -88,37 +100,12 @@ func (s *GRPCRestTestSuite) TestGetCertificates() { expLen int }{ { - "get deployments without filters", + "get certificates without filters", fmt.Sprintf("%s/akash/cert/%s/certificates/list", val.APIAddress, atypes.ProtoAPIVersion), false, certs, 1, }, - // { - // "get deployments with filters", - // fmt.Sprintf("%s/akash/deployment/%s/deployments/list?filters.owner=%s", val.APIAddress, - // atypes.ProtoAPIVersion, - // deployment.Deployment.DeploymentID.Owner), - // false, - // deployment, - // 1, - // }, - // { - // "get deployments with wrong state filter", - // fmt.Sprintf("%s/akash/deployment/%s/deployments/list?filters.state=%s", val.APIAddress, atypes.ProtoAPIVersion, - // types.DeploymentStateInvalid.String()), - // true, - // types.QueryDeploymentResponse{}, - // 0, - // }, - // { - // "get deployments with two filters", - // fmt.Sprintf("%s/akash/deployment/%s/deployments/list?filters.state=%s&filters.dseq=%d", - // val.APIAddress, atypes.ProtoAPIVersion, deployment.Deployment.State.String(), deployment.Deployment.DeploymentID.DSeq), - // false, - // deployment, - // 1, - // }, } for _, tc := range testCases { @@ -142,70 +129,6 @@ func (s *GRPCRestTestSuite) TestGetCertificates() { } } -// func (s *GRPCRestTestSuite) TestGetCertificate() { -// val := s.network.Validators[0] -// certs := s.certs -// -// testCases := []struct { -// name string -// url string -// expErr bool -// expResp types.QueryCertificatesResponse -// }{ -// { -// "get deployment with empty input", -// fmt.Sprintf("%s/akash/deployment/%s/deployments/info", val.APIAddress, atypes.ProtoAPIVersion), -// true, -// types.QueryCertificatesResponse{}, -// }, -// { -// "get deployment with invalid input", -// fmt.Sprintf("%s/akash/deployment/%s/deployments/info?id.owner=%s", val.APIAddress, -// atypes.ProtoAPIVersion, -// deployment.Deployment.DeploymentID.Owner), -// true, -// types.QueryDeploymentResponse{}, -// }, -// { -// "deployment not found", -// fmt.Sprintf("%s/akash/deployment/%s/deployments/info?id.owner=%s&id.dseq=%d", val.APIAddress, -// atypes.ProtoAPIVersion, -// deployment.Deployment.DeploymentID.Owner, -// 249), -// true, -// types.QueryDeploymentResponse{}, -// }, -// { -// "valid get deployment request", -// fmt.Sprintf("%s/akash/deployment/%s/deployments/info?id.owner=%s&id.dseq=%d", -// val.APIAddress, -// atypes.ProtoAPIVersion, -// deployment.Deployment.DeploymentID.Owner, -// deployment.Deployment.DeploymentID.DSeq), -// false, -// deployment, -// }, -// } -// -// for _, tc := range testCases { -// tc := tc -// s.Run(tc.name, func() { -// resp, err := sdkrest.GetRequest(tc.url) -// s.Require().NoError(err) -// -// var out types.QueryDeploymentResponse -// err = val.ClientCtx.Codec.UnmarshalJSON(resp, &out) -// -// if tc.expErr { -// s.Require().Error(err) -// } else { -// s.Require().NoError(err) -// s.Require().Equal(tc.expResp, out) -// } -// }) -// } -// } - func (s *GRPCRestTestSuite) TearDownSuite() { s.T().Log("tearing down integration test suite") s.network.Cleanup()