Skip to content

Commit

Permalink
[tests]: Added tests to use vsize_bip141 flag
Browse files Browse the repository at this point in the history
Asserts were added where vsize flags were used and vsize_bip141 could be
added
  • Loading branch information
kevkevinpal committed Oct 20, 2023
1 parent 9cf46b6 commit 4ab1f14
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/functional/feature_segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ def run_test(self):

# Check that weight and vsize are properly reported in mempool entry (txid1)
assert_equal(self.nodes[0].getmempoolentry(txid1)["vsize"], tx1.get_vsize())
assert_equal(self.nodes[0].getmempoolentry(txid1)["vsize_bip141"], tx1.get_vsize())
assert_equal(self.nodes[0].getmempoolentry(txid1)["weight"], tx1.get_weight())

# Now create tx2, which will spend from txid1.
Expand All @@ -304,6 +305,7 @@ def run_test(self):

# Check that weight and vsize are properly reported in mempool entry (txid2)
assert_equal(self.nodes[0].getmempoolentry(txid2)["vsize"], tx.get_vsize())
assert_equal(self.nodes[0].getmempoolentry(txid2)["vsize_bip141"], tx.get_vsize())
assert_equal(self.nodes[0].getmempoolentry(txid2)["weight"], tx.get_weight())

# Now create tx3, which will spend from txid2
Expand All @@ -327,6 +329,7 @@ def run_test(self):

# Check that weight and vsize are properly reported in mempool entry (txid3)
assert_equal(self.nodes[0].getmempoolentry(txid3)["vsize"], tx.get_vsize())
assert_equal(self.nodes[0].getmempoolentry(txid3)["vsize_bip141"], tx.get_vsize())
assert_equal(self.nodes[0].getmempoolentry(txid3)["weight"], tx.get_weight())

# Mine a block to clear the gbt cache again.
Expand Down
1 change: 1 addition & 0 deletions test/functional/mempool_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def run_test(self):
descendant_vsize = 0

assert_equal(ancestor_vsize, sum([mempool[tx]['vsize'] for tx in mempool]))
assert_equal(ancestor_vsize, sum([mempool[tx]['vsize_bip141'] for tx in mempool]))
ancestor_count = DEFAULT_ANCESTOR_LIMIT
assert_equal(ancestor_fees, sum([mempool[tx]['fees']['base'] for tx in mempool]))

Expand Down
1 change: 1 addition & 0 deletions test/functional/mempool_sigoplimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def test_sigops_limit(self, bytes_per_sigop, num_sigops):
res = self.nodes[0].testmempoolaccept([tx.serialize().hex()])[0]
assert_equal(res['allowed'], True)
assert_equal(res['vsize'], sigop_equivalent_vsize)
assert_equal(res['vsize_bip141'], sigop_equivalent_vsize)

# increase the tx's vsize to be right above the sigop-limit equivalent size
# => tx's vsize in mempool should also grow accordingly
Expand Down
3 changes: 3 additions & 0 deletions test/functional/mining_prioritisetransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,14 @@ def run_test(self):
# create more transactions.
mempool = self.nodes[0].getrawmempool(True)
sizes = [0, 0, 0]
sizes_bip141 = [0, 0, 0]
for i in range(3):
for j in txids[i]:
assert j in mempool
sizes[i] += mempool[j]['vsize']
sizes_bip141[i] += mempool[j]['vsize_bip141']
assert sizes[i] > MAX_BLOCK_WEIGHT // 4 # Fail => raise utxo_count
assert sizes_bip141[i] > MAX_BLOCK_WEIGHT // 4 # Fail => raise utxo_count

assert_equal(self.nodes[0].getprioritisedtransactions(), {})
# add a fee delta to something in the cheapest bucket and make sure it gets mined
Expand Down
3 changes: 3 additions & 0 deletions test/functional/rpc_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def test_rbf(self):
assert_equal(testres_replaceable["wtxid"], replaceable_tx["wtxid"])
assert testres_replaceable["allowed"]
assert_equal(testres_replaceable["vsize"], replaceable_tx["tx"].get_vsize())
assert_equal(testres_replaceable["vsize_bip141"], replaceable_tx["tx"].get_vsize())
assert_equal(testres_replaceable["fees"]["base"], fee)
assert_fee_amount(fee, replaceable_tx["tx"].get_vsize(), testres_replaceable["fees"]["effective-feerate"])
assert_equal(testres_replaceable["fees"]["effective-includes"], [replaceable_tx["wtxid"]])
Expand Down Expand Up @@ -280,9 +281,11 @@ def assert_equal_package_results(self, node, testmempoolaccept_result, submitpac
# No "allowed" if the tx was already in the mempool
if "allowed" in testres_tx and testres_tx["allowed"]:
assert_equal(submitres_tx["vsize"], testres_tx["vsize"])
assert_equal(submitres_tx["vsize_bip141"], testres_tx["vsize_bip141"])
assert_equal(submitres_tx["fees"]["base"], testres_tx["fees"]["base"])
entry_info = node.getmempoolentry(submitres_tx["txid"])
assert_equal(submitres_tx["vsize"], entry_info["vsize"])
assert_equal(submitres_tx["vsize_bip141"], entry_info["vsize_bip141"])
assert_equal(submitres_tx["fees"]["base"], entry_info["fees"]["base"])

def test_submit_child_with_parents(self, num_parents, partial_submit):
Expand Down
7 changes: 7 additions & 0 deletions test/functional/wallet_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def check_fee_amount(self, curr_balance, balance_with_fee, fee_per_byte, tx_size
def get_vsize(self, txn):
return self.nodes[0].decoderawtransaction(txn)['vsize']

def get_vsize_bip141(self, txn):
return self.nodes[0].decoderawtransaction(txn)['vsize_bip141']

def run_test(self):

# Check that there's no UTXO on none of the nodes
Expand Down Expand Up @@ -487,10 +490,12 @@ def run_test(self):
# Test passing fee_rate as an integer
txid = self.nodes[2].sendtoaddress(address=address, amount=amount, fee_rate=fee_rate_sat_vb)
tx_size = self.get_vsize(self.nodes[2].gettransaction(txid)['hex'])
tx_size_bip141 = self.get_vsize_bip141(self.nodes[2].gettransaction(txid)['hex'])
self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
postbalance = self.nodes[2].getbalance()
fee = prebalance - postbalance - Decimal(amount)
assert_fee_amount(fee, tx_size, Decimal(fee_rate_btc_kvb))
assert_fee_amount(fee, tx_size_bip141, Decimal(fee_rate_btc_kvb))

prebalance = self.nodes[2].getbalance()
amount = Decimal("0.001")
Expand All @@ -499,10 +504,12 @@ def run_test(self):
# Test passing fee_rate as a string
txid = self.nodes[2].sendtoaddress(address=address, amount=amount, fee_rate=str(fee_rate_sat_vb))
tx_size = self.get_vsize(self.nodes[2].gettransaction(txid)['hex'])
tx_size_bip141 = self.get_vsize_bip141(self.nodes[2].gettransaction(txid)['hex'])
self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
postbalance = self.nodes[2].getbalance()
fee = prebalance - postbalance - amount
assert_fee_amount(fee, tx_size, Decimal(fee_rate_btc_kvb))
assert_fee_amount(fee, tx_size_bip141, Decimal(fee_rate_btc_kvb))

# Test setting explicit fee rate just below the minimum.
self.log.info("Test sendtoaddress raises 'fee rate too low' if fee_rate of 0.99999999 is passed")
Expand Down
4 changes: 4 additions & 0 deletions test/functional/wallet_bumpfee.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ def test_notmine_bumpfee(self, rbf_node, peer_node, dest_address):
entry = rbf_node.getmempoolentry(rbfid)
old_fee = entry["fees"]["base"]
old_feerate = int(old_fee / entry["vsize"] * Decimal(1e8))
old_feerate_bip141 = int(old_fee / entry["vsize_bip141"] * Decimal(1e8))
assert_raises_rpc_error(-4, "Transaction contains inputs that don't belong to this wallet",
rbf_node.bumpfee, rbfid)

Expand All @@ -415,6 +416,9 @@ def finish_psbtbumpfee(psbt):
psbt = rbf_node.psbtbumpfee(txid=rbfid, fee_rate=old_feerate + 10)
finish_psbtbumpfee(psbt["psbt"])

psbt = rbf_node.psbtbumpfee(txid=rbfid, fee_rate=old_feerate_bip141 + 10)
finish_psbtbumpfee(psbt["psbt"])

self.clear_mempool()


Expand Down

0 comments on commit 4ab1f14

Please sign in to comment.