lbry-sdk/tests/unit/blockchain/test_claim_proofs.py

44 lines
1.6 KiB
Python
Raw Normal View History

2018-07-10 06:30:43 +02:00
import unittest
2018-10-15 23:16:43 +02:00
from binascii import hexlify, unhexlify
2018-07-10 06:30:43 +02:00
2020-05-01 15:28:51 +02:00
from lbry.blockchain.claim_proofs import get_hash_for_outpoint, verify_proof
2019-12-31 21:30:13 +01:00
from lbry.crypto.hash import double_sha256
2018-07-10 06:30:43 +02:00
class ClaimProofsTestCase(unittest.TestCase):
def test_verify_proof(self):
claim1_name = 97 # 'a'
claim1_txid = 'bd9fa7ffd57d810d4ce14de76beea29d847b8ac34e8e536802534ecb1ca43b68'
claim1_outpoint = 0
claim1_height = 10
claim1_node_hash = get_hash_for_outpoint(
unhexlify(claim1_txid)[::-1], claim1_outpoint, claim1_height)
2018-07-10 06:30:43 +02:00
claim2_name = 98 # 'b'
claim2_txid = 'ad9fa7ffd57d810d4ce14de76beea29d847b8ac34e8e536802534ecb1ca43b68'
claim2_outpoint = 1
claim2_height = 5
claim2_node_hash = get_hash_for_outpoint(
unhexlify(claim2_txid)[::-1], claim2_outpoint, claim2_height)
2018-07-10 06:30:43 +02:00
to_hash1 = claim1_node_hash
hash1 = double_sha256(to_hash1)
to_hash2 = bytes((claim1_name,)) + hash1 + bytes((claim2_name,)) + claim2_node_hash
2018-07-10 06:30:43 +02:00
root_hash = double_sha256(to_hash2)
proof = {
'last takeover height': claim1_height, 'txhash': claim1_txid, 'nOut': claim1_outpoint,
'nodes': [
{'children': [
{'character': 97},
{
'character': 98,
'nodeHash': hexlify(claim2_node_hash[::-1])
2018-07-10 06:30:43 +02:00
}
]},
{'children': []},
]
}
out = verify_proof(proof, hexlify(root_hash[::-1]), 'a')
self.assertTrue(out)