github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/gossip/integration/integration_test.go (about)

     1  /*
     2  Copyright IBM Corp. 2016 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  		 http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package integration
    18  
    19  import (
    20  	"fmt"
    21  	"net"
    22  	"strings"
    23  	"testing"
    24  	"time"
    25  
    26  	"github.com/hyperledger/fabric/gossip/api"
    27  	"github.com/hyperledger/fabric/gossip/common"
    28  	"github.com/hyperledger/fabric/gossip/identity"
    29  	"github.com/hyperledger/fabric/msp/mgmt"
    30  	"github.com/hyperledger/fabric/msp/mgmt/testtools"
    31  	"github.com/spf13/viper"
    32  	"google.golang.org/grpc"
    33  )
    34  
    35  // This is just a test that shows how to instantiate a gossip component
    36  func TestNewGossipCryptoService(t *testing.T) {
    37  	setupTestEnv()
    38  	s1 := grpc.NewServer()
    39  	s2 := grpc.NewServer()
    40  	s3 := grpc.NewServer()
    41  
    42  	ll1, _ := net.Listen("tcp", fmt.Sprintf("%s:%d", "", 5611))
    43  	ll2, _ := net.Listen("tcp", fmt.Sprintf("%s:%d", "", 5612))
    44  	ll3, _ := net.Listen("tcp", fmt.Sprintf("%s:%d", "", 5613))
    45  
    46  	endpoint1 := "localhost:5611"
    47  	endpoint2 := "localhost:5612"
    48  	endpoint3 := "localhost:5613"
    49  
    50  	msptesttools.LoadMSPSetupForTesting("../../msp/sampleconfig")
    51  	peerIdentity, _ := mgmt.GetLocalSigningIdentityOrPanic().Serialize()
    52  
    53  	cryptSvc := &cryptoService{}
    54  	secAdv := &secAdviser{}
    55  
    56  	idMapper := identity.NewIdentityMapper(cryptSvc)
    57  
    58  	g1 := NewGossipComponent(peerIdentity, endpoint1, s1, secAdv, cryptSvc, idMapper, []grpc.DialOption{grpc.WithInsecure()})
    59  	g2 := NewGossipComponent(peerIdentity, endpoint2, s2, secAdv, cryptSvc, idMapper, []grpc.DialOption{grpc.WithInsecure()}, endpoint1)
    60  	g3 := NewGossipComponent(peerIdentity, endpoint3, s3, secAdv, cryptSvc, idMapper, []grpc.DialOption{grpc.WithInsecure()}, endpoint1)
    61  	go s1.Serve(ll1)
    62  	go s2.Serve(ll2)
    63  	go s3.Serve(ll3)
    64  
    65  	time.Sleep(time.Second * 5)
    66  	fmt.Println(g1.Peers())
    67  	fmt.Println(g2.Peers())
    68  	fmt.Println(g3.Peers())
    69  	time.Sleep(time.Second)
    70  }
    71  
    72  func setupTestEnv() {
    73  	viper.SetConfigName("core")
    74  	viper.SetEnvPrefix("CORE")
    75  	viper.AddConfigPath("./../../peer")
    76  	viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
    77  	viper.AutomaticEnv()
    78  	err := viper.ReadInConfig()
    79  	if err != nil { // Handle errors reading the config file
    80  		panic(fmt.Errorf("Fatal error config file: %s \n", err))
    81  	}
    82  }
    83  
    84  type secAdviser struct {
    85  }
    86  
    87  func (sa *secAdviser) OrgByPeerIdentity(api.PeerIdentityType) api.OrgIdentityType {
    88  	return api.OrgIdentityType("DEFAULT")
    89  }
    90  
    91  type cryptoService struct {
    92  }
    93  
    94  func (s *cryptoService) GetPKIidOfCert(peerIdentity api.PeerIdentityType) common.PKIidType {
    95  	return common.PKIidType(peerIdentity)
    96  }
    97  
    98  func (s *cryptoService) VerifyBlock(chainID common.ChainID, signedBlock api.SignedBlock) error {
    99  	return nil
   100  }
   101  
   102  func (s *cryptoService) Sign(msg []byte) ([]byte, error) {
   103  	return msg, nil
   104  }
   105  
   106  func (s *cryptoService) Verify(peerIdentity api.PeerIdentityType, signature, message []byte) error {
   107  	return nil
   108  }
   109  
   110  func (s *cryptoService) VerifyByChannel(chainID common.ChainID, peerIdentity api.PeerIdentityType, signature, message []byte) error {
   111  	return nil
   112  }
   113  
   114  func (s *cryptoService) ValidateIdentity(peerIdentity api.PeerIdentityType) error {
   115  	return nil
   116  }