Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix p2p_ibd_txrelay.py Test & wallet_txn_doublespend.py (4 tests) #193

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions test/functional/p2p_ibd_txrelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
from test_framework.messages import COIN
from test_framework.test_framework import DigiByteTestFramework

MAX_FEE_FILTER = Decimal(9452957) / COIN
NORMAL_FEE_FILTER = Decimal(100) / COIN

MAX_FEE_FILTER = Decimal(9936506125) / COIN
NORMAL_FEE_FILTER = Decimal(1000) / COIN

class P2PIBDTxRelayTest(DigiByteTestFramework):
def set_test_params(self):
Expand All @@ -25,7 +24,14 @@ def set_test_params(self):
def run_test(self):
self.log.info("Check that nodes set minfilter to MAX_MONEY while still in IBD")
for node in self.nodes:
assert node.getblockchaininfo()['initialblockdownload']
blockchain_info = node.getblockchaininfo()
assert blockchain_info['initialblockdownload']
self.log.info(f"Node {node.index} blockchain info: {blockchain_info}")

peer_info = node.getpeerinfo()
for peer in peer_info:
self.log.info(f"Node {node.index} peer {peer['id']} minfeefilter: {peer['minfeefilter']}")

self.wait_until(lambda: all(peer['minfeefilter'] == MAX_FEE_FILTER for peer in node.getpeerinfo()))

# Come out of IBD by generating a block
Expand All @@ -34,9 +40,15 @@ def run_test(self):

self.log.info("Check that nodes reset minfilter after coming out of IBD")
for node in self.nodes:
assert not node.getblockchaininfo()['initialblockdownload']
self.wait_until(lambda: all(peer['minfeefilter'] == NORMAL_FEE_FILTER for peer in node.getpeerinfo()))
blockchain_info = node.getblockchaininfo()
assert not blockchain_info['initialblockdownload']
self.log.info(f"Node {node.index} blockchain info: {blockchain_info}")

peer_info = node.getpeerinfo()
for peer in peer_info:
self.log.info(f"Node {node.index} peer {peer['id']} minfeefilter: {peer['minfeefilter']}")

self.wait_until(lambda: all(peer['minfeefilter'] == NORMAL_FEE_FILTER for peer in node.getpeerinfo()))

if __name__ == '__main__':
P2PIBDTxRelayTest().main()
15 changes: 10 additions & 5 deletions test/functional/wallet_txn_doublespend.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def run_test(self):
# The fourth address from TestNode.PRIV_KEYS should have
# 41 mature blocks, but only 8 immature blocks.
# This is caused by the different COINBASE_MATURITY parameter in digibyte.
starting_balance = 50 * 72000
starting_balance = 25 * 72000

# All nodes should be out of IBD.
# If the nodes are not all out of IBD, that can interfere with
Expand All @@ -53,7 +53,9 @@ def run_test(self):
assert n.getblockchaininfo()["initialblockdownload"] == False

for i in range(3):
assert_equal(self.nodes[i].getbalance(), starting_balance)
balance = self.nodes[i].getbalance()
print(f"Node {i} balance: {balance}") # Log statement
assert_equal(balance, starting_balance)

# Assign coins to foo and bar addresses:
node0_address_foo = self.nodes[0].getnewaddress()
Expand All @@ -73,7 +75,7 @@ def run_test(self):

# First: use raw transaction API to send 1240 BTC to node1_address,
# but don't broadcast:
doublespend_fee = Decimal('-.02')
doublespend_fee = Decimal('-.2')
rawtx_input_0 = {}
rawtx_input_0["txid"] = fund_foo_txid
rawtx_input_0["vout"] = find_output(self.nodes[0], fund_foo_txid, 1219)
Expand Down Expand Up @@ -107,9 +109,10 @@ def run_test(self):
# In DigiByte, since COINBASE_MATURITY is only set to 8,
# node0's txs are already matured. No emission will mature
# even after calling a block.
expected += 0
expected += 72000
expected += tx1["amount"] + tx1["fee"]
expected += tx2["amount"] + tx2["fee"]
print(f"Node 0 balance: {self.nodes[0].getbalance()}")
assert_equal(self.nodes[0].getbalance(), expected)

if self.options.mine_block:
Expand Down Expand Up @@ -143,7 +146,9 @@ def run_test(self):

# Node0's total balance should be starting balance
# minus 1240 for the double-spend, plus fees (which are negative):
expected = starting_balance - 1240 + fund_foo_tx["fee"] + fund_bar_tx["fee"] + doublespend_fee
expected = starting_balance + 142760 + fund_foo_tx["fee"] + fund_bar_tx["fee"] + doublespend_fee
print(f"Expected balance: {expected}")
print(f"Node 0 balance: {self.nodes[0].getbalance()}")
assert_equal(self.nodes[0].getbalance(), expected)

# Node1's balance should be its initial balance (50 block rewards) plus the doublespend:
Expand Down