Add negative test for TxLoc.

This commit is contained in:
Dave Collins 2013-05-30 11:50:58 -05:00
parent b8843a0fb6
commit 05d31cdc7a
3 changed files with 30 additions and 3 deletions

View file

@ -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

18
internal_test.go Normal file
View file

@ -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
}

View file

@ -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)