Skip to content

Commit

Permalink
[FAB-8247] Improve instantiated chaincodes test
Browse files Browse the repository at this point in the history
Change-Id: I1fbf55377b61fc4d3c977ea658f8852794697b53
Signed-off-by: Sandra Vrtikapa <sandra.vrtikapa@securekey.com>
  • Loading branch information
sandrask committed Feb 13, 2018
1 parent 07808ad commit c981b55
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 10 additions & 2 deletions test/integration/fab/channel_ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestLedgerQueries(t *testing.T) {

testQueryBlock(t, ledger, targets)

testInstantiatedChaincodes(t, ledger, targets)
testInstantiatedChaincodes(t, chaincodeID, ledger, targets)

}

Expand Down Expand Up @@ -211,19 +211,27 @@ func testQueryBlock(t *testing.T, ledger fab.ChannelLedger, targets []fab.Propos
}
}

func testInstantiatedChaincodes(t *testing.T, ledger fab.ChannelLedger, targets []fab.ProposalProcessor) {
func testInstantiatedChaincodes(t *testing.T, ccID string, ledger fab.ChannelLedger, targets []fab.ProposalProcessor) {

// Test Query Instantiated chaincodes
chaincodeQueryResponses, err := ledger.QueryInstantiatedChaincodes(targets)
if err != nil {
t.Fatalf("QueryInstantiatedChaincodes return error: %v", err)
}

found := false
for _, chaincodeQueryResponse := range chaincodeQueryResponses {
for _, chaincode := range chaincodeQueryResponse.Chaincodes {
t.Logf("**InstantiatedCC: %s", chaincode)
if chaincode.Name == ccID {
found = true
}
}
}

if !found {
t.Fatalf("QueryInstantiatedChaincodes failed to find instantiated %s chaincode", ccID)
}
}

// MoveFundsAndGetTxID ...
Expand Down
11 changes: 9 additions & 2 deletions test/integration/fab/channel_queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestChannelQueries(t *testing.T) {

testQueryChannels(t, testSetup.Channel, testSetup.Client)

testInstalledChaincodes(t, testSetup.Channel, testSetup.Client)
testInstalledChaincodes(t, chaincodeID, testSetup.Channel, testSetup.Client)

testQueryByChaincode(t, testSetup.SDK.Config(), testSetup.Channel)
}
Expand Down Expand Up @@ -60,7 +60,7 @@ func testQueryChannels(t *testing.T, channel fab.Channel, client fab.Resource) {

}

func testInstalledChaincodes(t *testing.T, channel fab.Channel, client fab.Resource) {
func testInstalledChaincodes(t *testing.T, ccID string, channel fab.Channel, client fab.Resource) {

// Our target will be primary peer on this channel
target := channel.PrimaryPeer()
Expand All @@ -71,10 +71,17 @@ func testInstalledChaincodes(t *testing.T, channel fab.Channel, client fab.Resou
t.Fatalf("QueryInstalledChaincodes return error: %v", err)
}

found := false
for _, chaincode := range chaincodeQueryResponse.Chaincodes {
t.Logf("**InstalledCC: %s", chaincode)
if chaincode.Name == ccID {
found = true
}
}

if !found {
t.Fatalf("QueryInstalledChaincodes failed to find installed %s chaincode", ccID)
}
}

func testQueryByChaincode(t *testing.T, config apiconfig.Config, channel fab.Channel) {
Expand Down

0 comments on commit c981b55

Please sign in to comment.