diff --git a/block_test.go b/block_test.go index a97d01a..5231a21 100644 --- a/block_test.go +++ b/block_test.go @@ -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 diff --git a/test_coverage.txt b/test_coverage.txt index 61b3e61..0be2a59 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -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)