diff --git a/bigchaindb/core.py b/bigchaindb/core.py index 14892e95..dfc363b0 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -189,6 +189,8 @@ class Bigchain(object): # if assignee field in the transaction, remove it if 'assignee' in data: data.pop('assignee') + if 'signatures' not in data: + return False signatures = data.pop('signatures') for public_key_base58 in signed_transaction['transaction']['current_owners']: diff --git a/tests/db/test_bigchain_api.py b/tests/db/test_bigchain_api.py index aadf9147..1af1d874 100644 --- a/tests/db/test_bigchain_api.py +++ b/tests/db/test_bigchain_api.py @@ -59,6 +59,18 @@ class TestBigchainApi(object): with pytest.raises(TypeError): b.create_transaction('a', 'b', 'c', 'd', payload=[]) + def test_create_transaction_with_multiple_owners(self, b): + num_current_owners = 42 + num_new_owners = 73 + tx = b.create_transaction(['a']*num_current_owners, ['b']*num_new_owners, 'd', 'e') + + assert sorted(tx) == sorted(['id', 'transaction']) + assert sorted(tx['transaction']) == sorted(['current_owners', 'new_owners', 'input', 'operation', + 'timestamp', 'data']) + + assert len(tx['transaction']['current_owners']) == num_current_owners + assert len(tx['transaction']['new_owners']) == num_new_owners + def test_transaction_hash(self, b): payload = {'cats': 'are awesome'} tx = b.create_transaction('a', 'b', 'c', 'd', payload) @@ -79,11 +91,32 @@ class TestBigchainApi(object): def test_transaction_signature(self, b): sk, vk = b.generate_keys() tx = b.create_transaction(vk, 'b', 'c', 'd') + + assert b.verify_signature(tx) is False tx_signed = b.sign_transaction(tx, sk) assert 'signatures' in tx_signed assert b.verify_signature(tx_signed) + def test_transaction_signature_multiple_owners(self, b): + num_current_owners = 42 + sk, vk = [], [] + for _ in range(num_current_owners): + sk_, vk_ = b.generate_keys() + sk.append(sk_) + vk.append(vk_) + tx = b.create_transaction(vk, 'b', 'c', 'd') + tx_signed = tx + for i in range(num_current_owners): + assert b.verify_signature(tx_signed) is False + tx_signed = b.sign_transaction(tx_signed, sk[i], vk[i]) + + assert 'signatures' in tx_signed + assert 'public_key' in tx_signed['signatures'][0] + assert 'signature' in tx_signed['signatures'][0] + assert len(tx_signed['signatures']) == num_current_owners + assert b.verify_signature(tx_signed) + def test_serializer(self, b): tx = b.create_transaction('a', 'b', 'c', 'd') assert b.deserialize(b.serialize(tx)) == tx