diff --git a/block_test.go b/block_test.go index 30c8e78..1a2da5f 100644 --- a/block_test.go +++ b/block_test.go @@ -286,7 +286,6 @@ func TestBlockErrors(t *testing.T) { if err != io.EOF { t.Errorf("NewBlockFromBytes: did not get expected error - "+ "got %v, want %v", err, io.EOF) - return } // Ensure TxSha returns expected error on invalid indices. @@ -300,6 +299,16 @@ func TestBlockErrors(t *testing.T) { t.Errorf("TxSha: wrong error - got: %v <%T>, "+ "want: <%T>", err, err, btcutil.OutOfRangeError("")) } + + // Ensure TxLoc returns expected error with short byte buffer. + // This makes use of the test package only function, SetBlockBytes, to + // inject a short byte buffer. + b.SetBlockBytes(shortBytes) + _, err = b.TxLoc() + if err != io.EOF { + t.Errorf("TxLoc: did not get expected error - "+ + "got %v, want %v", err, io.EOF) + } } // Block100000 defines block 100,000 of the block chain. It is used to diff --git a/internal_test.go b/internal_test.go new file mode 100644 index 0000000..0dfb8df --- /dev/null +++ b/internal_test.go @@ -0,0 +1,18 @@ +// Copyright (c) 2013 Conformal Systems LLC. +// Use of this source code is governed by an ISC +// license that can be found in the LICENSE file. + +/* +This test file is part of the btcutil package rather than than the +btcutil_test package so it can bridge access to the internals to properly test +cases which are either not possible or can't reliably be tested via the public +interface. The functions are only exported while the tests are being run. +*/ + +package btcutil + +// SetBlockBytes sets the internal raw block byte buffer to the passed buffer. +// It is used to inject errors and only available to the test package. +func (b *Block) SetBlockBytes(buf []byte) { + b.rawBlock = buf +} diff --git a/test_coverage.txt b/test_coverage.txt index 2f5bb3c..1a13304 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -10,7 +10,7 @@ github.com/conformal/btcutil/block.go NewBlock 100.00% (1/1) github.com/conformal/btcutil/block.go NewBlockFromBlockAndBytes 100.00% (1/1) 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 Block.TxLoc 88.89% (8/9) github.com/conformal/btcutil/block.go Block.Bytes 88.89% (8/9) -github.com/conformal/btcutil/block.go Block.TxLoc 77.78% (7/9) -github.com/conformal/btcutil ------------------------- 94.83% (55/58) +github.com/conformal/btcutil ------------------------- 96.55% (56/58)