Skip to content

Commit

Permalink
fix(x/cert): cleanup grpc tests (#1929)
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Mar 6, 2024
1 parent 9df46e8 commit 88c34f8
Showing 1 changed file with 17 additions and 94 deletions.
111 changes: 17 additions & 94 deletions x/cert/client/cli/grpc_rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand All @@ -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()
Expand Down

0 comments on commit 88c34f8

Please sign in to comment.