Skip to content

Commit 226731a

Browse files
author
merge-script
committed
Merge bitcoin/bitcoin#23037: test: fix confusing off-by-one nValue in feature_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
2 parents 2560b68 + ebe49b5 commit 226731a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

test/functional/feature_coinstatsindex.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def _test_coin_stats_index(self):
164164
# Generate and send another tx with an OP_RETURN output (which is unspendable)
165165
tx2 = CTransaction()
166166
tx2.vin.append(CTxIn(COutPoint(int(tx1_txid, 16), n), b''))
167-
tx2.vout.append(CTxOut(int(20.99 * COIN), CScript([OP_RETURN] + [OP_FALSE]*30)))
167+
tx2.vout.append(CTxOut(int(Decimal('20.99') * COIN), CScript([OP_RETURN] + [OP_FALSE]*30)))
168168
tx2_hex = self.nodes[0].signrawtransactionwithwallet(tx2.serialize().hex())['hex']
169169
self.nodes[0].sendrawtransaction(tx2_hex)
170170

@@ -175,16 +175,16 @@ def _test_coin_stats_index(self):
175175
for hash_option in index_hash_options:
176176
# Check all amounts were registered correctly
177177
res6 = index_node.gettxoutsetinfo(hash_option, 108)
178-
assert_equal(res6['total_unspendable_amount'], Decimal('70.98999999'))
178+
assert_equal(res6['total_unspendable_amount'], Decimal('70.99000000'))
179179
assert_equal(res6['block_info'], {
180-
'unspendable': Decimal('20.98999999'),
180+
'unspendable': Decimal('20.99000000'),
181181
'prevout_spent': 111,
182182
'new_outputs_ex_coinbase': Decimal('89.99993620'),
183-
'coinbase': Decimal('50.01006381'),
183+
'coinbase': Decimal('50.01006380'),
184184
'unspendables': {
185185
'genesis_block': 0,
186186
'bip30': 0,
187-
'scripts': Decimal('20.98999999'),
187+
'scripts': Decimal('20.99000000'),
188188
'unclaimed_rewards': 0
189189
}
190190
})
@@ -206,7 +206,7 @@ def _test_coin_stats_index(self):
206206

207207
for hash_option in index_hash_options:
208208
res7 = index_node.gettxoutsetinfo(hash_option, 109)
209-
assert_equal(res7['total_unspendable_amount'], Decimal('80.98999999'))
209+
assert_equal(res7['total_unspendable_amount'], Decimal('80.99000000'))
210210
assert_equal(res7['block_info'], {
211211
'unspendable': 10,
212212
'prevout_spent': 0,

0 commit comments

Comments
 (0)