From b3ce15c7107fb626d68b58cfbdf4e3f86e98f5dd Mon Sep 17 00:00:00 2001 From: Muhammad Talha Dar Date: Fri, 27 Oct 2023 13:00:52 +0500 Subject: [PATCH] Update rbac abi and rbac tests with proper types --- ETH/rbac/rbac.sol.json | 108 ++++++++++++++++++++++++++++++++++++-- tests/bridge_rbac_test.py | 8 +-- 2 files changed, 110 insertions(+), 6 deletions(-) diff --git a/ETH/rbac/rbac.sol.json b/ETH/rbac/rbac.sol.json index 23a6a1c..02952e8 100644 --- a/ETH/rbac/rbac.sol.json +++ b/ETH/rbac/rbac.sol.json @@ -5,9 +5,15 @@ { "indexed": false, "internalType": "address", - "name": "owner", + "name": "sender", "type": "address" }, + { + "indexed": false, + "internalType": "bytes32", + "name": "owner", + "type": "bytes32" + }, { "indexed": false, "internalType": "bytes32", @@ -24,6 +30,37 @@ "name": "RoleAdded", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "owner", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "role_id", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "name", + "type": "bytes" + } + ], + "name": "RoleUpdated", + "type": "event" + }, { "inputs": [ { @@ -51,9 +88,9 @@ { "inputs": [ { - "internalType": "address", + "internalType": "bytes32", "name": "owner", - "type": "address" + "type": "bytes32" }, { "internalType": "bytes32", @@ -88,5 +125,70 @@ ], "stateMutability": "view", "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "owner", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + } + ], + "name": "fetch_roles", + "outputs": [ + { + "components": [ + { + "internalType": "bytes32", + "name": "owner", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "name", + "type": "bytes" + }, + { + "internalType": "bool", + "name": "enabled", + "type": "bool" + } + ], + "internalType": "struct RBAC.EntityAttribute[]", + "name": "", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role_id", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "name", + "type": "bytes" + } + ], + "name": "update_role", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" } ] \ No newline at end of file diff --git a/tests/bridge_rbac_test.py b/tests/bridge_rbac_test.py index 716a11a..b0e5d63 100644 --- a/tests/bridge_rbac_test.py +++ b/tests/bridge_rbac_test.py @@ -25,8 +25,8 @@ TOKEN_NUM = 10000 * pow(10, 15) # A role and it's name -ROLE_ID_1 = generate_random_hex() -ROLE_ID_1_NAME = 'role1' +ROLE_ID_1 = generate_random_hex(15).encode("utf-8") +ROLE_ID_1_NAME = generate_random_hex(15).encode("utf-8") def _calcualte_evm_basic_req(substrate, w3, addr): @@ -78,6 +78,8 @@ def check_item_from_event(self, event, account, role_id, name): self.assertEqual(f"0x{events[0]['args']['name'].hex()}", f"{name}") def test_add_role_and_check(self): + print("ROLE_ID ", ROLE_ID_1, "len: ", len(ROLE_ID_1)) + substrate = self._substrate eth_src = self._eth_src w3 = self._w3 @@ -106,4 +108,4 @@ def test_add_role_and_check(self): data = contract.functions.fetch_role(account, ROLE_ID_1).call() # Check: Fetch Role - self.assertEqual(f'0x{data.hex()}', ROLE_ID_1_NAME) + self.assertEqual(f'0x{data.hex()}', ROLE_ID_1_NAME) \ No newline at end of file