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

package types
import (
"testing"
"github.com/stretchr/testify/assert"
tmrand "github.com/tendermint/tendermint/libs/rand"
)
func makeTxs(cnt, size int) Txs {
txs := make(Txs, cnt)
for i := 0; i < cnt; i++ {
txs[i] = tmrand.Bytes(size)
}
return txs
}
func TestTxIndex(t *testing.T) {
for i := 0; i < 20; i++ {
txs := makeTxs(15, 60)
for j := 0; j < len(txs); j++ {
tx := txs[j]
idx := txs.Index(tx)
assert.Equal(t, j, idx)
}
assert.Equal(t, -1, txs.Index(nil))
assert.Equal(t, -1, txs.Index(Tx("foodnwkf")))
}
}
func TestTxIndexByHash(t *testing.T) {
for i := 0; i < 20; i++ {
txs := makeTxs(15, 60)
for j := 0; j < len(txs); j++ {
tx := txs[j]
idx := txs.IndexByHash(tx.Hash())
assert.Equal(t, j, idx)
}
assert.Equal(t, -1, txs.IndexByHash(nil))
assert.Equal(t, -1, txs.IndexByHash(Tx("foodnwkf").Hash()))
}
}