-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jsonrpc: functional tests for floresta-cli commands
* getmemoryinfo * getrpcinfo * uptime
- Loading branch information
Showing
5 changed files
with
272 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
""" | ||
floresta_cli_getmemoryinfo.py | ||
This functional test cli utility to interact with a Floresta node with `getmemoryinfo` | ||
""" | ||
|
||
import os | ||
import tempfile | ||
from test_framework.test_framework import FlorestaTestFramework | ||
from test_framework.floresta_rpc import REGTEST_RPC_SERVER | ||
|
||
|
||
class GetMemoryInfoTest(FlorestaTestFramework): | ||
""" | ||
Test `getmemoryinfo` rpc call, by creating a node and get | ||
some memory stats with `stats` and `mallocinfo` modes | ||
""" | ||
|
||
nodes = [-1] | ||
|
||
# pylint: disable=duplicate-code | ||
data_dir = os.path.normpath( | ||
os.path.join( | ||
tempfile.gettempdir(), | ||
"floresta-func-tests", | ||
"florestacli-getmemoryinfo-test", | ||
"node-0", | ||
) | ||
) | ||
|
||
def set_test_params(self): | ||
""" | ||
Setup the two node florestad process with different data-dirs, electrum-addresses | ||
and rpc-addresses in the same regtest network | ||
""" | ||
GetMemoryInfoTest.nodes[0] = self.add_node_settings( | ||
chain="regtest", | ||
extra_args=[ | ||
f"--data-dir={GetMemoryInfoTest.data_dir}", | ||
], | ||
rpcserver=REGTEST_RPC_SERVER, | ||
) | ||
|
||
def test_mode_stats_ibd(self, node): | ||
""" | ||
Test `getmemoryinfo stats` when node is in IBD | ||
""" | ||
result = node.get_memoryinfo("stats") | ||
assert "locked" in result | ||
assert "chunks_free" in result["locked"] | ||
assert "chunks_used" in result["locked"] | ||
assert "free" in result["locked"] | ||
assert "locked" in result["locked"] | ||
assert "total" in result["locked"] | ||
assert "used" in result["locked"] | ||
assert result["locked"]["chunks_free"] == 0 | ||
assert result["locked"]["chunks_used"] == 0 | ||
assert result["locked"]["free"] == 0 | ||
assert result["locked"]["locked"] == 0 | ||
assert result["locked"]["total"] == 0 | ||
assert result["locked"]["used"] == 0 | ||
|
||
def test_mode_mallocinfo_ibd(self, node): | ||
""" | ||
Test `getmemoryinfo mallocinfo` when node is in IBD | ||
""" | ||
result = node.get_memoryinfo("mallocinfo") | ||
assert result == "" | ||
|
||
def run_test(self): | ||
""" | ||
Run JSONRPC server on first, wait to connect, then call `addnode ip[:port]` | ||
""" | ||
# Start node | ||
self.run_node(GetMemoryInfoTest.nodes[0]) | ||
self.wait_for_rpc_connection(GetMemoryInfoTest.nodes[0]) | ||
|
||
# Test assertions | ||
node = self.get_node(GetMemoryInfoTest.nodes[0]) | ||
self.test_mode_stats_ibd(node) | ||
self.test_mode_mallocinfo_ibd(node) | ||
|
||
# Stop node | ||
self.stop_node(GetMemoryInfoTest.nodes[0]) | ||
|
||
|
||
if __name__ == "__main__": | ||
GetMemoryInfoTest().main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
""" | ||
floresta_cli_getrpcinfo.py | ||
This functional test cli utility to interact with a Floresta node with `getrpcinfo` | ||
""" | ||
|
||
import os | ||
import tempfile | ||
from test_framework.test_framework import FlorestaTestFramework | ||
from test_framework.floresta_rpc import REGTEST_RPC_SERVER | ||
|
||
|
||
class GetRpcInfoTest(FlorestaTestFramework): | ||
""" | ||
Test `getrpcinfo` rpc call, by creating a node | ||
""" | ||
|
||
nodes = [-1] | ||
data_dir = os.path.normpath( | ||
os.path.join( | ||
tempfile.gettempdir(), | ||
"floresta-func-tests", | ||
"florestacli-getrpcinfo-test", | ||
"node-0", | ||
) | ||
) | ||
|
||
def set_test_params(self): | ||
""" | ||
Setup the two node florestad process with different data-dirs, electrum-addresses | ||
and rpc-addresses in the same regtest network | ||
""" | ||
GetRpcInfoTest.nodes[0] = self.add_node_settings( | ||
chain="regtest", | ||
extra_args=[ | ||
f"--data-dir={GetRpcInfoTest.data_dir}", | ||
], | ||
rpcserver=REGTEST_RPC_SERVER, | ||
) | ||
|
||
def run_test(self): | ||
""" | ||
Run JSONRPC server on first, wait to connect, then call `addnode ip[:port]` | ||
""" | ||
# Start node | ||
self.run_node(GetRpcInfoTest.nodes[0]) | ||
self.wait_for_rpc_connection(GetRpcInfoTest.nodes[0]) | ||
|
||
# Test assertions | ||
node = self.get_node(GetRpcInfoTest.nodes[0]) | ||
result = node.get_rpcinfo() | ||
print(result) | ||
|
||
assert "active_commands" in result | ||
assert "logpath" in result | ||
assert len(result["active_commands"]) == 1 | ||
assert "duration" in result["active_commands"][0] | ||
assert "method" in result["active_commands"][0] | ||
assert result["active_commands"][0]["duration"] == 0 | ||
assert result["active_commands"][0]["method"] == "getrpcinfo" | ||
|
||
# FIX: receiving 'logpath' value | ||
# as /tmp/floresta-func-tests/florestacli-getrpcinfo-test/node-0/regtest//output.log | ||
# (with two //) | ||
# assert result["logpath"] == os.path.normpath( | ||
# os.path.join( | ||
# GetRpcInfoTest.data_dir, | ||
# "regtest", | ||
# "output.log" | ||
# ) | ||
# ) | ||
|
||
# Stop node | ||
self.stop_node(GetRpcInfoTest.nodes[0]) | ||
|
||
|
||
if __name__ == "__main__": | ||
GetRpcInfoTest().main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
""" | ||
floresta_cli_uptime.py | ||
This functional test cli utility to interact with a Floresta node with `uptime` | ||
""" | ||
|
||
import os | ||
import time | ||
import tempfile | ||
from test_framework.test_framework import FlorestaTestFramework | ||
from test_framework.floresta_rpc import REGTEST_RPC_SERVER | ||
|
||
|
||
class UptimeTest(FlorestaTestFramework): | ||
""" | ||
Test `uptime` rpc call, by creating a node, wait for | ||
some time (10 seconds) and assert that this wait time is | ||
equal to how long florestad has been running | ||
""" | ||
|
||
nodes = [-1] | ||
|
||
# pylint: disable=duplicate-code | ||
data_dir = os.path.normpath( | ||
os.path.join( | ||
tempfile.gettempdir(), | ||
"floresta-func-tests", | ||
"florestacli-uptime-test", | ||
"node-0", | ||
) | ||
) | ||
|
||
def set_test_params(self): | ||
""" | ||
Setup the two node florestad process with different data-dirs, electrum-addresses | ||
and rpc-addresses in the same regtest network | ||
""" | ||
UptimeTest.nodes[0] = self.add_node_settings( | ||
chain="regtest", | ||
extra_args=[ | ||
f"--data-dir={UptimeTest.data_dir}", | ||
], | ||
rpcserver=REGTEST_RPC_SERVER, | ||
) | ||
|
||
def run_test(self): | ||
""" | ||
Run JSONRPC server on first, wait to connect, then call `addnode ip[:port]` | ||
""" | ||
# Start node | ||
self.run_node(UptimeTest.nodes[0]) | ||
self.wait_for_rpc_connection(UptimeTest.nodes[0]) | ||
|
||
# wait for some seconds before get the uptime | ||
# and get the current time | ||
before = time.time() | ||
time.sleep(5) | ||
|
||
# Test assertions | ||
node = self.get_node(UptimeTest.nodes[0]) | ||
uptime = node.uptime() | ||
|
||
# calculate the elapsed time | ||
after = time.time() | ||
elapsed = int(after - before) | ||
|
||
assert uptime == elapsed | ||
|
||
# Stop node | ||
self.stop_node(UptimeTest.nodes[0]) | ||
|
||
|
||
if __name__ == "__main__": | ||
UptimeTest().main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters