From 4783e6da1fe2cedc98a1c857fb10792ab5e05866 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Fri, 18 Sep 2020 02:43:28 -0300 Subject: [PATCH] fix effective_amount --- lbry/db/queries/search.py | 10 ++++++++++ tests/integration/blockchain/test_blockchain.py | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/lbry/db/queries/search.py b/lbry/db/queries/search.py index cfa77c09d..2d0ef2604 100644 --- a/lbry/db/queries/search.py +++ b/lbry/db/queries/search.py @@ -32,6 +32,15 @@ BASE_SELECT_SUPPORT_COLUMNS = BASE_SELECT_TXO_COLUMNS + [ ] +def compat_layer(**constraints): + # for old sdk, to be removed later + replacements = {"effective_amount": "staked_amount"} + for old_key, new_key in replacements.items(): + if old_key in constraints: + constraints[new_key] = constraints.pop(old_key) + return constraints + + def select_supports(cols: List = None, **constraints) -> Select: if cols is None: cols = BASE_SELECT_SUPPORT_COLUMNS @@ -82,6 +91,7 @@ BASE_SELECT_CLAIM_COLUMNS = BASE_SELECT_TXO_COLUMNS + [ def select_claims(cols: List = None, for_count=False, **constraints) -> Select: + constraints = compat_layer(**constraints) if cols is None: cols = BASE_SELECT_CLAIM_COLUMNS if 'order_by' in constraints: diff --git a/tests/integration/blockchain/test_blockchain.py b/tests/integration/blockchain/test_blockchain.py index f991cc1a5..c08900607 100644 --- a/tests/integration/blockchain/test_blockchain.py +++ b/tests/integration/blockchain/test_blockchain.py @@ -919,6 +919,17 @@ class TestGeneralBlockchainSync(SyncingBlockchainTestCase): resolutions = Outputs.from_base64(await self.db.protobuf_resolve(["@notfound#ab/notfound"])) self.assertEqual(resolutions.txos[0].error.text, "Could not find channel in \"@notfound#ab/notfound\".") + async def test_claim_search_effective_amount(self): + claim = await self.get_claim(await self.create_claim(claim_id_startswith='ab', is_channel=True, amount='0.42')) + await self.generate(1) + results = await self.db.search_claims(staked_amount=42000000) + self.assertEqual(claim.claim_id, results[0].claim_id) + # compat layer + results = await self.db.search_claims(effective_amount=42000000) + self.assertEqual(claim.claim_id, results[0].claim_id) + + + class TestClaimtrieSync(SyncingBlockchainTestCase):