def test_blake2b(): h, _ = cry.blake2b256([b'hello world']) assert h.hex( ) == '256c83b297114d201b30179f3f0ef0cace9783622da5974326b436178aeef610' h, _ = cry.blake2b256([b'hello', b' world']) assert h.hex( ) == '256c83b297114d201b30179f3f0ef0cace9783622da5974326b436178aeef610'
def test_unsigned(): x = unsigned.encode() signing_hash, _ = cry.blake2b256([x]) assert signing_hash.hex() == '2a1c25ce0d66f45276a5f308b99bf410e2fc7d5b6ea37a49f2ab9f1da9446478' assert unsigned.get_signing_hash().hex() == '2a1c25ce0d66f45276a5f308b99bf410e2fc7d5b6ea37a49f2ab9f1da9446478' assert unsigned.get_id() is None assert unsigned.get_intrinsic_gas() == 37432 body_1 = copy.deepcopy(body) body_1.clauses = [] assert transaction.Transaction(body_1).get_intrinsic_gas() == 21000 body_2 = copy.deepcopy(body) body_2.clauses = [ transaction.Clause( to=None, value=0, data='0x' ) ] assert transaction.Transaction(body_2).get_intrinsic_gas() == 53000 assert unsigned.get_signature() == None assert unsigned.get_origin() == None assert unsigned.encode().hex() == unsigned_encoded.hex() assert transaction.Transaction.decode(unsigned_encoded, True) == unsigned
def test_verify(): to_be_signed, _ = cry.blake2b256([ certificate.encode(cert).encode('utf-8') ]) sig_bytes = cry.secp256k1.sign( to_be_signed, PRIV_KEY ) sig = '0x' + sig_bytes.hex() # Signature doesn't match. with pytest.raises(Exception, match='signature does not match with the signer.'): temp = copy.copy(cert_dict) temp['signature'] = sig temp['signer'] = '0x' certificate.verify(certificate.Certificate(**temp)) # Everything is fine. temp2 = copy.copy(cert_dict) temp2['signature'] = sig certificate.verify(certificate.Certificate(**temp2)) # Everything is fine. temp3 = copy.copy(cert_dict) temp3['signature'] = sig.upper() certificate.verify(certificate.Certificate(**temp3))
def test_encode(): assert certificate.encode(cert) == certificate.encode(cert2) temp = copy.deepcopy(cert_dict) temp['signer'] = temp['signer'].upper() temp_cert = certificate.Certificate(**temp) assert certificate.encode(cert) == certificate.encode(temp_cert) sig_bytes = cry.secp256k1.sign( cry.blake2b256([ certificate.encode(cert).encode('utf-8') ])[0], PRIV_KEY ) sig = '0x' + sig_bytes.hex() temp2 = copy.deepcopy(cert_dict) temp2['signature'] = sig temp2_cert = certificate.Certificate(**temp2) temp3 = copy.deepcopy(cert_dict) temp3['signature'] = sig.upper() temp3_cert = certificate.Certificate(**temp3) assert certificate.encode(temp2_cert) == certificate.encode(temp3_cert)
data='0x000000606060' ) ], gas_price_coef=128, gas=21000, depends_on=None, nonce=12345678 ) unsigned = transaction.Transaction(body) unsigned_encoded = bytes.fromhex('f8540184aabbccdd20f840df947567d83b7b8d80addcb281a71d54fc7b3364ffed82271086000000606060df947567d83b7b8d80addcb281a71d54fc7b3364ffed824e208600000060606081808252088083bc614ec0') signed = transaction.Transaction(body) signed_encoded = bytes.fromhex('f8970184aabbccdd20f840df947567d83b7b8d80addcb281a71d54fc7b3364ffed82271086000000606060df947567d83b7b8d80addcb281a71d54fc7b3364ffed824e208600000060606081808252088083bc614ec0b841f76f3c91a834165872aa9464fc55b03a13f46ea8d3b858e528fcceaf371ad6884193c3f313ff8effbb57fe4d1adc13dceb933bedbf9dbb528d2936203d5511df00') priv_key = bytes.fromhex('7582be841ca040aa940fff6c05773129e135623e41acce3e0b8ba520dc1ae26a') _a, _ = cry.blake2b256([signed.encode()]) _b = cry.secp256k1.sign(_a, priv_key) signed.set_signature(_b) signer = cry.public_key_to_address(cry.secp256k1.derive_publicKey(priv_key)) def test_unsigned(): x = unsigned.encode() signing_hash, _ = cry.blake2b256([x]) assert signing_hash.hex() == '2a1c25ce0d66f45276a5f308b99bf410e2fc7d5b6ea37a49f2ab9f1da9446478' assert unsigned.get_signing_hash().hex() == '2a1c25ce0d66f45276a5f308b99bf410e2fc7d5b6ea37a49f2ab9f1da9446478' assert unsigned.get_id() is None assert unsigned.get_intrinsic_gas() == 37432