Skip to content

Commit

Permalink
Add deposit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypan authored and Jay Pan committed Nov 1, 2024
1 parent 51c5866 commit 3048c35
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/pallet_did_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,28 @@
from tools.constants import WS_URL
from peaq.utils import ExtrinsicBatch
from peaq.did import did_add_payload, did_update_payload, did_remove_payload, did_rpc_read
from tools.runtime_upgrade import wait_until_block_height
from tools.constants import PARACHAIN_WS_URL, RELAYCHAIN_WS_URL
from peaq.utils import get_chain
from tools.utils import get_modified_chain_spec


DID_MIN_DEPOSIT = {
'peaq-dev': 0.1 * 10 ** 18,
'krest-network': 0.1 * 10 ** 18,
'peaq-network': 0.005 * 10 ** 18,
}


@pytest.mark.substrate
class TestPalletDid(unittest.TestCase):
def setUp(self):
self.substrate = SubstrateInterface(url=WS_URL)
self.kp_src = Keypair.create_from_uri('//Alice')
wait_until_block_height(SubstrateInterface(url=RELAYCHAIN_WS_URL), 1)
wait_until_block_height(SubstrateInterface(url=PARACHAIN_WS_URL), 1)
self.chain_spec = get_chain(self.substrate)
self.chain_spec = get_modified_chain_spec(self.chain_spec)

def test_did_add(self):
reserved_before = get_balance_reserve_value(self.substrate, self.kp_src.ss58_address, 'peaq_did')
Expand All @@ -32,6 +47,7 @@ def test_did_add(self):
self.assertEqual(data['value'], value)
reserved_after = get_balance_reserve_value(self.substrate, self.kp_src.ss58_address, 'peaq_did')
self.assertGreater(reserved_after, reserved_before)
self.assertGreaterEqual(reserved_after - reserved_before, DID_MIN_DEPOSIT[self.chain_spec])

def test_did_update(self):
name = int(time.time())
Expand Down
30 changes: 30 additions & 0 deletions tests/pallet_rbac_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,20 @@
from peaq.rbac import rbac_rpc_fetch_groups
from tools.utils import get_balance_reserve_value
from tools.constants import KP_GLOBAL_SUDO
from tools.runtime_upgrade import wait_until_block_height
from tools.constants import PARACHAIN_WS_URL, RELAYCHAIN_WS_URL
from peaq.utils import get_chain
from tools.utils import get_modified_chain_spec
import unittest


RBAC_MIN_DEPOSIT = {
'peaq-dev': 0.1 * 10 ** 18,
'krest-network': 0.1 * 10 ** 18,
'peaq-network': 0.005 * 10 ** 18,
}


KP_TEST = Keypair.create_from_mnemonic(Keypair.generate_mnemonic())
RANDOM_PREFIX = KP_TEST.public_key.hex()[2:26]

Expand Down Expand Up @@ -437,6 +448,10 @@ def verify_rpc_fail_disabled_id(self, kp_src):

def setUp(self):
self.substrate = SubstrateInterface(url=WS_URL)
wait_until_block_height(SubstrateInterface(url=RELAYCHAIN_WS_URL), 1)
wait_until_block_height(SubstrateInterface(url=PARACHAIN_WS_URL), 1)
self.chain_spec = get_chain(self.substrate)
self.chain_spec = get_modified_chain_spec(self.chain_spec)

def test_pallet_rbac(self):
print('---- pallet_rbac_test!! ----')
Expand Down Expand Up @@ -475,6 +490,21 @@ def test_pallet_rbac(self):
print(f'🔥 Test/{func}, Failed')
raise

def test_reserve_check(self):
ROLE_TEST = '{0}03456789abcdef0123456111abcde00123456111'.format(RANDOM_PREFIX)

kp_src = Keypair.create_from_mnemonic(Keypair.generate_mnemonic())
fund(self.substrate, KP_GLOBAL_SUDO, kp_src, 1000 * 10 ** 18)

reserved_before = get_balance_reserve_value(self.substrate, kp_src.ss58_address, 'peaqrbac')
batch = ExtrinsicBatch(self.substrate, kp_src)
rbac_add_role_payload(batch, f'0x{ROLE_TEST}', ROLE_NM1)
receipt = batch.execute()
self.assertTrue(receipt.is_success, f'Extrinsic-call-stack failed: {receipt.error_message}')
reserved_after = get_balance_reserve_value(self.substrate, kp_src.ss58_address, 'peaqrbac')
self.assertGreater(reserved_after, reserved_before)
self.assertGreaterEqual(reserved_after - reserved_before, RBAC_MIN_DEPOSIT[self.chain_spec])

def test_delete_types(self):
ROLE_TEST = '{0}03456789abcdef0123456111abcdef0123456111'.format(RANDOM_PREFIX)
GROUP_TEST = '{0}0defabcdabcdefabc111abcdabcdefabcdefa111'.format(RANDOM_PREFIX)
Expand Down
16 changes: 16 additions & 0 deletions tests/pallet_storage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@
from substrateinterface import SubstrateInterface, Keypair
from peaq.utils import ExtrinsicBatch
from peaq.storage import storage_add_payload, storage_update_payload, storage_rpc_read
from tools.utils import get_modified_chain_spec
from tools.runtime_upgrade import wait_until_block_height
from tools.constants import PARACHAIN_WS_URL, RELAYCHAIN_WS_URL
from peaq.utils import get_chain

import unittest


STORAGE_MIN_DEPOSIT = {
'peaq-dev': 0.1 * 10 ** 18,
'krest-network': 0.1 * 10 ** 18,
'peaq-network': 0.005 * 10 ** 18,
}


def storage_remove_payload(batch, item_type):
batch.compose_call(
'PeaqStorage',
Expand All @@ -23,6 +34,10 @@ class TestPalletStorage(unittest.TestCase):
def setUp(self):
self._substrate = SubstrateInterface(url=WS_URL)
self._kp_src = Keypair.create_from_uri('//Alice')
wait_until_block_height(SubstrateInterface(url=RELAYCHAIN_WS_URL), 1)
wait_until_block_height(SubstrateInterface(url=PARACHAIN_WS_URL), 1)
self._chain_spec = get_chain(self._substrate)
self._chain_spec = get_modified_chain_spec(self._chain_spec)

def test_storage(self):
reserved_before = get_balance_reserve_value(self._substrate, self._kp_src.ss58_address, 'peaqstor')
Expand All @@ -40,6 +55,7 @@ def test_storage(self):
item)
reserved_after = get_balance_reserve_value(self._substrate, self._kp_src.ss58_address, 'peaqstor')
self.assertGreater(reserved_after, reserved_before)
self.assertGreaterEqual(reserved_after - reserved_before, STORAGE_MIN_DEPOSIT[self._chain_spec])

def test_storage_update(self):
batch = ExtrinsicBatch(self._substrate, self._kp_src)
Expand Down

0 comments on commit 3048c35

Please sign in to comment.