def test_key():
    """Test get a generated keypair"""
    key1 = helper.user.key()
    key2 = helper.user.key()
    assert isinstance(key1, Key)
    assert isinstance(key2, Key)
    assert PUBLIC_KEY_PATTERN.match(key1.public_key)
    assert PUBLIC_KEY_PATTERN.match(key2.public_key)
    assert PRIVATE_KEY_PATTERN.match(key1.private_key)
    assert PRIVATE_KEY_PATTERN.match(key2.private_key)
    assert key1.public_key != key2.public_key
    assert key1.private_key != key2.private_key
Exemple #2
0
 def assertIsPrivateKeyHex(self, key):
     """Sanity checks a hexidecimal string private key"""
     self.assertIsInstance(key, str)
     self.assertTrue(PRIVATE_KEY_PATTERN.match(key))
     key = Secp256k1PrivateKey.from_hex(key)
     self.assertIsPrivateKeySecp256k1(key)
     return key
Exemple #3
0
 def test_key_class_given_private_key(self):
     """Test initializing the key class with a given private key"""
     private_key = Secp256k1PrivateKey.new_random()
     txn_key = Key(private_key.as_hex())
     self.assertEqual(len(txn_key.private_key), PRIVATE_KEY_LENGTH * 2)
     self.assertTrue(PRIVATE_KEY_PATTERN.match(txn_key.private_key))
     self.assertEqual(txn_key.private_key, private_key.as_hex())
     self.assertEqual(len(txn_key.public_key), PUBLIC_KEY_LENGTH * 2)
     self.assertTrue(PUBLIC_KEY_PATTERN.match(txn_key.public_key))
 def test_key_class_random_keys(self):
     value1 = Key()
     value2 = Key()
     self.assertTrue(isinstance(value1, Key))
     self.assertTrue(isinstance(value2, Key))
     self.assertNotEqual(value1, value2)
     self.assertIsInstance(value1.public_key, str)
     self.assertIsInstance(value2.public_key, str)
     self.assertIsInstance(value1.private_key, str)
     self.assertIsInstance(value2.private_key, str)
     self.assertEqual(len(value1.public_key), PUBLIC_KEY_LENGTH * 2)
     self.assertEqual(len(value2.public_key), PUBLIC_KEY_LENGTH * 2)
     self.assertEqual(len(value1.private_key), PRIVATE_KEY_LENGTH * 2)
     self.assertEqual(len(value2.private_key), PRIVATE_KEY_LENGTH * 2)
     self.assertTrue(PUBLIC_KEY_PATTERN.match(value1.public_key))
     self.assertTrue(PUBLIC_KEY_PATTERN.match(value2.public_key))
     self.assertTrue(PRIVATE_KEY_PATTERN.match(value1.private_key))
     self.assertTrue(PRIVATE_KEY_PATTERN.match(value2.private_key))
     self.assertNotEqual(value1.public_key, value2.public_key)
     self.assertNotEqual(value1.private_key, value2.private_key)
Exemple #5
0
 def test_key_class_random_keys(self):
     """Test the key class generates different keys each time initialized"""
     value1 = Key()
     value2 = Key()
     self.assertTrue(isinstance(value1, Key))
     self.assertTrue(isinstance(value2, Key))
     self.assertNotEqual(value1, value2)
     self.assertIsInstance(value1.public_key, str)
     self.assertIsInstance(value2.public_key, str)
     self.assertIsInstance(value1.private_key, str)
     self.assertIsInstance(value2.private_key, str)
     self.assertEqual(len(value1.public_key), PUBLIC_KEY_LENGTH * 2)
     self.assertEqual(len(value2.public_key), PUBLIC_KEY_LENGTH * 2)
     self.assertEqual(len(value1.private_key), PRIVATE_KEY_LENGTH * 2)
     self.assertEqual(len(value2.private_key), PRIVATE_KEY_LENGTH * 2)
     self.assertTrue(PUBLIC_KEY_PATTERN.match(value1.public_key))
     self.assertTrue(PUBLIC_KEY_PATTERN.match(value2.public_key))
     self.assertTrue(PRIVATE_KEY_PATTERN.match(value1.private_key))
     self.assertTrue(PRIVATE_KEY_PATTERN.match(value2.private_key))
     self.assertNotEqual(value1.public_key, value2.public_key)
     self.assertNotEqual(value1.private_key, value2.private_key)
Exemple #6
0
 def assertIsPrivateKeySecp256k1(self, key):
     """Sanity checks a Secp256k1PrivateKey private key"""
     self.assertIsInstance(key, Secp256k1PrivateKey)
     self.assertIsInstance(key.as_hex(), str)
     self.assertEqual(len(key.as_hex()), PRIVATE_KEY_LENGTH * 2)
     self.assertTrue(PRIVATE_KEY_PATTERN.match(key.as_hex()))
     self.assertIsInstance(key.as_bytes(), bytes)
     self.assertEqual(len(key.as_bytes()), PRIVATE_KEY_LENGTH)
     self.assertEqual(key.as_hex(),
                      str(binascii.hexlify(key.as_bytes()), "ascii"))
     self.assertEqual(binascii.unhexlify(key.as_hex()), key.as_bytes())
     return key
 def test_key_class_private_key(self):
     private_key = Secp256k1PrivateKey.new_random()
     txn_key = Key(private_key.as_hex())
     self.assertEqual(len(txn_key.private_key), PRIVATE_KEY_LENGTH * 2)
     self.assertTrue(PRIVATE_KEY_PATTERN.match(txn_key.private_key))
     self.assertEqual(txn_key.private_key, private_key.as_hex())
 def test_key_class_no_constructor_inputs(self):
     txn_key = Key()
     self.assertEqual(len(txn_key.private_key), PRIVATE_KEY_LENGTH * 2)
     self.assertTrue(PRIVATE_KEY_PATTERN.match(txn_key.private_key))
Exemple #9
0
 def test_key_class_no_constructor_inputs(self):
     """Test making random keypair (no init values)"""
     txn_key = Key()
     self.assertEqual(len(txn_key.private_key), PRIVATE_KEY_LENGTH * 2)
     self.assertTrue(PRIVATE_KEY_PATTERN.match(txn_key.private_key))