From f9250a6b2e7078297afcb77d48f5f25b5ea75c56 Mon Sep 17 00:00:00 2001 From: SwimmingTiger Date: Tue, 15 Jan 2019 14:26:27 +0800 Subject: [PATCH] add a testcase for StratumServerBitcoin::checkShare() --- test/TestStratumServer.cc | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/TestStratumServer.cc b/test/TestStratumServer.cc index 1ba76305d..a21a6a976 100644 --- a/test/TestStratumServer.cc +++ b/test/TestStratumServer.cc @@ -27,6 +27,9 @@ #include "Utils.h" #include "StratumServer.h" +#include "bitcoin/BitcoinUtils.h" +#include "bitcoin/StratumBitcoin.h" +#include "bitcoin/StratumServerBitcoin.h" // #include "Kafka.h" @@ -180,3 +183,44 @@ TEST(StratumServer, SessionIDManager8Bits) { } #endif // #ifndef WORK_WITH_STRATUM_SWITCHER + +TEST(StratumServerBitcoin, CheckShare) { + string sjobJson = "{\"jobId\":6645522065066147329,\"gbtHash\":\"d349be274f007c2e1ee773b33bd21ef43d2615c089b7c5460b66584881a10683\"," + "\"prevHash\":\"00000000000000000019d1d9c84df0ecc23e549b86644ad47cb92570a26b12a5\",\"prevHashBeStr\":\"a26b12a57cb9257086644ad4c23e" + "549bc84df0ec0019d1d90000000000000000\",\"height\":558201,\"coinbase1\":\"020000000100000000000000000000000000000000000000000000000" + "00000000000000000ffffffff4b03798408041ba3395c612f4254432e434f4d2ffabe6d6dc807e51bd76025d65ccad2ba8ba1e9fba5f09118b6b55a348638cc17b" + "14e3909080000005fb54ad0\",\"coinbase2\":\"ffffffff036734ec4a0000000016001497cfc76442fe717f2a3f0cc9c175f7561b6619970000000000000000" + "266a24aa21a9ed40cbdaa98da815640f815b938df95bffe0775d8078771bc47ed4f43ac4e30b0600000000000000002952534b424c4f434b3a9ad45fdcc194d788" + "895f3ad389b583ea327f826353f7edf6b168db038372cb2700000000\",\"merkleBranch\":\"53146311555e15816f4549a893ff2eb50e60741ecccb2996bafd" + "dcf4ee008d5ac504967e375b2522af2be8411b1b032dda0e700c2e8913d869533256ff30caccea4ba404b68e625cfd3237e07e8deddb342690b08314d2638b5272" + "b74ab12fa3b3812908cd6bef999dea979875ba2730615be08b480e4b6f7b878000510a778c557f44bc3f21813d138d25530df85a89a38e2d2827f758ebc68a62e8" + "225933a5af086e72d9a65fd9be526648e8bcf74271308d9d273425b47bd12db075e841ba703f4c8a20be62d036958278b16f214d7fcd35c46a9f9fb1910618fa9e" + "029d3f96518aae34efbdabfbfbc055bffe891d93edbc7539ae9c0a22a35e87d5ccb033b89976cbb624af024b53c6a02309cb838eb285ecf675b801f1dd7f2d5c92" + "4cb1491731c28bea800b12b94bb4f70502a40559c8edb5f73b906ba8e814f10e852ef87365a49346c4b7361b75e38f1d9b96f028880227b7186a0b114e170b170b" + "47\",\"nVersion\":536870912,\"nBits\":389159077,\"nTime\":1547281171,\"minTime\":1547277926,\"coinbaseValue\":1256993895,\"witness" + "Commitment\":\"6a24aa21a9ed40cbdaa98da815640f815b938df95bffe0775d8078771bc47ed4f43ac4e30b06\",\"nmcBlockHash\":\"c807e51bd76025d65" + "ccad2ba8ba1e9fba5f09118b6b55a348638cc17b14e3909\",\"nmcBits\":402868319,\"nmcHeight\":433937,\"nmcRpcAddr\":\"http://127.0.0.1:899" + "9\",\"nmcRpcUserpass\":\"user:pass\",\"rskBlockHashForMergedMining\":\"0x9ad45fdcc194d788895f3ad389b583ea327f826353f7edf6b168db038" + "372cb27\",\"rskNetworkTarget\":\"0x00000000000000001386e3444eba74f8a750a71a75ed0b7fecdfd282a8cef091\",\"rskFeesForMiner\":\"0\",\"" + "rskdRpcAddress\":\"http://127.0.0.1:4444\",\"rskdRpcUserPwd\":\"user:pass\",\"isRskCleanJob\":true}"; + + StratumJobBitcoin *sjob = new StratumJobBitcoin(); + sjob->unserializeFromJson(sjobJson.c_str(), sjobJson.size()); + + StratumJobExBitcoin exjob(sjob, true); + + CBlockHeader header; + std::vector coinbaseBin; + + exjob.generateBlockHeader( + &header, &coinbaseBin, + 0xfe0000c3u, "260103fe60004690", + sjob->merkleBranch_, sjob->prevHash_, + sjob->nBits_, sjob->nVersion_, + 0x5c39a313u, 0x07ba7929u, + 0x00013f00u + ); + + uint256 blkHash = uint256S("1028e53e8145994a9ebe4f39eb6a7e3fd4036f2f21a05a5a696e8ac6d0829ef4"); + ASSERT_EQ(blkHash, header.GetHash()); +}