@@ -13,26 +13,29 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
- package cscc
16
+ package chaincode
17
17
18
18
import (
19
19
"fmt"
20
20
"net"
21
21
"os"
22
22
"testing"
23
+ "time"
23
24
24
25
"github.com/spf13/viper"
25
26
"github.com/stretchr/testify/assert"
26
27
"google.golang.org/grpc"
27
28
28
29
"github.com/golang/protobuf/proto"
29
30
"github.com/hyperledger/fabric/core/chaincode/shim"
31
+ "github.com/hyperledger/fabric/core/peer"
30
32
"github.com/hyperledger/fabric/gossip/service"
31
33
"github.com/hyperledger/fabric/protos/common"
34
+ pb "github.com/hyperledger/fabric/protos/peer"
32
35
"github.com/hyperledger/fabric/protos/utils"
33
36
)
34
37
35
- func TestInit (t * testing.T ) {
38
+ func TestConfigerInit (t * testing.T ) {
36
39
e := new (PeerConfiger )
37
40
stub := shim .NewMockStub ("PeerConfiger" , e )
38
41
@@ -42,27 +45,48 @@ func TestInit(t *testing.T) {
42
45
}
43
46
}
44
47
45
- func TestInvokeJoinChainMissingParams (t * testing.T ) {
48
+ func setupEndpoint (t * testing.T ) {
49
+ peerAddress := peer .GetLocalIP ()
50
+ if peerAddress == "" {
51
+ peerAddress = "0.0.0.0"
52
+ }
53
+ peerAddress = peerAddress + ":21213"
54
+ t .Logf ("Local peer IP address: %s" , peerAddress )
55
+ var opts []grpc.ServerOption
56
+ grpcServer := grpc .NewServer (opts ... )
57
+ getPeerEndpoint := func () (* pb.PeerEndpoint , error ) {
58
+ return & pb.PeerEndpoint {ID : & pb.PeerID {Name : "cscctestpeer" }, Address : peerAddress }, nil
59
+ }
60
+ ccStartupTimeout := time .Duration (30000 ) * time .Millisecond
61
+ pb .RegisterChaincodeSupportServer (grpcServer , NewChaincodeSupport (getPeerEndpoint , false , ccStartupTimeout ))
62
+ }
63
+
64
+ func TestConfigerInvokeJoinChainMissingParams (t * testing.T ) {
65
+ //t.Skip("Test CI build")
46
66
viper .Set ("peer.fileSystemPath" , "/var/hyperledger/test/" )
47
67
defer os .RemoveAll ("/var/hyperledger/test/" )
48
68
49
69
e := new (PeerConfiger )
50
70
stub := shim .NewMockStub ("PeerConfiger" , e )
51
71
72
+ setupEndpoint (t )
52
73
// Failed path: Not enough parameters
53
74
args := [][]byte {[]byte ("JoinChain" )}
54
75
if _ , err := stub .MockInvoke ("1" , args ); err == nil {
55
76
t .Fatalf ("cscc invoke JoinChain should have failed with invalid number of args: %v" , args )
56
77
}
57
78
}
58
79
59
- func TestInvokeJoinChainWrongParams (t * testing.T ) {
80
+ func TestConfigerInvokeJoinChainWrongParams (t * testing.T ) {
81
+ //t.Skip("Test CI build")
60
82
viper .Set ("peer.fileSystemPath" , "/var/hyperledger/test/" )
61
83
defer os .RemoveAll ("/var/hyperledger/test/" )
62
84
63
85
e := new (PeerConfiger )
64
86
stub := shim .NewMockStub ("PeerConfiger" , e )
65
87
88
+ setupEndpoint (t )
89
+
66
90
// Failed path: wrong parameter type
67
91
args := [][]byte {[]byte ("JoinChain" ), []byte ("action" )}
68
92
if _ , err := stub .MockInvoke ("1" , args ); err == nil {
@@ -71,13 +95,16 @@ func TestInvokeJoinChainWrongParams(t *testing.T) {
71
95
}
72
96
}
73
97
74
- func TestInvokeJoinChainCorrectParams (t * testing.T ) {
98
+ func TestConfigerInvokeJoinChainCorrectParams (t * testing.T ) {
99
+ //t.Skip("Test CI build")
75
100
viper .Set ("peer.fileSystemPath" , "/var/hyperledger/test/" )
76
101
defer os .RemoveAll ("/var/hyperledger/test/" )
77
102
78
103
e := new (PeerConfiger )
79
104
stub := shim .NewMockStub ("PeerConfiger" , e )
80
105
106
+ setupEndpoint (t )
107
+
81
108
// Initialize gossip service
82
109
grpcServer := grpc .NewServer ()
83
110
socket , err := net .Listen ("tcp" , fmt .Sprintf ("%s:%d" , "" , 13611 ))
@@ -92,7 +119,7 @@ func TestInvokeJoinChainCorrectParams(t *testing.T) {
92
119
t .Fatalf ("cscc invoke JoinChain failed because invalid block" )
93
120
}
94
121
args := [][]byte {[]byte ("JoinChain" ), blockBytes }
95
- if _ , err : = stub .MockInvoke ("1" , args ); err != nil {
122
+ if _ , err = stub .MockInvoke ("1" , args ); err != nil {
96
123
t .Fatalf ("cscc invoke JoinChain failed with: %v" , err )
97
124
}
98
125
@@ -103,15 +130,18 @@ func TestInvokeJoinChainCorrectParams(t *testing.T) {
103
130
t .Fatalf ("cscc invoke JoinChain failed with: %v" , err )
104
131
}
105
132
args = [][]byte {[]byte ("GetConfigBlock" ), []byte (chainID )}
106
- if _ , err : = stub .MockInvoke ("1" , args ); err != nil {
133
+ if _ , err = stub .MockInvoke ("1" , args ); err != nil {
107
134
t .Fatalf ("cscc invoke GetConfigBlock failed with: %v" , err )
108
135
}
109
136
}
110
137
111
- func TestInvokeUpdateConfigBlock (t * testing.T ) {
138
+ func TestConfigerInvokeUpdateConfigBlock (t * testing.T ) {
139
+ //t.Skip("Test CI build")
112
140
e := new (PeerConfiger )
113
141
stub := shim .NewMockStub ("PeerConfiger" , e )
114
142
143
+ setupEndpoint (t )
144
+
115
145
// Failed path: Not enough parameters
116
146
args := [][]byte {[]byte ("UpdateConfigBlock" )}
117
147
if _ , err := stub .MockInvoke ("1" , args ); err == nil {
0 commit comments