Skip to content

Commit

Permalink
[FAB-3324] Get organization units
Browse files Browse the repository at this point in the history
Change-Id: I9c9dab93e3d71b47fd4a860447bf521d4f4d025f
Signed-off-by: biljana lukovic <biljana.lukovic@securekey.com>
  • Loading branch information
biljanaLukovic committed Apr 18, 2017
1 parent e12e9c5 commit b920301
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
21 changes: 20 additions & 1 deletion fabric-client/chain.go
Expand Up @@ -88,7 +88,7 @@ type Chain interface {
SendTransaction(tx *Transaction) ([]*TransactionResponse, error)
SendInstallProposal(chaincodeName string, chaincodePath string, chaincodeVersion string, chaincodePackage []byte, targets []Peer) ([]*TransactionProposalResponse, string, error)
SendInstantiateProposal(chaincodeName string, chainID string, args []string, chaincodePath string, chaincodeVersion string, targets []Peer) ([]*TransactionProposalResponse, string, error)

GetOrganizationUnits() ([]string, error)
QueryExtensionInterface() ChainExtension
}

Expand Down Expand Up @@ -424,6 +424,25 @@ func (c *chain) GetMSPManager() msp.MSPManager {
return c.mspManager
}

// GetOrganizationUnits - to get identifier for the organization configured on the channel
func (c *chain) GetOrganizationUnits() ([]string, error) {
chainMSPManager := c.GetMSPManager()
msps, err := chainMSPManager.GetMSPs()
if err != nil {
logger.Info("Cannot get channel manager")
return nil, fmt.Errorf("Organization uits were not set: %v", err)
}
var orgIdentifiers []string
for _, v := range msps {
orgName, err := v.GetIdentifier()
if err != nil {
logger.Info("Organization does not have an identifier")
}
orgIdentifiers = append(orgIdentifiers, orgName)
}
return orgIdentifiers, nil
}

// Initialize initializes the chain
/**
* Retrieve the configuration from the orderer and initializes this chain (channel)
Expand Down
54 changes: 54 additions & 0 deletions fabric-client/chain_test.go
Expand Up @@ -314,6 +314,60 @@ func TestChainInitializeFromOrderer(t *testing.T) {
}
}

func TestOrganizationUnits(t *testing.T) {
org1MSPID := "ORG1MSP"
org2MSPID := "ORG2MSP"

chain, _ := setupTestChain()
orgUnits, err := chain.GetOrganizationUnits()
if len(orgUnits) > 0 {
t.Fatalf("Returned non configured organizational unit : %v", err)
}
builder := &mocks.MockConfigBlockBuilder{
MockConfigGroupBuilder: mocks.MockConfigGroupBuilder{
ModPolicy: "Admins",
MSPNames: []string{
chain.GetName(),
org1MSPID,
org2MSPID,
},
OrdererAddress: "localhost:7054",
},
Index: 0,
LastConfigIndex: 0,
}
orderer := &mockOrderer{DeliverResponse: NewMockDeliverResponse(builder.Build())}
chain.AddOrderer(orderer)

err = chain.Initialize(nil)
if err != nil {
t.Fatalf("channel Initialize failed : %v", err)
}
orgUnits, err = chain.GetOrganizationUnits()
if err != nil {
t.Fatalf("CANNOT retrieve organizational units : %v", err)
}
if !isValueInList(chain.GetName(), orgUnits) {
t.Fatalf("Could not find %s in the list of organizations", chain.GetName())
}
if !isValueInList(org1MSPID, orgUnits) {
t.Fatalf("Could not find %s in the list of organizations", org1MSPID)
}
if !isValueInList(org2MSPID, orgUnits) {
t.Fatalf("Could not find %s in the list of organizations", org2MSPID)
}

}

func isValueInList(value string, list []string) bool {
for _, v := range list {
if v == value {
return true
}
}
return false
}

func TestChainInitializeFromUpdate(t *testing.T) {
org1MSPID := "ORG1MSP"
org2MSPID := "ORG2MSP"
Expand Down

0 comments on commit b920301

Please sign in to comment.