1 // Copyright (c) 2013-2016 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
15 "github.com/btcsuite/btcd/chaincfg/chainhash"
16 "github.com/davecgh/go-spew/spew"
19 // mainNetGenesisHash is the hash of the first block in the block chain for the
20 // main network (genesis block).
21 var mainNetGenesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
22 0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72,
23 0xc1, 0xa6, 0xa2, 0x46, 0xae, 0x63, 0xf7, 0x4f,
24 0x93, 0x1e, 0x83, 0x65, 0xe1, 0x5a, 0x08, 0x9c,
25 0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
28 // mainNetGenesisMerkleRoot is the hash of the first transaction in the genesis
29 // block for the main network.
30 var mainNetGenesisMerkleRoot = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
31 0x3b, 0xa3, 0xed, 0xfd, 0x7a, 0x7b, 0x12, 0xb2,
32 0x7a, 0xc7, 0x2c, 0x3e, 0x67, 0x76, 0x8f, 0x61,
33 0x7f, 0xc8, 0x1b, 0xc3, 0x88, 0x8a, 0x51, 0x32,
34 0x3a, 0x9f, 0xb8, 0xaa, 0x4b, 0x1e, 0x5e, 0x4a,
37 // fakeRandReader implements the io.Reader interface and is used to force
38 // errors in the RandomUint64 function.
39 type fakeRandReader struct {
44 // Read returns the fake reader error and the lesser of the fake reader value
45 // and the length of p.
46 func (r *fakeRandReader) Read(p []byte) (int, error) {
54 // TestElementWire tests wire encode and decode for various element types. This
55 // is mainly to test the "fast" paths in readElement and writeElement which use
56 // type assertions to avoid reflection when possible.
57 func TestElementWire(t *testing.T) {
58 type writeElementReflect int32
61 in interface{} // Value to encode
62 buf []byte // Wire encoding
64 {int32(1), []byte{0x01, 0x00, 0x00, 0x00}},
65 {uint32(256), []byte{0x00, 0x01, 0x00, 0x00}},
68 []byte{0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00},
72 []byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00},
83 [4]byte{0x01, 0x02, 0x03, 0x04},
84 []byte{0x01, 0x02, 0x03, 0x04},
88 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
89 0x09, 0x0a, 0x0b, 0x0c,
92 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
93 0x09, 0x0a, 0x0b, 0x0c,
98 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
99 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
102 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
103 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
107 (*chainhash.Hash)(&[chainhash.HashSize]byte{ // Make go vet happy.
108 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
109 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
110 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
111 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
114 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
115 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
116 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
117 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
121 ServiceFlag(SFNodeNetwork),
122 []byte{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
126 []byte{0x01, 0x00, 0x00, 0x00},
130 []byte{0xf9, 0xbe, 0xb4, 0xd9},
132 // Type not supported by the "fast" path and requires reflection.
134 writeElementReflect(1),
135 []byte{0x01, 0x00, 0x00, 0x00},
139 t.Logf("Running %d tests", len(tests))
140 for i, test := range tests {
141 // Write to wire format.
143 err := writeElement(&buf, test.in)
145 t.Errorf("writeElement #%d error %v", i, err)
148 if !bytes.Equal(buf.Bytes(), test.buf) {
149 t.Errorf("writeElement #%d\n got: %s want: %s", i,
150 spew.Sdump(buf.Bytes()), spew.Sdump(test.buf))
154 // Read from wire format.
155 rbuf := bytes.NewReader(test.buf)
157 if reflect.ValueOf(test.in).Kind() != reflect.Ptr {
158 val = reflect.New(reflect.TypeOf(test.in)).Interface()
160 err = readElement(rbuf, val)
162 t.Errorf("readElement #%d error %v", i, err)
166 if reflect.ValueOf(test.in).Kind() != reflect.Ptr {
167 ival = reflect.Indirect(reflect.ValueOf(val)).Interface()
169 if !reflect.DeepEqual(ival, test.in) {
170 t.Errorf("readElement #%d\n got: %s want: %s", i,
171 spew.Sdump(ival), spew.Sdump(test.in))
177 // TestElementWireErrors performs negative tests against wire encode and decode
178 // of various element types to confirm error paths work correctly.
179 func TestElementWireErrors(t *testing.T) {
181 in interface{} // Value to encode
182 max int // Max size of fixed buffer to induce errors
183 writeErr error // Expected write error
184 readErr error // Expected read error
186 {int32(1), 0, io.ErrShortWrite, io.EOF},
187 {uint32(256), 0, io.ErrShortWrite, io.EOF},
188 {int64(65536), 0, io.ErrShortWrite, io.EOF},
189 {true, 0, io.ErrShortWrite, io.EOF},
190 {[4]byte{0x01, 0x02, 0x03, 0x04}, 0, io.ErrShortWrite, io.EOF},
193 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
194 0x09, 0x0a, 0x0b, 0x0c,
196 0, io.ErrShortWrite, io.EOF,
200 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
201 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
203 0, io.ErrShortWrite, io.EOF,
206 (*chainhash.Hash)(&[chainhash.HashSize]byte{ // Make go vet happy.
207 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
208 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
209 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
210 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
212 0, io.ErrShortWrite, io.EOF,
214 {ServiceFlag(SFNodeNetwork), 0, io.ErrShortWrite, io.EOF},
215 {InvType(InvTypeTx), 0, io.ErrShortWrite, io.EOF},
216 {BitcoinNet(MainNet), 0, io.ErrShortWrite, io.EOF},
219 t.Logf("Running %d tests", len(tests))
220 for i, test := range tests {
221 // Encode to wire format.
222 w := newFixedWriter(test.max)
223 err := writeElement(w, test.in)
224 if err != test.writeErr {
225 t.Errorf("writeElement #%d wrong error got: %v, want: %v",
226 i, err, test.writeErr)
230 // Decode from wire format.
231 r := newFixedReader(test.max, nil)
233 if reflect.ValueOf(test.in).Kind() != reflect.Ptr {
234 val = reflect.New(reflect.TypeOf(test.in)).Interface()
236 err = readElement(r, val)
237 if err != test.readErr {
238 t.Errorf("readElement #%d wrong error got: %v, want: %v",
239 i, err, test.readErr)
245 // TestVarIntWire tests wire encode and decode for variable length integers.
246 func TestVarIntWire(t *testing.T) {
247 pver := ProtocolVersion
250 in uint64 // Value to encode
251 out uint64 // Expected decoded value
252 buf []byte // Wire encoding
253 pver uint32 // Protocol version for wire encoding
255 // Latest protocol version.
257 {0, 0, []byte{0x00}, pver},
259 {0xfc, 0xfc, []byte{0xfc}, pver},
261 {0xfd, 0xfd, []byte{0xfd, 0x0fd, 0x00}, pver},
263 {0xffff, 0xffff, []byte{0xfd, 0xff, 0xff}, pver},
265 {0x10000, 0x10000, []byte{0xfe, 0x00, 0x00, 0x01, 0x00}, pver},
267 {0xffffffff, 0xffffffff, []byte{0xfe, 0xff, 0xff, 0xff, 0xff}, pver},
270 0x100000000, 0x100000000,
271 []byte{0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00},
276 0xffffffffffffffff, 0xffffffffffffffff,
277 []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
282 t.Logf("Running %d tests", len(tests))
283 for i, test := range tests {
284 // Encode to wire format.
286 err := WriteVarInt(&buf, test.pver, test.in)
288 t.Errorf("WriteVarInt #%d error %v", i, err)
291 if !bytes.Equal(buf.Bytes(), test.buf) {
292 t.Errorf("WriteVarInt #%d\n got: %s want: %s", i,
293 spew.Sdump(buf.Bytes()), spew.Sdump(test.buf))
297 // Decode from wire format.
298 rbuf := bytes.NewReader(test.buf)
299 val, err := ReadVarInt(rbuf, test.pver)
301 t.Errorf("ReadVarInt #%d error %v", i, err)
305 t.Errorf("ReadVarInt #%d\n got: %d want: %d", i,
312 // TestVarIntWireErrors performs negative tests against wire encode and decode
313 // of variable length integers to confirm error paths work correctly.
314 func TestVarIntWireErrors(t *testing.T) {
315 pver := ProtocolVersion
318 in uint64 // Value to encode
319 buf []byte // Wire encoding
320 pver uint32 // Protocol version for wire encoding
321 max int // Max size of fixed buffer to induce errors
322 writeErr error // Expected write error
323 readErr error // Expected read error
325 // Force errors on discriminant.
326 {0, []byte{0x00}, pver, 0, io.ErrShortWrite, io.EOF},
327 // Force errors on 2-byte read/write.
328 {0xfd, []byte{0xfd}, pver, 2, io.ErrShortWrite, io.ErrUnexpectedEOF},
329 // Force errors on 4-byte read/write.
330 {0x10000, []byte{0xfe}, pver, 2, io.ErrShortWrite, io.ErrUnexpectedEOF},
331 // Force errors on 8-byte read/write.
332 {0x100000000, []byte{0xff}, pver, 2, io.ErrShortWrite, io.ErrUnexpectedEOF},
335 t.Logf("Running %d tests", len(tests))
336 for i, test := range tests {
337 // Encode to wire format.
338 w := newFixedWriter(test.max)
339 err := WriteVarInt(w, test.pver, test.in)
340 if err != test.writeErr {
341 t.Errorf("WriteVarInt #%d wrong error got: %v, want: %v",
342 i, err, test.writeErr)
346 // Decode from wire format.
347 r := newFixedReader(test.max, test.buf)
348 _, err = ReadVarInt(r, test.pver)
349 if err != test.readErr {
350 t.Errorf("ReadVarInt #%d wrong error got: %v, want: %v",
351 i, err, test.readErr)
357 // TestVarIntNonCanonical ensures variable length integers that are not encoded
358 // canonically return the expected error.
359 func TestVarIntNonCanonical(t *testing.T) {
360 pver := ProtocolVersion
363 name string // Test name for easier identification
364 in []byte // Value to decode
365 pver uint32 // Protocol version for wire encoding
368 "0 encoded with 3 bytes", []byte{0xfd, 0x00, 0x00},
372 "max single-byte value encoded with 3 bytes",
373 []byte{0xfd, 0xfc, 0x00}, pver,
376 "0 encoded with 5 bytes",
377 []byte{0xfe, 0x00, 0x00, 0x00, 0x00}, pver,
380 "max three-byte value encoded with 5 bytes",
381 []byte{0xfe, 0xff, 0xff, 0x00, 0x00}, pver,
384 "0 encoded with 9 bytes",
385 []byte{0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
389 "max five-byte value encoded with 9 bytes",
390 []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00},
395 t.Logf("Running %d tests", len(tests))
396 for i, test := range tests {
397 // Decode from wire format.
398 rbuf := bytes.NewReader(test.in)
399 val, err := ReadVarInt(rbuf, test.pver)
400 if _, ok := err.(*MessageError); !ok {
401 t.Errorf("ReadVarInt #%d (%s) unexpected error %v", i,
406 t.Errorf("ReadVarInt #%d (%s)\n got: %d want: 0", i,
413 // TestVarIntWire tests the serialize size for variable length integers.
414 func TestVarIntSerializeSize(t *testing.T) {
416 val uint64 // Value to get the serialized size for
417 size int // Expected serialized size
434 {0xffffffffffffffff, 9},
437 t.Logf("Running %d tests", len(tests))
438 for i, test := range tests {
439 serializedSize := VarIntSerializeSize(test.val)
440 if serializedSize != test.size {
441 t.Errorf("VarIntSerializeSize #%d got: %d, want: %d", i,
442 serializedSize, test.size)
448 // TestVarStringWire tests wire encode and decode for variable length strings.
449 func TestVarStringWire(t *testing.T) {
450 pver := ProtocolVersion
452 // str256 is a string that takes a 2-byte varint to encode.
453 str256 := strings.Repeat("test", 64)
456 in string // String to encode
457 out string // String to decoded value
458 buf []byte // Wire encoding
459 pver uint32 // Protocol version for wire encoding
461 // Latest protocol version.
463 {"", "", []byte{0x00}, pver},
464 // Single byte varint + string
465 {"Test", "Test", append([]byte{0x04}, []byte("Test")...), pver},
466 // 2-byte varint + string
467 {str256, str256, append([]byte{0xfd, 0x00, 0x01}, []byte(str256)...), pver},
470 t.Logf("Running %d tests", len(tests))
471 for i, test := range tests {
472 // Encode to wire format.
474 err := WriteVarString(&buf, test.pver, test.in)
476 t.Errorf("WriteVarString #%d error %v", i, err)
479 if !bytes.Equal(buf.Bytes(), test.buf) {
480 t.Errorf("WriteVarString #%d\n got: %s want: %s", i,
481 spew.Sdump(buf.Bytes()), spew.Sdump(test.buf))
485 // Decode from wire format.
486 rbuf := bytes.NewReader(test.buf)
487 val, err := ReadVarString(rbuf, test.pver)
489 t.Errorf("ReadVarString #%d error %v", i, err)
493 t.Errorf("ReadVarString #%d\n got: %s want: %s", i,
500 // TestVarStringWireErrors performs negative tests against wire encode and
501 // decode of variable length strings to confirm error paths work correctly.
502 func TestVarStringWireErrors(t *testing.T) {
503 pver := ProtocolVersion
505 // str256 is a string that takes a 2-byte varint to encode.
506 str256 := strings.Repeat("test", 64)
509 in string // Value to encode
510 buf []byte // Wire encoding
511 pver uint32 // Protocol version for wire encoding
512 max int // Max size of fixed buffer to induce errors
513 writeErr error // Expected write error
514 readErr error // Expected read error
516 // Latest protocol version with intentional read/write errors.
517 // Force errors on empty string.
518 {"", []byte{0x00}, pver, 0, io.ErrShortWrite, io.EOF},
519 // Force error on single byte varint + string.
520 {"Test", []byte{0x04}, pver, 2, io.ErrShortWrite, io.ErrUnexpectedEOF},
521 // Force errors on 2-byte varint + string.
522 {str256, []byte{0xfd}, pver, 2, io.ErrShortWrite, io.ErrUnexpectedEOF},
525 t.Logf("Running %d tests", len(tests))
526 for i, test := range tests {
527 // Encode to wire format.
528 w := newFixedWriter(test.max)
529 err := WriteVarString(w, test.pver, test.in)
530 if err != test.writeErr {
531 t.Errorf("WriteVarString #%d wrong error got: %v, want: %v",
532 i, err, test.writeErr)
536 // Decode from wire format.
537 r := newFixedReader(test.max, test.buf)
538 _, err = ReadVarString(r, test.pver)
539 if err != test.readErr {
540 t.Errorf("ReadVarString #%d wrong error got: %v, want: %v",
541 i, err, test.readErr)
547 // TestVarStringOverflowErrors performs tests to ensure deserializing variable
548 // length strings intentionally crafted to use large values for the string
549 // length are handled properly. This could otherwise potentially be used as an
551 func TestVarStringOverflowErrors(t *testing.T) {
552 pver := ProtocolVersion
555 buf []byte // Wire encoding
556 pver uint32 // Protocol version for wire encoding
557 err error // Expected error
559 {[]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
560 pver, &MessageError{}},
561 {[]byte{0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
562 pver, &MessageError{}},
565 t.Logf("Running %d tests", len(tests))
566 for i, test := range tests {
567 // Decode from wire format.
568 rbuf := bytes.NewReader(test.buf)
569 _, err := ReadVarString(rbuf, test.pver)
570 if reflect.TypeOf(err) != reflect.TypeOf(test.err) {
571 t.Errorf("ReadVarString #%d wrong error got: %v, "+
572 "want: %v", i, err, reflect.TypeOf(test.err))
579 // TestVarBytesWire tests wire encode and decode for variable length byte array.
580 func TestVarBytesWire(t *testing.T) {
581 pver := ProtocolVersion
583 // bytes256 is a byte array that takes a 2-byte varint to encode.
584 bytes256 := bytes.Repeat([]byte{0x01}, 256)
587 in []byte // Byte Array to write
588 buf []byte // Wire encoding
589 pver uint32 // Protocol version for wire encoding
591 // Latest protocol version.
593 {[]byte{}, []byte{0x00}, pver},
594 // Single byte varint + byte array
595 {[]byte{0x01}, []byte{0x01, 0x01}, pver},
596 // 2-byte varint + byte array
597 {bytes256, append([]byte{0xfd, 0x00, 0x01}, bytes256...), pver},
600 t.Logf("Running %d tests", len(tests))
601 for i, test := range tests {
602 // Encode to wire format.
604 err := WriteVarBytes(&buf, test.pver, test.in)
606 t.Errorf("WriteVarBytes #%d error %v", i, err)
609 if !bytes.Equal(buf.Bytes(), test.buf) {
610 t.Errorf("WriteVarBytes #%d\n got: %s want: %s", i,
611 spew.Sdump(buf.Bytes()), spew.Sdump(test.buf))
615 // Decode from wire format.
616 rbuf := bytes.NewReader(test.buf)
617 val, err := ReadVarBytes(rbuf, test.pver, MaxMessagePayload,
620 t.Errorf("ReadVarBytes #%d error %v", i, err)
623 if !bytes.Equal(buf.Bytes(), test.buf) {
624 t.Errorf("ReadVarBytes #%d\n got: %s want: %s", i,
631 // TestVarBytesWireErrors performs negative tests against wire encode and
632 // decode of variable length byte arrays to confirm error paths work correctly.
633 func TestVarBytesWireErrors(t *testing.T) {
634 pver := ProtocolVersion
636 // bytes256 is a byte array that takes a 2-byte varint to encode.
637 bytes256 := bytes.Repeat([]byte{0x01}, 256)
640 in []byte // Byte Array to write
641 buf []byte // Wire encoding
642 pver uint32 // Protocol version for wire encoding
643 max int // Max size of fixed buffer to induce errors
644 writeErr error // Expected write error
645 readErr error // Expected read error
647 // Latest protocol version with intentional read/write errors.
648 // Force errors on empty byte array.
649 {[]byte{}, []byte{0x00}, pver, 0, io.ErrShortWrite, io.EOF},
650 // Force error on single byte varint + byte array.
651 {[]byte{0x01, 0x02, 0x03}, []byte{0x04}, pver, 2, io.ErrShortWrite, io.ErrUnexpectedEOF},
652 // Force errors on 2-byte varint + byte array.
653 {bytes256, []byte{0xfd}, pver, 2, io.ErrShortWrite, io.ErrUnexpectedEOF},
656 t.Logf("Running %d tests", len(tests))
657 for i, test := range tests {
658 // Encode to wire format.
659 w := newFixedWriter(test.max)
660 err := WriteVarBytes(w, test.pver, test.in)
661 if err != test.writeErr {
662 t.Errorf("WriteVarBytes #%d wrong error got: %v, want: %v",
663 i, err, test.writeErr)
667 // Decode from wire format.
668 r := newFixedReader(test.max, test.buf)
669 _, err = ReadVarBytes(r, test.pver, MaxMessagePayload,
671 if err != test.readErr {
672 t.Errorf("ReadVarBytes #%d wrong error got: %v, want: %v",
673 i, err, test.readErr)
679 // TestVarBytesOverflowErrors performs tests to ensure deserializing variable
680 // length byte arrays intentionally crafted to use large values for the array
681 // length are handled properly. This could otherwise potentially be used as an
683 func TestVarBytesOverflowErrors(t *testing.T) {
684 pver := ProtocolVersion
687 buf []byte // Wire encoding
688 pver uint32 // Protocol version for wire encoding
689 err error // Expected error
691 {[]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
692 pver, &MessageError{}},
693 {[]byte{0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
694 pver, &MessageError{}},
697 t.Logf("Running %d tests", len(tests))
698 for i, test := range tests {
699 // Decode from wire format.
700 rbuf := bytes.NewReader(test.buf)
701 _, err := ReadVarBytes(rbuf, test.pver, MaxMessagePayload,
703 if reflect.TypeOf(err) != reflect.TypeOf(test.err) {
704 t.Errorf("ReadVarBytes #%d wrong error got: %v, "+
705 "want: %v", i, err, reflect.TypeOf(test.err))
712 // TestRandomUint64 exercises the randomness of the random number generator on
713 // the system by ensuring the probability of the generated numbers. If the RNG
714 // is evenly distributed as a proper cryptographic RNG should be, there really
715 // should only be 1 number < 2^56 in 2^8 tries for a 64-bit number. However,
716 // use a higher number of 5 to really ensure the test doesn't fail unless the
717 // RNG is just horrendous.
718 func TestRandomUint64(t *testing.T) {
719 tries := 1 << 8 // 2^8
720 watermark := uint64(1 << 56) // 2^56
722 badRNG := "The random number generator on this system is clearly " +
723 "terrible since we got %d values less than %d in %d runs " +
724 "when only %d was expected"
727 for i := 0; i < tries; i++ {
728 nonce, err := RandomUint64()
730 t.Errorf("RandomUint64 iteration %d failed - err %v",
734 if nonce < watermark {
737 if numHits > maxHits {
738 str := fmt.Sprintf(badRNG, numHits, watermark, tries, maxHits)
739 t.Errorf("Random Uint64 iteration %d failed - %v %v", i,
746 // TestRandomUint64Errors uses a fake reader to force error paths to be executed
747 // and checks the results accordingly.
748 func TestRandomUint64Errors(t *testing.T) {
750 fr := &fakeRandReader{n: 2, err: io.EOF}
751 nonce, err := randomUint64(fr)
752 if err != io.ErrUnexpectedEOF {
753 t.Errorf("Error not expected value of %v [%v]",
754 io.ErrUnexpectedEOF, err)
757 t.Errorf("Nonce is not 0 [%v]", nonce)