@@ -17,6 +17,7 @@ import (
17
17
18
18
"github.com/tendermint/tendermint/crypto/ed25519"
19
19
"github.com/tendermint/tendermint/crypto/tmhash"
20
+ tmbytes "github.com/tendermint/tendermint/libs/bytes"
20
21
"github.com/tendermint/tendermint/libs/log"
21
22
tmmath "github.com/tendermint/tendermint/libs/math"
22
23
mempl "github.com/tendermint/tendermint/mempool"
@@ -414,14 +415,25 @@ func TestTx(t *testing.T) {
414
415
}
415
416
416
417
func TestTxSearch (t * testing.T ) {
417
- // first we broadcast a tx
418
418
c := getHTTPClient ()
419
- _ , _ , tx := MakeTxKV ()
420
- bres , err := c .BroadcastTxCommit (tx )
421
- require .Nil (t , err )
422
419
423
- txHeight := bres .Height
424
- txHash := bres .Hash
420
+ // first we broadcast a few txs
421
+ var tx []byte
422
+ var txHeight int64
423
+ var txHash tmbytes.HexBytes
424
+ for i := 0 ; i < 10 ; i ++ {
425
+ _ , _ , tx = MakeTxKV ()
426
+ res , err := c .BroadcastTxCommit (tx )
427
+ require .NoError (t , err )
428
+ txHeight = res .Height
429
+ txHash = res .Hash
430
+ }
431
+
432
+ // Since we're not using an isolated test server, we'll have lingering transactions
433
+ // from other tests as well
434
+ result , err := c .TxSearch ("tx.height >= 0" , true , 1 , 100 , "asc" )
435
+ require .NoError (t , err )
436
+ txCount := len (result .Txs )
425
437
426
438
anotherTxHash := types .Tx ("a different tx" ).Hash ()
427
439
@@ -433,6 +445,7 @@ func TestTxSearch(t *testing.T) {
433
445
result , err := c .TxSearch (fmt .Sprintf ("tx.hash='%v'" , txHash ), true , 1 , 30 , "asc" )
434
446
require .Nil (t , err )
435
447
require .Len (t , result .Txs , 1 )
448
+ require .Equal (t , txHash , result .Txs [0 ].Hash )
436
449
437
450
ptx := result .Txs [0 ]
438
451
assert .EqualValues (t , txHeight , ptx .Height )
@@ -476,12 +489,7 @@ func TestTxSearch(t *testing.T) {
476
489
require .Nil (t , err )
477
490
require .Len (t , result .Txs , 0 )
478
491
479
- // broadcast another transaction to make sure we have at least two.
480
- _ , _ , tx2 := MakeTxKV ()
481
- _ , err = c .BroadcastTxCommit (tx2 )
482
- require .Nil (t , err )
483
-
484
- // chech sorting
492
+ // check sorting
485
493
result , err = c .TxSearch (fmt .Sprintf ("tx.height >= 1" ), false , 1 , 30 , "asc" )
486
494
require .Nil (t , err )
487
495
for k := 0 ; k < len (result .Txs )- 1 ; k ++ {
@@ -495,6 +503,31 @@ func TestTxSearch(t *testing.T) {
495
503
require .GreaterOrEqual (t , result .Txs [k ].Height , result .Txs [k + 1 ].Height )
496
504
require .GreaterOrEqual (t , result .Txs [k ].Index , result .Txs [k + 1 ].Index )
497
505
}
506
+
507
+ // check pagination
508
+ seen := map [int64 ]bool {}
509
+ maxHeight := int64 (0 )
510
+ perPage := 3
511
+ pages := txCount / perPage + 1
512
+ for page := 1 ; page <= pages ; page ++ {
513
+ result , err = c .TxSearch ("tx.height >= 1" , false , page , perPage , "asc" )
514
+ require .NoError (t , err )
515
+ if page < pages {
516
+ require .Len (t , result .Txs , perPage )
517
+ } else {
518
+ require .LessOrEqual (t , len (result .Txs ), perPage )
519
+ }
520
+ require .Equal (t , txCount , result .TotalCount )
521
+ for _ , tx := range result .Txs {
522
+ require .False (t , seen [tx .Height ],
523
+ "Found duplicate height %v in page %v" , tx .Height , page )
524
+ require .Greater (t , tx .Height , maxHeight ,
525
+ "Found decreasing height %v (max seen %v) in page %v" , tx .Height , maxHeight , page )
526
+ seen [tx .Height ] = true
527
+ maxHeight = tx .Height
528
+ }
529
+ }
530
+ require .Len (t , seen , txCount )
498
531
}
499
532
}
500
533
0 commit comments