github.com/osdi23p228/fabric@v0.0.0-20221218062954-77808885f5db/orderer/consensus/etcdraft/initialization_test.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package etcdraft_test
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/osdi23p228/fabric/bccsp/sw"
    13  	"github.com/osdi23p228/fabric/common/metrics/disabled"
    14  	"github.com/osdi23p228/fabric/internal/pkg/comm"
    15  	"github.com/osdi23p228/fabric/orderer/common/cluster"
    16  	"github.com/osdi23p228/fabric/orderer/common/localconfig"
    17  	"github.com/osdi23p228/fabric/orderer/common/multichannel"
    18  	"github.com/osdi23p228/fabric/orderer/consensus/etcdraft"
    19  	"github.com/osdi23p228/fabric/orderer/consensus/etcdraft/mocks"
    20  	"github.com/stretchr/testify/assert"
    21  )
    22  
    23  func TestNewEtcdRaftConsenter(t *testing.T) {
    24  	srv, err := comm.NewGRPCServer("127.0.0.1:0", comm.ServerConfig{})
    25  	assert.NoError(t, err)
    26  	defer srv.Stop()
    27  	dialer := &cluster.PredicateDialer{}
    28  	cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())
    29  	assert.NoError(t, err)
    30  	consenter := etcdraft.New(dialer,
    31  		&localconfig.TopLevel{},
    32  		comm.ServerConfig{
    33  			SecOpts: comm.SecureOptions{
    34  				Certificate: []byte{1, 2, 3},
    35  			},
    36  		}, srv, &multichannel.Registrar{},
    37  		&mocks.InactiveChainRegistry{},
    38  		&disabled.Provider{},
    39  		cryptoProvider,
    40  	)
    41  
    42  	// Assert that the certificate from the gRPC server was passed to the consenter
    43  	assert.Equal(t, []byte{1, 2, 3}, consenter.Cert)
    44  	// Assert that all dependencies for the consenter were populated
    45  	assert.NotNil(t, consenter.Communication)
    46  	assert.NotNil(t, consenter.Chains)
    47  	assert.NotNil(t, consenter.ChainSelector)
    48  	assert.NotNil(t, consenter.Dispatcher)
    49  	assert.NotNil(t, consenter.Logger)
    50  }
    51  
    52  func TestNewEtcdRaftConsenterNoSystemChannel(t *testing.T) {
    53  	srv, err := comm.NewGRPCServer("127.0.0.1:0", comm.ServerConfig{})
    54  	assert.NoError(t, err)
    55  	defer srv.Stop()
    56  	dialer := &cluster.PredicateDialer{}
    57  	cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())
    58  	assert.NoError(t, err)
    59  	consenter := etcdraft.New(
    60  		dialer,
    61  		&localconfig.TopLevel{},
    62  		comm.ServerConfig{
    63  			SecOpts: comm.SecureOptions{
    64  				Certificate: []byte{1, 2, 3},
    65  			},
    66  		}, srv, &multichannel.Registrar{},
    67  		nil, // without a system channel we have InactiveChainRegistry == nil
    68  		&disabled.Provider{},
    69  		cryptoProvider,
    70  	)
    71  
    72  	// Assert that the certificate from the gRPC server was passed to the consenter
    73  	assert.Equal(t, []byte{1, 2, 3}, consenter.Cert)
    74  	// Assert that all dependencies for the consenter were populated
    75  	assert.NotNil(t, consenter.Communication)
    76  	assert.NotNil(t, consenter.Chains)
    77  	assert.NotNil(t, consenter.ChainSelector)
    78  	assert.NotNil(t, consenter.Dispatcher)
    79  	assert.NotNil(t, consenter.Logger)
    80  	assert.Nil(t, consenter.InactiveChainRegistry)
    81  }