github.com/bchainhub/blockbook@v0.3.2/bchain/coins/btg/bgoldparser_test.go (about) 1 // +build unittest 2 3 package btg 4 5 import ( 6 "blockbook/bchain/coins/btc" 7 "bytes" 8 "encoding/hex" 9 "fmt" 10 "io/ioutil" 11 "os" 12 "path/filepath" 13 "testing" 14 15 "github.com/martinboehm/btcutil/chaincfg" 16 ) 17 18 func TestMain(m *testing.M) { 19 c := m.Run() 20 chaincfg.ResetParams() 21 os.Exit(c) 22 } 23 24 type testBlock struct { 25 size int 26 time int64 27 txs []string 28 } 29 30 var testParseBlockTxs = map[int]testBlock{ 31 104000: { 32 size: 15776, 33 time: 1295705889, 34 txs: []string{ 35 "331d4ef64118e9e5be75f0f51f1a4c5057550c3320e22ff7206f3e1101f113d0", 36 "1f4817d8e91c21d8c8d163dabccdd1875f760fd2dc34a1c2b7b8fa204e103597", 37 "268163b1a1092aa0996d118a6027b0b6f1076627e02addc4e66ae30239936818", 38 "27277a1049fafa2a46368ad02961d37da633416b014bcd42a1f1391753cbf559", 39 "276d2d331585d0968762d9788f71ae71524ccba3494f638b2328ac51e52edd3d", 40 "28d9f85089834c20507cc5e4ec54aaaf5b79feab80cad24a48b8296b6d327a43", 41 "2a2d66d3d9e8b6f154958a388377f681abd82ce98785a5bbf2e27d0ca454da3f", 42 "39c9e995a12b638b541d21ed9f9e555716709add6a97c8ba63fe26e4d26bdc3f", 43 "4a768efc6cc0716932800115989376c2ce3e5e17668b08bd2f43031105a6ac6e", 44 "4bc41fa0188d988d853a176eb847a541c5adf35348eab21d128904aab36e8574", 45 "4cad1bd38cc7be880f3a968af6f13a3aeb5dbdb51a774b7d1ae3d6d6bfd114e4", 46 "6bc558801583bfdb656106889c4b8bd783168133784666338c57e5b2a675a922", 47 "75eb5c1aa89b18ce71f363f95147942b46645ca9b1e472784fcb8c9a096f4f5c", 48 "91755365cff22c4eed09a57a8fb7b2faa5c1caa5fa750c89f830a2bb56fa4c68", 49 "9417d34969891f2a0b9aa3a1226505edf3b429fa1acd21a140d358a217d11d55", 50 "950fbb5f413af9f7c6e5dabfacf68b715c9851b5cf6ab6806960f7cc7cad2f9d", 51 "99b134dae55ddfab1f5d5243c2e60030a9ed969ba5915f98840b877f8af28ce0", 52 "9d7b15eaaccce66e25efe7e2979454ae4968b61281d50f32be9872d2d256c244", 53 "a54df5296f1d1a6101cee0869ffda03502e417fc72475b7902a6dfd5b9329399", 54 "adba400f14b476f0c2b11340ee1fa440208b49fd99c1072136198b5c43664826", 55 "bd7d8fee068bd45b06b4c17ccdf577b4bc2b21c9c4e0cee8453409b0e63b4f5d", 56 "beabd2d68b66a9b47b6aff23b569c1b59e429074f06bdd4993e9d3c2cb69c992", 57 "bfa81174d549eb7ed15be3f965686aff3084f22523c52fbed03c3fc3e18b7cda", 58 "e42472099cb039b1c2248b611ce212580338550977e02bd77accdf29bfd86e96", 59 "f056e02b12d99377f724a4987cde68ecf6f234fd7e2bdf4324172c03d015ba25", 60 "f1815cfb1ef4cfe13ff5ec2c15b5bc55fde043db85daca1bb34cc1b491193308", 61 "f225abce64f75383686fa08abe47242e59e97809a31c8fd7a88acce1e6cbcd27", 62 "f93f1b125bfa2da5ccaaf30ff96635b905b657d48a5962c24be93884a82ef354", 63 "fef75d015f2e9926d1d4bf82e567b91e51af66a6e636d03a072f203dd3062ae5", 64 "051b60a6accead85da54b8d18f4b2360ea946da948d3a27836306d2927fed13e", 65 "28e47b050ec4064cdbd3364f3be9445d52635e9730691ef71ed1db0f0147afd6", 66 "446ebde2457102bcbc2c86cac6ff582c595b00346fd0b27ea5a645240020504b", 67 "46c8fafe2b7bb1646aeefa229b18fa7ffe20fee0a30c4a9ef3e63c36c808f6f7", 68 "550d96cf82fbe91dcc9b96e7aa404f392ee47400c22a98a7631d29eee43fceaa", 69 "59b6b78a72cc33cd29741894b3007b1330fc7f7945bdc0a7a4044ed1dd289c19", 70 "5a3aa07474338cf193c1d7aacdc37f3311c971857ba8cfd308e8fabf5e473882", 71 "82e014b1a9c6cb7729274653ce748c66953de6abb3d1411471515b41b727cf75", 72 "8d70af4f135696da396c9aa9f936b54195bfbe6ff0e08b3b210ca0b52bc167d2", 73 "9949c2f2f3b96a557ef6e14004cbd239a0744c056faca34bdff01e125b4380e8", 74 "d09a8c83123ce1cb6ff837e7670aab5f50c5155d9706dd26f7e0761fd20c5536", 75 "f601482efc5b2dd3d0031e318e840cd06f7cab0ffff8cc37a5bf471b515ddfb7", 76 "f88d3c0ebe8b294f11e70d2ae6d2f0048437bfb20dae7e69d545a4c72d3432dd", 77 "2b9e574b90556250b20a79d9c94ceaff3dfd062291c34c3fa79c7ca8d85a3500", 78 "b9484ef8e38ceafe8d2b09ecf59562d262b15d185844b2d00db362718d52b2c2", 79 "07a4af0a81b55313a1c16da7d808829d689436fd078fa9559b6d1603dd72474e", 80 "3393bdcc3a7232b37d0fb6b56d603a2b9b0419e461bf989f1c375859a5d0156a", 81 "33ad36d79d63b575c7532c516f16b19541f5c637caf7073beb7ddf604c3f39cc", 82 }, 83 }, 84 532144: { 85 size: 12198, 86 time: 1528372417, 87 txs: []string{ 88 "574348e23301cc89535408b6927bf75f2ac88fadf8fdfb181c17941a5de02fe0", 89 "9f048446401e7fac84963964df045b1f3992eda330a87b02871e422ff0a3fd28", 90 "9516c320745a227edb07c98087b1febea01c3ba85122a34387896fc82ba965e4", 91 "9d37e1ab5a28c49ce5e7ece4a2b9df740fb4c3a84bdec93b3023148cf20f0de7", 92 "a3cd0481b983ba402fed8805ef9daf5063d6d4e5085b82eca5b4781c9e362d6a", 93 "7f2c2567e8de0321744817cfeb751922d7e8d82ef71aa01164c84fb74a463a53", 94 "cd064315e3f5d07920b3d159160c218d0bb5b7b4be606265767b208ae7e256eb", 95 "a9523400f341aa425b0fcc00656ec1fa5421bf3545433bff98a8614fc9a99d1f", 96 "ec766daacbb05a8f48a3205e5c6494a7c817bd35eefff9aaf55e0dd47fe6e8fc", 97 "0837a4116872abf52caa52d1ff7608674ba5b09a239a1f43f3a25ba4052e4c77", 98 "a3e23a0344fe6ba7083fc6afb940517cdb666dce00389cbd8598bd599199cdda", 99 "048d951cef84d35d68f0bc3b575662caf23fee692e8035bd5efe38ab67e0d6c2", 100 "11307491b24d42ddd7ea27fc795d444b65c3936be31b904a97da68fabc85e5b8", 101 "84ad99dc0884e03fc71f163eebf515a1eb79d00b1aad7a1126b22747960a8275", 102 "728c8d0858e506d4a1a9b506f7b974b335e6c54047af9f40d4cb1a0561f783e1", 103 }, 104 }, 105 } 106 107 func helperLoadBlock(t *testing.T, height int) []byte { 108 name := fmt.Sprintf("block_dump.%d", height) 109 path := filepath.Join("testdata", name) 110 111 d, err := ioutil.ReadFile(path) 112 if err != nil { 113 t.Fatal(err) 114 } 115 116 d = bytes.TrimSpace(d) 117 118 b := make([]byte, hex.DecodedLen(len(d))) 119 _, err = hex.Decode(b, d) 120 if err != nil { 121 t.Fatal(err) 122 } 123 124 return b 125 } 126 127 func TestParseBlock(t *testing.T) { 128 p := NewBGoldParser(GetChainParams("main"), &btc.Configuration{}) 129 130 for height, tb := range testParseBlockTxs { 131 b := helperLoadBlock(t, height) 132 133 blk, err := p.ParseBlock(b) 134 if err != nil { 135 t.Fatal(err) 136 } 137 138 if blk.Size != tb.size { 139 t.Errorf("ParseBlock() block size: got %d, want %d", blk.Size, tb.size) 140 } 141 142 if blk.Time != tb.time { 143 t.Errorf("ParseBlock() block time: got %d, want %d", blk.Time, tb.time) 144 } 145 146 if len(blk.Txs) != len(tb.txs) { 147 t.Errorf("ParseBlock() number of transactions: got %d, want %d", len(blk.Txs), len(tb.txs)) 148 } 149 150 for ti, tx := range tb.txs { 151 if blk.Txs[ti].Txid != tx { 152 t.Errorf("ParseBlock() transaction %d: got %s, want %s", ti, blk.Txs[ti].Txid, tx) 153 } 154 } 155 } 156 }