Merge pull request #243 from mutatrum/master

Change stratum message_id to int64_t
This commit is contained in:
WantClue 2024-06-26 08:02:38 +02:00 committed by GitHub
commit 220c220017
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 2 deletions

View File

@ -45,7 +45,7 @@ typedef struct
char * extranonce_str;
int extranonce_2_len;
int16_t message_id;
int64_t message_id;
// Indicates the type of request the message represents.
stratum_method method;

View File

@ -111,7 +111,7 @@ void STRATUM_V1_parse(StratumApiV1Message * message, const char * stratum_json)
cJSON * json = cJSON_Parse(stratum_json);
cJSON * id_json = cJSON_GetObjectItem(json, "id");
int16_t parsed_id = -1;
int64_t parsed_id = -1;
if (id_json != NULL && cJSON_IsNumber(id_json)) {
parsed_id = id_json->valueint;
}

View File

@ -125,6 +125,26 @@ TEST_CASE("Parse stratum result success", "[stratum]")
TEST_ASSERT_TRUE(stratum_api_v1_message.response_success);
}
TEST_CASE("Parse stratum result success with large id", "[stratum]")
{
StratumApiV1Message stratum_api_v1_message = {};
const char *json_string = "{\"id\":32769,\"error\":null,\"result\":true}";
STRATUM_V1_parse(&stratum_api_v1_message, json_string);
TEST_ASSERT_EQUAL(32768, stratum_api_v1_message.message_id);
TEST_ASSERT_EQUAL(STRATUM_RESULT, stratum_api_v1_message.method);
TEST_ASSERT_TRUE(stratum_api_v1_message.response_success);
}
TEST_CASE("Parse stratum result success with larger id", "[stratum]")
{
StratumApiV1Message stratum_api_v1_message = {};
const char *json_string = "{\"id\":65536,\"error\":null,\"result\":true}";
STRATUM_V1_parse(&stratum_api_v1_message, json_string);
TEST_ASSERT_EQUAL(65536, stratum_api_v1_message.message_id);
TEST_ASSERT_EQUAL(STRATUM_RESULT, stratum_api_v1_message.method);
TEST_ASSERT_TRUE(stratum_api_v1_message.response_success);
}
TEST_CASE("Parse stratum result error", "[stratum]")
{
StratumApiV1Message stratum_api_v1_message = {};