buidl-bitcoin / buidl-python

python3 bitcoin library with no dependencies and extensive test coverage
https://pypi.org/project/buidl/
MIT License
83 stars 26 forks source link

Test are sloooooow #132

Closed mflaxman closed 2 years ago

mflaxman commented 2 years ago

Some issues:

  1. We do a lot of tests, which is a good thing
  2. We test many OS's and versions of python, which is a good thing
  3. All these crypto operations are inherently slow. Perhaps we should try to install libsec bindings on github. IDK how hard that is, and since it's optional (slash rarely used) I'd still like that GitHub CI enforce that the more commonly used (slower) tests always validate.
  4. The tests are already parallelized, so I'm not sure there's much low hanging fruit here :(
mflaxman commented 2 years ago
  1. Add caching: https://github.com/actions/setup-python#caching-packages-dependencies
  2. Maybe only run musig tests on PRs, but skip them for regular commits? Not a perfect solution.
mflaxman commented 2 years ago

Some notes on what's causing the slowness:

$ pytest buidl --durations=0
========================================================== test session starts ===========================================================
platform darwin -- Python 3.9.13, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /Users/mflaxman/workspace/buidl-python
collected 255 items                                                                                                                      

buidl/test/test_bcur.py .........                                                                                                  [  3%]
buidl/test/test_bech32.py .                                                                                                        [  3%]
buidl/test/test_blinding.py ........                                                                                               [  7%]
buidl/test/test_block.py ..........                                                                                                [ 10%]
buidl/test/test_bloomfilter.py ..                                                                                                  [ 11%]
buidl/test/test_compactfilter.py ...                                                                                               [ 12%]
buidl/test/test_descriptor.py ............                                                                                         [ 17%]
buidl/test/test_ecc.py ...........                                                                                                 [ 21%]
buidl/test/test_hash.py .                                                                                                          [ 22%]
buidl/test/test_hd.py .....................                                                                                        [ 30%]
buidl/test/test_helper.py ..........                                                                                               [ 34%]
buidl/test/test_merkleblock.py .....                                                                                               [ 36%]
buidl/test/test_mnemonic.py ..                                                                                                     [ 37%]
buidl/test/test_musig.py ................                                                                                          [ 43%]
buidl/test/test_network.py ......sss....                                                                                           [ 48%]
buidl/test/test_op.py .......                                                                                                      [ 51%]
buidl/test/test_pecc.py ..............                                                                                             [ 56%]
buidl/test/test_psbt.py ....................................                                                                       [ 70%]
buidl/test/test_psbt_helper.py .....                                                                                               [ 72%]
buidl/test/test_schnorr.py ...                                                                                                     [ 74%]
buidl/test/test_script.py ...........                                                                                              [ 78%]
buidl/test/test_shamir.py ....                                                                                                     [ 80%]
buidl/test/test_taproot.py .....                                                                                                   [ 81%]
buidl/test/test_timelock.py ..                                                                                                     [ 82%]
buidl/test/test_tx.py .........................................sss                                                                 [100%]

=========================================================== slowest durations ============================================================
81.90s call     buidl/test/test_musig.py::MuSigTest::test_everything_multisig
66.81s call     buidl/test/test_musig.py::MuSigTest::test_degrading_multisig_2
66.27s call     buidl/test/test_musig.py::MuSigTest::test_degrading_multisig
61.83s call     buidl/test/test_musig.py::MuSigTest::test_single_leaf_multisig_locktime
61.74s call     buidl/test/test_musig.py::MuSigTest::test_single_leaf_multisig_sequence
54.27s call     buidl/test/test_musig.py::MuSigTest::test_musig_and_single_leaf_multisig
48.06s call     buidl/test/test_musig.py::MuSigTest::test_multi_leaf_multisig_locktime
47.41s call     buidl/test/test_musig.py::MuSigTest::test_multi_leaf_multisig_sequence
38.86s call     buidl/test/test_musig.py::MuSigTest::test_single_leaf_multisig
31.79s call     buidl/test/test_musig.py::MuSigTest::test_multi_leaf_multisig
29.06s call     buidl/test/test_musig.py::MuSigTest::test_musig_sequence
28.71s call     buidl/test/test_musig.py::MuSigTest::test_musig_locktime
18.51s call     buidl/test/test_musig.py::MuSigTest::test_musig
10.07s call     buidl/test/test_psbt_helper.py::P2SHTest::test_full_wallet_functionality
8.07s call     buidl/test/test_musig.py::MuSigTest::test_internal_pubkey_musig
5.95s call     buidl/test/test_descriptor.py::P2WSHMultiTest::test_p2wsh_1of2_sorted_and_unsorted
5.42s call     buidl/test/test_psbt.py::PSBTTest::test_describe_basic_multisig_nopubkeymap
4.86s call     buidl/test/test_psbt_helper.py::P2SHTest::test_spend_1of2_with_change
4.07s call     buidl/test/test_psbt.py::PSBTTest::test_psbt_multisig_describe_1of4
4.05s call     buidl/test/test_descriptor.py::P2WSHMultiTest::test_p2wsh_1of4
3.88s call     buidl/test/test_taproot.py::TaprootTest::test_p2tr_spending
3.83s call     buidl/test/test_psbt.py::PSBTTest::test_p2sh_p2wsh
3.37s call     buidl/test/test_psbt.py::PSBTTest::test_p2sh_p2wpkh
2.99s call     buidl/test/test_hd.py::HDTest::test_get_address
2.87s call     buidl/test/test_psbt.py::PSBTTest::test_describe_psbt_batch_1of2
2.82s call     buidl/test/test_hd.py::HDTest::test_prv_pub
2.75s call     buidl/test/test_psbt.py::PSBTTest::test_update_p2wsh
2.74s call     buidl/test/test_psbt.py::PSBTTest::test_update_p2sh
2.63s call     buidl/test/test_psbt_helper.py::P2SHTest::test_sweep_1of2_p2sh
2.42s call     buidl/test/test_hd.py::HDTest::test_traverse
2.19s call     buidl/test/test_psbt.py::PSBTTest::test_describe_psbt_2of3
2.14s call     buidl/test/test_psbt_helper.py::P2SHTest::test_sweep_1of2_p2sh_with_non_BIP67_input
2.12s call     buidl/test/test_script.py::RedeemScriptTest::test_create_p2sh_multisig
1.82s call     buidl/test/test_hd.py::HDTest::test_from_mnemonic
1.74s call     buidl/test/test_hd.py::HDTest::test_key_record
1.63s call     buidl/test/test_tx.py::TxTest::test_verify_lightning_receiver_timeout
1.57s call     buidl/test/test_schnorr.py::SchnorrTest::test_signing
1.54s call     buidl/test/test_musig.py::MuSigTest::test_musig2_point_aggregation
1.51s call     buidl/test/test_psbt.py::PSBTTest::test_finalize
1.38s call     buidl/test/test_psbt.py::PSBTTest::test_update_p2wpkh
1.36s call     buidl/test/test_psbt.py::PSBTTest::test_update_p2pkh
1.36s call     buidl/test/test_blinding.py::BlindingTest::test_blind_root_xpub
1.21s call     buidl/test/test_hd.py::HDTest::test_p2tr_address
1.16s call     buidl/test/test_psbt.py::PSBTTest::test_update_1
1.12s call     buidl/test/test_taproot.py::TaprootTest::test_p2tr_validation
1.00s call     buidl/test/test_psbt.py::PSBTTest::test_combine
0.99s call     buidl/test/test_hd.py::HDTest::test_seedpicker
0.83s call     buidl/test/test_ecc.py::PrivateKeyTest::test_sign_schnorr
0.81s call     buidl/test/test_psbt.py::PSBTTest::test_sign_1
0.80s call     buidl/test/test_psbt.py::PSBTTest::test_sign_2
0.76s call     buidl/test/test_hd.py::HDTest::test_child
0.76s call     buidl/test/test_psbt.py::PSBTTest::test_parse
0.72s call     buidl/test/test_blinding.py::BlindingTest::test_blind_m48_vpub
0.72s call     buidl/test/test_blinding.py::BlindingTest::test_blind_m48_xpub
0.66s call     buidl/test/test_musig.py::MuSigTest::test_musig2_compute_r
0.64s call     buidl/test/test_psbt_helper.py::P2SHTest::test_receive_1of2
0.63s call     buidl/test/test_psbt.py::PSBTTest::test_parse_2
0.60s call     buidl/test/test_hd.py::HDTest::test_bip49
0.57s call     buidl/test/test_descriptor.py::P2WSHMultiTest::test_p2wsh_2of3
0.51s call     buidl/test/test_psbt.py::PSBTTest::test_finalize_p2wsh
0.50s call     buidl/test/test_psbt.py::PSBTTest::test_finalize_p2sh
0.50s call     buidl/test/test_schnorr.py::SchnorrTest::test_errors
0.43s call     buidl/test/test_psbt.py::PSBTTest::test_sign_p2wpkh
0.43s call     buidl/test/test_psbt.py::PSBTTest::test_sign_p2pkh
0.41s call     buidl/test/test_hd.py::HDTest::test_zprv
0.41s call     buidl/test/test_hd.py::HDTest::test_vpub
0.39s call     buidl/test/test_tx.py::TxTest::test_sign_p2wsh_multisig
0.39s call     buidl/test/test_tx.py::TxTest::test_sign_p2sh_multisig
0.39s call     buidl/test/test_hd.py::HDTest::test_p2wpkh_address
0.39s call     buidl/test/test_mnemonic.py::MnemonicTest::test_secure_mnemonic_extra_entropy
0.38s call     buidl/test/test_taproot.py::TaprootTest::test_p2tr_general
0.38s call     buidl/test/test_mnemonic.py::MnemonicTest::test_secure_mnemonic_bits
0.38s call     buidl/test/test_tx.py::TxTest::test_sign_p2sh_p2wsh_multisig
0.38s call     buidl/test/test_ecc.py::S256Test::test_verify
0.37s call     buidl/test/test_psbt.py::NamedHDPublicKeyTest::test_redeem_script_lookup
0.37s call     buidl/test/test_op.py::OpTest::test_op_checksig
0.35s call     buidl/test/test_hd.py::HDTest::test_xpub_version
0.33s call     buidl/test/test_blinding.py::BlindingTest::test_bad_depth
0.31s call     buidl/test/test_hd.py::HDTest::test_from_shares
0.31s call     buidl/test/test_shamir.py::ShamirTest::test_generate
0.26s call     buidl/test/test_psbt.py::PSBTTest::test_final_tx_p2wpkh
0.25s call     buidl/test/test_ecc.py::PrivateKeyTest::test_sign_message
0.25s call     buidl/test/test_tx.py::TxTest::test_verify_lightning_sender_timeout
0.25s call     buidl/test/test_tx.py::TxTest::test_verify_p2sh
0.25s call     buidl/test/test_op.py::OpTest::test_op_checkmultisig
0.25s call     buidl/test/test_psbt.py::PSBTTest::test_final_tx
0.25s call     buidl/test/test_ecc.py::PrivateKeyTest::test_sign
0.25s call     buidl/test/test_tx.py::TxTest::test_verify_lightning_local_penalty
0.25s call     buidl/test/test_schnorr.py::SchnorrTest::test_verify
0.25s call     buidl/test/test_tx.py::TxTest::test_verify_lightning_receiver_preimage
0.25s call     buidl/test/test_tx.py::TxTest::test_verify_p2pkh
0.20s call     buidl/test/test_tx.py::TxTest::test_sign_p2pkh
0.19s call     buidl/test/test_tx.py::TxTest::test_sign_p2sh_p2wpkh
0.19s call     buidl/test/test_tx.py::TxTest::test_sign_p2wpkh
0.19s call     buidl/test/test_tx.py::TxTest::test_sign_input
0.19s call     buidl/test/test_hd.py::HDTest::test_from_seed
0.13s call     buidl/test/test_psbt.py::PSBTTest::test_errors
0.13s call     buidl/test/test_descriptor.py::P2WSHMultiTest::test_invalid_p2wsh_sortedmulti
0.13s call     buidl/test/test_psbt.py::PSBTTest::test_finalize_p2wpkh
0.13s call     buidl/test/test_tx.py::TxTest::test_verify_p2sh_p2wsh
0.13s call     buidl/test/test_tx.py::TxTest::test_verify_p2wpkh
0.13s call     buidl/test/test_tx.py::TxTest::test_verify_p2wsh
0.12s call     buidl/test/test_psbt.py::PSBTTest::test_finalize_p2pkh
0.12s call     buidl/test/test_tx.py::TxTest::test_verify_if
0.12s call     buidl/test/test_tx.py::TxTest::test_verify_lightning_local_success
0.12s call     buidl/test/test_tx.py::TxTest::test_verify_p2sh_p2wpkh
0.12s call     buidl/test/test_tx.py::TxTest::test_verify_csv
0.12s call     buidl/test/test_tx.py::TxTest::test_verify_csv_2
0.12s call     buidl/test/test_tx.py::TxTest::test_verify_lightning_sender_preimage
0.12s call     buidl/test/test_tx.py::TxTest::test_verify_cltv
0.11s call     buidl/test/test_ecc.py::S256Test::test_pubpoint
0.06s call     buidl/test/test_psbt.py::PSBTTest::test_psbt_singlsig_describe_sweep
0.06s call     buidl/test/test_descriptor.py::ParseTest::test_valid_key_record_regular
0.06s call     buidl/test/test_taproot.py::TaprootTest::test_p2tr_empty_script_tree
0.06s call     buidl/test/test_taproot.py::TaprootTest::test_hd
0.06s call     buidl/test/test_hd.py::HDTest::test_parse
0.03s call     buidl/test/test_shamir.py::ShamirTest::test_recover
0.02s call     buidl/test/test_ecc.py::S256Test::test_p2wpkh_address
0.02s call     buidl/test/test_ecc.py::S256Test::test_p2sh_p2wpkh_address
0.02s call     buidl/test/test_ecc.py::S256Test::test_address
0.02s call     buidl/test/test_ecc.py::S256Test::test_sec
0.01s call     buidl/test/test_psbt.py::PSBTTest::test_inferring_psbt_network
0.01s call     buidl/test/test_op.py::OfflineTestCase::test_socket_guard
0.01s call     buidl/test/test_bcur.py::BCURMultiTest::test_bcur_multi_encoding_decoding
0.01s call     buidl/test/test_tx.py::OfflineTestCase::test_socket_guard

(634 durations < 0.005s hidden.  Use -vv to show these durations.)
=============================================== 249 passed, 6 skipped in 756.99s (0:12:36) ===============================================
mflaxman commented 2 years ago

Fixed in https://github.com/buidl-bitcoin/buidl-python/pull/143