func TestProcessProposalGoodDial(t *testing.T) {
	grpcServer := grpc.NewServer()
	defer grpcServer.Stop()
	_, addr := startEndorserServer(t, grpcServer)
	_, err := testProcessProposal(t, addr)
	if err != nil {
		t.Fatalf("Process proposal failed (%v)", err)
	}
}
TestProcessProposalGoodDial validates that an up
endorser connects.
package peer
import (
	"crypto/x509"
	"fmt"
	"net"
	"reflect"
	"testing"
	"time"
	"github.com/golang/mock/gomock"
	"github.com/stretchr/testify/assert"
	"google.golang.org/grpc"
	grpcCodes "google.golang.org/grpc/codes"
	"google.golang.org/grpc/keepalive"
	pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
	"github.com/hyperledger/fabric-sdk-go/api/apiconfig"
	"github.com/hyperledger/fabric-sdk-go/api/apiconfig/mocks"
	"github.com/hyperledger/fabric-sdk-go/api/apifabclient"
	"github.com/hyperledger/fabric-sdk-go/pkg/errors/status"
	"github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/mocks"
)
const (
	ecertPath   = "../../../test/fixtures/fabricca/tls/certs/client/client_client1.pem"
	peer1URL    = "localhost:7050"
	peer2URL    = "localhost:7054"
	peerURLBad  = "localhost:9999"
	testAddress = "127.0.0.1:0"
)
var kap keepalive.ClientParameters
func TestNewPeerEndorserTLS(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.DefaultMockConfig(mockCtrl)
	url := "grpcs://0.0.0.0:1234"
	conn, err := newPeerEndorser(getPeerEndorserRequest(url, mock_apiconfig.GoodCert, "", true, config, kap, false))
	if err != nil {
		t.Fatalf("Peer conn should be constructed")
	}
	optInsecure := reflect.ValueOf(grpc.WithInsecure())
	for _, opt := range conn.grpcDialOption {
		optr := reflect.ValueOf(opt)
		if optr.Pointer() == optInsecure.Pointer() {
			t.Fatalf("TLS enabled - insecure not allowed")
		}
	}
}
func TestNewPeerEndorserMutualTLS(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.DefaultMockConfig(mockCtrl)
	url := "grpcs://0.0.0.0:1234"
	conn, err := newPeerEndorser(getPeerEndorserRequest(url, mock_apiconfig.GoodCert, "", true, config, kap, false))
	if err != nil {
		t.Fatalf("Peer conn should be constructed: %v", err)
	}
	optInsecure := reflect.ValueOf(grpc.WithInsecure())
	for _, opt := range conn.grpcDialOption {
		optr := reflect.ValueOf(opt)
		if optr.Pointer() == optInsecure.Pointer() {
			t.Fatalf("TLS enabled - insecure not allowed")
		}
	}
}
func TestNewPeerEndorserMutualTLSNoClientCerts(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.DefaultMockConfig(mockCtrl)
	url := "grpcs://0.0.0.0:1234"
	_, err := newPeerEndorser(getPeerEndorserRequest(url, mock_apiconfig.GoodCert, "", true, config, kap, false))
	if err != nil {
		t.Fatalf("Peer conn should be constructed: %v", err)
	}
}
func TestNewPeerEndorserTLSBadPool(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.DefaultMockConfig(mockCtrl)
	url := "grpcs://0.0.0.0:1234"
	_, err := newPeerEndorser(getPeerEndorserRequest(url, mock_apiconfig.BadCert, "", true, config, kap, false))
	if err == nil {
		t.Fatalf("Peer conn construction should have failed")
	}
}
func TestNewPeerEndorserNoTLS(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.DefaultMockConfig(mockCtrl)
	url := "grpc://0.0.0.0:1234"
	conn, err := newPeerEndorser(getPeerEndorserRequest(url, nil, "", true, config, kap, false))
	if err != nil {
		t.Fatalf("Peer conn should be constructed")
	}
	optInsecure := reflect.ValueOf(grpc.WithInsecure())
	optInsecureFound := false
	for _, opt := range conn.grpcDialOption {
		optr := reflect.ValueOf(opt)
		if optr.Pointer() == optInsecure.Pointer() {
			optInsecureFound = true
		}
	}
	if !optInsecureFound {
		t.Fatalf("Expected insecure to be found")
	}
}
func TestNewPeerEndorserBlocking(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.DefaultMockConfig(mockCtrl)
	url := "0.0.0.0:1234"
	conn, err := newPeerEndorser(getPeerEndorserRequest(url, nil, "", true, config, kap, false))
	if err != nil {
		t.Fatalf("Peer conn should be constructed")
	}
	optBlocking := reflect.ValueOf(grpc.WithBlock())
	optBlockingFound := false
	for _, opt := range conn.grpcDialOption {
		optr := reflect.ValueOf(opt)
		if optr.Pointer() == optBlocking.Pointer() {
			optBlockingFound = true
		}
	}
	if !optBlockingFound {
		t.Fatalf("Expected blocking to be found")
	}
}
func TestNewPeerEndorserNonBlocking(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.DefaultMockConfig(mockCtrl)
	url := "0.0.0.0:1234"
	conn, err := newPeerEndorser(getPeerEndorserRequest(url, nil, "", false, config, kap, false))
	if err != nil {
		t.Fatalf("Peer conn should be constructed")
	}
	optBlocking := reflect.ValueOf(grpc.WithBlock())
	for _, opt := range conn.grpcDialOption {
		optr := reflect.ValueOf(opt)
		if optr.Pointer() == optBlocking.Pointer() {
			t.Fatalf("Blocking opt found when not expected")
		}
	}
}
func TestNewPeerEndorserBadParams(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.DefaultMockConfig(mockCtrl)
	url := ""
	_, err := newPeerEndorser(getPeerEndorserRequest(url, nil, "", true, config, kap, false))
	if err == nil {
		t.Fatalf("Peer conn should not be constructed - bad params")
	}
}
func TestNewPeerEndorserTLSBad(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()
	config := mock_apiconfig.DefaultMockConfig(mockCtrl)
	url := "grpcs://0.0.0.0:1234"
	_, err := newPeerEndorser(getPeerEndorserRequest(url, nil, "", true, config, kap, false))
	if err == nil {
		t.Fatalf("Peer conn should not be constructed - bad cert pool")
	}
}
func TestProcessProposalBadDial(t *testing.T) {
	_, err := testProcessProposal(t, testAddress)
	if err == nil {
		t.Fatalf("Process proposal should have failed")
	}
}