def test_determine_role_admin_addr(self): """Tests that a specific role_id and admin_id generates the expected role admin address, and thus is probably deterministic. """ role_id = "99968acb8f1a48b3a4bc21e2cd252e67" admin_id = "966ab67317234df489adb4bc1f517b88" expected_address = "9f444809326a1713a905b26359fc8d\ a2817c1a5f67de6f464701f0c10042da345d28f7" address = addresser.make_role_admins_address(role_id, admin_id) self.assertEqual(len(address), addresser.ADDRESS_LENGTH, "The address is 70 characters") self.assertTrue(addresser.is_address(address), "The address is 70 character hexidecimal") self.assertTrue(addresser.namespace_ok(address), "The address has correct namespace prefix") self.assertTrue( addresser.is_family_address(address), "The address is 70 character hexidecimal with family prefix", ) self.assertEqual(address, expected_address, "The address is the one we expected it to be") self.assertEqual( addresser.address_is(address), AddressSpace.ROLES_ADMINS, "The address created must be a Role Attributes address.", )
def test_generated_user_address(self): """Tests the Users address creation function as well as the address_is function. """ ident = uuid4().hex address = addresser.make_user_address(ident) self.assertEqual(len(address), addresser.ADDRESS_LENGTH, "The address is 70 characters") self.assertTrue(addresser.is_address(address), "The address is 70 character hexidecimal") self.assertTrue(addresser.namespace_ok(address), "The address has correct namespace prefix") self.assertTrue( addresser.is_family_address(address), "The address is 70 character hexidecimal with family prefix", ) self.assertEqual( addresser.address_is(address), AddressSpace.USER, "The address created must be found to be a User address.", )
def test_generated_task_admin_addr(self): """Tests the task admin address creation function as well as the address_is function. """ task_id = uuid4().hex admin_id = uuid4().hex address = addresser.make_task_admins_address(task_id, admin_id) self.assertEqual( len(address), addresser.ADDRESS_LENGTH, "The address is 70 characters" ) self.assertTrue( addresser.is_address(address), "The address is 70 character hexidecimal" ) self.assertTrue( addresser.namespace_ok(address), "The address has correct namespace prefix" ) self.assertTrue( addresser.is_family_address(address), "The address is 70 character hexidecimal with family prefix", ) self.assertEqual( addresser.address_is(address), AddressSpace.TASKS_ADMINS, "The address created must be a Task Attributes address.", )
def test_gen_sysadmin_member_addr(self): """Tests the sysadmin member address creation function as well as the address_is function. """ member_id = uuid4().hex address = addresser.make_sysadmin_members_address(member_id) self.assertEqual(len(address), addresser.ADDRESS_LENGTH, "The address is 70 characters") self.assertTrue(addresser.is_address(address), "The address is 70 character hexidecimal") self.assertTrue(addresser.namespace_ok(address), "The address has correct namespace prefix") self.assertTrue( addresser.is_family_address(address), "The address is 70 character hexidecimal with family prefix", ) self.assertEqual( addresser.address_is(address), AddressSpace.SYSADMIN_MEMBERS, "The address created must be a SysAdmin Attributes address.", )
def test_deterministic_user_address(self): """Tests that a specific user_id generates the expected user address, and thus is probably deterministic. """ ident = "966ab67317234df489adb4bc1f517b88" expected_address = "9f444847e7570f3f6f7d2c1635f6de\ eabc1f4d78d9d42b64b70e1819f244138c1e38d6" address = addresser.make_user_address(ident) self.assertEqual(len(address), addresser.ADDRESS_LENGTH, "The address is 70 characters") self.assertTrue(addresser.is_address(address), "The address is 70 character hexidecimal") self.assertTrue(addresser.namespace_ok(address), "The address has correct namespace prefix") self.assertTrue( addresser.is_family_address(address), "The address is 70 character hexidecimal with family prefix", ) self.assertEqual(address, expected_address, "The address is the one we expected it to be") self.assertEqual( addresser.address_is(address), AddressSpace.USER, "The User address created must be found to be a User address.", )
def test_wrong_family_address(self): """Tests that an address with the wrong family prefix does not validate. """ address = "8f444847e7570f3f6f7d2c1635f6de\ eabc1f4d78d9d42b64b70e1819f244138c1e38d6" self.assertEqual(len(address), addresser.ADDRESS_LENGTH, "The address is 70 characters") self.assertTrue(addresser.is_address(address), "The address is 70 character hexidecimal") self.assertFalse( addresser.namespace_ok(address), "The address does not have correct namespace prefix", ) self.assertFalse( addresser.is_family_address(address), "The address is not 70 character hexidecimal with family prefix", ) with self.assertRaises(ValueError): addresser.address_is(address)
def test_det_sysadmin_member_addr(self): """Tests that a specific member_id generates the expected sysadmin member address, and thus is probably deterministic. """ member_id = "966ab67317234df489adb4bc1f517b88" expected_address = "9f4448000000000000000000000000\ 0000000000000000000000000000000000000083" address = addresser.make_sysadmin_members_address(member_id) self.assertEqual(len(address), addresser.ADDRESS_LENGTH, "The address is 70 characters") self.assertTrue(addresser.is_address(address), "The address is 70 character hexidecimal") self.assertTrue(addresser.namespace_ok(address), "The address has correct namespace prefix") self.assertTrue( addresser.is_family_address(address), "The address is 70 character hexidecimal with family prefix", ) self.assertEqual(address, expected_address, "The address is the one we expected it to be") self.assertEqual( addresser.address_is(address), AddressSpace.SYSADMIN_MEMBERS, "The address created must be a SysAdmin Attributes address.", )
def test_deterministic_task_address(self): """Tests that a specific task_id generates the expected task address, and thus is probably deterministic. """ ident = "99968acb8f1a48b3a4bc21e2cd252e67" expected_address = "9f44481e326a1713a905b26359fc8d\ a2817c1a5f67de6f464701f0c10042da345d2800" address = addresser.make_task_attributes_address(ident) self.assertEqual(len(address), addresser.ADDRESS_LENGTH, "The address is 70 characters") self.assertTrue(addresser.is_address(address), "The address is 70 character hexidecimal") self.assertTrue(addresser.namespace_ok(address), "The address has correct namespace prefix") self.assertTrue( addresser.is_family_address(address), "The address is 70 character hexidecimal with family prefix", ) self.assertEqual(address, expected_address, "The address is the one we expected it to be") self.assertEqual( addresser.address_is(address), AddressSpace.TASKS_ATTRIBUTES, "The address created must be a Task Attributes address.", )
def test_determine_task_owner_addr(self): """Tests that a specific task_id and owner_id generates the expected task owner address, and thus is probably deterministic. """ task_id = "99968acb8f1a48b3a4bc21e2cd252e67" owner_id = "966ab67317234df489adb4bc1f517b88" expected_address = "9f44481e326a1713a905b26359fc8d\ a2817c1a5f67de6f464701f0c10042da345d2808" address = addresser.make_task_owners_address(task_id, owner_id) self.assertEqual(len(address), addresser.ADDRESS_LENGTH, "The address is 70 characters") self.assertTrue(addresser.is_address(address), "The address is 70 character hexidecimal") self.assertTrue(addresser.namespace_ok(address), "The address has correct namespace prefix") self.assertTrue( addresser.is_family_address(address), "The address is 70 character hexidecimal with family prefix", ) self.assertEqual(address, expected_address, "The address is the one we expected it to be") self.assertEqual( addresser.address_is(address), AddressSpace.TASKS_OWNERS, "The address created must be a Task Attributes address.", )
def test_generated_role_member_addr(self): """Tests the role member address creation function as well as the address_is function. """ role_id = uuid4().hex member_id = uuid4().hex address = addresser.make_role_members_address(role_id, member_id) self.assertEqual(len(address), addresser.ADDRESS_LENGTH, "The address is 70 characters") self.assertTrue(addresser.is_address(address), "The address is 70 character hexidecimal") self.assertTrue(addresser.namespace_ok(address), "The address has correct namespace prefix") self.assertTrue( addresser.is_family_address(address), "The address is 70 character hexidecimal with family prefix", ) self.assertEqual( addresser.address_is(address), AddressSpace.ROLES_MEMBERS, "The address created must be a Role Attributes address.", )
def test_determine_sysadmin_addr(self): """Tests that a specific sysadmin_id generates the expected sysadmin address, and thus is probably deterministic. """ expected_address = "9f4448000000000000000000000000\ 0000000000000000000000000000000000000000" address = addresser.make_sysadmin_attr_address() self.assertEqual(len(address), addresser.ADDRESS_LENGTH, "The address is 70 characters") self.assertTrue(addresser.is_address(address), "The address is 70 character hexidecimal") self.assertTrue(addresser.namespace_ok(address), "The address has correct namespace prefix") self.assertTrue( addresser.is_family_address(address), "The address is 70 character hexidecimal with family prefix", ) self.assertEqual(address, expected_address, "The address is the one we expected it to be") self.assertEqual( addresser.address_is(address), AddressSpace.SYSADMIN_ATTRIBUTES, "The address created must be a SysAdmin Attributes address.", )
def test_gen_proposal_addr(self): """Tests the proposal address creation function as well as the address_is function. """ object_id = uuid4().hex related_id = uuid4().hex address = addresser.make_proposal_address(object_id, related_id) self.assertEqual(len(address), addresser.ADDRESS_LENGTH, "The address is 70 characters") self.assertTrue(addresser.is_address(address), "The address is 70 character hexidecimal") self.assertTrue(addresser.namespace_ok(address), "The address has correct namespace prefix") self.assertTrue( addresser.is_family_address(address), "The address is 70 character hexidecimal with family prefix", ) self.assertEqual( addresser.address_is(address), AddressSpace.PROPOSALS, "The address created must be a Proposal address.", )
def test_determine_proposal_addr(self): """Tests that a specific proposal_id generates the expected proposal address, and thus is probably deterministic. """ object_id = "cb048d507eec42a5845e20eed982d5d2" related_id = "f1e916b663164211a9ac34516324681a" expected_address = "9f4448e3b874e90b2bcf58e65e0727\ 91ea499543ee52fc9d0449fc1e41f77d4d4f926e" address = addresser.make_proposal_address(object_id, related_id) self.assertEqual(len(address), addresser.ADDRESS_LENGTH, "The address is 70 characters") self.assertTrue(addresser.is_address(address), "The address is 70 character hexidecimal") self.assertTrue(addresser.namespace_ok(address), "The address has correct namespace prefix") self.assertTrue( addresser.is_family_address(address), "The address is 70 character hexidecimal with family prefix", ) self.assertEqual(address, expected_address, "The address is the one we expected it to be") self.assertEqual( addresser.address_is(address), AddressSpace.PROPOSALS, "The address created must be a Proposal address.", )
def test_nonhex_address(self): """Tests that an address that is not hex does not validate. """ address = "9f444847e7570f3f6f7d2c1635f6de\ eabc1f4d78d9d42b64b70e1819f244138c1e38X6" self.assertFalse(addresser.is_address(address), "The address is not 70 character hexidecimal") self.assertFalse( addresser.is_family_address(address), "The address is not 70 character hexidecimal with family prefix", ) with self.assertRaises(ValueError): addresser.address_is(address)
def test_long_address(self): """Tests that an address that is too long does not validate. """ address = "9f444847e7570f3f6f7d2c1635f6de\ eabc1f4d78d9d42b64b70e1819f244138c1e38d6fe" self.assertFalse( len(address) == addresser.ADDRESS_LENGTH, "The address is not 70 characters") self.assertFalse(addresser.is_address(address), "The address is not 70 character hexidecimal") self.assertFalse( addresser.is_family_address(address), "The address is not 70 character hexidecimal with family prefix", ) with self.assertRaises(ValueError): addresser.address_is(address)
def create_user_transaction(self, name, username, metadata): txn_private_key = Secp256k1PrivateKey.new_random() batch_private_key = Secp256k1PrivateKey.new_random() txn_key = Key(txn_private_key.as_hex()) batch_key = Key(batch_private_key.as_hex()) batchlist, sig = create_user( txn_key, batch_key, name, username, txn_key.public_key, metadata ) self.assertEqual(type(sig), str) self.assertEqual(type(batchlist), batch_pb2.BatchList) self.assertEqual(len(sig), SIGNATURE_LENGTH) self.assertTrue(SIGNATURE_PATTERN.match(sig)) batch_count = 0 for batch in batchlist.batches: batch_count += 1 self.assertEqual(type(batch), batch_pb2.Batch) self.assertEqual(type(batch.header_signature), str) self.assertEqual(len(batch.header_signature), SIGNATURE_LENGTH) self.assertTrue(SIGNATURE_PATTERN.match(batch.header_signature)) trans_count = 0 for transaction in batch.transactions: trans_count += 1 self.assertEqual(type(transaction.header), bytes) self.assertEqual(type(transaction.header_signature), str) self.assertEqual(type(transaction.payload), bytes) self.assertEqual(len(transaction.header_signature), SIGNATURE_LENGTH) self.assertTrue(SIGNATURE_PATTERN.match(transaction.header_signature)) header = transaction_pb2.TransactionHeader() header.ParseFromString(transaction.header) self.assertEqual(type(header), transaction_pb2.TransactionHeader) self.assertEqual(header.family_name, addresser.FAMILY_NAME) self.assertEqual(header.family_version, addresser.FAMILY_VERSION) self.assertEqual(header.batcher_public_key, batch_key.public_key) self.assertEqual(header.signer_public_key, txn_key.public_key) self.assertEqual(len(header.payload_sha512), SIGNATURE_LENGTH) self.assertTrue(SIGNATURE_PATTERN.match(header.payload_sha512)) input_count = 0 for address in header.inputs: input_count += 1 self.assertEqual(type(address), str) self.assertEqual(len(address), addresser.ADDRESS_LENGTH) self.assertTrue(addresser.is_address(address)) self.assertTrue(addresser.namespace_ok(address)) self.assertTrue(addresser.is_family_address(address)) self.assertEqual(addresser.address_is(address), AddressSpace.USER) self.assertEqual(input_count, 1) output_count = 0 for address in header.outputs: output_count += 1 self.assertEqual(type(address), str) self.assertEqual(len(address), addresser.ADDRESS_LENGTH) self.assertTrue(addresser.is_address(address)) self.assertTrue(addresser.namespace_ok(address)) self.assertTrue(addresser.is_family_address(address)) self.assertEqual(addresser.address_is(address), AddressSpace.USER) self.assertEqual(output_count, 1) payload = rbac_payload_pb2.RBACPayload() payload.ParseFromString(transaction.payload) self.assertEqual(type(payload), rbac_payload_pb2.RBACPayload) self.assertEqual( payload.message_type, rbac_payload_pb2.RBACPayload.CREATE_USER ) self.assertEqual(type(payload.content), bytes) user = user_transaction_pb2.CreateUser() user.ParseFromString(payload.content) self.assertEqual(type(user), user_transaction_pb2.CreateUser) self.assertEqual(user.name, name) self.assertEqual(user.user_name, username) self.assertEqual(type(user.user_id), str) self.assertEqual(user.user_id, txn_key.public_key) self.assertEqual(trans_count, 1) self.assertEqual(batch_count, 1)