Add negative test for NewBlockFromBytes.
This commit is contained in:
parent
b90727cc8a
commit
f8fc23a541
2 changed files with 24 additions and 2 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/conformal/btcutil"
|
||||
"github.com/conformal/btcwire"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"io"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -253,6 +254,27 @@ func TestNewBlockFromBlockAndBytes(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestBlockErrors tests the error paths for the Block API.
|
||||
func TestBlockErrors(t *testing.T) {
|
||||
// Encode the test block to bytes.
|
||||
pver := btcwire.ProtocolVersion
|
||||
var block100000Buf bytes.Buffer
|
||||
err := Block100000.BtcEncode(&block100000Buf, pver)
|
||||
if err != nil {
|
||||
t.Errorf("BtcEncode: %v", err)
|
||||
}
|
||||
block100000Bytes := block100000Buf.Bytes()
|
||||
|
||||
// Truncate the block byte buffer to force errors.
|
||||
shortBytes := block100000Bytes[:80]
|
||||
_, err = btcutil.NewBlockFromBytes(shortBytes, pver)
|
||||
if err != io.EOF {
|
||||
t.Errorf("NewBlockFromBytes: did not get expected error - "+
|
||||
"got %v, want %v", err, io.EOF)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Block100000 defines block 100,000 of the block chain. It is used to
|
||||
// test Block operations.
|
||||
var Block100000 btcwire.MsgBlock = btcwire.MsgBlock{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
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)
|
||||
github.com/conformal/btcutil/block.go NewBlockFromBlockAndBytes 100.00% (1/1)
|
||||
github.com/conformal/btcutil/block.go Block.MsgBlock 100.00% (1/1)
|
||||
|
@ -8,9 +9,8 @@ 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 NewBlockFromBytes 85.71% (6/7)
|
||||
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 ------------------------- 87.93% (51/58)
|
||||
github.com/conformal/btcutil ------------------------- 89.66% (52/58)
|
||||
|
||||
|
|
Loading…
Reference in a new issue