@@ -90,6 +90,33 @@ func TestConfigerInit(t *testing.T) {
90
90
}
91
91
}
92
92
93
+ func TestConfigerInvokeInvalidParameters (t * testing.T ) {
94
+ e := new (PeerConfiger )
95
+ stub := shim .NewMockStub ("PeerConfiger" , e )
96
+
97
+ res := stub .MockInit ("1" , nil )
98
+ assert .Equal (t , res .Status , int32 (shim .OK ), "Init failed" )
99
+
100
+ res = stub .MockInvoke ("2" , nil )
101
+ assert .Equal (t , res .Status , int32 (shim .ERROR ), "CSCC invoke expected to fail having zero arguments" )
102
+ assert .Equal (t , res .Message , "Incorrect number of arguments, 0" )
103
+
104
+ args := [][]byte {[]byte ("GetChannels" )}
105
+ res = stub .MockInvokeWithSignedProposal ("3" , args , nil )
106
+ assert .Equal (t , res .Status , int32 (shim .ERROR ), "CSCC invoke expected to fail no signed proposal provided" )
107
+ assert .Contains (t , res .Message , "failed authorization check" )
108
+
109
+ args = [][]byte {[]byte ("GetConfigBlock" ), []byte ("testChainID" )}
110
+ res = stub .MockInvokeWithSignedProposal ("4" , args , nil )
111
+ assert .Equal (t , res .Status , int32 (shim .ERROR ), "CSCC invoke expected to fail no signed proposal provided" )
112
+ assert .Contains (t , res .Message , "failed authorization check" )
113
+
114
+ args = [][]byte {[]byte ("fooFunction" ), []byte ("testChainID" )}
115
+ res = stub .MockInvoke ("5" , args )
116
+ assert .Equal (t , res .Status , int32 (shim .ERROR ), "CSCC invoke expected wrong function name provided" )
117
+ assert .Equal (t , res .Message , "Requested function fooFunction not found." )
118
+ }
119
+
93
120
func TestConfigerInvokeJoinChainMissingParams (t * testing.T ) {
94
121
viper .Set ("peer.fileSystemPath" , "/tmp/hyperledgertest/" )
95
122
os .Mkdir ("/tmp/hyperledgertest" , 0755 )
@@ -103,7 +130,7 @@ func TestConfigerInvokeJoinChainMissingParams(t *testing.T) {
103
130
t .FailNow ()
104
131
}
105
132
106
- // Failed path: Not enough parameters
133
+ // Failed path: expected to have at least one argument
107
134
args := [][]byte {[]byte ("JoinChain" )}
108
135
if res := stub .MockInvoke ("2" , args ); res .Status == shim .OK {
109
136
t .Fatalf ("cscc invoke JoinChain should have failed with invalid number of args: %v" , args )
@@ -181,13 +208,19 @@ func TestConfigerInvokeJoinChainCorrectParams(t *testing.T) {
181
208
sProp , _ := utils .MockSignedEndorserProposalOrPanic ("" , & pb.ChaincodeSpec {}, []byte ("Alice" ), []byte ("msg1" ))
182
209
identityDeserializer .Msg = sProp .ProposalBytes
183
210
sProp .Signature = sProp .ProposalBytes
211
+
212
+ // Try fail path with nil block
213
+ res := stub .MockInvokeWithSignedProposal ("2" , [][]byte {[]byte ("JoinChain" ), nil }, sProp )
214
+ assert .Equal (t , res .Status , int32 (shim .ERROR ))
215
+
216
+ // Now, continue with valid execution path
184
217
if res := stub .MockInvokeWithSignedProposal ("2" , args , sProp ); res .Status != shim .OK {
185
218
t .Fatalf ("cscc invoke JoinChain failed with: %v" , res .Message )
186
219
}
187
220
188
221
// This call must fail
189
222
sProp .Signature = nil
190
- res : = stub .MockInvokeWithSignedProposal ("3" , args , sProp )
223
+ res = stub .MockInvokeWithSignedProposal ("3" , args , sProp )
191
224
if res .Status == shim .OK {
192
225
t .Fatalf ("cscc invoke JoinChain must fail : %v" , res .Message )
193
226
}
0 commit comments