From 5e73f82c239fededd84a3a63f058899bc21bf02b Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Fri, 12 Nov 2021 13:48:56 -0500 Subject: [PATCH] fix effective amount for resolve/ES being off while claims/supports are unactivated --- lbry/wallet/server/leveldb.py | 2 +- .../takeovers/test_resolve_command.py | 27 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lbry/wallet/server/leveldb.py b/lbry/wallet/server/leveldb.py index 426778d07..da9d1d4a9 100644 --- a/lbry/wallet/server/leveldb.py +++ b/lbry/wallet/server/leveldb.py @@ -213,7 +213,7 @@ class LevelDB: support_amount = self.get_support_amount(claim_hash) claim_amount = self.get_cached_claim_txo(claim_hash).amount - effective_amount = support_amount + claim_amount + effective_amount = self.get_effective_amount(claim_hash) channel_hash = self.get_channel_for_claim(claim_hash, tx_num, position) reposted_claim_hash = self.get_repost(claim_hash) short_url = self.get_short_claim_id_url(name, normalized_name, claim_hash, root_tx_num, root_position) diff --git a/tests/integration/takeovers/test_resolve_command.py b/tests/integration/takeovers/test_resolve_command.py index 57112cf92..32cab56a8 100644 --- a/tests/integration/takeovers/test_resolve_command.py +++ b/tests/integration/takeovers/test_resolve_command.py @@ -68,7 +68,14 @@ class BaseResolveTestCase(CommandTestCase): self.assertEqual(expected['txId'], claim.tx_hash[::-1].hex()) self.assertEqual(expected['n'], claim.position) self.assertEqual(expected['amount'], claim.amount) - self.assertEqual(expected['effectiveAmount'], claim.effective_amount) + self.assertEqual(expected['effectiveAmount'], claim.effective_amount, claim.claim_hash.hex()) + self.assertEqual(claim_from_es[0][0]['activation_height'], claim.activation_height) + self.assertEqual(claim_from_es[0][0]['last_take_over_height'], claim.last_takeover_height) + self.assertEqual(claim_from_es[0][0]['tx_id'], claim.tx_hash[::-1].hex()) + self.assertEqual(claim_from_es[0][0]['tx_nout'], claim.position) + self.assertEqual(claim_from_es[0][0]['amount'], claim.amount) + self.assertEqual(claim_from_es[0][0]['effective_amount'], claim.effective_amount) + return claim async def assertMatchClaim(self, claim_id, is_active_in_lbrycrd=True): @@ -126,10 +133,20 @@ class BaseResolveTestCase(CommandTestCase): for c in expected['claims']: check_supports(c['claimId'], c['supports']) claim_hash = bytes.fromhex(c['claimId']) + effective_amount = db.get_effective_amount(claim_hash) + claim = db._fs_get_claim_by_hash(claim_hash) + self.assertEqual(c['validAtHeight'], db.get_activation( db.prefix_db.tx_num.get(bytes.fromhex(c['txId'])[::-1]).tx_num, c['n'] )) - self.assertEqual(c['effectiveAmount'], db.get_effective_amount(claim_hash)) + self.assertEqual(c['effectiveAmount'], effective_amount) + self.assertEqual(effective_amount, claim.effective_amount) + claim_from_es = await self.conductor.spv_node.server.bp.db.search_index.search( + claim_id=c['claimId'] + ) + self.assertEqual(len(claim_from_es[0]), 1) + self.assertEqual(claim_from_es[0][0]['claim_hash'][::-1].hex(), c['claimId']) + self.assertEqual(claim_from_es[0][0]['effective_amount'], effective_amount) class ResolveCommand(BaseResolveTestCase): @@ -1176,10 +1193,12 @@ class ResolveClaimTakeovers(BaseResolveTestCase): self.assertNotEqual(first_claim_id, second_claim_id) # takeover should not have happened yet await self.assertMatchClaimIsWinning(name, first_claim_id) - await self.generate(8) - await self.assertMatchClaimIsWinning(name, first_claim_id) + for _ in range(8): + await self.generate(1) + await self.assertMatchClaimIsWinning(name, first_claim_id) # prevent the takeover by adding a support one block before the takeover happens await self.support_create(first_claim_id, bid='1.0') + await self.assertMatchClaimIsWinning(name, first_claim_id) # one more block until activation await self.generate(1) await self.assertMatchClaimIsWinning(name, first_claim_id)