mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Merge remote-tracking branch 'remotes/origin/feat/127/crypto-conditions-ilp-bigchain-integration' into feat/128/multiple-input-output
This commit is contained in:
commit
4936ce6ff4
@ -123,7 +123,7 @@ class BaseConsensusRules(AbstractConsensusRules):
|
||||
# TODO: for now lets assume a CREATE transaction only has one fulfillment
|
||||
if transaction['transaction']['fulfillments'][0]['input']:
|
||||
raise ValueError('A CREATE operation has no inputs')
|
||||
# TODO: fow now lets assume a CREATE transaction only has one current_owner
|
||||
# TODO: for now lets assume a CREATE transaction only has one current_owner
|
||||
if transaction['transaction']['fulfillments'][0]['current_owners'][0] not in (
|
||||
bigchain.federation_nodes + [bigchain.me]):
|
||||
raise exceptions.OperationError(
|
||||
@ -144,7 +144,7 @@ class BaseConsensusRules(AbstractConsensusRules):
|
||||
raise exceptions.TransactionDoesNotExist(
|
||||
'input `{}` does not exist in the bigchain'.format(
|
||||
fulfillment['input']['txid']))
|
||||
|
||||
# TODO: check if current owners own tx_input (maybe checked by InvalidSignature)
|
||||
# check if the input was already spent by a transaction other than
|
||||
# this one.
|
||||
spent = bigchain.get_spent(fulfillment['input'])
|
||||
@ -159,8 +159,7 @@ class BaseConsensusRules(AbstractConsensusRules):
|
||||
for fulfillment in transaction_data['transaction']['fulfillments']:
|
||||
fulfillment['fulfillment'] = None
|
||||
|
||||
calculated_hash = crypto.hash_data(util.serialize(
|
||||
transaction['transaction']))
|
||||
calculated_hash = crypto.hash_data(util.serialize(transaction_data['transaction']))
|
||||
if calculated_hash != transaction['id']:
|
||||
raise exceptions.InvalidHash()
|
||||
|
||||
|
@ -34,9 +34,9 @@ class TestBigchainApi(object):
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_create_transaction_transfer(self, b, user_vk, user_sk):
|
||||
input_tx = b.get_owned_ids(user_vk).pop()
|
||||
assert b.verify_signature(b.get_transaction(input_tx)) == True
|
||||
assert b.verify_signature(b.get_transaction(input_tx['txid'])) == True
|
||||
|
||||
tx = b.create_transaction(b.me, user_sk, {'txid': input_tx, 'cid': 0}, 'TRANSFER')
|
||||
tx = b.create_transaction(b.me, user_sk, input_tx, 'TRANSFER')
|
||||
|
||||
assert sorted(tx) == sorted(['id', 'transaction', 'version'])
|
||||
assert sorted(tx['transaction']) == sorted(['conditions', 'data', 'fulfillments', 'operation', 'timestamp'])
|
||||
@ -79,7 +79,7 @@ class TestBigchainApi(object):
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_write_transaction(self, b, user_vk, user_sk):
|
||||
input_tx = b.get_owned_ids(user_vk).pop()
|
||||
tx = b.create_transaction(user_vk, user_vk, {'txid': input_tx, 'cid': 0}, 'TRANSFER')
|
||||
tx = b.create_transaction(user_vk, user_vk, input_tx, 'TRANSFER')
|
||||
tx_signed = b.sign_transaction(tx, user_sk)
|
||||
response = b.write_transaction(tx_signed)
|
||||
|
||||
@ -93,7 +93,7 @@ class TestBigchainApi(object):
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_read_transaction(self, b, user_vk, user_sk):
|
||||
input_tx = b.get_owned_ids(user_vk).pop()
|
||||
tx = b.create_transaction(user_vk, user_vk, {'txid': input_tx, 'cid': 0}, 'TRANSFER')
|
||||
tx = b.create_transaction(user_vk, user_vk, input_tx, 'TRANSFER')
|
||||
tx_signed = b.sign_transaction(tx, user_sk)
|
||||
b.write_transaction(tx_signed)
|
||||
|
||||
@ -107,7 +107,7 @@ class TestBigchainApi(object):
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_assign_transaction_one_node(self, b, user_vk, user_sk):
|
||||
input_tx = b.get_owned_ids(user_vk).pop()
|
||||
tx = b.create_transaction(user_vk, user_vk, {'txid': input_tx, 'cid': 0}, 'TRANSFER')
|
||||
tx = b.create_transaction(user_vk, user_vk, input_tx, 'TRANSFER')
|
||||
tx_signed = b.sign_transaction(tx, user_sk)
|
||||
b.write_transaction(tx_signed)
|
||||
|
||||
@ -126,7 +126,7 @@ class TestBigchainApi(object):
|
||||
# test assignee for several transactions
|
||||
for _ in range(20):
|
||||
input_tx = b.get_owned_ids(user_vk).pop()
|
||||
tx = b.create_transaction(user_vk, user_vk, {'txid': input_tx, 'cid': 0}, 'TRANSFER')
|
||||
tx = b.create_transaction(user_vk, user_vk, input_tx, 'TRANSFER')
|
||||
tx_signed = b.sign_transaction(tx, user_sk)
|
||||
b.write_transaction(tx_signed)
|
||||
|
||||
@ -240,7 +240,7 @@ class TestTransactionValidation(object):
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_create_operation_with_inputs(self, b, user_vk):
|
||||
input_tx = b.get_owned_ids(user_vk).pop()
|
||||
tx = b.create_transaction(b.me, user_vk, {'txid': input_tx, 'cid': 0}, 'CREATE')
|
||||
tx = b.create_transaction(b.me, user_vk, input_tx, 'CREATE')
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
b.validate_transaction(tx)
|
||||
|
||||
@ -273,19 +273,19 @@ class TestTransactionValidation(object):
|
||||
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_non_create_valid_input_wrong_owner(self, b, user_vk):
|
||||
valid_input = b.get_owned_ids(user_vk).pop()
|
||||
input_valid = b.get_owned_ids(user_vk).pop()
|
||||
sk, vk = crypto.generate_key_pair()
|
||||
tx = b.create_transaction(vk, user_vk, {'txid': valid_input, 'cid': 0}, 'TRANSFER')
|
||||
with pytest.raises(exceptions.TransactionOwnerError) as excinfo:
|
||||
tx = b.create_transaction(vk, user_vk, input_valid, 'TRANSFER')
|
||||
with pytest.raises(exceptions.InvalidSignature) as excinfo:
|
||||
b.validate_transaction(tx)
|
||||
|
||||
assert excinfo.value.args[0] == 'current_owner `a` does not own the input `{}`'.format(valid_input)
|
||||
# assert excinfo.value.args[0] == 'current_owner `a` does not own the input `{}`'.format(valid_input)
|
||||
assert b.is_valid_transaction(tx) is False
|
||||
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_non_create_double_spend(self, b, user_vk, user_sk):
|
||||
input_valid = b.get_owned_ids(user_vk).pop()
|
||||
tx_valid = b.create_transaction(user_vk, 'b', input_valid, 'd')
|
||||
tx_valid = b.create_transaction(user_vk, user_vk, input_valid, 'TRANSFER')
|
||||
tx_valid_signed = b.sign_transaction(tx_valid, user_sk)
|
||||
b.write_transaction(tx_valid_signed)
|
||||
|
||||
@ -294,7 +294,7 @@ class TestTransactionValidation(object):
|
||||
b.write_block(block, durability='hard')
|
||||
|
||||
# create another transaction with the same input
|
||||
tx_double_spend = b.create_transaction(user_vk, 'd', input_valid, 'd')
|
||||
tx_double_spend = b.create_transaction(user_vk, user_vk, input_valid, 'TRANSFER')
|
||||
with pytest.raises(exceptions.DoubleSpend) as excinfo:
|
||||
b.validate_transaction(tx_double_spend)
|
||||
|
||||
@ -304,7 +304,7 @@ class TestTransactionValidation(object):
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_wrong_transaction_hash(self, b, user_vk):
|
||||
input_valid = b.get_owned_ids(user_vk).pop()
|
||||
tx_valid = b.create_transaction(user_vk, 'b', input_valid, 'd')
|
||||
tx_valid = b.create_transaction(user_vk, user_vk, input_valid, 'TRANSFER')
|
||||
|
||||
# change the transaction hash
|
||||
tx_valid.update({'id': 'abcd'})
|
||||
@ -315,7 +315,7 @@ class TestTransactionValidation(object):
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_wrong_signature(self, b, user_vk):
|
||||
input_valid = b.get_owned_ids(user_vk).pop()
|
||||
tx_valid = b.create_transaction(user_vk, 'b', input_valid, 'd')
|
||||
tx_valid = b.create_transaction(user_vk, user_vk, input_valid, 'TRANSFER')
|
||||
|
||||
wrong_private_key = '4fyvJe1aw2qHZ4UNRYftXK7JU7zy9bCqoU5ps6Ne3xrY'
|
||||
|
||||
@ -333,7 +333,7 @@ class TestTransactionValidation(object):
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_valid_non_create_transaction(self, b, user_vk, user_sk):
|
||||
input_valid = b.get_owned_ids(user_vk).pop()
|
||||
tx_valid = b.create_transaction(user_vk, 'b', input_valid, 'd')
|
||||
tx_valid = b.create_transaction(user_vk, user_vk, input_valid, 'TRANSFER')
|
||||
|
||||
tx_valid_signed = b.sign_transaction(tx_valid, user_sk)
|
||||
assert tx_valid_signed == b.validate_transaction(tx_valid_signed)
|
||||
@ -342,7 +342,7 @@ class TestTransactionValidation(object):
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_valid_non_create_transaction_after_block_creation(self, b, user_vk, user_sk):
|
||||
input_valid = b.get_owned_ids(user_vk).pop()
|
||||
tx_valid = b.create_transaction(user_vk, 'b', input_valid, 'd')
|
||||
tx_valid = b.create_transaction(user_vk, user_vk, input_valid, 'TRANSFER')
|
||||
|
||||
tx_valid_signed = b.sign_transaction(tx_valid, user_sk)
|
||||
assert tx_valid_signed == b.validate_transaction(tx_valid_signed)
|
||||
@ -412,7 +412,7 @@ class TestBlockValidation(object):
|
||||
def test_valid_block(self, b, user_vk, user_sk):
|
||||
# create valid transaction
|
||||
input_valid = b.get_owned_ids(user_vk).pop()
|
||||
tx_valid = b.create_transaction(user_vk, 'b', input_valid, 'd')
|
||||
tx_valid = b.create_transaction(user_vk, user_vk, input_valid, 'TRANSFER')
|
||||
tx_valid_signed = b.sign_transaction(tx_valid, user_sk)
|
||||
|
||||
# create valid block
|
||||
|
@ -125,7 +125,7 @@ class TestBigchainVoter(object):
|
||||
|
||||
# create a `TRANSFER` transaction
|
||||
test_user2_priv, test_user2_pub = crypto.generate_key_pair()
|
||||
tx2 = b.create_transaction(test_user_pub, test_user2_pub, tx['id'], 'TRANSFER')
|
||||
tx2 = b.create_transaction(test_user_pub, test_user2_pub, {'txid': tx['id'], 'cid': 0}, 'TRANSFER')
|
||||
tx2_signed = b.sign_transaction(tx2, test_user_priv)
|
||||
assert b.is_valid_transaction(tx2_signed)
|
||||
|
||||
|
@ -11,8 +11,8 @@ TX_ENDPOINT = '/api/v1/transactions/'
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_get_transaction_endpoint(b, client, user_vk):
|
||||
input_tx = b.get_owned_ids(user_vk).pop()
|
||||
tx = b.get_transaction(input_tx)
|
||||
res = client.get(TX_ENDPOINT + input_tx)
|
||||
tx = b.get_transaction(input_tx['txid'])
|
||||
res = client.get(TX_ENDPOINT + input_tx['txid'])
|
||||
assert tx == res.json
|
||||
|
||||
|
||||
@ -22,21 +22,18 @@ def test_post_create_transaction_endpoint(b, client):
|
||||
tx = util.create_and_sign_tx(keypair[0], keypair[1], keypair[1], None, 'CREATE')
|
||||
|
||||
res = client.post(TX_ENDPOINT, data=json.dumps(tx))
|
||||
assert res.json['transaction']['current_owner'] == b.me
|
||||
assert res.json['transaction']['new_owner'] == keypair[1]
|
||||
assert res.json['transaction']['fulfillments'][0]['current_owners'][0] == b.me
|
||||
assert res.json['transaction']['conditions'][0]['new_owners'][0] == keypair[1]
|
||||
|
||||
|
||||
def test_post_transfer_transaction_endpoint(b, client):
|
||||
from_keypair = crypto.generate_key_pair()
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_post_transfer_transaction_endpoint(b, client, user_vk, user_sk):
|
||||
to_keypair = crypto.generate_key_pair()
|
||||
input_valid = b.get_owned_ids(user_vk).pop()
|
||||
|
||||
tx = util.create_and_sign_tx(from_keypair[0], from_keypair[1], from_keypair[1], None, 'CREATE')
|
||||
res = client.post(TX_ENDPOINT, data=json.dumps(tx))
|
||||
tx_id = res.json['id']
|
||||
|
||||
transfer = util.create_and_sign_tx(from_keypair[0], from_keypair[1], to_keypair[1], tx_id)
|
||||
transfer = util.create_and_sign_tx(user_sk, user_vk, to_keypair[1], input_valid)
|
||||
res = client.post(TX_ENDPOINT, data=json.dumps(transfer))
|
||||
|
||||
assert res.json['transaction']['current_owner'] == from_keypair[1]
|
||||
assert res.json['transaction']['new_owner'] == to_keypair[1]
|
||||
assert res.json['transaction']['fulfillments'][0]['current_owners'][0] == user_vk
|
||||
assert res.json['transaction']['conditions'][0]['new_owners'][0] == to_keypair[1]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user