def test_load_key(self): pri_k, pub_k = ECCipher.load_key_pair(self.private_key_file_path, self.password) self.assertIsNotNone(pri_k) self.assertIsNotNone(pub_k) pri_key = ECCipher.load_private_key(self.private_key_file_path, self.password) self.assertIsNotNone(pri_key) msg = 'test123' sig = ECCipher.create_signature(pri_key, msg) print('sig:', sig) self.assertIsNotNone(sig) create_pub_key = ECCipher.create_public_key_from_private_key(pri_key) self.assertIsNotNone(create_pub_key) load_pub_key = ECCipher.load_public_key(self.private_key_file_path, self.password) self.assertIsNotNone(load_pub_key) v1 = ECCipher.verify_sign(load_pub_key, sig, msg) self.assertTrue(v1) v2 = ECCipher.verify_sign(create_pub_key, sig, msg) self.assertTrue(v2) addr = ECCipher.get_address_from_public_key(load_pub_key) print(addr) self.assertIsNotNone(addr)
def mockup_product(self): private_key = ECCipher.create_private_key(self.account.privateKey) public_key = ECCipher.create_public_key_from_private_key(private_key) public_key = ECCipher.serialize_public_key(public_key) price = randint(1, 10000) * 0.01 return { 'description': 'stress testing description', 'signature': '304502201b31544ff65ebbfff3743a0b2536388e1f6cf2533de4bbf0ffab57d762f54d50022100a8101face8c6a6d2f0e01a9a01ea49d80598c880872db9e3c1e9eb27a23a2554', 'cover_image': 'upload_images/20181127072441_13.png', 'end_date': '2018-12-04T15:24:41.664517Z', 'msg_hash': 'dRFWYcWC9TKujDo7mLiUCq00MthHezzkyncAGIdaEos=', 'id': 53, 'start_date': '2018-11-27T15:24:41.664517Z', 'ptype': 'file', 'seq': 0, 'owner_address': public_key, 'tags': 'stress testing tags', 'price': price, 'title': 'stress testing product', 'category': 'stress testing category', 'status': 0, 'created': '2018-11-27T07:24:41.715315Z' }
def __init__(self, eth_account): self.private_key = ECCipher.create_private_key(eth_account.privateKey) public_key = ECCipher.create_public_key_from_private_key(self.private_key) self.public_key = ECCipher.serialize_public_key(public_key) # self.address = eth_account.address self.address = ECCipher.get_address_from_public_key(public_key)