Skip to content

Commit

Permalink
Merge pull request ElementsProject#1275 from delta1/issues-1269
Browse files Browse the repository at this point in the history
test: fix flaky CLTV test in signrawtransaction.py
  • Loading branch information
psgreco authored Oct 18, 2023
2 parents c92a8f2 + 181b9e5 commit e14d987
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion test/functional/rpc_signrawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
getcontext,
)

import time # ELEMENTS

class SignRawTransactionsTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
Expand Down Expand Up @@ -213,6 +215,8 @@ def witness_script_test(self):
self.generate(self.nodes[0], COINBASE_MATURITY + 1, sync_fun=self.no_op)
self.nodes[0].sendtoaddress(p2sh_p2wsh_address["address"], 49.999)
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
# ElEMENTS: allow time for block sync
time.sleep(1)
# Get the UTXO info from scantxoutset
unspent_output = self.nodes[1].scantxoutset('start', [p2sh_p2wsh_address['descriptor']])['unspents'][0]
spk = script_to_p2sh_p2wsh_script(p2sh_p2wsh_address['redeemScript']).hex()
Expand Down Expand Up @@ -279,7 +283,7 @@ def OP_1NEGATE_test(self):
def test_signing_with_csv(self):
self.log.info("Test signing a transaction containing a fully signed CSV input")
self.nodes[0].walletpassphrase("password", 9999)
getcontext().prec = 8
getcontext().prec = 10

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

0 comments on commit e14d987

Please sign in to comment.