From 0f53e1156c3a45149d8be207f723ad76244cda0a Mon Sep 17 00:00:00 2001 From: Yoav Tock Date: Wed, 15 May 2024 17:40:57 +0300 Subject: [PATCH] fix TestGetOrdererEndpointFromConfigTx Signed-off-by: Yoav Tock --- internal/peer/common/common_test.go | 50 +++++++++++++++++++++++------ sampleconfig/configtx.yaml | 4 +++ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/internal/peer/common/common_test.go b/internal/peer/common/common_test.go index d520a368c2a..4e328cb244c 100644 --- a/internal/peer/common/common_test.go +++ b/internal/peer/common/common_test.go @@ -20,7 +20,6 @@ import ( "github.com/hyperledger/fabric-lib-go/common/flogging" cb "github.com/hyperledger/fabric-protos-go/common" pb "github.com/hyperledger/fabric-protos-go/peer" - "github.com/hyperledger/fabric/common/channelconfig" "github.com/hyperledger/fabric/common/crypto/tlsgen" "github.com/hyperledger/fabric/common/util" "github.com/hyperledger/fabric/core/config/configtest" @@ -268,17 +267,19 @@ func TestGetOrdererEndpointFromConfigTx(t *testing.T) { require.NoError(t, err) t.Run("green-path", func(t *testing.T) { - profile := genesisconfig.Load(genesisconfig.SampleInsecureSoloProfile, configtest.GetDevConfigDir()) - profile.Capabilities = map[string]bool{"V_2": true} + tlsCA, err := tlsgen.NewCA() + require.NoError(t, err) + certDir := t.TempDir() + profile := genesisconfig.Load(genesisconfig.SampleAppChannelEtcdRaftProfile, configtest.GetDevConfigDir()) + profile.Capabilities = map[string]bool{"V3_0": true} + generateCertificates(profile, tlsCA, certDir) + + t.Logf("%+v", profile.Orderer.Organizations[0]) + channelGroup, err := encoder.NewChannelGroup(profile) require.NoError(t, err) channelConfig := &cb.Config{ChannelGroup: channelGroup} - ordererAddresses := channelconfig.OrdererAddressesValue([]string{"order-1-endpoint", "order-2-end-point"}) - channelConfig.ChannelGroup.Values[ordererAddresses.Key()] = &cb.ConfigValue{ - Value: protoutil.MarshalOrPanic(ordererAddresses.Value()), - } - mockEndorserClient := common.GetMockEndorserClient( &pb.ProposalResponse{ Response: &pb.Response{Status: 200, Payload: protoutil.MarshalOrPanic(channelConfig)}, @@ -289,7 +290,7 @@ func TestGetOrdererEndpointFromConfigTx(t *testing.T) { ordererEndpoints, err := common.GetOrdererEndpointOfChain("test-channel", signer, mockEndorserClient, cryptoProvider) require.NoError(t, err) - require.Equal(t, []string{"order-1-endpoint", "order-2-end-point"}, ordererEndpoints) + require.Equal(t, []string{"127.0.0.1:7050", "127.0.0.1:7051", "127.0.0.1:7052"}, ordererEndpoints) }) t.Run("error-invoking-CSCC", func(t *testing.T) { @@ -405,3 +406,34 @@ func TestConfigFromEnv(t *testing.T) { require.Equal(t, org1ServerKP.Key, clientConfig.SecOpts.Key, "Client.SecOpts.Key should be set to configured key") require.Equal(t, org1ServerKP.Cert, clientConfig.SecOpts.Certificate, "Client.SecOpts.Certificate shoulbe bet set to configured certificate") } + +// TODO this pattern repeats itself in several places. Make it common in the 'genesisconfig' package to easily create +// Raft genesis blocks +func generateCertificates(confAppRaft *genesisconfig.Profile, tlsCA tlsgen.CA, certDir string) error { + for i, c := range confAppRaft.Orderer.EtcdRaft.Consenters { + srvC, err := tlsCA.NewServerCertKeyPair(c.Host) + if err != nil { + return err + } + srvP := path.Join(certDir, fmt.Sprintf("server%d.crt", i)) + err = os.WriteFile(srvP, srvC.Cert, 0o644) + if err != nil { + return err + } + + clnC, err := tlsCA.NewClientCertKeyPair() + if err != nil { + return err + } + clnP := path.Join(certDir, fmt.Sprintf("client%d.crt", i)) + err = os.WriteFile(clnP, clnC.Cert, 0o644) + if err != nil { + return err + } + + c.ServerTlsCert = []byte(srvP) + c.ClientTlsCert = []byte(clnP) + } + + return nil +} diff --git a/sampleconfig/configtx.yaml b/sampleconfig/configtx.yaml index 3bcc2f588b3..29437f96e36 100644 --- a/sampleconfig/configtx.yaml +++ b/sampleconfig/configtx.yaml @@ -658,6 +658,10 @@ Profiles: Admins: Type: Signature Rule: "OR('SampleOrg.member')" + OrdererEndpoints: + - "127.0.0.1:7050" + - "127.0.0.1:7051" + - "127.0.0.1:7052" Application: <<: *ApplicationDefaults Organizations: