Skip to content

Commit

Permalink
Merge pull request #193 from JaredTate/develop
Browse files Browse the repository at this point in the history
Fix p2p_ibd_txrelay.py Test & wallet_txn_doublespend.py (4 tests)
  • Loading branch information
ycagel authored Mar 12, 2024
2 parents 3fd7c74 + d201d4b commit d4089cc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
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

0 comments on commit d4089cc

Please sign in to comment.