def test_roundtrip_wif(self): k1 = PrivateKey.generate() k2 = PrivateKey.from_wif(k1.to_wif()) assert k1.key.private_numbers().private_value == k2.key.private_numbers().private_value assert k1.network is k2.network assert k1.compressed == k2.compressed
def test_from_invalid_wif(self): too_short = encoding.b2a_base58check('a') with raises(privkey.InvalidEncoding): PrivateKey.from_wif(too_short) too_long = encoding.b2a_base58check('a' * 30) with raises(privkey.InvalidEncoding): PrivateKey.from_wif(too_long) valid = encoding.a2b_base58check(PrivateKey.generate().to_wif()) with raises(privkey.InvalidEncoding): PrivateKey.from_wif(encoding.b2a_base58check(valid[:-1] + 'a')) with raises(privkey.InvalidEncoding): PrivateKey.from_wif(encoding.b2a_base58check('a' + valid[1:]))
def test_generate_random_keys(self): k1 = PrivateKey.generate() k2 = PrivateKey.generate() assert k1.key.private_numbers() != k2.key.private_numbers()