From db358ac39ae164304aca202a7aa06b0ea7a7b7d4 Mon Sep 17 00:00:00 2001 From: Sudesh Shetty Date: Thu, 29 Jun 2017 15:30:14 -0400 Subject: [PATCH] [FAB-5115] Refactoring config and channel get methods. Change-Id: I7e3555caab19e574b99c86e8db1b04db6f54e0fd Signed-off-by: Sudesh Shetty --- api/channel.go | 22 +- api/config.go | 36 +-- api/mocks/mockconfig.gen.go | 264 +++++++++--------- fabric-txn/admin/transactionconfig.go | 10 +- fabric-txn/defaultImpl/defaultImpl.go | 4 +- fabric-txn/transaction.go | 4 +- pkg/config/config.go | 86 +++--- pkg/config/config_test.go | 162 ++++++++++- pkg/fabric-ca-client/fabricca.go | 12 +- pkg/fabric-ca-client/mocks/mockconfig.go | 72 ++--- pkg/fabric-client/channel/channel.go | 130 ++++----- pkg/fabric-client/channel/channel_test.go | 24 +- pkg/fabric-client/client_test.go | 4 +- pkg/fabric-client/events/consumer/consumer.go | 2 +- pkg/fabric-client/events/eventmocks.go | 2 +- pkg/fabric-client/mocks/mockconfig.go | 72 ++--- pkg/fabric-client/mocks/mockpeer.go | 4 +- pkg/fabric-client/orderer/orderer.go | 4 +- pkg/fabric-client/orderer/orderer_test.go | 6 +- pkg/fabric-client/peer/peer_test.go | 2 +- pkg/fabric-client/peer/peerendorser.go | 2 +- pkg/fabric-client/peer/peerendorser_test.go | 4 +- pkg/fabric-client/peer_test.go | 4 +- test/integration/base_test_setup.go | 12 +- test/integration/channel_queries_test.go | 12 +- test/integration/end_to_end_test.go | 2 +- test/integration/events_test.go | 10 +- test/integration/fabric_ca_test.go | 6 +- test/integration/install_chaincode_test.go | 2 +- test/integration/transient_data_test.go | 4 +- test/integration/utils.go | 8 +- 31 files changed, 560 insertions(+), 428 deletions(-) diff --git a/api/channel.go b/api/channel.go index d604357441..e31ea77450 100644 --- a/api/channel.go +++ b/api/channel.go @@ -23,24 +23,24 @@ import ( * primary orderer to retrieve the configuration settings for this channel. */ type Channel interface { - GetName() string + Name() string Initialize(data []byte) error IsInitialized() bool IsSecurityEnabled() bool - GetTCertBatchSize() int + TCertBatchSize() int SetTCertBatchSize(batchSize int) AddPeer(peer Peer) error RemovePeer(peer Peer) - GetPeers() []Peer - GetAnchorPeers() []OrgAnchorPeer + Peers() []Peer + AnchorPeers() []OrgAnchorPeer SetPrimaryPeer(peer Peer) error - GetPrimaryPeer() Peer + PrimaryPeer() Peer AddOrderer(orderer Orderer) error RemoveOrderer(orderer Orderer) - GetOrderers() []Orderer + Orderers() []Orderer SetMSPManager(mspManager msp.MSPManager) - GetMSPManager() msp.MSPManager - GetGenesisBlock(request *GenesisBlockRequest) (*common.Block, error) + MSPManager() msp.MSPManager + GenesisBlock(request *GenesisBlockRequest) (*common.Block, error) JoinChannel(request *JoinChannelRequest) error UpdateChannel() bool IsReadonly() bool @@ -55,20 +55,20 @@ type Channel interface { CreateTransaction(resps []*TransactionProposalResponse) (*Transaction, error) SendTransaction(tx *Transaction) ([]*TransactionResponse, error) SendInstantiateProposal(chaincodeName string, channelID string, args []string, chaincodePath string, chaincodeVersion string, targets []Peer) ([]*TransactionProposalResponse, string, error) - GetOrganizationUnits() ([]string, error) + OrganizationUnits() ([]string, error) QueryExtensionInterface() ChannelExtension LoadConfigUpdateEnvelope(data []byte) error } // The ChannelExtension interface allows extensions of the SDK to add functionality to Channel overloads. type ChannelExtension interface { - GetClientContext() FabricClient + ClientContext() FabricClient SignPayload(payload []byte) (*SignedEnvelope, error) BroadcastEnvelope(envelope *SignedEnvelope) ([]*TransactionResponse, error) // TODO: This should go somewhere else - see TransactionProposal.GetBytes(). - deprecated - GetProposalBytes(tp *TransactionProposal) ([]byte, error) + ProposalBytes(tp *TransactionProposal) ([]byte, error) } // OrgAnchorPeer contains information about an anchor peer on this channel diff --git a/api/config.go b/api/config.go index 8b68f424e2..8adaaaad94 100644 --- a/api/config.go +++ b/api/config.go @@ -15,25 +15,25 @@ import ( // Config fabric-sdk-go configuration interface type Config interface { - GetCAConfig(org string) (*CAConfig, error) - GetCAServerCertFiles(org string) ([]string, error) - GetCAClientKeyFile(org string) (string, error) - GetCAClientCertFile(org string) (string, error) - GetMspID(org string) (string, error) - GetFabricClientViper() *viper.Viper - GetRandomOrdererConfig() (*OrdererConfig, error) - GetOrdererConfig(name string) (*OrdererConfig, error) - GetPeersConfig(org string) ([]PeerConfig, error) - GetNetworkConfig() (*NetworkConfig, error) + CAConfig(org string) (*CAConfig, error) + CAServerCertFiles(org string) ([]string, error) + CAClientKeyFile(org string) (string, error) + CAClientCertFile(org string) (string, error) + MspID(org string) (string, error) + FabricClientViper() *viper.Viper + RandomOrdererConfig() (*OrdererConfig, error) + OrdererConfig(name string) (*OrdererConfig, error) + PeersConfig(org string) ([]PeerConfig, error) + NetworkConfig() (*NetworkConfig, error) IsTLSEnabled() bool - GetTLSCACertPool(tlsCertificate string) (*x509.CertPool, error) - GetTLSCACertPoolFromRoots(ordererRootCAs [][]byte) (*x509.CertPool, error) + TLSCACertPool(tlsCertificate string) (*x509.CertPool, error) + TLSCACertPoolFromRoots(ordererRootCAs [][]byte) (*x509.CertPool, error) IsSecurityEnabled() bool TcertBatchSize() int - GetSecurityAlgorithm() string - GetSecurityLevel() int - GetKeyStorePath() string - GetCAKeyStorePath() string - GetCryptoConfigPath() string - GetCSPConfig() *bccspFactory.FactoryOpts + SecurityAlgorithm() string + SecurityLevel() int + KeyStorePath() string + CAKeyStorePath() string + CryptoConfigPath() string + CSPConfig() *bccspFactory.FactoryOpts } diff --git a/api/mocks/mockconfig.gen.go b/api/mocks/mockconfig.gen.go index 3fe5c4571c..f3ada5a473 100644 --- a/api/mocks/mockconfig.gen.go +++ b/api/mocks/mockconfig.gen.go @@ -34,255 +34,255 @@ func (_m *MockConfig) EXPECT() *MockConfigMockRecorder { return _m.recorder } -// GetCAClientCertFile mocks base method -func (_m *MockConfig) GetCAClientCertFile(_param0 string) (string, error) { - ret := _m.ctrl.Call(_m, "GetCAClientCertFile", _param0) +// CAClientCertFile mocks base method +func (_m *MockConfig) CAClientCertFile(_param0 string) (string, error) { + ret := _m.ctrl.Call(_m, "CAClientCertFile", _param0) ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetCAClientCertFile indicates an expected call of GetCAClientCertFile -func (_mr *MockConfigMockRecorder) GetCAClientCertFile(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetCAClientCertFile", arg0) +// CAClientCertFile indicates an expected call of CAClientCertFile +func (_mr *MockConfigMockRecorder) CAClientCertFile(arg0 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "CAClientCertFile", arg0) } -// GetCAClientKeyFile mocks base method -func (_m *MockConfig) GetCAClientKeyFile(_param0 string) (string, error) { - ret := _m.ctrl.Call(_m, "GetCAClientKeyFile", _param0) +// CAClientKeyFile mocks base method +func (_m *MockConfig) CAClientKeyFile(_param0 string) (string, error) { + ret := _m.ctrl.Call(_m, "CAClientKeyFile", _param0) ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetCAClientKeyFile indicates an expected call of GetCAClientKeyFile -func (_mr *MockConfigMockRecorder) GetCAClientKeyFile(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetCAClientKeyFile", arg0) +// CAClientKeyFile indicates an expected call of CAClientKeyFile +func (_mr *MockConfigMockRecorder) CAClientKeyFile(arg0 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "CAClientKeyFile", arg0) } -// GetCAConfig mocks base method -func (_m *MockConfig) GetCAConfig(_param0 string) (*api.CAConfig, error) { - ret := _m.ctrl.Call(_m, "GetCAConfig", _param0) +// CAConfig mocks base method +func (_m *MockConfig) CAConfig(_param0 string) (*api.CAConfig, error) { + ret := _m.ctrl.Call(_m, "CAConfig", _param0) ret0, _ := ret[0].(*api.CAConfig) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetCAConfig indicates an expected call of GetCAConfig -func (_mr *MockConfigMockRecorder) GetCAConfig(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetCAConfig", arg0) +// CAConfig indicates an expected call of CAConfig +func (_mr *MockConfigMockRecorder) CAConfig(arg0 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "CAConfig", arg0) } -// GetCAKeyStorePath mocks base method -func (_m *MockConfig) GetCAKeyStorePath() string { - ret := _m.ctrl.Call(_m, "GetCAKeyStorePath") +// CAKeyStorePath mocks base method +func (_m *MockConfig) CAKeyStorePath() string { + ret := _m.ctrl.Call(_m, "CAKeyStorePath") ret0, _ := ret[0].(string) return ret0 } -// GetCAKeyStorePath indicates an expected call of GetCAKeyStorePath -func (_mr *MockConfigMockRecorder) GetCAKeyStorePath() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetCAKeyStorePath") +// CAKeyStorePath indicates an expected call of CAKeyStorePath +func (_mr *MockConfigMockRecorder) CAKeyStorePath() *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "CAKeyStorePath") } -// GetCAServerCertFiles mocks base method -func (_m *MockConfig) GetCAServerCertFiles(_param0 string) ([]string, error) { - ret := _m.ctrl.Call(_m, "GetCAServerCertFiles", _param0) +// CAServerCertFiles mocks base method +func (_m *MockConfig) CAServerCertFiles(_param0 string) ([]string, error) { + ret := _m.ctrl.Call(_m, "CAServerCertFiles", _param0) ret0, _ := ret[0].([]string) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetCAServerCertFiles indicates an expected call of GetCAServerCertFiles -func (_mr *MockConfigMockRecorder) GetCAServerCertFiles(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetCAServerCertFiles", arg0) +// CAServerCertFiles indicates an expected call of CAServerCertFiles +func (_mr *MockConfigMockRecorder) CAServerCertFiles(arg0 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "CAServerCertFiles", arg0) } -// GetCSPConfig mocks base method -func (_m *MockConfig) GetCSPConfig() *factory.FactoryOpts { - ret := _m.ctrl.Call(_m, "GetCSPConfig") +// CSPConfig mocks base method +func (_m *MockConfig) CSPConfig() *factory.FactoryOpts { + ret := _m.ctrl.Call(_m, "CSPConfig") ret0, _ := ret[0].(*factory.FactoryOpts) return ret0 } -// GetCSPConfig indicates an expected call of GetCSPConfig -func (_mr *MockConfigMockRecorder) GetCSPConfig() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetCSPConfig") +// CSPConfig indicates an expected call of CSPConfig +func (_mr *MockConfigMockRecorder) CSPConfig() *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "CSPConfig") } -// GetCryptoConfigPath mocks base method -func (_m *MockConfig) GetCryptoConfigPath() string { - ret := _m.ctrl.Call(_m, "GetCryptoConfigPath") +// CryptoConfigPath mocks base method +func (_m *MockConfig) CryptoConfigPath() string { + ret := _m.ctrl.Call(_m, "CryptoConfigPath") ret0, _ := ret[0].(string) return ret0 } -// GetCryptoConfigPath indicates an expected call of GetCryptoConfigPath -func (_mr *MockConfigMockRecorder) GetCryptoConfigPath() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetCryptoConfigPath") +// CryptoConfigPath indicates an expected call of CryptoConfigPath +func (_mr *MockConfigMockRecorder) CryptoConfigPath() *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "CryptoConfigPath") } -// GetFabricClientViper mocks base method -func (_m *MockConfig) GetFabricClientViper() *viper.Viper { - ret := _m.ctrl.Call(_m, "GetFabricClientViper") +// FabricClientViper mocks base method +func (_m *MockConfig) FabricClientViper() *viper.Viper { + ret := _m.ctrl.Call(_m, "FabricClientViper") ret0, _ := ret[0].(*viper.Viper) return ret0 } -// GetFabricClientViper indicates an expected call of GetFabricClientViper -func (_mr *MockConfigMockRecorder) GetFabricClientViper() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetFabricClientViper") +// FabricClientViper indicates an expected call of FabricClientViper +func (_mr *MockConfigMockRecorder) FabricClientViper() *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "FabricClientViper") } -// GetKeyStorePath mocks base method -func (_m *MockConfig) GetKeyStorePath() string { - ret := _m.ctrl.Call(_m, "GetKeyStorePath") +// IsSecurityEnabled mocks base method +func (_m *MockConfig) IsSecurityEnabled() bool { + ret := _m.ctrl.Call(_m, "IsSecurityEnabled") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsSecurityEnabled indicates an expected call of IsSecurityEnabled +func (_mr *MockConfigMockRecorder) IsSecurityEnabled() *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "IsSecurityEnabled") +} + +// IsTLSEnabled mocks base method +func (_m *MockConfig) IsTLSEnabled() bool { + ret := _m.ctrl.Call(_m, "IsTLSEnabled") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsTLSEnabled indicates an expected call of IsTLSEnabled +func (_mr *MockConfigMockRecorder) IsTLSEnabled() *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "IsTLSEnabled") +} + +// KeyStorePath mocks base method +func (_m *MockConfig) KeyStorePath() string { + ret := _m.ctrl.Call(_m, "KeyStorePath") ret0, _ := ret[0].(string) return ret0 } -// GetKeyStorePath indicates an expected call of GetKeyStorePath -func (_mr *MockConfigMockRecorder) GetKeyStorePath() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetKeyStorePath") +// KeyStorePath indicates an expected call of KeyStorePath +func (_mr *MockConfigMockRecorder) KeyStorePath() *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "KeyStorePath") } -// GetMspID mocks base method -func (_m *MockConfig) GetMspID(_param0 string) (string, error) { - ret := _m.ctrl.Call(_m, "GetMspID", _param0) +// MspID mocks base method +func (_m *MockConfig) MspID(_param0 string) (string, error) { + ret := _m.ctrl.Call(_m, "MspID", _param0) ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetMspID indicates an expected call of GetMspID -func (_mr *MockConfigMockRecorder) GetMspID(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetMspID", arg0) +// MspID indicates an expected call of MspID +func (_mr *MockConfigMockRecorder) MspID(arg0 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "MspID", arg0) } -// GetNetworkConfig mocks base method -func (_m *MockConfig) GetNetworkConfig() (*api.NetworkConfig, error) { - ret := _m.ctrl.Call(_m, "GetNetworkConfig") +// NetworkConfig mocks base method +func (_m *MockConfig) NetworkConfig() (*api.NetworkConfig, error) { + ret := _m.ctrl.Call(_m, "NetworkConfig") ret0, _ := ret[0].(*api.NetworkConfig) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetNetworkConfig indicates an expected call of GetNetworkConfig -func (_mr *MockConfigMockRecorder) GetNetworkConfig() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetNetworkConfig") +// NetworkConfig indicates an expected call of NetworkConfig +func (_mr *MockConfigMockRecorder) NetworkConfig() *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "NetworkConfig") } -// GetOrdererConfig mocks base method -func (_m *MockConfig) GetOrdererConfig(_param0 string) (*api.OrdererConfig, error) { - ret := _m.ctrl.Call(_m, "GetOrdererConfig", _param0) +// OrdererConfig mocks base method +func (_m *MockConfig) OrdererConfig(_param0 string) (*api.OrdererConfig, error) { + ret := _m.ctrl.Call(_m, "OrdererConfig", _param0) ret0, _ := ret[0].(*api.OrdererConfig) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetOrdererConfig indicates an expected call of GetOrdererConfig -func (_mr *MockConfigMockRecorder) GetOrdererConfig(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetOrdererConfig", arg0) +// OrdererConfig indicates an expected call of OrdererConfig +func (_mr *MockConfigMockRecorder) OrdererConfig(arg0 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "OrdererConfig", arg0) } -// GetPeersConfig mocks base method -func (_m *MockConfig) GetPeersConfig(_param0 string) ([]api.PeerConfig, error) { - ret := _m.ctrl.Call(_m, "GetPeersConfig", _param0) +// PeersConfig mocks base method +func (_m *MockConfig) PeersConfig(_param0 string) ([]api.PeerConfig, error) { + ret := _m.ctrl.Call(_m, "PeersConfig", _param0) ret0, _ := ret[0].([]api.PeerConfig) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetPeersConfig indicates an expected call of GetPeersConfig -func (_mr *MockConfigMockRecorder) GetPeersConfig(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetPeersConfig", arg0) +// PeersConfig indicates an expected call of PeersConfig +func (_mr *MockConfigMockRecorder) PeersConfig(arg0 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "PeersConfig", arg0) } -// GetRandomOrdererConfig mocks base method -func (_m *MockConfig) GetRandomOrdererConfig() (*api.OrdererConfig, error) { - ret := _m.ctrl.Call(_m, "GetRandomOrdererConfig") +// RandomOrdererConfig mocks base method +func (_m *MockConfig) RandomOrdererConfig() (*api.OrdererConfig, error) { + ret := _m.ctrl.Call(_m, "RandomOrdererConfig") ret0, _ := ret[0].(*api.OrdererConfig) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetRandomOrdererConfig indicates an expected call of GetRandomOrdererConfig -func (_mr *MockConfigMockRecorder) GetRandomOrdererConfig() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetRandomOrdererConfig") +// RandomOrdererConfig indicates an expected call of RandomOrdererConfig +func (_mr *MockConfigMockRecorder) RandomOrdererConfig() *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "RandomOrdererConfig") } -// GetSecurityAlgorithm mocks base method -func (_m *MockConfig) GetSecurityAlgorithm() string { - ret := _m.ctrl.Call(_m, "GetSecurityAlgorithm") +// SecurityAlgorithm mocks base method +func (_m *MockConfig) SecurityAlgorithm() string { + ret := _m.ctrl.Call(_m, "SecurityAlgorithm") ret0, _ := ret[0].(string) return ret0 } -// GetSecurityAlgorithm indicates an expected call of GetSecurityAlgorithm -func (_mr *MockConfigMockRecorder) GetSecurityAlgorithm() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetSecurityAlgorithm") +// SecurityAlgorithm indicates an expected call of SecurityAlgorithm +func (_mr *MockConfigMockRecorder) SecurityAlgorithm() *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "SecurityAlgorithm") } -// GetSecurityLevel mocks base method -func (_m *MockConfig) GetSecurityLevel() int { - ret := _m.ctrl.Call(_m, "GetSecurityLevel") +// SecurityLevel mocks base method +func (_m *MockConfig) SecurityLevel() int { + ret := _m.ctrl.Call(_m, "SecurityLevel") ret0, _ := ret[0].(int) return ret0 } -// GetSecurityLevel indicates an expected call of GetSecurityLevel -func (_mr *MockConfigMockRecorder) GetSecurityLevel() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetSecurityLevel") +// SecurityLevel indicates an expected call of SecurityLevel +func (_mr *MockConfigMockRecorder) SecurityLevel() *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "SecurityLevel") } -// GetTLSCACertPool mocks base method -func (_m *MockConfig) GetTLSCACertPool(_param0 string) (*x509.CertPool, error) { - ret := _m.ctrl.Call(_m, "GetTLSCACertPool", _param0) +// TLSCACertPool mocks base method +func (_m *MockConfig) TLSCACertPool(_param0 string) (*x509.CertPool, error) { + ret := _m.ctrl.Call(_m, "TLSCACertPool", _param0) ret0, _ := ret[0].(*x509.CertPool) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetTLSCACertPool indicates an expected call of GetTLSCACertPool -func (_mr *MockConfigMockRecorder) GetTLSCACertPool(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetTLSCACertPool", arg0) +// TLSCACertPool indicates an expected call of TLSCACertPool +func (_mr *MockConfigMockRecorder) TLSCACertPool(arg0 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TLSCACertPool", arg0) } -// GetTLSCACertPoolFromRoots mocks base method -func (_m *MockConfig) GetTLSCACertPoolFromRoots(_param0 [][]byte) (*x509.CertPool, error) { - ret := _m.ctrl.Call(_m, "GetTLSCACertPoolFromRoots", _param0) +// TLSCACertPoolFromRoots mocks base method +func (_m *MockConfig) TLSCACertPoolFromRoots(_param0 [][]byte) (*x509.CertPool, error) { + ret := _m.ctrl.Call(_m, "TLSCACertPoolFromRoots", _param0) ret0, _ := ret[0].(*x509.CertPool) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetTLSCACertPoolFromRoots indicates an expected call of GetTLSCACertPoolFromRoots -func (_mr *MockConfigMockRecorder) GetTLSCACertPoolFromRoots(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetTLSCACertPoolFromRoots", arg0) -} - -// IsSecurityEnabled mocks base method -func (_m *MockConfig) IsSecurityEnabled() bool { - ret := _m.ctrl.Call(_m, "IsSecurityEnabled") - ret0, _ := ret[0].(bool) - return ret0 -} - -// IsSecurityEnabled indicates an expected call of IsSecurityEnabled -func (_mr *MockConfigMockRecorder) IsSecurityEnabled() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "IsSecurityEnabled") -} - -// IsTLSEnabled mocks base method -func (_m *MockConfig) IsTLSEnabled() bool { - ret := _m.ctrl.Call(_m, "IsTLSEnabled") - ret0, _ := ret[0].(bool) - return ret0 -} - -// IsTLSEnabled indicates an expected call of IsTLSEnabled -func (_mr *MockConfigMockRecorder) IsTLSEnabled() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "IsTLSEnabled") +// TLSCACertPoolFromRoots indicates an expected call of TLSCACertPoolFromRoots +func (_mr *MockConfigMockRecorder) TLSCACertPoolFromRoots(arg0 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TLSCACertPoolFromRoots", arg0) } // TcertBatchSize mocks base method diff --git a/fabric-txn/admin/transactionconfig.go b/fabric-txn/admin/transactionconfig.go index e213a42dbf..79da98bf4e 100644 --- a/fabric-txn/admin/transactionconfig.go +++ b/fabric-txn/admin/transactionconfig.go @@ -78,7 +78,7 @@ func SendInstantiateCC(channel api.Channel, chainCodeID string, channelID string // CreateOrUpdateChannel creates a channel if it does not exist or updates a channel // if it does and a different channelConfig is used func CreateOrUpdateChannel(client api.FabricClient, ordererUser api.User, orgUser api.User, channel api.Channel, channelConfig string) error { - logger.Debugf("***** Creating or updating channel: %s *****\n", channel.GetName()) + logger.Debugf("***** Creating or updating channel: %s *****\n", channel.Name()) currentUser := client.GetUserContext() defer client.SetUserContext(currentUser) @@ -117,8 +117,8 @@ func CreateOrUpdateChannel(client api.FabricClient, ordererUser api.User, orgUse } request := api.CreateChannelRequest{ - Name: channel.GetName(), - Orderer: channel.GetOrderers()[0], + Name: channel.Name(), + Orderer: channel.Orderers()[0], Config: config, Signatures: configSignatures, TxID: txID, @@ -159,7 +159,7 @@ func JoinChannel(client api.FabricClient, orgUser api.User, channel api.Channel) TxID: txID, Nonce: nonce, } - genesisBlock, err := channel.GetGenesisBlock(genesisBlockRequest) + genesisBlock, err := channel.GenesisBlock(genesisBlockRequest) if err != nil { return fmt.Errorf("Error getting genesis block: %v", err) } @@ -173,7 +173,7 @@ func JoinChannel(client api.FabricClient, orgUser api.User, channel api.Channel) return fmt.Errorf("Could not compute TxID: %s", err) } joinChannelRequest := &api.JoinChannelRequest{ - Targets: channel.GetPeers(), + Targets: channel.Peers(), GenesisBlock: genesisBlock, TxID: txID, Nonce: nonce, diff --git a/fabric-txn/defaultImpl/defaultImpl.go b/fabric-txn/defaultImpl/defaultImpl.go index 43cb61efc8..539b00cfec 100644 --- a/fabric-txn/defaultImpl/defaultImpl.go +++ b/fabric-txn/defaultImpl/defaultImpl.go @@ -102,7 +102,7 @@ func NewUser(client api.FabricClient, msp api.FabricCAClient, name string, pwd s } if user == nil { - mspID, err := client.GetConfig().GetMspID(orgName) + mspID, err := client.GetConfig().MspID(orgName) if err != nil { return nil, fmt.Errorf("Error reading MSP ID config: %s", err) } @@ -127,7 +127,7 @@ func NewUser(client api.FabricClient, msp api.FabricCAClient, name string, pwd s // The user should already be pre-enrolled. func NewPreEnrolledUser(client api.FabricClient, privateKeyPath string, enrollmentCertPath string, username string, orgName string) (api.User, error) { - mspID, err := client.GetConfig().GetMspID(orgName) + mspID, err := client.GetConfig().MspID(orgName) if err != nil { return nil, fmt.Errorf("Error reading MSP ID config: %s", err) } diff --git a/fabric-txn/transaction.go b/fabric-txn/transaction.go index a536efa9c2..b42b88342f 100644 --- a/fabric-txn/transaction.go +++ b/fabric-txn/transaction.go @@ -26,7 +26,7 @@ func QueryChaincode(client api.FabricClient, channel api.Channel, chaincodeID st } transactionProposalResponses, _, err := internal.CreateAndSendTransactionProposal(channel, - chaincodeID, channel.GetName(), args, []api.Peer{channel.GetPrimaryPeer()}, nil) + chaincodeID, channel.Name(), args, []api.Peer{channel.PrimaryPeer()}, nil) if err != nil { return "", fmt.Errorf("CreateAndSendTransactionProposal returned error: %v", err) @@ -60,7 +60,7 @@ func InvokeChaincode(client api.FabricClient, channel api.Channel, targets []api } transactionProposalResponses, txID, err := internal.CreateAndSendTransactionProposal(channel, - chaincodeID, channel.GetName(), args, targets, transientData) + chaincodeID, channel.Name(), args, targets, transientData) if err != nil { return fmt.Errorf("CreateAndSendTransactionProposal returned error: %v", err) diff --git a/pkg/config/config.go b/pkg/config/config.go index 6f6173b5bf..eb7e7cec2a 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -84,8 +84,8 @@ func InitConfigWithCmdRoot(configFile string, cmdRootPrefix string) (api.Config, } -func (c *config) GetCAConfig(org string) (*api.CAConfig, error) { - config, err := c.GetNetworkConfig() +func (c *config) CAConfig(org string) (*api.CAConfig, error) { + config, err := c.NetworkConfig() if err != nil { return nil, err } @@ -95,8 +95,8 @@ func (c *config) GetCAConfig(org string) (*api.CAConfig, error) { } //GetCAServerCertFiles Read configuration option for the server certificate files -func (c *config) GetCAServerCertFiles(org string) ([]string, error) { - config, err := c.GetNetworkConfig() +func (c *config) CAServerCertFiles(org string) ([]string, error) { + config, err := c.NetworkConfig() if err != nil { return nil, err } @@ -111,8 +111,8 @@ func (c *config) GetCAServerCertFiles(org string) ([]string, error) { } //GetCAClientKeyFile Read configuration option for the fabric CA client key file -func (c *config) GetCAClientKeyFile(org string) (string, error) { - config, err := c.GetNetworkConfig() +func (c *config) CAClientKeyFile(org string) (string, error) { + config, err := c.NetworkConfig() if err != nil { return "", err } @@ -122,8 +122,8 @@ func (c *config) GetCAClientKeyFile(org string) (string, error) { } //GetCAClientCertFile Read configuration option for the fabric CA client cert file -func (c *config) GetCAClientCertFile(org string) (string, error) { - config, err := c.GetNetworkConfig() +func (c *config) CAClientCertFile(org string) (string, error) { + config, err := c.NetworkConfig() if err != nil { return "", err } @@ -132,9 +132,9 @@ func (c *config) GetCAClientCertFile(org string) (string, error) { "$GOPATH", os.Getenv("GOPATH"), -1), nil } -// GetMspID returns the MSP ID for the requested organization -func (c *config) GetMspID(org string) (string, error) { - config, err := c.GetNetworkConfig() +// MspID returns the MSP ID for the requested organization +func (c *config) MspID(org string) (string, error) { + config, err := c.NetworkConfig() if err != nil { return "", err } @@ -142,9 +142,9 @@ func (c *config) GetMspID(org string) (string, error) { return config.Organizations[org].MspID, nil } -// GetFabricClientViper returns the internal viper instance used by the +// FabricClientViper returns the internal viper instance used by the // SDK to read configuration options -func (c *config) GetFabricClientViper() *viper.Viper { +func (c *config) FabricClientViper() *viper.Viper { return myViper } @@ -158,9 +158,9 @@ func (c *config) cacheNetworkConfiguration() error { return err } -// GetRandomOrdererConfig returns a pseudo-random orderer from the network config -func (c *config) GetRandomOrdererConfig() (*api.OrdererConfig, error) { - config, err := c.GetNetworkConfig() +// RandomOrdererConfig returns a pseudo-random orderer from the network config +func (c *config) RandomOrdererConfig() (*api.OrdererConfig, error) { + config, err := c.NetworkConfig() if err != nil { return nil, err } @@ -182,9 +182,9 @@ func (c *config) GetRandomOrdererConfig() (*api.OrdererConfig, error) { return nil, nil } -// GetOrdererConfig returns the requested orderer -func (c *config) GetOrdererConfig(name string) (*api.OrdererConfig, error) { - config, err := c.GetNetworkConfig() +// OrdererConfig returns the requested orderer +func (c *config) OrdererConfig(name string) (*api.OrdererConfig, error) { + config, err := c.NetworkConfig() if err != nil { return nil, err } @@ -196,10 +196,10 @@ func (c *config) GetOrdererConfig(name string) (*api.OrdererConfig, error) { return &orderer, nil } -// GetPeersConfig Retrieves the fabric peers for the specified org from the +// PeersConfig Retrieves the fabric peers for the specified org from the // config file provided -func (c *config) GetPeersConfig(org string) ([]api.PeerConfig, error) { - config, err := c.GetNetworkConfig() +func (c *config) PeersConfig(org string) ([]api.PeerConfig, error) { + config, err := c.NetworkConfig() if err != nil { return nil, err } @@ -224,8 +224,8 @@ func (c *config) GetPeersConfig(org string) ([]api.PeerConfig, error) { return peers, nil } -// GetNetworkConfig returns the network configuration defined in the config file -func (c *config) GetNetworkConfig() (*api.NetworkConfig, error) { +// NetworkConfig returns the network configuration defined in the config file +func (c *config) NetworkConfig() (*api.NetworkConfig, error) { if c.networkConfigCached { return c.networkConfig, nil } @@ -241,9 +241,9 @@ func (c *config) IsTLSEnabled() bool { return myViper.GetBool("client.tls.enabled") } -// GetTLSCACertPool ... +// TLSCACertPool ... // TODO: Should be related to configuration. -func (c *config) GetTLSCACertPool(tlsCertificate string) (*x509.CertPool, error) { +func (c *config) TLSCACertPool(tlsCertificate string) (*x509.CertPool, error) { certPool := x509.NewCertPool() if tlsCertificate != "" { rawData, err := ioutil.ReadFile(tlsCertificate) @@ -262,8 +262,8 @@ func (c *config) GetTLSCACertPool(tlsCertificate string) (*x509.CertPool, error) return certPool, nil } -// GetTLSCACertPoolFromRoots ... -func (c *config) GetTLSCACertPoolFromRoots(ordererRootCAs [][]byte) (*x509.CertPool, error) { +// TLSCACertPoolFromRoots ... +func (c *config) TLSCACertPoolFromRoots(ordererRootCAs [][]byte) (*x509.CertPool, error) { certPool := x509.NewCertPool() for _, root := range ordererRootCAs { @@ -288,34 +288,34 @@ func (c *config) TcertBatchSize() int { return myViper.GetInt("client.tcert.batch.size") } -// GetSecurityAlgorithm ... -func (c *config) GetSecurityAlgorithm() string { +// SecurityAlgorithm ... +func (c *config) SecurityAlgorithm() string { return myViper.GetString("client.security.hashAlgorithm") } -// GetSecurityLevel ... -func (c *config) GetSecurityLevel() int { +// SecurityLevel ... +func (c *config) SecurityLevel() int { return myViper.GetInt("client.security.level") } -// GetKeyStorePath returns the keystore path used by BCCSP -func (c *config) GetKeyStorePath() string { +// KeyStorePath returns the keystore path used by BCCSP +func (c *config) KeyStorePath() string { keystorePath := strings.Replace(myViper.GetString("client.keystore.path"), "$GOPATH", os.Getenv("GOPATH"), -1) return path.Join(keystorePath, "keystore") } -// GetCAKeystorePath returns the same path as GetKeyStorePath() without the +// CAKeystorePath returns the same path as KeyStorePath() without the // 'keystore' directory added. This is done because the fabric-ca-client // adds this to the path -func (c *config) GetCAKeyStorePath() string { +func (c *config) CAKeyStorePath() string { return strings.Replace(myViper.GetString("client.keystore.path"), "$GOPATH", os.Getenv("GOPATH"), -1) } -// GetCryptoConfigPath ... -func (c *config) GetCryptoConfigPath() string { +// CryptoConfigPath ... +func (c *config) CryptoConfigPath() string { return strings.Replace(myViper.GetString("client.cryptoconfig.path"), "$GOPATH", os.Getenv("GOPATH"), -1) } @@ -335,15 +335,15 @@ func loadCAKey(rawData []byte) (*x509.Certificate, error) { return nil, errors.New("No pem data found") } -// GetCSPConfig ... -func (c *config) GetCSPConfig() *bccspFactory.FactoryOpts { +// CSPConfig ... +func (c *config) CSPConfig() *bccspFactory.FactoryOpts { return &bccspFactory.FactoryOpts{ ProviderName: "SW", SwOpts: &bccspFactory.SwOpts{ - HashFamily: c.GetSecurityAlgorithm(), - SecLevel: c.GetSecurityLevel(), + HashFamily: c.SecurityAlgorithm(), + SecLevel: c.SecurityLevel(), FileKeystore: &bccspFactory.FileKeystoreOpts{ - KeyStorePath: c.GetKeyStorePath(), + KeyStorePath: c.KeyStorePath(), }, Ephemeral: false, }, diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 0b7951b61b..96d9eb34a2 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -9,6 +9,7 @@ package config import ( "fmt" "os" + "strings" "testing" api "github.com/hyperledger/fabric-sdk-go/api" @@ -18,18 +19,113 @@ import ( var configImpl api.Config var org1 = "peerorg1" +var validRootCA = `-----BEGIN CERTIFICATE----- +MIICYjCCAgmgAwIBAgIUB3CTDOU47sUC5K4kn/Caqnh114YwCgYIKoZIzj0EAwIw +fzELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh +biBGcmFuY2lzY28xHzAdBgNVBAoTFkludGVybmV0IFdpZGdldHMsIEluYy4xDDAK +BgNVBAsTA1dXVzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wHhcNMTYxMDEyMTkzMTAw +WhcNMjExMDExMTkzMTAwWjB/MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZv +cm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEfMB0GA1UEChMWSW50ZXJuZXQg +V2lkZ2V0cywgSW5jLjEMMAoGA1UECxMDV1dXMRQwEgYDVQQDEwtleGFtcGxlLmNv +bTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABKIH5b2JaSmqiQXHyqC+cmknICcF +i5AddVjsQizDV6uZ4v6s+PWiJyzfA/rTtMvYAPq/yeEHpBUB1j053mxnpMujYzBh +MA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBQXZ0I9 +qp6CP8TFHZ9bw5nRtZxIEDAfBgNVHSMEGDAWgBQXZ0I9qp6CP8TFHZ9bw5nRtZxI +EDAKBggqhkjOPQQDAgNHADBEAiAHp5Rbp9Em1G/UmKn8WsCbqDfWecVbZPQj3RK4 +oG5kQQIgQAe4OOKYhJdh3f7URaKfGTf492/nmRmtK+ySKjpHSrU= +-----END CERTIFICATE-----` + func TestCAConfig(t *testing.T) { - config, err := configImpl.GetCAConfig(org1) + + //Test config + vConfig := viper.New() + vConfig.SetConfigFile("../../test/fixtures/config/config_test.yaml") + vConfig.ReadInConfig() + + //Test TLS config + if vConfig.GetBool("client.tls.enabled") != configImpl.IsTLSEnabled() { + t.Fatalf("Incorrect TLS config flag") + } + + //Test Security enabled + if vConfig.GetBool("client.security.enabled") != configImpl.IsSecurityEnabled() { + t.Fatalf("Incorrect Security config flag") + } + + //Test Tcert batch size + if vConfig.GetInt("client.tcert.batch.size") != configImpl.TcertBatchSize() { + t.Fatalf("Incorrect Tcert batch size") + } + + //Test Security Algorithm + if vConfig.GetString("client.security.hashAlgorithm") != configImpl.SecurityAlgorithm() { + t.Fatalf("Incorrect security hash algorithm") + } + + //Test Security level + if vConfig.GetInt("client.security.level") != configImpl.SecurityLevel() { + t.Fatalf("Incorrect Security Level") + } + + //Test Crypto config path + crossCheckWithViperConfig(myViper.GetString("client.cryptoconfig.path"), configImpl.CryptoConfigPath(), "Incorrect crypto config path", t) + +} + +func TestTLSACAConfig(t *testing.T) { + + //Test TLSCA Cert Pool (Negative test case + _, err := configImpl.TLSCACertPool("some random invalid path") + if err == nil { + t.Fatalf("TLS CA cert pool was supposed to fail") + } + + //Test TLSCA Cert Pool from roots(Negative test case + samplebytes := [][]byte{ + []byte(validRootCA), + } + _, err = configImpl.TLSCACertPoolFromRoots(samplebytes) if err != nil { - t.Fatal(err) + t.Fatalf("TLS CA cert pool fetch failed, reason %v", err) + } + + //Test TLSCA Cert Pool from roots(Negative test case + samplebytes = [][]byte{ + []byte("sample invalid string"), } - if config.Name != "ca-org1" { - t.Fatalf("caname doesn't match. got: %s", config.Name) + _, err = configImpl.TLSCACertPoolFromRoots(samplebytes) + if err == nil { + t.Fatalf("TLS CA cert pool was supposed to fail") + } + +} + +func TestCSPConfig(t *testing.T) { + cspconfig := configImpl.CSPConfig() + + if cspconfig.ProviderName != "SW" { + t.Fatalf("In correct provider name found for cspconfig") + } + + if cspconfig.SwOpts.HashFamily != configImpl.SecurityAlgorithm() { + t.Fatalf("In correct hashfamily found for cspconfig") + } + + if cspconfig.SwOpts.SecLevel != configImpl.SecurityLevel() { + t.Fatalf("In correct security level found for cspconfig") + } + + if cspconfig.SwOpts.Ephemeral { + t.Fatalf("In correct Ephemeral found for cspconfig") + } + + if cspconfig.SwOpts.FileKeystore.KeyStorePath != configImpl.KeyStorePath() { + t.Fatalf("In correct keystore path found for cspconfig") } } func TestGetPeersConfig(t *testing.T) { - pc, err := configImpl.GetPeersConfig(org1) + pc, err := configImpl.PeersConfig(org1) if err != nil { t.Fatalf(err.Error()) } @@ -52,6 +148,52 @@ func TestGetPeersConfig(t *testing.T) { } +func TestInitConfig(t *testing.T) { + //Test init config + //...Positive case + _, err := InitConfig("../../test/fixtures/config/config_test.yaml") + if err != nil { + t.Fatal("Failed to initialize config") + } + //...Negative case + _, err = InitConfig("invalid file location") + if err == nil { + t.Fatal("Config file initialization is supposed to fail") + } + + //Test init config with cmd root + cmdRoot := "fabric_sdk" + _, err = InitConfigWithCmdRoot("../../test/fixtures/config/config_test.yaml", cmdRoot) + if err != nil { + t.Fatal("Failed to initialize config with cmd root") + } + + //Test if Viper is initialized after calling init config + myViper := configImpl.FabricClientViper() + + if myViper.GetString("client.security.hashAlgorithm") != configImpl.SecurityAlgorithm() { + t.Fatal("Config initialized with incorrect viper configuration") + } + +} + +func TestInitConfigPanic(t *testing.T) { + myViper := configImpl.FabricClientViper() + existingLogLevel := myViper.Get("client.logging.level") + myViper.Set("client.logging.level", "INVALID") + + defer func() { + if r := recover(); r == nil { + t.Errorf("Init config with cmdroot was supposed to panic") + } else { + //Setting it back during panic so as not to fail other tests + myViper.Set("client.logging.level", existingLogLevel) + } + + }() + InitConfigWithCmdRoot("../../test/fixtures/config/config_test.yaml", "fabric-sdk") +} + // Test case to create a new viper instance to prevent conflict with existing // viper instances in applications that use the SDK func TestMultipleVipers(t *testing.T) { @@ -70,6 +212,7 @@ func TestMultipleVipers(t *testing.T) { if err != nil { fmt.Println(err.Error()) } + // Make sure initial value is unaffected testValue2 := viper.GetString("test.testKey") if testValue2 != "testvalue" { @@ -131,7 +274,7 @@ func TestEnvironmentVariablesSpecificCmdRoot(t *testing.T) { } func TestNetworkConfig(t *testing.T) { - conf, err := configImpl.GetNetworkConfig() + conf, err := configImpl.NetworkConfig() if err != nil { t.Fatal(err) } @@ -154,3 +297,10 @@ func TestMain(m *testing.M) { } os.Exit(m.Run()) } + +func crossCheckWithViperConfig(expected string, actual string, message string, t *testing.T) { + expected = strings.Replace(expected, "$GOPATH", "", -1) + if !strings.HasSuffix(actual, expected) { + t.Fatalf(message) + } +} diff --git a/pkg/fabric-ca-client/fabricca.go b/pkg/fabric-ca-client/fabricca.go index 77d01be8c6..7632297b3e 100644 --- a/pkg/fabric-ca-client/fabricca.go +++ b/pkg/fabric-ca-client/fabricca.go @@ -39,7 +39,7 @@ func NewFabricCAClient(config sdkApi.Config, org string) (sdkApi.FabricCAClient, Config: &fabric_ca.ClientConfig{}, } - conf, err := config.GetCAConfig(org) + conf, err := config.CAConfig(org) if err != nil { return nil, err } @@ -49,26 +49,26 @@ func NewFabricCAClient(config sdkApi.Config, org string) (sdkApi.FabricCAClient, //set server URL c.Config.URL = conf.ServerURL //certs file list - c.Config.TLS.CertFiles, err = config.GetCAServerCertFiles(org) + c.Config.TLS.CertFiles, err = config.CAServerCertFiles(org) if err != nil { return nil, err } // set key file and cert file - c.Config.TLS.Client.CertFile, err = config.GetCAClientCertFile(org) + c.Config.TLS.Client.CertFile, err = config.CAClientCertFile(org) if err != nil { return nil, err } - c.Config.TLS.Client.KeyFile, err = config.GetCAClientKeyFile(org) + c.Config.TLS.Client.KeyFile, err = config.CAClientKeyFile(org) if err != nil { return nil, err } //TLS flag enabled/disabled c.Config.TLS.Enabled = conf.TLSEnabled - c.Config.MSPDir = config.GetCAKeyStorePath() - c.Config.CSP = config.GetCSPConfig() + c.Config.MSPDir = config.CAKeyStorePath() + c.Config.CSP = config.CSPConfig() fabricCAClient := &fabricCA{fabricCAClient: c} logger.Infof("Constructed fabricCAClient instance: %v", fabricCAClient) diff --git a/pkg/fabric-ca-client/mocks/mockconfig.go b/pkg/fabric-ca-client/mocks/mockconfig.go index 9bfefb73ca..cfb325d411 100644 --- a/pkg/fabric-ca-client/mocks/mockconfig.go +++ b/pkg/fabric-ca-client/mocks/mockconfig.go @@ -24,34 +24,34 @@ func NewMockConfig() api.Config { return &MockConfig{} } -// GetCAConfig not implemented -func (c *MockConfig) GetCAConfig(org string) (*api.CAConfig, error) { +// CAConfig not implemented +func (c *MockConfig) CAConfig(org string) (*api.CAConfig, error) { return &api.CAConfig{}, nil } -//GetCAServerCertFiles Read configuration option for the server certificate files -func (c *MockConfig) GetCAServerCertFiles(org string) ([]string, error) { +// CAServerCertFiles Read configuration option for the server certificate files +func (c *MockConfig) CAServerCertFiles(org string) ([]string, error) { return nil, nil } -//GetCAClientKeyFile Read configuration option for the fabric CA client key file -func (c *MockConfig) GetCAClientKeyFile(org string) (string, error) { +// CAClientKeyFile Read configuration option for the fabric CA client key file +func (c *MockConfig) CAClientKeyFile(org string) (string, error) { return "", nil } -//GetCAClientCertFile Read configuration option for the fabric CA client cert file -func (c *MockConfig) GetCAClientCertFile(org string) (string, error) { +// CAClientCertFile Read configuration option for the fabric CA client cert file +func (c *MockConfig) CAClientCertFile(org string) (string, error) { return "", nil } -// GetFabricClientViper returns the internal viper instance used by the +// FabricClientViper returns the internal viper instance used by the // SDK to read configuration options -func (c *MockConfig) GetFabricClientViper() *viper.Viper { +func (c *MockConfig) FabricClientViper() *viper.Viper { return nil } -// GetPeersConfig Retrieves the fabric peers from the config file provided -func (c *MockConfig) GetPeersConfig(org string) ([]api.PeerConfig, error) { +// PeersConfig Retrieves the fabric peers from the config file provided +func (c *MockConfig) PeersConfig(org string) ([]api.PeerConfig, error) { return nil, nil } @@ -60,13 +60,13 @@ func (c *MockConfig) IsTLSEnabled() bool { return false } -// GetTLSCACertPool ... -func (c *MockConfig) GetTLSCACertPool(tlsCertificate string) (*x509.CertPool, error) { +// TLSCACertPool ... +func (c *MockConfig) TLSCACertPool(tlsCertificate string) (*x509.CertPool, error) { return nil, nil } -// GetTLSCACertPoolFromRoots ... -func (c *MockConfig) GetTLSCACertPoolFromRoots(ordererRootCAs [][]byte) (*x509.CertPool, error) { +// TLSCACertPoolFromRoots ... +func (c *MockConfig) TLSCACertPoolFromRoots(ordererRootCAs [][]byte) (*x509.CertPool, error) { return nil, nil } @@ -80,53 +80,53 @@ func (c *MockConfig) TcertBatchSize() int { return 0 } -// GetSecurityAlgorithm ... -func (c *MockConfig) GetSecurityAlgorithm() string { +// SecurityAlgorithm ... +func (c *MockConfig) SecurityAlgorithm() string { return "" } -// GetSecurityLevel ... -func (c *MockConfig) GetSecurityLevel() int { +// SecurityLevel ... +func (c *MockConfig) SecurityLevel() int { return 0 } -// GetRandomOrdererConfig not implemented -func (c *MockConfig) GetRandomOrdererConfig() (*api.OrdererConfig, error) { +// RandomOrdererConfig not implemented +func (c *MockConfig) RandomOrdererConfig() (*api.OrdererConfig, error) { return nil, nil } -// GetOrdererConfig not implemented -func (c *MockConfig) GetOrdererConfig(name string) (*api.OrdererConfig, error) { +// OrdererConfig not implemented +func (c *MockConfig) OrdererConfig(name string) (*api.OrdererConfig, error) { return nil, nil } -// GetMspID ... -func (c *MockConfig) GetMspID(org string) (string, error) { +// MspID ... +func (c *MockConfig) MspID(org string) (string, error) { return "", nil } -// GetKeyStorePath ... -func (c *MockConfig) GetKeyStorePath() string { +// KeyStorePath ... +func (c *MockConfig) KeyStorePath() string { return "" } -// GetCAKeyStorePath not implemented -func (c *MockConfig) GetCAKeyStorePath() string { +// CAKeyStorePath not implemented +func (c *MockConfig) CAKeyStorePath() string { return "" } -// GetCryptoConfigPath ... -func (c *MockConfig) GetCryptoConfigPath() string { +// CryptoConfigPath ... +func (c *MockConfig) CryptoConfigPath() string { return "" } -// GetCSPConfig ... -func (c *MockConfig) GetCSPConfig() *bccspFactory.FactoryOpts { +// CSPConfig ... +func (c *MockConfig) CSPConfig() *bccspFactory.FactoryOpts { return nil } -// GetNetworkConfig not implemented -func (c *MockConfig) GetNetworkConfig() (*api.NetworkConfig, error) { +// NetworkConfig not implemented +func (c *MockConfig) NetworkConfig() (*api.NetworkConfig, error) { return nil, nil } diff --git a/pkg/fabric-client/channel/channel.go b/pkg/fabric-client/channel/channel.go index cdff937f31..8d12a0e2b0 100644 --- a/pkg/fabric-client/channel/channel.go +++ b/pkg/fabric-client/channel/channel.go @@ -91,22 +91,22 @@ func (c *channel) QueryExtensionInterface() api.ChannelExtension { return c } -// GetClientContext returns the Client that was passed in to NewChannel -func (c *channel) GetClientContext() api.FabricClient { +// ClientContext returns the Client that was passed in to NewChannel +func (c *channel) ClientContext() api.FabricClient { return c.clientContext } -// GetProposalBytes returns the serialized transaction. -func (c *channel) GetProposalBytes(tp *api.TransactionProposal) ([]byte, error) { +// ProposalBytes returns the serialized transaction. +func (c *channel) ProposalBytes(tp *api.TransactionProposal) ([]byte, error) { return proto.Marshal(tp.SignedProposal) } -// GetName ... +// Name ... /** * Get the channel name. * @returns {string} The name of the channel. */ -func (c *channel) GetName() string { +func (c *channel) Name() string { return c.name } @@ -118,11 +118,11 @@ func (c *channel) IsSecurityEnabled() bool { return c.securityEnabled } -// GetTCertBatchSize ... +// TCertBatchSize ... /** * Get the tcert batch size. */ -func (c *channel) GetTCertBatchSize() int { +func (c *channel) TCertBatchSize() int { return c.tcertBatchSize } @@ -163,12 +163,12 @@ func (c *channel) RemovePeer(peer api.Peer) { } } -// GetPeers ... +// Peers ... /** * Get peers of a channel from local information. * @returns {[]Peer} The peer list on the channel. */ -func (c *channel) GetPeers() []api.Peer { +func (c *channel) Peers() []api.Peer { var peersArray []api.Peer for _, v := range c.peers { peersArray = append(peersArray, v) @@ -176,9 +176,9 @@ func (c *channel) GetPeers() []api.Peer { return peersArray } -// GetAnchorPeers returns the anchor peers for this channel. +// AnchorPeers returns the anchor peers for this channel. // Note: channel.Initialize() must be called first to retrieve anchor peers -func (c *channel) GetAnchorPeers() []api.OrgAnchorPeer { +func (c *channel) AnchorPeers() []api.OrgAnchorPeer { anchors := []api.OrgAnchorPeer{} for _, anchor := range c.anchorPeers { anchors = append(anchors, *anchor) @@ -215,7 +215,7 @@ func (c *channel) SetPrimaryPeer(peer api.Peer) error { return nil } -// GetPrimaryPeer ... +// PrimaryPeer ... /** * Get the primary peer * The peer to use for doing queries. @@ -223,7 +223,7 @@ func (c *channel) SetPrimaryPeer(peer api.Peer) error { * from map range will be used. * @returns {Peer} peer An instance of the Peer class. */ -func (c *channel) GetPrimaryPeer() api.Peer { +func (c *channel) PrimaryPeer() api.Peer { if c.primaryPeer != nil { return c.primaryPeer @@ -271,11 +271,11 @@ func (c *channel) RemoveOrderer(orderer api.Orderer) { } } -// GetOrderers ... +// Orderers ... /** * Get orderers of a channel. */ -func (c *channel) GetOrderers() []api.Orderer { +func (c *channel) Orderers() []api.Orderer { var orderersArray []api.Orderer for _, v := range c.orderers { orderersArray = append(orderersArray, v) @@ -292,14 +292,14 @@ func (c *channel) SetMSPManager(mspManager msp.MSPManager) { c.mspManager = mspManager } -// GetMSPManager returns the MSP Manager for this channel -func (c *channel) GetMSPManager() msp.MSPManager { +// MSPManager returns the MSP Manager for this channel +func (c *channel) MSPManager() msp.MSPManager { return c.mspManager } -// GetOrganizationUnits - to get identifier for the organization configured on the channel -func (c *channel) GetOrganizationUnits() ([]string, error) { - channelMSPManager := c.GetMSPManager() +// OrganizationUnits - to get identifier for the organization configured on the channel +func (c *channel) OrganizationUnits() ([]string, error) { + channelMSPManager := c.MSPManager() msps, err := channelMSPManager.GetMSPs() if err != nil { logger.Info("Cannot get channel manager") @@ -316,7 +316,7 @@ func (c *channel) GetOrganizationUnits() ([]string, error) { return orgIdentifiers, nil } -// GetGenesisBlock ... +// GenesisBlock ... /** * Will get the genesis block from the defined orderer that may be * used in a join request @@ -327,20 +327,20 @@ func (c *channel) GetOrganizationUnits() ([]string, error) { * @returns A Genesis block * @see /protos/peer/proposal_response.proto */ -func (c *channel) GetGenesisBlock(request *api.GenesisBlockRequest) (*common.Block, error) { - logger.Debug("GetGenesisBlock - start") +func (c *channel) GenesisBlock(request *api.GenesisBlockRequest) (*common.Block, error) { + logger.Debug("GenesisBlock - start") // verify that we have an orderer configured - if len(c.GetOrderers()) == 0 { - return nil, fmt.Errorf("GetGenesisBlock - error: Missing orderer assigned to this channel for the getGenesisBlock request") + if len(c.Orderers()) == 0 { + return nil, fmt.Errorf("GenesisBlock - error: Missing orderer assigned to this channel for the GenesisBlock request") } // verify that we have transaction id if request.TxID == "" { - return nil, fmt.Errorf("GetGenesisBlock - error: Missing txId input parameter with the required transaction identifier") + return nil, fmt.Errorf("GenesisBlock - error: Missing txId input parameter with the required transaction identifier") } // verify that we have the nonce if request.Nonce == nil { - return nil, fmt.Errorf("GetGenesisBlock - error: Missing nonce input parameter with the required single use number") + return nil, fmt.Errorf("GenesisBlock - error: Missing nonce input parameter with the required single use number") } creator, err := c.clientContext.GetIdentity() @@ -357,8 +357,8 @@ func (c *channel) GetGenesisBlock(request *api.GenesisBlockRequest) (*common.Blo Stop: seekStop, Behavior: ab.SeekInfo_BLOCK_UNTIL_READY, } - protos_utils.MakeChannelHeader(common.HeaderType_DELIVER_SEEK_INFO, 1, c.GetName(), 0) - seekInfoHeader, err := BuildChannelHeader(common.HeaderType_DELIVER_SEEK_INFO, c.GetName(), request.TxID, 0, "", time.Now()) + protos_utils.MakeChannelHeader(common.HeaderType_DELIVER_SEEK_INFO, 1, c.Name(), 0) + seekInfoHeader, err := BuildChannelHeader(common.HeaderType_DELIVER_SEEK_INFO, c.Name(), request.TxID, 0, "", time.Now()) if err != nil { return nil, fmt.Errorf("Error building channel header: %v", err) } @@ -393,7 +393,7 @@ func (c *channel) GetGenesisBlock(request *api.GenesisBlockRequest) (*common.Blo *
`targets` : required - An array of `Peer` objects that will join * this channel *
`block` : the genesis block of the channel -* see getGenesisBlock() method +* see genesisBlock() method *
`txId` : required - String of the transaction id *
`nonce` : required - Integer of the once time number * @returns {Promise} A Promise for a `ProposalResponse` @@ -498,30 +498,30 @@ func (c *channel) JoinChannel(request *api.JoinChannelRequest) error { * @see /protos/orderer/ab.proto * @see /protos/common/configtx.proto */ -func (c *channel) getChannelConfig() (*common.ConfigEnvelope, error) { - logger.Debugf("getChannelConfig - start for channel %s", c.name) +func (c *channel) channelConfig() (*common.ConfigEnvelope, error) { + logger.Debugf("channelConfig - start for channel %s", c.name) // Get the newest block - block, err := c.getBlock(fc.NewNewestSeekPosition()) + block, err := c.block(fc.NewNewestSeekPosition()) if err != nil { return nil, err } - logger.Debugf("GetChannelConfig - Retrieved newest block number: %d\n", block.Header.Number) + logger.Debugf("channelConfig - Retrieved newest block number: %d\n", block.Header.Number) // Get the index of the last config block lastConfig, err := fc.GetLastConfigFromBlock(block) if err != nil { return nil, fmt.Errorf("Unable to get last config from block: %v", err) } - logger.Debugf("GetChannelConfig - Last config index: %d\n", lastConfig.Index) + logger.Debugf("channelConfig - Last config index: %d\n", lastConfig.Index) // Get the last config block - block, err = c.getBlock(fc.NewSpecificSeekPosition(lastConfig.Index)) + block, err = c.block(fc.NewSpecificSeekPosition(lastConfig.Index)) if err != nil { return nil, fmt.Errorf("Unable to retrieve block at index %d: %v", lastConfig.Index, err) } - logger.Debugf("GetChannelConfig - Last config block number %d, Number of tx: %d", block.Header.Number, len(block.Data.Data)) + logger.Debugf("channelConfig - Last config block number %d, Number of tx: %d", block.Header.Number, len(block.Data.Data)) if len(block.Data.Data) != 1 { return nil, fmt.Errorf("Config block must only contain one transaction but contains %d", len(block.Data.Data)) @@ -691,9 +691,9 @@ func (c *channel) QueryInfo() (*common.BlockchainInfo, error) { // prepare arguments to call qscc GetChainInfo function var args []string args = append(args, "GetChainInfo") - args = append(args, c.GetName()) + args = append(args, c.Name()) - payload, err := c.queryByChaincodeByTarget("qscc", args, c.GetPrimaryPeer()) + payload, err := c.queryByChaincodeByTarget("qscc", args, c.PrimaryPeer()) if err != nil { return nil, fmt.Errorf("Invoke qscc GetChainInfo return error: %v", err) } @@ -723,10 +723,10 @@ func (c *channel) QueryBlockByHash(blockHash []byte) (*common.Block, error) { // prepare arguments to call qscc GetBlockByNumber function var args []string args = append(args, "GetBlockByHash") - args = append(args, c.GetName()) + args = append(args, c.Name()) args = append(args, string(blockHash[:len(blockHash)])) - payload, err := c.queryByChaincodeByTarget("qscc", args, c.GetPrimaryPeer()) + payload, err := c.queryByChaincodeByTarget("qscc", args, c.PrimaryPeer()) if err != nil { return nil, fmt.Errorf("Invoke qscc GetBlockByHash return error: %v", err) } @@ -756,10 +756,10 @@ func (c *channel) QueryBlock(blockNumber int) (*common.Block, error) { // prepare arguments to call qscc GetBlockByNumber function var args []string args = append(args, "GetBlockByNumber") - args = append(args, c.GetName()) + args = append(args, c.Name()) args = append(args, strconv.Itoa(blockNumber)) - payload, err := c.queryByChaincodeByTarget("qscc", args, c.GetPrimaryPeer()) + payload, err := c.queryByChaincodeByTarget("qscc", args, c.PrimaryPeer()) if err != nil { return nil, fmt.Errorf("Invoke qscc GetBlockByNumber return error: %v", err) } @@ -790,7 +790,7 @@ func (c *channel) Initialize(configUpdate []byte) error { return nil } - configEnvelope, err := c.getChannelConfig() + configEnvelope, err := c.channelConfig() if err != nil { return fmt.Errorf("Unable to retrieve channel configuration from orderer service: %v", err) } @@ -815,10 +815,10 @@ func (c *channel) QueryTransaction(transactionID string) (*pb.ProcessedTransacti // prepare arguments to call qscc GetTransactionByID function var args []string args = append(args, "GetTransactionByID") - args = append(args, c.GetName()) + args = append(args, c.Name()) args = append(args, transactionID) - payload, err := c.queryByChaincodeByTarget("qscc", args, c.GetPrimaryPeer()) + payload, err := c.queryByChaincodeByTarget("qscc", args, c.PrimaryPeer()) if err != nil { return nil, fmt.Errorf("Invoke qscc GetBlockByNumber return error: %v", err) } @@ -840,7 +840,7 @@ func (c *channel) QueryTransaction(transactionID string) (*pb.ProcessedTransacti */ func (c *channel) QueryInstantiatedChaincodes() (*pb.ChaincodeQueryResponse, error) { - payload, err := c.queryByChaincodeByTarget("lscc", []string{"getchaincodes"}, c.GetPrimaryPeer()) + payload, err := c.queryByChaincodeByTarget("lscc", []string{"getchaincodes"}, c.PrimaryPeer()) if err != nil { return nil, fmt.Errorf("Invoke lscc getchaincodes return error: %v", err) } @@ -1007,7 +1007,7 @@ func (c *channel) SendTransactionProposal(proposal *api.TransactionProposal, ret return nil, fmt.Errorf("peers and target peers is nil or empty") } - return SendTransactionProposal(proposal, retry, c.GetPeers()) + return SendTransactionProposal(proposal, retry, c.Peers()) } return SendTransactionProposal(proposal, retry, targets) @@ -1157,12 +1157,13 @@ func (c *channel) SendTransaction(tx *api.Transaction) ([]*api.TransactionRespon if c.orderers == nil || len(c.orderers) == 0 { return nil, fmt.Errorf("orderers is nil") } - if tx == nil || tx.Proposal == nil || tx.Proposal.Proposal == nil { - return nil, fmt.Errorf("proposal is nil") - } if tx == nil { return nil, fmt.Errorf("Transaction is nil") } + if tx.Proposal == nil || tx.Proposal.Proposal == nil { + return nil, fmt.Errorf("proposal is nil") + } + // the original header hdr, err := protos_utils.GetHeader(tx.Proposal.Proposal.Header) if err != nil { @@ -1403,27 +1404,6 @@ func (c *channel) signProposal(proposal *pb.Proposal) (*pb.SignedProposal, error return &pb.SignedProposal{ProposalBytes: proposalBytes, Signature: signature}, nil } -// fetchGenesisBlock fetches the configuration block for this channel -func (c *channel) fetchGenesisBlock() (*common.Block, error) { - // Get user enrolment info and serialize for signing requests - creator, err := c.clientContext.GetIdentity() - if err != nil { - return nil, fmt.Errorf("Error getting creator: %v", err) - } - // Seek block zero (the configuration tx for this channel) - payload := fc.CreateSeekGenesisBlockRequest(c.name, creator) - blockRequest, err := c.SignPayload(payload) - if err != nil { - return nil, fmt.Errorf("Error signing payload: %s", err) - } - // Request genesis block from ordering service - block, err := c.SendEnvelope(blockRequest) - if err != nil { - return nil, fmt.Errorf("Error from SendEnvelope: %s", err.Error()) - } - return block, nil -} - // internal utility method to build chaincode policy // FIXME: for now always construct a 'Signed By any member of an organization by mspid' policy func buildChaincodePolicy(mspid string) (*common.SignaturePolicyEnvelope, error) { @@ -1689,7 +1669,7 @@ func loadPolicy(configItems *configItems, versionsPolicy *common.ConfigPolicy, k } // getBlock retrieves the block at the given position -func (c *channel) getBlock(pos *ab.SeekPosition) (*common.Block, error) { +func (c *channel) block(pos *ab.SeekPosition) (*common.Block, error) { nonce, err := fc.GenerateRandomNonce() if err != nil { return nil, fmt.Errorf("error when generating nonce: %v", err) @@ -1705,7 +1685,7 @@ func (c *channel) getBlock(pos *ab.SeekPosition) (*common.Block, error) { return nil, fmt.Errorf("error when generating TX ID: %v", err) } - seekInfoHeader, err := BuildChannelHeader(common.HeaderType_DELIVER_SEEK_INFO, c.GetName(), txID, 0, "", time.Now()) + seekInfoHeader, err := BuildChannelHeader(common.HeaderType_DELIVER_SEEK_INFO, c.Name(), txID, 0, "", time.Now()) if err != nil { return nil, fmt.Errorf("error when building channel header: %v", err) } diff --git a/pkg/fabric-client/channel/channel_test.go b/pkg/fabric-client/channel/channel_test.go index c9b8a5e3e9..e0f45fc740 100644 --- a/pkg/fabric-client/channel/channel_test.go +++ b/pkg/fabric-client/channel/channel_test.go @@ -46,7 +46,7 @@ func TestChannelMethods(t *testing.T) { if err != nil { t.Fatalf("NewChannel return error[%s]", err) } - if channel.GetName() != "testChannel" { + if channel.Name() != "testChannel" { t.Fatalf("NewChannel create wrong channel") } @@ -108,7 +108,7 @@ func TestPrimaryPeer(t *testing.T) { } // Test primary defaults to channel peer - primary := channel.GetPrimaryPeer() + primary := channel.PrimaryPeer() if primary.URL() != peer1.URL() { t.Fatalf("Primary Peer failed to default") } @@ -135,7 +135,7 @@ func TestPrimaryPeer(t *testing.T) { } // Test primary equals our choice - primary = channel.GetPrimaryPeer() + primary = channel.PrimaryPeer() if primary.URL() != peer2.URL() || primary.Name() != peer2.Name() { t.Fatalf("Primary and our choice are not equal") } @@ -195,7 +195,7 @@ func TestJoinChannel(t *testing.T) { TxID: txID, Nonce: nonce, } - genesisBlock, err := channel.GetGenesisBlock(genesisBlockReqeust) + genesisBlock, err := channel.GenesisBlock(genesisBlockReqeust) if err == nil { t.Fatalf("Should not have been able to get genesis block because of orderer missing") } @@ -204,7 +204,7 @@ func TestJoinChannel(t *testing.T) { if err != nil { t.Fatalf("Error adding orderer: %v", err) } - genesisBlock, err = channel.GetGenesisBlock(genesisBlockReqeust) + genesisBlock, err = channel.GenesisBlock(genesisBlockReqeust) if err != nil { t.Fatalf("Error getting genesis block: %v", err) } @@ -317,7 +317,7 @@ func TestChannelInitializeFromOrderer(t *testing.T) { if err != nil { t.Fatalf("channel Initialize failed : %v", err) } - mspManager := channel.GetMSPManager() + mspManager := channel.MSPManager() if mspManager == nil { t.Fatalf("nil MSPManager on new channel") } @@ -346,7 +346,7 @@ func TestOrganizationUnits(t *testing.T) { org2MSPID := "ORG2MSP" channel, _ := setupTestChannel() - orgUnits, err := channel.GetOrganizationUnits() + orgUnits, err := channel.OrganizationUnits() if len(orgUnits) > 0 { t.Fatalf("Returned non configured organizational unit : %v", err) } @@ -354,7 +354,7 @@ func TestOrganizationUnits(t *testing.T) { MockConfigGroupBuilder: mocks.MockConfigGroupBuilder{ ModPolicy: "Admins", MSPNames: []string{ - channel.GetName(), + channel.Name(), org1MSPID, org2MSPID, }, @@ -376,12 +376,12 @@ func TestOrganizationUnits(t *testing.T) { if err != nil { t.Fatalf("channel Initialize failed : %v", err) } - orgUnits, err = channel.GetOrganizationUnits() + orgUnits, err = channel.OrganizationUnits() if err != nil { t.Fatalf("CANNOT retrieve organizational units : %v", err) } - if !isValueInList(channel.GetName(), orgUnits) { - t.Fatalf("Could not find %s in the list of organizations", channel.GetName()) + if !isValueInList(channel.Name(), orgUnits) { + t.Fatalf("Could not find %s in the list of organizations", channel.Name()) } if !isValueInList(org1MSPID, orgUnits) { t.Fatalf("Could not find %s in the list of organizations", org1MSPID) @@ -423,7 +423,7 @@ func TestChannelInitializeFromUpdate(t *testing.T) { if err != nil { t.Fatalf("channel Initialize failed : %v", err) } - mspManager := channel.GetMSPManager() + mspManager := channel.MSPManager() if mspManager == nil { t.Fatalf("nil MSPManager on new channel") } diff --git a/pkg/fabric-client/client_test.go b/pkg/fabric-client/client_test.go index a97ee9a8cd..92ae1b1619 100644 --- a/pkg/fabric-client/client_test.go +++ b/pkg/fabric-client/client_test.go @@ -100,11 +100,11 @@ func TestClientMethods(t *testing.T) { if err != nil { t.Fatalf("client.NewChain return error[%s]", err) } - if chain.GetName() != "someChain" { + if chain.Name() != "someChain" { t.Fatalf("client.NewChain create wrong chain") } chain1 := client.GetChannel("someChain") - if chain1.GetName() != "someChain" { + if chain1.Name() != "someChain" { t.Fatalf("client.NewChain create wrong chain") } diff --git a/pkg/fabric-client/events/consumer/consumer.go b/pkg/fabric-client/events/consumer/consumer.go index fe0d2cd15d..8fa573592f 100644 --- a/pkg/fabric-client/events/consumer/consumer.go +++ b/pkg/fabric-client/events/consumer/consumer.go @@ -59,7 +59,7 @@ func newEventsClientConnectionWithAddress(peerAddress string, certificate string var opts []grpc.DialOption opts = append(opts, grpc.WithTimeout(time.Second*3)) if config.IsTLSEnabled() { - tlsCaCertPool, err := config.GetTLSCACertPool(certificate) + tlsCaCertPool, err := config.TLSCACertPool(certificate) if err != nil { return nil, err } diff --git a/pkg/fabric-client/events/eventmocks.go b/pkg/fabric-client/events/eventmocks.go index bf3f354fdf..9519ef9fe6 100644 --- a/pkg/fabric-client/events/eventmocks.go +++ b/pkg/fabric-client/events/eventmocks.go @@ -112,7 +112,7 @@ func (mec *mockEventClient) Stop() error { func createMockedEventHub(t *testing.T) (*eventHub, *mockEventClientFactory) { // Initialize bccsp factories before calling get client - err := bccspFactory.InitFactories(mocks.NewMockConfig().GetCSPConfig()) + err := bccspFactory.InitFactories(mocks.NewMockConfig().CSPConfig()) if err != nil { t.Fatalf("Failed getting ephemeral software-based BCCSP [%s]", err) } diff --git a/pkg/fabric-client/mocks/mockconfig.go b/pkg/fabric-client/mocks/mockconfig.go index 4e62d31940..69d24e228d 100644 --- a/pkg/fabric-client/mocks/mockconfig.go +++ b/pkg/fabric-client/mocks/mockconfig.go @@ -24,34 +24,34 @@ func NewMockConfig() api.Config { return &MockConfig{} } -// GetCAConfig not implemented -func (c *MockConfig) GetCAConfig(org string) (*api.CAConfig, error) { +// CAConfig not implemented +func (c *MockConfig) CAConfig(org string) (*api.CAConfig, error) { return nil, nil } -//GetCAServerCertFiles Read configuration option for the server certificate files -func (c *MockConfig) GetCAServerCertFiles(org string) ([]string, error) { +//CAServerCertFiles Read configuration option for the server certificate files +func (c *MockConfig) CAServerCertFiles(org string) ([]string, error) { return nil, nil } -//GetCAClientKeyFile Read configuration option for the fabric CA client key file -func (c *MockConfig) GetCAClientKeyFile(org string) (string, error) { +//CAClientKeyFile Read configuration option for the fabric CA client key file +func (c *MockConfig) CAClientKeyFile(org string) (string, error) { return "", nil } -//GetCAClientCertFile Read configuration option for the fabric CA client cert file -func (c *MockConfig) GetCAClientCertFile(org string) (string, error) { +//CAClientCertFile Read configuration option for the fabric CA client cert file +func (c *MockConfig) CAClientCertFile(org string) (string, error) { return "", nil } -// GetFabricClientViper returns the internal viper instance used by the +// FabricClientViper returns the internal viper instance used by the // SDK to read configuration options -func (c *MockConfig) GetFabricClientViper() *viper.Viper { +func (c *MockConfig) FabricClientViper() *viper.Viper { return nil } -// GetPeersConfig Retrieves the fabric peers from the config file provided -func (c *MockConfig) GetPeersConfig(org string) ([]api.PeerConfig, error) { +// PeersConfig Retrieves the fabric peers from the config file provided +func (c *MockConfig) PeersConfig(org string) ([]api.PeerConfig, error) { return nil, nil } @@ -60,13 +60,13 @@ func (c *MockConfig) IsTLSEnabled() bool { return false } -// GetTLSCACertPool ... -func (c *MockConfig) GetTLSCACertPool(tlsCertificate string) (*x509.CertPool, error) { +// TLSCACertPool ... +func (c *MockConfig) TLSCACertPool(tlsCertificate string) (*x509.CertPool, error) { return nil, nil } -// GetTLSCACertPoolFromRoots ... -func (c *MockConfig) GetTLSCACertPoolFromRoots(ordererRootCAs [][]byte) (*x509.CertPool, error) { +// TLSCACertPoolFromRoots ... +func (c *MockConfig) TLSCACertPoolFromRoots(ordererRootCAs [][]byte) (*x509.CertPool, error) { return nil, nil } @@ -80,53 +80,53 @@ func (c *MockConfig) TcertBatchSize() int { return 0 } -// GetSecurityAlgorithm ... -func (c *MockConfig) GetSecurityAlgorithm() string { +// SecurityAlgorithm ... +func (c *MockConfig) SecurityAlgorithm() string { return "" } -// GetSecurityLevel ... -func (c *MockConfig) GetSecurityLevel() int { +// SecurityLevel ... +func (c *MockConfig) SecurityLevel() int { return 0 } -// GetRandomOrdererConfig not implemented -func (c *MockConfig) GetRandomOrdererConfig() (*api.OrdererConfig, error) { +// RandomOrdererConfig not implemented +func (c *MockConfig) RandomOrdererConfig() (*api.OrdererConfig, error) { return nil, nil } -// GetOrdererConfig not implemented -func (c *MockConfig) GetOrdererConfig(name string) (*api.OrdererConfig, error) { +// OrdererConfig not implemented +func (c *MockConfig) OrdererConfig(name string) (*api.OrdererConfig, error) { return nil, nil } -// GetMspID ... -func (c *MockConfig) GetMspID(org string) (string, error) { +// MspID ... +func (c *MockConfig) MspID(org string) (string, error) { return "", nil } -// GetKeyStorePath ... -func (c *MockConfig) GetKeyStorePath() string { +// KeyStorePath ... +func (c *MockConfig) KeyStorePath() string { return "" } -// GetCAKeyStorePath not implemented -func (c *MockConfig) GetCAKeyStorePath() string { +// CAKeyStorePath not implemented +func (c *MockConfig) CAKeyStorePath() string { return "" } -// GetCryptoConfigPath ... -func (c *MockConfig) GetCryptoConfigPath() string { +// CryptoConfigPath ... +func (c *MockConfig) CryptoConfigPath() string { return "" } -// GetCSPConfig ... -func (c *MockConfig) GetCSPConfig() *bccspFactory.FactoryOpts { +// CSPConfig ... +func (c *MockConfig) CSPConfig() *bccspFactory.FactoryOpts { return nil } -// GetNetworkConfig not implemented -func (c *MockConfig) GetNetworkConfig() (*api.NetworkConfig, error) { +// NetworkConfig not implemented +func (c *MockConfig) NetworkConfig() (*api.NetworkConfig, error) { return nil, nil } diff --git a/pkg/fabric-client/mocks/mockpeer.go b/pkg/fabric-client/mocks/mockpeer.go index 1c27ea3e34..7db068acb4 100644 --- a/pkg/fabric-client/mocks/mockpeer.go +++ b/pkg/fabric-client/mocks/mockpeer.go @@ -81,9 +81,11 @@ func (p *MockPeer) URL() string { // SendProposal does not send anything anywhere but returns an empty mock ProposalResponse func (p *MockPeer) SendProposal(tp *api.TransactionProposal) (*api.TransactionProposalResponse, error) { + return &api.TransactionProposalResponse{ Endorser: p.MockURL, Proposal: tp, - ProposalResponse: &pb.ProposalResponse{}, + ProposalResponse: &pb.ProposalResponse{Response: &pb.Response{Message: "success", Status: 99, Payload: []byte("")}}, }, nil + } diff --git a/pkg/fabric-client/orderer/orderer.go b/pkg/fabric-client/orderer/orderer.go index c2a1e00b37..a6d15b7204 100644 --- a/pkg/fabric-client/orderer/orderer.go +++ b/pkg/fabric-client/orderer/orderer.go @@ -31,7 +31,7 @@ type orderer struct { // CreateNewOrdererWithRootCAs Returns a new Orderer instance using the passed in orderer root CAs func CreateNewOrdererWithRootCAs(url string, ordererRootCAs [][]byte, serverHostOverride string, config api.Config) (api.Orderer, error) { if config.IsTLSEnabled() { - tlsCaCertPool, err := config.GetTLSCACertPoolFromRoots(ordererRootCAs) + tlsCaCertPool, err := config.TLSCACertPoolFromRoots(ordererRootCAs) if err != nil { return nil, err } @@ -188,7 +188,7 @@ func NewOrderer(url string, certificate string, serverHostOverride string, confi var opts []grpc.DialOption opts = append(opts, grpc.WithTimeout(time.Second*3)) if config.IsTLSEnabled() { - tlsCaCertPool, err := config.GetTLSCACertPool(certificate) + tlsCaCertPool, err := config.TLSCACertPool(certificate) if err != nil { return nil, err } diff --git a/pkg/fabric-client/orderer/orderer_test.go b/pkg/fabric-client/orderer/orderer_test.go index 1b0ea53c7c..47a91d5836 100644 --- a/pkg/fabric-client/orderer/orderer_test.go +++ b/pkg/fabric-client/orderer/orderer_test.go @@ -41,7 +41,7 @@ func TestOrdererViaChain(t *testing.T) { t.Fatalf("Error adding orderer: %v", err) } - orderers := chain.GetOrderers() + orderers := chain.Orderers() if orderers == nil || len(orderers) != 1 || orderers[0].GetURL() != "localhost:7050" { t.Fatalf("Failed to retieve the new orderer URL from the chain") } @@ -54,7 +54,7 @@ func TestOrdererViaChain(t *testing.T) { if err != nil { t.Fatalf("Error adding orderer: %v", err) } - orderers = chain.GetOrderers() + orderers = chain.Orderers() if orderers == nil || len(orderers) != 1 || orderers[0].GetURL() != "localhost:7054" { t.Fatalf("Failed to retieve the new orderer URL from the chain") @@ -111,7 +111,7 @@ func TestOrdererViaChainNilData(t *testing.T) { if err == nil { t.Fatalf("SendTransaction didn't return error") } - if err.Error() != "proposal is nil" { + if err.Error() != "Transaction is nil" { t.Fatalf("SendTransaction didn't return right error") } } diff --git a/pkg/fabric-client/peer/peer_test.go b/pkg/fabric-client/peer/peer_test.go index 0884b240a4..568adfd3b0 100644 --- a/pkg/fabric-client/peer/peer_test.go +++ b/pkg/fabric-client/peer/peer_test.go @@ -46,7 +46,7 @@ func TestNewPeerTLSFromCert(t *testing.T) { certPool := x509.NewCertPool() config.EXPECT().IsTLSEnabled().Return(true) - config.EXPECT().GetTLSCACertPool("cert").Return(certPool, nil) + config.EXPECT().TLSCACertPool("cert").Return(certPool, nil) url := "0.0.0.0:1234" // TODO - test actual parameters and test server name override diff --git a/pkg/fabric-client/peer/peerendorser.go b/pkg/fabric-client/peer/peerendorser.go index 1bd83c2cd9..e0af54a4e6 100644 --- a/pkg/fabric-client/peer/peerendorser.go +++ b/pkg/fabric-client/peer/peerendorser.go @@ -40,7 +40,7 @@ func newPeerEndorser(target string, certificate string, serverHostOverride strin return peerEndorser{}, fmt.Errorf("Certificate is required") } - tlsCaCertPool, err := config.GetTLSCACertPool(certificate) + tlsCaCertPool, err := config.TLSCACertPool(certificate) if err != nil { return peerEndorser{}, err } diff --git a/pkg/fabric-client/peer/peerendorser_test.go b/pkg/fabric-client/peer/peerendorser_test.go index 0037c752be..0b310af0be 100644 --- a/pkg/fabric-client/peer/peerendorser_test.go +++ b/pkg/fabric-client/peer/peerendorser_test.go @@ -42,7 +42,7 @@ func TestNewPeerEndorserTLS(t *testing.T) { certPool := x509.NewCertPool() config.EXPECT().IsTLSEnabled().Return(true) - config.EXPECT().GetTLSCACertPool("cert").Return(certPool, nil) + config.EXPECT().TLSCACertPool("cert").Return(certPool, nil) conn, err := newPeerEndorser(url, "cert", "", connTimeout, true, config) if err != nil { @@ -70,7 +70,7 @@ func TestNewPeerEndorserTLSBadPool(t *testing.T) { certPool := x509.NewCertPool() config.EXPECT().IsTLSEnabled().Return(true) - config.EXPECT().GetTLSCACertPool("cert").Return(certPool, fmt.Errorf("ohoh")) + config.EXPECT().TLSCACertPool("cert").Return(certPool, fmt.Errorf("ohoh")) _, err := newPeerEndorser(url, "cert", "", connTimeout, true, config) if err == nil { diff --git a/pkg/fabric-client/peer_test.go b/pkg/fabric-client/peer_test.go index 99a677630c..80e036f80a 100644 --- a/pkg/fabric-client/peer_test.go +++ b/pkg/fabric-client/peer_test.go @@ -44,7 +44,7 @@ func TestPeerViaChannel(t *testing.T) { t.Fatalf("Error adding peer: %v", err) } - peers := channel.GetPeers() + peers := channel.Peers() if peers == nil || len(peers) != 1 || peers[0].URL() != peer1URL { t.Fatalf("Failed to retieve the new peers URL from the channel") } @@ -57,7 +57,7 @@ func TestPeerViaChannel(t *testing.T) { if err != nil { t.Fatalf("Error adding peer: %v", err) } - peers = channel.GetPeers() + peers = channel.Peers() if peers == nil || len(peers) != 1 || peers[0].URL() != peer2URL { t.Fatalf("Failed to retieve the new peers URL from the channel") diff --git a/test/integration/base_test_setup.go b/test/integration/base_test_setup.go index 1e4f175e06..215974ad2c 100644 --- a/test/integration/base_test_setup.go +++ b/test/integration/base_test_setup.go @@ -48,7 +48,7 @@ func (setup *BaseSetupImpl) Initialize() error { } // Initialize bccsp factories before calling get client - err = bccspFactory.InitFactories(configImpl.GetCSPConfig()) + err = bccspFactory.InitFactories(configImpl.CSPConfig()) if err != nil { return fmt.Errorf("Failed getting ephemeral software-based BCCSP [%s]", err) } @@ -157,7 +157,7 @@ func (setup *BaseSetupImpl) InstantiateCC(chainCodeID string, channelID string, // must reset client user context to normal user once done with Admin privilieges defer setup.Client.SetUserContext(setup.NormalUser) - if err := admin.SendInstantiateCC(setup.Channel, chainCodeID, channelID, args, chainCodePath, chainCodeVersion, []api.Peer{setup.Channel.GetPrimaryPeer()}, setup.EventHub); err != nil { + if err := admin.SendInstantiateCC(setup.Channel, chainCodeID, channelID, args, chainCodePath, chainCodeVersion, []api.Peer{setup.Channel.PrimaryPeer()}, setup.EventHub); err != nil { return err } return nil @@ -171,7 +171,7 @@ func (setup *BaseSetupImpl) InstallCC(chainCodeID string, chainCodePath string, // must reset client user context to normal user once done with Admin privilieges defer setup.Client.SetUserContext(setup.NormalUser) - if err := admin.SendInstallCC(setup.Client, chainCodeID, chainCodePath, chainCodeVersion, chaincodePackage, setup.Channel.GetPeers(), setup.GetDeployPath()); err != nil { + if err := admin.SendInstallCC(setup.Client, chainCodeID, chainCodePath, chainCodeVersion, chaincodePackage, setup.Channel.Peers(), setup.GetDeployPath()); err != nil { return fmt.Errorf("SendInstallProposal return error: %v", err) } @@ -231,7 +231,7 @@ func (setup *BaseSetupImpl) GetChannel(client api.FabricClient, channelID string return nil, fmt.Errorf("NewChannel return error: %v", err) } - ordererConfig, err := client.GetConfig().GetRandomOrdererConfig() + ordererConfig, err := client.GetConfig().RandomOrdererConfig() if err != nil { return nil, fmt.Errorf("GetRandomOrdererConfig() return error: %s", err) } @@ -248,7 +248,7 @@ func (setup *BaseSetupImpl) GetChannel(client api.FabricClient, channelID string } for _, org := range orgs { - peerConfig, err := client.GetConfig().GetPeersConfig(org) + peerConfig, err := client.GetConfig().PeersConfig(org) if err != nil { return nil, fmt.Errorf("Error reading peer config: %v", err) } @@ -344,7 +344,7 @@ func (setup *BaseSetupImpl) getEventHub(client api.FabricClient) (api.EventHub, return nil, fmt.Errorf("Error creating new event hub: %v", err) } foundEventHub := false - peerConfig, err := client.GetConfig().GetPeersConfig(setup.OrgID) + peerConfig, err := client.GetConfig().PeersConfig(setup.OrgID) if err != nil { return nil, fmt.Errorf("Error reading peer config: %v", err) } diff --git a/test/integration/channel_queries_test.go b/test/integration/channel_queries_test.go index b571dbf7ba..bae70c89ac 100644 --- a/test/integration/channel_queries_test.go +++ b/test/integration/channel_queries_test.go @@ -169,7 +169,7 @@ func testQueryBlock(t *testing.T, channel api.Channel) { func testQueryChannels(t *testing.T, channel api.Channel, client api.FabricClient) { // Our target will be primary peer on this channel - target := channel.GetPrimaryPeer() + target := channel.PrimaryPeer() fmt.Printf("****QueryChannels for %s\n", target.URL()) channelQueryResponse, err := client.QueryChannels(target) if err != nil { @@ -185,7 +185,7 @@ func testQueryChannels(t *testing.T, channel api.Channel, client api.FabricClien func testInstalledChaincodes(t *testing.T, channel api.Channel, client api.FabricClient, testSetup *BaseSetupImpl) { // Our target will be primary peer on this channel - target := channel.GetPrimaryPeer() + target := channel.PrimaryPeer() fmt.Printf("****QueryInstalledChaincodes for %s\n", target.URL()) // Test Query Installed chaincodes for target (primary) // set Client User Context to Admin first @@ -206,7 +206,7 @@ func testInstalledChaincodes(t *testing.T, channel api.Channel, client api.Fabri func testInstantiatedChaincodes(t *testing.T, channel api.Channel) { // Our target will indirectly be primary peer on this channel - target := channel.GetPrimaryPeer() + target := channel.PrimaryPeer() fmt.Printf("QueryInstantiatedChaincodes for primary %s\n", target.URL()) @@ -225,7 +225,7 @@ func testInstantiatedChaincodes(t *testing.T, channel api.Channel) { func testQueryByChaincode(t *testing.T, channel api.Channel, config api.Config, testSetup *BaseSetupImpl) { // Test valid targets - targets := channel.GetPeers() + targets := channel.Peers() // set Client User Context to Admin before calling QueryByChaincode testSetup.Client.SetUserContext(testSetup.AdminUser) @@ -240,7 +240,7 @@ func testQueryByChaincode(t *testing.T, channel api.Channel, config api.Config, } // Configured cert for cert pool - cert, err := config.GetCAClientCertFile(org1Name) + cert, err := config.CAClientCertFile(org1Name) if err != nil { t.Fatal(err) } @@ -300,7 +300,7 @@ func moveFundsAndGetTxID(setup *BaseSetupImpl) (string, error) { transientDataMap := make(map[string][]byte) transientDataMap["result"] = []byte("Transient data in move funds...") - transactionProposalResponse, txID, err := setup.CreateAndSendTransactionProposal(setup.Channel, setup.ChainCodeID, setup.ChannelID, args, []api.Peer{setup.Channel.GetPrimaryPeer()}, transientDataMap) + transactionProposalResponse, txID, err := setup.CreateAndSendTransactionProposal(setup.Channel, setup.ChainCodeID, setup.ChannelID, args, []api.Peer{setup.Channel.PrimaryPeer()}, transientDataMap) if err != nil { return "", fmt.Errorf("CreateAndSendTransactionProposal return error: %v", err) } diff --git a/test/integration/end_to_end_test.go b/test/integration/end_to_end_test.go index a2674717fc..c0901506c0 100644 --- a/test/integration/end_to_end_test.go +++ b/test/integration/end_to_end_test.go @@ -88,5 +88,5 @@ func moveFunds(setup *BaseSetupImpl) error { transientDataMap := make(map[string][]byte) transientDataMap["result"] = []byte("Transient data in move funds...") - return fabricTxn.InvokeChaincode(setup.Client, setup.Channel, []api.Peer{setup.Channel.GetPrimaryPeer()}, setup.EventHub, setup.ChainCodeID, args, transientDataMap) + return fabricTxn.InvokeChaincode(setup.Client, setup.Channel, []api.Peer{setup.Channel.PrimaryPeer()}, setup.EventHub, setup.ChainCodeID, args, transientDataMap) } diff --git a/test/integration/events_test.go b/test/integration/events_test.go index 7aeef55237..0e7bd056bc 100644 --- a/test/integration/events_test.go +++ b/test/integration/events_test.go @@ -66,12 +66,12 @@ func testFailedTx(t *testing.T, testSetup BaseSetupImpl) { args = append(args, "invoke") args = append(args, "SEVERE") - tpResponses1, tx1, err := testSetup.CreateAndSendTransactionProposal(testSetup.Channel, testSetup.ChainCodeID, testSetup.ChannelID, args, []api.Peer{testSetup.Channel.GetPrimaryPeer()}, nil) + tpResponses1, tx1, err := testSetup.CreateAndSendTransactionProposal(testSetup.Channel, testSetup.ChainCodeID, testSetup.ChannelID, args, []api.Peer{testSetup.Channel.PrimaryPeer()}, nil) if err != nil { t.Fatalf("CreateAndSendTransactionProposal return error: %v", err) } - tpResponses2, tx2, err := testSetup.CreateAndSendTransactionProposal(testSetup.Channel, testSetup.ChainCodeID, testSetup.ChannelID, args, []api.Peer{testSetup.Channel.GetPrimaryPeer()}, nil) + tpResponses2, tx2, err := testSetup.CreateAndSendTransactionProposal(testSetup.Channel, testSetup.ChainCodeID, testSetup.ChannelID, args, []api.Peer{testSetup.Channel.PrimaryPeer()}, nil) if err != nil { t.Fatalf("CreateAndSendTransactionProposal return error: %v", err) } @@ -139,13 +139,13 @@ func testFailedTxErrorCode(t *testing.T, testSetup BaseSetupImpl) { args = append(args, "invoke") args = append(args, "SEVERE") - tpResponses1, tx1, err := testSetup.CreateAndSendTransactionProposal(testSetup.Channel, testSetup.ChainCodeID, testSetup.ChannelID, args, []api.Peer{testSetup.Channel.GetPrimaryPeer()}, nil) + tpResponses1, tx1, err := testSetup.CreateAndSendTransactionProposal(testSetup.Channel, testSetup.ChainCodeID, testSetup.ChannelID, args, []api.Peer{testSetup.Channel.PrimaryPeer()}, nil) if err != nil { t.Fatalf("CreateAndSendTransactionProposal return error: %v", err) } - tpResponses2, tx2, err := testSetup.CreateAndSendTransactionProposal(testSetup.Channel, testSetup.ChainCodeID, testSetup.ChannelID, args, []api.Peer{testSetup.Channel.GetPrimaryPeer()}, nil) + tpResponses2, tx2, err := testSetup.CreateAndSendTransactionProposal(testSetup.Channel, testSetup.ChainCodeID, testSetup.ChannelID, args, []api.Peer{testSetup.Channel.PrimaryPeer()}, nil) if err != nil { t.Fatalf("CreateAndSendTransactionProposal return error: %v", err) } @@ -255,7 +255,7 @@ func testMultipleBlockEventCallbacks(t *testing.T, testSetup BaseSetupImpl) { test <- true }) - tpResponses, tx, err := testSetup.CreateAndSendTransactionProposal(testSetup.Channel, testSetup.ChainCodeID, testSetup.ChannelID, args, []api.Peer{testSetup.Channel.GetPrimaryPeer()}, nil) + tpResponses, tx, err := testSetup.CreateAndSendTransactionProposal(testSetup.Channel, testSetup.ChainCodeID, testSetup.ChannelID, args, []api.Peer{testSetup.Channel.PrimaryPeer()}, nil) if err != nil { t.Fatalf("CreateAndSendTransactionProposal returned error: %v", err) } diff --git a/test/integration/fabric_ca_test.go b/test/integration/fabric_ca_test.go index df6c8f4432..912911102e 100644 --- a/test/integration/fabric_ca_test.go +++ b/test/integration/fabric_ca_test.go @@ -50,19 +50,19 @@ func TestMain(m *testing.M) { // This test loads/enrols an admin user // Using the admin, it registers, enrols, and revokes a test user func TestRegisterEnrollRevoke(t *testing.T) { - mspID, err := testFabricCAConfig.GetMspID(org1Name) + mspID, err := testFabricCAConfig.MspID(org1Name) if err != nil { t.Fatalf("GetMspId() returned error: %v", err) } - caConfig, err := testFabricCAConfig.GetCAConfig(org1Name) + caConfig, err := testFabricCAConfig.CAConfig(org1Name) if err != nil { t.Fatalf("GetCAConfig returned error: %s", err) } client := client.NewClient(testFabricCAConfig) - err = bccspFactory.InitFactories(testFabricCAConfig.GetCSPConfig()) + err = bccspFactory.InitFactories(testFabricCAConfig.CSPConfig()) if err != nil { t.Fatalf("Failed getting ephemeral software-based BCCSP [%s]", err) } diff --git a/test/integration/install_chaincode_test.go b/test/integration/install_chaincode_test.go index 9e7dcd1e5d..7cda58cc39 100644 --- a/test/integration/install_chaincode_test.go +++ b/test/integration/install_chaincode_test.go @@ -59,7 +59,7 @@ func testChaincodeInstallUsingChaincodePath(t *testing.T, testSetup *BaseSetupIm // set Client User Context to Admin testSetup.Client.SetUserContext(testSetup.AdminUser) defer testSetup.Client.SetUserContext(testSetup.NormalUser) - chaincodeQueryResponse, err := client.QueryInstalledChaincodes(testSetup.Channel.GetPrimaryPeer()) + chaincodeQueryResponse, err := client.QueryInstalledChaincodes(testSetup.Channel.PrimaryPeer()) if err != nil { t.Fatalf("QueryInstalledChaincodes return error: %v", err) } diff --git a/test/integration/transient_data_test.go b/test/integration/transient_data_test.go index 1ea2acc7c7..0737ad9ffb 100644 --- a/test/integration/transient_data_test.go +++ b/test/integration/transient_data_test.go @@ -42,7 +42,7 @@ func TestTransient(t *testing.T) { transientDataMap := make(map[string][]byte) transientDataMap["result"] = []byte(transientData) - transactionProposalResponse, _, err := testSetup.CreateAndSendTransactionProposal(testSetup.Channel, testSetup.ChainCodeID, testSetup.ChannelID, args, []api.Peer{testSetup.Channel.GetPrimaryPeer()}, transientDataMap) + transactionProposalResponse, _, err := testSetup.CreateAndSendTransactionProposal(testSetup.Channel, testSetup.ChainCodeID, testSetup.ChannelID, args, []api.Peer{testSetup.Channel.PrimaryPeer()}, transientDataMap) if err != nil { t.Fatalf("CreateAndSendTransactionProposal return error: %v", err) } @@ -58,7 +58,7 @@ func TestTransient(t *testing.T) { } //transient data null transientDataMap["result"] = []byte{} - transactionProposalResponse, _, err = testSetup.CreateAndSendTransactionProposal(testSetup.Channel, testSetup.ChainCodeID, testSetup.ChannelID, args, []api.Peer{testSetup.Channel.GetPrimaryPeer()}, transientDataMap) + transactionProposalResponse, _, err = testSetup.CreateAndSendTransactionProposal(testSetup.Channel, testSetup.ChainCodeID, testSetup.ChannelID, args, []api.Peer{testSetup.Channel.PrimaryPeer()}, transientDataMap) if err != nil { t.Fatalf("CreateAndSendTransactionProposal with empty transient data return an error: %v", err) } diff --git a/test/integration/utils.go b/test/integration/utils.go index 2348fe058b..1d30a7cd3d 100644 --- a/test/integration/utils.go +++ b/test/integration/utils.go @@ -58,13 +58,13 @@ func randomString(strlen int) string { // GetDefaultImplPreEnrolledUser ... func getDefaultImplPreEnrolledUser(client api.FabricClient, keyDir string, certDir string, username string, orgName string) (api.User, error) { - privateKeyDir := filepath.Join(client.GetConfig().GetCryptoConfigPath(), keyDir) + privateKeyDir := filepath.Join(client.GetConfig().CryptoConfigPath(), keyDir) privateKeyPath, err := getFirstPathFromDir(privateKeyDir) if err != nil { return nil, fmt.Errorf("Error finding the private key path: %v", err) } - enrollmentCertDir := filepath.Join(client.GetConfig().GetCryptoConfigPath(), certDir) + enrollmentCertDir := filepath.Join(client.GetConfig().CryptoConfigPath(), certDir) enrollmentCertPath, err := getFirstPathFromDir(enrollmentCertDir) if err != nil { return nil, fmt.Errorf("Error finding the enrollment cert path: %v", err) @@ -107,7 +107,7 @@ func getFirstPathFromDir(dir string) (string, error) { // or an error func HasPrimaryPeerJoinedChannel(client api.FabricClient, orgUser api.User, channel api.Channel) (bool, error) { foundChannel := false - primaryPeer := channel.GetPrimaryPeer() + primaryPeer := channel.PrimaryPeer() currentUser := client.GetUserContext() defer client.SetUserContext(currentUser) @@ -118,7 +118,7 @@ func HasPrimaryPeerJoinedChannel(client api.FabricClient, orgUser api.User, chan return false, fmt.Errorf("Error querying channel for primary peer: %s", err) } for _, responseChannel := range response.Channels { - if responseChannel.ChannelId == channel.GetName() { + if responseChannel.ChannelId == channel.Name() { foundChannel = true } }