Skip to content

Commit 1ed7f84

Browse files
committed
test: fix dbcrash and fee_estimation extended tests
1 parent 2d298f7 commit 1ed7f84

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

test/functional/feature_dbcrash.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,18 @@ def verify_utxo_hash(self):
186186
assert_equal(nodei_utxo_hash, node3_utxo_hash)
187187

188188
def generate_small_transactions(self, node, count, utxo_list):
189-
FEE = 1000 # TODO: replace this with node relay fee based calculation
190189
num_transactions = 0
191190
random.shuffle(utxo_list)
192191
while len(utxo_list) >= 2 and num_transactions < count:
192+
fee = 1000
193193
tx = CTransaction()
194194
input_amount = 0
195195
for _ in range(2):
196196
utxo = utxo_list.pop()
197197
tx.vin.append(CTxIn(COutPoint(int(utxo['txid'], 16), utxo['vout'])))
198198
input_amount += int(utxo['amount'] * COIN)
199-
output_amount = (input_amount - FEE) // 3
199+
output_amount = (input_amount - fee) // 3
200+
fee = input_amount - (3 * output_amount)
200201

201202
if output_amount <= 0:
202203
# Sanity check -- if we chose inputs that are too small, skip
@@ -205,6 +206,9 @@ def generate_small_transactions(self, node, count, utxo_list):
205206
for _ in range(3):
206207
tx.vout.append(CTxOut(output_amount, bytes.fromhex(utxo['scriptPubKey'])))
207208

209+
# ELEMENTS: add fee output
210+
tx.vout.append(CTxOut(fee))
211+
208212
# Sign and send the transaction to get into the mempool
209213
tx_signed_hex = node.signrawtransactionwithwallet(tx.serialize().hex())['hex']
210214
node.sendrawtransaction(tx_signed_hex)
@@ -234,7 +238,8 @@ def run_test(self):
234238
# Main test loop:
235239
# each time through the loop, generate a bunch of transactions,
236240
# and then either mine a single new block on the tip, or some-sized reorg.
237-
for i in range(40):
241+
# ELEMENTS: reduced iters to run in some "reasonable" amount of time (~6 hours)
242+
for i in range(4):
238243
self.log.info(f"Iteration {i}, generating 2500 transactions {self.restart_counts}")
239244
# Generate a bunch of small-ish transactions
240245
self.generate_small_transactions(self.nodes[3], 2500, utxo_list)

test/functional/feature_fee_estimation.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,13 @@ def send_tx(node, utxo, feerate):
134134
"""Broadcast a 1in-1out transaction with a specific input and feerate (sat/vb)."""
135135
tx = CTransaction()
136136
tx.vin = [CTxIn(COutPoint(int(utxo["txid"], 16), utxo["vout"]), REDEEM_SCRIPT)]
137-
tx.vout = [CTxOut(int(utxo["amount"] * COIN), P2SH)]
137+
tx.vout = [CTxOut(int(utxo["amount"] * COIN), P2SH), CTxOut(int(utxo["amount"] * COIN))]
138138

139139
# vbytes == bytes as we are using legacy transactions
140140
fee = tx.get_vsize() * feerate
141-
tx.vout[0].nValue -= fee
141+
amount = tx.vout[0].nValue.getAmount()
142+
tx.vout[0].nValue.setToAmount(amount - fee)
143+
tx.vout[1].nValue.setToAmount(fee)
142144

143145
return node.sendrawtransaction(tx.serialize().hex())
144146

@@ -208,7 +210,7 @@ def transact_and_mine(self, numblocks, mining_node):
208210

209211
def initial_split(self, node):
210212
"""Split two coinbase UTxOs into many small coins"""
211-
utxo_count = 2048
213+
utxo_count = 1450 # ELEMENTS reduced to fit into max tx weight
212214
self.confutxo = []
213215
splitted_amount = Decimal("0.04")
214216
fee = Decimal("0.1")
@@ -220,6 +222,7 @@ def initial_split(self, node):
220222
]
221223
tx.vout = [CTxOut(int(splitted_amount * COIN), P2SH) for _ in range(utxo_count)]
222224
tx.vout.append(CTxOut(int(change * COIN), P2SH))
225+
tx.vout.append(CTxOut(int(fee * COIN)))
223226
txhex = node.signrawtransactionwithwallet(tx.serialize().hex())["hex"]
224227
txid = node.sendrawtransaction(txhex)
225228
self.confutxo = [

test/functional/test_framework/util.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,10 @@ def create_confirmed_utxos(test_framework, fee, node, count, **kwargs):
519519
inputs = []
520520
inputs.append({"txid": t["txid"], "vout": t["vout"]})
521521
send_value = t['amount'] - fee
522-
outputs = [{addr1: satoshi_round(send_value / 2)}, {addr2: satoshi_round(send_value / 2)}, {"fee": fee}]
522+
# ELEMENTS: ensure outputs balance with inputs
523+
val1 = satoshi_round(send_value / 2)
524+
val2 = send_value - val1
525+
outputs = [{addr1: val1}, {addr2: val2}, {"fee": fee}]
523526
raw_tx = node.createrawtransaction(inputs, outputs)
524527
signed_tx = node.signrawtransactionwithwallet(raw_tx)["hex"]
525528
node.sendrawtransaction(signed_tx)

0 commit comments

Comments
 (0)