stratum: add additional test for test_nonce_value

This commit is contained in:
johnny9 2023-05-26 15:37:29 -04:00
parent b9858777b0
commit d583332f3b
2 changed files with 38 additions and 4 deletions

View File

@ -102,15 +102,13 @@ double test_nonce_value(bm_job * job, uint32_t nonce) {
double d64, s64, ds;
unsigned char header[80];
uint8_t flipped_prev_block_hash[32];
uint8_t flipped_merkle_root[32];
flip32bytes(flipped_prev_block_hash, job->prev_block_hash);
flip32bytes(flipped_merkle_root, job->merkle_root);
//copy data from job to header
memcpy(header, &job->version, 4);
memcpy(header + 4, flipped_prev_block_hash, 32);
memcpy(header + 36, flipped_merkle_root, 32);
memcpy(header + 36, job->merkle_root, 32);
memcpy(header + 68, &job->ntime, 4);
memcpy(header + 72, &job->target, 4);
memcpy(header + 76, &nonce, 4);

View File

@ -105,10 +105,46 @@ TEST_CASE("Test nonce diff checking", "[mining test_nonce]")
notify_message.version = 0x20000004;
notify_message.target = 0x1705ae3a;
notify_message.ntime = 0x646ff1a9;
const char * merkle_root = "C459036D054643519C5A2AC50B3474E0632C7CE4F93107843FDBF1EDD9CDB126646FF1A9";
const char * merkle_root = "6d0359c451434605c52a5a9ce074340be47c2c63840731f9edf1db3f26b1cdd9a9f16f64";
bm_job job = construct_bm_job(&notify_message, merkle_root);
uint32_t nonce = 0x276E8947;
double diff = test_nonce_value(&job, nonce);
TEST_ASSERT_EQUAL_INT(18, (int) diff);
}
TEST_CASE("Test nonce diff checking 2", "[mining test_nonce]")
{
mining_notify notify_message;
notify_message.prev_block_hash = "0c859545a3498373a57452fac22eb7113df2a465000543520000000000000000";
notify_message.version = 0x20000004;
notify_message.target = 0x1705ae3a;
notify_message.ntime = 0x647025b5;
const char * coinbase_tx = "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4b0389130cfabe6d6d5cbab26a2599e92916edec5657a94a0708ddb970f5c45b5d12905085617eff8e010000000000000031650707758de07b010000000000001cfd7038212f736c7573682f000000000379ad0c2a000000001976a9147c154ed1dc59609e3d26abb2df2ea3d587cd8c4188ac00000000000000002c6a4c2952534b424c4f434b3ae725d3994b811572c1f345deb98b56b465ef8e153ecbbd27fa37bf1b005161380000000000000000266a24aa21a9ed63b06a7946b190a3fda1d76165b25c9b883bcc6621b040773050ee2a1bb18f1800000000";
uint8_t merkles[13][32];
int num_merkles = 13;
hex2bin("2b77d9e413e8121cd7a17ff46029591051d0922bd90b2b2a38811af1cb57a2b2", merkles[0], 32);
hex2bin("5c8874cef00f3a233939516950e160949ef327891c9090467cead995441d22c5", merkles[1], 32);
hex2bin("2d91ff8e19ac5fa69a40081f26c5852d366d608b04d2efe0d5b65d111d0d8074", merkles[2], 32);
hex2bin("0ae96f609ad2264112a0b2dfb65624bedbcea3b036a59c0173394bba3a74e887", merkles[3], 32);
hex2bin("e62172e63973d69574a82828aeb5711fc5ff97946db10fc7ec32830b24df7bde", merkles[4], 32);
hex2bin("adb49456453aab49549a9eb46bb26787fb538e0a5f656992275194c04651ec97", merkles[5], 32);
hex2bin("a7bc56d04d2672a8683892d6c8d376c73d250a4871fdf6f57019bcc737d6d2c2", merkles[6], 32);
hex2bin("d94eceb8182b4f418cd071e93ec2a8993a0898d4c93bc33d9302f60dbbd0ed10", merkles[7], 32);
hex2bin("5ad7788b8c66f8f50d332b88a80077ce10e54281ca472b4ed9bbbbcb6cf99083", merkles[8], 32);
hex2bin("9f9d784b33df1b3ed3edb4211afc0dc1909af9758c6f8267e469f5148ed04809", merkles[9], 32);
hex2bin("48fd17affa76b23e6fb2257df30374da839d6cb264656a82e34b350722b05123", merkles[10], 32);
hex2bin("c4f5ab01913fc186d550c1a28f3f3e9ffaca2016b961a6a751f8cca0089df924", merkles[11], 32);
hex2bin("cff737e1d00176dd6bbfa73071adbb370f227cfb5fba186562e4060fcec877e1", merkles[12], 32);
char * merkle_root = calculate_merkle_root_hash(coinbase_tx, merkles, num_merkles);
TEST_ASSERT_EQUAL_STRING("5bdc1968499c3393873edf8e07a1c3a50a97fc3a9d1a376bbf77087dd63778eb", merkle_root);
bm_job job = construct_bm_job(&notify_message, merkle_root);
uint32_t nonce = 0x0a029ed1;
double diff = test_nonce_value(&job, nonce);
TEST_ASSERT_EQUAL_INT(683, (int) diff);
}