Skip to content

Commit

Permalink
[FAB-10595] Fabric Selection Integration Tests
Browse files Browse the repository at this point in the history
Added integration tests for the Fabric Selection
service.

Also, fixed some linter errors.

Change-Id: Icc60989a0291d1544d57787c69e01b513279831d
Signed-off-by: Bob Stasyszyn <Bob.Stasyszyn@securekey.com>
  • Loading branch information
bstasyszyn committed Jun 11, 2018
1 parent 117f2eb commit 65f5a15
Show file tree
Hide file tree
Showing 3 changed files with 426 additions and 35 deletions.
18 changes: 10 additions & 8 deletions test/integration/base_test_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/util/test"
"github.com/hyperledger/fabric-sdk-go/test/metadata"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/common/cauthdsl"
cb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -256,13 +257,13 @@ func JoinPeersToChannel(channelID string, orgsContext []*OrgContext) error {
}

// InstallAndInstantiateChaincode installs the given chaincode to all peers in the given orgs and instantiates it on the given channel
func InstallAndInstantiateChaincode(channelID string, ccPkg *resource.CCPackage, ccID, ccVersion, ccPolicy string, orgs []*OrgContext) error {
func InstallAndInstantiateChaincode(channelID string, ccPkg *resource.CCPackage, ccID, ccVersion, ccPolicy string, orgs []*OrgContext, collConfigs ...*cb.CollectionConfig) error {
for _, orgCtx := range orgs {
if err := InstallChaincode(orgCtx.ResMgmt, orgCtx.CtxProvider, ccPkg, ccID, ccVersion, orgCtx.Peers); err != nil {
return errors.Wrapf(err, "failed to install chaincode to peers in org [%s]", orgCtx.OrgID)
}
}
_, err := InstantiateChaincode(orgs[0].ResMgmt, channelID, ccID, ccVersion, ccPolicy)
_, err := InstantiateChaincode(orgs[0].ResMgmt, channelID, ccID, ccVersion, ccPolicy, collConfigs...)
return err
}

Expand All @@ -274,7 +275,7 @@ func InstallChaincode(resMgmt *resmgmt.Client, ctxProvider contextAPI.ClientProv
}

// InstantiateChaincode instantiates the given chaincode to the given channel
func InstantiateChaincode(resMgmt *resmgmt.Client, channelID, ccName, ccVersion string, ccPolicyStr string) (resmgmt.InstantiateCCResponse, error) {
func InstantiateChaincode(resMgmt *resmgmt.Client, channelID, ccName, ccVersion string, ccPolicyStr string, collConfigs ...*cb.CollectionConfig) (resmgmt.InstantiateCCResponse, error) {
ccPolicy, err := cauthdsl.FromString(ccPolicyStr)
if err != nil {
return resmgmt.InstantiateCCResponse{}, errors.Wrapf(err, "error creating CC policy [%s]", ccPolicyStr)
Expand All @@ -283,11 +284,12 @@ func InstantiateChaincode(resMgmt *resmgmt.Client, channelID, ccName, ccVersion
return resMgmt.InstantiateCC(
channelID,
resmgmt.InstantiateCCRequest{
Name: ccName,
Path: "github.com/example_cc",
Version: ccVersion,
Args: ExampleCCInitArgs(),
Policy: ccPolicy,
Name: ccName,
Path: "github.com/example_cc",
Version: ccVersion,
Args: ExampleCCInitArgs(),
Policy: ccPolicy,
CollConfig: collConfigs,
},
resmgmt.WithRetry(retry.DefaultResMgmtOpts),
)
Expand Down
50 changes: 23 additions & 27 deletions test/integration/fab/discoveryclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ import (
)

const (
peer0_Org1 = "peer0.org1.example.com"
peer1_Org1 = "peer1.org1.example.com"
peer0_Org2 = "peer0.org2.example.com"
peer0Org1 = "peer0.org1.example.com"
peer1Org1 = "peer1.org1.example.com"
peer0Org2 = "peer0.org2.example.com"

peer0_Org1URL = "peer0.org1.example.com:7051"
peer1_Org1URL = "peer1.org1.example.com:7151"
peer0_Org2URL = "peer0.org2.example.com:8051"
peer0Org1URL = "peer0.org1.example.com:7051"
peer1Org1URL = "peer1.org1.example.com:7151"
peer0Org2URL = "peer0.org2.example.com:8051"

adminUser = "Admin"
org2Name = "Org2"
Expand All @@ -63,8 +63,8 @@ func TestDiscoveryClientPeers(t *testing.T) {

req := discclient.NewRequest().OfChannel(orgChannelID).AddPeersQuery()

peerCfg1, err := comm.NetworkPeerConfig(ctx.EndpointConfig(), peer0_Org1)
require.NoErrorf(t, err, "error getting peer config for [%s]", peer0_Org1)
peerCfg1, err := comm.NetworkPeerConfig(ctx.EndpointConfig(), peer0Org1)
require.NoErrorf(t, err, "error getting peer config for [%s]", peer0Org1)

responses, err := client.Send(reqCtx, req, peerCfg1.PeerConfig)
require.NoError(t, err, "error calling discover service send")
Expand Down Expand Up @@ -128,8 +128,8 @@ func TestDiscoveryClientLocalPeers(t *testing.T) {

req := discclient.NewRequest().AddLocalPeersQuery()

peerCfg1, err := comm.NetworkPeerConfig(ctx.EndpointConfig(), peer0_Org1)
require.NoErrorf(t, err, "error getting peer config for [%s]", peer0_Org1)
peerCfg1, err := comm.NetworkPeerConfig(ctx.EndpointConfig(), peer0Org1)
require.NoErrorf(t, err, "error getting peer config for [%s]", peer0Org1)

responses, err := client.Send(reqCtx, req, peerCfg1.PeerConfig)
require.NoError(t, err, "error calling discover service send")
Expand Down Expand Up @@ -165,20 +165,16 @@ func TestDiscoveryClientEndorsers(t *testing.T) {

ccVersion := "v0"
ccPkg, err := packager.NewCCPackage("github.com/example_cc", "../../fixtures/testdata")
if err != nil {
t.Fatal(err)
}

// TODO: Add tests with private data collections
require.NoError(t, err)

t.Run("Policy: Org1 Only", func(t *testing.T) {
ccID := integration.GenerateRandomID()
err = integration.InstallAndInstantiateChaincode(orgChannelID, ccPkg, ccID, ccVersion, "OR('Org1MSP.member')", orgsContext)
testEndorsers(
t, mainSDK,
newInterest(newCCCall(ccID)),
[]string{peer0_Org1URL},
[]string{peer1_Org1URL},
[]string{peer0Org1URL},
[]string{peer1Org1URL},
)
})

Expand All @@ -189,7 +185,7 @@ func TestDiscoveryClientEndorsers(t *testing.T) {
testEndorsers(
t, mainSDK,
newInterest(newCCCall(ccID)),
[]string{peer0_Org2URL},
[]string{peer0Org2URL},
)
})

Expand All @@ -200,9 +196,9 @@ func TestDiscoveryClientEndorsers(t *testing.T) {
testEndorsers(
t, mainSDK,
newInterest(newCCCall(ccID)),
[]string{peer0_Org1URL},
[]string{peer1_Org1URL},
[]string{peer0_Org2URL},
[]string{peer0Org1URL},
[]string{peer1Org1URL},
[]string{peer0Org2URL},
)
})

Expand All @@ -213,8 +209,8 @@ func TestDiscoveryClientEndorsers(t *testing.T) {
testEndorsers(
t, mainSDK,
newInterest(newCCCall(ccID)),
[]string{peer0_Org1URL, peer0_Org2URL},
[]string{peer1_Org1URL, peer0_Org2URL},
[]string{peer0Org1URL, peer0Org2URL},
[]string{peer1Org1URL, peer0Org2URL},
)
})

Expand All @@ -229,8 +225,8 @@ func TestDiscoveryClientEndorsers(t *testing.T) {
testEndorsers(
t, mainSDK,
newInterest(newCCCall(ccID1), newCCCall(ccID2)),
[]string{peer0_Org1URL, peer0_Org2URL},
[]string{peer1_Org1URL, peer0_Org2URL},
[]string{peer0Org1URL, peer0Org2URL},
[]string{peer1Org1URL, peer0Org2URL},
)
})
}
Expand All @@ -244,8 +240,8 @@ func testEndorsers(t *testing.T, sdk *fabsdk.FabricSDK, interest *fabdiscovery.C
client, err = discovery.New(ctx)
require.NoError(t, err, "error creating discovery client")

peerCfg1, err := comm.NetworkPeerConfig(ctx.EndpointConfig(), peer0_Org1)
require.NoErrorf(t, err, "error getting peer config for [%s]", peer0_Org1)
peerCfg1, err := comm.NetworkPeerConfig(ctx.EndpointConfig(), peer0Org1)
require.NoErrorf(t, err, "error getting peer config for [%s]", peer0Org1)

var chanResp discclient.ChannelResponse
var lastErr error
Expand Down
Loading

0 comments on commit 65f5a15

Please sign in to comment.