diff --git a/bigchaindb/consensus.py b/bigchaindb/consensus.py index bc6d458f..04179b3f 100644 --- a/bigchaindb/consensus.py +++ b/bigchaindb/consensus.py @@ -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() diff --git a/tests/db/test_bigchain_api.py b/tests/db/test_bigchain_api.py index c891f12a..e787d454 100644 --- a/tests/db/test_bigchain_api.py +++ b/tests/db/test_bigchain_api.py @@ -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, {'txid': input_valid, 'cid': 0}, '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, {'txid': input_valid, 'cid': 0}, 'TRANSFER') tx_valid_signed = b.sign_transaction(tx_valid, user_sk) b.write_transaction(tx_valid_signed) @@ -294,17 +294,17 @@ 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, {'txid': input_valid, 'cid': 0}, 'TRANSFER') with pytest.raises(exceptions.DoubleSpend) as excinfo: b.validate_transaction(tx_double_spend) - assert excinfo.value.args[0] == 'input `{}` was already spent'.format(input_valid) + assert excinfo.value.args[0] == 'input `{}` was already spent'.format({'txid': input_valid, 'cid': 0}) assert b.is_valid_transaction(tx_double_spend) is False @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, {'txid': input_valid, 'cid': 0}, '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, {'txid': input_valid, 'cid': 0}, '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, {'txid': input_valid, 'cid': 0}, '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, {'txid': input_valid, 'cid': 0}, '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, {'txid': input_valid, 'cid': 0}, 'TRANSFER') tx_valid_signed = b.sign_transaction(tx_valid, user_sk) # create valid block diff --git a/tests/db/test_voter.py b/tests/db/test_voter.py index 3ebb9a8e..ce1b42e1 100644 --- a/tests/db/test_voter.py +++ b/tests/db/test_voter.py @@ -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) diff --git a/tests/web/test_basic_views.py b/tests/web/test_basic_views.py index eb840748..52bad2ee 100644 --- a/tests/web/test_basic_views.py +++ b/tests/web/test_basic_views.py @@ -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], {'txid': input_valid, 'cid': 0}) 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]