decred.org/dcrdex@v1.0.5/dex/networks/doge/block_test.go (about) 1 // This code is available on the terms of the project LICENSE.md file, 2 // also available online at https://blueoakcouncil.org/license/1.0.0. 3 4 package doge 5 6 import ( 7 _ "embed" 8 "testing" 9 10 "github.com/btcsuite/btcd/chaincfg/chainhash" 11 ) 12 13 var ( 14 // Block 299983 is version 2 with no AuxPOW section, and two txns. 15 //go:embed test-data/block299983.dat 16 block299983 []byte 17 18 // Block 371027 is version 6422530 with and AuxPOW section, and five txns. 19 //go:embed test-data/block371027.dat 20 block371027 []byte 21 22 // Block 371469 is version 6422786 with and AuxPOW section, and three txns. 23 //go:embed test-data/block371469.dat 24 block371469 []byte 25 26 // Block 4193723 is version 6422788 with an AuxPOW section, and two txns. 27 //go:embed test-data/block4193723.dat 28 block4193723 []byte 29 ) 30 31 func TestDeserializeBlock(t *testing.T) { 32 tests := []struct { 33 name string 34 blk []byte 35 wantHash string 36 wantNumTx int 37 wantLastTx string 38 }{ 39 { 40 "block 299983 ver 2 no AuxPOW", 41 block299983, 42 "1cf943b386ffb79595ef7587deef02419e9d0af6a0e3a1e826d8f34f89c678db", 43 2, 44 "51a9edf6eccf76c09f7ee150634d9425498fbf70108b1c05d39b71f32574ffe7", 45 }, 46 { 47 "block 371027 ver 6422530 AuxPOW", 48 block371027, 49 "f498b4d866dd602749fb5bb2765333d09ae9d807a0c72434994d617ad38a4197", 50 5, 51 "9813c190f5733e12030f2bc0b6581ebfbba2a039ceb8432b4d73a159e90f08ea", 52 }, 53 { 54 "block 371469 ver 6422786 AuxPOW", 55 block371469, 56 "99c426b4c1b3f6c62f7d6fd1ccf8554a046b0156eef1ea2fe98daf53a3f7f184", 57 3, 58 "446ef44f9ec21695f481af8b60a3c84560faca40c9cc82a460eee87b9ea8aba1", 59 }, 60 { 61 "block 4193723 ver 6422788 AuxPOW", 62 block4193723, 63 "7395d83c7a7acdaa69b08af0c3bc1b8f57a1102a5f4090bee9380985833c3682", 64 2, 65 "31f6c10a2afcd2759de7cd9cc1247e6994e62bda3f202bd87cff1cb14fab5934", 66 }, 67 } 68 69 for _, tt := range tests { 70 t.Run(tt.name, func(t *testing.T) { 71 msgBlk, err := DeserializeBlock(tt.blk) 72 if err != nil { 73 t.Fatal(err) 74 } 75 76 wantHash, err := chainhash.NewHashFromStr(tt.wantHash) 77 if err != nil { 78 t.Fatal(err) 79 } 80 81 blkHash := msgBlk.BlockHash() 82 if blkHash != *wantHash { 83 t.Errorf("Wanted block hash %v, got %v", wantHash, blkHash) 84 } 85 86 if len(msgBlk.Transactions) != tt.wantNumTx { 87 t.Errorf("Wanted %d txns, found %d", tt.wantNumTx, len(msgBlk.Transactions)) 88 } 89 90 wantLastTx, err := chainhash.NewHashFromStr(tt.wantLastTx) 91 if err != nil { 92 t.Fatal(err) 93 } 94 95 lastTxHash := msgBlk.Transactions[len(msgBlk.Transactions)-1].TxHash() 96 if lastTxHash != *wantLastTx { 97 t.Errorf("Wanted last block hash %v, got %v", wantLastTx, lastTxHash) 98 } 99 }) 100 } 101 }