fix depth on resolve, add tests

This commit is contained in:
Victor Shyba 2019-04-04 19:17:11 -03:00 committed by Lex Berezhny
parent a0a810edc3
commit fd56dc68cd
3 changed files with 10 additions and 10 deletions

View file

@ -67,12 +67,9 @@ class Resolver:
certificate_resolution_type = resolution['certificate']['resolution_type'] certificate_resolution_type = resolution['certificate']['resolution_type']
if certificate_resolution_type == "winning" and certificate_response: if certificate_resolution_type == "winning" and certificate_response:
if 'height' in certificate_response: if 'height' in certificate_response:
height = certificate_response['height']
depth = self.height - height
certificate_response = _verify_proof(parsed_uri.name, certificate_response = _verify_proof(parsed_uri.name,
claim_trie_root, claim_trie_root,
certificate_response, certificate_response,
height, depth,
ledger=self.ledger) ledger=self.ledger)
elif certificate_resolution_type not in ['winning', 'claim_id', 'sequence']: elif certificate_resolution_type not in ['winning', 'claim_id', 'sequence']:
raise Exception(f"unknown response type: {certificate_resolution_type}") raise Exception(f"unknown response type: {certificate_resolution_type}")
@ -85,12 +82,9 @@ class Resolver:
claim_resolution_type = resolution['claim']['resolution_type'] claim_resolution_type = resolution['claim']['resolution_type']
if claim_resolution_type == "winning" and claim_response: if claim_resolution_type == "winning" and claim_response:
if 'height' in claim_response: if 'height' in claim_response:
height = claim_response['height']
depth = self.height - height
claim_response = _verify_proof(parsed_uri.name, claim_response = _verify_proof(parsed_uri.name,
claim_trie_root, claim_trie_root,
claim_response, claim_response,
height, depth,
ledger=self.ledger) ledger=self.ledger)
elif claim_resolution_type not in ["sequence", "winning", "claim_id"]: elif claim_resolution_type not in ["sequence", "winning", "claim_id"]:
raise Exception(f"unknown response type: {claim_resolution_type}") raise Exception(f"unknown response type: {claim_resolution_type}")
@ -260,7 +254,7 @@ class Resolver:
return page_generator, upper_bound return page_generator, upper_bound
def _verify_proof(name, claim_trie_root, result, height, depth, ledger): def _verify_proof(name, claim_trie_root, result, ledger):
""" """
Verify proof for name claim Verify proof for name claim
""" """
@ -276,8 +270,8 @@ def _verify_proof(name, claim_trie_root, result, height, depth, ledger):
'nout': nOut, 'nout': nOut,
'amount': output.amount, 'amount': output.amount,
'effective_amount': output.amount + support_amount, 'effective_amount': output.amount + support_amount,
'height': height, 'height': result['height'],
'depth': depth, 'depth': result['depth'],
'claim_sequence': result['claim_sequence'], 'claim_sequence': result['claim_sequence'],
'address': output.get_address(ledger), 'address': output.get_address(ledger),
'valid_at_height': result['valid_at_height'], 'valid_at_height': result['valid_at_height'],

View file

@ -241,7 +241,7 @@ class LBRYElectrumX(ElectrumX):
"txid": claim['txid'], "txid": claim['txid'],
"nout": claim['n'], "nout": claim['n'],
"amount": amount, "amount": amount,
"depth": self.db.db_height - height, "depth": self.db.db_height - height + 1,
"height": height, "height": height,
"value": hexlify(claim['value'].encode('ISO-8859-1')).decode(), "value": hexlify(claim['value'].encode('ISO-8859-1')).decode(),
"address": address, # from index "address": address, # from index

View file

@ -1,3 +1,5 @@
import json
from integration.testcase import CommandTestCase from integration.testcase import CommandTestCase
@ -63,6 +65,10 @@ class ResolveCommand(CommandTestCase):
self.assertEqual(claim['certificate']['name'], '@abc') self.assertEqual(claim['certificate']['name'], '@abc')
self.assertEqual(claim['claims_in_channel'], 0) self.assertEqual(claim['claims_in_channel'], 0)
# resolve has correct depth
tx_details = await self.blockchain.get_raw_transaction(claim['claim']['txid'])
self.assertEqual(claim['claim']['depth'], json.loads(tx_details)['confirmations'])
# resolve handles invalid data # resolve handles invalid data
txid = await self.blockchain_claim_name("gibberish", "cafecafe", "0.1") txid = await self.blockchain_claim_name("gibberish", "cafecafe", "0.1")
await self.generate(1) await self.generate(1)