mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-31 17:31:36 +00:00
Merge pull request #5537 from xaya/test-verify-header
Unit tests for Blockchain.verify_header
This commit is contained in:
commit
cf02e32f20
1 changed files with 34 additions and 0 deletions
|
@ -339,3 +339,37 @@ class TestBlockchain(SequentialTestCase):
|
|||
|
||||
for b in (chain_u, chain_l, chain_z):
|
||||
self.assertTrue(all([b.can_connect(b.read_header(i), False) for i in range(b.height())]))
|
||||
|
||||
|
||||
class TestVerifyHeader(SequentialTestCase):
|
||||
|
||||
# Data for Bitcoin block header #100.
|
||||
valid_header = "0100000095194b8567fe2e8bbda931afd01a7acd399b9325cb54683e64129bcd00000000660802c98f18fd34fd16d61c63cf447568370124ac5f3be626c2e1c3c9f0052d19a76949ffff001d33f3c25d"
|
||||
target = Blockchain.bits_to_target(0x1d00ffff)
|
||||
prev_hash = "00000000cd9b12643e6854cb25939b39cd7a1ad0af31a9bd8b2efe67854b1995"
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.header = deserialize_header(bfh(self.valid_header), 100)
|
||||
|
||||
def test_valid_header(self):
|
||||
Blockchain.verify_header(self.header, self.prev_hash, self.target)
|
||||
|
||||
def test_expected_hash_mismatch(self):
|
||||
with self.assertRaises(Exception):
|
||||
Blockchain.verify_header(self.header, self.prev_hash, self.target,
|
||||
expected_header_hash="foo")
|
||||
|
||||
def test_prev_hash_mismatch(self):
|
||||
with self.assertRaises(Exception):
|
||||
Blockchain.verify_header(self.header, "foo", self.target)
|
||||
|
||||
def test_target_mismatch(self):
|
||||
with self.assertRaises(Exception):
|
||||
other_target = Blockchain.bits_to_target(0x1d00eeee)
|
||||
Blockchain.verify_header(self.header, self.prev_hash, other_target)
|
||||
|
||||
def test_insufficient_pow(self):
|
||||
with self.assertRaises(Exception):
|
||||
self.header["nonce"] = 42
|
||||
Blockchain.verify_header(self.header, self.prev_hash, self.target)
|
||||
|
|
Loading…
Add table
Reference in a new issue