test: add boundary check for implicit response method (#548)

Test the boundary of STRATUM_RESULT and STRATUM_RESULT_SETUP more completely
This commit is contained in:
tdb3 2025-01-04 17:57:27 -05:00 committed by GitHub
parent 5e56bcdccc
commit 3bf8997a72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -117,10 +117,17 @@ TEST_CASE("Parse stratum mining.set_version_mask params", "[stratum]")
TEST_CASE("Parse stratum result success", "[stratum]")
{
StratumApiV1Message stratum_api_v1_setup_message = {};
const char* resp1 = "{\"id\":4,\"error\":null,\"result\":true}";
STRATUM_V1_parse(&stratum_api_v1_setup_message, resp1);
TEST_ASSERT_EQUAL(4, stratum_api_v1_setup_message.message_id);
TEST_ASSERT_EQUAL(STRATUM_RESULT_SETUP, stratum_api_v1_setup_message.method);
TEST_ASSERT_TRUE(stratum_api_v1_setup_message.response_success);
StratumApiV1Message stratum_api_v1_message = {};
const char *json_string = "{\"id\":1,\"error\":null,\"result\":true}";
const char* json_string = "{\"id\":5,\"error\":null,\"result\":true}";
STRATUM_V1_parse(&stratum_api_v1_message, json_string);
TEST_ASSERT_EQUAL(1, stratum_api_v1_message.message_id);
TEST_ASSERT_EQUAL(5, 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);
}
@ -147,13 +154,21 @@ TEST_CASE("Parse stratum result success with larger id", "[stratum]")
TEST_CASE("Parse stratum result error", "[stratum]")
{
StratumApiV1Message stratum_api_v1_setup_message = {};
const char* resp1 = "{\"id\":4,\"result\":null,\"error\":[21,\"Job not found\",\"\"]}";
STRATUM_V1_parse(&stratum_api_v1_setup_message, resp1);
TEST_ASSERT_EQUAL(4, stratum_api_v1_setup_message.message_id);
TEST_ASSERT_EQUAL(STRATUM_RESULT_SETUP, stratum_api_v1_setup_message.method);
TEST_ASSERT_FALSE(stratum_api_v1_setup_message.response_success);
TEST_ASSERT_EQUAL_STRING("Job not found", stratum_api_v1_setup_message.error_str);
StratumApiV1Message stratum_api_v1_message = {};
const char *json_string = "{\"id\":1,\"result\":null,\"error\":[21,\"Job not found\",\"\"]}";
const char* json_string = "{\"id\":5,\"result\":null,\"error\":[21,\"Job not found\",\"\"]}";
STRATUM_V1_parse(&stratum_api_v1_message, json_string);
TEST_ASSERT_EQUAL(1, stratum_api_v1_message.message_id);
TEST_ASSERT_EQUAL(5, stratum_api_v1_message.message_id);
TEST_ASSERT_EQUAL(STRATUM_RESULT, stratum_api_v1_message.method);
TEST_ASSERT_FALSE(stratum_api_v1_message.response_success);
TEST_ASSERT_EQUAL("Job not found", stratum_api_v1_message.error_str);
TEST_ASSERT_EQUAL_STRING("Job not found", stratum_api_v1_message.error_str);
}
TEST_CASE("Parse stratum result alternative error", "[stratum]")