github.com/annchain/OG@v0.0.9/consensus/bft_test/consensus_message_gen_test.go (about) 1 package bft_test 2 3 // Code generated by github.com/tinylib/msgp DO NOT EDIT. 4 5 import ( 6 "bytes" 7 "github.com/annchain/OG/consensus/bft" 8 "testing" 9 10 "github.com/tinylib/msgp/msgp" 11 ) 12 13 func TestMarshalUnmarshalBftBasicInfo(t *testing.T) { 14 v := bft.BftBasicInfo{} 15 bts, err := v.MarshalMsg(nil) 16 if err != nil { 17 t.Fatal(err) 18 } 19 left, err := v.UnmarshalMsg(bts) 20 if err != nil { 21 t.Fatal(err) 22 } 23 if len(left) > 0 { 24 t.Errorf("%d bytes left over after UnmarshalMsg(): %q", len(left), left) 25 } 26 27 left, err = msgp.Skip(bts) 28 if err != nil { 29 t.Fatal(err) 30 } 31 if len(left) > 0 { 32 t.Errorf("%d bytes left over after Skip(): %q", len(left), left) 33 } 34 } 35 36 func BenchmarkMarshalMsgBftBasicInfo(b *testing.B) { 37 v := bft.BftBasicInfo{} 38 b.ReportAllocs() 39 b.ResetTimer() 40 for i := 0; i < b.N; i++ { 41 v.MarshalMsg(nil) 42 } 43 } 44 45 func BenchmarkAppendMsgBftBasicInfo(b *testing.B) { 46 v := bft.BftBasicInfo{} 47 bts := make([]byte, 0, v.Msgsize()) 48 bts, _ = v.MarshalMsg(bts[0:0]) 49 b.SetBytes(int64(len(bts))) 50 b.ReportAllocs() 51 b.ResetTimer() 52 for i := 0; i < b.N; i++ { 53 bts, _ = v.MarshalMsg(bts[0:0]) 54 } 55 } 56 57 func BenchmarkUnmarshalBftBasicInfo(b *testing.B) { 58 v := bft.BftBasicInfo{} 59 bts, _ := v.MarshalMsg(nil) 60 b.ReportAllocs() 61 b.SetBytes(int64(len(bts))) 62 b.ResetTimer() 63 for i := 0; i < b.N; i++ { 64 _, err := v.UnmarshalMsg(bts) 65 if err != nil { 66 b.Fatal(err) 67 } 68 } 69 } 70 71 func TestEncodeDecodeBftBasicInfo(t *testing.T) { 72 v := bft.BftBasicInfo{} 73 var buf bytes.Buffer 74 msgp.Encode(&buf, &v) 75 76 m := v.Msgsize() 77 if buf.Len() > m { 78 t.Log("WARNING: TestEncodeDecodeBftBasicInfo Msgsize() is inaccurate") 79 } 80 81 vn := bft.BftBasicInfo{} 82 err := msgp.Decode(&buf, &vn) 83 if err != nil { 84 t.Error(err) 85 } 86 87 buf.Reset() 88 msgp.Encode(&buf, &v) 89 err = msgp.NewReader(&buf).Skip() 90 if err != nil { 91 t.Error(err) 92 } 93 } 94 95 func BenchmarkEncodeBftBasicInfo(b *testing.B) { 96 v := bft.BftBasicInfo{} 97 var buf bytes.Buffer 98 msgp.Encode(&buf, &v) 99 b.SetBytes(int64(buf.Len())) 100 en := msgp.NewWriter(msgp.Nowhere) 101 b.ReportAllocs() 102 b.ResetTimer() 103 for i := 0; i < b.N; i++ { 104 v.EncodeMsg(en) 105 } 106 en.Flush() 107 } 108 109 func BenchmarkDecodeBftBasicInfo(b *testing.B) { 110 v := bft.BftBasicInfo{} 111 var buf bytes.Buffer 112 msgp.Encode(&buf, &v) 113 b.SetBytes(int64(buf.Len())) 114 rd := msgp.NewEndlessReader(buf.Bytes(), b) 115 dc := msgp.NewReader(rd) 116 b.ReportAllocs() 117 b.ResetTimer() 118 for i := 0; i < b.N; i++ { 119 err := v.DecodeMsg(dc) 120 if err != nil { 121 b.Fatal(err) 122 } 123 } 124 } 125 126 func TestMarshalUnmarshalBftMessage(t *testing.T) { 127 v := bft.BftMessage{} 128 bts, err := v.MarshalMsg(nil) 129 if err != nil { 130 t.Fatal(err) 131 } 132 left, err := v.UnmarshalMsg(bts) 133 if err != nil { 134 t.Fatal(err) 135 } 136 if len(left) > 0 { 137 t.Errorf("%d bytes left over after UnmarshalMsg(): %q", len(left), left) 138 } 139 140 left, err = msgp.Skip(bts) 141 if err != nil { 142 t.Fatal(err) 143 } 144 if len(left) > 0 { 145 t.Errorf("%d bytes left over after Skip(): %q", len(left), left) 146 } 147 } 148 149 func BenchmarkMarshalMsgBftMessage(b *testing.B) { 150 v := bft.BftMessage{} 151 b.ReportAllocs() 152 b.ResetTimer() 153 for i := 0; i < b.N; i++ { 154 v.MarshalMsg(nil) 155 } 156 } 157 158 func BenchmarkAppendMsgBftMessage(b *testing.B) { 159 v := bft.BftMessage{} 160 bts := make([]byte, 0, v.Msgsize()) 161 bts, _ = v.MarshalMsg(bts[0:0]) 162 b.SetBytes(int64(len(bts))) 163 b.ReportAllocs() 164 b.ResetTimer() 165 for i := 0; i < b.N; i++ { 166 bts, _ = v.MarshalMsg(bts[0:0]) 167 } 168 } 169 170 func BenchmarkUnmarshalBftMessage(b *testing.B) { 171 v := bft.BftMessage{} 172 bts, _ := v.MarshalMsg(nil) 173 b.ReportAllocs() 174 b.SetBytes(int64(len(bts))) 175 b.ResetTimer() 176 for i := 0; i < b.N; i++ { 177 _, err := v.UnmarshalMsg(bts) 178 if err != nil { 179 b.Fatal(err) 180 } 181 } 182 } 183 184 func TestEncodeDecodeBftMessage(t *testing.T) { 185 v := bft.BftMessage{} 186 var buf bytes.Buffer 187 msgp.Encode(&buf, &v) 188 189 m := v.Msgsize() 190 if buf.Len() > m { 191 t.Log("WARNING: TestEncodeDecodeBftMessage Msgsize() is inaccurate") 192 } 193 194 vn := bft.BftMessage{} 195 err := msgp.Decode(&buf, &vn) 196 if err != nil { 197 t.Error(err) 198 } 199 200 buf.Reset() 201 msgp.Encode(&buf, &v) 202 err = msgp.NewReader(&buf).Skip() 203 if err != nil { 204 t.Error(err) 205 } 206 } 207 208 func BenchmarkEncodeBftMessage(b *testing.B) { 209 v := bft.BftMessage{} 210 var buf bytes.Buffer 211 msgp.Encode(&buf, &v) 212 b.SetBytes(int64(buf.Len())) 213 en := msgp.NewWriter(msgp.Nowhere) 214 b.ReportAllocs() 215 b.ResetTimer() 216 for i := 0; i < b.N; i++ { 217 v.EncodeMsg(en) 218 } 219 en.Flush() 220 } 221 222 func BenchmarkDecodeBftMessage(b *testing.B) { 223 v := bft.BftMessage{} 224 var buf bytes.Buffer 225 msgp.Encode(&buf, &v) 226 b.SetBytes(int64(buf.Len())) 227 rd := msgp.NewEndlessReader(buf.Bytes(), b) 228 dc := msgp.NewReader(rd) 229 b.ReportAllocs() 230 b.ResetTimer() 231 for i := 0; i < b.N; i++ { 232 err := v.DecodeMsg(dc) 233 if err != nil { 234 b.Fatal(err) 235 } 236 } 237 } 238 239 func TestMarshalUnmarshalHeightRound(t *testing.T) { 240 v := bft.HeightRound{} 241 bts, err := v.MarshalMsg(nil) 242 if err != nil { 243 t.Fatal(err) 244 } 245 left, err := v.UnmarshalMsg(bts) 246 if err != nil { 247 t.Fatal(err) 248 } 249 if len(left) > 0 { 250 t.Errorf("%d bytes left over after UnmarshalMsg(): %q", len(left), left) 251 } 252 253 left, err = msgp.Skip(bts) 254 if err != nil { 255 t.Fatal(err) 256 } 257 if len(left) > 0 { 258 t.Errorf("%d bytes left over after Skip(): %q", len(left), left) 259 } 260 } 261 262 func BenchmarkMarshalMsgHeightRound(b *testing.B) { 263 v := bft.HeightRound{} 264 b.ReportAllocs() 265 b.ResetTimer() 266 for i := 0; i < b.N; i++ { 267 v.MarshalMsg(nil) 268 } 269 } 270 271 func BenchmarkAppendMsgHeightRound(b *testing.B) { 272 v := bft.HeightRound{} 273 bts := make([]byte, 0, v.Msgsize()) 274 bts, _ = v.MarshalMsg(bts[0:0]) 275 b.SetBytes(int64(len(bts))) 276 b.ReportAllocs() 277 b.ResetTimer() 278 for i := 0; i < b.N; i++ { 279 bts, _ = v.MarshalMsg(bts[0:0]) 280 } 281 } 282 283 func BenchmarkUnmarshalHeightRound(b *testing.B) { 284 v := bft.HeightRound{} 285 bts, _ := v.MarshalMsg(nil) 286 b.ReportAllocs() 287 b.SetBytes(int64(len(bts))) 288 b.ResetTimer() 289 for i := 0; i < b.N; i++ { 290 _, err := v.UnmarshalMsg(bts) 291 if err != nil { 292 b.Fatal(err) 293 } 294 } 295 } 296 297 func TestEncodeDecodeHeightRound(t *testing.T) { 298 v := bft.HeightRound{} 299 var buf bytes.Buffer 300 msgp.Encode(&buf, &v) 301 302 m := v.Msgsize() 303 if buf.Len() > m { 304 t.Log("WARNING: TestEncodeDecodeHeightRound Msgsize() is inaccurate") 305 } 306 307 vn := bft.HeightRound{} 308 err := msgp.Decode(&buf, &vn) 309 if err != nil { 310 t.Error(err) 311 } 312 313 buf.Reset() 314 msgp.Encode(&buf, &v) 315 err = msgp.NewReader(&buf).Skip() 316 if err != nil { 317 t.Error(err) 318 } 319 } 320 321 func BenchmarkEncodeHeightRound(b *testing.B) { 322 v := bft.HeightRound{} 323 var buf bytes.Buffer 324 msgp.Encode(&buf, &v) 325 b.SetBytes(int64(buf.Len())) 326 en := msgp.NewWriter(msgp.Nowhere) 327 b.ReportAllocs() 328 b.ResetTimer() 329 for i := 0; i < b.N; i++ { 330 v.EncodeMsg(en) 331 } 332 en.Flush() 333 } 334 335 func BenchmarkDecodeHeightRound(b *testing.B) { 336 v := bft.HeightRound{} 337 var buf bytes.Buffer 338 msgp.Encode(&buf, &v) 339 b.SetBytes(int64(buf.Len())) 340 rd := msgp.NewEndlessReader(buf.Bytes(), b) 341 dc := msgp.NewReader(rd) 342 b.ReportAllocs() 343 b.ResetTimer() 344 for i := 0; i < b.N; i++ { 345 err := v.DecodeMsg(dc) 346 if err != nil { 347 b.Fatal(err) 348 } 349 } 350 } 351 352 func TestMarshalUnmarshalMessagePreCommit(t *testing.T) { 353 v := bft.BftMessagePreCommit{} 354 bts, err := v.MarshalMsg(nil) 355 if err != nil { 356 t.Fatal(err) 357 } 358 left, err := v.UnmarshalMsg(bts) 359 if err != nil { 360 t.Fatal(err) 361 } 362 if len(left) > 0 { 363 t.Errorf("%d bytes left over after UnmarshalMsg(): %q", len(left), left) 364 } 365 366 left, err = msgp.Skip(bts) 367 if err != nil { 368 t.Fatal(err) 369 } 370 if len(left) > 0 { 371 t.Errorf("%d bytes left over after Skip(): %q", len(left), left) 372 } 373 } 374 375 func BenchmarkMarshalMsgMessagePreCommit(b *testing.B) { 376 v := bft.BftMessagePreCommit{} 377 b.ReportAllocs() 378 b.ResetTimer() 379 for i := 0; i < b.N; i++ { 380 v.MarshalMsg(nil) 381 } 382 } 383 384 func BenchmarkAppendMsgMessagePreCommit(b *testing.B) { 385 v := bft.BftMessagePreCommit{} 386 bts := make([]byte, 0, v.Msgsize()) 387 bts, _ = v.MarshalMsg(bts[0:0]) 388 b.SetBytes(int64(len(bts))) 389 b.ReportAllocs() 390 b.ResetTimer() 391 for i := 0; i < b.N; i++ { 392 bts, _ = v.MarshalMsg(bts[0:0]) 393 } 394 } 395 396 func BenchmarkUnmarshalMessagePreCommit(b *testing.B) { 397 v := bft.BftMessagePreCommit{} 398 bts, _ := v.MarshalMsg(nil) 399 b.ReportAllocs() 400 b.SetBytes(int64(len(bts))) 401 b.ResetTimer() 402 for i := 0; i < b.N; i++ { 403 _, err := v.UnmarshalMsg(bts) 404 if err != nil { 405 b.Fatal(err) 406 } 407 } 408 } 409 410 func TestEncodeDecodeMessagePreCommit(t *testing.T) { 411 v := bft.BftMessagePreCommit{} 412 var buf bytes.Buffer 413 msgp.Encode(&buf, &v) 414 415 m := v.Msgsize() 416 if buf.Len() > m { 417 t.Log("WARNING: TestEncodeDecodeMessagePreCommit Msgsize() is inaccurate") 418 } 419 420 vn := bft.BftMessagePreCommit{} 421 err := msgp.Decode(&buf, &vn) 422 if err != nil { 423 t.Error(err) 424 } 425 426 buf.Reset() 427 msgp.Encode(&buf, &v) 428 err = msgp.NewReader(&buf).Skip() 429 if err != nil { 430 t.Error(err) 431 } 432 } 433 434 func BenchmarkEncodeMessagePreCommit(b *testing.B) { 435 v := bft.BftMessagePreCommit{} 436 var buf bytes.Buffer 437 msgp.Encode(&buf, &v) 438 b.SetBytes(int64(buf.Len())) 439 en := msgp.NewWriter(msgp.Nowhere) 440 b.ReportAllocs() 441 b.ResetTimer() 442 for i := 0; i < b.N; i++ { 443 v.EncodeMsg(en) 444 } 445 en.Flush() 446 } 447 448 func BenchmarkDecodeMessagePreCommit(b *testing.B) { 449 v := bft.BftMessagePreCommit{} 450 var buf bytes.Buffer 451 msgp.Encode(&buf, &v) 452 b.SetBytes(int64(buf.Len())) 453 rd := msgp.NewEndlessReader(buf.Bytes(), b) 454 dc := msgp.NewReader(rd) 455 b.ReportAllocs() 456 b.ResetTimer() 457 for i := 0; i < b.N; i++ { 458 err := v.DecodeMsg(dc) 459 if err != nil { 460 b.Fatal(err) 461 } 462 } 463 } 464 465 func TestMarshalUnmarshalMessagePreVote(t *testing.T) { 466 v := bft.BftMessagePreVote{} 467 bts, err := v.MarshalMsg(nil) 468 if err != nil { 469 t.Fatal(err) 470 } 471 left, err := v.UnmarshalMsg(bts) 472 if err != nil { 473 t.Fatal(err) 474 } 475 if len(left) > 0 { 476 t.Errorf("%d bytes left over after UnmarshalMsg(): %q", len(left), left) 477 } 478 479 left, err = msgp.Skip(bts) 480 if err != nil { 481 t.Fatal(err) 482 } 483 if len(left) > 0 { 484 t.Errorf("%d bytes left over after Skip(): %q", len(left), left) 485 } 486 } 487 488 func BenchmarkMarshalMsgMessagePreVote(b *testing.B) { 489 v := bft.BftMessagePreVote{} 490 b.ReportAllocs() 491 b.ResetTimer() 492 for i := 0; i < b.N; i++ { 493 v.MarshalMsg(nil) 494 } 495 } 496 497 func BenchmarkAppendMsgMessagePreVote(b *testing.B) { 498 v := bft.BftMessagePreVote{} 499 bts := make([]byte, 0, v.Msgsize()) 500 bts, _ = v.MarshalMsg(bts[0:0]) 501 b.SetBytes(int64(len(bts))) 502 b.ReportAllocs() 503 b.ResetTimer() 504 for i := 0; i < b.N; i++ { 505 bts, _ = v.MarshalMsg(bts[0:0]) 506 } 507 } 508 509 func BenchmarkUnmarshalMessagePreVote(b *testing.B) { 510 v := bft.BftMessagePreVote{} 511 bts, _ := v.MarshalMsg(nil) 512 b.ReportAllocs() 513 b.SetBytes(int64(len(bts))) 514 b.ResetTimer() 515 for i := 0; i < b.N; i++ { 516 _, err := v.UnmarshalMsg(bts) 517 if err != nil { 518 b.Fatal(err) 519 } 520 } 521 } 522 523 func TestEncodeDecodeMessagePreVote(t *testing.T) { 524 v := bft.BftMessagePreVote{} 525 var buf bytes.Buffer 526 msgp.Encode(&buf, &v) 527 528 m := v.Msgsize() 529 if buf.Len() > m { 530 t.Log("WARNING: TestEncodeDecodeMessagePreVote Msgsize() is inaccurate") 531 } 532 533 vn := bft.BftMessagePreVote{} 534 err := msgp.Decode(&buf, &vn) 535 if err != nil { 536 t.Error(err) 537 } 538 539 buf.Reset() 540 msgp.Encode(&buf, &v) 541 err = msgp.NewReader(&buf).Skip() 542 if err != nil { 543 t.Error(err) 544 } 545 } 546 547 func BenchmarkEncodeMessagePreVote(b *testing.B) { 548 v := bft.BftMessagePreVote{} 549 var buf bytes.Buffer 550 msgp.Encode(&buf, &v) 551 b.SetBytes(int64(buf.Len())) 552 en := msgp.NewWriter(msgp.Nowhere) 553 b.ReportAllocs() 554 b.ResetTimer() 555 for i := 0; i < b.N; i++ { 556 v.EncodeMsg(en) 557 } 558 en.Flush() 559 } 560 561 func BenchmarkDecodeMessagePreVote(b *testing.B) { 562 v := bft.BftMessagePreVote{} 563 var buf bytes.Buffer 564 msgp.Encode(&buf, &v) 565 b.SetBytes(int64(buf.Len())) 566 rd := msgp.NewEndlessReader(buf.Bytes(), b) 567 dc := msgp.NewReader(rd) 568 b.ReportAllocs() 569 b.ResetTimer() 570 for i := 0; i < b.N; i++ { 571 err := v.DecodeMsg(dc) 572 if err != nil { 573 b.Fatal(err) 574 } 575 } 576 } 577 578 func TestMarshalUnmarshalMessageProposal(t *testing.T) { 579 v := bft.BftMessageProposal{} 580 bts, err := v.MarshalMsg(nil) 581 if err != nil { 582 t.Fatal(err) 583 } 584 left, err := v.UnmarshalMsg(bts) 585 if err != nil { 586 t.Fatal(err) 587 } 588 if len(left) > 0 { 589 t.Errorf("%d bytes left over after UnmarshalMsg(): %q", len(left), left) 590 } 591 592 left, err = msgp.Skip(bts) 593 if err != nil { 594 t.Fatal(err) 595 } 596 if len(left) > 0 { 597 t.Errorf("%d bytes left over after Skip(): %q", len(left), left) 598 } 599 } 600 601 func BenchmarkMarshalMsgMessageProposal(b *testing.B) { 602 v := bft.BftMessageProposal{} 603 b.ReportAllocs() 604 b.ResetTimer() 605 for i := 0; i < b.N; i++ { 606 v.MarshalMsg(nil) 607 } 608 } 609 610 func BenchmarkAppendMsgMessageProposal(b *testing.B) { 611 v := bft.BftMessageProposal{} 612 bts := make([]byte, 0, v.Msgsize()) 613 bts, _ = v.MarshalMsg(bts[0:0]) 614 b.SetBytes(int64(len(bts))) 615 b.ReportAllocs() 616 b.ResetTimer() 617 for i := 0; i < b.N; i++ { 618 bts, _ = v.MarshalMsg(bts[0:0]) 619 } 620 } 621 622 func BenchmarkUnmarshalMessageProposal(b *testing.B) { 623 v := bft.BftMessageProposal{} 624 bts, _ := v.MarshalMsg(nil) 625 b.ReportAllocs() 626 b.SetBytes(int64(len(bts))) 627 b.ResetTimer() 628 for i := 0; i < b.N; i++ { 629 _, err := v.UnmarshalMsg(bts) 630 if err != nil { 631 b.Fatal(err) 632 } 633 } 634 } 635 636 func TestEncodeDecodeMessageProposal(t *testing.T) { 637 v := bft.BftMessageProposal{} 638 var buf bytes.Buffer 639 msgp.Encode(&buf, &v) 640 641 m := v.Msgsize() 642 if buf.Len() > m { 643 t.Log("WARNING: TestEncodeDecodeMessageProposal Msgsize() is inaccurate") 644 } 645 646 vn := bft.BftMessageProposal{} 647 err := msgp.Decode(&buf, &vn) 648 if err != nil { 649 t.Error(err) 650 } 651 652 buf.Reset() 653 msgp.Encode(&buf, &v) 654 err = msgp.NewReader(&buf).Skip() 655 if err != nil { 656 t.Error(err) 657 } 658 } 659 660 func BenchmarkEncodeMessageProposal(b *testing.B) { 661 v := bft.BftMessageProposal{} 662 var buf bytes.Buffer 663 msgp.Encode(&buf, &v) 664 b.SetBytes(int64(buf.Len())) 665 en := msgp.NewWriter(msgp.Nowhere) 666 b.ReportAllocs() 667 b.ResetTimer() 668 for i := 0; i < b.N; i++ { 669 v.EncodeMsg(en) 670 } 671 en.Flush() 672 } 673 674 func BenchmarkDecodeMessageProposal(b *testing.B) { 675 v := bft.BftMessageProposal{} 676 var buf bytes.Buffer 677 msgp.Encode(&buf, &v) 678 b.SetBytes(int64(buf.Len())) 679 rd := msgp.NewEndlessReader(buf.Bytes(), b) 680 dc := msgp.NewReader(rd) 681 b.ReportAllocs() 682 b.ResetTimer() 683 for i := 0; i < b.N; i++ { 684 err := v.DecodeMsg(dc) 685 if err != nil { 686 b.Fatal(err) 687 } 688 } 689 }