mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
added tests for multisig
fixed bug in validate_transaction if no signature
This commit is contained in:
parent
9a1a3bdc2d
commit
dca74116ab
@ -189,6 +189,8 @@ class Bigchain(object):
|
|||||||
# if assignee field in the transaction, remove it
|
# if assignee field in the transaction, remove it
|
||||||
if 'assignee' in data:
|
if 'assignee' in data:
|
||||||
data.pop('assignee')
|
data.pop('assignee')
|
||||||
|
if 'signatures' not in data:
|
||||||
|
return False
|
||||||
|
|
||||||
signatures = data.pop('signatures')
|
signatures = data.pop('signatures')
|
||||||
for public_key_base58 in signed_transaction['transaction']['current_owners']:
|
for public_key_base58 in signed_transaction['transaction']['current_owners']:
|
||||||
|
|||||||
@ -59,6 +59,18 @@ class TestBigchainApi(object):
|
|||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
b.create_transaction('a', 'b', 'c', 'd', payload=[])
|
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):
|
def test_transaction_hash(self, b):
|
||||||
payload = {'cats': 'are awesome'}
|
payload = {'cats': 'are awesome'}
|
||||||
tx = b.create_transaction('a', 'b', 'c', 'd', payload)
|
tx = b.create_transaction('a', 'b', 'c', 'd', payload)
|
||||||
@ -79,11 +91,32 @@ class TestBigchainApi(object):
|
|||||||
def test_transaction_signature(self, b):
|
def test_transaction_signature(self, b):
|
||||||
sk, vk = b.generate_keys()
|
sk, vk = b.generate_keys()
|
||||||
tx = b.create_transaction(vk, 'b', 'c', 'd')
|
tx = b.create_transaction(vk, 'b', 'c', 'd')
|
||||||
|
|
||||||
|
assert b.verify_signature(tx) is False
|
||||||
tx_signed = b.sign_transaction(tx, sk)
|
tx_signed = b.sign_transaction(tx, sk)
|
||||||
|
|
||||||
assert 'signatures' in tx_signed
|
assert 'signatures' in tx_signed
|
||||||
assert b.verify_signature(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):
|
def test_serializer(self, b):
|
||||||
tx = b.create_transaction('a', 'b', 'c', 'd')
|
tx = b.create_transaction('a', 'b', 'c', 'd')
|
||||||
assert b.deserialize(b.serialize(tx)) == tx
|
assert b.deserialize(b.serialize(tx)) == tx
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user