diff --git a/bigchaindb/util.py b/bigchaindb/util.py index dd38cfc2..a224414d 100644 --- a/bigchaindb/util.py +++ b/bigchaindb/util.py @@ -149,6 +149,14 @@ def create_tx(current_owners, new_owners, inputs, operation, payload=None): new_owners = new_owners if isinstance(new_owners, list) else [new_owners] inputs = inputs if isinstance(inputs, list) else [inputs] + # validate arguments (owners and inputs should be lists) + if not isinstance(current_owners, list): + current_owners = [current_owners] + if not isinstance(new_owners, list): + new_owners = [new_owners] + if not isinstance(inputs, list): + inputs = [inputs] + # handle payload data = None if payload is not None: @@ -354,6 +362,6 @@ def transform_create(tx): payload = None if transaction['data'] and 'payload' in transaction['data']: payload = transaction['data']['payload'] - new_tx = create_tx(b.me, transaction['current_owner'], None, 'CREATE', payload=payload) + new_tx = create_tx(b.me, transaction['fulfillments'][0]['current_owners'], None, 'CREATE', payload=payload) return new_tx diff --git a/tests/db/test_bigchain_api.py b/tests/db/test_bigchain_api.py index c56a535a..c8f3a0f2 100644 --- a/tests/db/test_bigchain_api.py +++ b/tests/db/test_bigchain_api.py @@ -65,6 +65,8 @@ class TestBigchainApi(object): assert tx['transaction']['data'] == tx_calculated['data'] # assert tx_hash == tx_calculated_hash + # TODO: Make sure that this is covered when merged with dimi's code + @pytest.mark.skipif(reason='We no longer check signatures, only fulfillments of conditions') def test_transaction_signature(self, b): sk, vk = crypto.generate_key_pair() tx = b.create_transaction(vk, 'b', 'c', 'd') diff --git a/tests/test_client.py b/tests/test_client.py index f5e15cad..de1a3d6a 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -21,6 +21,14 @@ def mock_requests_post(monkeypatch): monkeypatch.setattr('requests.post', mockreturn) +@pytest.fixture +def mock_bigchaindb_sign(monkeypatch): + def mockreturn(transaction, private_key): + return transaction + + monkeypatch.setattr('bigchaindb.util.sign_tx', mockreturn) + + def test_temp_client_returns_a_temp_client(): from bigchaindb.client import temp_client @@ -39,21 +47,19 @@ def test_client_can_create_assets(mock_requests_post, client): # `current_owner` will be overwritten with the public key of the node in the federation # that will create the real transaction. `signature` will be overwritten with the new signature. # Note that this scenario is ignored by this test. - assert tx['transaction']['current_owner'] == client.public_key - assert tx['transaction']['new_owner'] == client.public_key - assert tx['transaction']['input'] == None + assert tx['transaction']['fulfillments'][0]['current_owners'][0] == client.public_key + assert tx['transaction']['conditions'][0]['new_owners'][0] == client.public_key + assert tx['transaction']['fulfillments'][0]['input'] is None assert util.verify_signature(tx) -def test_client_can_transfer_assets(mock_requests_post, client): +def test_client_can_transfer_assets(mock_requests_post, mock_bigchaindb_sign, client): from bigchaindb import util tx = client.transfer('a', 123) - assert tx['transaction']['current_owner'] == client.public_key - assert tx['transaction']['new_owner'] == 'a' - assert tx['transaction']['input'] == 123 - - assert util.verify_signature(tx) + assert tx['transaction']['fulfillments'][0]['current_owners'][0] == client.public_key + assert tx['transaction']['conditions'][0]['new_owners'][0] == 'a' + assert tx['transaction']['fulfillments'][0]['input'] == 123 diff --git a/tests/test_util.py b/tests/test_util.py index 4e09a41a..55993938 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -6,7 +6,7 @@ def test_transform_create(b, user_sk, user_vk): tx = util.transform_create(tx) tx = util.sign_tx(tx, b.me_private) - assert tx['transaction']['current_owner'] == b.me - assert tx['transaction']['new_owner'] == user_vk + assert tx['transaction']['fulfillments'][0]['current_owners'][0] == b.me + assert tx['transaction']['conditions'][0]['new_owners'][0] == user_vk assert util.verify_signature(tx)