github.com/bchainhub/blockbook@v0.3.2/bchain/coins/dogecoin/dogecoinparser_test.go (about) 1 // +build unittest 2 3 package dogecoin 4 5 import ( 6 "blockbook/bchain" 7 "blockbook/bchain/coins/btc" 8 "bytes" 9 "encoding/hex" 10 "fmt" 11 "io/ioutil" 12 "math/big" 13 "os" 14 "path/filepath" 15 "reflect" 16 "testing" 17 18 "github.com/martinboehm/btcutil/chaincfg" 19 ) 20 21 func TestMain(m *testing.M) { 22 c := m.Run() 23 chaincfg.ResetParams() 24 os.Exit(c) 25 } 26 27 func Test_GetAddrDescFromAddress_Mainnet(t *testing.T) { 28 type args struct { 29 address string 30 } 31 tests := []struct { 32 name string 33 args args 34 want string 35 wantErr bool 36 }{ 37 { 38 name: "P2PKH1", 39 args: args{address: "DHZYinsaM9nW5piCMN639ELRKbZomThPnZ"}, 40 want: "76a9148841590909747c0f97af158f22fadacb1652522088ac", 41 wantErr: false, 42 }, 43 { 44 name: "P2PKH2", 45 args: args{address: "DSzaAYEYyy9ngjoJ294r7jzFM3xhD6bKHK"}, 46 want: "76a914efb6158f75743c611858fdfd0f4aaec6cc6196bc88ac", 47 wantErr: false, 48 }, 49 { 50 name: "P2PKH3", 51 args: args{address: "DHobAps6DjZ5n4xMV75n7kJv299Zi85FCG"}, 52 want: "76a9148ae937291e72f7368421dbaa966c44950eb14db788ac", 53 wantErr: false, 54 }, 55 { 56 name: "P2SH1", 57 args: args{address: "9tg1kVUk339Tk58ewu5T8QT82Z6cE4UvSU"}, 58 want: "a9141889a089400ea25d28694fd98aa7702b21eeeab187", 59 wantErr: false, 60 }, 61 { 62 name: "P2SH2", 63 args: args{address: "9sLa1AKzjWuNTe1CkLh5GDYyRP9enb1Spp"}, 64 want: "a91409e41aff9f97412ab3d4a07cf0667fdba84caf4487", 65 wantErr: false, 66 }, 67 } 68 parser := NewDogecoinParser(GetChainParams("main"), &btc.Configuration{}) 69 70 for _, tt := range tests { 71 t.Run(tt.name, func(t *testing.T) { 72 got, err := parser.GetAddrDescFromAddress(tt.args.address) 73 if (err != nil) != tt.wantErr { 74 t.Errorf("GetAddrDescFromAddress() error = %v, wantErr %v", err, tt.wantErr) 75 return 76 } 77 h := hex.EncodeToString(got) 78 if !reflect.DeepEqual(h, tt.want) { 79 t.Errorf("GetAddrDescFromAddress() = %v, want %v", h, tt.want) 80 } 81 }) 82 } 83 } 84 85 func Test_GetAddressesFromAddrDesc_Mainnet(t *testing.T) { 86 type args struct { 87 script string 88 } 89 tests := []struct { 90 name string 91 args args 92 want []string 93 want2 bool 94 wantErr bool 95 }{ 96 { 97 name: "P2PKH1", 98 args: args{script: "76a9148841590909747c0f97af158f22fadacb1652522088ac"}, 99 want: []string{"DHZYinsaM9nW5piCMN639ELRKbZomThPnZ"}, 100 want2: true, 101 wantErr: false, 102 }, 103 { 104 name: "P2PKH2", 105 args: args{script: "76a914efb6158f75743c611858fdfd0f4aaec6cc6196bc88ac"}, 106 want: []string{"DSzaAYEYyy9ngjoJ294r7jzFM3xhD6bKHK"}, 107 want2: true, 108 wantErr: false, 109 }, 110 { 111 name: "P2PKH3", 112 args: args{script: "76a91450e86eeac599ad023b8981296d01b50bdabcdd9788ac"}, 113 want: []string{"DCWu3MLz9xBGFuuLyNDf6QjuGp49f5tfc9"}, 114 want2: true, 115 wantErr: false, 116 }, 117 { 118 name: "P2SH1", 119 args: args{script: "a9141889a089400ea25d28694fd98aa7702b21eeeab187"}, 120 want: []string{"9tg1kVUk339Tk58ewu5T8QT82Z6cE4UvSU"}, 121 want2: true, 122 wantErr: false, 123 }, 124 { 125 name: "OP_RETURN ascii", 126 args: args{script: "6a0461686f6a"}, 127 want: []string{"OP_RETURN (ahoj)"}, 128 want2: false, 129 wantErr: false, 130 }, 131 { 132 name: "OP_RETURN hex", 133 args: args{script: "6a072020f1686f6a20"}, 134 want: []string{"OP_RETURN 2020f1686f6a20"}, 135 want2: false, 136 wantErr: false, 137 }, 138 } 139 140 parser := NewDogecoinParser(GetChainParams("main"), &btc.Configuration{}) 141 142 for _, tt := range tests { 143 t.Run(tt.name, func(t *testing.T) { 144 b, _ := hex.DecodeString(tt.args.script) 145 got, got2, err := parser.GetAddressesFromAddrDesc(b) 146 if (err != nil) != tt.wantErr { 147 t.Errorf("GetAddressesFromAddrDesc() error = %v, wantErr %v", err, tt.wantErr) 148 return 149 } 150 if !reflect.DeepEqual(got, tt.want) { 151 t.Errorf("GetAddressesFromAddrDesc() = %v, want %v", got, tt.want) 152 } 153 if !reflect.DeepEqual(got2, tt.want2) { 154 t.Errorf("GetAddressesFromAddrDesc() = %v, want %v", got2, tt.want2) 155 } 156 }) 157 } 158 } 159 160 var ( 161 testTx1 bchain.Tx 162 testTxPacked1 = "00030e6d8ba8d7aa2001000000016b3c0c53267964120acf7f7e72217e3f463e52ce622f89659f6a6bb8e69a4d91000000006c493046022100a96454237e3a020994534583e28c04757881374bceac89f933ea9ff00b4db259022100fbb757ff7ea4f02c4e42556b2834c61eba1f1af605db089d836a0614d90a3b46012103cebdde6d1046e285df4f48497bc50dc20a4a258ca5b7308cb0a929c9fdadcd9dffffffff0217e823ca7f0200001976a914eef21768a546590993e313c7f3dfadf6a6efa1e888acaddf4cba010000001976a914e0fee2ea29dd9c6c759d8341bd0da4c4f738cced88ac00000000" 163 164 testTx2 bchain.Tx 165 testTxPacked2 = "0001193a8ba8d7835601000000016d0211b5656f1b8c2ac002445638e247082090ffc5d5fa7c38b445b84a2c2054000000006b4830450221008856f2f620df278c0fc6a5d5e2d50451c0a65a75aaf7a4a9cbfcac3918b5536802203dc685a784d49e2a95eb72763ad62f02094af78507c57b0a3c3f1d8a60f74db6012102db814cd43df584804fde1949365a6309714e342aef0794dc58385d7e413444cdffffffff0237daa2ee0a4715001976a9149355c01ed20057eac9fe0bbf8b07d87e62fe712d88ac8008389e7e8d03001976a9145b4f2511c94e4fcaa8f8835b2458f8cb6542ca7688ac00000000" 166 ) 167 168 func init() { 169 testTx1 = bchain.Tx{ 170 Hex: "01000000016b3c0c53267964120acf7f7e72217e3f463e52ce622f89659f6a6bb8e69a4d91000000006c493046022100a96454237e3a020994534583e28c04757881374bceac89f933ea9ff00b4db259022100fbb757ff7ea4f02c4e42556b2834c61eba1f1af605db089d836a0614d90a3b46012103cebdde6d1046e285df4f48497bc50dc20a4a258ca5b7308cb0a929c9fdadcd9dffffffff0217e823ca7f0200001976a914eef21768a546590993e313c7f3dfadf6a6efa1e888acaddf4cba010000001976a914e0fee2ea29dd9c6c759d8341bd0da4c4f738cced88ac00000000", 171 Blocktime: 1519053456, 172 Txid: "097ea09ba284f3f2a9e880e11f837edf7e5cea81c8da2238f5bc7c2c4c407943", 173 LockTime: 0, 174 Version: 1, 175 Vin: []bchain.Vin{ 176 { 177 ScriptSig: bchain.ScriptSig{ 178 Hex: "493046022100a96454237e3a020994534583e28c04757881374bceac89f933ea9ff00b4db259022100fbb757ff7ea4f02c4e42556b2834c61eba1f1af605db089d836a0614d90a3b46012103cebdde6d1046e285df4f48497bc50dc20a4a258ca5b7308cb0a929c9fdadcd9d", 179 }, 180 Txid: "914d9ae6b86b6a9f65892f62ce523e463f7e21727e7fcf0a12647926530c3c6b", 181 Vout: 0, 182 Sequence: 4294967295, 183 }, 184 }, 185 Vout: []bchain.Vout{ 186 { 187 ValueSat: *big.NewInt(2747875452951), 188 N: 0, 189 ScriptPubKey: bchain.ScriptPubKey{ 190 Hex: "76a914eef21768a546590993e313c7f3dfadf6a6efa1e888ac", 191 Addresses: []string{ 192 "DSvXNiqvG42wdteLqh3i6inxgDTs8Y9w2i", 193 }, 194 }, 195 }, 196 { 197 ValueSat: *big.NewInt(7420567469), 198 N: 1, 199 ScriptPubKey: bchain.ScriptPubKey{ 200 Hex: "76a914e0fee2ea29dd9c6c759d8341bd0da4c4f738cced88ac", 201 Addresses: []string{ 202 "DRemF3ZcqJ1PFeM7e7sXzzwQJKR8GNUtwK", 203 }, 204 }, 205 }, 206 }, 207 } 208 209 testTx2 = bchain.Tx{ 210 Hex: "01000000016d0211b5656f1b8c2ac002445638e247082090ffc5d5fa7c38b445b84a2c2054000000006b4830450221008856f2f620df278c0fc6a5d5e2d50451c0a65a75aaf7a4a9cbfcac3918b5536802203dc685a784d49e2a95eb72763ad62f02094af78507c57b0a3c3f1d8a60f74db6012102db814cd43df584804fde1949365a6309714e342aef0794dc58385d7e413444cdffffffff0237daa2ee0a4715001976a9149355c01ed20057eac9fe0bbf8b07d87e62fe712d88ac8008389e7e8d03001976a9145b4f2511c94e4fcaa8f8835b2458f8cb6542ca7688ac00000000", 211 Blocktime: 1519050987, 212 Txid: "b276545af246e3ed5a4e3e5b60d359942a1808579effc53ff4f343e4f6cfc5a0", 213 LockTime: 0, 214 Version: 1, 215 Vin: []bchain.Vin{ 216 { 217 ScriptSig: bchain.ScriptSig{ 218 Hex: "4830450221008856f2f620df278c0fc6a5d5e2d50451c0a65a75aaf7a4a9cbfcac3918b5536802203dc685a784d49e2a95eb72763ad62f02094af78507c57b0a3c3f1d8a60f74db6012102db814cd43df584804fde1949365a6309714e342aef0794dc58385d7e413444cd", 219 }, 220 Txid: "54202c4ab845b4387cfad5c5ff90200847e238564402c02a8c1b6f65b511026d", 221 Vout: 0, 222 Sequence: 4294967295, 223 }, 224 }, 225 Vout: []bchain.Vout{ 226 { 227 ValueSat: *big.NewInt(5989086789818935), 228 N: 0, 229 ScriptPubKey: bchain.ScriptPubKey{ 230 Hex: "76a9149355c01ed20057eac9fe0bbf8b07d87e62fe712d88ac", 231 Addresses: []string{ 232 "DJa8bWDrZKu4HgsYRYWuJrvxt6iTYuvXJ6", 233 }, 234 }, 235 }, 236 { 237 ValueSat: *big.NewInt(999999890000000), 238 N: 1, 239 ScriptPubKey: bchain.ScriptPubKey{ 240 Hex: "76a9145b4f2511c94e4fcaa8f8835b2458f8cb6542ca7688ac", 241 Addresses: []string{ 242 "DDTtqnuZ5kfRT5qh2c7sNtqrJmV3iXYdGG", 243 }, 244 }, 245 }, 246 }, 247 } 248 } 249 250 func Test_PackTx(t *testing.T) { 251 type args struct { 252 tx bchain.Tx 253 height uint32 254 blockTime int64 255 parser *DogecoinParser 256 } 257 tests := []struct { 258 name string 259 args args 260 want string 261 wantErr bool 262 }{ 263 { 264 name: "dogecoin-1", 265 args: args{ 266 tx: testTx1, 267 height: 200301, 268 blockTime: 1519053456, 269 parser: NewDogecoinParser(GetChainParams("main"), &btc.Configuration{}), 270 }, 271 want: testTxPacked1, 272 wantErr: false, 273 }, 274 { 275 name: "dogecoin-2", 276 args: args{ 277 tx: testTx2, 278 height: 71994, 279 blockTime: 1519050987, 280 parser: NewDogecoinParser(GetChainParams("main"), &btc.Configuration{}), 281 }, 282 want: testTxPacked2, 283 wantErr: false, 284 }, 285 } 286 for _, tt := range tests { 287 t.Run(tt.name, func(t *testing.T) { 288 got, err := tt.args.parser.PackTx(&tt.args.tx, tt.args.height, tt.args.blockTime) 289 if (err != nil) != tt.wantErr { 290 t.Errorf("packTx() error = %v, wantErr %v", err, tt.wantErr) 291 return 292 } 293 h := hex.EncodeToString(got) 294 if !reflect.DeepEqual(h, tt.want) { 295 t.Errorf("packTx() = %v, want %v", h, tt.want) 296 } 297 }) 298 } 299 } 300 301 func Test_UnpackTx(t *testing.T) { 302 type args struct { 303 packedTx string 304 parser *DogecoinParser 305 } 306 tests := []struct { 307 name string 308 args args 309 want *bchain.Tx 310 want1 uint32 311 wantErr bool 312 }{ 313 { 314 name: "dogecoin-1", 315 args: args{ 316 packedTx: testTxPacked1, 317 parser: NewDogecoinParser(GetChainParams("main"), &btc.Configuration{}), 318 }, 319 want: &testTx1, 320 want1: 200301, 321 wantErr: false, 322 }, 323 { 324 name: "dogecoin-2", 325 args: args{ 326 packedTx: testTxPacked2, 327 parser: NewDogecoinParser(GetChainParams("main"), &btc.Configuration{}), 328 }, 329 want: &testTx2, 330 want1: 71994, 331 wantErr: false, 332 }, 333 } 334 for _, tt := range tests { 335 t.Run(tt.name, func(t *testing.T) { 336 b, _ := hex.DecodeString(tt.args.packedTx) 337 got, got1, err := tt.args.parser.UnpackTx(b) 338 if (err != nil) != tt.wantErr { 339 t.Errorf("unpackTx() error = %v, wantErr %v", err, tt.wantErr) 340 return 341 } 342 if !reflect.DeepEqual(got, tt.want) { 343 t.Errorf("unpackTx() got = %v, want %v", got, tt.want) 344 } 345 if got1 != tt.want1 { 346 t.Errorf("unpackTx() got1 = %v, want %v", got1, tt.want1) 347 } 348 }) 349 } 350 } 351 352 type testBlock struct { 353 size int 354 time int64 355 txs []string 356 } 357 358 var testParseBlockTxs = map[int]testBlock{ 359 // block without auxpow 360 12345: { 361 size: 8582, 362 time: 1387104223, 363 txs: []string{ 364 "9d1662dcc1443af9999c4fd1d6921b91027b5e2d0d3ebfaa41d84163cb99cad5", 365 "8284292cedeb0c9c509f9baa235802d52a546e1e9990040d35d018b97ad11cfa", 366 "3299d93aae5c3d37c795c07150ceaf008aefa5aad3205ea2519f94a35adbbe10", 367 "3f03016f32b63db48fdc0b17443c2d917ba5e307dcc2fc803feeb21c7219ee1b", 368 "a889449e9bc618c131c01f564cd309d2217ba1c5731480314795e44f1e02609b", 369 "29f79d91c10bc311ff5b69fe7ba57101969f68b6391cf0ca67d5f37ca1f0601b", 370 "b794ebc7c0176c35b125cd8b84a980257cf3dd9cefe2ed47da4ed1d73ee568f3", 371 "0ec479ba3c954dd422d75c4c5488a6edc3c588deb10ebdbfa8bd8edb7afcfea0", 372 "f357b6e667dfa456e7988bfa474377df25d0e0bfe07e5f97fc97ea3a0155f031", 373 "4ff189766f0455721a93d6be27a91eafa750383c800cb053fad2f86c434122d2", 374 "446d164e2ec4c9f2ac6c499c110735606d949a3625fb849274ac627c033eddbc", 375 "c489edebd8a2e17fd08f2801f528b95663aaafe15c897d56686423dd430e2d1f", 376 "3f42a7f1a356897da324d41eed94169c79438212bb9874eea58e9cbaf07481df", 377 "62c88fdd0fb111676844fcbaebc9e2211a0c990aa7e7529539cb25947a307a1b", 378 "522c47e315bc1949826339c535d419eb206aec4a332f91dfbd25c206f3c9527b", 379 "18ea78346e7e34cbdf2d2b6ba1630f8b15f9ef9a940114a3e6ee92d26f96691e", 380 "43dc0fbd1b9b87bcfc9a51c89457a7b3274855c01d429193aff1181791225f3c", 381 "d78cdfaadbe5b6b591529cb5c6869866a4cabe46ef82aa835fd2432056b4a383", 382 "d181759c7a3900ccaf4958f1f25a44949163ceefc306006502efc7a1de6f579e", 383 "8610b9230188854c7871258163cd1c2db353443d631c5512bff17224a24e95bf", 384 "e82f40a6bea32122f1d568d427c92708dcb684bdb3035ff3905617230e5ae5b8", 385 "c50ae6c127f8c346c60e7438fbd10c44c3629f3fe426646db77a2250fb2939f9", 386 "585202c03894ecaf25188ba4e5447dadd413f2010c2dc2a65c37598dbc6ad907", 387 "8bd766fde8c65e2f724dad581944dde4e23e4dbb4f7f7faf55bc348923f4d5ee", 388 "2d2fa25691088181569e508dd8f683b21f2b80ceefb5ccbd6714ebe2a697139f", 389 "5954622ffc602bec177d61da6c26a68990c42c1886627b218c3ab0e9e3491f4a", 390 "01b634bc53334df1cd9f04522729a34d811c418c2535144c3ed156cbc319e43e", 391 "c429a6c8265482b2d824af03afe1c090b233a856f243791485cb4269f2729649", 392 "dbe79231b916b6fb47a91ef874f35150270eb571af60c2d640ded92b41749940", 393 "1c396493a8dfd59557052b6e8643123405894b64f48b2eb6eb7a003159034077", 394 "2e2816ffb7bf1378f11acf5ba30d498efc8fd219d4b67a725e8254ce61b1b7ee", 395 }, 396 }, 397 // 1st block with auxpow 398 371337: { 399 size: 1704, 400 time: 1410464577, 401 txs: []string{ 402 "4547b14bc16db4184fa9f141d645627430dd3dfa662d0e6f418fba497091da75", 403 "a965dba2ed06827ed9a24f0568ec05b73c431bc7f0fb6913b144e62db7faa519", 404 "5e3ab18cb7ba3abc44e62fb3a43d4c8168d00cf0a2e0f8dbeb2636bb9a212d12", 405 "f022935ac7c4c734bd2c9c6a780f8e7280352de8bd358d760d0645b7fe734a93", 406 "ec063cc8025f9f30a6ed40fc8b1fe63b0cbd2ea2c62664eb26b365e6243828ca", 407 "02c16e3389320da3e77686d39773dda65a1ecdf98a2ef9cfb938c9f4b58f7a40", 408 }, 409 }, 410 // block with auxpow 411 567890: { 412 size: 3833, 413 time: 1422855443, 414 txs: []string{ 415 "db20feea53be1f60848a66604d5bca63df62de4f6c66220f9c84436d788625a8", 416 "cf7e9e27c0f56f0b100eaf5c776ce106025e3412bd5927c6e1ce575500e24eaa", 417 "af84e010c1cf0bd927740d08e5e8163db45397b70f00df07aea5339c14d5f3aa", 418 "7362e25e8131255d101e5d874e6b6bb2faa7a821356cb041f1843d0901dffdbd", 419 "3b875344302e8893f6d5c9e7269d806ed27217ec67944940ae9048fc619bdae9", 420 "e3b95e269b7c251d87e8e241ea2a08a66ec14d12a1012762be368b3db55471e3", 421 "6ba3f95a37bcab5d0cb5b8bd2fe48040db0a6ae390f320d6dcc8162cc096ff8f", 422 "3211ccc66d05b10959fa6e56d1955c12368ea52b40303558b254d7dc22570382", 423 "54c1b279e78b924dfa15857c80131c3ddf835ab02f513dc03aa514f87b680493", 424 }, 425 }, 426 // recent block 427 2264125: { 428 size: 8531, 429 time: 1529099968, 430 txs: []string{ 431 "76f0126562c99e020b5fba41b68dd8141a4f21eef62012b76a1e0635092045e9", 432 "7bb6688bec16de94014574e3e1d3f6f5fb956530d6b179b28db367f1fd8ae099", 433 "d7e2ee30c3d179ac896651fc09c1396333f41d952d008af8d5d6665cbea377bf", 434 "8e4783878df782003c43d014fcbb9c57d2034dfd1d9fcd7319bb1a9f501dbbb7", 435 "8d2a4ae226b6f23eea545957be5d71c68cd08674d96a3502d4ca21ffadacb5a9", 436 "a0da2b49de881133655c54b1b5c23af443a71c2b937e2d9bbdf3f498247e6b7b", 437 "c780a19b9cf46ed70b53c5d5722e8d33951211a4051cb165b25fb0c22a4ae1ff", 438 "ce29c2644d642bb4fedd09d0840ed98c9945bf292967fede8fcc6b26054b4058", 439 "a360b0566f68c329e2757918f67ee6421d3d76f70f1b452cdd32266805986119", 440 "17e85bd33cc5fb5035e489c5188979f45e75e92d14221eca937e14f5f7d7b074", 441 "3973eb930fd2d0726abbd81912eae645384268cd3500b9ec84d806fdd65a426a", 442 "b91cc1c98e5c77e80eec9bf93e86af27f810b00dfbce3ee2646758797a28d5f2", 443 "1a8c7bd3389dcbbc1133ee600898ed9e082f7a9c75f9eb52f33940ed7c2247ef", 444 "9b1782449bbd3fc3014c363167777f7bdf41f5ef6db192fbda784b29603911b0", 445 "afab4bcdc1a32891d638579c3029ae49ee72be3303425c6d62e1f8eaebe0ce18", 446 "5f839f9cd5293c02ff4f7cf5589c53dec52adb42a077599dc7a2c5842a156ca9", 447 "756d2dfd1d2872ba2531fae3b8984008506871bec41d19cb299f5e0f216cfb9b", 448 "6aa82514ab7a9cc624fabf3d06ccbd46ecb4009b3c784768e6243d7840d4bf93", 449 "d1430b3f7ecf147534796c39ba631ea22ac03530e25b9428367c0dc381b10863", 450 "2aeb69b1eb9eef8039da6b97d7851e46f57325851e6998ef5a84fc9a826c2c74", 451 "fc61d13eef806af8da693cfa621fe92110694f1514567b186a35c54e7ef4a188", 452 "a02dd44e60ba62fa00c83a67116f8079bf71062939b207bee0808cb98b30cf22", 453 "279f97cfc606fe62777b44614ff28675ce661687904e068e3ec79f619c4fdae7", 454 "d515d271849717b091a9c46bf11c47efb9d975e72b668c137786a208cf0a9739", 455 "a800da44e6eed944043561fe22ee0a6e11341e6bc1a8ec2789b83930cc9b170e", 456 }, 457 }, 458 } 459 460 func helperLoadBlock(t *testing.T, height int) []byte { 461 name := fmt.Sprintf("block_dump.%d", height) 462 path := filepath.Join("testdata", name) 463 464 d, err := ioutil.ReadFile(path) 465 if err != nil { 466 t.Fatal(err) 467 } 468 469 d = bytes.TrimSpace(d) 470 471 b := make([]byte, hex.DecodedLen(len(d))) 472 _, err = hex.Decode(b, d) 473 if err != nil { 474 t.Fatal(err) 475 } 476 477 return b 478 } 479 480 func TestParseBlock(t *testing.T) { 481 p := NewDogecoinParser(GetChainParams("main"), &btc.Configuration{}) 482 483 for height, tb := range testParseBlockTxs { 484 b := helperLoadBlock(t, height) 485 486 blk, err := p.ParseBlock(b) 487 if err != nil { 488 t.Fatal(err) 489 } 490 491 if blk.Size != tb.size { 492 t.Errorf("ParseBlock() block size: got %d, want %d", blk.Size, tb.size) 493 } 494 495 if blk.Time != tb.time { 496 t.Errorf("ParseBlock() block time: got %d, want %d", blk.Time, tb.time) 497 } 498 499 if len(blk.Txs) != len(tb.txs) { 500 t.Errorf("ParseBlock() number of transactions: got %d, want %d", len(blk.Txs), len(tb.txs)) 501 } 502 503 for ti, tx := range tb.txs { 504 if blk.Txs[ti].Txid != tx { 505 t.Errorf("ParseBlock() transaction %d: got %s, want %s", ti, blk.Txs[ti].Txid, tx) 506 } 507 } 508 } 509 }