You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. Regression tests
  2. ================
  3. ### [test_framework/authproxy.py](test_framework/authproxy.py)
  4. Taken from the [python-bitcoinrpc repository](https://github.com/jgarzik/python-bitcoinrpc).
  5. ### [test_framework/test_framework.py](test_framework/test_framework.py)
  6. Base class for new regression tests.
  7. ### [test_framework/util.py](test_framework/util.py)
  8. Generally useful functions.
  9. ### [test_framework/mininode.py](test_framework/mininode.py)
  10. Basic code to support p2p connectivity to a bitcoind.
  11. ### [test_framework/comptool.py](test_framework/comptool.py)
  12. Framework for comparison-tool style, p2p tests.
  13. ### [test_framework/script.py](test_framework/script.py)
  14. Utilities for manipulating transaction scripts (originally from python-bitcoinlib)
  15. ### [test_framework/blockstore.py](test_framework/blockstore.py)
  16. Implements disk-backed block and tx storage.
  17. ### [test_framework/key.py](test_framework/key.py)
  18. Wrapper around OpenSSL EC_Key (originally from python-bitcoinlib)
  19. ### [test_framework/bignum.py](test_framework/bignum.py)
  20. Helpers for script.py
  21. ### [test_framework/blocktools.py](test_framework/blocktools.py)
  22. Helper functions for creating blocks and transactions.
  23. P2P test design notes
  24. ---------------------
  25. ## Mininode
  26. * ```mininode.py``` contains all the definitions for objects that pass
  27. over the network (```CBlock```, ```CTransaction```, etc, along with the network-level
  28. wrappers for them, ```msg_block```, ```msg_tx```, etc).
  29. * P2P tests have two threads. One thread handles all network communication
  30. with the bitcoind(s) being tested (using python's asyncore package); the other
  31. implements the test logic.
  32. * ```NodeConn``` is the class used to connect to a bitcoind. If you implement
  33. a callback class that derives from ```NodeConnCB``` and pass that to the
  34. ```NodeConn``` object, your code will receive the appropriate callbacks when
  35. events of interest arrive.
  36. * You can pass the same handler to multiple ```NodeConn```'s if you like, or pass
  37. different ones to each -- whatever makes the most sense for your test.
  38. * Call ```NetworkThread.start()``` after all ```NodeConn``` objects are created to
  39. start the networking thread. (Continue with the test logic in your existing
  40. thread.)
  41. * RPC calls are available in p2p tests.
  42. * Can be used to write free-form tests, where specific p2p-protocol behavior
  43. is tested. Examples: ```p2p-accept-block.py```, ```maxblocksinflight.py```.
  44. ## Comptool
  45. * Testing framework for writing tests that compare the block/tx acceptance
  46. behavior of a bitcoind against 1 or more other bitcoind instances, or against
  47. known outcomes, or both.
  48. * Set the ```num_nodes``` variable (defined in ```ComparisonTestFramework```) to start up
  49. 1 or more nodes. If using 1 node, then ```--testbinary``` can be used as a command line
  50. option to change the bitcoind binary used by the test. If using 2 or more nodes,
  51. then ```--refbinary``` can be optionally used to change the bitcoind that will be used
  52. on nodes 2 and up.
  53. * Implement a (generator) function called ```get_tests()``` which yields ```TestInstance```s.
  54. Each ```TestInstance``` consists of:
  55. - a list of ```[object, outcome, hash]``` entries
  56. * ```object``` is a ```CBlock```, ```CTransaction```, or
  57. ```CBlockHeader```. ```CBlock```'s and ```CTransaction```'s are tested for
  58. acceptance. ```CBlockHeader```s can be used so that the test runner can deliver
  59. complete headers-chains when requested from the bitcoind, to allow writing
  60. tests where blocks can be delivered out of order but still processed by
  61. headers-first bitcoind's.
  62. * ```outcome``` is ```True```, ```False```, or ```None```. If ```True```
  63. or ```False```, the tip is compared with the expected tip -- either the
  64. block passed in, or the hash specified as the optional 3rd entry. If
  65. ```None``` is specified, then the test will compare all the bitcoind's
  66. being tested to see if they all agree on what the best tip is.
  67. * ```hash``` is the block hash of the tip to compare against. Optional to
  68. specify; if left out then the hash of the block passed in will be used as
  69. the expected tip. This allows for specifying an expected tip while testing
  70. the handling of either invalid blocks or blocks delivered out of order,
  71. which complete a longer chain.
  72. - ```sync_every_block```: ```True/False```. If ```False```, then all blocks
  73. are inv'ed together, and the test runner waits until the node receives the
  74. last one, and tests only the last block for tip acceptance using the
  75. outcome and specified tip. If ```True```, then each block is tested in
  76. sequence and synced (this is slower when processing many blocks).
  77. - ```sync_every_transaction```: ```True/False```. Analogous to
  78. ```sync_every_block```, except if the outcome on the last tx is "None",
  79. then the contents of the entire mempool are compared across all bitcoind
  80. connections. If ```True``` or ```False```, then only the last tx's
  81. acceptance is tested against the given outcome.
  82. * For examples of tests written in this framework, see
  83. ```invalidblockrequest.py``` and ```p2p-fullblocktest.py```.