Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/floresta-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ mod tests {
let (mut _proc, client) = start_florestad();

let stop = client.stop().expect("rpc not working");
assert_eq!(stop.as_str(), "florestad stopping");
assert_eq!(stop.as_str(), "Floresta stopping");
}

#[test]
Expand Down
5 changes: 4 additions & 1 deletion crates/floresta-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ pub enum Methods {
#[command(name = "gettxout")]
GetTxOut { txid: Txid, vout: u32 },

/// Stops the node
/// Request a graceful shutdown of Floresta.
///
/// Result:
/// "str" (string) A string with the content 'Floresta stopping'
#[command(name = "stop")]
Stop,

Expand Down
2 changes: 1 addition & 1 deletion florestad/src/json_rpc/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<Blockchain: RpcChain> RpcImpl<Blockchain> {
pub(super) async fn stop(&self) -> Result<&str, Error> {
*self.kill_signal.write().await = true;

Ok("florestad stopping")
Ok("Floresta stopping")
}

// uptime
Expand Down
44 changes: 29 additions & 15 deletions tests/floresta-cli/stop-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,59 @@
This functional test cli utility to interact with a Floresta node with `stop`
"""

import re
from test_framework import FlorestaTestFramework
from test_framework.rpc.floresta import REGTEST_RPC_SERVER
from test_framework.rpc.floresta import REGTEST_RPC_SERVER as florestad_rpc
from test_framework.rpc.bitcoin import REGTEST_RPC_SERVER as bitcoin_rpc


class StopTest(FlorestaTestFramework):
"""
Test `stop` command with a fresh node and its initial state.
"""

nodes = [-1]
nodes = [-1, -1]

def set_test_params(self):
"""
Setup a single node
"""
StopTest.nodes[0] = self.add_node(extra_args=[], rpcserver=REGTEST_RPC_SERVER)
StopTest.nodes[0] = self.add_node(
variant="florestad", extra_args=[], rpcserver=florestad_rpc
)
StopTest.nodes[1] = self.add_node(
variant="bitcoind", extra_args=[], rpcserver=bitcoin_rpc
)

def run_test(self):
"""
Run JSONRPC server and get some data about blockchain with only regtest genesis block
Run JSONRPC stop command on both flrestad and bitcoin core nodes and
check if floresta and bitcoin core nodes are stopped correctly and if
the floresta's stop message is compliant with bitcoin core's stop message.
"""
# Start node and wait for it to be ready
# This is important to ensure that the node
# is fully initialized before we attempt to stop it.
# This is already made in the `run_node` method
# but let's wait a bit more to be sure
self.run_node(StopTest.nodes[0])
node = self.get_node(StopTest.nodes[0])
node.rpc.wait_for_connections(opened=True)
self.run_node(StopTest.nodes[1])

floresta = self.get_node(StopTest.nodes[0])
bitcoin = self.get_node(StopTest.nodes[1])

# Generally, the self.stop_node() method
# do all the work for us, but in this case
# we're testing the method rpc.stop(), so
# re-do all the steps to ensure that it
# was successful and the ports are closed
result = node.rpc.stop()
self.assertEqual(result, "florestad stopping")
node.rpc.wait_for_connections(opened=False)
node.daemon.process.wait()
result_floresta = floresta.rpc.stop()
result_bitcoin = bitcoin.rpc.stop()

# Check if the messages are correct
for res in [result_floresta, result_bitcoin]:
self.assertIsSome(res)
self.assertIn("stopping", res)
self.assertMatch(res, re.compile(r"^(Floresta|Bitcoin Core) stopping$"))

# Check that the node is stopped
floresta.rpc.wait_for_connections(opened=False)
bitcoin.rpc.wait_for_connections(opened=False)


if __name__ == "__main__":
Expand Down
Loading