Skip to content

Commit

Permalink
[FAB-10625] fixing local integration test
Browse files Browse the repository at this point in the history
Change-Id: I2e78004640c81a282cd526cdbb9d11f003923c98
Signed-off-by: Sudesh Shetty <sudesh.shetty@securekey.com>
  • Loading branch information
sudeshrshetty committed Jun 13, 2018
1 parent 7dca4ca commit e1d3ddb
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pkg/fab/comm/network.go
Expand Up @@ -17,7 +17,7 @@ import (
func NetworkPeerConfig(cfg fab.EndpointConfig, key string) (*fab.NetworkPeer, error) {
peerCfg, ok := cfg.PeerConfig(key)
if !ok {
return nil, errors.Errorf("peer not found")
return nil, errors.Errorf("peer [%s] not found", key)
}

// find MSP ID
Expand Down
22 changes: 11 additions & 11 deletions test/fixtures/config/config_test.yaml
Expand Up @@ -406,17 +406,17 @@ certificateAuthorities:
# SubstitutionExp for the fields eventUrl and gprcOptions.ssl-target-name-override respectively
# In any case mappedHost's config will be used, so mapped host cannot be empty, if entityMatchers are used
#entityMatchers:
entityMatchers:
peer:
- pattern: (\w+).org1.example.com:(\d+)
urlSubstitutionExp: $1.org1.example.com:$2
sslTargetOverrideUrlSubstitutionExp: $1.org1.example.com
mappedHost: peer0.org1.example.com

- pattern: (\w+).org2.example.com:(\d+)
urlSubstitutionExp: $1.org2.example.com:$2
sslTargetOverrideUrlSubstitutionExp: $1.org2.example.com
mappedHost: peer0.org2.example.com
#entityMatchers:
# peer:
# - pattern: (\w+).org1.example.com:(\d+)
# urlSubstitutionExp: $1.org1.example.com:$2
# sslTargetOverrideUrlSubstitutionExp: $1.org1.example.com
# mappedHost: peer0.org1.example.com
#
# - pattern: (\w+).org2.example.com:(\d+)
# urlSubstitutionExp: $1.org2.example.com:$2
# sslTargetOverrideUrlSubstitutionExp: $1.org2.example.com
# mappedHost: peer0.org2.example.com

# - pattern: (\w+).org1.example.(\w+)
# urlSubstitutionExp: peer0.org1.example.com:7051
Expand Down
28 changes: 26 additions & 2 deletions test/fixtures/config/overrides/local_entity_matchers.yaml
Expand Up @@ -20,25 +20,49 @@
# In any case mappedHost's config will be used, so mapped host cannot be empty, if entityMatchers are used
entityMatchers:
peer:
- pattern: (\w+).org1.example.(\w+)
- pattern: peer0.org1.example.(\w+)
urlSubstitutionExp: localhost:7051
eventUrlSubstitutionExp: localhost:7053
sslTargetOverrideUrlSubstitutionExp: peer0.org1.example.com
mappedHost: local.peer0.org1.example.com

- pattern: peer1.org1.example.(\w+)
urlSubstitutionExp: localhost:7151
eventUrlSubstitutionExp: localhost:7153
sslTargetOverrideUrlSubstitutionExp: peer1.org1.example.com
mappedHost: local.peer1.org1.example.com

- pattern: (\w+).org2.example.(\w+)
urlSubstitutionExp: localhost:8051
eventUrlSubstitutionExp: localhost:8053
sslTargetOverrideUrlSubstitutionExp: peer0.org2.example.com
mappedHost: local.peer0.org2.example.com

- pattern: (\w+).org1.example.(\w+):(\d+)
urlSubstitutionExp: localhost:$2
eventUrlSubstitutionExp: localhost:$2
sslTargetOverrideUrlSubstitutionExp: $1.org1.example.com
mappedHost: local.$1.org1.example.com

- pattern: (\w+).org2.example.(\w+):(\d+)
urlSubstitutionExp: localhost:8051
eventUrlSubstitutionExp: localhost:8053
sslTargetOverrideUrlSubstitutionExp: peer0.org2.example.com
mappedHost: local.peer0.org2.example.com

- pattern: (\w+):7051
urlSubstitutionExp: localhost:7051
eventUrlSubstitutionExp: localhost:7053
sslTargetOverrideUrlSubstitutionExp: peer0.org1.example.com
mappedHost: local.peer0.org1.example.com

- pattern: (\w+).org2.example.(\w+):(\d+)
- pattern: (\w+):7151
urlSubstitutionExp: localhost:7151
eventUrlSubstitutionExp: localhost:7153
sslTargetOverrideUrlSubstitutionExp: peer1.org1.example.com
mappedHost: local.peer1.org1.example.com

- pattern: (\w+):8051
urlSubstitutionExp: localhost:8051
eventUrlSubstitutionExp: localhost:8053
sslTargetOverrideUrlSubstitutionExp: peer0.org2.example.com
Expand Down
22 changes: 22 additions & 0 deletions test/fixtures/config/overrides/local_orderers_peers_ca.yaml
Expand Up @@ -63,6 +63,28 @@ peers:
# Certificate location absolute path
path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem

local.peer1.org1.example.com:
# this URL is used to send endorsement and query requests
url: peer1.org1.example.com:7151
# eventUrl is only needed when using eventhub (default is delivery service)
eventUrl: peer1.org1.example.com:7153

grpcOptions:
ssl-target-name-override: peer1.org1.example.com
# These parameters should be set in coordination with the keepalive policy on the server,
# as incompatible settings can result in closing of connection.
# When duration of the 'keep-alive-time' is set to 0 or less the keep alive client parameters are disabled
keep-alive-time: 0s
keep-alive-timeout: 20s
keep-alive-permit: false
fail-fast: false
# allow-insecure will be taken into consideration if address has no protocol defined, if true then grpc or else grpcs
allow-insecure: false

tlsCACerts:
# Certificate location absolute path
path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem

local.peer0.org2.example.com:
url: peer0.org2.example.com:8051
# eventUrl is only needed when using eventhub (default is delivery service)
Expand Down
36 changes: 36 additions & 0 deletions test/integration/e2e/configless/endpointconfig_override_test.go
Expand Up @@ -198,6 +198,35 @@ var (
},
}

peersByLocalURL = map[string]fab.PeerConfig{
"localhost:7051": {
URL: "localhost:7051",
EventURL: "localhost:7053",
GRPCOptions: map[string]interface{}{
"ssl-target-name-override": "peer0.org1.example.com",
"keep-alive-time": 0 * time.Second,
"keep-alive-timeout": 20 * time.Second,
"keep-alive-permit": false,
"fail-fast": false,
"allow-insecure": false,
},
TLSCACert: tlsCertByBytes("${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem"),
},
"localhost:8051": {
URL: "localhost:8051",
EventURL: "localhost:8053",
GRPCOptions: map[string]interface{}{
"ssl-target-name-override": "peer0.org2.example.com",
"keep-alive-time": 0 * time.Second,
"keep-alive-timeout": 20 * time.Second,
"keep-alive-permit": false,
"fail-fast": false,
"allow-insecure": false,
},
TLSCACert: tlsCertByBytes("${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org2.example.com/tlsca/tlsca.org2.example.com-cert.pem"),
},
}

caConfigObj = map[string]caConfig{
"ca.org1.example.com": {
URL: "https://ca.org1.example.com:7054",
Expand Down Expand Up @@ -496,6 +525,13 @@ func (m *examplePeerConfig) PeerConfig(nameOrURL string) (*fab.PeerConfig, bool)
return &pcfg, true
}

if integration.IsLocal() {
pcfg, ok := peersByLocalURL[nameOrURL]
if ok {
return &pcfg, true
}
}

i := strings.Index(nameOrURL, ":")
if i > 0 {
return m.PeerConfig(nameOrURL[0:i])
Expand Down
18 changes: 12 additions & 6 deletions test/integration/e2e/end_to_end.go
Expand Up @@ -9,7 +9,6 @@ package e2e
import (
"path"
"strconv"
"strings"
"testing"
"time"

Expand All @@ -27,6 +26,8 @@ import (

mspclient "github.com/hyperledger/fabric-sdk-go/pkg/client/msp"

"strings"

"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
packager "github.com/hyperledger/fabric-sdk-go/pkg/fab/ccpackager/gopackager"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
Expand Down Expand Up @@ -106,10 +107,8 @@ func setupAndRun(t *testing.T, doSetup bool, configOpt core.ConfigProvider, sdkO
t.Fatalf("Did NOT receive CC event for eventId(%s)\n", eventID)
}

i := strings.Index(ccEvent.SourceURL, ":")

// Verify move funds transaction result on the same peer where the event came from.
verifyFundsIsMoved(client, t, value, ccEvent.SourceURL[0:i])
verifyFundsIsMoved(client, t, value, ccEvent)

}

Expand Down Expand Up @@ -148,8 +147,15 @@ func createChannelAndCC(t *testing.T, sdk *fabsdk.FabricSDK) {
createCC(t, orgResMgmt)
}

func verifyFundsIsMoved(client *channel.Client, t *testing.T, value []byte, targetEndpoints ...string) {
newValue := queryCC(client, t, targetEndpoints...)
func verifyFundsIsMoved(client *channel.Client, t *testing.T, value []byte, ccevent *fab.CCEvent) {

//Fix for issue prev in release test, where 'ccEvent.SourceURL' has event URL
if !integration.IsLocal() {
portIndex := strings.Index(ccevent.SourceURL, ":")
ccevent.SourceURL = ccevent.SourceURL[0:portIndex]
}

newValue := queryCC(client, t, ccevent.SourceURL)
valueInt, err := strconv.Atoi(string(value))
if err != nil {
t.Fatal(err.Error())
Expand Down
9 changes: 8 additions & 1 deletion test/integration/sdk/ledger_queries_test.go
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
"github.com/hyperledger/fabric-sdk-go/pkg/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
"github.com/hyperledger/fabric-sdk-go/test/integration"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -113,7 +114,13 @@ func TestNoLedgerEndpoints(t *testing.T) {
// Using shared SDK instance to increase test speed.
testSetup := mainTestSetup

sdk, err := fabsdk.New(config.FromFile("../../fixtures/config/config_test_endpoints.yaml"))
configProvider := config.FromFile("../../fixtures/config/config_test_endpoints.yaml")
//Add entity matchers if local test
if integration.IsLocal() {
configProvider = integration.AddLocalEntityMapping(configProvider, integration.LocalOrdererPeersConfig)
}

sdk, err := fabsdk.New(configProvider)
if err != nil {
panic(fmt.Sprintf("Failed to create new SDK: %s", err))
}
Expand Down

0 comments on commit e1d3ddb

Please sign in to comment.