Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit f048f16

Browse files
committed
[FAB-6423] Go SDK config reused issue
Change-Id: I89bc8a91532e8b1ebd4bb79bcf82c27bc405adeb Signed-off-by: Sandra Vrtikapa <sandra.vrtikapa@securekey.com>
1 parent 171e0c6 commit f048f16

File tree

7 files changed

+279
-108
lines changed

7 files changed

+279
-108
lines changed

def/fabapi/fabapi_test.go

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,103 @@ import (
1515
func TestNewDefaultSDK(t *testing.T) {
1616

1717
setup := Options{
18-
ConfigFile: "../../test/fixtures/config/config_test.yaml",
18+
ConfigFile: "../../test/fixtures/config/invalid.yaml",
1919
StateStoreOpts: opt.StateStoreOpts{
2020
Path: "/tmp/state",
2121
},
2222
}
2323

24+
// Test new SDK with invalid config file
25+
_, err := NewSDK(setup)
26+
if err == nil {
27+
t.Fatalf("Should have failed for invalid config file")
28+
}
29+
30+
// Test New SDK with valid config file
31+
setup.ConfigFile = "../../test/fixtures/config/config_test.yaml"
2432
sdk, err := NewSDK(setup)
2533
if err != nil {
2634
t.Fatalf("Error initializing SDK: %s", err)
2735
}
2836

37+
// Default channel client (uses organisation from client configuration)
2938
_, err = sdk.NewChannelClient("mychannel", "User1")
3039
if err != nil {
3140
t.Fatalf("Failed to create new channel client: %s", err)
3241
}
3342

43+
// Test configuration failure for channel client (mychannel does't have event source configured for Org2)
44+
_, err = sdk.NewChannelClientWithOpts("mychannel", "User1", &ChannelClientOpts{OrgName: "Org2"})
45+
if err == nil {
46+
t.Fatalf("Should have failed to create channel client since event source not configured for Org2")
47+
}
48+
49+
// Test new channel client with options
50+
_, err = sdk.NewChannelClientWithOpts("orgchannel", "User1", &ChannelClientOpts{OrgName: "Org2"})
51+
if err != nil {
52+
t.Fatalf("Failed to create new channel client: %s", err)
53+
}
54+
55+
}
56+
57+
func TestNewDefaultTwoValidSDK(t *testing.T) {
58+
setup := Options{
59+
ConfigFile: "../../test/fixtures/config/config_test.yaml",
60+
StateStoreOpts: opt.StateStoreOpts{
61+
Path: "/tmp/state",
62+
},
63+
}
64+
65+
sdk1, err := NewSDK(setup)
66+
if err != nil {
67+
t.Fatalf("Error initializing SDK: %s", err)
68+
}
69+
70+
setup.ConfigFile = "./testdata/test.yaml"
71+
sdk2, err := NewSDK(setup)
72+
if err != nil {
73+
t.Fatalf("Error initializing SDK: %s", err)
74+
}
75+
76+
// Default sdk with two channels
77+
client1, err := sdk1.configProvider.Client()
78+
if err != nil {
79+
t.Fatalf("Error getting client from config: %s", err)
80+
}
81+
82+
if client1.Organization != "Org1" {
83+
t.Fatalf("Unexpected org in config: %s", client1.Organization)
84+
}
85+
86+
client2, err := sdk2.configProvider.Client()
87+
if err != nil {
88+
t.Fatalf("Error getting client from config: %s", err)
89+
}
90+
91+
if client2.Organization != "Org2" {
92+
t.Fatalf("Unexpected org in config: %s", client1.Organization)
93+
}
94+
95+
// Test SDK1 channel clients ('mychannel', 'orgchannel')
96+
_, err = sdk1.NewChannelClient("mychannel", "User1")
97+
if err != nil {
98+
t.Fatalf("Failed to create new channel client: %s", err)
99+
}
100+
101+
_, err = sdk1.NewChannelClient("orgchannel", "User1")
102+
if err != nil {
103+
t.Fatalf("Failed to create new channel client: %s", err)
104+
}
105+
106+
// SDK 2 doesn't have 'mychannel' configured
107+
_, err = sdk2.NewChannelClient("mychannel", "User1")
108+
if err == nil {
109+
t.Fatalf("Should have failed to create channel that is not configured")
110+
}
111+
112+
// SDK 2 has 'orgchannel' configured
113+
_, err = sdk2.NewChannelClient("orgchannel", "User1")
114+
if err != nil {
115+
t.Fatalf("Failed to create new 'orgchannel' channel client: %s", err)
116+
}
34117
}

def/fabapi/testdata/test.yaml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#
2+
# Copyright SecureKey Technologies Inc. All Rights Reserved.
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
name: "global-trade-network"
8+
9+
x-type: "hlfv1"
10+
x-loggingLevel: info
11+
12+
description: "The network to be in if you want to stay in the global trade business"
13+
version: 1.0.0
14+
15+
client:
16+
organization: Org2
17+
18+
logging:
19+
level: info
20+
21+
# Global configuration for peer, event service and orderer timeouts
22+
peer:
23+
timeout:
24+
connection: 3s
25+
queryResponse: 20s
26+
executeTxResponse: 30s
27+
eventService:
28+
timeout:
29+
connection: 3s
30+
registrationResponse: 3s
31+
orderer:
32+
timeout:
33+
connection: 3s
34+
response: 5s
35+
36+
cryptoconfig:
37+
path: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/channel/crypto-config
38+
39+
credentialStore:
40+
path: "/tmp/hfc-kvs"
41+
42+
cryptoStore:
43+
# Specific to the underlying KeyValueStore that backs the crypto key store.
44+
path: /tmp/msp
45+
46+
# BCCSP config for the client. Used by GO SDK.
47+
BCCSP:
48+
security:
49+
enabled: true
50+
default:
51+
provider: "SW"
52+
hashAlgorithm: "SHA2"
53+
softVerify: true
54+
ephemeral: false
55+
level: 256
56+
57+
channels:
58+
59+
orgchannel:
60+
61+
orderers:
62+
- orderer.example.com
63+
64+
peers:
65+
peer0.org2.example.com:
66+
endorsingPeer: true
67+
chaincodeQuery: true
68+
ledgerQuery: true
69+
eventSource: true
70+
71+
organizations:
72+
73+
Org2:
74+
mspid: Org2MSP
75+
76+
# Needed to load users crypto keys and certs for this org (absolute path or relative to global crypto path, DEV mode)
77+
cryptoPath: peerOrganizations/org2.example.com/users/{userName}@org2.example.com/msp
78+
79+
peers:
80+
- peer0.org2.example.com
81+
82+
certificateAuthorities:
83+
- ca-org2
84+
85+
ordererorg:
86+
mspID: "OrdererOrg"
87+
88+
# Needed to load users crypto keys and certs for this org (absolute path or relative to global crypto path, DEV mode)
89+
cryptoPath: ordererOrganizations/example.com/users/{userName}@example.com/msp
90+
91+
92+
orderers:
93+
orderer.example.com:
94+
url: grpcs://orderer.example.com:7050
95+
96+
grpcOptions:
97+
ssl-target-name-override: orderer.example.com
98+
grpc-max-send-message-length: 15
99+
100+
tlsCACerts:
101+
path: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/channel/crypto-config/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
102+
103+
peers:
104+
peer0.org2.example.com:
105+
url: grpcs://peer0.org2.example.com:7051
106+
eventUrl: grpcs://peer0.org2.example.com:7053
107+
grpcOptions:
108+
ssl-target-name-override: peer0.org2.example.com
109+
tlsCACerts:
110+
path: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/channel/crypto-config/peerOrganizations/org2.example.com/tlsca/tlsca.org2.example.com-cert.pem
111+
112+
certificateAuthorities:
113+
ca-org2:
114+
url: https://ca_peerOrg2:7054
115+
116+
httpOptions:
117+
verify: true
118+
119+
tlsCACerts:
120+
path: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/tls/fabricca/certs/ca_root.pem
121+
client:
122+
keyfile: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/tls/fabricca/certs/client/client_fabric_client-key.pem
123+
certfile: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/tls/fabricca/certs/client/client_fabric_client.pem
124+
125+
registrar:
126+
enrollId: admin
127+
enrollSecret: adminpw
128+
129+
caName: ca-org2

0 commit comments

Comments
 (0)