Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chroe: add testcase for verify_new_client #18

Merged

Conversation

EthanYuan
Copy link
Collaborator

@EthanYuan EthanYuan commented Apr 30, 2024

Add test cases for verify_new_client. The cases test verify_new_client by extracting data from the update tx, and this process can show the log in the spv lib for analysis of the dumped tx. The following fix pr uses this approach:

This PR just adds tests and does not affect the main code of the library.

The log looks like this:

ethan@T14s-Gen4:~/projects/cell-studio/ckb-bitcoin-spv$ cargo test --package ckb-bitcoin-spv-verifier --lib -- tests::testnet::testnet_verify_new_client_error --exact --show-output

[2024-05-09T07:32:01Z INFO  ckb_bitcoin_spv_verifier::types::extension::packed] old client is { id: 21, tip: 0x0000000000000013f8286e880929e01248fd44b092aca3e103e92fb030992e06, mmr-root: { headers-range: [2582496, 2588540], work: 0x000000000000000000000000000000000000000000000064f6addc5c12f19430, hash: 0xa82bba5734f6fcd1a54e1e96171769c74180ac045dfae1277cf2bef9fb9df990 } }
[2024-05-09T07:32:01Z INFO  ckb_bitcoin_spv_verifier::types::extension::packed] new client is { id: 21, tip: 0x000000000000f0861e4ff8bf8c7f5689ddd9d959e8d3e867b3d20c200f113696, mmr-root: { headers-range: [2582496, 2588550], work: 0x000000000000000000000000000000000000000000000064fc3bade51f756a11, hash: 0x7a18677bc2aef83159f6c9cee87e43e458f3b3a285b7f458048449643b216a42 } }
[2024-05-09T07:32:01Z DEBUG ckb_bitcoin_spv_verifier::types::extension::packed] update has 10 headers
[2024-05-09T07:32:01Z TRACE ckb_bitcoin_spv_verifier::types::extension::packed] tip block hash: 0x0000000000000013f8286e880929e01248fd44b092aca3e103e92fb030992e06, max height: 2588540
[2024-05-09T07:32:01Z TRACE ckb_bitcoin_spv_verifier::types::extension::packed] tip block hash: 0x000000000000000686ee6e56aea7aa5cc653da1ae44e17c4ece7137041727afb, max height: 2588541, digest: { headers-range: [2588541, 2588541], work: 0x000000000000000000000000000000000000000000000000058dd175e4e61594, hash: 0x000000000000000686ee6e56aea7aa5cc653da1ae44e17c4ece7137041727afb }
[2024-05-09T07:32:01Z ERROR ckb_bitcoin_spv_verifier::types::extension::packed] failed: invalid difficulty for header-2588542, expect 422451157 but got 486604799
[2024-05-09T07:32:01Z TRACE ckb_bitcoin_spv_verifier::types::extension::packed] tip block hash: 0x00000000c5e34108e82af72092b6f3c82211c90642a05ed8f7a9f4eae305649c, max height: 2588542, digest: { headers-range: [2588542, 2588542], work: 0x0000000000000000000000000000000000000000000000000000000100010001, hash: 0x00000000c5e34108e82af72092b6f3c82211c90642a05ed8f7a9f4eae305649c }
[2024-05-09T07:32:01Z ERROR ckb_bitcoin_spv_verifier::types::extension::packed] failed: invalid difficulty for header-2588543, expect 422451157 but got 486604799
[2024-05-09T07:32:01Z TRACE ckb_bitcoin_spv_verifier::utilities::bitcoin] prev-target = 26959535291011309493156476344723991336010898738574164086137773096960
[2024-05-09T07:32:01Z TRACE ckb_bitcoin_spv_verifier::utilities::bitcoin] prev-target * 493586 = 13306849186149108207489132533086935987576275464777867354620398871836098560
[2024-05-09T07:32:01Z TRACE ckb_bitcoin_spv_verifier::utilities::bitcoin] 13306849186149108207489132533086935987576275464777867354620398871836098560 / 1209600 = 11001032726644434695344851631189596550575624557521385048462631342457
[2024-05-09T07:32:01Z TRACE ckb_bitcoin_spv_verifier::utilities::bitcoin] use the calculated target
[2024-05-09T07:32:01Z TRACE ckb_bitcoin_spv_verifier::types::extension::packed] tip block hash: 0x000000007f31278326e2cf458be3fbc904d4f98f3b348c8f2f3042d590fe2ddd, max height: 2588543, digest: { headers-range: [2588543, 2588543], work: 0x0000000000000000000000000000000000000000000000000000000100010001, hash: 0x000000007f31278326e2cf458be3fbc904d4f98f3b348c8f2f3042d590fe2ddd }
[2024-05-09T07:32:01Z TRACE ckb_bitcoin_spv_verifier::types::extension::packed] tip block hash: 0x000000000000d6fe7f71089f0317602b5056b0ff9398affe1970a057ca5a2be0, max height: 2588544, digest: { headers-range: [2588544, 2588544], work: 0x00000000000000000000000000000000000000000000000000000002735f649d, hash: 0x000000000000d6fe7f71089f0317602b5056b0ff9398affe1970a057ca5a2be0 }
[2024-05-09T07:32:01Z TRACE ckb_bitcoin_spv_verifier::types::extension::packed] tip block hash: 0x000000000000fa58f6f1312af7e511cfb6c1c4e83d584afe519c47e1cf29fee9, max height: 2588545, digest: { headers-range: [2588545, 2588545], work: 0x00000000000000000000000000000000000000000000000000000002735f649d, hash: 0x000000000000fa58f6f1312af7e511cfb6c1c4e83d584afe519c47e1cf29fee9 }
[2024-05-09T07:32:01Z TRACE ckb_bitcoin_spv_verifier::types::extension::packed] tip block hash: 0x000000000000c1d564f02846d8e34eb3c43cb2aadddbbedd2d7c339a6c9ce1d2, max height: 2588546, digest: { headers-range: [2588546, 2588546], work: 0x00000000000000000000000000000000000000000000000000000002735f649d, hash: 0x000000000000c1d564f02846d8e34eb3c43cb2aadddbbedd2d7c339a6c9ce1d2 }
[2024-05-09T07:32:01Z TRACE ckb_bitcoin_spv_verifier::types::extension::packed] tip block hash: 0x00000000000057ea35b3d301b48da2f65204e57d3931dbebc43a7e1ba2599bb2, max height: 2588547, digest: { headers-range: [2588547, 2588547], work: 0x00000000000000000000000000000000000000000000000000000002735f649d, hash: 0x00000000000057ea35b3d301b48da2f65204e57d3931dbebc43a7e1ba2599bb2 }
[2024-05-09T07:32:01Z TRACE ckb_bitcoin_spv_verifier::types::extension::packed] tip block hash: 0x000000000000b48525b11c9711869c72e268adee108d32c73b510f233c109423, max height: 2588548, digest: { headers-range: [2588548, 2588548], work: 0x00000000000000000000000000000000000000000000000000000002735f649d, hash: 0x000000000000b48525b11c9711869c72e268adee108d32c73b510f233c109423 }
[2024-05-09T07:32:01Z TRACE ckb_bitcoin_spv_verifier::types::extension::packed] tip block hash: 0x000000000000da8a05b0d82b52f1cd100995a58e029751ea6c1c4ee9cf7aad60, max height: 2588549, digest: { headers-range: [2588549, 2588549], work: 0x00000000000000000000000000000000000000000000000000000002735f649d, hash: 0x000000000000da8a05b0d82b52f1cd100995a58e029751ea6c1c4ee9cf7aad60 }
[2024-05-09T07:32:01Z TRACE ckb_bitcoin_spv_verifier::types::extension::packed] tip block hash: 0x000000000000f0861e4ff8bf8c7f5689ddd9d959e8d3e867b3d20c200f113696, max height: 2588550, digest: { headers-range: [2588550, 2588550], work: 0x00000000000000000000000000000000000000000000000000000002735f649d, hash: 0x000000000000f0861e4ff8bf8c7f5689ddd9d959e8d3e867b3d20c200f113696 }
[2024-05-09T07:32:01Z DEBUG ckb_bitcoin_spv_verifier::types::extension::packed] check MMR root with size: 12101, max-index: 6054
[2024-05-09T07:32:01Z DEBUG ckb_bitcoin_spv_verifier::types::extension::packed] passed: verify MMR proof for headers between 2588541 and 2588550

@EthanYuan EthanYuan requested review from Flouse and jjyr April 30, 2024 11:50
@EthanYuan EthanYuan marked this pull request as ready for review May 9, 2024 07:58
verifier/src/tests/testnet.rs Outdated Show resolved Hide resolved
@EthanYuan EthanYuan requested a review from jjyr May 10, 2024 07:00
@EthanYuan EthanYuan enabled auto-merge May 14, 2024 04:27
@Flouse Flouse disabled auto-merge May 21, 2024 02:49
@Flouse Flouse merged commit bfb9ed0 into utxostack:master May 21, 2024
5 checks passed
@EthanYuan EthanYuan deleted the add-test-case-for-verify-new-client branch June 4, 2024 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants