Skip to content

Commit

Permalink
Reformat files
Browse files Browse the repository at this point in the history
  • Loading branch information
shohamc1 committed Mar 20, 2023
1 parent 4e4f7f3 commit 47c4cc6
Show file tree
Hide file tree
Showing 282 changed files with 9,861 additions and 7,059 deletions.
10 changes: 4 additions & 6 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ etc.
This directory contains the following sets of tests:

- [functional](/test/functional) which test the functionality of
defid and defi-qt by interacting with them through the RPC and P2P
interfaces.
defid and defi-qt by interacting with them through the RPC and P2P
interfaces.
- [util](/test/util) which tests the defi utilities, currently only
defi-tx.
defi-tx.
- [lint](/test/lint/) which perform various static analysis checks.

The util tests are run as part of `make check` target. The functional
tests and lint scripts can be run as explained in the sections below.

# Running tests locally

Before tests can be run locally, DeFi Blockchain must be built. See the [building instructions](/doc#building) for help.

Before tests can be run locally, DeFi Blockchain must be built. See the [building instructions](/doc#building) for help.

### Functional tests

Expand Down Expand Up @@ -119,7 +118,6 @@ or
pkill -9 defid
```


##### Data directory cache

A pre-mined blockchain with 200 blocks is generated the first time a
Expand Down
30 changes: 20 additions & 10 deletions test/functional/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ don't have test cases for.
- The oldest supported Python version is specified in [doc/dependencies.md](/doc/dependencies.md).
Consider using [pyenv](https://github.com/pyenv/pyenv), which checks [.python-version](/.python-version),
to prevent accidentally introducing modern syntax from an unsupported Python version.
The Travis linter also checks this, but [possibly not in all cases](https://github.com/bitcoin/bitcoin/pull/14884#discussion_r239585126).
The Travis linter also checks this,
but [possibly not in all cases](https://github.com/bitcoin/bitcoin/pull/14884#discussion_r239585126).
- See [the python lint script](/test/lint/lint-python.sh) that checks for violations that
could lead to bugs and issues in the test code.
- Avoid wildcard imports
Expand All @@ -46,7 +47,8 @@ don't have test cases for.
- `tool` for tests for tools, eg `tool_wallet.py`
- `wallet` for tests for wallet features, eg `wallet_keypool.py`
- use an underscore to separate words
- 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`
- 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`
- Don't use the redundant word `test` in the name, eg `interface_zmq.py`, not `interface_zmq_test.py`

#### General test-writing advice
Expand Down Expand Up @@ -83,45 +85,53 @@ P2P messages. These can be found in the following source files:
#### Using the P2P interface

- `messages.py` contains all the definitions for objects that pass
over the network (`CBlock`, `CTransaction`, etc, along with the network-level
wrappers for them, `msg_block`, `msg_tx`, etc).
over the network (`CBlock`, `CTransaction`, etc, along with the network-level
wrappers for them, `msg_block`, `msg_tx`, etc).

- P2P tests have two threads. One thread handles all network communication
with the defid(s) being tested in a callback-based event loop; the other
implements the test logic.
with the defid(s) being tested in a callback-based event loop; the other
implements the test logic.

- `P2PConnection` is the class used to connect to a defid. `P2PInterface`
contains the higher level logic for processing P2P payloads and connecting to
the DeFi Blockchain node application logic. For custom behaviour, subclass the
P2PInterface object and override the callback methods.
contains the higher level logic for processing P2P payloads and connecting to
the DeFi Blockchain node application logic. For custom behaviour, subclass the
P2PInterface object and override the callback methods.

- Can be used to write tests where specific P2P protocol behavior is tested.
Examples tests are `p2p_unrequested_blocks.py`, `p2p_compactblocks.py`.
Examples tests are `p2p_unrequested_blocks.py`, `p2p_compactblocks.py`.

### test-framework modules

#### [test_framework/authproxy.py](test_framework/authproxy.py)

Taken from the [python-bitcoinrpc repository](https://github.com/jgarzik/python-bitcoinrpc).

#### [test_framework/test_framework.py](test_framework/test_framework.py)

Base class for functional tests.

#### [test_framework/util.py](test_framework/util.py)

Generally useful functions.

#### [test_framework/mininode.py](test_framework/mininode.py)

Basic code to support P2P connectivity to a defid.

#### [test_framework/script.py](test_framework/script.py)

Utilities for manipulating transaction scripts (originally from python-bitcoinlib)

#### [test_framework/key.py](test_framework/key.py)

Wrapper around OpenSSL EC_Key (originally from python-bitcoinlib)

#### [test_framework/bignum.py](test_framework/bignum.py)

Helpers for script.py

#### [test_framework/blocktools.py](test_framework/blocktools.py)

Helper functions for creating blocks and transactions.

### Benchmarking with perf
Expand Down
17 changes: 10 additions & 7 deletions test/functional/combine_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

LogEvent = namedtuple('LogEvent', ['timestamp', 'source', 'event'])


def main():
"""Main function. Parses args, reads the log files and renders them as text or html."""
parser = argparse.ArgumentParser(
Expand All @@ -36,8 +37,10 @@ def main():
'testdir', nargs='?', default='',
help=('temporary test directory to combine logs from. '
'Defaults to the most recent'))
parser.add_argument('-c', '--color', dest='color', action='store_true', help='outputs the combined log with events colored by source (requires posix terminal colors. Use less -r for viewing)')
parser.add_argument('--html', dest='html', action='store_true', help='outputs the combined log as html. Requires jinja2. pip install jinja2')
parser.add_argument('-c', '--color', dest='color', action='store_true',
help='outputs the combined log with events colored by source (requires posix terminal colors. Use less -r for viewing)')
parser.add_argument('--html', dest='html', action='store_true',
help='outputs the combined log as html. Requires jinja2. pip install jinja2')
args = parser.parse_args()

if args.html and args.color:
Expand Down Expand Up @@ -125,9 +128,9 @@ def join_tmp(basename):
def is_valid_test_tmpdir(basename):
fullpath = join_tmp(basename)
return (
os.path.isdir(fullpath)
and basename.startswith(TMPDIR_PREFIX)
and os.access(fullpath, os.R_OK)
os.path.isdir(fullpath)
and basename.startswith(TMPDIR_PREFIX)
and os.access(fullpath, os.R_OK)
)

testdir_paths = [
Expand Down Expand Up @@ -190,8 +193,8 @@ def print_logs_html(log_events):
print("jinja2 not found. Try `pip install jinja2`")
sys.exit(1)
print(jinja2.Environment(loader=jinja2.FileSystemLoader('./'))
.get_template('combined_log_template.html')
.render(title="Combined Logs from testcase", log_events=[event._asdict() for event in log_events]))
.get_template('combined_log_template.html')
.render(title="Combined Logs from testcase", log_events=[event._asdict() for event in log_events]))


if __name__ == '__main__':
Expand Down
13 changes: 10 additions & 3 deletions test/functional/combined_log_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,42 @@
list-style-type: none;
font-family: monospace;
}

li {
border: 1px solid slategray;
margin-bottom: 1px;
}

li:hover {
filter: brightness(85%);
}

li.log-test {
background-color: cyan;
}

li.log-node0 {
background-color: lightblue;
}

li.log-node1 {
background-color: lightgreen;
}

li.log-node2 {
background-color: lightsalmon;
}

li.log-node3 {
background-color: lightyellow;
}
</style>
</head>
<body>
<ul>
{% for event in log_events %}
<li class="log-{{ event.source }}"> {{ event.source }} {{ event.timestamp }} {{event.event}}</li>
{% endfor %}
{% for event in log_events %}
<li class="log-{{ event.source }}"> {{ event.source }} {{ event.timestamp }} {{event.event}}</li>
{% endfor %}
</ul>
</body>
</html>
2 changes: 2 additions & 0 deletions test/functional/create_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from test_framework.test_framework import DefiTestFramework


class CreateCache(DefiTestFramework):
# Test network and test nodes are not required:

Expand All @@ -24,5 +25,6 @@ def setup_network(self):
def run_test(self):
pass


if __name__ == '__main__':
CreateCache().main()
Loading

0 comments on commit 47c4cc6

Please sign in to comment.