@@ -17,13 +17,11 @@ package cscc
17
17
18
18
import (
19
19
"fmt"
20
- "net"
21
20
"os"
21
+ "strings"
22
22
"testing"
23
23
"time"
24
24
25
- "strings"
26
-
27
25
"github.com/golang/protobuf/proto"
28
26
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
29
27
"github.com/hyperledger/fabric/common/localmsp"
@@ -45,7 +43,6 @@ import (
45
43
"github.com/hyperledger/fabric/protos/utils"
46
44
"github.com/spf13/viper"
47
45
"github.com/stretchr/testify/assert"
48
- "google.golang.org/grpc"
49
46
)
50
47
51
48
type mockDeliveryClient struct {
@@ -91,22 +88,6 @@ func TestConfigerInit(t *testing.T) {
91
88
}
92
89
}
93
90
94
- func setupEndpoint (t * testing.T ) {
95
- peerAddress := peer .GetLocalIP ()
96
- if peerAddress == "" {
97
- peerAddress = "0.0.0.0"
98
- }
99
- peerAddress = peerAddress + ":21213"
100
- t .Logf ("Local peer IP address: %s" , peerAddress )
101
- var opts []grpc.ServerOption
102
- grpcServer := grpc .NewServer (opts ... )
103
- getPeerEndpoint := func () (* pb.PeerEndpoint , error ) {
104
- return & pb.PeerEndpoint {Id : & pb.PeerID {Name : "cscctestpeer" }, Address : peerAddress }, nil
105
- }
106
- ccStartupTimeout := time .Duration (30000 ) * time .Millisecond
107
- pb .RegisterChaincodeSupportServer (grpcServer , chaincode .NewChaincodeSupport (getPeerEndpoint , false , ccStartupTimeout ))
108
- }
109
-
110
91
func TestConfigerInvokeJoinChainMissingParams (t * testing.T ) {
111
92
viper .Set ("peer.fileSystemPath" , "/tmp/hyperledgertest/" )
112
93
os .Mkdir ("/tmp/hyperledgertest" , 0755 )
@@ -120,7 +101,6 @@ func TestConfigerInvokeJoinChainMissingParams(t *testing.T) {
120
101
t .FailNow ()
121
102
}
122
103
123
- setupEndpoint (t )
124
104
// Failed path: Not enough parameters
125
105
args := [][]byte {[]byte ("JoinChain" )}
126
106
if res := stub .MockInvoke ("2" , args ); res .Status == shim .OK {
@@ -141,8 +121,6 @@ func TestConfigerInvokeJoinChainWrongParams(t *testing.T) {
141
121
t .FailNow ()
142
122
}
143
123
144
- setupEndpoint (t )
145
-
146
124
// Failed path: wrong parameter type
147
125
args := [][]byte {[]byte ("JoinChain" ), []byte ("action" )}
148
126
if res := stub .MockInvoke ("2" , args ); res .Status == shim .OK {
@@ -152,6 +130,7 @@ func TestConfigerInvokeJoinChainWrongParams(t *testing.T) {
152
130
153
131
func TestConfigerInvokeJoinChainCorrectParams (t * testing.T ) {
154
132
viper .Set ("peer.fileSystemPath" , "/tmp/hyperledgertest/" )
133
+ viper .Set ("chaincode.executetimeout" , "3000" )
155
134
os .Mkdir ("/tmp/hyperledgertest" , 0755 )
156
135
157
136
peer .MockInitialize ()
@@ -162,6 +141,13 @@ func TestConfigerInvokeJoinChainCorrectParams(t *testing.T) {
162
141
e := new (PeerConfiger )
163
142
stub := shim .NewMockStub ("PeerConfiger" , e )
164
143
144
+ peerEndpoint := "localhost:13611"
145
+ getPeerEndpoint := func () (* pb.PeerEndpoint , error ) {
146
+ return & pb.PeerEndpoint {Id : & pb.PeerID {Name : "cscctestpeer" }, Address : peerEndpoint }, nil
147
+ }
148
+ ccStartupTimeout := time .Duration (30000 ) * time .Millisecond
149
+ chaincode .NewChaincodeSupport (getPeerEndpoint , false , ccStartupTimeout )
150
+
165
151
// Init the policy checker
166
152
policyManagerGetter := & policy.MockChannelPolicyManagerGetter {
167
153
Managers : map [string ]policies.Manager {
@@ -177,18 +163,9 @@ func TestConfigerInvokeJoinChainCorrectParams(t *testing.T) {
177
163
& policy.MockMSPPrincipalGetter {Principal : []byte ("Alice" )},
178
164
)
179
165
180
- setupEndpoint (t )
181
-
182
- // Initialize gossip service
183
- grpcServer := grpc .NewServer ()
184
- socket , err := net .Listen ("tcp" , fmt .Sprintf ("%s:%d" , "" , 13611 ))
185
- assert .NoError (t , err )
186
- go grpcServer .Serve (socket )
187
- defer grpcServer .Stop ()
188
-
189
166
identity , _ := mgmt .GetLocalSigningIdentityOrPanic ().Serialize ()
190
167
messageCryptoService := mcs .New (& mcs.MockChannelPolicyManagerGetter {}, localmsp .NewSigner (), mgmt .NewDeserializersManager ())
191
- service .InitGossipServiceCustomDeliveryFactory (identity , "localhost:13611" , grpcServer , & mockDeliveryClientFactory {}, messageCryptoService )
168
+ service .InitGossipServiceCustomDeliveryFactory (identity , peerEndpoint , nil , & mockDeliveryClientFactory {}, messageCryptoService )
192
169
193
170
// Successful path for JoinChain
194
171
blockBytes := mockConfigBlock ()
@@ -262,8 +239,6 @@ func TestConfigerInvokeUpdateConfigBlock(t *testing.T) {
262
239
& policy.MockMSPPrincipalGetter {Principal : []byte ("Alice" )},
263
240
)
264
241
265
- setupEndpoint (t )
266
-
267
242
sProp , _ := utils .MockSignedEndorserProposalOrPanic ("" , & pb.ChaincodeSpec {}, []byte ("Alice" ), []byte ("msg1" ))
268
243
identityDeserializer .Msg = sProp .ProposalBytes
269
244
sProp .Signature = sProp .ProposalBytes
0 commit comments