Skip to content

Commit

Permalink
fix TestGetOrdererEndpointFromConfigTx
Browse files Browse the repository at this point in the history
Signed-off-by: Yoav Tock <[email protected]>
  • Loading branch information
tock-ibm committed May 15, 2024
1 parent 1b22af9 commit 0f53e11
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
50 changes: 41 additions & 9 deletions internal/peer/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)},
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions sampleconfig/configtx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 0f53e11

Please sign in to comment.