Skip to content

Commit

Permalink
Fix the peaq forked test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypan committed Sep 14, 2024
1 parent 0fda9f2 commit db394db
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 8 deletions.
24 changes: 23 additions & 1 deletion tests/delegator_issue_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from peaq.utils import get_block_height, get_block_hash, get_chain
from peaq.utils import ExtrinsicBatch, get_account_balance
from tests.utils_func import restart_parachain_and_runtime_upgrade
from tools.utils import set_block_reward_configuration
import warnings


Expand Down Expand Up @@ -79,6 +80,8 @@ def set_reward_rate(substrate, collator, delegator):
@pytest.mark.substrate
class TestDelegator(unittest.TestCase):
def setUp(self):
restart_parachain_and_runtime_upgrade()

self.substrate = SubstrateInterface(
url=WS_URL,
)
Expand All @@ -88,9 +91,28 @@ def setUp(self):
Keypair.create_from_mnemonic(Keypair.generate_mnemonic()),
Keypair.create_from_mnemonic(Keypair.generate_mnemonic())
]
self.ori_reward_config = self.substrate.query(
module='BlockReward',
storage_function='RewardDistributionConfigStorage',
)
self.set_collator_delegator_precentage()

def tearDown(self):
restart_parachain_and_runtime_upgrade()
receipt = set_block_reward_configuration(self.substrate, self.ori_reward_config.value)
self.assertTrue(receipt.is_success, 'cannot reset the block reward configuration')

def set_collator_delegator_precentage(self):
set_value = {
'treasury_percent': 20000000,
'depin_incentivization_percent': 10000000,
'collators_delegators_percent': 20000000,
'depin_staking_percent': 50000000,
'coretime_percent': 40000000,
'subsidization_pool_percent': 860000000,
}
receipt = set_block_reward_configuration(self.substrate, set_value)
self.assertTrue(receipt.is_success,
'cannot setup the block reward configuration')

def get_balance_difference(self, addr):
current_height = get_block_height(self.substrate)
Expand Down
2 changes: 1 addition & 1 deletion tests/pallet_inflation_manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

INFLATION_RECALCULATION = {
'peaq-network': 5256000,
'peaq-network-fork': 3617954,
'peaq-network-fork': 5684095,
'peaq-dev': 5256000,
'peaq-dev-fork': 5084632,
# Because of the delay TGE
Expand Down
8 changes: 4 additions & 4 deletions tests/pallet_vesting_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ def merge_schedule_test(self, substrate, kp_source, kp_target_second):
block_header = substrate.get_block_header()
current_block_number = int(block_header['header']['number'])

first_starting_block_number = current_block_number + 10
second_starting_block_number = current_block_number + 20
first_starting_block_number = current_block_number + 100
second_starting_block_number = current_block_number + 200

print("Current Block: ", current_block_number)
print("Starting Block Number of first schedule: ", first_starting_block_number)
Expand All @@ -233,10 +233,10 @@ def merge_schedule_test(self, substrate, kp_source, kp_target_second):
max(first_starting_block_number, second_starting_block_number))

first_schedule = {'locked': 100 * TOKEN_NUM_BASE_DEV,
'per_block': 10 * TOKEN_NUM_BASE_DEV,
'per_block': 1 * TOKEN_NUM_BASE_DEV,
'starting_block': first_starting_block_number}
second_schedule = {'locked': 200 * TOKEN_NUM_BASE_DEV,
'per_block': 20 * TOKEN_NUM_BASE_DEV,
'per_block': 2 * TOKEN_NUM_BASE_DEV,
'starting_block': second_starting_block_number}

print("First vested trasnfer")
Expand Down
10 changes: 9 additions & 1 deletion tests/token_economy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@
'subsidization_pool_percent': 50000000,
'depin_staking_percent': 50000000,
'depin_incentivization_percent': 150000000,
},
'peaq-network-fork': {
'treasury_percent': 650000000,
'collators_delegators_percent': 0,
'coretime_percent': 100000000,
'subsidization_pool_percent': 50000000,
'depin_staking_percent': 50000000,
'depin_incentivization_percent': 150000000,
}
}
}]
Expand Down Expand Up @@ -194,7 +202,7 @@ def test_block_reward(self):
block_reward = {
'peaq-dev-fork': int(3.805175038 * 10 ** 18),
'krest-network-fork': int(3.805175038 * 10 ** 18),
'peaq-network-fork': int(55.93607306 * 10 ** 18),
'peaq-network-fork': int(27.96803653 * 10 ** 18),
}
if 'peaq-dev-fork' != self._chain_spec and \
'krest-network-fork' != self._chain_spec and \
Expand Down
1 change: 1 addition & 0 deletions tests/xcm_transfer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def get_parachain_id(self, peaq_substrate):
@classmethod
def setUpClass(cls):
restart_parachain_and_runtime_upgrade()
wait_until_block_height(SubstrateInterface(url=RELAYCHAIN_WS_URL), 3)
wait_until_block_height(SubstrateInterface(url=PARACHAIN_WS_URL), 3)
wait_until_block_height(SubstrateInterface(url=ACA_WS_URL), 3)

Expand Down
10 changes: 9 additions & 1 deletion tools/runtime_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
sys.path.append('./')
import os
import time
import importlib

from substrateinterface import SubstrateInterface
from tools.constants import WS_URL, KP_GLOBAL_SUDO, RELAYCHAIN_WS_URL, KP_COLLATOR
Expand Down Expand Up @@ -154,7 +155,7 @@ def do_runtime_upgrade(wasm_path):
batch.execute()

upgrade(wasm_path)
wait_for_n_blocks(substrate, 10)
wait_for_n_blocks(substrate, 15)
# Cannot move in front of the upgrade because V4 only exists in 1.7.2
update_xcm_default_version(substrate)

Expand Down Expand Up @@ -186,4 +187,11 @@ def main():


if __name__ == '__main__':
# For the monkey patching to work, the module must be reloaded
# Avoid the dependency on the module name
if 'substrateinterface' in sys.modules:
importlib.reload(sys.modules['substrateinterface'])
if 'peaq.utils' in sys.modules:
importlib.reload(sys.modules['peaq.utils'])

main()

0 comments on commit db394db

Please sign in to comment.