mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Merge pull request #1863 from bigchaindb/write-transfer-test
Write transfer test
This commit is contained in:
commit
359efbba15
@ -55,7 +55,7 @@ def get_spent(conn, transaction_id, output):
|
||||
try:
|
||||
return conn.run(
|
||||
conn.collection('transactions')
|
||||
.find_one({'id': transaction_id,
|
||||
.find_one({'inputs.fulfills.transaction_id': transaction_id,
|
||||
'inputs.fulfills.output_index': output},
|
||||
{'_id': 0}))
|
||||
except IndexError:
|
||||
|
@ -69,7 +69,19 @@ class BigchainDB(Bigchain):
|
||||
def get_spent(self, txid, output):
|
||||
transaction = backend.query.get_spent(self.connection, txid,
|
||||
output)
|
||||
return Transaction.from_dict(transaction)
|
||||
if transaction and transaction['operation'] == 'CREATE':
|
||||
asset = backend.query.get_asset(self.connection, transaction['id'])
|
||||
|
||||
if asset:
|
||||
transaction['asset'] = asset
|
||||
else:
|
||||
transaction['asset'] = {'data': None}
|
||||
|
||||
return Transaction.from_dict(transaction)
|
||||
elif transaction and transaction['operation'] == 'TRANSFER':
|
||||
return Transaction.from_dict(transaction)
|
||||
else:
|
||||
return None
|
||||
|
||||
def store_block(self, block):
|
||||
"""Create a new block."""
|
||||
|
@ -74,3 +74,42 @@ def test_deliver_tx__double_spend_fails(b):
|
||||
assert b.get_transaction(tx.id).id == tx.id
|
||||
result = app.deliver_tx(encode_tx_to_bytes(tx))
|
||||
assert result.is_error()
|
||||
|
||||
|
||||
def test_deliver_transfer_tx__double_spend_fails(b):
|
||||
from bigchaindb.tendermint import App
|
||||
from bigchaindb.models import Transaction
|
||||
from bigchaindb.common.crypto import generate_key_pair
|
||||
|
||||
app = App(b)
|
||||
alice = generate_key_pair()
|
||||
bob = generate_key_pair()
|
||||
carly = generate_key_pair()
|
||||
|
||||
asset = {
|
||||
"msg": "live long and prosper"
|
||||
}
|
||||
|
||||
tx = Transaction.create([alice.public_key],
|
||||
[([alice.public_key], 1)],
|
||||
asset=asset)\
|
||||
.sign([alice.private_key])
|
||||
|
||||
result = app.deliver_tx(encode_tx_to_bytes(tx))
|
||||
assert result.is_ok()
|
||||
|
||||
tx_transfer = Transaction.transfer(tx.to_inputs(),
|
||||
[([bob.public_key], 1)],
|
||||
asset_id=tx.id)\
|
||||
.sign([alice.private_key])
|
||||
|
||||
result = app.deliver_tx(encode_tx_to_bytes(tx_transfer))
|
||||
assert result.is_ok()
|
||||
|
||||
double_spend = Transaction.transfer(tx.to_inputs(),
|
||||
[([carly.public_key], 1)],
|
||||
asset_id=tx.id)\
|
||||
.sign([alice.private_key])
|
||||
|
||||
result = app.deliver_tx(encode_tx_to_bytes(double_spend))
|
||||
assert result.is_error()
|
||||
|
Loading…
x
Reference in New Issue
Block a user