Implemented and tested Txs.Index, hopefully better coverage
This commit is contained in:
parent
285a2a7061
commit
705e7bd577
|
@ -36,6 +36,11 @@ func (txs Txs) Hash() []byte {
|
|||
|
||||
// Index returns the index of this transaction in the list, or -1 if not found
|
||||
func (txs Txs) Index(tx Tx) int {
|
||||
for i := range txs {
|
||||
if bytes.Equal(txs[i], tx) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,20 @@ func randInt(low, high int) int {
|
|||
return low + off
|
||||
}
|
||||
|
||||
func TestTxIndex(t *testing.T) {
|
||||
assert := assert.New(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(j, idx)
|
||||
}
|
||||
assert.Equal(-1, txs.Index(nil))
|
||||
assert.Equal(-1, txs.Index(Tx("foodnwkf")))
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidTxProof(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
cases := []struct {
|
||||
|
|
Loading…
Reference in New Issue