Skip to content

Commit e14d987

Browse files
authored
Merge pull request #1275 from delta1/issues-1269
test: fix flaky CLTV test in signrawtransaction.py
2 parents c92a8f2 + 181b9e5 commit e14d987

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

test/functional/rpc_signrawtransaction.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
getcontext,
4343
)
4444

45+
import time # ELEMENTS
46+
4547
class SignRawTransactionsTest(BitcoinTestFramework):
4648
def set_test_params(self):
4749
self.setup_clean_chain = True
@@ -213,6 +215,8 @@ def witness_script_test(self):
213215
self.generate(self.nodes[0], COINBASE_MATURITY + 1, sync_fun=self.no_op)
214216
self.nodes[0].sendtoaddress(p2sh_p2wsh_address["address"], 49.999)
215217
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
218+
# ElEMENTS: allow time for block sync
219+
time.sleep(1)
216220
# Get the UTXO info from scantxoutset
217221
unspent_output = self.nodes[1].scantxoutset('start', [p2sh_p2wsh_address['descriptor']])['unspents'][0]
218222
spk = script_to_p2sh_p2wsh_script(p2sh_p2wsh_address['redeemScript']).hex()
@@ -279,7 +283,7 @@ def OP_1NEGATE_test(self):
279283
def test_signing_with_csv(self):
280284
self.log.info("Test signing a transaction containing a fully signed CSV input")
281285
self.nodes[0].walletpassphrase("password", 9999)
282-
getcontext().prec = 8
286+
getcontext().prec = 10
283287

284288
# Make sure CSV is active
285289
assert self.nodes[0].getdeploymentinfo()['deployments']['csv']['active']
@@ -328,6 +332,14 @@ def test_signing_with_cltv(self):
328332
vout = find_vout_for_address(self.nodes[0], txid, address)
329333
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
330334
utxo = self.nodes[0].listunspent()[0]
335+
# ELEMENTS:
336+
# use increased Decimal precision
337+
# when utxo['amount'] has many decimal places (eg: 50.00005640)
338+
# then this 'amt' calculation would be incorrect
339+
# precision 8: 1 + 50.00005640 - 0.00001 = 51.000046
340+
# precision 10: 1 + 50.00005640 - 0.00001 = 51.00004640
341+
# which causes the inputs/outputs to not balance
342+
getcontext().prec = 10
331343
amt = Decimal(1) + utxo["amount"] - Decimal(0.00001)
332344
tx = self.nodes[0].createrawtransaction(
333345
[{"txid": txid, "vout": vout},{"txid": utxo["txid"], "vout": utxo["vout"]}],

0 commit comments

Comments
 (0)