Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_input_deserialization_with_unsigned_fulfillment(ffill_uri, user_pub):
from bigchaindb.common.transaction import Input
from cryptoconditions import Fulfillment
expected = Input(Fulfillment.from_uri(ffill_uri), [user_pub])
ffill = {
'owners_before': [user_pub],
'fulfillment': Fulfillment.from_uri(ffill_uri),
'fulfills': None,
}
input = Input.from_dict(ffill)
assert input == expected
def test_fulfill_transaction(alice_transaction, alice_sk):
from bigchaindb_driver.offchain import fulfill_transaction
fulfilled_transaction = fulfill_transaction(
alice_transaction, private_keys=alice_sk)
inputs = fulfilled_transaction['inputs']
assert len(inputs) == 1
alice_transaction['inputs'][0]['fulfillment'] = None
message = rapidjson.dumps(
alice_transaction,
skipkeys=False,
ensure_ascii=False,
sort_keys=True,
)
message = sha3_256(message.encode())
fulfillment_uri = inputs[0]['fulfillment']
assert Fulfillment.from_uri(fulfillment_uri).\
validate(message=message.digest())
Optionally, this method can also serialize a Cryptoconditions-
Fulfillment that is not yet signed.
Args:
data (dict): The Input to be transformed.
Returns:
:class:`~bigchaindb.common.transaction.Input`
Raises:
InvalidSignature: If an Input's URI couldn't be parsed.
"""
fulfillment = data['fulfillment']
if not isinstance(fulfillment, (Fulfillment, type(None))):
try:
fulfillment = Fulfillment.from_uri(data['fulfillment'])
except ASN1DecodeError:
# TODO Remove as it is legacy code, and simply fall back on
# ASN1DecodeError
raise InvalidSignature("Fulfillment URI couldn't been parsed")
except TypeError:
# NOTE: See comment about this special case in
# `Input.to_dict`
fulfillment = _fulfillment_from_details(data['fulfillment'])
fulfills = TransactionLink.from_dict(data['fulfills'])
return cls(fulfillment, data['owners_before'], fulfills)