Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(x/cert): cleanup grpc tests #1929

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading