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:
UdjinM6 2023-04-09 08:09:18 +03:00 committed by GitHub
parent 3bb9cca242
commit 54681dbf09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 49 deletions

View File

@ -106,12 +106,16 @@ class DIP3V19Test(DashTestFramework):
def test_revoke_protx(self, revoke_protx, revoke_keyoperator): def test_revoke_protx(self, revoke_protx, revoke_keyoperator):
funds_address = self.nodes[0].getnewaddress() funds_address = self.nodes[0].getnewaddress()
self.nodes[0].sendtoaddress(funds_address, 1) fund_txid = self.nodes[0].sendtoaddress(funds_address, 1)
self.nodes[0].generate(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.sync_all(self.nodes)
self.nodes[0].protx('revoke', revoke_protx, revoke_keyoperator, 1, funds_address) protx_result = self.nodes[0].protx('revoke', revoke_protx, revoke_keyoperator, 1, funds_address)
self.nodes[0].generate(1) 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.sync_all(self.nodes)
self.log.info(f"Succesfully revoked={revoke_protx}") self.log.info(f"Succesfully revoked={revoke_protx}")
for mn in self.mninfo: for mn in self.mninfo:

View File

@ -112,46 +112,48 @@ class LLMQHPMNTest(DashTestFramework):
self.test_hpmn_protx_are_in_mnlist(hpmn_protxhash_list) self.test_hpmn_protx_are_in_mnlist(hpmn_protxhash_list)
self.log.info("Test that HPMNs are paid 4x blocks in a row") 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()) self.log.info(self.nodes[0].masternodelist())
return return
def test_hpmmn_payements(self, window_analysis): def test_hpmn_payments(self, window_analysis):
current_hpmn = None current_hpmn = None
consecutive_paymments = 0 consecutive_payments = 0
for i in range(0, window_analysis): for i in range(0, window_analysis):
payee = self.get_mn_payee_for_block(self.nodes[0].getbestblockhash()) payee = self.get_mn_payee_for_block(self.nodes[0].getbestblockhash())
if payee is not None and payee.hpmn: if payee is not None and payee.hpmn:
if current_hpmn is not None and payee.proTxHash == current_hpmn.proTxHash: if current_hpmn is not None and payee.proTxHash == current_hpmn.proTxHash:
# same HPMN # same HPMN
assert consecutive_paymments > 0 assert consecutive_payments > 0
consecutive_paymments += 1 consecutive_payments += 1
consecutive_paymments_rpc = self.nodes[0].protx('info', current_hpmn.proTxHash)['state']['consecutivePayments'] consecutive_payments_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: else:
# new HPMN # new HPMN
if current_hpmn is not None: if current_hpmn is not None:
# make sure the old one was paid 4 times in a row # make sure the old one was paid 4 times in a row
assert_equal(consecutive_paymments, 4) assert_equal(consecutive_payments, 4)
consecutive_paymments_rpc = self.nodes[0].protx('info', current_hpmn.proTxHash)['state']['consecutivePayments'] consecutive_payments_rpc = self.nodes[0].protx('info', current_hpmn.proTxHash)['state']['consecutivePayments']
# old HPMN should have its nConsecutivePayments reset to 0 # 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 current_hpmn = payee
consecutive_paymments = 1 assert_equal(consecutive_payments, consecutive_payments_rpc)
consecutive_paymments_rpc = self.nodes[0].protx('info', current_hpmn.proTxHash)['state']['consecutivePayments']
assert_equal(consecutive_paymments, consecutive_paymments_rpc)
else: else:
# not a HPMN # not a HPMN
if current_hpmn is not None: if current_hpmn is not None:
# make sure the old one was paid 4 times in a row # make sure the old one was paid 4 times in a row
assert_equal(consecutive_paymments, 4) assert_equal(consecutive_payments, 4)
consecutive_paymments_rpc = self.nodes[0].protx('info', current_hpmn.proTxHash)['state']['consecutivePayments'] consecutive_payments_rpc = self.nodes[0].protx('info', current_hpmn.proTxHash)['state']['consecutivePayments']
# old HPMN should have its nConsecutivePayments reset to 0 # old HPMN should have its nConsecutivePayments reset to 0
assert_equal(consecutive_paymments_rpc, 0) assert_equal(consecutive_payments_rpc, 0)
current_hpmn = None current_hpmn = None
consecutive_paymments = 0 consecutive_payments = 0
self.nodes[0].generate(1) self.nodes[0].generate(1)
if i % 8 == 0: if i % 8 == 0:
@ -199,14 +201,15 @@ class LLMQHPMNTest(DashTestFramework):
reward_address = self.nodes[0].getnewaddress() reward_address = self.nodes[0].getnewaddress()
collateral_amount = 4000 collateral_amount = 4000
collateral_txid = self.nodes[0].sendtoaddress(collateral_address, collateral_amount) outputs = {collateral_address: collateral_amount, funds_address: 1}
# send to same address to reserve some funds for fees collateral_txid = self.nodes[0].sendmany("", outputs)
self.nodes[0].sendtoaddress(funds_address, 1) self.wait_for_instantlock(collateral_txid, self.nodes[0])
collateral_vout = 0 tip = self.nodes[0].generate(1)[0]
self.nodes[0].generate(1)
self.sync_all(self.nodes) 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']: for txout in rawtx['vout']:
if txout['value'] == Decimal(collateral_amount): if txout['value'] == Decimal(collateral_amount):
collateral_vout = txout['n'] collateral_vout = txout['n']
@ -216,15 +219,12 @@ class LLMQHPMNTest(DashTestFramework):
ipAndPort = '127.0.0.1:%d' % p2p_port(len(self.nodes)) ipAndPort = '127.0.0.1:%d' % p2p_port(len(self.nodes))
operatorReward = len(self.nodes) operatorReward = len(self.nodes)
self.nodes[0].generate(1)
protx_success = False
try: try:
self.nodes[0].protx('register_hpmn', collateral_txid, collateral_vout, ipAndPort, owner_address, bls['public'], voting_address, operatorReward, reward_address, funds_address, True) 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: except:
self.log.info("protx_hpmn rejected") self.log.info("protx_hpmn rejected")
assert_equal(protx_success, False)
def test_masternode_count(self, expected_mns_count, expected_hpmns_count): def test_masternode_count(self, expected_mns_count, expected_hpmns_count):
mn_count = self.nodes[0].masternode('count') mn_count = self.nodes[0].masternode('count')

View File

@ -1098,8 +1098,11 @@ class DashTestFramework(BitcoinTestFramework):
protx_success = True protx_success = True
except: except:
self.log.info("protx_hpmn rejected") self.log.info("protx_hpmn rejected")
assert_equal(protx_success, not should_be_rejected)
if should_be_rejected: if should_be_rejected:
assert_equal(protx_success, False) # nothing to do
return return
self.dynamically_initialize_datadir(self.nodes[0].chain,node_p2p_port, node_rpc_port) self.dynamically_initialize_datadir(self.nodes[0].chain,node_p2p_port, node_rpc_port)
@ -1135,14 +1138,15 @@ class DashTestFramework(BitcoinTestFramework):
platform_http_port = '%d' % (node_p2p_port + 102) if hpmn else '' platform_http_port = '%d' % (node_p2p_port + 102) if hpmn else ''
collateral_amount = 4000 if hpmn else 1000 collateral_amount = 4000 if hpmn else 1000
collateral_txid = self.nodes[0].sendtoaddress(collateral_address, collateral_amount) outputs = {collateral_address: collateral_amount, funds_address: 1}
# send to same address to reserve some funds for fees collateral_txid = self.nodes[0].sendmany("", outputs)
self.nodes[0].sendtoaddress(funds_address, 1) self.wait_for_instantlock(collateral_txid, self.nodes[0])
collateral_vout = 0 tip = self.nodes[0].generate(1)[0]
self.nodes[0].generate(1)
self.sync_all(self.nodes) 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']: for txout in rawtx['vout']:
if txout['value'] == Decimal(collateral_amount): if txout['value'] == Decimal(collateral_amount):
collateral_vout = txout['n'] collateral_vout = txout['n']
@ -1152,11 +1156,13 @@ class DashTestFramework(BitcoinTestFramework):
ipAndPort = '127.0.0.1:%d' % node_p2p_port ipAndPort = '127.0.0.1:%d' % node_p2p_port
operatorReward = idx operatorReward = idx
self.nodes[0].generate(1)
register_rpc = 'register_hpmn' if hpmn else 'register' 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) 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) 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) 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) self.mninfo.append(mn_info)
@ -1169,26 +1175,30 @@ class DashTestFramework(BitcoinTestFramework):
operator_reward_address = self.nodes[0].getnewaddress() operator_reward_address = self.nodes[0].getnewaddress()
# For the sake of the test, generate random nodeid, p2p and http platform values # 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_node_id = hash160(b'%d' % r).hex()
platform_p2p_port = '%d' % (r + 1) platform_p2p_port = '%d' % (r + 1)
platform_http_port = '%d' % (r + 2) platform_http_port = '%d' % (r + 2)
self.nodes[0].sendtoaddress(funds_address, 1) fund_txid = self.nodes[0].sendtoaddress(funds_address, 1)
self.nodes[0].generate(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.sync_all(self.nodes)
protx_success = False protx_success = False
try: 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) 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.nodes[0].generate(1) 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.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)) 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 protx_success = True
except: except:
self.log.info("protx_hpmn rejected") 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): def prepare_masternodes(self):
self.log.info("Preparing %d masternodes" % self.mn_count) self.log.info("Preparing %d masternodes" % self.mn_count)
@ -1335,7 +1345,7 @@ class DashTestFramework(BitcoinTestFramework):
self.start_node(0) self.start_node(0)
self.import_deterministic_coinbase_privkeys() self.import_deterministic_coinbase_privkeys()
required_balance = HIGHPERFORMANCE_MASTERNODE_COLLATERAL * self.hpmn_count 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) self.log.info("Generating %d coins" % required_balance)
while self.nodes[0].getbalance() < required_balance: while self.nodes[0].getbalance() < required_balance:
self.bump_mocktime(1) self.bump_mocktime(1)