Skip to content

Commit

Permalink
Update the collator sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypan authored and Jay Pan committed Dec 19, 2024
1 parent 578d4a1 commit f48a51a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/bridge_multiple_collator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def get_event(self, block_hash, module, event):
def test_delegator_another_candidate(self):
contract = get_contract(self._w3, PARACHAIN_STAKING_ADDR, PARACHAIN_STAKING_ABI_FILE)
out = contract.functions.getCollatorList().call()
out = sorted(out, key=lambda x: x[1], reverse=True)
collator_num = out[0][1]
collator_eth_addr = out[0][0]

Expand Down
10 changes: 10 additions & 0 deletions tests/bridge_parachain_staking_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def test_get_collator_list(self):
contract = get_contract(self._w3, PARACHAIN_STAKING_ADDR, PARACHAIN_STAKING_ABI_FILE)

out = contract.functions.getCollatorList().call()
out = sorted(out, key=lambda x: x[1], reverse=True)
golden_data = self._substrate.query('ParachainStaking', 'TopCandidates')
golden_data = golden_data.value
self.assertEqual(len(out), len(golden_data))
Expand All @@ -174,6 +175,7 @@ def get_event(self, block_hash, module, event):
def test_evm_api_cannot_transfer_over_stake_others(self):
contract = get_contract(self._w3, PARACHAIN_STAKING_ADDR, PARACHAIN_STAKING_ABI_FILE)
out = contract.functions.getCollatorList().call()
out = sorted(out, key=lambda x: x[1], reverse=True)

collator_eth_addr = out[0][0]
collator_num = out[0][1]
Expand Down Expand Up @@ -212,6 +214,7 @@ def test_evm_api_cannot_transfer_over_stake_others(self):
def test_evm_api_cannot_transfer_over_stake_agung(self):
contract = get_contract(self._w3, PARACHAIN_STAKING_ADDR, PARACHAIN_STAKING_ABI_FILE)
out = contract.functions.getCollatorList().call()
out = sorted(out, key=lambda x: x[1], reverse=True)

collator_eth_addr = out[0][0]
collator_num = out[0][1]
Expand Down Expand Up @@ -249,6 +252,7 @@ def test_evm_api_cannot_transfer_over_stake_agung(self):
def test_delegator_join_more_less_leave(self):
contract = get_contract(self._w3, PARACHAIN_STAKING_ADDR, PARACHAIN_STAKING_ABI_FILE)
out = contract.functions.getCollatorList().call()
out = sorted(out, key=lambda x: x[1], reverse=True)

collator_eth_addr = out[0][0]
collator_num = out[0][1]
Expand Down Expand Up @@ -320,6 +324,7 @@ def test_commission_rate(self):

contract = get_contract(self._w3, PARACHAIN_STAKING_ADDR, PARACHAIN_STAKING_ABI_FILE)
out = contract.functions.getCollatorList().call()
out = sorted(out, key=lambda x: x[1], reverse=True)
all_colators_info = self._substrate.query_map(
module='ParachainStaking',
storage_function='CandidatePool',
Expand Down Expand Up @@ -350,6 +355,7 @@ def test_commission_rate(self):
def test_wait_list(self):
contract = get_contract(self._w3, PARACHAIN_STAKING_ADDR, PARACHAIN_STAKING_ABI_FILE)
out = contract.functions.getCollatorList().call()
out = sorted(out, key=lambda x: x[1], reverse=True)
collator_num = out[0][1]
receipt = self._fund_users(collator_num * 2)

Expand All @@ -368,6 +374,7 @@ def test_wait_list(self):
self.assertEqual(receipt.is_success, True, f'set_commission fails, receipt: {receipt}')

wait_list = contract.functions.getWaitList().call()
wait_list = sorted(wait_list, key=lambda x: x[1], reverse=True)
self.assertEqual(len(wait_list), 1)
pk = bytes.fromhex(self._substrate.ss58_decode(self._kp_new_collator.ss58_address))
self.assertEqual(wait_list[0][0], pk)
Expand All @@ -376,6 +383,7 @@ def test_wait_list(self):

# Check the wait list
collator_list = contract.functions.getCollatorList().call()
out = sorted(out, key=lambda x: x[1], reverse=True)
self.assertEqual(len(collator_list), 2)
self.assertTrue(wait_list[0][0] in [collator[0] for collator in collator_list])

Expand All @@ -393,6 +401,7 @@ def test_wait_list(self):
def test_delegator_revoke(self):
contract = get_contract(self._w3, PARACHAIN_STAKING_ADDR, PARACHAIN_STAKING_ABI_FILE)
out = contract.functions.getCollatorList().call()
out = sorted(out, key=lambda x: x[1], reverse=True)

collator_eth_addr = out[0][0]
collator_num = out[0][1]
Expand Down Expand Up @@ -445,6 +454,7 @@ def test_delegator_customized_claim(self):

contract = get_contract(self._w3, PARACHAIN_STAKING_ADDR, PARACHAIN_STAKING_ABI_FILE)
out = contract.functions.getCollatorList().call()
out = sorted(out, key=lambda x: x[1], reverse=True)

collator_eth_addr = out[0][0]
collator_num = out[0][1]
Expand Down
1 change: 1 addition & 0 deletions tools/stress/stress_delegator_multi_collators_evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def main(): # noqa: C901
wait_until_block_height(substrate, 1)
contract = get_contract(w3, PARACHAIN_STAKING_ADDR, PARACHAIN_STAKING_ABI_FILE)
validators = contract.functions.getCollatorList().call()
validators = sorted(validators, key=lambda x: x[1], reverse=True)
collator_nums = [validator[1] for validator in validators]
validators = [validator[0] for validator in validators]
if len(validators) == 0:
Expand Down

0 comments on commit f48a51a

Please sign in to comment.