Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
49f9064
Add comprehensive tests for getDelegatorState precompile function
Aug 13, 2025
a350339
Fix getDelegatorState tests: use updated ABI and ensure minimum stake…
Aug 13, 2025
9f03ead
Refactor getDelegatorState tests and fix ABI
Aug 14, 2025
6405947
Fix test to use 3-parameter getDelegatorState function
Aug 14, 2025
45fa854
Remove redundant test_get_delegator_state_nine_delegators_two_collators
Aug 14, 2025
07a844f
Optimize delegation setup with batch transaction sending
Aug 14, 2025
b742132
Refactor test setup methods for improved maintainability
Aug 14, 2025
c860fd1
Fix getDelegatorState precompile integration and address handling
Aug 15, 2025
ca160be
Eliminate conditional logic and optimize async processing in tests
Aug 15, 2025
17888af
Optimize collator setup and implement comprehensive result caching
Aug 15, 2025
22e16df
Fix NameError: use cls.assertTrue instead of self.assertTrue in class…
Aug 15, 2025
d7cd4b1
Fix AttributeError: replace cls.assertEqual with assert statements in…
Aug 15, 2025
68b63bc
Simplify caching to be more explicit and predictable for testing
Aug 15, 2025
c9c9bec
Improve error messages and assertion clarity in tests
Aug 15, 2025
79b7d30
refactor: comprehensive test_get_delegator_state improvements
Aug 16, 2025
bc99d6a
refactor: minor code cleanup for better maintainability
Aug 16, 2025
0c4dd99
refactor: simplify _setup_infrastructure method
Aug 16, 2025
f91715f
fix: resolve all flake8 style issues
Aug 16, 2025
7f20e5b
refactor: extract zero_address constant to module level
Aug 16, 2025
f562fdb
refactor: optimize _ensure_minimum_collators with batch funding
Aug 16, 2025
12d5e97
refactor: extract NUM_DELEGATORS constant
Aug 16, 2025
860f720
refactor: consolidate _fund_users into common utility function
Aug 16, 2025
b634ac7
Update tests/test_get_delegator_state.py
sfffaaa Aug 20, 2025
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
77 changes: 77 additions & 0 deletions ETH/parachain-staking/abi
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
[
{
"inputs": [
{
"internalType": "address",
"name": "ethAddress",
"type": "address"
}
],
"name": "convertEthToSubstrateAccount",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -83,6 +102,64 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "delegator",
"type": "address"
},
{
"internalType": "uint256",
"name": "offset",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "limit",
"type": "uint256"
}
],
"name": "getDelegatorState",
"outputs": [
{
"components": [
{
"internalType": "bytes32",
"name": "delegator",
"type": "bytes32"
},
{
"components": [
{
"internalType": "bytes32",
"name": "collator",
"type": "bytes32"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"internalType": "struct ParachainStaking.DelegationInfo[]",
"name": "collators",
"type": "tuple[]"
},
{
"internalType": "uint256",
"name": "total",
"type": "uint256"
}
],
"internalType": "struct ParachainStaking.CollatorDelegatorState[]",
"name": "",
"type": "tuple[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getWaitList",
Expand Down
29 changes: 8 additions & 21 deletions tests/bridge_asset_factory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
from substrateinterface import SubstrateInterface
from tools.asset import get_valid_asset_id
from tools.constants import WS_URL, ETH_URL
from peaq.utils import ExtrinsicBatch
from tools.peaq_eth_utils import get_contract
from tools.peaq_eth_utils import get_eth_chain_id
from tools.peaq_eth_utils import calculate_asset_to_evm_address
from tools.peaq_eth_utils import get_eth_info
from tools.constants import KP_GLOBAL_SUDO
from tests.evm_utils import sign_and_submit_evm_transaction
from web3 import Web3

Expand All @@ -33,25 +31,14 @@ def setUp(self):
self._eth_chain_id = get_eth_chain_id(self._substrate)

def _fund_users(self):
# Fund users
batch = ExtrinsicBatch(self._substrate, KP_GLOBAL_SUDO)
batch.compose_call(
'Balances',
'transfer_keep_alive',
{
'dest': self._kp_creator['substrate'],
'value': 10000 * 10 ** 18,
}
)
batch.compose_call(
'Balances',
'transfer_keep_alive',
{
'dest': self._kp_admin['substrate'],
'value': 10000 * 10 ** 18,
}
)
batch.execute()
from tools.peaq_eth_utils import fund_test_accounts

accounts_to_fund = [
self._kp_creator['substrate'],
self._kp_admin['substrate']
]

return fund_test_accounts(self._substrate, accounts_to_fund, 10000 * 10 ** 18, method='transfer_keep_alive')

def evm_asset_create(self, contract, eth_kp_src, asset_id, eth_admin, min_balance):
w3 = self._w3
Expand Down
38 changes: 9 additions & 29 deletions tests/bridge_multiple_collator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,15 @@ def setUp(self):
self._kp_src = Keypair.create_from_uri('//Moon')

def _fund_users(self, num=100 * 10 ** 18):
if num < 100 * 10 ** 18:
num = 100 * 10 ** 18
# Fund users
batch = ExtrinsicBatch(self._substrate, KP_GLOBAL_SUDO)
batch.compose_sudo_call(
'Balances',
'force_set_balance',
{
'who': self._kp_moon['substrate'],
'new_free': num,
}
)
batch.compose_sudo_call(
'Balances',
'force_set_balance',
{
'who': self._kp_mars['substrate'],
'new_free': num,
}
)
batch.compose_sudo_call(
'Balances',
'force_set_balance',
{
'who': self._kp_src.ss58_address,
'new_free': num,
}
)
return batch.execute()
from tools.peaq_eth_utils import fund_test_accounts

accounts_to_fund = [
self._kp_moon['substrate'],
self._kp_mars['substrate'],
self._kp_src.ss58_address
]

return fund_test_accounts(self._substrate, accounts_to_fund, num)

def evm_join_delegators(self, contract, eth_kp_src, sub_collator_addr, stake):
w3 = self._w3
Expand Down
48 changes: 11 additions & 37 deletions tests/bridge_parachain_staking_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,45 +62,19 @@ def restart_chain_and_reinit(self):

# Will regenerate the moon/mars
def _fund_users(self, num=100 * 10 ** 18):
from tools.peaq_eth_utils import fund_test_accounts

self._kp_moon = get_eth_info()
self._kp_mars = get_eth_info()
if num < 100 * 10 ** 18:
num = 100 * 10 ** 18
# Fund users
batch = ExtrinsicBatch(self._substrate, KP_GLOBAL_SUDO)
batch.compose_sudo_call(
'Balances',
'force_set_balance',
{
'who': self._kp_moon['substrate'],
'new_free': num,
}
)
batch.compose_sudo_call(
'Balances',
'force_set_balance',
{
'who': self._kp_mars['substrate'],
'new_free': num,
}
)
batch.compose_sudo_call(
'Balances',
'force_set_balance',
{
'who': self._kp_src.ss58_address,
'new_free': num,
}
)
batch.compose_sudo_call(
'Balances',
'force_set_balance',
{
'who': self._kp_new_collator.ss58_address,
'new_free': num,
}
)
return batch.execute()

accounts_to_fund = [
self._kp_moon['substrate'],
self._kp_mars['substrate'],
self._kp_src.ss58_address,
self._kp_new_collator.ss58_address
]

return fund_test_accounts(self._substrate, accounts_to_fund, num)

def evm_join_delegators(self, contract, eth_kp_src, sub_collator_addr, stake):
w3 = self._w3
Expand Down
Loading