-
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.
Added test for getblockheader JSONRPC call (#398)
This commit add a structure to test calls of `getblockheader` in tests/test_framework/floresta_rpc.py, a simple test in tests/floresta_cli_getblockheader.py and a helper in pyproject.toml as `florestacli-getblockheader-test`. This simple test just call the `getblockheader` with the hash of regtest's genesis block and expect, among some data, a prev_blockhash full of zeros.
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 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,69 @@ | ||
""" | ||
floresta_cli_getblockheader.py | ||
This functional test cli utility to interact with a Floresta node with `getblockheader` | ||
""" | ||
|
||
from test_framework.test_framework import FlorestaTestFramework | ||
from test_framework.floresta_rpc import REGTEST_RPC_SERVER | ||
|
||
|
||
class GetBlockheaderHeightZeroTest(FlorestaTestFramework): | ||
""" | ||
Test `getblockheader` with a fresh node and expect a result like this: | ||
````bash | ||
$> ./target/release floresta_cli --network=regtest getblockheader \ | ||
0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206 | ||
{ | ||
"version": 1, | ||
"prev_blockhash": "0000000000000000000000000000000000000000000000000000000000000000", | ||
"merkle_root": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b", | ||
"time": 1296688602, | ||
"bits": 545259519, | ||
"nonce": 2 | ||
} | ||
``` | ||
""" | ||
|
||
nodes = [-1] | ||
version = 1 | ||
blockhash = "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206" | ||
prev_blockhash = "0000000000000000000000000000000000000000000000000000000000000000" | ||
merkle_root = "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b" | ||
time = 1296688602 | ||
bits = 545259519 | ||
nonce = 2 | ||
|
||
def set_test_params(self): | ||
""" | ||
Setup a single node | ||
""" | ||
GetBlockheaderHeightZeroTest.nodes[0] = self.add_node_settings( | ||
chain="regtest", extra_args=[], rpcserver=REGTEST_RPC_SERVER | ||
) | ||
|
||
def run_test(self): | ||
""" | ||
Run JSONRPC and get the header of the genesis block | ||
""" | ||
# Start node | ||
self.run_node(GetBlockheaderHeightZeroTest.nodes[0]) | ||
self.wait_for_rpc_connection(GetBlockheaderHeightZeroTest.nodes[0]) | ||
|
||
# Test assertions | ||
node = self.get_node(GetBlockheaderHeightZeroTest.nodes[0]) | ||
response = node.get_blockheader(GetBlockheaderHeightZeroTest.blockhash) | ||
assert response["version"] == GetBlockheaderHeightZeroTest.version | ||
assert response["prev_blockhash"] == GetBlockheaderHeightZeroTest.prev_blockhash | ||
assert response["merkle_root"] == GetBlockheaderHeightZeroTest.merkle_root | ||
assert response["time"] == GetBlockheaderHeightZeroTest.time | ||
assert response["bits"] == GetBlockheaderHeightZeroTest.bits | ||
assert response["nonce"] == GetBlockheaderHeightZeroTest.nonce | ||
|
||
# Shutdown node | ||
self.stop_node(GetBlockheaderHeightZeroTest.nodes[0]) | ||
|
||
|
||
if __name__ == "__main__": | ||
GetBlockheaderHeightZeroTest().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