From bfd7b69a7ed81318582f66107ba5a645e9ee2130 Mon Sep 17 00:00:00 2001 From: Nikolay Bryskin Date: Wed, 24 Apr 2024 22:45:31 +0300 Subject: [PATCH] chore(v1): add tests for mining.subscribe --- protocols/v1/src/methods/client_to_server.rs | 33 ++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/protocols/v1/src/methods/client_to_server.rs b/protocols/v1/src/methods/client_to_server.rs index ee5f11e849..78f1ed3c51 100644 --- a/protocols/v1/src/methods/client_to_server.rs +++ b/protocols/v1/src/methods/client_to_server.rs @@ -714,3 +714,36 @@ fn test_version_extension_with_no_bit_count() { _ => panic!(), }; } + +#[test] +fn test_mining_subscribe_even_sized_extranonce() { + let client_message = r#"{"id":0, + "method": "mining.subscribe", + "params": ["user agent/version", "aaeeffdd"] + }"#; + let client_message: StandardRequest = serde_json::from_str(&client_message).unwrap(); + Subscribe::try_from(client_message).unwrap(); +} + +#[test] +fn test_mining_subscribe_odd_sized_extranonce() { + let client_message = r#"{"id":0, + "method": "mining.subscribe", + "params": ["user agent/version", "aeeffdd"] + }"#; + let client_message: StandardRequest = serde_json::from_str(&client_message).unwrap(); + Subscribe::try_from(client_message).unwrap(); +} + +#[test] +#[should_panic( + expected = "called `Result::unwrap()` on an `Err` value: HexError(InvalidHexCharacter { c: 'z', index: 0 })" +)] +fn test_mining_subscribe_invalid_extranonce() { + let client_message = r#"{"id":0, + "method": "mining.subscribe", + "params": ["user agent/version", "zxczxc"] + }"#; + let client_message: StandardRequest = serde_json::from_str(&client_message).unwrap(); + Subscribe::try_from(client_message).unwrap(); +}