Add negative tests for TxSha.
This commit is contained in:
parent
f8fc23a541
commit
a5bb254ac6
2 changed files with 21 additions and 2 deletions
|
@ -265,6 +265,13 @@ func TestBlockErrors(t *testing.T) {
|
|||
}
|
||||
block100000Bytes := block100000Buf.Bytes()
|
||||
|
||||
// Create a new block from the encoded bytes.
|
||||
b, err := btcutil.NewBlockFromBytes(block100000Bytes, pver)
|
||||
if err != nil {
|
||||
t.Errorf("NewBlockFromBytes: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Truncate the block byte buffer to force errors.
|
||||
shortBytes := block100000Bytes[:80]
|
||||
_, err = btcutil.NewBlockFromBytes(shortBytes, pver)
|
||||
|
@ -273,6 +280,18 @@ func TestBlockErrors(t *testing.T) {
|
|||
"got %v, want %v", err, io.EOF)
|
||||
return
|
||||
}
|
||||
|
||||
// Ensure TxSha returns expected error on invalid indices.
|
||||
_, err = b.TxSha(-1)
|
||||
if _, ok := err.(btcutil.OutOfRangeError); !ok {
|
||||
t.Errorf("TxSha: wrong error - got: %v <%T>, "+
|
||||
"want: <%T>", err, err, btcutil.OutOfRangeError(""))
|
||||
}
|
||||
_, err = b.TxSha(len(Block100000.Transactions) + 1)
|
||||
if _, ok := err.(btcutil.OutOfRangeError); !ok {
|
||||
t.Errorf("TxSha: wrong error - got: %v <%T>, "+
|
||||
"want: <%T>", err, err, btcutil.OutOfRangeError(""))
|
||||
}
|
||||
}
|
||||
|
||||
// Block100000 defines block 100,000 of the block chain. It is used to
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
|
||||
github.com/conformal/btcutil/block.go Block.TxSha 100.00% (11/11)
|
||||
github.com/conformal/btcutil/block.go Block.TxShas 100.00% (10/10)
|
||||
github.com/conformal/btcutil/block.go NewBlockFromBytes 100.00% (7/7)
|
||||
github.com/conformal/btcutil/block.go Block.Sha 100.00% (5/5)
|
||||
|
@ -9,8 +10,7 @@ github.com/conformal/btcutil/block.go Block.Height 100.00% (1/1)
|
|||
github.com/conformal/btcutil/block.go Block.SetHeight 100.00% (1/1)
|
||||
github.com/conformal/btcutil/block.go NewBlock 100.00% (1/1)
|
||||
github.com/conformal/btcutil/block.go Block.Bytes 88.89% (8/9)
|
||||
github.com/conformal/btcutil/block.go Block.TxSha 81.82% (9/11)
|
||||
github.com/conformal/btcutil/block.go Block.TxLoc 77.78% (7/9)
|
||||
github.com/conformal/btcutil/block.go OutOfRangeError.Error 0.00% (0/1)
|
||||
github.com/conformal/btcutil ------------------------- 89.66% (52/58)
|
||||
github.com/conformal/btcutil ------------------------- 93.10% (54/58)
|
||||
|
||||
|
|
Loading…
Reference in a new issue