Skip to content
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
3 changes: 1 addition & 2 deletions test/functional/example_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ def run_test(self):
peer_messaging = self.nodes[0].add_p2p_connection(BaseNode())

# Generating a block on one of the nodes will get us out of IBD
blocks = [int(self.nodes[0].generate(nblocks=1)[0], 16)]
self.sync_all(self.nodes[0:2])
blocks = [int(self.generate(self.nodes[0], sync_fun=lambda: self.sync_all(self.nodes[0:2]), nblocks=1)[0], 16)]

# Notice above how we called an RPC by calling a method with the same
# name on the node object. Notice also how we used a keyword argument
Expand Down
6 changes: 3 additions & 3 deletions test/functional/feature_abortnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ def setup_network(self):
# We'll connect the nodes later

def run_test(self):
self.nodes[0].generate(3)
self.generate(self.nodes[0], 3, sync_fun=self.no_op)
datadir = get_datadir_path(self.options.tmpdir, 0)

# Deleting the undo file will result in reorg failure
os.unlink(os.path.join(datadir, self.chain, 'blocks', 'rev00000.dat'))

# Connecting to a node with a more work chain will trigger a reorg
# attempt.
self.nodes[1].generate(3)
self.generate(self.nodes[1], 3, sync_fun=self.no_op)
with self.nodes[0].assert_debug_log(["Failed to disconnect block"]):
self.connect_nodes(0, 1)
self.nodes[1].generate(1)
self.generate(self.nodes[1], 1, sync_fun=self.no_op)

# Check that node0 aborted
self.log.info("Waiting for crash")
Expand Down
39 changes: 15 additions & 24 deletions test/functional/feature_addressindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def run_test(self):

self.log.info("Mining blocks...")
mining_address = self.nodes[0].getnewaddress()
self.nodes[0].generatetoaddress(105, mining_address)
self.sync_all()
self.generatetoaddress(self.nodes[0], 105, mining_address)

chain_height = self.nodes[1].getblockcount()
assert_equal(chain_height, 105)
Expand All @@ -72,24 +71,22 @@ def run_test(self):
self.log.info("Testing p2pkh and p2sh address index...")

txid0 = self.nodes[0].sendtoaddress("yMNJePdcKvXtWWQnFYHNeJ5u8TF2v1dfK4", 10)
self.nodes[0].generate(1)
self.generate(self.nodes[0], 1, sync_fun=self.no_op)

txidb0 = self.nodes[0].sendtoaddress("93bVhahvUKmQu8gu9g3QnPPa2cxFK98pMB", 10)
self.nodes[0].generate(1)
self.generate(self.nodes[0], 1, sync_fun=self.no_op)

txid1 = self.nodes[0].sendtoaddress("yMNJePdcKvXtWWQnFYHNeJ5u8TF2v1dfK4", 15)
self.nodes[0].generate(1)
self.generate(self.nodes[0], 1, sync_fun=self.no_op)

txidb1 = self.nodes[0].sendtoaddress("93bVhahvUKmQu8gu9g3QnPPa2cxFK98pMB", 15)
self.nodes[0].generate(1)
self.generate(self.nodes[0], 1, sync_fun=self.no_op)

txid2 = self.nodes[0].sendtoaddress("yMNJePdcKvXtWWQnFYHNeJ5u8TF2v1dfK4", 20)
self.nodes[0].generate(1)
self.generate(self.nodes[0], 1, sync_fun=self.no_op)

txidb2 = self.nodes[0].sendtoaddress("93bVhahvUKmQu8gu9g3QnPPa2cxFK98pMB", 20)
self.nodes[0].generate(1)

self.sync_all()
self.generate(self.nodes[0], 1)

txids = self.nodes[1].getaddresstxids("yMNJePdcKvXtWWQnFYHNeJ5u8TF2v1dfK4")
assert_equal(len(txids), 3)
Expand Down Expand Up @@ -141,8 +138,7 @@ def run_test(self):
signed_tx = self.nodes[0].signrawtransactionwithwallet(tx.serialize().hex())
sent_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], 0)

self.nodes[0].generate(1)
self.sync_all()
self.generate(self.nodes[0], 1)

txidsmany = self.nodes[1].getaddresstxids("93bVhahvUKmQu8gu9g3QnPPa2cxFK98pMB")
assert_equal(len(txidsmany), 4)
Expand Down Expand Up @@ -170,8 +166,7 @@ def run_test(self):
tx.rehash()
signed_tx = self.nodes[0].signrawtransactionwithwallet(tx.serialize().hex())
spending_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], 0)
self.nodes[0].generate(1)
self.sync_all()
self.generate(self.nodes[0], 1)
balance1 = self.nodes[1].getaddressbalance(address2)
assert_equal(balance1["balance"], amount)

Expand All @@ -184,8 +179,7 @@ def run_test(self):

signed_tx = self.nodes[0].signrawtransactionwithwallet(tx.serialize().hex())
sent_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], 0)
self.nodes[0].generate(1)
self.sync_all()
self.generate(self.nodes[0], 1)

balance2 = self.nodes[1].getaddressbalance(address2)
assert_equal(balance2["balance"], change_amount)
Expand Down Expand Up @@ -233,13 +227,12 @@ def run_test(self):
assert_equal(utxos2[0]["satoshis"], amount)

# Check sorting of utxos
self.nodes[2].generate(150)
self.generate(self.nodes[2], 150, sync_fun=self.no_op)

self.nodes[2].sendtoaddress(address2, 50)
self.nodes[2].generate(1)
self.generate(self.nodes[2], 1, sync_fun=self.no_op)
self.nodes[2].sendtoaddress(address2, 50)
self.nodes[2].generate(1)
self.sync_all()
self.generate(self.nodes[2], 1)

utxos3 = self.nodes[1].getaddressutxos({"addresses": [address2]})
assert_equal(len(utxos3), 3)
Expand Down Expand Up @@ -291,8 +284,7 @@ def run_test(self):
assert_equal(mempool[2]["txid"], memtxid2)
assert_equal(mempool[2]["index"], 1)

self.nodes[2].generate(1)
self.sync_all()
self.generate(self.nodes[2], 1)
mempool2 = self.nodes[2].getaddressmempool({"addresses": [address3]})
assert_equal(len(mempool2), 0)

Expand Down Expand Up @@ -322,8 +314,7 @@ def run_test(self):
address1script = CScript([OP_DUP, OP_HASH160, address1hash, OP_EQUALVERIFY, OP_CHECKSIG])

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

utxos = self.nodes[1].getaddressutxos({"addresses": [address1]})
assert_equal(len(utxos), 1)
Expand Down
67 changes: 23 additions & 44 deletions test/functional/feature_asset_locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ def generate_batch(self, count):
batch = min(50, count)
count -= batch
self.bump_mocktime(batch)
self.nodes[1].generate(batch)
self.sync_all()
self.generate(self.nodes[1], batch)

# This functional test intentionally setup only 2 MN and only 2 Evo nodes
# to ensure that corner case of quorum with minimum amount of nodes as possible
Expand All @@ -256,12 +255,10 @@ def run_test(self):

for _ in range(2):
self.dynamically_add_masternode(evo=True)
node.generate(8)
self.sync_blocks()
self.generate(node, 8, sync_fun=lambda: self.sync_blocks())

self.set_sporks()
node.generate(1)
self.sync_all()
self.generate(node, 1)
self.mempool_size = 0

key = ECKey()
Expand Down Expand Up @@ -295,11 +292,10 @@ def test_asset_locks(self, node_wallet, node, pubkey):
assert_equal(rpc_tx["assetLockTx"]["creditOutputs"][0]["scriptPubKey"]["hex"], key_to_p2pkh_script(pubkey).hex())
assert_equal(rpc_tx["assetLockTx"]["creditOutputs"][1]["scriptPubKey"]["hex"], key_to_p2pkh_script(pubkey).hex())
self.validate_credit_pool_balance(0)
node.generate(1)
self.generate(node, 1, sync_fun=self.no_op)
assert_equal(self.get_credit_pool_balance(node=node), locked_1)
self.log.info("Generate a number of blocks to ensure this is the longest chain for later in the test when we reconsiderblock")
node.generate(12)
self.sync_all()
self.generate(node, 12)

self.validate_credit_pool_balance(locked_1)

Expand All @@ -309,15 +305,13 @@ def test_asset_locks(self, node_wallet, node, pubkey):
for inode in self.nodes:
inode.invalidateblock(self.block_hash_1)
assert_equal(self.get_credit_pool_balance(node=inode), 0)
node.generate(3)
self.sync_all()
self.generate(node, 3)
self.validate_credit_pool_balance(0)
self.log.info("Resubmit asset lock tx to new chain...")
# NEW tx appears
asset_lock_tx_2 = self.create_assetlock(coin, locked_2, pubkey)
txid_in_block = self.send_tx(asset_lock_tx_2)
node.generate(1)
self.sync_all()
self.generate(node, 1)
self.validate_credit_pool_balance(locked_2)
self.log.info("Reconsider old blocks...")
for inode in self.nodes:
Expand Down Expand Up @@ -401,8 +395,7 @@ def test_asset_unlocks(self, node_wallet, node, pubkey):
self.mempool_size += 2
self.check_mempool_size()
self.validate_credit_pool_balance(locked)
node.generate(1)
self.sync_all()
self.generate(node, 1)
assert_equal(rawtx["instantlock"], False)
assert_equal(rawtx["chainlock"], False)
rawtx = node.getrawtransaction(txid, 1)
Expand All @@ -424,15 +417,13 @@ def test_asset_unlocks(self, node_wallet, node, pubkey):
self.log.info("Checking credit pool amount still is same...")
self.validate_credit_pool_balance(locked - 1 * COIN)
self.send_tx(asset_unlock_tx_late)
node.generate(1)
self.sync_all()
self.generate(node, 1)
self.validate_credit_pool_balance(locked - 2 * COIN)

self.log.info("Generating many blocks to make quorum far behind (even still active)...")
self.generate_batch(too_late_height - node.getblockcount() - 1)
self.check_mempool_result(tx=asset_unlock_tx_too_late, result_expected={'allowed': True, 'fees': {'base': Decimal(str(tiny_amount / COIN))}})
node.generate(1)
self.sync_all()
self.generate(node, 1)
self.check_mempool_result(tx=asset_unlock_tx_too_late,
result_expected={'allowed': False, 'reject-reason' : 'bad-assetunlock-too-late'})

Expand All @@ -456,8 +447,7 @@ def test_asset_unlocks(self, node_wallet, node, pubkey):
self.log.info("Forcibly mining asset_unlock_tx_too_late and ensure block is invalid")
self.create_and_check_block([asset_unlock_tx_too_late], expected_error = "bad-assetunlock-not-active-quorum")

node.generate(1)
self.sync_all()
self.generate(node, 1)

self.validate_credit_pool_balance(locked - 2 * COIN)
self.validate_credit_pool_balance(block_hash=self.block_hash_1, expected=locked)
Expand All @@ -476,8 +466,7 @@ def test_withdrawal_limits(self, node_wallet, node, pubkey):
self.check_mempool_result(tx=asset_unlock_tx_full, result_expected={'allowed': True, 'fees': {'base': Decimal(str(tiny_amount / COIN))}})

txid_in_block = self.send_tx(asset_unlock_tx_full)
node.generate(1)
self.sync_all()
self.generate(node, 1)

self.ensure_tx_is_not_mined(txid_in_block)

Expand All @@ -490,8 +479,7 @@ def test_withdrawal_limits(self, node_wallet, node, pubkey):

txid_in_block = self.send_tx(asset_unlock_tx_full)
expected_balance = (Decimal(self.get_credit_pool_balance()) - Decimal(tiny_amount))
node.generate(1)
self.sync_all()
self.generate(node, 1)
self.log.info("Check txid_in_block was mined")
block = node.getblock(node.getbestblockhash())
assert txid_in_block in block['tx']
Expand All @@ -508,7 +496,7 @@ def test_withdrawal_limits(self, node_wallet, node, pubkey):
self.check_mempool_result(tx=spend_withdrawal, result_expected={'allowed': True, 'fees': {'base': Decimal(str(tiny_amount / COIN))}})
spend_txid_in_block = self.send_tx(spend_withdrawal)

node.generate(1)
self.generate(node, 1, sync_fun=self.no_op)
block = node.getblock(node.getbestblockhash())
assert spend_txid_in_block in block['tx']

Expand All @@ -528,8 +516,7 @@ def test_withdrawal_limits(self, node_wallet, node, pubkey):
self.send_tx_simple(tx)
self.log.info(f"Collecting coins in pool... Collected {total}/{10_901 * COIN}")
self.sync_mempools()
node.generate(1)
self.sync_all()
self.generate(node, 1)
credit_pool_balance_1 = self.get_credit_pool_balance()
assert_greater_than(credit_pool_balance_1, 10_901 * COIN)
limit_amount_1 = 1000 * COIN
Expand All @@ -548,8 +535,7 @@ def test_withdrawal_limits(self, node_wallet, node, pubkey):
node.prioritisetransaction(last_txid, next_amount // 10000)

self.sync_mempools()
node.generate(1)
self.sync_all()
self.generate(node, 1)

new_total = self.get_credit_pool_balance()
amount_actually_withdrawn = total - new_total
Expand All @@ -561,8 +547,7 @@ def test_withdrawal_limits(self, node_wallet, node, pubkey):
assert_greater_than_or_equal(limit_amount_1, amount_actually_withdrawn)
assert_equal(amount_actually_withdrawn, 900 * COIN + 10001)

node.generate(1)
self.sync_all()
self.generate(node, 1)
self.log.info("Checking that exactly 1 tx stayed in mempool...")
self.mempool_size = 1
self.check_mempool_size()
Expand All @@ -575,8 +560,7 @@ def test_withdrawal_limits(self, node_wallet, node, pubkey):
asset_unlock_tx = self.create_assetunlock(index, amount_to_withdraw_2, pubkey)
self.send_tx_simple(asset_unlock_tx)
self.sync_mempools()
node.generate(1)
self.sync_all()
self.generate(node, 1)
new_total = self.get_credit_pool_balance()
amount_actually_withdrawn = total - new_total
assert_equal(limit_amount_1, amount_actually_withdrawn)
Expand All @@ -599,19 +583,16 @@ def test_withdrawal_limits(self, node_wallet, node, pubkey):
index += 1
asset_unlock_tx = self.create_assetunlock(index, limit_amount_2, pubkey)
self.send_tx(asset_unlock_tx)
node.generate(1)
self.sync_all()
self.generate(node, 1)
assert_equal(new_total, self.get_credit_pool_balance())
node.generate(1)
self.sync_all()
self.generate(node, 1)
new_total -= limit_amount_2
assert_equal(new_total, self.get_credit_pool_balance())
self.log.info("Trying to withdraw more... expecting to fail")
index += 1
asset_unlock_tx = self.create_assetunlock(index, COIN, pubkey)
self.send_tx(asset_unlock_tx)
node.generate(1)
self.sync_all()
self.generate(node, 1)

tip = self.nodes[0].getblockcount()
indexes_statuses_no_height = self.nodes[0].getassetunlockstatuses(["101", "102", "103"])
Expand Down Expand Up @@ -644,17 +625,15 @@ def test_mn_rr(self, node_wallet, node, pubkey):
assert_equal(platform_reward, all_mn_rewards * 375 // 1000) # 0.375 platform share
assert_equal(platform_reward, 34371430)
assert_equal(locked, self.get_credit_pool_balance())
node.generate(1)
self.sync_all()
self.generate(node, 1)
locked += platform_reward
assert_equal(locked, self.get_credit_pool_balance())

coins = node_wallet.listunspent(query_options={'minimumAmount': 1})
coin = coins.pop()
self.send_tx(self.create_assetlock(coin, COIN, pubkey))
locked += platform_reward + COIN
node.generate(1)
self.sync_all()
self.generate(node, 1)
assert_equal(locked, self.get_credit_pool_balance())


Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_backwards_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def setup_nodes(self):
self.import_deterministic_coinbase_privkeys()

def run_test(self):
self.nodes[0].generatetoaddress(101, self.nodes[0].getnewaddress())
self.generatetoaddress(self.nodes[0], 101, self.nodes[0].getnewaddress())

self.sync_blocks()

Expand Down Expand Up @@ -92,7 +92,7 @@ def run_test(self):
address = wallet.getnewaddress()
self.nodes[0].sendtoaddress(address, 1)
self.sync_mempools()
self.nodes[0].generate(1)
self.generate(self.nodes[0], 1)
self.sync_blocks()

# w1_v19: regular wallet, created with v0.19
Expand Down
Loading
Loading