def test_order_transactions_fails_with_cyclic_tx( bdb_driver, alice_keypair, bob_keypair, carly_keypair): from coalaip_bigchaindb.utils import make_transfer_tx, order_transactions create_tx = bdb_driver.transactions.prepare( operation='CREATE', signers=alice_keypair['public_key']) transfer_to_bob_tx = make_transfer_tx(bdb_driver, input_tx=create_tx, recipients=bob_keypair['public_key']) transfer_to_carly_tx = make_transfer_tx( bdb_driver, input_tx=transfer_to_bob_tx, recipients=carly_keypair['public_key']) transfer_to_alice_tx = make_transfer_tx( bdb_driver, input_tx=transfer_to_carly_tx, recipients=alice_keypair['public_key']) # Modify transfer to bob tx so that it links back to the transfer to alice. # This should create a # bob_transfer <- carly_transfer <- alice_transfer <- bob_transfer # dependency cycle. transfer_to_bob_tx['inputs'][0]['fulfills']['transaction_id'] = transfer_to_alice_tx['id'] with raises(ValueError): order_transactions([ transfer_to_bob_tx, transfer_to_carly_tx, transfer_to_alice_tx, ])
def test_order_transactions_fails_with_multiple_endings( bdb_driver, alice_keypair, bob_keypair, carly_keypair): from coalaip_bigchaindb.utils import make_transfer_tx, order_transactions create_tx = bdb_driver.transactions.prepare( operation='CREATE', signers=alice_keypair['public_key']) transfer_to_bob_tx = make_transfer_tx(bdb_driver, input_tx=create_tx, recipients=bob_keypair['public_key']) transfer_to_carly_tx = make_transfer_tx( bdb_driver, input_tx=create_tx, recipients=carly_keypair['public_key']) with raises(ValueError): # Transfer to both bob and carly should result in a multiple endings # error order_transactions([create_tx, transfer_to_bob_tx, transfer_to_carly_tx])
def test_order_transactions_fails_with_missing_tx(bdb_driver, alice_keypair, bob_keypair, carly_keypair): from coalaip_bigchaindb.utils import make_transfer_tx, order_transactions create_tx = bdb_driver.transactions.prepare( operation='CREATE', signers=alice_keypair['public_key']) transfer_to_bob_tx = make_transfer_tx(bdb_driver, input_tx=create_tx, recipients=bob_keypair['public_key']) transfer_to_carly_tx = make_transfer_tx( bdb_driver, input_tx=transfer_to_bob_tx, recipients=carly_keypair['public_key']) transfer_to_alice_tx = make_transfer_tx( bdb_driver, input_tx=transfer_to_carly_tx, recipients=alice_keypair['public_key']) with raises(ValueError): # Missing transfer to carly (that the transfer to alice is based on) # should result in an error with an unfound tx order_transactions([ create_tx, transfer_to_bob_tx, transfer_to_alice_tx, ])
def test_order_transactions_fails_with_multiple_starts( bdb_driver, alice_keypair, bob_keypair, carly_keypair): from coalaip_bigchaindb.utils import make_transfer_tx, order_transactions create_tx_alice = bdb_driver.transactions.prepare( operation='CREATE', signers=alice_keypair['public_key']) create_tx_bob = bdb_driver.transactions.prepare( operation='CREATE', signers=bob_keypair['public_key']) transfer_to_carly_tx = make_transfer_tx( bdb_driver, input_tx=create_tx_alice, recipients=carly_keypair['public_key']) with raises(ValueError): # Multiple CREATEs should result in an error with multiple tx not # fulfilling a prior tx order_transactions([ create_tx_alice, create_tx_bob, transfer_to_carly_tx, ])
def test_order_transactions(bdb_driver, alice_keypair, bob_keypair): import random from coalaip_bigchaindb.utils import make_transfer_tx, order_transactions create_tx = bdb_driver.transactions.prepare( operation='CREATE', signers=alice_keypair['public_key']) transfer_to_bob_tx = make_transfer_tx(bdb_driver, input_tx=create_tx, recipients=bob_keypair['public_key']) transfer_back_to_alice_tx = make_transfer_tx( bdb_driver, input_tx=transfer_to_bob_tx, recipients=alice_keypair['public_key']) correct_order = [create_tx, transfer_to_bob_tx, transfer_back_to_alice_tx] for _ in range(0, 100): assert correct_order == order_transactions( random.sample(correct_order, len(correct_order)))
def test_order_empty_transations(): from coalaip_bigchaindb.utils import order_transactions ordered_tx = order_transactions([]) assert ordered_tx == []