mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
fix(tests): a couple of fixes for dynamically_add/update functions (#5288)
## Issue being fixed or feature implemented should hopefully fix some sporadic ci test failures (like https://gitlab.com/dashpay/dash/-/jobs/4052206622#L1962) ## What was done? tweaked dynamically_add/update functions to make checks more consistent and avoid some edge cases, pls see individual commits ## How Has This Been Tested? `feature_llmq_hpmn.py` and `feature_dip3_v19.py` still work locally, let's see if ci is now (constantly) happy about these too... ## Breaking Changes n/a ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [x] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation **For repository code-owners and collaborators only** - [x] I have assigned this pull request to a milestone
This commit is contained in:
parent
93dc8076aa
commit
1664246f77
@ -106,12 +106,16 @@ class DIP3V19Test(DashTestFramework):
|
||||
|
||||
def test_revoke_protx(self, revoke_protx, revoke_keyoperator):
|
||||
funds_address = self.nodes[0].getnewaddress()
|
||||
self.nodes[0].sendtoaddress(funds_address, 1)
|
||||
self.nodes[0].generate(1)
|
||||
fund_txid = self.nodes[0].sendtoaddress(funds_address, 1)
|
||||
self.wait_for_instantlock(fund_txid, self.nodes[0])
|
||||
tip = self.nodes[0].generate(1)[0]
|
||||
assert_equal(self.nodes[0].getrawtransaction(fund_txid, 1, tip)['confirmations'], 1)
|
||||
self.sync_all(self.nodes)
|
||||
|
||||
self.nodes[0].protx('revoke', revoke_protx, revoke_keyoperator, 1, funds_address)
|
||||
self.nodes[0].generate(1)
|
||||
protx_result = self.nodes[0].protx('revoke', revoke_protx, revoke_keyoperator, 1, funds_address)
|
||||
self.wait_for_instantlock(protx_result, self.nodes[0])
|
||||
tip = self.nodes[0].generate(1)[0]
|
||||
assert_equal(self.nodes[0].getrawtransaction(protx_result, 1, tip)['confirmations'], 1)
|
||||
self.sync_all(self.nodes)
|
||||
self.log.info(f"Succesfully revoked={revoke_protx}")
|
||||
for mn in self.mninfo:
|
||||
|
@ -112,46 +112,48 @@ class LLMQHPMNTest(DashTestFramework):
|
||||
self.test_hpmn_protx_are_in_mnlist(hpmn_protxhash_list)
|
||||
|
||||
self.log.info("Test that HPMNs are paid 4x blocks in a row")
|
||||
self.test_hpmmn_payements(window_analysis=256)
|
||||
self.test_hpmn_payments(window_analysis=256)
|
||||
|
||||
self.log.info(self.nodes[0].masternodelist())
|
||||
|
||||
return
|
||||
|
||||
def test_hpmmn_payements(self, window_analysis):
|
||||
def test_hpmn_payments(self, window_analysis):
|
||||
current_hpmn = None
|
||||
consecutive_paymments = 0
|
||||
consecutive_payments = 0
|
||||
for i in range(0, window_analysis):
|
||||
payee = self.get_mn_payee_for_block(self.nodes[0].getbestblockhash())
|
||||
if payee is not None and payee.hpmn:
|
||||
if current_hpmn is not None and payee.proTxHash == current_hpmn.proTxHash:
|
||||
# same HPMN
|
||||
assert consecutive_paymments > 0
|
||||
consecutive_paymments += 1
|
||||
consecutive_paymments_rpc = self.nodes[0].protx('info', current_hpmn.proTxHash)['state']['consecutivePayments']
|
||||
assert_equal(consecutive_paymments, consecutive_paymments_rpc)
|
||||
assert consecutive_payments > 0
|
||||
consecutive_payments += 1
|
||||
consecutive_payments_rpc = self.nodes[0].protx('info', current_hpmn.proTxHash)['state']['consecutivePayments']
|
||||
assert_equal(consecutive_payments, consecutive_payments_rpc)
|
||||
else:
|
||||
# new HPMN
|
||||
if current_hpmn is not None:
|
||||
# make sure the old one was paid 4 times in a row
|
||||
assert_equal(consecutive_paymments, 4)
|
||||
consecutive_paymments_rpc = self.nodes[0].protx('info', current_hpmn.proTxHash)['state']['consecutivePayments']
|
||||
assert_equal(consecutive_payments, 4)
|
||||
consecutive_payments_rpc = self.nodes[0].protx('info', current_hpmn.proTxHash)['state']['consecutivePayments']
|
||||
# old HPMN should have its nConsecutivePayments reset to 0
|
||||
assert_equal(consecutive_paymments_rpc, 0)
|
||||
assert_equal(consecutive_payments_rpc, 0)
|
||||
consecutive_payments_rpc = self.nodes[0].protx('info', payee.proTxHash)['state']['consecutivePayments']
|
||||
# if hpmn is the one we start "for" loop with,
|
||||
# we have no idea how many times it was paid before - rely on rpc results here
|
||||
consecutive_payments = consecutive_payments_rpc if i == 0 and current_hpmn is None else 1
|
||||
current_hpmn = payee
|
||||
consecutive_paymments = 1
|
||||
consecutive_paymments_rpc = self.nodes[0].protx('info', current_hpmn.proTxHash)['state']['consecutivePayments']
|
||||
assert_equal(consecutive_paymments, consecutive_paymments_rpc)
|
||||
assert_equal(consecutive_payments, consecutive_payments_rpc)
|
||||
else:
|
||||
# not a HPMN
|
||||
if current_hpmn is not None:
|
||||
# make sure the old one was paid 4 times in a row
|
||||
assert_equal(consecutive_paymments, 4)
|
||||
consecutive_paymments_rpc = self.nodes[0].protx('info', current_hpmn.proTxHash)['state']['consecutivePayments']
|
||||
assert_equal(consecutive_payments, 4)
|
||||
consecutive_payments_rpc = self.nodes[0].protx('info', current_hpmn.proTxHash)['state']['consecutivePayments']
|
||||
# old HPMN should have its nConsecutivePayments reset to 0
|
||||
assert_equal(consecutive_paymments_rpc, 0)
|
||||
assert_equal(consecutive_payments_rpc, 0)
|
||||
current_hpmn = None
|
||||
consecutive_paymments = 0
|
||||
consecutive_payments = 0
|
||||
|
||||
self.nodes[0].generate(1)
|
||||
if i % 8 == 0:
|
||||
@ -199,14 +201,15 @@ class LLMQHPMNTest(DashTestFramework):
|
||||
reward_address = self.nodes[0].getnewaddress()
|
||||
|
||||
collateral_amount = 4000
|
||||
collateral_txid = self.nodes[0].sendtoaddress(collateral_address, collateral_amount)
|
||||
# send to same address to reserve some funds for fees
|
||||
self.nodes[0].sendtoaddress(funds_address, 1)
|
||||
collateral_vout = 0
|
||||
self.nodes[0].generate(1)
|
||||
outputs = {collateral_address: collateral_amount, funds_address: 1}
|
||||
collateral_txid = self.nodes[0].sendmany("", outputs)
|
||||
self.wait_for_instantlock(collateral_txid, self.nodes[0])
|
||||
tip = self.nodes[0].generate(1)[0]
|
||||
self.sync_all(self.nodes)
|
||||
|
||||
rawtx = self.nodes[0].getrawtransaction(collateral_txid, 1)
|
||||
rawtx = self.nodes[0].getrawtransaction(collateral_txid, 1, tip)
|
||||
assert_equal(rawtx['confirmations'], 1)
|
||||
collateral_vout = 0
|
||||
for txout in rawtx['vout']:
|
||||
if txout['value'] == Decimal(collateral_amount):
|
||||
collateral_vout = txout['n']
|
||||
@ -216,15 +219,12 @@ class LLMQHPMNTest(DashTestFramework):
|
||||
ipAndPort = '127.0.0.1:%d' % p2p_port(len(self.nodes))
|
||||
operatorReward = len(self.nodes)
|
||||
|
||||
self.nodes[0].generate(1)
|
||||
|
||||
protx_success = False
|
||||
try:
|
||||
self.nodes[0].protx('register_hpmn', collateral_txid, collateral_vout, ipAndPort, owner_address, bls['public'], voting_address, operatorReward, reward_address, funds_address, True)
|
||||
protx_success = True
|
||||
# this should never succeed
|
||||
assert False
|
||||
except:
|
||||
self.log.info("protx_hpmn rejected")
|
||||
assert_equal(protx_success, False)
|
||||
|
||||
def test_masternode_count(self, expected_mns_count, expected_hpmns_count):
|
||||
mn_count = self.nodes[0].masternode('count')
|
||||
|
@ -1068,8 +1068,11 @@ class DashTestFramework(BitcoinTestFramework):
|
||||
protx_success = True
|
||||
except:
|
||||
self.log.info("protx_hpmn rejected")
|
||||
|
||||
assert_equal(protx_success, not should_be_rejected)
|
||||
|
||||
if should_be_rejected:
|
||||
assert_equal(protx_success, False)
|
||||
# nothing to do
|
||||
return
|
||||
|
||||
self.dynamically_initialize_datadir(self.nodes[0].chain,node_p2p_port, node_rpc_port)
|
||||
@ -1105,14 +1108,15 @@ class DashTestFramework(BitcoinTestFramework):
|
||||
platform_http_port = '%d' % (node_p2p_port + 102) if hpmn else ''
|
||||
|
||||
collateral_amount = 4000 if hpmn else 1000
|
||||
collateral_txid = self.nodes[0].sendtoaddress(collateral_address, collateral_amount)
|
||||
# send to same address to reserve some funds for fees
|
||||
self.nodes[0].sendtoaddress(funds_address, 1)
|
||||
collateral_vout = 0
|
||||
self.nodes[0].generate(1)
|
||||
outputs = {collateral_address: collateral_amount, funds_address: 1}
|
||||
collateral_txid = self.nodes[0].sendmany("", outputs)
|
||||
self.wait_for_instantlock(collateral_txid, self.nodes[0])
|
||||
tip = self.nodes[0].generate(1)[0]
|
||||
self.sync_all(self.nodes)
|
||||
|
||||
rawtx = self.nodes[0].getrawtransaction(collateral_txid, 1)
|
||||
rawtx = self.nodes[0].getrawtransaction(collateral_txid, 1, tip)
|
||||
assert_equal(rawtx['confirmations'], 1)
|
||||
collateral_vout = 0
|
||||
for txout in rawtx['vout']:
|
||||
if txout['value'] == Decimal(collateral_amount):
|
||||
collateral_vout = txout['n']
|
||||
@ -1122,11 +1126,13 @@ class DashTestFramework(BitcoinTestFramework):
|
||||
ipAndPort = '127.0.0.1:%d' % node_p2p_port
|
||||
operatorReward = idx
|
||||
|
||||
self.nodes[0].generate(1)
|
||||
register_rpc = 'register_hpmn' if hpmn else 'register'
|
||||
protx_result = self.nodes[0].protx(register_rpc, collateral_txid, collateral_vout, ipAndPort, owner_address, bls['public'], voting_address, operatorReward, reward_address, platform_node_id, platform_p2p_port, platform_http_port, funds_address, True)
|
||||
self.nodes[0].generate(1)
|
||||
self.wait_for_instantlock(protx_result, self.nodes[0])
|
||||
tip = self.nodes[0].generate(1)[0]
|
||||
self.sync_all(self.nodes)
|
||||
|
||||
assert_equal(self.nodes[0].getrawtransaction(protx_result, 1, tip)['confirmations'], 1)
|
||||
mn_info = MasternodeInfo(protx_result, owner_address, voting_address, bls['public'], bls['secret'], collateral_address, collateral_txid, collateral_vout, ipAndPort, hpmn)
|
||||
self.mninfo.append(mn_info)
|
||||
|
||||
@ -1139,26 +1145,30 @@ class DashTestFramework(BitcoinTestFramework):
|
||||
operator_reward_address = self.nodes[0].getnewaddress()
|
||||
|
||||
# For the sake of the test, generate random nodeid, p2p and http platform values
|
||||
r = rnd if rnd is not None else random.randint(1000, 65000)
|
||||
r = rnd if rnd is not None else random.randint(21000, 65000)
|
||||
platform_node_id = hash160(b'%d' % r).hex()
|
||||
platform_p2p_port = '%d' % (r + 1)
|
||||
platform_http_port = '%d' % (r + 2)
|
||||
|
||||
self.nodes[0].sendtoaddress(funds_address, 1)
|
||||
self.nodes[0].generate(1)
|
||||
fund_txid = self.nodes[0].sendtoaddress(funds_address, 1)
|
||||
self.wait_for_instantlock(fund_txid, self.nodes[0])
|
||||
tip = self.nodes[0].generate(1)[0]
|
||||
assert_equal(self.nodes[0].getrawtransaction(fund_txid, 1, tip)['confirmations'], 1)
|
||||
self.sync_all(self.nodes)
|
||||
|
||||
protx_success = False
|
||||
try:
|
||||
self.nodes[0].protx('update_service_hpmn', hpmn_info.proTxHash, hpmn_info.addr, hpmn_info.keyOperator, platform_node_id, platform_p2p_port, platform_http_port, operator_reward_address, funds_address)
|
||||
self.nodes[0].generate(1)
|
||||
protx_result = self.nodes[0].protx('update_service_hpmn', hpmn_info.proTxHash, hpmn_info.addr, hpmn_info.keyOperator, platform_node_id, platform_p2p_port, platform_http_port, operator_reward_address, funds_address)
|
||||
self.wait_for_instantlock(protx_result, self.nodes[0])
|
||||
tip = self.nodes[0].generate(1)[0]
|
||||
assert_equal(self.nodes[0].getrawtransaction(protx_result, 1, tip)['confirmations'], 1)
|
||||
self.sync_all(self.nodes)
|
||||
self.log.info("Updated HPMN %s: platformNodeID=%s, platformP2PPort=%s, platformHTTPPort=%s" % (hpmn_info.proTxHash, platform_node_id, platform_p2p_port, platform_http_port))
|
||||
protx_success = True
|
||||
except:
|
||||
self.log.info("protx_hpmn rejected")
|
||||
if should_be_rejected:
|
||||
assert_equal(protx_success, False)
|
||||
|
||||
assert_equal(protx_success, not should_be_rejected)
|
||||
|
||||
def prepare_masternodes(self):
|
||||
self.log.info("Preparing %d masternodes" % self.mn_count)
|
||||
@ -1305,7 +1315,7 @@ class DashTestFramework(BitcoinTestFramework):
|
||||
self.start_node(0)
|
||||
self.import_deterministic_coinbase_privkeys()
|
||||
required_balance = HIGHPERFORMANCE_MASTERNODE_COLLATERAL * self.hpmn_count
|
||||
required_balance += MASTERNODE_COLLATERAL * (self.mn_count - self.hpmn_count) + 1
|
||||
required_balance += MASTERNODE_COLLATERAL * (self.mn_count - self.hpmn_count) + 100
|
||||
self.log.info("Generating %d coins" % required_balance)
|
||||
while self.nodes[0].getbalance() < required_balance:
|
||||
self.bump_mocktime(1)
|
||||
|
Loading…
Reference in New Issue
Block a user