-
Notifications
You must be signed in to change notification settings - Fork 28
Feature add state api #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Add /nodestate API
add test for nodestate APIs
refactor: simplify node_state control flow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Requested some small changes. Please also squash into a single signed commit saying add /nodestate API
and then rebase on top of the updated master.
Finally check lint and format with the latest stable rust
@@ -1676,6 +1690,7 @@ mod issue; | |||
mod lock_unlock_changepassword; | |||
mod multi_hop; | |||
mod multi_open_close; | |||
mod node_state_test; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mod node_state_test; | |
mod node_state; |
|
||
use super::*; | ||
|
||
const TEST_DIR_BASE: &str = "tmp/node_state_test/"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const TEST_DIR_BASE: &str = "tmp/node_state_test/"; | |
const TEST_DIR_BASE: &str = "tmp/node_state/"; |
@@ -791,6 +791,19 @@ pub(crate) struct NodeInfoResponse { | |||
pub(crate) network_channels: usize, | |||
} | |||
|
|||
#[derive(Deserialize, Serialize)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[derive(Deserialize, Serialize)] | |
#[derive(Debug, PartialEq, Deserialize, Serialize)] |
@@ -791,6 +791,19 @@ pub(crate) struct NodeInfoResponse { | |||
pub(crate) network_channels: usize, | |||
} | |||
|
|||
#[derive(Deserialize, Serialize)] | |||
pub(crate) enum NodeState { | |||
None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None, | |
Uninitialized, |
please rename also in openapi
description: | | ||
The current state of the RGB Lightning Node: | ||
* `None` - Node is not initialized (no mnemonic file exists) | ||
* `Locked` - Node is initialized but locked (needs to be unlocked) | ||
* `Running` - Node is unlocked and running (can perform all operations) | ||
* `Changing` - Node is in the process of changing state (wait for completion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description: | | |
The current state of the RGB Lightning Node: | |
* `None` - Node is not initialized (no mnemonic file exists) | |
* `Locked` - Node is initialized but locked (needs to be unlocked) | |
* `Running` - Node is unlocked and running (can perform all operations) | |
* `Changing` - Node is in the process of changing state (wait for completion) |
names seem sufficiently descriptive
|
||
let node1_addr = start_daemon(&test_dir_node1, NODE1_PEER_PORT).await; | ||
let state_response = node_state(node1_addr).await; | ||
assert!(matches!(state_response.state, NodeState::None)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use assert_eq!
(here and in the rest of this test) since in case of failure it shows also the actual value that is not matching.
unlock(node1_addr, &password).await; | ||
let state_response = node_state(node1_addr).await; | ||
assert!(matches!(state_response.state, NodeState::Running)); | ||
|
||
let node_info_response = node_info(node1_addr).await; | ||
assert!(!node_info_response.pubkey.is_empty()); | ||
assert_eq!(node_info_response.num_channels, 0); | ||
assert_eq!(node_info_response.num_peers, 0); | ||
|
||
println!("Node state test completed successfully"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unlock(node1_addr, &password).await; | |
let state_response = node_state(node1_addr).await; | |
assert!(matches!(state_response.state, NodeState::Running)); | |
let node_info_response = node_info(node1_addr).await; | |
assert!(!node_info_response.pubkey.is_empty()); | |
assert_eq!(node_info_response.num_channels, 0); | |
assert_eq!(node_info_response.num_peers, 0); | |
println!("Node state test completed successfully"); | |
let handle = tokio::task::spawn(async move { | |
unlock(node1_addr, &password).await; | |
}); | |
let state_response = node_state(node1_addr).await; | |
assert_eq!(state_response.state, NodeState::Changing); | |
let _ = handle.await; | |
let state_response = node_state(node1_addr).await; | |
assert_eq!(state_response.state, NodeState::Running); |
Adding a state API can help users better understand the status of the node.