Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MoellerDi committed Apr 15, 2024
1 parent 28ebc8e commit 324fa22
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion components/stratum/test/test_stratum_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// }
// }

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);
}

0 comments on commit 324fa22

Please sign in to comment.