txmgr_test.go 16.6 KB
Newer Older
manish's avatar
manish committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
Copyright IBM Corp. 2016 All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

		 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

17
package commontests
manish's avatar
manish committed
18
19

import (
20
	"encoding/json"
manish's avatar
manish committed
21
22
23
	"fmt"
	"testing"

24
	"github.com/hyperledger/fabric/common/ledger/testutil"
manish's avatar
manish committed
25
	"github.com/hyperledger/fabric/core/ledger"
26
	"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/version"
27
	"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
manish's avatar
manish committed
28
29
30
)

func TestTxSimulatorWithNoExistingData(t *testing.T) {
31
32
33
34
35
36
37
38
39
40
	for _, testEnv := range testEnvs {
		t.Logf("Running test for TestEnv = %s", testEnv.getName())
		testEnv.init(t)
		testTxSimulatorWithNoExistingData(t, testEnv)
		testEnv.cleanup()
	}
}

func testTxSimulatorWithNoExistingData(t *testing.T, env testEnv) {
	txMgr := env.getTxMgr()
manish's avatar
manish committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
	s, _ := txMgr.NewTxSimulator()
	value, err := s.GetState("ns1", "key1")
	testutil.AssertNoError(t, err, fmt.Sprintf("Error in GetState(): %s", err))
	testutil.AssertNil(t, value)

	s.SetState("ns1", "key1", []byte("value1"))
	s.SetState("ns1", "key2", []byte("value2"))
	s.SetState("ns2", "key3", []byte("value3"))
	s.SetState("ns2", "key4", []byte("value4"))

	value, _ = s.GetState("ns2", "key3")
	testutil.AssertNil(t, value)
}

func TestTxSimulatorWithExistingData(t *testing.T) {
56
57
58
59
60
61
62
	for _, testEnv := range testEnvs {
		t.Logf("Running test for TestEnv = %s", testEnv.getName())
		testEnv.init(t)
		testTxSimulatorWithExistingData(t, testEnv)
		testEnv.cleanup()
	}
}
manish's avatar
manish committed
63

64
65
66
func testTxSimulatorWithExistingData(t *testing.T, env testEnv) {
	txMgr := env.getTxMgr()
	txMgrHelper := newTxMgrTestHelper(t, txMgr)
manish's avatar
manish committed
67
68
69
70
71
72
73
74
	// simulate tx1
	s1, _ := txMgr.NewTxSimulator()
	s1.SetState("ns1", "key1", []byte("value1"))
	s1.SetState("ns1", "key2", []byte("value2"))
	s1.SetState("ns2", "key3", []byte("value3"))
	s1.SetState("ns2", "key4", []byte("value4"))
	s1.Done()
	// validate and commit RWset
75
76
	txRWSet1, _ := s1.GetTxSimulationResults()
	txMgrHelper.validateAndCommitRWSet(txRWSet1)
77

manish's avatar
manish committed
78
79
80
81
82
83
84
	// simulate tx2 that make changes to existing data
	s2, _ := txMgr.NewTxSimulator()
	value, _ := s2.GetState("ns1", "key1")
	testutil.AssertEquals(t, value, []byte("value1"))
	s2.SetState("ns1", "key1", []byte("value1_1"))
	s2.DeleteState("ns2", "key3")
	value, _ = s2.GetState("ns1", "key1")
manish's avatar
manish committed
85
	testutil.AssertEquals(t, value, []byte("value1"))
manish's avatar
manish committed
86
87
	s2.Done()
	// validate and commit RWset for tx2
88
89
	txRWSet2, _ := s2.GetTxSimulationResults()
	txMgrHelper.validateAndCommitRWSet(txRWSet2)
manish's avatar
manish committed
90
91
92
93
94
95
96
97
98
99

	// simulate tx3
	s3, _ := txMgr.NewTxSimulator()
	value, _ = s3.GetState("ns1", "key1")
	testutil.AssertEquals(t, value, []byte("value1_1"))
	value, _ = s3.GetState("ns2", "key3")
	testutil.AssertEquals(t, value, nil)
	s3.Done()

	// verify the versions of keys in persistence
100
	vv, _ := env.getVDB().GetState("ns1", "key1")
101
102
	//TODO re-enable after adding couch version wrapper
	//testutil.AssertEquals(t, vv.Version, version.NewHeight(2, 1))
103
104
	vv, _ = env.getVDB().GetState("ns1", "key2")
	testutil.AssertEquals(t, vv.Version, version.NewHeight(1, 1))
manish's avatar
manish committed
105
106
107
}

func TestTxValidation(t *testing.T) {
108
109
110
111
112
113
114
	for _, testEnv := range testEnvs {
		t.Logf("Running test for TestEnv = %s", testEnv.getName())
		testEnv.init(t)
		testTxValidation(t, testEnv)
		testEnv.cleanup()
	}
}
manish's avatar
manish committed
115

116
117
118
func testTxValidation(t *testing.T, env testEnv) {
	txMgr := env.getTxMgr()
	txMgrHelper := newTxMgrTestHelper(t, txMgr)
manish's avatar
manish committed
119
120
121
122
123
124
125
126
	// simulate tx1
	s1, _ := txMgr.NewTxSimulator()
	s1.SetState("ns1", "key1", []byte("value1"))
	s1.SetState("ns1", "key2", []byte("value2"))
	s1.SetState("ns2", "key3", []byte("value3"))
	s1.SetState("ns2", "key4", []byte("value4"))
	s1.Done()
	// validate and commit RWset
127
128
	txRWSet1, _ := s1.GetTxSimulationResults()
	txMgrHelper.validateAndCommitRWSet(txRWSet1)
manish's avatar
manish committed
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

	// simulate tx2 that make changes to existing data
	s2, _ := txMgr.NewTxSimulator()
	value, _ := s2.GetState("ns1", "key1")
	testutil.AssertEquals(t, value, []byte("value1"))

	s2.SetState("ns1", "key1", []byte("value1_2"))
	s2.DeleteState("ns2", "key3")
	s2.Done()

	// simulate tx3 before committing tx2 changes. Reads and modifies the key changed by tx2
	s3, _ := txMgr.NewTxSimulator()
	s3.GetState("ns1", "key1")
	s3.SetState("ns1", "key1", []byte("value1_3"))
	s3.Done()

	// simulate tx4 before committing tx2 changes. Reads and Deletes the key changed by tx2
	s4, _ := txMgr.NewTxSimulator()
	s4.GetState("ns2", "key3")
	s4.DeleteState("ns2", "key3")
	s4.Done()

	// simulate tx5 before committing tx2 changes. Modifies and then Reads the key changed by tx2 and writes a new key
	s5, _ := txMgr.NewTxSimulator()
	s5.SetState("ns1", "key1", []byte("new_value"))
	s5.GetState("ns1", "key1")
	s5.Done()

	// simulate tx6 before committing tx2 changes. Only writes a new key, does not reads/writes a key changed by tx2
	s6, _ := txMgr.NewTxSimulator()
	s6.SetState("ns1", "new_key", []byte("new_value"))
	s6.Done()

	// validate and commit RWset for tx2
163
164
	txRWSet2, _ := s2.GetTxSimulationResults()
	txMgrHelper.validateAndCommitRWSet(txRWSet2)
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
	//TODO re-enable after adding couch version wrapper
	/*
		//RWSet for tx3 and tx4 should not be invalid now
		txRWSet3, _ := s3.GetTxSimulationResults()
		txMgrHelper.checkRWsetInvalid(txRWSet3)

		txRWSet4, _ := s4.GetTxSimulationResults()
		txMgrHelper.checkRWsetInvalid(txRWSet4)

		//tx5 shold still be valid as it over-writes the key first and then reads
		txRWSet5, _ := s5.GetTxSimulationResults()
		txMgrHelper.validateAndCommitRWSet(txRWSet5)

		// tx6 should still be valid as it only writes a new key
		txRWSet6, _ := s6.GetTxSimulationResults()
		txMgrHelper.validateAndCommitRWSet(txRWSet6)
	*/
manish's avatar
manish committed
182
}
manish's avatar
manish committed
183

184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
func TestTxPhantomValidation(t *testing.T) {
	for _, testEnv := range testEnvs {
		t.Logf("Running test for TestEnv = %s", testEnv.getName())
		testEnv.init(t)
		testTxPhantomValidation(t, testEnv)
		testEnv.cleanup()
	}
}

func testTxPhantomValidation(t *testing.T, env testEnv) {
	txMgr := env.getTxMgr()
	txMgrHelper := newTxMgrTestHelper(t, txMgr)
	// simulate tx1
	s1, _ := txMgr.NewTxSimulator()
	s1.SetState("ns", "key1", []byte("value1"))
	s1.SetState("ns", "key2", []byte("value2"))
	s1.SetState("ns", "key3", []byte("value3"))
	s1.SetState("ns", "key4", []byte("value4"))
	s1.SetState("ns", "key5", []byte("value5"))
	s1.SetState("ns", "key6", []byte("value6"))
	s1.Done()
	// validate and commit RWset
	txRWSet1, _ := s1.GetTxSimulationResults()
	txMgrHelper.validateAndCommitRWSet(txRWSet1)

	// simulate tx2
	s2, _ := txMgr.NewTxSimulator()
	itr2, _ := s2.GetStateRangeScanIterator("ns", "key2", "key5")
	for {
		if result, _ := itr2.Next(); result == nil {
			break
		}
	}
	s2.DeleteState("ns", "key3")
	s2.Done()
	txRWSet2, _ := s2.GetTxSimulationResults()

	// simulate tx3
	s3, _ := txMgr.NewTxSimulator()
	itr3, _ := s3.GetStateRangeScanIterator("ns", "key2", "key5")
	for {
		if result, _ := itr3.Next(); result == nil {
			break
		}
	}
	s3.SetState("ns", "key3", []byte("value3_new"))
	s3.Done()
	txRWSet3, _ := s3.GetTxSimulationResults()

	// simulate tx4
	s4, _ := txMgr.NewTxSimulator()
	itr4, _ := s4.GetStateRangeScanIterator("ns", "key4", "key6")
	for {
		if result, _ := itr4.Next(); result == nil {
			break
		}
	}
	s4.SetState("ns", "key3", []byte("value3_new"))
	s4.Done()
	txRWSet4, _ := s4.GetTxSimulationResults()

	// txRWSet2 should be valid
	txMgrHelper.validateAndCommitRWSet(txRWSet2)
	// txRWSet2 makes txRWSet3 invalid as it deletes a key in the range
	txMgrHelper.checkRWsetInvalid(txRWSet3)
	// txRWSet4 should be valid as it iterates over a different range
	txMgrHelper.validateAndCommitRWSet(txRWSet4)
}

manish's avatar
manish committed
253
func TestIterator(t *testing.T) {
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
	for _, testEnv := range testEnvs {
		t.Logf("Running test for TestEnv = %s", testEnv.getName())
		testEnv.init(t)
		testIterator(t, testEnv, 10, 2, 7)
		testEnv.cleanup()

		testEnv.init(t)
		testIterator(t, testEnv, 10, 1, 11)
		testEnv.cleanup()

		testEnv.init(t)
		testIterator(t, testEnv, 10, 0, 0)
		testEnv.cleanup()

		testEnv.init(t)
		testIterator(t, testEnv, 10, 5, 0)
		testEnv.cleanup()

		testEnv.init(t)
		testIterator(t, testEnv, 10, 0, 5)
		testEnv.cleanup()
	}
manish's avatar
manish committed
276
277
}

278
func testIterator(t *testing.T, env testEnv, numKeys int, startKeyNum int, endKeyNum int) {
manish's avatar
manish committed
279
	cID := "cID"
280
281
	txMgr := env.getTxMgr()
	txMgrHelper := newTxMgrTestHelper(t, txMgr)
manish's avatar
manish committed
282
283
284
285
286
287
288
289
290
	s, _ := txMgr.NewTxSimulator()
	for i := 1; i <= numKeys; i++ {
		k := createTestKey(i)
		v := createTestValue(i)
		t.Logf("Adding k=[%s], v=[%s]", k, v)
		s.SetState(cID, k, v)
	}
	s.Done()
	// validate and commit RWset
291
292
	txRWSet, _ := s.GetTxSimulationResults()
	txMgrHelper.validateAndCommitRWSet(txRWSet)
manish's avatar
manish committed
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327

	var startKey string
	var endKey string
	var begin int
	var end int

	if startKeyNum != 0 {
		begin = startKeyNum
		startKey = createTestKey(startKeyNum)
	} else {
		begin = 1 //first key in the db
		startKey = ""
	}

	if endKeyNum != 0 {
		endKey = createTestKey(endKeyNum)
		end = endKeyNum
	} else {
		endKey = ""
		end = numKeys + 1 //last key in the db
	}

	expectedCount := end - begin

	queryExecuter, _ := txMgr.NewQueryExecutor()
	itr, _ := queryExecuter.GetStateRangeScanIterator(cID, startKey, endKey)
	count := 0
	for {
		kv, _ := itr.Next()
		if kv == nil {
			break
		}
		keyNum := begin + count
		k := kv.(*ledger.KV).Key
		v := kv.(*ledger.KV).Value
328
		t.Logf("Retrieved k=%s, v=%s at count=%d start=%s end=%s", k, v, count, startKey, endKey)
manish's avatar
manish committed
329
330
331
332
333
334
335
336
		testutil.AssertEquals(t, k, createTestKey(keyNum))
		testutil.AssertEquals(t, v, createTestValue(keyNum))
		count++
	}
	testutil.AssertEquals(t, count, expectedCount)
}

func TestIteratorWithDeletes(t *testing.T) {
337
338
339
340
341
342
343
344
345
	for _, testEnv := range testEnvs {
		t.Logf("Running test for TestEnv = %s", testEnv.getName())
		testEnv.init(t)
		testIteratorWithDeletes(t, testEnv)
		testEnv.cleanup()
	}
}

func testIteratorWithDeletes(t *testing.T, env testEnv) {
manish's avatar
manish committed
346
	cID := "cID"
347
348
	txMgr := env.getTxMgr()
	txMgrHelper := newTxMgrTestHelper(t, txMgr)
manish's avatar
manish committed
349
350
351
352
353
354
355
356
357
	s, _ := txMgr.NewTxSimulator()
	for i := 1; i <= 10; i++ {
		k := createTestKey(i)
		v := createTestValue(i)
		t.Logf("Adding k=[%s], v=[%s]", k, v)
		s.SetState(cID, k, v)
	}
	s.Done()
	// validate and commit RWset
358
359
	txRWSet1, _ := s.GetTxSimulationResults()
	txMgrHelper.validateAndCommitRWSet(txRWSet1)
manish's avatar
manish committed
360
361
362
363
364

	s, _ = txMgr.NewTxSimulator()
	s.DeleteState(cID, createTestKey(4))
	s.Done()
	// validate and commit RWset
365
366
	txRWSet2, _ := s.GetTxSimulationResults()
	txMgrHelper.validateAndCommitRWSet(txRWSet2)
manish's avatar
manish committed
367
368
369
370
371
372

	queryExecuter, _ := txMgr.NewQueryExecutor()
	itr, _ := queryExecuter.GetStateRangeScanIterator(cID, createTestKey(3), createTestKey(6))
	defer itr.Close()
	kv, _ := itr.Next()
	testutil.AssertEquals(t, kv.(*ledger.KV).Key, createTestKey(3))
373
374
375
	//TODO re-enable after adding couch delete function
	//kv, _ = itr.Next()
	//testutil.AssertEquals(t, kv.(*ledger.KV).Key, createTestKey(5))
manish's avatar
manish committed
376
377
378
}

func TestTxValidationWithItr(t *testing.T) {
379
380
381
382
383
384
385
386
387
	for _, testEnv := range testEnvs {
		t.Logf("Running test for TestEnv = %s", testEnv.getName())
		testEnv.init(t)
		testTxValidationWithItr(t, testEnv)
		testEnv.cleanup()
	}
}

func testTxValidationWithItr(t *testing.T, env testEnv) {
manish's avatar
manish committed
388
	cID := "cID"
389
390
	txMgr := env.getTxMgr()
	txMgrHelper := newTxMgrTestHelper(t, txMgr)
manish's avatar
manish committed
391
392
393
394
395
396
397
398
399
400
401

	// simulate tx1
	s1, _ := txMgr.NewTxSimulator()
	for i := 1; i <= 10; i++ {
		k := createTestKey(i)
		v := createTestValue(i)
		t.Logf("Adding k=[%s], v=[%s]", k, v)
		s1.SetState(cID, k, v)
	}
	s1.Done()
	// validate and commit RWset
402
403
	txRWSet1, _ := s1.GetTxSimulationResults()
	txMgrHelper.validateAndCommitRWSet(txRWSet1)
manish's avatar
manish committed
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428

	// simulate tx2 that reads key_001 and key_002
	s2, _ := txMgr.NewTxSimulator()
	itr, _ := s2.GetStateRangeScanIterator(cID, createTestKey(1), createTestKey(5))
	// read key_001 and key_002
	itr.Next()
	itr.Next()
	itr.Close()
	s2.Done()

	// simulate tx3 that reads key_004 and key_005
	s3, _ := txMgr.NewTxSimulator()
	itr, _ = s3.GetStateRangeScanIterator(cID, createTestKey(4), createTestKey(6))
	// read key_001 and key_002
	itr.Next()
	itr.Next()
	itr.Close()
	s3.Done()

	// simulate tx4 before committing tx2 and tx3. Modifies a key read by tx3
	s4, _ := txMgr.NewTxSimulator()
	s4.DeleteState(cID, createTestKey(5))
	s4.Done()

	// validate and commit RWset for tx4
429
430
	txRWSet4, _ := s4.GetTxSimulationResults()
	txMgrHelper.validateAndCommitRWSet(txRWSet4)
manish's avatar
manish committed
431

432
433
434
435
436
437
	//TODO re-enable after adding couch version wrapper
	/*
		//RWSet tx3 should not be invalid now
		txRWSet3, _ := s3.GetTxSimulationResults()
		txMgrHelper.checkRWsetInvalid(txRWSet3)
	*/
manish's avatar
manish committed
438
439

	// tx2 should still be valid
440
441
	txRWSet2, _ := s2.GetTxSimulationResults()
	txMgrHelper.validateAndCommitRWSet(txRWSet2)
442

manish's avatar
manish committed
443
444
445
}

func TestGetSetMultipeKeys(t *testing.T) {
446
447
448
449
450
451
452
	for _, testEnv := range testEnvs {
		t.Logf("Running test for TestEnv = %s", testEnv.getName())
		testEnv.init(t)
		testGetSetMultipeKeys(t, testEnv)
		testEnv.cleanup()
	}
}
manish's avatar
manish committed
453

454
455
456
457
func testGetSetMultipeKeys(t *testing.T, env testEnv) {
	cID := "cID"
	txMgr := env.getTxMgr()
	txMgrHelper := newTxMgrTestHelper(t, txMgr)
manish's avatar
manish committed
458
459
460
461
462
463
464
465
466
467
468
	// simulate tx1
	s1, _ := txMgr.NewTxSimulator()
	multipleKeyMap := make(map[string][]byte)
	for i := 1; i <= 10; i++ {
		k := createTestKey(i)
		v := createTestValue(i)
		multipleKeyMap[k] = v
	}
	s1.SetStateMultipleKeys(cID, multipleKeyMap)
	s1.Done()
	// validate and commit RWset
469
470
	txRWSet, _ := s1.GetTxSimulationResults()
	txMgrHelper.validateAndCommitRWSet(txRWSet)
manish's avatar
manish committed
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
	qe, _ := txMgr.NewQueryExecutor()
	defer qe.Done()
	multipleKeys := []string{}
	for k := range multipleKeyMap {
		multipleKeys = append(multipleKeys, k)
	}
	values, _ := qe.GetStateMultipleKeys(cID, multipleKeys)
	testutil.AssertEquals(t, len(values), 10)
	for i, v := range values {
		testutil.AssertEquals(t, v, multipleKeyMap[multipleKeys[i]])
	}

	s2, _ := txMgr.NewTxSimulator()
	defer s2.Done()
	values, _ = s2.GetStateMultipleKeys(cID, multipleKeys[5:7])
	testutil.AssertEquals(t, len(values), 2)
	for i, v := range values {
		testutil.AssertEquals(t, v, multipleKeyMap[multipleKeys[i+5]])
	}
}

func createTestKey(i int) string {
	if i == 0 {
		return ""
	}
	return fmt.Sprintf("key_%03d", i)
}

func createTestValue(i int) []byte {
	return []byte(fmt.Sprintf("value_%03d", i))
}
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585

//TestExecuteQueryQuery is only tested on the CouchDB testEnv
func TestExecuteQuery(t *testing.T) {

	// Query is only tested on the CouchDB testEnv
	if ledgerconfig.IsCouchDBEnabled() == true {
		testEnvs = []testEnv{&couchDBLockBasedEnv{}}
	} else {
		testEnvs = []testEnv{}
	}

	for _, testEnv := range testEnvs {
		t.Logf("Running test for TestEnv = %s", testEnv.getName())
		testEnv.init(t)
		testExecuteQuery(t, testEnv)
		testEnv.cleanup()
	}
}

func testExecuteQuery(t *testing.T, env testEnv) {

	type Asset struct {
		ID        string `json:"_id"`
		Rev       string `json:"_rev"`
		AssetName string `json:"asset_name"`
		Color     string `json:"color"`
		Size      string `json:"size"`
		Owner     string `json:"owner"`
	}

	txMgr := env.getTxMgr()
	txMgrHelper := newTxMgrTestHelper(t, txMgr)

	s1, _ := txMgr.NewTxSimulator()

	s1.SetState("ns1", "key1", []byte("value1"))
	s1.SetState("ns1", "key2", []byte("value2"))
	s1.SetState("ns1", "key3", []byte("value3"))
	s1.SetState("ns1", "key4", []byte("value4"))
	s1.SetState("ns1", "key5", []byte("value5"))
	s1.SetState("ns1", "key6", []byte("value6"))
	s1.SetState("ns1", "key7", []byte("value7"))
	s1.SetState("ns1", "key8", []byte("value8"))

	s1.SetState("ns1", "key9", []byte(`{"asset_name":"marble1","color":"red","size":"25","owner":"jerry"}`))
	s1.SetState("ns1", "key10", []byte(`{"asset_name":"marble2","color":"blue","size":"10","owner":"bob"}`))
	s1.SetState("ns1", "key11", []byte(`{"asset_name":"marble3","color":"blue","size":"35","owner":"jerry"}`))
	s1.SetState("ns1", "key12", []byte(`{"asset_name":"marble4","color":"green","size":"15","owner":"bob"}`))
	s1.SetState("ns1", "key13", []byte(`{"asset_name":"marble5","color":"red","size":"35","owner":"jerry"}`))
	s1.SetState("ns1", "key14", []byte(`{"asset_name":"marble6","color":"blue","size":"25","owner":"bob"}`))

	s1.Done()

	// validate and commit RWset
	txRWSet, _ := s1.GetTxSimulationResults()
	txMgrHelper.validateAndCommitRWSet(txRWSet)

	queryExecuter, _ := txMgr.NewQueryExecutor()
	queryString := "{\"selector\":{\"owner\": {\"$eq\": \"bob\"}},\"limit\": 10,\"skip\": 0}"

	itr, _ := queryExecuter.ExecuteQuery(queryString)

	counter := 0
	for {
		queryRecord, _ := itr.Next()
		if queryRecord == nil {
			break
		}

		//Unmarshal the document to Asset structure
		assetResp := &Asset{}
		json.Unmarshal(queryRecord.(*ledger.QueryRecord).Record, &assetResp)

		//Verify the owner retrieved matches
		testutil.AssertEquals(t, assetResp.Owner, "bob")

		counter++

	}

	//Ensure the query returns 3 documents
	testutil.AssertEquals(t, counter, 3)

}