Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_findforkhash.py
- This file was added.
#!/usr/bin/env python3 | |||||
# Copyright (c) 2020 The Bitcoin developers | |||||
# Distributed under the MIT software license, see the accompanying | |||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | |||||
"""Test the findforkhash RPC.""" | |||||
from test_framework.test_framework import BitcoinTestFramework | |||||
from test_framework.util import assert_equal | |||||
class FindForkHashTest(BitcoinTestFramework): | |||||
def set_test_params(self): | |||||
self.setup_clean_chain = True | |||||
self.num_nodes = 1 | |||||
self.extra_args = [[]] | |||||
def setup_network(self): | |||||
self.setup_nodes() | |||||
def run_test(self): | |||||
genesis_hash = self.nodes[0].getbestblockhash() | |||||
# Create the fork block | |||||
self.nodes[0].generatetoaddress( | |||||
1, self.nodes[0].get_deterministic_priv_key().address) | |||||
fork_block_hash = self.nodes[0].getblockhash( | |||||
self.nodes[0].getblockcount()) | |||||
# Create off-chain fork | |||||
self.nodes[0].generatetoaddress( | |||||
1, self.nodes[0].get_deterministic_priv_key().address) | |||||
off_chain_hash = self.nodes[0].getblockhash( | |||||
self.nodes[0].getblockcount()) | |||||
self.nodes[0].invalidateblock(off_chain_hash) | |||||
# Off-chain block | |||||
assert_equal(self.nodes[0].findforkhash( | |||||
off_chain_hash), fork_block_hash) | |||||
# On-chain block | |||||
assert_equal(self.nodes[0].findforkhash( | |||||
fork_block_hash), fork_block_hash) | |||||
# Non-existent block | |||||
assert_equal(self.nodes[0].findforkhash( | |||||
"0cf7bb8b1697ea987f3b223ba7819250cae33efacb068d23dc24859824a77844"), genesis_hash) | |||||
if __name__ == '__main__': | |||||
FindForkHashTest().main() |