From 324fa2284f0d678f6a1e7b968d3daa7c8820d649 Mon Sep 17 00:00:00 2001 From: Dirk Moeller Date: Mon, 15 Apr 2024 15:23:18 +0000 Subject: [PATCH] add unit tests --- components/stratum/test/test_stratum_json.c | 32 ++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/components/stratum/test/test_stratum_json.c b/components/stratum/test/test_stratum_json.c index 909a64e59..49c4b3dc4 100644 --- a/components/stratum/test/test_stratum_json.c +++ b/components/stratum/test/test_stratum_json.c @@ -103,4 +103,34 @@ TEST_CASE("Parse stratum notify params", "[mining.notify]") // TEST_ASSERT_EQUAL(result, 0); // TEST_ASSERT_EQUAL_STRING(extranonce, "e9695791"); // TEST_ASSERT_EQUAL_INT(extranonce2_len, 4); -// } \ No newline at end of file +// } + +TEST_CASE("Parse stratum mining.set_version_mask params", "[stratum]") +{ + StratumApiV1Message stratum_api_v1_message = {}; + const char *json_string = "{\"id\":1,\"method\":\"mining.set_version_mask\",\"params\":[\"1fffe000\"]}"; + STRATUM_V1_parse(&stratum_api_v1_message, json_string); + TEST_ASSERT_EQUAL(1, stratum_api_v1_message.message_id); + TEST_ASSERT_EQUAL(MINING_SET_VERSION_MASK, stratum_api_v1_message.method); + TEST_ASSERT_EQUAL_HEX32(0x1fffe000, stratum_api_v1_message.version_mask); +} + +TEST_CASE("Parse stratum result success", "[stratum]") +{ + StratumApiV1Message stratum_api_v1_message = {}; + const char *json_string = "{\"id\":1,\"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(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 = {}; + const char *json_string = "{\"id\":1,\"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(STRATUM_RESULT, stratum_api_v1_message.method); + TEST_ASSERT_FALSE(stratum_api_v1_message.response_success); +} \ No newline at end of file