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

Functional tests #49

Closed
wants to merge 6 commits into from
Closed
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
1 change: 0 additions & 1 deletion debian.minimal/copyright
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,6 @@ Files: Makefile.am
test/functional/wallet_balance.py
test/functional/wallet_basic.py
test/functional/wallet_bumpfee.py
test/functional/wallet_bumpfee_totalfee_deprecation.py
test/functional/wallet_coinbase_category.py
test/functional/wallet_create_tx.py
test/functional/wallet_createwallet.py
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "gettxout", 1, "n" },
{ "gettxout", 2, "include_mempool" },
{ "gettxoutproof", 0, "txids" },
{ "gettxoutsetinfo", 1, "hash_or_height" },
{ "gettxoutsetinfo", 2, "use_index"},
{ "lockunspent", 0, "unlock" },
{ "lockunspent", 1, "transactions" },
{ "lockunspent", 2, "persistent" },
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_blockfilterindex_prune.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def run_test(self):

self.log.info("prune some blocks")
pruneheight = self.nodes[0].pruneblockchain(1000)
assert_equal(pruneheight, 506)
assert_equal(pruneheight, 504)

self.log.info("check if we can access the tips blockfilter when we have pruned some blocks")
assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getbestblockhash())['filter']), 0)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_uacomment.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def run_test(self):
self.nodes[0].assert_start_raises_init_error(["-uacomment=" + 'a' * 256], expected, match=ErrorMatch.FULL_REGEX)

self.log.info("test -uacomment unsafe characters")
for unsafe_char in ['/', ':', '(', ')', '₿', '🏃']:
for unsafe_char in ['/', ':', '(', ')']:
expected = r"Error: User Agent comment \(" + re.escape(unsafe_char) + r"\) contains unsafe characters."
self.nodes[0].assert_start_raises_init_error(["-uacomment=" + unsafe_char], expected, match=ErrorMatch.FULL_REGEX)

Expand Down
3 changes: 1 addition & 2 deletions test/functional/mempool_updatefromblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ def transaction_graph_test(self, size, n_tx_to_mine=None, start_input_txid='', e
assert_equal(entry['ancestorsize'], sum(tx_size[0:(k + 1)]))

def run_test(self):
# Use batch size limited by DEFAULT_ANCESTOR_LIMIT = 25 to not fire "too many unconfirmed parents" error.
self.transaction_graph_test(size=100, n_tx_to_mine=[25, 50, 75])
self.transaction_graph_test(size=90, n_tx_to_mine=[15, 30, 45, 60, 75])


if __name__ == '__main__':
Expand Down
7 changes: 1 addition & 6 deletions test/functional/p2p_eviction.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,11 @@ def run_test(self):
prevtx = node.getblock(node.getblockhash(i + 1), 2)['tx'][0]
rawtx = node.createrawtransaction(
inputs=[{'txid': prevtx['txid'], 'vout': 0}],
outputs=[{node.get_deterministic_priv_key().address: 50 - 0.00125}],
outputs=[{node.get_deterministic_priv_key().address: 200 - 0.00125}],
)
sigtx = node.signrawtransactionwithkey(
hexstring=rawtx,
privkeys=[node.get_deterministic_priv_key().key],
prevtxs=[{
'txid': prevtx['txid'],
'vout': 0,
'scriptPubKey': prevtx['vout'][0]['scriptPubKey']['hex'],
}],
)['hex']
txpeer.send_message(msg_tx(tx_from_hex(sigtx)))
protected_peers.add(current_peer)
Expand Down
21 changes: 4 additions & 17 deletions test/functional/p2p_invalid_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def run_test(self):
block_time += 1

# b'0x51' is OP_TRUE
tx1 = create_tx_with_script(block1.vtx[0], 0, script_sig=b'\x51', amount=50 * COIN)
tx2 = create_tx_with_script(tx1, 0, script_sig=b'\x51', amount=50 * COIN)
tx1 = create_tx_with_script(block1.vtx[0], 0, script_sig=b'\x51', amount=200 * COIN)
tx2 = create_tx_with_script(tx1, 0, script_sig=b'\x51', amount=200 * COIN)

block2.vtx.extend([tx1, tx2])
block2.hashMerkleRoot = block2.calc_merkle_root()
Expand Down Expand Up @@ -103,7 +103,7 @@ def run_test(self):

block3 = create_block(tip, create_coinbase(height), block_time)
block_time += 1
block3.vtx[0].vout[0].nValue = 100 * COIN # Too high!
block3.vtx[0].vout[0].nValue = 600 * COIN # Too high!
block3.vtx[0].sha256 = None
block3.vtx[0].calc_sha256()
block3.hashMerkleRoot = block3.calc_merkle_root()
Expand All @@ -127,7 +127,7 @@ def run_test(self):
# Complete testing of CVE-2018-17144, by checking for the inflation bug.
# Create a block that spends the output of a tx in a previous block.
block4 = create_block(tip, create_coinbase(height), block_time)
tx3 = create_tx_with_script(tx2, 0, script_sig=b'\x51', amount=50 * COIN)
tx3 = create_tx_with_script(tx2, 0, script_sig=b'\x51', amount=200 * COIN)

# Duplicates input
tx3.vin.append(tx3.vin[0])
Expand All @@ -139,18 +139,5 @@ def run_test(self):
self.log.info("Test inflation by duplicating input")
peer.send_blocks_and_test([block4], node, success=False, reject_reason='bad-txns-inputs-duplicate')

self.log.info("Test accepting identical block after rejecting it due to a future timestamp.")
t = int(time.time())
node.setmocktime(t)
# Set block time +1 second past max future validity
block = create_block(tip, create_coinbase(height), t + MAX_FUTURE_BLOCK_TIME + 1)
block.hashMerkleRoot = block.calc_merkle_root()
block.solve()
# Need force_send because the block will get rejected without a getdata otherwise
peer.send_blocks_and_test([block], node, force_send=True, success=False, reject_reason='time-too-new')
node.setmocktime(t + 1)
peer.send_blocks_and_test([block], node, success=True)


if __name__ == '__main__':
InvalidBlockRequestTest().main()
6 changes: 2 additions & 4 deletions test/functional/p2p_timeouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ def run_test(self):
assert no_version_node.is_connected
assert no_send_node.is_connected

with self.nodes[0].assert_debug_log(['Unsupported message "ping" prior to verack from peer=0']):
no_verack_node.send_message(msg_ping())
with self.nodes[0].assert_debug_log(['non-version message before version handshake. Message "ping" from peer=1']):
no_version_node.send_message(msg_ping())
no_verack_node.send_message(msg_ping())
no_version_node.send_message(msg_ping())

sleep(1)

Expand Down
33 changes: 16 additions & 17 deletions test/functional/rpc_scantxoutset.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@ def run_test(self):
self.nodes[0].sendtoaddress(addr_BECH32, 0.004)

#send to child keys of tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK
self.nodes[0].sendtoaddress("mkHV1C6JLheLoUSSZYk7x3FH5tnx9bu7yc", 0.008) # (m/0'/0'/0')
self.nodes[0].sendtoaddress("mipUSRmJAj2KrjSvsPQtnP8ynUon7FhpCR", 0.016) # (m/0'/0'/1')
self.nodes[0].sendtoaddress("n37dAGe6Mq1HGM9t4b6rFEEsDGq7Fcgfqg", 0.032) # (m/0'/0'/1500')
self.nodes[0].sendtoaddress("mqS9Rpg8nNLAzxFExsgFLCnzHBsoQ3PRM6", 0.064) # (m/0'/0'/0)
self.nodes[0].sendtoaddress("mnTg5gVWr3rbhHaKjJv7EEEc76ZqHgSj4S", 0.128) # (m/0'/0'/1)
self.nodes[0].sendtoaddress("mketCd6B9U9Uee1iCsppDJJBHfvi6U6ukC", 0.256) # (m/0'/0'/1500)
self.nodes[0].sendtoaddress("mj8zFzrbBcdaWXowCQ1oPZ4qioBVzLzAp7", 0.512) # (m/1/1/0')
self.nodes[0].sendtoaddress("mfnKpKQEftniaoE1iXuMMePQU3PUpcNisA", 1.024) # (m/1/1/1')
self.nodes[0].sendtoaddress("mou6cB1kaP1nNJM1sryW6YRwnd4shTbXYQ", 2.048) # (m/1/1/1500')
self.nodes[0].sendtoaddress("mtfUoUax9L4tzXARpw1oTGxWyoogp52KhJ", 4.096) # (m/1/1/0)
self.nodes[0].sendtoaddress("mxp7w7j8S1Aq6L8StS2PqVvtt4HGxXEvdy", 8.192) # (m/1/1/1)
self.nodes[0].sendtoaddress("mpQ8rokAhp1TAtJQR6F6TaUmjAWkAWYYBq", 16.384) # (m/1/1/1500)
self.nodes[0].sendtoaddress("rbgl1qx3x8pd2j82774x9v5jtrt67v6eq0xg33h9wtfn", 0.008) # (m/0'/0'/0')
self.nodes[0].sendtoaddress("rbgl1qysufe22kf66mz3jtq33f0d88arruws4ye5egv0", 0.016) # (m/0'/0'/1')
self.nodes[0].sendtoaddress("rbgl1qan5n5jj47futj90060396taeegswnhusutx05j", 0.032) # (m/0'/0'/1500')

self.nodes[0].sendtoaddress("rbgl1qdny83c9q5x3glq86aa68gevelzqwwu9qhdhxqa", 0.064) # (m/0'/0'/0)
self.nodes[0].sendtoaddress("rbgl1qfs4pjvfdkscn82qraqvvwahw0fyd20ykgp4hjd", 0.128) # (m/0'/0'/1)
self.nodes[0].sendtoaddress("rbgl1q8pvg59ekgx6lryuysvqf4ljtgyjr8nsl3kl00s", 0.256) # (m/0'/0'/1500)

self.nodes[0].sendtoaddress("rbgl1qy7u0mmtl4qz4833p8f43v63m7nqmscls6jgxc8", 0.512) # (m/1/1/0')
self.nodes[0].sendtoaddress("rbgl1qqt5rga2600fjzhlvh89p8qy7nyrp9e6807hwha", 1.024) # (m/1/1/1')
self.nodes[0].sendtoaddress("rbgl1qt0c33ft6cfw852p6chqvqpkwxvmfl8vnzy02zv", 2.048) # (m/1/1/1500')

self.nodes[0].sendtoaddress("rbgl1qjqmxmkpmxt80xz4y3746zgt0q3u3ferrg2ss57", 4.096) # (m/1/1/0)
self.nodes[0].sendtoaddress("rbgl1qhku5rq7jz8ulufe2y6fkcpnlvpsta7rqv2cz5w", 8.192) # (m/1/1/1)
self.nodes[0].sendtoaddress("rbgl1qv9hs5rhkgcx0ef6f9g26k3k83hmhugjtart6dr", 16.384) # (m/1/1/1500)


self.generate(self.nodes[0], 1)
Expand Down Expand Up @@ -84,7 +87,7 @@ def run_test(self):

self.log.info("Test extended key derivation.")
# Run various scans, and verify that the sum of the amounts of the matches corresponds to the expected subset.
# Note that all amounts in the UTXO set are powers of 2 multiplied by 0.001 BTC, so each amounts uniquely identifies a subset.
# Note that all amounts in the UTXO set are powers of 2 multiplied by 0.001 BGL, so each amounts uniquely identifies a subset.
assert_equal(self.nodes[0].scantxoutset("start", [ "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0'/0h/0h)"])['total_amount'], Decimal("0.008"))
assert_equal(self.nodes[0].scantxoutset("start", [ "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0'/0'/1h)"])['total_amount'], Decimal("0.016"))
assert_equal(self.nodes[0].scantxoutset("start", [ "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0h/0'/1500')"])['total_amount'], Decimal("0.032"))
Expand Down Expand Up @@ -112,10 +115,6 @@ def run_test(self):
assert_equal(self.nodes[0].scantxoutset("start", [ {"desc": "combo(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/*)", "range": 1500}])['total_amount'], Decimal("28.672"))
assert_equal(self.nodes[0].scantxoutset("start", [ {"desc": "combo(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/*)", "range": [1500,1500]}])['total_amount'], Decimal("16.384"))

# Test the reported descriptors for a few matches
assert_equal(descriptors(self.nodes[0].scantxoutset("start", [ {"desc": "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0h/0'/*)", "range": 1499}])), ["pkh([0c5f9a1e/0'/0'/0]026dbd8b2315f296d36e6b6920b1579ca75569464875c7ebe869b536a7d9503c8c)#dzxw429x", "pkh([0c5f9a1e/0'/0'/1]033e6f25d76c00bedb3a8993c7d5739ee806397f0529b1b31dda31ef890f19a60c)#43rvceed"])
assert_equal(descriptors(self.nodes[0].scantxoutset("start", [ "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/0)"])), ["pkh([0c5f9a1e/1/1/0]03e1c5b6e650966971d7e71ef2674f80222752740fc1dfd63bbbd220d2da9bd0fb)#cxmct4w8"])
assert_equal(descriptors(self.nodes[0].scantxoutset("start", [ {"desc": "combo(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/*)", "range": 1500}])), ['pkh([0c5f9a1e/1/1/0]03e1c5b6e650966971d7e71ef2674f80222752740fc1dfd63bbbd220d2da9bd0fb)#cxmct4w8', 'pkh([0c5f9a1e/1/1/1500]03832901c250025da2aebae2bfb38d5c703a57ab66ad477f9c578bfbcd78abca6f)#vchwd07g', 'pkh([0c5f9a1e/1/1/1]030d820fc9e8211c4169be8530efbc632775d8286167afd178caaf1089b77daba7)#z2t3ypsa'])

# Check that status and abort don't need second arg
assert_equal(self.nodes[0].scantxoutset("status"), None)
Expand Down
9 changes: 4 additions & 5 deletions test/functional/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def __init__(self):
self.rpc_timeout = 60 # Wait for up to 60 seconds for the RPC server to respond
self.supports_cli = True
self.bind_to_localhost_only = True
self.set_test_params()
self.parse_args()
self.disable_syscall_sandbox = self.options.nosandbox
self.default_wallet_name = "default_wallet" if self.options.descriptors else ""
Expand Down Expand Up @@ -735,7 +734,6 @@ def _start_logging(self):

def _initialize_chain(self):
"""Initialize a pre-mined blockchain for use by the test.

Create a cache of a 199-block-long chain
Afterward, create num_nodes copies from the cache."""

Expand Down Expand Up @@ -778,12 +776,13 @@ def _initialize_chain(self):
# block in the cache does not age too much (have an old tip age).
# This is needed so that we are out of IBD when the test starts,
# see the tip age check in IsInitialBlockDownload().
gen_addresses = [k.address for k in TestNode.PRIV_KEYS] + [ADDRESS_BCRT1_P2WSH_OP_TRUE]
gen_addresses = [k.address for k in TestNode.PRIV_KEYS][:3] + [ADDRESS_BCRT1_P2WSH_OP_TRUE]
assert_equal(len(gen_addresses), 4)
for i in range(8):
self.generatetoaddress(
cache_node,
nblocks=25 if i != 7 else 24,
address=gen_addresses[i % 4],
address=gen_addresses[i % len(gen_addresses)],
)

assert_equal(cache_node.getblockchaininfo()["blocks"], 199)
Expand All @@ -797,7 +796,7 @@ def cache_path(*paths):

os.rmdir(cache_path('wallets')) # Remove empty wallets dir
for entry in os.listdir(cache_path()):
if entry not in ['chainstate', 'blocks']: # Only keep chainstate and blocks folder
if entry not in ['chainstate', 'blocks', 'indexes']: # Only indexes, chainstate and blocks folders
os.remove(cache_path(entry))

for i in range(self.num_nodes):
Expand Down
4 changes: 2 additions & 2 deletions test/functional/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ def gen_return_txouts():
# Some pre-processing to create a bunch of OP_RETURN txouts to insert into transactions we create
# So we have big transactions (and therefore can't fit very many into each block)
# create one script_pubkey
script_pubkey = "6a4d0200" # OP_RETURN OP_PUSH2 512 bytes
for _ in range(512):
script_pubkey = "6a4d0200" # OP_RETURN OP_PUSH2 128 bytes
for _ in range(128):
script_pubkey = script_pubkey + "01"
# concatenate 128 txouts of above script_pubkey which we'll insert before the txout for change
txouts = []
Expand Down
6 changes: 3 additions & 3 deletions test/functional/wallet_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,9 @@ def run_test(self):

# Test getaddressinfo on external address. Note that these addresses are taken from disablewallet.py
assert_raises_rpc_error(-5, "Invalid prefix for Base58-encoded address", self.nodes[0].getaddressinfo, "3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy")
address_info = self.nodes[0].getaddressinfo("mneYUmWYsuk7kySiURxCi3AGxrAqZxLgPZ")
assert_equal(address_info['address'], "mneYUmWYsuk7kySiURxCi3AGxrAqZxLgPZ")
assert_equal(address_info["scriptPubKey"], "76a9144e3854046c7bd1594ac904e4793b6a45b36dea0988ac")
address_info = self.nodes[0].getaddressinfo("rbgl1qdny83c9q5x3glq86aa68gevelzqwwu9qhdhxqa")
assert_equal(address_info['address'], "rbgl1qdny83c9q5x3glq86aa68gevelzqwwu9qhdhxqa")
assert_equal(address_info["scriptPubKey"], "00146cc878e0a0a1a28f80faef74746599f880e770a0")
assert not address_info["ismine"]
assert not address_info["iswatchonly"]
assert not address_info["isscript"]
Expand Down
54 changes: 0 additions & 54 deletions test/functional/wallet_bumpfee_totalfee_deprecation.py

This file was deleted.

16 changes: 8 additions & 8 deletions test/functional/wallet_txn_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ def run_test(self):
else:
output_type = "legacy"

# All nodes should start with 1,250 BTC:
starting_balance = 1250
# All nodes should start with 5000 BGL:
starting_balance = 5000
for i in range(3):
assert_equal(self.nodes[i].getbalance(), starting_balance)

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

node0_address1 = self.nodes[0].getnewaddress(address_type=output_type)
node0_txid1 = self.nodes[0].sendtoaddress(node0_address1, 1219)
node0_txid1 = self.nodes[0].sendtoaddress(node0_address1, 4969)
node0_tx1 = self.nodes[0].gettransaction(node0_txid1)
self.nodes[0].lockunspent(False, [{"txid":node0_txid1, "vout": find_vout_for_address(self.nodes[0], node0_txid1, node0_address1)}])

Expand Down Expand Up @@ -97,11 +97,11 @@ def run_test(self):
tx1 = self.nodes[0].gettransaction(txid1)
tx2 = self.nodes[0].gettransaction(txid2)

# Node0's balance should be starting balance, plus 50BTC for another
# Node0's balance should be starting balance, plus 200 BGL 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:
expected += 50
expected += 200
expected += tx1["amount"] + tx1["fee"]
expected += tx2["amount"] + tx2["fee"]
assert_equal(self.nodes[0].getbalance(), expected)
Expand Down Expand Up @@ -140,11 +140,11 @@ def run_test(self):
assert_equal(tx1_clone["confirmations"], 2)
assert_equal(tx2["confirmations"], 1)

# Check node0's total balance; should be same as before the clone, + 100 BTC for 2 matured,
# Check node0's total balance; should be same as before the clone, + 400 BGL for 2 matured,
# less possible orphaned matured subsidy
expected += 100
expected += 400
if (self.options.mine_block):
expected -= 50
expected -= 200
assert_equal(self.nodes[0].getbalance(), expected)


Expand Down
Loading