Skip to content

Commit 4ba9cd8

Browse files
Add basic CI tests
1 parent 9e7d63e commit 4ba9cd8

10 files changed

Lines changed: 187 additions & 97 deletions

‎.github/workflows/test.yml‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: 'Tests'
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
workflow_dispatch:
12+
13+
jobs:
14+
ubuntu:
15+
runs-on: ubuntu-latest
16+
name: ubuntu
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Install dependencies
22+
run: |
23+
sudo apt update
24+
sudo apt install -y build-essential cmake pkg-config libssl-dev libzmq3-dev libunbound-dev libsodium-dev libunwind8-dev liblzma-dev libreadline6-dev libexpat1-dev libpgm-dev qttools5-dev-tools libhidapi-dev libusb-1.0-0-dev libprotobuf-dev protobuf-compiler libudev-dev libboost-chrono-dev libboost-date-time-dev libboost-filesystem-dev libboost-locale-dev libboost-program-options-dev libboost-regex-dev libboost-serialization-dev libboost-system-dev libboost-thread-dev python3 ccache doxygen graphviz git curl autoconf libtool gperf nettle-dev libevent-dev debhelper python3-all python3-pip python3-pybind11 python3-pytest
25+
pip3 install pybind11-stubgen pytest --break-system-packages
26+
27+
- name: Install expat
28+
run: |
29+
wget https://github.com/libexpat/libexpat/releases/download/R_2_4_8/expat-2.4.8.tar.bz2
30+
tar -xf expat-2.4.8.tar.bz2
31+
sudo rm expat-2.4.8.tar.bz2
32+
cd expat-2.4.8
33+
./configure --enable-static --disable-shared
34+
make
35+
sudo make install
36+
cd ../
37+
38+
- name: Install unbound
39+
run: |
40+
wget https://www.nlnetlabs.nl/downloads/unbound/unbound-1.22.0.tar.gz
41+
tar xzf unbound-1.22.0.tar.gz
42+
sudo apt install -y build-essential
43+
sudo apt install -y libssl-dev
44+
sudo apt install -y libexpat1-dev
45+
sudo apt-get install -y bison
46+
sudo apt-get install -y flex
47+
cd unbound-1.22.0
48+
./configure --with-libexpat=/usr --with-ssl=/usr --enable-static-exe
49+
make
50+
sudo make install
51+
cd ../
52+
53+
- name: Update submodules
54+
run: |
55+
git submodule update --init --recursive
56+
57+
- name: Build monero
58+
run: |
59+
mkdir build
60+
cd external/monero-cpp/external/monero-project
61+
mkdir -p build/release
62+
cd build/release
63+
cmake -DSTATIC=ON -DBUILD_64=ON -DCMAKE_BUILD_TYPE=Release ../../
64+
make -j3 wallet cryptonote_protocol
65+
cd ../../../../../../
66+
67+
- name: Build monero-cpp
68+
run: |
69+
cd external/monero-cpp
70+
mkdir -p build
71+
cd build
72+
cmake ..
73+
cmake --build .
74+
make -j3
75+
sudo cp libmonero-cpp.so /usr/lib/
76+
cd ../../../
77+
78+
- name: Build monero-python
79+
run: |
80+
mkdir -p build
81+
pip3 install .
82+
83+
- name: Run tests
84+
run: |
85+
pytest

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Monero Python Library
22
[![Build](https://github.com/everoddandeven/monero-python/actions/workflows/build-deb.yml/badge.svg)](https://github.com/everoddandeven/monero-python/actions/workflows/build-deb.yml)
3+
[![Tests](https://github.com/everoddandeven/monero-python/actions/workflows/test.yml/badge.svg)](https://github.com/everoddandeven/monero-python/actions/workflows/test.yml)
34
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/aeff91a5b1d543ddb400f88ffce150a8)](https://app.codacy.com/gh/everoddandeven/monero-python/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
45

56
> [!NOTE]

‎tests/test_monero_connection_manager.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from utils import ConnectionChangeCollector, MoneroTestUtils as Utils
88

99

10-
@pytest.mark.monero_connection_manager
10+
# TODO enable connection manager tests
11+
@pytest.mark.skipif(True, reason="TODO")
1112
class TestMoneroConnectionManager:
1213

1314
def test_connection_manager(self):

‎tests/test_monero_daemon_rpc.py‎

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,34 @@
1313
from utils import MoneroTestUtils as Utils, TestContext, BinaryBlockContext
1414

1515

16-
@pytest.mark.monero_daemon_rpc
16+
# TODO enable rpc daemon tests
17+
@pytest.mark.skipif(True, reason="TODO")
1718
class TestMoneroDaemonRpc:
1819
_daemon: MoneroDaemonRpc = Utils.get_daemon_rpc()
19-
_wallet: MoneroWalletRpc = Utils.get_wallet_rpc()
20+
_wallet: MoneroWalletRpc #= Utils.get_wallet_rpc()
2021
BINARY_BLOCK_CTX: BinaryBlockContext = BinaryBlockContext()
2122

2223
# Can get the daemon's version
23-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
24+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
2425
def test_get_version(self):
2526
version: MoneroVersion = self._daemon.get_version()
2627
assert version.number is not None
2728
Utils.assert_true(version.number > 0)
2829
Utils.assert_not_none(version.is_release)
2930

3031
# Can indicate if it's trusted
31-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
32+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
3233
def test_is_trusted(self):
3334
self._daemon.is_trusted()
3435

3536
# Can get the blockchain height
36-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
37+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
3738
def test_get_height(self):
3839
height = self._daemon.get_height()
3940
Utils.assert_true(height > 0, "Height must be greater than 0")
4041

4142
# Can get a block hash by height
42-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
43+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
4344
def test_get_block_id_by_height(self):
4445
last_header: MoneroBlockHeader = self._daemon.get_last_block_header()
4546
assert last_header.height is not None
@@ -48,19 +49,19 @@ def test_get_block_id_by_height(self):
4849
Utils.assert_equals(64, len(hash_str))
4950

5051
# Can get a block template
51-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
52+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
5253
def test_get_block_template(self):
5354
template: MoneroBlockTemplate = self._daemon.get_block_template(Utils.ADDRESS, 2)
5455
Utils.test_block_template(template)
5556

5657
# Can get the last block's header
57-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
58+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
5859
def test_get_last_block_header(self):
5960
last_header: MoneroBlockHeader = self._daemon.get_last_block_header()
6061
Utils.test_block_header(last_header, True)
6162

6263
# Can get a block header by hash
63-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
64+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
6465
def test_get_block_header_by_hash(self):
6566
# retrieve by hash of last block
6667
last_header: MoneroBlockHeader = self._daemon.get_last_block_header()
@@ -77,7 +78,7 @@ def test_get_block_header_by_hash(self):
7778
Utils.assert_equals(last_header.height - 1, header.height)
7879

7980
# Can get a block header by height
80-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
81+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
8182
def test_get_block_header_by_height(self):
8283
# retrieve by height of last block
8384
last_header: MoneroBlockHeader = self._daemon.get_last_block_header()
@@ -93,7 +94,7 @@ def test_get_block_header_by_height(self):
9394

9495
# Can get block headers by range
9596
# TODO: test start with no end, vice versa, inclusivity
96-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
97+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
9798
def test_get_block_headers_by_range(self):
9899
# determine start and end height based on number of blocks and how many blocks ago
99100
num_blocks = 100
@@ -115,7 +116,7 @@ def test_get_block_headers_by_range(self):
115116
i += 1
116117

117118
# Can get a block by hash
118-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
119+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
119120
def test_get_block_by_hash(self):
120121
# test config
121122
ctx = TestContext()
@@ -141,12 +142,12 @@ def test_get_block_by_hash(self):
141142
Utils.assert_equals(None, block.txs)
142143

143144
# Can get blocks by hash which includes transactions (binary)
144-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
145+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
145146
def test_get_blocks_by_hash_binary(self) -> None:
146147
raise NotImplementedError("Not implemented")
147148

148149
# Can get a block by height
149-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
150+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
150151
def test_get_block_by_height(self):
151152
# config for testing blocks
152153
ctx = TestContext()
@@ -168,7 +169,7 @@ def test_get_block_by_height(self):
168169
Utils.assert_equals(last_header.height - 1, block.height)
169170

170171
# Can get blocks by height which includes transactions (binary)
171-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
172+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
172173
def test_get_blocks_by_height_binary(self):
173174
# set number of blocks to test
174175
num_blocks = 100
@@ -207,7 +208,7 @@ def test_get_blocks_by_height_binary(self):
207208
Utils.assert_true(tx_found, "No transactions found to test")
208209

209210
# Can get transaction pool statistics
210-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
211+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
211212
def test_get_tx_pool_statistics(self):
212213
daemon = self._daemon
213214
wallet = self._wallet
@@ -238,40 +239,40 @@ def test_get_tx_pool_statistics(self):
238239
raise e
239240

240241
# Can get general information
241-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
242+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
242243
def test_get_general_information(self):
243244
info: MoneroDaemonInfo = self._daemon.get_info()
244245
Utils.test_info(info)
245246

246247
# Can get sync information
247-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
248+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
248249
def test_get_sync_information(self):
249250
sync_info: MoneroDaemonSyncInfo = self._daemon.get_sync_info()
250251
Utils.test_sync_info(sync_info)
251252

252253
# Can get hard fork information
253-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
254+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
254255
def test_get_hard_fork_information(self):
255256
hard_fork_info: MoneroHardForkInfo = self._daemon.get_hard_fork_info()
256257
Utils.test_hard_fork_info(hard_fork_info)
257258

258259
# Can get alternative chains
259-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
260+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
260261
def test_get_alternative_chains(self):
261262
alt_chains: list[MoneroAltChain] = self._daemon.get_alt_chains()
262263
for altChain in alt_chains:
263264
Utils.test_alt_chain(altChain)
264265

265266
# Can get alternative block hashes
266-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
267+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
267268
def test_get_alternative_block_ids(self):
268269
alt_block_ids: list[str] = self._daemon.get_alt_block_hashes()
269270
for altBlockId in alt_block_ids:
270271
Utils.assert_not_none(altBlockId)
271272
Utils.assert_equals(64, len(altBlockId)) # TODO: common validation
272273

273274
# Can get, set, and reset a download bandwidth limit
274-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
275+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
275276
def test_set_download_bandwidth(self):
276277
init_val: int = self._daemon.get_download_limit()
277278
Utils.assert_true(init_val > 0)
@@ -291,7 +292,7 @@ def test_set_download_bandwidth(self):
291292
Utils.assert_equals(self._daemon.get_download_limit(), init_val)
292293

293294
# Can get, set, and reset an upload bandwidth limit
294-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
295+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
295296
def test_set_upload_bandwidth(self):
296297
init_val: int = self._daemon.get_upload_limit()
297298
Utils.assert_true(init_val > 0)
@@ -311,37 +312,37 @@ def test_set_upload_bandwidth(self):
311312
Utils.assert_equals(init_val, self._daemon.get_upload_limit())
312313

313314
# Can get peers with active incoming or outgoing connections
314-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
315+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
315316
def test_get_peers(self):
316317
peers: list[MoneroPeer] = self._daemon.get_peers()
317318
Utils.assert_false(len(peers) == 0, "Daemon has no incoming or outgoing peers to test")
318319
for peer in peers:
319320
Utils.test_peer(peer)
320321

321322
# Can get all known peers which may be online or offline
322-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
323+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
323324
def test_get_known_peers(self):
324325
peers: list[MoneroPeer] = self._daemon.get_known_peers()
325326
Utils.assert_false(len(peers) == 0, "Daemon has no known peers to test")
326327
for peer in peers:
327328
Utils.test_known_peer(peer, False)
328329

329330
# Can limit the number of outgoing peers
330-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
331+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
331332
def test_set_outgoing_peer_limit(self):
332333
self._daemon.set_outgoing_peer_limit(0)
333334
self._daemon.set_outgoing_peer_limit(8)
334335
self._daemon.set_outgoing_peer_limit(10)
335336

336337
# Can limit the number of incoming peers
337-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
338+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
338339
def test_set_incoming_peer_limit(self):
339340
self._daemon.set_incoming_peer_limit(0)
340341
self._daemon.set_incoming_peer_limit(8)
341342
self._daemon.set_incoming_peer_limit(10)
342343

343344
# Can notify listeners when a new block is added to the chain
344-
@pytest.mark.skipif(Utils.LITE_MODE is True or Utils.TEST_NOTIFICATIONS is False)
345+
@pytest.mark.skipif(Utils.LITE_MODE is True or Utils.TEST_NOTIFICATIONS is False, reason="TEST_NOTIFICATIONS disabled")
345346
def test_block_listener(self):
346347
try:
347348
# start mining if possible to help push the network along
@@ -372,7 +373,7 @@ def test_block_listener(self):
372373
print(f"[!]: {str(e)}")
373374

374375
# Can start and stop mining
375-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
376+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
376377
def test_mining(self):
377378
# stop mining at beginning of test
378379
try:
@@ -390,7 +391,7 @@ def test_mining(self):
390391
self._daemon.stop_mining()
391392

392393
# Can get mining status
393-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
394+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
394395
def test_get_mining_status(self):
395396
try:
396397
# stop mining at beginning of test
@@ -429,7 +430,7 @@ def test_get_mining_status(self):
429430
print(f"[!]: {str(e)}")
430431

431432
# Can submit a mined block to the network
432-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
433+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
433434
def test_submit_mined_block(self):
434435
# get template to mine on
435436
template: MoneroBlockTemplate = self._daemon.get_block_template(Utils.ADDRESS)
@@ -446,7 +447,7 @@ def test_submit_mined_block(self):
446447
Utils.assert_equals("Block not accepted", str(e))
447448

448449
# Can prune the blockchain
449-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
450+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
450451
def test_prune_blockchain(self):
451452
result: MoneroPruneResult = self._daemon.prune_blockchain(True)
452453

@@ -457,13 +458,13 @@ def test_prune_blockchain(self):
457458
Utils.assert_equals(0, result.pruning_seed)
458459

459460
# Can check for an update
460-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
461+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
461462
def test_check_for_update(self):
462463
result: MoneroDaemonUpdateCheckResult = self._daemon.check_for_update()
463464
Utils.test_update_check_result(result)
464465

465466
# Can download an update
466-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
467+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
467468
def test_download_update(self):
468469
# download to default path
469470
result: MoneroDaemonUpdateDownloadResult = self._daemon.download_update()
@@ -484,7 +485,7 @@ def test_download_update(self):
484485
# Utils.assert_equals(500, (int) e.getCode()) # TODO monerod: this causes a 500 in daemon rpc
485486

486487
# Can be stopped
487-
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, "TEST_NON_RELAYS disabled")
488+
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
488489
@pytest.mark.skip(reason="test is disabled to not interfere with other tests")
489490
def test_stop(self):
490491
# stop the daemon

0 commit comments

Comments
 (0)