Skip to content

Commit 5aadd4b

Browse files
author
Prayank
committed
Convert amounts from float to decimal
+ fee, fee_expected, output_amount + Using value of coin['amount'] as decimal and removed 'int' + Removed unnecessary parentheses + Remove str() and use quotes
1 parent de4b7f2 commit 5aadd4b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

test/functional/mempool_accept.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,31 @@ def run_test(self):
8383
)
8484

8585
self.log.info('A transaction not in the mempool')
86-
fee = 0.00000700
86+
fee = Decimal('0.000007')
8787
raw_tx_0 = node.signrawtransactionwithwallet(node.createrawtransaction(
8888
inputs=[{"txid": txid_in_block, "vout": 0, "sequence": BIP125_SEQUENCE_NUMBER}], # RBF is used later
89-
outputs=[{node.getnewaddress(): 0.3 - fee}],
89+
outputs=[{node.getnewaddress(): Decimal('0.3') - fee}],
9090
))['hex']
9191
tx = CTransaction()
9292
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_0)))
9393
txid_0 = tx.rehash()
9494
self.check_mempool_result(
95-
result_expected=[{'txid': txid_0, 'allowed': True, 'vsize': tx.get_vsize(), 'fees': {'base': Decimal(str(fee))}}],
95+
result_expected=[{'txid': txid_0, 'allowed': True, 'vsize': tx.get_vsize(), 'fees': {'base': fee}}],
9696
rawtxs=[raw_tx_0],
9797
)
9898

9999
self.log.info('A final transaction not in the mempool')
100100
coin = coins.pop() # Pick a random coin(base) to spend
101-
output_amount = 0.025
101+
output_amount = Decimal('0.025')
102102
raw_tx_final = node.signrawtransactionwithwallet(node.createrawtransaction(
103103
inputs=[{'txid': coin['txid'], 'vout': coin['vout'], "sequence": 0xffffffff}], # SEQUENCE_FINAL
104104
outputs=[{node.getnewaddress(): output_amount}],
105105
locktime=node.getblockcount() + 2000, # Can be anything
106106
))['hex']
107107
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_final)))
108-
fee_expected = int(coin['amount']) - output_amount
108+
fee_expected = coin['amount'] - output_amount
109109
self.check_mempool_result(
110-
result_expected=[{'txid': tx.rehash(), 'allowed': True, 'vsize': tx.get_vsize(), 'fees': {'base': Decimal(str(fee_expected))}}],
110+
result_expected=[{'txid': tx.rehash(), 'allowed': True, 'vsize': tx.get_vsize(), 'fees': {'base': fee_expected}}],
111111
rawtxs=[tx.serialize().hex()],
112112
maxfeerate=0,
113113
)
@@ -130,7 +130,7 @@ def run_test(self):
130130
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_0)))
131131
txid_0 = tx.rehash()
132132
self.check_mempool_result(
133-
result_expected=[{'txid': txid_0, 'allowed': True, 'vsize': tx.get_vsize(), 'fees': {'base': Decimal(str(2 * fee))}}],
133+
result_expected=[{'txid': txid_0, 'allowed': True, 'vsize': tx.get_vsize(), 'fees': {'base': (2 * fee)}}],
134134
rawtxs=[raw_tx_0],
135135
)
136136

@@ -190,7 +190,7 @@ def run_test(self):
190190
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
191191
# Reference tx should be valid on itself
192192
self.check_mempool_result(
193-
result_expected=[{'txid': tx.rehash(), 'allowed': True, 'vsize': tx.get_vsize(), 'fees': { 'base': Decimal(str(0.1 - 0.05))}}],
193+
result_expected=[{'txid': tx.rehash(), 'allowed': True, 'vsize': tx.get_vsize(), 'fees': { 'base': Decimal('0.1') - Decimal('0.05')}}],
194194
rawtxs=[tx.serialize().hex()],
195195
maxfeerate=0,
196196
)

0 commit comments

Comments
 (0)