lbryio / lbrycrd

The blockchain that provides the digital content namespace for the LBRY protocol
https://lbry.com
MIT License
2.57k stars 178 forks source link

Unit test for recursivePruneName and for future CClaimTrieCache unit tests #105

Closed kaykurokawa closed 6 years ago

kaykurokawa commented 6 years ago

This adds a unit test for function CClaimTrieCache::recursivePruneName()

The new test file claimtriecache_tests.cpp can also contain additional unit tests for CClaimTrieCache in the future which is very lacking as of now.

I had to change use of "private" in CClaimTrieCache to "protected" in order to unit test non-public functions. Not sure if this is the best way but I think its ok. Other classes like CClaimTrie could switch to using "protected" in the future as well for better unit tests.

kaykurokawa commented 6 years ago

I added simple tests here for computing merkle hashes on the trie which could be expanded upon. In this case it tests the hash for when the trie is empty, and when it just has a single empty root node.

technovelist commented 6 years ago

Please generate at least test #10 of the tests I asked for. Here's the list again:

I need some tests for the claimtrie rewrite project, to get a baseline on the existing code's behavior.

Here is a preliminary list. In each case, the test should complete the block, persist it, and display the hash for each node in the block so that I can try to reproduce the hashing.

If any of these tests are impossible to write, please let me know why.

  1. A block with no transactions.

  2. A block with 1 transaction, 0 claims.

  3. A block with 1 transaction, 1 claim.

  4. A block with 1 transaction, 2 claims. The first claim should be the winner.

  5. A block with 1 transaction, 2 claims. The second claim should be the winner.

  6. A block with 2 transactions that do not share any part of the key. 0 claims in either transaction.

  7. A block with 2 transactions that do not share any part of the key. 1 claim in the first transaction, 0 in the second.

  8. A block with 2 transactions that do not share any part of the key. 0 claim in the first transaction, 1 in the second.

  9. A block with 2 transactions that share the first byte of the key. 0 claims in either transaction.

  10. A block with 2 transactions that share the first byte of the key. 1 claim in the first transaction, 0 in the second.

  11. A block with 2 transactions that share the first byte of the key. 0 claim in the first transaction, 1 in the second.

kaykurokawa commented 6 years ago

Merging as a baseline for future unit tests.