Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_blockchain.py
Show First 20 Lines • Show All 161 Lines • ▼ Show 20 Lines | def _test_getchaintxstats(self): | ||||
assert_raises_rpc_error( | assert_raises_rpc_error( | ||||
-5, "Block not found", self.nodes[0].getchaintxstats, blockhash='0') | -5, "Block not found", self.nodes[0].getchaintxstats, blockhash='0') | ||||
blockhash = self.nodes[0].getblockhash(200) | blockhash = self.nodes[0].getblockhash(200) | ||||
self.nodes[0].invalidateblock(blockhash) | self.nodes[0].invalidateblock(blockhash) | ||||
assert_raises_rpc_error( | assert_raises_rpc_error( | ||||
-8, "Block is not in main chain", self.nodes[0].getchaintxstats, blockhash=blockhash) | -8, "Block is not in main chain", self.nodes[0].getchaintxstats, blockhash=blockhash) | ||||
self.nodes[0].reconsiderblock(blockhash) | self.nodes[0].reconsiderblock(blockhash) | ||||
chaintxstats = self.nodes[0].getchaintxstats(1) | chaintxstats = self.nodes[0].getchaintxstats(nblocks=1) | ||||
# 200 txs plus genesis tx | # 200 txs plus genesis tx | ||||
assert_equal(chaintxstats['txcount'], 201) | assert_equal(chaintxstats['txcount'], 201) | ||||
# tx rate should be 1 per 10 minutes, or 1/600 | # tx rate should be 1 per 10 minutes, or 1/600 | ||||
# we have to round because of binary math | # we have to round because of binary math | ||||
assert_equal(round(chaintxstats['txrate'] * 600, 10), Decimal(1)) | assert_equal(round(chaintxstats['txrate'] * 600, 10), Decimal(1)) | ||||
b1_hash = self.nodes[0].getblockhash(1) | b1_hash = self.nodes[0].getblockhash(1) | ||||
b1 = self.nodes[0].getblock(b1_hash) | b1 = self.nodes[0].getblock(b1_hash) | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | class BlockchainTest(BitcoinTestFramework): | ||||
def _test_getblockheader(self): | def _test_getblockheader(self): | ||||
node = self.nodes[0] | node = self.nodes[0] | ||||
assert_raises_rpc_error(-5, "Block not found", | assert_raises_rpc_error(-5, "Block not found", | ||||
node.getblockheader, "nonsense") | node.getblockheader, "nonsense") | ||||
besthash = node.getbestblockhash() | besthash = node.getbestblockhash() | ||||
secondbesthash = node.getblockhash(199) | secondbesthash = node.getblockhash(199) | ||||
header = node.getblockheader(besthash) | header = node.getblockheader(blockhash=besthash) | ||||
assert_equal(header['hash'], besthash) | assert_equal(header['hash'], besthash) | ||||
assert_equal(header['height'], 200) | assert_equal(header['height'], 200) | ||||
assert_equal(header['confirmations'], 1) | assert_equal(header['confirmations'], 1) | ||||
assert_equal(header['previousblockhash'], secondbesthash) | assert_equal(header['previousblockhash'], secondbesthash) | ||||
assert_is_hex_string(header['chainwork']) | assert_is_hex_string(header['chainwork']) | ||||
assert_equal(header['nTx'], 1) | assert_equal(header['nTx'], 1) | ||||
assert_is_hash_string(header['hash']) | assert_is_hash_string(header['hash']) | ||||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | def _test_waitforblockheight(self): | ||||
b21f = solve_and_send_block(int(b20hash, 16), 21, b20['time'] + 1) | b21f = solve_and_send_block(int(b20hash, 16), 21, b20['time'] + 1) | ||||
b22f = solve_and_send_block(b21f.sha256, 22, b21f.nTime + 1) | b22f = solve_and_send_block(b21f.sha256, 22, b21f.nTime + 1) | ||||
node.invalidateblock(b22f.hash) | node.invalidateblock(b22f.hash) | ||||
def assert_waitforheight(height, timeout=2): | def assert_waitforheight(height, timeout=2): | ||||
assert_equal( | assert_equal( | ||||
node.waitforblockheight(height, timeout)['height'], | node.waitforblockheight( | ||||
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) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
BlockchainTest().main() | BlockchainTest().main() |