Skip to content

Commit

Permalink
Update the testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypan authored and Jay Pan committed Nov 6, 2024
1 parent 9bc88d9 commit 8c436bf
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 14 deletions.
68 changes: 68 additions & 0 deletions tests/xcm_transfer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,27 @@ def get_asset_token_location(asset_id):
}


def get_asset_pallet_location(asset_id):
if asset_id >= 16:
raise ValueError('Asset id should < 16')

return {
'peaq': {
XCM_VER: {
'parents': '1',
'interior': {
'X2': [
{'Parachain': 3000},
{'PalletInstance': 10},
]
}
}
},
# Force failed
'para': {}
}


def get_metadata(symbol):
return {
'name': symbol,
Expand All @@ -103,6 +124,12 @@ def get_metadata(symbol):
TEST_SUFF_ASSET_TOKEN = get_asset_token_location(TEST_SUFF_ASSET_IDX)
TEST_SUFF_ASSET_METADATA = get_metadata('suf')

TEST_PALLET_ASSET_IDX = 12
TEST_PALLET_ASSET_ID = get_test_asset_id(TEST_PALLET_ASSET_IDX)
TEST_PALLET_ASSET_TOKEN = get_asset_pallet_location(TEST_PALLET_ASSET_IDX)
TEST_PALLET_ASSET_METADATA = get_metadata('pal')


TEST_LP_ASSET_ID = {
'peaq': convert_enum_to_asset_id({'LPToken': [0, 1]}),
'para': 1000,
Expand Down Expand Up @@ -466,6 +493,26 @@ def _set_up_peaq_asset_on_peaq_if_not_exist(self, asset_id, kp_para_src, is_suff
asset_token['peaq'], UNITS_PER_SECOND)
self.assertTrue(receipt.is_success, f'Failed to register foreign asset: {receipt.error_message}')

def _set_up_peaq_pallet_asset_on_peaq_if_not_exist(self, asset_id, kp_para_src):
import pdb
pdb.set_trace()
asset_token = TEST_PALLET_ASSET_TOKEN
kp_self_dst = kp_para_src
batch = ExtrinsicBatch(self.si_peaq, KP_GLOBAL_SUDO)
batch_fund(batch, kp_self_dst, INIT_TOKEN_NUM)
if not self.si_peaq.query("Assets", "Asset", [asset_id]).value:
batch_force_create_asset(batch, KP_GLOBAL_SUDO.ss58_address, asset_id)
batch_set_metadata(
batch, asset_id,
TEST_ASSET_METADATA['name'], TEST_ASSET_METADATA['symbol'], TEST_ASSET_METADATA['decimals'])
batch_mint(batch, self.alice.ss58_address, asset_id, 10 * TEST_TOKEN_NUM)
receipt = batch.execute()
self.assertTrue(receipt.is_success, f'Failed to create asset: {receipt.error_message}')
receipt = setup_xc_register_if_not_exist(
self.si_peaq, KP_GLOBAL_SUDO, asset_id,
asset_token['peaq'], UNITS_PER_SECOND)
self.assertTrue(receipt.is_success, f'Failed to register foreign asset: {receipt.error_message}')

def _check_peaq_asset_from_peaq_to_aca_and_back(self, kp_para_src, kp_self_dst, asset_id, is_sufficient):
aca_block_num = self.si_aca.get_block_number(None)
receipt = send_token_from_peaq_to_para(
Expand Down Expand Up @@ -629,3 +676,24 @@ def test_sibling_parachain_delivery_fee(self):
# Assert that the delivery fee is within the expected range
self.assertGreaterEqual(delivery_fee, TEST_FEES_RANGE[self.chain_spec]['min'])
self.assertLessEqual(delivery_fee, TEST_FEES_RANGE[self.chain_spec]['max'])

# However, cannot receive on the other side
def test_asset_with_pallet_from_peaq_to_aca(self):
# From Alice transfer to kp_para_src (other chain) and move to the kp_self_dst
# Create new asset id and register on peaq
asset_id = TEST_PALLET_ASSET_ID['peaq']
kp_para_src = Keypair.create_from_mnemonic(Keypair.generate_mnemonic())
self._set_up_peaq_pallet_asset_on_peaq_if_not_exist(asset_id, kp_para_src)

batch = ExtrinsicBatch(self.si_peaq, KP_GLOBAL_SUDO)
batch_fund(batch, SOVERIGN_ADDR, INIT_TOKEN_NUM)
receipt = batch.execute()
self.assertTrue(receipt.is_success, f'Failed to create asset: {receipt.error_message}')

# we won't register on aca because the multilocation is not correct
# we won't need to setup the dst account because we cannot receive it

receipt = send_token_from_peaq_to_para(
self.si_peaq, self.alice, kp_para_src,
ACA_PD_CHAIN_ID, TEST_PALLET_ASSET_ID['peaq'], TEST_TOKEN_NUM)
self.assertTrue(receipt.is_success, f'Failed to send token from peaq to para chain: {receipt.error_message}')
15 changes: 1 addition & 14 deletions tools/runtime_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import importlib

from substrateinterface import SubstrateInterface
from tools.constants import WS_URL, KP_GLOBAL_SUDO, RELAYCHAIN_WS_URL, KP_COLLATOR
from tools.constants import WS_URL, KP_GLOBAL_SUDO, RELAYCHAIN_WS_URL
from peaq.sudo_extrinsic import funds
from peaq.utils import show_extrinsic, get_block_height
from substrateinterface.utils.hasher import blake2_256
Expand Down Expand Up @@ -143,22 +143,9 @@ def do_runtime_upgrade(wasm_path):
# Move it in front of the upgrade because this 1.7.2 upgrade will need to change the node
remove_asset_id(substrate)

batch = ExtrinsicBatch(substrate, KP_GLOBAL_SUDO)
batch.compose_sudo_call(
'ParachainStaking',
'set_max_candidate_stake',
{'new': 1500000 * 10 ** 18}
)
batch.execute()

batch = ExtrinsicBatch(substrate, KP_COLLATOR)
batch.compose_call('ParachainStaking', 'candidate_stake_more', {'more': 50000 * 10 ** 18})
batch.execute()

upgrade(wasm_path)
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)

new_version = substrate.get_block_runtime_version(substrate.get_block_hash())['specVersion']
if old_version == new_version:
Expand Down

0 comments on commit 8c436bf

Please sign in to comment.