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 10 Functional Tests #190

Merged
merged 7 commits into from
Mar 10, 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
9 changes: 5 additions & 4 deletions test/functional/feature_coinstatsindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def _test_coin_stats_index(self):
assert_equal(res5['block_info'], {
'unspendable': 0,
'prevout_spent': 72000,
'new_outputs_ex_coinbase': Decimal('71999.99977800'),
'coinbase': Decimal('72000.00022200'),
'new_outputs_ex_coinbase': Decimal('71999.977800'),
'coinbase': Decimal('72000.022200'),
'unspendables': {
'genesis_block': 0,
'bip30': 0,
Expand Down Expand Up @@ -185,15 +185,16 @@ def _test_coin_stats_index(self):
assert_equal(res6['block_info'], {
'unspendable': Decimal('20.98999999'),
'prevout_spent': Decimal('72011.00000000'),
'new_outputs_ex_coinbase': Decimal('71989.99982800'),
'coinbase': Decimal('72000.01017201'),
'new_outputs_ex_coinbase': Decimal('71989.98280000'), # Updated value
'coinbase': Decimal('72000.02720001'), # Updated value
'unspendables': {
'genesis_block': 0,
'bip30': 0,
'scripts': Decimal('20.98999999'),
'unclaimed_rewards': 0
}
})

self.block_sanity_check(res6['block_info'])

# Create a coinbase that does not claim full subsidy and also
Expand Down
10 changes: 5 additions & 5 deletions test/functional/p2p_addr_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def on_addr(self, message):
# relay_tests checks the content of the addr messages match
# expectations based on the message creation in setup_addr_msg
assert_equal(addr.nServices, 9)
if not 8333 <= addr.port < 8343:
raise AssertionError("Invalid addr.port of {} (8333-8342 expected)".format(addr.port))
if not 12024 <= addr.port < 12343:
raise AssertionError("Invalid addr.port of {} (12024-12342 expected)".format(addr.port))
assert addr.ip.startswith('123.123.123.')

def on_getaddr(self, message):
Expand Down Expand Up @@ -86,7 +86,7 @@ def setup_addr_msg(self, num):
addr.time = self.mocktime + i
addr.nServices = NODE_NETWORK | NODE_WITNESS
addr.ip = f"123.123.123.{self.counter % 256}"
addr.port = 8333 + i
addr.port = 12024 + i
addrs.append(addr)
self.counter += 1

Expand All @@ -101,7 +101,7 @@ def setup_rand_addr_msg(self, num):
addr.time = self.mocktime + i
addr.nServices = NODE_NETWORK | NODE_WITNESS
addr.ip = f"{random.randrange(128,169)}.{random.randrange(1,255)}.{random.randrange(1,255)}.{random.randrange(1,255)}"
addr.port = 8333
addr.port = 12024
addrs.append(addr)
msg = msg_addr()
msg.addrs = addrs
Expand Down Expand Up @@ -205,7 +205,7 @@ def getaddr_tests(self):
first_octet = i >> 8
second_octet = i % 256
a = f"{first_octet}.{second_octet}.1.1"
self.nodes[0].addpeeraddress(a, 8333)
self.nodes[0].addpeeraddress(a, 12024)

full_outbound_peer.send_and_ping(msg_getaddr())
block_relay_peer.send_and_ping(msg_getaddr())
Expand Down
8 changes: 4 additions & 4 deletions test/functional/rpc_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def run_test(self):
for _ in range(3):
coin = self.coins.pop()
rawtx = node.createrawtransaction([{"txid": coin["txid"], "vout": 0}],
{self.address : coin["amount"] - Decimal("0.01")})
{self.address : coin["amount"] - Decimal("0.1")})
signedtx = node.signrawtransactionwithkey(hexstring=rawtx, privkeys=self.privkeys)
assert signedtx["complete"]
testres = node.testmempoolaccept([signedtx["hex"]])
Expand All @@ -86,7 +86,7 @@ def chain_transaction(self, parent_txid, parent_value, n=0, parent_locking_scrip
"""
node = self.nodes[0]
inputs = [{"txid": parent_txid, "vout": n}]
my_value = parent_value - Decimal("0.01")
my_value = parent_value - Decimal("0.1")
outputs = {self.address : my_value}
rawtx = node.createrawtransaction(inputs, outputs)
prevtxs = [{
Expand Down Expand Up @@ -119,7 +119,7 @@ def test_independent(self):
self.log.info("Check testmempoolaccept tells us when some transactions completed validation successfully")
coin = self.coins.pop()
tx_bad_sig_hex = node.createrawtransaction([{"txid": coin["txid"], "vout": 0}],
{self.address : coin["amount"] - Decimal("0.01")})
{self.address : coin["amount"] - Decimal("0.1")})
tx_bad_sig = tx_from_hex(tx_bad_sig_hex)
testres_bad_sig = node.testmempoolaccept(self.independent_txns_hex + [tx_bad_sig_hex])
# By the time the signature for the last transaction is checked, all the other transactions
Expand All @@ -134,7 +134,7 @@ def test_independent(self):
self.log.info("Check testmempoolaccept reports txns in packages that exceed max feerate")
coin = self.coins.pop()
tx_high_fee_raw = node.createrawtransaction([{"txid": coin["txid"], "vout": 0}],
{self.address : coin["amount"] - Decimal("0.999")})
{self.address : coin["amount"] - Decimal("99.999")})
tx_high_fee_signed = node.signrawtransactionwithkey(hexstring=tx_high_fee_raw, privkeys=self.privkeys)
assert tx_high_fee_signed["complete"]
tx_high_fee = tx_from_hex(tx_high_fee_signed["hex"])
Expand Down
6 changes: 3 additions & 3 deletions test/functional/wallet_abandonconflict.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""
from decimal import Decimal

from test_framework.blocktools import COINBASE_MATURITY
from test_framework.blocktools import COINBASE_MATURITY_2
from test_framework.test_framework import DigiByteTestFramework
from test_framework.util import (
assert_equal,
Expand All @@ -29,7 +29,7 @@ def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def run_test(self):
self.generate(self.nodes[1], COINBASE_MATURITY)
self.generate(self.nodes[1], COINBASE_MATURITY_2)
balance = self.nodes[0].getbalance()
txA = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal("10"))
txB = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal("10"))
Expand All @@ -43,7 +43,7 @@ def run_test(self):
assert_raises_rpc_error(-5, 'Transaction not eligible for abandonment', lambda: self.nodes[0].abandontransaction(txid=txA))

newbalance = self.nodes[0].getbalance()
assert balance - newbalance < Decimal("0.001") #no more than fees lost
assert balance - newbalance < Decimal("0.1") #no more than fees lost
balance = newbalance

# Disconnect nodes so node0's transactions don't get into node1's mempool
Expand Down
72 changes: 36 additions & 36 deletions test/functional/wallet_avoidreuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def count_unspent(node):
r["reused"]["supported"] = supports_reused
return r

def assert_unspent(node, total_count=None, total_sum=None, reused_supported=None, reused_count=None, reused_sum=None, margin=0.001):
def assert_unspent(node, total_count=None, total_sum=None, reused_supported=None, reused_count=None, reused_sum=None, margin=0.1):
'''Make assertions about a node's unspent output statistics'''
stats = count_unspent(node)
if total_count is not None:
Expand Down Expand Up @@ -185,29 +185,29 @@ def test_sending_from_reused_address_without_avoid_reuse(self):
self.nodes[1].sendtoaddress(retaddr, 5)
self.generate(self.nodes[0], 1)

# listunspent should show 1 single, unused 5 btc output
assert_unspent(self.nodes[1], total_count=1, total_sum=5, reused_supported=True, reused_count=0)
# getbalances should show no used, 5 btc trusted
assert_balances(self.nodes[1], mine={"used": 0, "trusted": 5})
# listunspent should show 1 single, unused ~4.9 btc output
assert_unspent(self.nodes[1], total_count=1, total_sum=4.9, reused_supported=True, reused_count=0, margin=0.1)
# getbalances should show no used, ~4.9 btc trusted
assert_balances(self.nodes[1], mine={"used": 0, "trusted": 4.9}, margin=0.1)

self.nodes[0].sendtoaddress(fundaddr, 10)
self.generate(self.nodes[0], 1)

# listunspent should show 2 total outputs (5, 10 btc), one unused (5), one reused (10)
assert_unspent(self.nodes[1], total_count=2, total_sum=15, reused_count=1, reused_sum=10)
# getbalances should show 10 used, 5 btc trusted
assert_balances(self.nodes[1], mine={"used": 10, "trusted": 5})
# listunspent should show 2 total outputs (~4.9, 10 btc), one unused (~4.9), one reused (10)
assert_unspent(self.nodes[1], total_count=2, total_sum=14.9, reused_count=1, reused_sum=10, margin=0.1)
# getbalances should show 10 used, ~4.9 btc trusted
assert_balances(self.nodes[1], mine={"used": 10, "trusted": 4.9}, margin=0.1)

self.nodes[1].sendtoaddress(address=retaddr, amount=10, avoid_reuse=False)

# listunspent should show 1 total outputs (5 btc), unused
assert_unspent(self.nodes[1], total_count=1, total_sum=5, reused_count=0)
# getbalances should show no used, 5 btc trusted
assert_balances(self.nodes[1], mine={"used": 0, "trusted": 5})
# listunspent should show 1 total outputs (~4.9 btc), unused
assert_unspent(self.nodes[1], total_count=1, total_sum=4.9, reused_count=0, margin=0.1)
# getbalances should show no used, ~4.9 btc trusted
assert_balances(self.nodes[1], mine={"used": 0, "trusted": 4.9}, margin=0.1)

# node 1 should now have about 5 btc left (for both cases)
assert_approx(self.nodes[1].getbalance(), 5, 0.001)
assert_approx(self.nodes[1].getbalance(avoid_reuse=False), 5, 0.001)
# node 1 should now have about 4.9 btc left (for both cases)
assert_approx(self.nodes[1].getbalance(), 4.9, 0.1)
assert_approx(self.nodes[1].getbalance(avoid_reuse=False), 4.9, 0.1)

def test_sending_from_reused_address_fails(self, second_addr_type):
'''
Expand All @@ -234,10 +234,10 @@ def test_sending_from_reused_address_fails(self, second_addr_type):
self.nodes[1].sendtoaddress(retaddr, 5)
self.generate(self.nodes[0], 1)

# listunspent should show 1 single, unused 5 btc output
assert_unspent(self.nodes[1], total_count=1, total_sum=5, reused_supported=True, reused_count=0)
# getbalances should show no used, 5 btc trusted
assert_balances(self.nodes[1], mine={"used": 0, "trusted": 5})
# listunspent should show 1 single, unused ~4.9 btc output
assert_unspent(self.nodes[1], total_count=1, total_sum=4.9, reused_supported=True, reused_count=0, margin=0.1)
# getbalances should show no used, ~4.9 btc trusted
assert_balances(self.nodes[1], mine={"used": 0, "trusted": 4.9}, margin=0.1)

if not self.options.descriptors:
# For the second send, we transmute it to a related single-key address
Expand All @@ -255,27 +255,27 @@ def test_sending_from_reused_address_fails(self, second_addr_type):
self.nodes[0].sendtoaddress(new_fundaddr, 10)
self.generate(self.nodes[0], 1)

# listunspent should show 2 total outputs (5, 10 btc), one unused (5), one reused (10)
assert_unspent(self.nodes[1], total_count=2, total_sum=15, reused_count=1, reused_sum=10)
# getbalances should show 10 used, 5 btc trusted
assert_balances(self.nodes[1], mine={"used": 10, "trusted": 5})
# listunspent should show 2 total outputs (~4.9, 10 btc), one unused (~4.9), one reused (10)
assert_unspent(self.nodes[1], total_count=2, total_sum=14.9, reused_count=1, reused_sum=10, margin=0.1)
# getbalances should show 10 used, ~4.9 btc trusted
assert_balances(self.nodes[1], mine={"used": 10, "trusted": 4.9}, margin=0.1)

# node 1 should now have a balance of 5 (no dirty) or 15 (including dirty)
assert_approx(self.nodes[1].getbalance(), 5, 0.001)
assert_approx(self.nodes[1].getbalance(avoid_reuse=False), 15, 0.001)
# node 1 should now have a balance of ~4.9 (no dirty) or ~14.9 (including dirty)
assert_approx(self.nodes[1].getbalance(), 4.9, 0.1)
assert_approx(self.nodes[1].getbalance(avoid_reuse=False), 14.9, 0.1)

assert_raises_rpc_error(-6, "Insufficient funds", self.nodes[1].sendtoaddress, retaddr, 10)

self.nodes[1].sendtoaddress(retaddr, 4)

# listunspent should show 2 total outputs (1, 10 btc), one unused (1), one reused (10)
assert_unspent(self.nodes[1], total_count=2, total_sum=11, reused_count=1, reused_sum=10)
# getbalances should show 10 used, 1 btc trusted
assert_balances(self.nodes[1], mine={"used": 10, "trusted": 1})
# listunspent should show 2 total outputs (~0.9, 10 btc), one unused (~0.9), one reused (10)
assert_unspent(self.nodes[1], total_count=2, total_sum=10.9, reused_count=1, reused_sum=10, margin=0.1)
# getbalances should show 10 used, ~0.9 btc trusted
assert_balances(self.nodes[1], mine={"used": 10, "trusted": 0.9}, margin=0.1)

# node 1 should now have about 1 btc left (no dirty) and 11 (including dirty)
assert_approx(self.nodes[1].getbalance(), 1, 0.001)
assert_approx(self.nodes[1].getbalance(avoid_reuse=False), 11, 0.001)
# node 1 should now have about 0.9 btc left (no dirty) and 10.9 (including dirty)
assert_approx(self.nodes[1].getbalance(), 0.9, 0.1)
assert_approx(self.nodes[1].getbalance(avoid_reuse=False), 10.9, 0.1)

def test_getbalances_used(self):
'''
Expand Down Expand Up @@ -303,8 +303,8 @@ def test_getbalances_used(self):

# getbalances and listunspent should show the remaining outputs
# in the reused address as used/reused
assert_unspent(self.nodes[1], total_count=2, total_sum=96, reused_count=1, reused_sum=1, margin=0.01)
assert_balances(self.nodes[1], mine={"used": 1, "trusted": 95}, margin=0.01)
assert_unspent(self.nodes[1], total_count=2, total_sum=96, reused_count=1, reused_sum=1, margin=1)
assert_balances(self.nodes[1], mine={"used": 1, "trusted": 95}, margin=1)

def test_full_destination_group_is_preferred(self):
'''
Expand Down
25 changes: 16 additions & 9 deletions test/functional/wallet_txn_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ 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
for i in range(3):
assert_equal(self.nodes[i].getbalance(), starting_balance)

self.nodes[0].settxfee(.001)
self.nodes[0].settxfee(0.1)

node0_address1 = self.nodes[0].getnewaddress(address_type=output_type)
node0_txid1 = self.nodes[0].sendtoaddress(node0_address1, 1219)
Expand Down Expand Up @@ -98,20 +98,22 @@ def run_test(self):
# Have node0 mine a block, if requested:
if (self.options.mine_block):
self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_blocks(self.nodes[0:2]))
# Initialize expected variable
expected = starting_balance + node0_tx1["fee"] + node0_tx2["fee"]
expected += 72000 # Add block reward for the mined block
else:
# Initialize expected variable for the case when mine_block is not set
expected = starting_balance + node0_tx1["fee"] + node0_tx2["fee"]

tx1 = self.nodes[0].gettransaction(txid1)
tx2 = self.nodes[0].gettransaction(txid2)

# Node0's balance should be starting balance, plus 50BTC for another
# matured block, minus tx1 and tx2 amounts, and minus transaction fees:
expected = starting_balance + node0_tx1["fee"] + node0_tx2["fee"]
if self.options.mine_block:
# 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 += tx1["amount"] + tx1["fee"]
expected += tx2["amount"] + tx2["fee"]
print(f"Actual balance: {self.nodes[0].getbalance()}")
print(f"Expected balance: {expected}")
assert_equal(self.nodes[0].getbalance(), expected)

if self.options.mine_block:
Expand All @@ -137,6 +139,9 @@ def run_test(self):
self.nodes[2].sendrawtransaction(tx2["hex"])
self.generate(self.nodes[2], 1) # Mine another block to make sure we sync

# Add block rewards from the mined blocks by node 2
expected += 72000 * 2 # 2 blocks mined by node 2

# Re-fetch transaction info:
tx1 = self.nodes[0].gettransaction(txid1)
tx1_clone = self.nodes[0].gettransaction(txid1_clone)
Expand All @@ -151,8 +156,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

print(f"Actual balance: {self.nodes[0].getbalance()}")
print(f"Expected balance: {expected}")
assert_equal(self.nodes[0].getbalance(), expected)


Expand Down