Skip to content

Commit

Permalink
Port python tests part 4
Browse files Browse the repository at this point in the history
  • Loading branch information
timemarkovqtum committed Mar 28, 2024
1 parent 7e752c1 commit b872df1
Show file tree
Hide file tree
Showing 7 changed files with 414 additions and 341 deletions.
150 changes: 79 additions & 71 deletions test/functional/feature_block.py

Large diffs are not rendered by default.

74 changes: 37 additions & 37 deletions test/functional/feature_coinstatsindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def run_test(self):
self._test_init_index_after_reorg()

def block_sanity_check(self, block_info):
block_subsidy = 50
block_subsidy = 20000
assert_equal(
block_info['prevout_spent'] + block_subsidy,
block_info['new_outputs_ex_coinbase'] + block_info['coinbase'] + block_info['unspendable']
Expand Down Expand Up @@ -97,7 +97,7 @@ def _test_coin_stats_index(self):

for hash_option in index_hash_options:
# Fetch old stats by height
res2 = index_node.gettxoutsetinfo(hash_option, 102)
res2 = index_node.gettxoutsetinfo(hash_option, 2002)
del res2['block_info'], res2['total_unspendable_amount']
res2.pop('muhash', None)
assert_equal(res0, res2)
Expand All @@ -116,14 +116,14 @@ def _test_coin_stats_index(self):
for hash_option in index_hash_options:
# Genesis block is unspendable
res4 = index_node.gettxoutsetinfo(hash_option, 0)
assert_equal(res4['total_unspendable_amount'], 50)
assert_equal(res4['total_unspendable_amount'], 20000)
assert_equal(res4['block_info'], {
'unspendable': 50,
'unspendable': 20000,
'prevout_spent': 0,
'new_outputs_ex_coinbase': 0,
'coinbase': 0,
'unspendables': {
'genesis_block': 50,
'genesis_block': 20000,
'bip30': 0,
'scripts': 0,
'unclaimed_rewards': 0
Expand All @@ -132,18 +132,18 @@ def _test_coin_stats_index(self):
self.block_sanity_check(res4['block_info'])

# Test an older block height that included a normal tx
res5 = index_node.gettxoutsetinfo(hash_option, 102)
assert_equal(res5['total_unspendable_amount'], 50)
res5 = index_node.gettxoutsetinfo(hash_option, 2002)
assert_equal(res5['total_unspendable_amount'], 20000)
assert_equal(res5['block_info'], {
'unspendable': 0,
'prevout_spent': 50,
'new_outputs_ex_coinbase': Decimal('49.99968800'),
'coinbase': Decimal('50.00031200'),
'unspendable': Decimal('0E-8'),
'prevout_spent': Decimal('20000.00000000'),
'new_outputs_ex_coinbase': Decimal('19999.99688000'),
'coinbase': Decimal('20000.00312000'),
'unspendables': {
'genesis_block': 0,
'bip30': 0,
'scripts': 0,
'unclaimed_rewards': 0,
'genesis_block': Decimal('0E-8'),
'bip30': Decimal('0E-8'),
'scripts': Decimal('0E-8'),
'unclaimed_rewards': Decimal('0E-8'),
}
})
self.block_sanity_check(res5['block_info'])
Expand All @@ -170,26 +170,26 @@ def _test_coin_stats_index(self):

for hash_option in index_hash_options:
# Check all amounts were registered correctly
res6 = index_node.gettxoutsetinfo(hash_option, 108)
assert_equal(res6['total_unspendable_amount'], Decimal('70.99000000'))
res6 = index_node.gettxoutsetinfo(hash_option, 2008)
assert_equal(res6['total_unspendable_amount'], Decimal('20020.99000000'))
assert_equal(res6['block_info'], {
'unspendable': Decimal('20.99000000'),
'prevout_spent': 71,
'new_outputs_ex_coinbase': Decimal('49.99999000'),
'coinbase': Decimal('50.01001000'),
'prevout_spent': Decimal('20021.00000000'),
'new_outputs_ex_coinbase': Decimal('19999.99920000'),
'coinbase': Decimal('20000.01080000'),
'unspendables': {
'genesis_block': 0,
'bip30': 0,
'genesis_block': Decimal('0E-8'),
'bip30': Decimal('0E-8'),
'scripts': Decimal('20.99000000'),
'unclaimed_rewards': 0,
'unclaimed_rewards': Decimal('0E-8'),
}
})
self.block_sanity_check(res6['block_info'])

# Create a coinbase that does not claim full subsidy and also
# has two outputs
cb = create_coinbase(109, nValue=35)
cb.vout.append(CTxOut(5 * COIN, CScript([OP_FALSE])))
cb = create_coinbase(2009, nValue=35)
cb.vout.append(CTxOut(5000 * COIN, CScript([OP_FALSE])))
cb.rehash()

# Generate a block that includes previous coinbase
Expand All @@ -201,18 +201,18 @@ def _test_coin_stats_index(self):
self.sync_all()

for hash_option in index_hash_options:
res7 = index_node.gettxoutsetinfo(hash_option, 109)
assert_equal(res7['total_unspendable_amount'], Decimal('80.99000000'))
res7 = index_node.gettxoutsetinfo(hash_option, 2009)
assert_equal(res7['total_unspendable_amount'], Decimal('35020.98999965'))
assert_equal(res7['block_info'], {
'unspendable': 10,
'unspendable': Decimal('14999.99999965'),
'prevout_spent': 0,
'new_outputs_ex_coinbase': 0,
'coinbase': 40,
'coinbase': Decimal('5000.00000035'),
'unspendables': {
'genesis_block': 0,
'bip30': 0,
'scripts': 0,
'unclaimed_rewards': 10
'unclaimed_rewards': Decimal('14999.99999965')
}
})
self.block_sanity_check(res7['block_info'])
Expand Down Expand Up @@ -246,7 +246,7 @@ def _test_use_index_option(self):
self.log.info("Test use_index option for nodes running the index")

self.connect_nodes(0, 1)
self.nodes[0].waitforblockheight(110)
self.nodes[0].waitforblockheight(2010)
res = self.nodes[0].gettxoutsetinfo('muhash')
option_res = self.nodes[1].gettxoutsetinfo(hash_type='muhash', hash_or_height=None, use_index=False)
del res['disk_size'], option_res['disk_size']
Expand All @@ -262,14 +262,14 @@ def _test_reorg_index(self):
self.sync_index_node()
res_invalid = index_node.gettxoutsetinfo('muhash')
index_node.invalidateblock(reorg_blocks[0])
assert_equal(index_node.gettxoutsetinfo('muhash')['height'], 110)
assert_equal(index_node.gettxoutsetinfo('muhash')['height'], 2010)

# Add two new blocks
block = self.generate(index_node, 2, sync_fun=self.no_op)[1]
res = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=None, use_index=False)

# Test that the result of the reorged block is not returned for its old block height
res2 = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=112)
res2 = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=2012)
assert_equal(res["bestblock"], block)
assert_equal(res["muhash"], res2["muhash"])
assert res["muhash"] != res_invalid["muhash"]
Expand All @@ -284,20 +284,20 @@ def _test_reorg_index(self):
self.generate(index_node, 1)

# Ensure that removing and re-adding blocks yields consistent results
block = index_node.getblockhash(99)
block = index_node.getblockhash(1999)
index_node.invalidateblock(block)
index_node.reconsiderblock(block)
res3 = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=112)
res3 = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=2012)
assert_equal(res2, res3)

def _test_index_rejects_hash_serialized(self):
self.log.info("Test that the rpc raises if the legacy hash is passed with the index")

msg = "hash_serialized_3 hash type cannot be queried for a specific block"
assert_raises_rpc_error(-8, msg, self.nodes[1].gettxoutsetinfo, hash_type='hash_serialized_3', hash_or_height=111)
assert_raises_rpc_error(-8, msg, self.nodes[1].gettxoutsetinfo, hash_type='hash_serialized_3', hash_or_height=2011)

for use_index in {True, False, None}:
assert_raises_rpc_error(-8, msg, self.nodes[1].gettxoutsetinfo, hash_type='hash_serialized_3', hash_or_height=111, use_index=use_index)
assert_raises_rpc_error(-8, msg, self.nodes[1].gettxoutsetinfo, hash_type='hash_serialized_3', hash_or_height=2011, use_index=use_index)

def _test_init_index_after_reorg(self):
self.log.info("Test a reorg while the index is deactivated")
Expand Down
Loading

0 comments on commit b872df1

Please sign in to comment.