Skip to content

Commit 2285be3

Browse files
committed
add test folder from upstream btc
1 parent c4d027d commit 2285be3

File tree

173 files changed

+27289
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+27289
-0
lines changed

test/README.md

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
This directory contains integration tests that test syscoind and its
2+
utilities in their entirety. It does not contain unit tests, which
3+
can be found in [/src/test](/src/test), [/src/wallet/test](/src/wallet/test),
4+
etc.
5+
6+
There are currently two sets of tests in this directory:
7+
8+
- [functional](/test/functional) which test the functionality of
9+
syscoind and syscoin-qt by interacting with them through the RPC and P2P
10+
interfaces.
11+
- [util](/test/util) which tests the syscoin utilities, currently only
12+
syscoin-tx.
13+
14+
The util tests are run as part of `make check` target. The functional
15+
tests are run by the travis continuous build process whenever a pull
16+
request is opened. Both sets of tests can also be run locally.
17+
18+
# Running tests locally
19+
20+
Build for your system first. Be sure to enable wallet, utils and daemon when you configure. Tests will not run otherwise.
21+
22+
### Functional tests
23+
24+
#### Dependencies
25+
26+
The ZMQ functional test requires a python ZMQ library. To install it:
27+
28+
- on Unix, run `sudo apt-get install python3-zmq`
29+
- on mac OS, run `pip3 install pyzmq`
30+
31+
#### Running the tests
32+
33+
Individual tests can be run by directly calling the test script, eg:
34+
35+
```
36+
test/functional/feature_rbf.py
37+
```
38+
39+
or can be run through the test_runner harness, eg:
40+
41+
```
42+
test/functional/test_runner.py feature_rbf.py
43+
```
44+
45+
You can run any combination (incl. duplicates) of tests by calling:
46+
47+
```
48+
test/functional/test_runner.py <testname1> <testname2> <testname3> ...
49+
```
50+
51+
Run the regression test suite with:
52+
53+
```
54+
test/functional/test_runner.py
55+
```
56+
57+
Run all possible tests with
58+
59+
```
60+
test/functional/test_runner.py --extended
61+
```
62+
63+
By default, up to 4 tests will be run in parallel by test_runner. To specify
64+
how many jobs to run, append `--jobs=n`
65+
66+
The individual tests and the test_runner harness have many command-line
67+
options. Run `test_runner.py -h` to see them all.
68+
69+
#### Troubleshooting and debugging test failures
70+
71+
##### Resource contention
72+
73+
The P2P and RPC ports used by the syscoind nodes-under-test are chosen to make
74+
conflicts with other processes unlikely. However, if there is another syscoind
75+
process running on the system (perhaps from a previous test which hasn't successfully
76+
killed all its syscoind nodes), then there may be a port conflict which will
77+
cause the test to fail. It is recommended that you run the tests on a system
78+
where no other syscoind processes are running.
79+
80+
On linux, the test_framework will warn if there is another
81+
syscoind process running when the tests are started.
82+
83+
If there are zombie syscoind processes after test failure, you can kill them
84+
by running the following commands. **Note that these commands will kill all
85+
syscoind processes running on the system, so should not be used if any non-test
86+
syscoind processes are being run.**
87+
88+
```bash
89+
killall syscoind
90+
```
91+
92+
or
93+
94+
```bash
95+
pkill -9 syscoind
96+
```
97+
98+
99+
##### Data directory cache
100+
101+
A pre-mined blockchain with 200 blocks is generated the first time a
102+
functional test is run and is stored in test/cache. This speeds up
103+
test startup times since new blockchains don't need to be generated for
104+
each test. However, the cache may get into a bad state, in which case
105+
tests will fail. If this happens, remove the cache directory (and make
106+
sure syscoind processes are stopped as above):
107+
108+
```bash
109+
rm -rf cache
110+
killall syscoind
111+
```
112+
113+
##### Test logging
114+
115+
The tests contain logging at different levels (debug, info, warning, etc). By
116+
default:
117+
118+
- when run through the test_runner harness, *all* logs are written to
119+
`test_framework.log` and no logs are output to the console.
120+
- when run directly, *all* logs are written to `test_framework.log` and INFO
121+
level and above are output to the console.
122+
- when run on Travis, no logs are output to the console. However, if a test
123+
fails, the `test_framework.log` and syscoind `debug.log`s will all be dumped
124+
to the console to help troubleshooting.
125+
126+
To change the level of logs output to the console, use the `-l` command line
127+
argument.
128+
129+
`test_framework.log` and syscoind `debug.log`s can be combined into a single
130+
aggregate log by running the `combine_logs.py` script. The output can be plain
131+
text, colorized text or html. For example:
132+
133+
```
134+
combine_logs.py -c <test data directory> | less -r
135+
```
136+
137+
will pipe the colorized logs from the test into less.
138+
139+
Use `--tracerpc` to trace out all the RPC calls and responses to the console. For
140+
some tests (eg any that use `submitblock` to submit a full block over RPC),
141+
this can result in a lot of screen output.
142+
143+
By default, the test data directory will be deleted after a successful run.
144+
Use `--nocleanup` to leave the test data directory intact. The test data
145+
directory is never deleted after a failed test.
146+
147+
##### Attaching a debugger
148+
149+
A python debugger can be attached to tests at any point. Just add the line:
150+
151+
```py
152+
import pdb; pdb.set_trace()
153+
```
154+
155+
anywhere in the test. You will then be able to inspect variables, as well as
156+
call methods that interact with the syscoind nodes-under-test.
157+
158+
If further introspection of the syscoind instances themselves becomes
159+
necessary, this can be accomplished by first setting a pdb breakpoint
160+
at an appropriate location, running the test to that point, then using
161+
`gdb` to attach to the process and debug.
162+
163+
For instance, to attach to `self.node[1]` during a run:
164+
165+
```bash
166+
2017-06-27 14:13:56.686000 TestFramework (INFO): Initializing test directory /tmp/user/1000/testo9vsdjo3
167+
```
168+
169+
use the directory path to get the pid from the pid file:
170+
171+
```bash
172+
cat /tmp/user/1000/testo9vsdjo3/node1/regtest/syscoind.pid
173+
gdb /home/example/syscoind <pid>
174+
```
175+
176+
Note: gdb attach step may require `sudo`
177+
178+
### Util tests
179+
180+
Util tests can be run locally by running `test/util/syscoin-util-test.py`.
181+
Use the `-v` option for verbose output.
182+
183+
# Writing functional tests
184+
185+
You are encouraged to write functional tests for new or existing features.
186+
Further information about the functional test framework and individual
187+
tests is found in [test/functional](/test/functional).

test/config.ini.in

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2013-2016 The Syscoin Core developers
2+
# Distributed under the MIT software license, see the accompanying
3+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
# These environment variables are set by the build process and read by
6+
# test/functional/test_runner.py and test/util/syscoin-util-test.py
7+
8+
[environment]
9+
SRCDIR=@abs_top_srcdir@
10+
BUILDDIR=@abs_top_builddir@
11+
EXEEXT=@EXEEXT@
12+
RPCAUTH=@abs_top_srcdir@/share/rpcauth/rpcauth.py
13+
14+
[components]
15+
# Which components are enabled. These are commented out by `configure` if they were disabled when running config.
16+
@ENABLE_WALLET_TRUE@ENABLE_WALLET=true
17+
@BUILD_SYSCOIN_UTILS_TRUE@ENABLE_UTILS=true
18+
@BUILD_SYSCOIND_TRUE@ENABLE_SYSCOIND=true
19+
@ENABLE_ZMQ_TRUE@ENABLE_ZMQ=true

test/functional/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.pyc
2+
cache

test/functional/README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Functional tests
2+
3+
### Writing Functional Tests
4+
5+
#### Example test
6+
7+
The [example_test.py](example_test.py) is a heavily commented example of a test case that uses both
8+
the RPC and P2P interfaces. If you are writing your first test, copy that file
9+
and modify to fit your needs.
10+
11+
#### Coverage
12+
13+
Running `test_runner.py` with the `--coverage` argument tracks which RPCs are
14+
called by the tests and prints a report of uncovered RPCs in the summary. This
15+
can be used (along with the `--extended` argument) to find out which RPCs we
16+
don't have test cases for.
17+
18+
#### Style guidelines
19+
20+
- Where possible, try to adhere to [PEP-8 guidelines](https://www.python.org/dev/peps/pep-0008/)
21+
- Use a python linter like flake8 before submitting PRs to catch common style
22+
nits (eg trailing whitespace, unused imports, etc)
23+
- Avoid wildcard imports where possible
24+
- Use a module-level docstring to describe what the test is testing, and how it
25+
is testing it.
26+
- When subclassing the SyscoinTestFramwork, place overrides for the
27+
`set_test_params()`, `add_options()` and `setup_xxxx()` methods at the top of
28+
the subclass, then locally-defined helper methods, then the `run_test()` method.
29+
30+
#### Naming guidelines
31+
32+
- Name the test `<area>_test.py`, where area can be one of the following:
33+
- `feature` for tests for full features that aren't wallet/mining/mempool, eg `feature_rbf.py`
34+
- `interface` for tests for other interfaces (REST, ZMQ, etc), eg `interface_rest.py`
35+
- `mempool` for tests for mempool behaviour, eg `mempool_reorg.py`
36+
- `mining` for tests for mining features, eg `mining_prioritisetransaction.py`
37+
- `p2p` for tests that explicitly test the p2p interface, eg `p2p_disconnect_ban.py`
38+
- `rpc` for tests for individual RPC methods or features, eg `rpc_listtransactions.py`
39+
- `wallet` for tests for wallet features, eg `wallet_keypool.py`
40+
- use an underscore to separate words
41+
- exception: for tests for specific RPCs or command line options which don't include underscores, name the test after the exact RPC or argument name, eg `rpc_decodescript.py`, not `rpc_decode_script.py`
42+
- Don't use the redundant word `test` in the name, eg `interface_zmq.py`, not `interface_zmq_test.py`
43+
44+
#### General test-writing advice
45+
46+
- Set `self.num_nodes` to the minimum number of nodes necessary for the test.
47+
Having additional unrequired nodes adds to the execution time of the test as
48+
well as memory/CPU/disk requirements (which is important when running tests in
49+
parallel or on Travis).
50+
- Avoid stop-starting the nodes multiple times during the test if possible. A
51+
stop-start takes several seconds, so doing it several times blows up the
52+
runtime of the test.
53+
- Set the `self.setup_clean_chain` variable in `set_test_params()` to control whether
54+
or not to use the cached data directories. The cached data directories
55+
contain a 200-block pre-mined blockchain and wallets for four nodes. Each node
56+
has 25 mature blocks (25x50=1250 BTC) in its wallet.
57+
- When calling RPCs with lots of arguments, consider using named keyword
58+
arguments instead of positional arguments to make the intent of the call
59+
clear to readers.
60+
61+
#### RPC and P2P definitions
62+
63+
Test writers may find it helpful to refer to the definitions for the RPC and
64+
P2P messages. These can be found in the following source files:
65+
66+
- `/src/rpc/*` for RPCs
67+
- `/src/wallet/rpc*` for wallet RPCs
68+
- `ProcessMessage()` in `/src/net_processing.cpp` for parsing P2P messages
69+
70+
#### Using the P2P interface
71+
72+
- `mininode.py` contains all the definitions for objects that pass
73+
over the network (`CBlock`, `CTransaction`, etc, along with the network-level
74+
wrappers for them, `msg_block`, `msg_tx`, etc).
75+
76+
- P2P tests have two threads. One thread handles all network communication
77+
with the syscoind(s) being tested (using python's asyncore package); the other
78+
implements the test logic.
79+
80+
- `P2PConnection` is the class used to connect to a syscoind. `P2PInterface`
81+
contains the higher level logic for processing P2P payloads and connecting to
82+
the Syscoin Core node application logic. For custom behaviour, subclass the
83+
P2PInterface object and override the callback methods.
84+
85+
- Call `network_thread_start()` after all `P2PInterface` objects are created to
86+
start the networking thread. (Continue with the test logic in your existing
87+
thread.)
88+
89+
- Can be used to write tests where specific P2P protocol behavior is tested.
90+
Examples tests are `p2p_unrequested_blocks.py`, `p2p_compactblocks.py`.
91+
92+
### test-framework modules
93+
94+
#### [test_framework/authproxy.py](test_framework/authproxy.py)
95+
Taken from the [python-syscoinrpc repository](https://github.com/jgarzik/python-syscoinrpc).
96+
97+
#### [test_framework/test_framework.py](test_framework/test_framework.py)
98+
Base class for functional tests.
99+
100+
#### [test_framework/util.py](test_framework/util.py)
101+
Generally useful functions.
102+
103+
#### [test_framework/mininode.py](test_framework/mininode.py)
104+
Basic code to support P2P connectivity to a syscoind.
105+
106+
#### [test_framework/script.py](test_framework/script.py)
107+
Utilities for manipulating transaction scripts (originally from python-syscoinlib)
108+
109+
#### [test_framework/key.py](test_framework/key.py)
110+
Wrapper around OpenSSL EC_Key (originally from python-syscoinlib)
111+
112+
#### [test_framework/bignum.py](test_framework/bignum.py)
113+
Helpers for script.py
114+
115+
#### [test_framework/blocktools.py](test_framework/blocktools.py)
116+
Helper functions for creating blocks and transactions.

0 commit comments

Comments
 (0)