diff --git a/common.go b/common.go index dd6b61bd..792158ce 100644 --- a/common.go +++ b/common.go @@ -508,10 +508,7 @@ func writeVarBytes(w io.Writer, pver uint32, bytes []byte) error { // can be properly tested by passing a fake reader in the tests. func randomUint64(r io.Reader) (uint64, error) { var b [8]byte - n, err := r.Read(b[:]) - if n != len(b) { - return 0, io.ErrShortBuffer - } + _, err := io.ReadFull(r, b[:]) if err != nil { return 0, err } diff --git a/common_test.go b/common_test.go index 21706ee5..fbafe248 100644 --- a/common_test.go +++ b/common_test.go @@ -691,24 +691,13 @@ func TestRandomUint64(t *testing.T) { // and checks the results accordingly. func TestRandomUint64Errors(t *testing.T) { // Test short reads. - fr := &fakeRandReader{n: 2, err: nil} + fr := &fakeRandReader{n: 2, err: io.EOF} nonce, err := btcwire.TstRandomUint64(fr) - if err != io.ErrShortBuffer { + if err != io.ErrUnexpectedEOF { t.Errorf("TestRandomUint64Fails: Error not expected value of %v [%v]", io.ErrShortBuffer, err) } if nonce != 0 { t.Errorf("TestRandomUint64Fails: nonce is not 0 [%v]", nonce) } - - // Test err with full read. - fr = &fakeRandReader{n: 20, err: io.ErrClosedPipe} - nonce, err = btcwire.TstRandomUint64(fr) - if err != io.ErrClosedPipe { - t.Errorf("TestRandomUint64Fails: Error not expected value of %v [%v]", - io.ErrClosedPipe, err) - } - if nonce != 0 { - t.Errorf("TestRandomUint64Fails: nonce is not 0 [%v]", nonce) - } }