fixed get_spent naming issue

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
Lorenz Herzberger 2023-04-11 13:47:09 +02:00
parent f142b79832
commit f46e9879ea
No known key found for this signature in database
GPG Key ID: FA5EE906EB55316A
8 changed files with 24 additions and 24 deletions

View File

@ -77,7 +77,7 @@ def get_assets(conn, asset_ids):
@register_query(LocalMongoDBConnection)
def get_spent(conn, transaction_id, output):
def get_spending_transaction(conn, transaction_id, output):
query = {
"inputs": {
"$elemMatch": {"$and": [{"fulfills.transaction_id": transaction_id}, {"fulfills.output_index": output}]}

View File

@ -133,7 +133,7 @@ def get_asset(connection, asset_id) -> Asset:
@singledispatch
def get_spent(connection, transaction_id, condition_id):
def get_spending_transaction(connection, transaction_id, condition_id):
"""Check if a `txid` was already used as an input.
A transaction can be used as an input for another transaction. Bigchain

View File

@ -221,7 +221,7 @@ def get_assets(connection, assets_ids: list) -> list[Asset]:
@register_query(TarantoolDBConnection)
@catch_db_exception
def get_spent(connection, fullfil_transaction_id: str, fullfil_output_index: str) -> list[DbTransaction]:
def get_spending_transaction(connection, fullfil_transaction_id: str, fullfil_output_index: str) -> list[DbTransaction]:
_inputs = (
connection.connect()
.select(
@ -301,7 +301,7 @@ def get_spending_transactions(connection, inputs):
_transactions = []
for inp in inputs:
_trans_list = get_spent(
_trans_list = get_spending_transaction(
fullfil_transaction_id=inp["transaction_id"],
fullfil_output_index=inp["output_index"],
connection=connection,

View File

@ -151,8 +151,8 @@ class DataAccessor:
return validators
def get_spent(self, txid, output, current_transactions=[]) -> DbTransaction:
transactions = backend.query.get_spent(self.connection, txid, output)
def get_spending_transaction(self, txid, output, current_transactions=[]) -> DbTransaction:
transactions = backend.query.get_spending_transaction(self.connection, txid, output)
current_spent_transactions = []
for ctxn in current_transactions:
@ -209,7 +209,7 @@ class DataAccessor:
if input_tx is None:
raise InputDoesNotExist("input `{}` doesn't exist".format(input_txid))
spent = self.get_spent(input_txid, input_.fulfills.output, current_transactions)
spent = self.get_spending_transaction(input_txid, input_.fulfills.output, current_transactions)
if spent:
raise DoubleSpend("input `{}` was already spent".format(input_txid))

View File

@ -29,7 +29,7 @@ def test_schema(schema_func_name, args_qty):
("get_txids_filtered", 1),
("get_owned_ids", 1),
("get_block", 1),
("get_spent", 2),
("get_spending_transaction", 2),
("get_spending_transactions", 1),
("store_assets", 1),
("get_asset", 1),

View File

@ -287,7 +287,7 @@ class TestMultipleInputs(object):
owned_inputs_user1 = b.models.get_outputs_filtered(user_pk)
owned_inputs_user2 = b.models.get_outputs_filtered(user2_pk)
spent_user1 = b.models.get_spent(tx.id, 0)
spent_user1 = b.models.get_spending_transaction(tx.id, 0)
assert owned_inputs_user1 == owned_inputs_user2
assert not spent_user1
@ -303,7 +303,7 @@ class TestMultipleInputs(object):
# check spents
input_txid = owned_inputs_user1.transaction_id
spent_inputs_user1 = b.models.get_spent(input_txid, 0)
spent_inputs_user1 = b.models.get_spending_transaction(input_txid, 0)
assert spent_inputs_user1 is None
# create a transaction and send it
@ -311,7 +311,7 @@ class TestMultipleInputs(object):
tx = tx.sign([user_sk])
b.models.store_bulk_transactions([tx])
spent_inputs_user1 = b.models.get_spent(input_txid, 0)
spent_inputs_user1 = b.models.get_spending_transaction(input_txid, 0)
assert spent_inputs_user1 == tx.to_dict()
def test_get_spent_single_tx_multiple_outputs(self, b, user_sk, user_pk, alice):
@ -327,7 +327,7 @@ class TestMultipleInputs(object):
# check spents
for input_tx in owned_inputs_user1:
assert b.models.get_spent(input_tx.transaction_id, input_tx.index) is None
assert b.models.get_spending_transaction(input_tx.transaction_id, input_tx.index) is None
# transfer the first 2 inputs
tx_transfer = Transfer.generate(
@ -338,12 +338,12 @@ class TestMultipleInputs(object):
# check that used inputs are marked as spent
for ffill in tx_create.to_inputs()[:2]:
spent_tx = b.models.get_spent(ffill.fulfills.txid, ffill.fulfills.output)
spent_tx = b.models.get_spending_transaction(ffill.fulfills.txid, ffill.fulfills.output)
assert spent_tx == tx_transfer_signed.to_dict()
# check if remaining transaction that was unspent is also perceived
# spendable by Planetmint
assert b.models.get_spent(tx_create.to_inputs()[2].fulfills.txid, 2) is None
assert b.models.get_spending_transaction(tx_create.to_inputs()[2].fulfills.txid, 2) is None
def test_get_spent_multiple_owners(self, b, user_sk, user_pk, alice):
user2_sk, user2_pk = crypto.generate_key_pair()
@ -361,7 +361,7 @@ class TestMultipleInputs(object):
owned_inputs_user1 = b.models.get_outputs_filtered(user_pk)
# check spents
for input_tx in owned_inputs_user1:
assert b.models.get_spent(input_tx.transaction_id, input_tx.index) is None
assert b.models.get_spending_transaction(input_tx.transaction_id, input_tx.index) is None
# create a transaction
tx = Transfer.generate(transactions[0].to_inputs(), [([user3_pk], 1)], asset_ids=[transactions[0].id])
@ -369,10 +369,10 @@ class TestMultipleInputs(object):
b.models.store_bulk_transactions([tx])
# check that used inputs are marked as spent
assert b.models.get_spent(transactions[0].id, 0) == tx.to_dict()
assert b.models.get_spending_transaction(transactions[0].id, 0) == tx.to_dict()
# check that the other remain marked as unspent
for unspent in transactions[1:]:
assert b.models.get_spent(unspent.id, 0) is None
assert b.models.get_spending_transaction(unspent.id, 0) is None
def test_get_outputs_filtered_only_unspent(b, alice):

View File

@ -256,7 +256,7 @@ def test_get_utxoset_merkle_root(b, user_sk, user_pk):
@pytest.mark.bdb
def test_get_spent_transaction_double_spend(b, alice, bob, carol):
def test_get_spending_transaction_double_spend(b, alice, bob, carol):
from transactions.common.exceptions import DoubleSpend
assets = [{"data": multihash(marshal({"test": "asset"}))}]
@ -280,15 +280,15 @@ def test_get_spent_transaction_double_spend(b, alice, bob, carol):
with pytest.raises(DoubleSpend):
b.validate_transaction(same_input_double_spend)
assert b.models.get_spent(tx.id, tx_transfer.inputs[0].fulfills.output, [tx_transfer])
assert b.models.get_spending_transaction(tx.id, tx_transfer.inputs[0].fulfills.output, [tx_transfer])
with pytest.raises(DoubleSpend):
b.models.get_spent(tx.id, tx_transfer.inputs[0].fulfills.output, [tx_transfer, double_spend])
b.models.get_spending_transaction(tx.id, tx_transfer.inputs[0].fulfills.output, [tx_transfer, double_spend])
b.models.store_bulk_transactions([tx_transfer])
with pytest.raises(DoubleSpend):
b.models.get_spent(tx.id, tx_transfer.inputs[0].fulfills.output, [double_spend])
b.models.get_spending_transaction(tx.id, tx_transfer.inputs[0].fulfills.output, [double_spend])
def test_validation_with_transaction_buffer(b):

View File

@ -48,7 +48,7 @@ def test_bigchain_class_default_initialization(config):
@pytest.mark.bdb
def test_get_spent_issue_1271(b, alice, bob, carol):
def test_get_spending_transaction_issue_1271(b, alice, bob, carol):
tx_1 = Create.generate(
[carol.public_key],
[([carol.public_key], 8)],
@ -88,7 +88,7 @@ def test_get_spent_issue_1271(b, alice, bob, carol):
assert b.validate_transaction(tx_5)
b.models.store_bulk_transactions([tx_5])
assert b.models.get_spent(tx_2.id, 0) == tx_5.to_dict()
assert not b.models.get_spent(tx_5.id, 0)
assert b.models.get_spending_transaction(tx_2.id, 0) == tx_5.to_dict()
assert not b.models.get_spending_transaction(tx_5.id, 0)
assert b.models.get_outputs_filtered(alice.public_key)
assert b.models.get_outputs_filtered(alice.public_key, spent=False)