Skip to content

Commit 18ea0ff

Browse files
committed
[FAB-9924] UT preperations for pluggable validation
This change set makes some simple unit test changes to make the top change set more easy to review Change-Id: I4c51fc776e4f36bfef1460d52a9569ae9846916d Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent 92eeb20 commit 18ea0ff

File tree

1 file changed

+1
-91
lines changed

1 file changed

+1
-91
lines changed

core/scc/vscc/validator_onevalidsignature_test.go

Lines changed: 1 addition & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,6 @@ func createLSCCTxPutCds(ccname, ccver, f string, res, cdsbytes []byte, putcds bo
276276
return utils.CreateSignedTx(prop, id, presp)
277277
}
278278

279-
func TestInit(t *testing.T) {
280-
v := New(NewMockProvider())
281-
stub := shim.NewMockStub("validatoronevalidsignature", v)
282-
283-
if res := stub.MockInit("1", nil); res.Status != shim.OK {
284-
t.Fatalf("vscc init failed with %s", res.Message)
285-
}
286-
}
287-
288279
func getSignedByMSPMemberPolicy(mspID string) ([]byte, error) {
289280
p := cauthdsl.SignedByMspMember(mspID)
290281

@@ -332,33 +323,8 @@ func TestInvoke(t *testing.T) {
332323
t.Fatalf("vscc init failed with %s", res.Message)
333324
}
334325

335-
// Failed path: Invalid arguments
336-
args := [][]byte{[]byte("dv")}
337-
if res := stub.MockInvoke("1", args); res.Status == shim.OK {
338-
t.Fatalf("vscc invoke should have failed")
339-
}
340-
341-
// not enough args
342-
args = [][]byte{[]byte("dv"), []byte("tx")}
343-
args[1] = nil
344-
if res := stub.MockInvoke("1", args); res.Status == shim.OK {
345-
t.Fatalf("vscc invoke should have failed")
346-
}
347-
348-
// nil args
349-
args = [][]byte{nil, nil, nil}
350-
if res := stub.MockInvoke("1", args); res.Status == shim.OK {
351-
t.Fatalf("vscc invoke should have failed")
352-
}
353-
354-
// nil args
355-
args = [][]byte{[]byte("a"), []byte("a"), nil}
356-
if res := stub.MockInvoke("1", args); res.Status == shim.OK {
357-
t.Fatalf("vscc invoke should have failed")
358-
}
359-
360326
// broken Envelope
361-
args = [][]byte{[]byte("a"), []byte("a"), []byte("a")}
327+
args := [][]byte{[]byte("a"), []byte("a"), []byte("a")}
362328
if res := stub.MockInvoke("1", args); res.Status == shim.OK {
363329
t.Fatalf("vscc invoke should have failed")
364330
}
@@ -448,62 +414,6 @@ func TestInvoke(t *testing.T) {
448414
}
449415
}
450416

451-
func TestInvalidFunction(t *testing.T) {
452-
State := make(map[string]map[string][]byte)
453-
mp := (&scc.MocksccProviderFactory{
454-
Qe: lm.NewMockQueryExecutor(State),
455-
ApplicationConfigBool: true,
456-
ApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
457-
}).NewSystemChaincodeProvider().(*scc.MocksccProviderImpl)
458-
459-
v := New(mp)
460-
stub := shim.NewMockStub("validatoronevalidsignature", v)
461-
462-
lccc := lscc.New(mp)
463-
stublccc := shim.NewMockStub("lscc", lccc)
464-
State["lscc"] = stublccc.State
465-
stub.MockPeerChaincode("lscc", stublccc)
466-
467-
r1 := stub.MockInit("1", [][]byte{})
468-
if r1.Status != shim.OK {
469-
fmt.Println("Init failed", string(r1.Message))
470-
t.FailNow()
471-
}
472-
473-
r := stublccc.MockInit("1", [][]byte{})
474-
if r.Status != shim.OK {
475-
fmt.Println("Init failed", string(r.Message))
476-
t.FailNow()
477-
}
478-
479-
ccname := "mycc"
480-
ccver := "1"
481-
482-
res, err := createCCDataRWset(ccname, ccname, ccver, nil)
483-
assert.NoError(t, err)
484-
485-
tx, err := createLSCCTx(ccname, ccver, lscc.GETCCDATA, res)
486-
if err != nil {
487-
t.Fatalf("createTx returned err %s", err)
488-
}
489-
490-
envBytes, err := utils.GetBytesEnvelope(tx)
491-
if err != nil {
492-
t.Fatalf("GetBytesEnvelope returned err %s", err)
493-
}
494-
495-
// good path: signed by the right MSP
496-
policy, err := getSignedByMSPMemberPolicy(mspid)
497-
if err != nil {
498-
t.Fatalf("failed getting policy, err %s", err)
499-
}
500-
501-
args := [][]byte{[]byte("dv"), envBytes, policy}
502-
if res := stub.MockInvoke("1", args); res.Status == shim.OK {
503-
t.Fatalf("vscc invoke should have failed")
504-
}
505-
}
506-
507417
func TestRWSetTooBig(t *testing.T) {
508418
State := make(map[string]map[string][]byte)
509419
mp := (&scc.MocksccProviderFactory{

0 commit comments

Comments
 (0)