You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
867 B

  1. package types
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. tmrand "github.com/tendermint/tendermint/libs/rand"
  6. )
  7. func makeTxs(cnt, size int) Txs {
  8. txs := make(Txs, cnt)
  9. for i := 0; i < cnt; i++ {
  10. txs[i] = tmrand.Bytes(size)
  11. }
  12. return txs
  13. }
  14. func TestTxIndex(t *testing.T) {
  15. for i := 0; i < 20; i++ {
  16. txs := makeTxs(15, 60)
  17. for j := 0; j < len(txs); j++ {
  18. tx := txs[j]
  19. idx := txs.Index(tx)
  20. assert.Equal(t, j, idx)
  21. }
  22. assert.Equal(t, -1, txs.Index(nil))
  23. assert.Equal(t, -1, txs.Index(Tx("foodnwkf")))
  24. }
  25. }
  26. func TestTxIndexByHash(t *testing.T) {
  27. for i := 0; i < 20; i++ {
  28. txs := makeTxs(15, 60)
  29. for j := 0; j < len(txs); j++ {
  30. tx := txs[j]
  31. idx := txs.IndexByHash(tx.Hash())
  32. assert.Equal(t, j, idx)
  33. }
  34. assert.Equal(t, -1, txs.IndexByHash(nil))
  35. assert.Equal(t, -1, txs.IndexByHash(Tx("foodnwkf").Hash()))
  36. }
  37. }