Skip to content

Commit

Permalink
Merge bitcoin#23037: test: fix confusing off-by-one nValue in feature…
Browse files Browse the repository at this point in the history
…_coinstatsindex.py

ebe49b5 test: fix confusing off-by-one nValue in feature_coinstatsindex.py (Sebastian Falbesoner)

Pull request description:

  Due to evil floating-point arithmetic, the creation of one of the transaction outputs in feature_coinstatsindex.py leads to it's nValue being off by one satoshi: the Python expression `int(21.99 * COIN)` doesn't yield 2199000000 as expected, but 2198999999.

  This makes the test more confusing than necessary (w.r.t. the expected `gettxoutsetinfo` values), and could also cause problems if the value is ever changed. Fix by using a `Decimal` type for specifying the value in BTC, rather than using a bare floating-point.

ACKs for top commit:
  MarcoFalke:
    cr ACK ebe49b5

Tree-SHA512: c74c51dbf99818f3d1c881873e0c053a649e4fed9b36767ff971dd3a48bff7122afea4e07cc9925236570368b45579f63e443701f2aaef838a0fafdbe986dfd4
  • Loading branch information
merge-script authored and vijaydasmp committed Sep 10, 2024
1 parent 54a5b32 commit aecda91
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions test/functional/feature_coinstatsindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def _test_coin_stats_index(self):
# Generate and send another tx with an OP_RETURN output (which is unspendable)
tx2 = CTransaction()
tx2.vin.append(CTxIn(COutPoint(int(tx1_txid, 16), n), b''))
tx2.vout.append(CTxOut(int(20.99 * COIN), CScript([OP_RETURN] + [OP_FALSE]*30)))
tx2.vout.append(CTxOut(int(Decimal('20.99') * COIN), CScript([OP_RETURN] + [OP_FALSE]*30)))
tx2_hex = self.nodes[0].signrawtransactionwithwallet(tx2.serialize().hex())['hex']
self.nodes[0].sendrawtransaction(tx2_hex)

Expand All @@ -189,16 +189,16 @@ 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.98999999'))
assert_equal(res6['total_unspendable_amount'], Decimal('70.99000000'))
assert_equal(res6['block_info'], {
'unspendable': Decimal('20.98999999'),
'unspendable': Decimal('20.99000000'),
'prevout_spent': 511,
'new_outputs_ex_coinbase': Decimal('489.99999741'),
'coinbase': Decimal('500.01000260'),
'coinbase': Decimal('500.01006380'),
'unspendables': {
'genesis_block': 0,
'bip30': 0,
'scripts': Decimal('20.98999999'),
'scripts': Decimal('20.99000000'),
'unclaimed_rewards': 0
}
})
Expand All @@ -220,7 +220,7 @@ def _test_coin_stats_index(self):

for hash_option in index_hash_options:
res7 = index_node.gettxoutsetinfo(hash_option, 109)
assert_equal(res7['total_unspendable_amount'], Decimal('530.98999999'))
assert_equal(res7['total_unspendable_amount'], Decimal('530.99000000'))
assert_equal(res7['block_info'], {
'unspendable': 460,
'prevout_spent': 0,
Expand Down

0 comments on commit aecda91

Please sign in to comment.