Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_blockchain.py
Show First 20 Lines • Show All 354 Lines • ▼ Show 20 Lines | def _test_stopatheight(self): | ||||
1, self.nodes[0].get_deterministic_priv_key().address) | 1, self.nodes[0].get_deterministic_priv_key().address) | ||||
except (ConnectionError, http.client.BadStatusLine): | except (ConnectionError, http.client.BadStatusLine): | ||||
pass # The node already shut down before response | pass # The node already shut down before response | ||||
self.log.debug('Node should stop at this height...') | self.log.debug('Node should stop at this height...') | ||||
self.nodes[0].wait_until_stopped() | self.nodes[0].wait_until_stopped() | ||||
self.start_node(0) | self.start_node(0) | ||||
assert_equal(self.nodes[0].getblockcount(), 207) | assert_equal(self.nodes[0].getblockcount(), 207) | ||||
def _test_getblock(self): | |||||
# Checks for getblock verbose outputs | |||||
node = self.nodes[0] | |||||
getblockinfo = node.getblock(node.getblockhash(1), 2) | |||||
gettransactioninfo = node.gettransaction(getblockinfo['tx'][0]['txid']) | |||||
getblockheaderinfo = node.getblockheader(node.getblockhash(1), True) | |||||
assert_equal(getblockinfo['hash'], gettransactioninfo['blockhash']) | |||||
assert_equal( | |||||
getblockinfo['confirmations'], gettransactioninfo['confirmations']) | |||||
assert_equal(getblockinfo['height'], getblockheaderinfo['height']) | |||||
assert_equal( | |||||
getblockinfo['versionHex'], getblockheaderinfo['versionHex']) | |||||
assert_equal(getblockinfo['version'], getblockheaderinfo['version']) | |||||
assert_equal(getblockinfo['size'], 181) | |||||
assert_equal( | |||||
getblockinfo['merkleroot'], getblockheaderinfo['merkleroot']) | |||||
# Verify transaction data by check the hex values | |||||
for tx in getblockinfo['tx']: | |||||
getrawtransaction = node.getrawtransaction(tx['txid'], True) | |||||
assert_equal(tx['hex'], getrawtransaction['hex']) | |||||
assert_equal(getblockinfo['time'], getblockheaderinfo['time']) | |||||
assert_equal( | |||||
getblockinfo['mediantime'], getblockheaderinfo['mediantime']) | |||||
assert_equal(getblockinfo['nonce'], getblockheaderinfo['nonce']) | |||||
assert_equal(getblockinfo['bits'], getblockheaderinfo['bits']) | |||||
assert_equal( | |||||
getblockinfo['difficulty'], getblockheaderinfo['difficulty']) | |||||
assert_equal( | |||||
getblockinfo['chainwork'], getblockheaderinfo['chainwork']) | |||||
assert_equal( | |||||
getblockinfo['previousblockhash'], getblockheaderinfo['previousblockhash']) | |||||
assert_equal( | |||||
getblockinfo['nextblockhash'], getblockheaderinfo['nextblockhash']) | |||||
def _test_waitforblockheight(self): | def _test_waitforblockheight(self): | ||||
self.log.info("Test waitforblockheight") | self.log.info("Test waitforblockheight") | ||||
node = self.nodes[0] | node = self.nodes[0] | ||||
node.add_p2p_connection(P2PInterface()) | node.add_p2p_connection(P2PInterface()) | ||||
current_height = node.getblock(node.getbestblockhash())['height'] | current_height = node.getblock(node.getbestblockhash())['height'] | ||||
# Create a fork somewhere below our current height, invalidate the tip | # Create a fork somewhere below our current height, invalidate the tip | ||||
Show All 24 Lines | def _test_waitforblockheight(self): | ||||
height=height, timeout=timeout)['height'], | height=height, timeout=timeout)['height'], | ||||
current_height) | current_height) | ||||
assert_waitforheight(0) | assert_waitforheight(0) | ||||
assert_waitforheight(current_height - 1) | assert_waitforheight(current_height - 1) | ||||
assert_waitforheight(current_height) | assert_waitforheight(current_height) | ||||
assert_waitforheight(current_height + 1) | assert_waitforheight(current_height + 1) | ||||
def _test_getblock(self): | |||||
# Checks for getblock verbose outputs | |||||
node = self.nodes[0] | |||||
blockinfo = node.getblock(node.getblockhash(1), 2) | |||||
transactioninfo = node.gettransaction(blockinfo['tx'][0]['txid']) | |||||
blockheaderinfo = node.getblockheader(node.getblockhash(1), True) | |||||
assert_equal(blockinfo['hash'], transactioninfo['blockhash']) | |||||
assert_equal( | |||||
blockinfo['confirmations'], | |||||
transactioninfo['confirmations']) | |||||
assert_equal(blockinfo['height'], blockheaderinfo['height']) | |||||
assert_equal(blockinfo['versionHex'], blockheaderinfo['versionHex']) | |||||
assert_equal(blockinfo['version'], blockheaderinfo['version']) | |||||
assert_equal(blockinfo['size'], 181) | |||||
assert_equal(blockinfo['merkleroot'], blockheaderinfo['merkleroot']) | |||||
# Verify transaction data by check the hex values | |||||
for tx in blockinfo['tx']: | |||||
rawtransaction = node.getrawtransaction(tx['txid'], True) | |||||
assert_equal(tx['hex'], rawtransaction['hex']) | |||||
assert_equal(blockinfo['time'], blockheaderinfo['time']) | |||||
assert_equal(blockinfo['mediantime'], blockheaderinfo['mediantime']) | |||||
assert_equal(blockinfo['nonce'], blockheaderinfo['nonce']) | |||||
assert_equal(blockinfo['bits'], blockheaderinfo['bits']) | |||||
assert_equal(blockinfo['difficulty'], blockheaderinfo['difficulty']) | |||||
assert_equal(blockinfo['chainwork'], blockheaderinfo['chainwork']) | |||||
assert_equal( | |||||
blockinfo['previousblockhash'], | |||||
blockheaderinfo['previousblockhash']) | |||||
assert_equal( | |||||
blockinfo['nextblockhash'], | |||||
blockheaderinfo['nextblockhash']) | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
BlockchainTest().main() | BlockchainTest().main() |