Skip to content

Commit

Permalink
Add unit test for GetStateByPartialCompositeKey
Browse files Browse the repository at this point in the history
Add a unit test to ensure no collisions across similarly
named object types.

Change-Id: I4911ce8bba1f9851db379f084c9b69ab2889934b
Signed-off-by: denyeart <enyeart@us.ibm.com>
  • Loading branch information
denyeart committed Feb 16, 2017
1 parent 7559dd9 commit 695715e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions core/chaincode/shim/mockstub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,33 @@ func TestGetStateByPartialCompositeKey(t *testing.T) {
}
}
}

func TestGetStateByPartialCompositeKeyCollision(t *testing.T) {
stub := NewMockStub("GetStateByPartialCompositeKeyCollisionTest", nil)
stub.MockTransactionStart("init")

vehicle1Bytes := []byte("vehicle1")
compositeKeyVehicle1, _ := stub.CreateCompositeKey("Vehicle", []string{"VIN_1234"})
stub.PutState(compositeKeyVehicle1, vehicle1Bytes)

vehicleListing1Bytes := []byte("vehicleListing1")
compositeKeyVehicleListing1, _ := stub.CreateCompositeKey("VehicleListing", []string{"LIST_1234"})
stub.PutState(compositeKeyVehicleListing1, vehicleListing1Bytes)

stub.MockTransactionEnd("init")

// Only the single "Vehicle" object should be returned, not the "VehicleListing" object
rqi, _ := stub.GetStateByPartialCompositeKey("Vehicle", []string{})
i := 0
fmt.Println("Running loop")
for rqi.HasNext() {
i++
key, value, err := rqi.Next()
fmt.Println("Loop", i, "got", key, value, err)
}
// Only the single "Vehicle" object should be returned, not the "VehicleListing" object
if i != 1 {
fmt.Println("Expected 1, got", i)
t.FailNow()
}
}

0 comments on commit 695715e

Please sign in to comment.