Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ jobs:
- name: Install monero-python
run: |
mkdir -p build
export CFLAGS="--coverage -O0 -g"
export CXXFLAGS="--coverage -O0 -g"
export CFLAGS="--coverage -fprofile-update=atomic -O0 -g"
export CXXFLAGS="--coverage -fprofile-update=atomic -O0 -g"
export LDFLAGS="--coverage"
COVERAGE=1 pip3 install -vvv .

Expand Down
2 changes: 1 addition & 1 deletion tests/test_monero_wallet_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def after_each(self, request: pytest.FixtureRequest) -> None:

# Validates inputs when sending funds
@pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled")
@pytest.mark.flaky(reruns=5, reruns_delay=5)
def test_validate_inputs_sending_funds(self, wallet: MoneroWallet) -> None:
# try sending with invalid address
try:
Expand Down Expand Up @@ -3501,7 +3502,6 @@ def test_stop_listening(self) -> None:
# Can be created and receive funds
# TODO this test is flaky on monero-wallet-rpc because of mining speed
@pytest.mark.skipif(TestUtils.TEST_NOTIFICATIONS is False, reason="TEST_NOTIFICATIONS disabled")
#@pytest.mark.flaky(reruns=5, reruns_delay=5)
def test_create_and_receive(self, daemon: MoneroDaemonRpc, wallet: MoneroWallet) -> None:
# create random wallet
receiver: MoneroWallet = self._create_wallet(MoneroWalletConfig())
Expand Down
23 changes: 14 additions & 9 deletions tests/utils/blockchain_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def wait_for_height(cls, height: int) -> int:
:returns int: blockchain height
"""
daemon = MiningUtils.get_daemon()
current_height = daemon.get_height()
current_height: int = daemon.get_height()
if height <= current_height:
return current_height

Expand Down Expand Up @@ -94,30 +94,35 @@ def wait_until_blockchain_ready(cls) -> int:

:returns int: blockchain height.
"""
height = cls.wait_for_height(Utils.MIN_BLOCK_HEIGHT)
height: int = cls.wait_for_height(Utils.MIN_BLOCK_HEIGHT)
MiningUtils.try_stop_mining()
return height

@classmethod
def wait_for_blocks(cls, num_blocks: int) -> None:
def wait_for_blocks(cls, num_blocks: int) -> int:
"""
Start mining and wait for blocks.

:param int num_blocks: number of blocks to wait.
:returns int: blockchain height.
"""
if num_blocks <= 0:
return
height = cls.get_height()
cls.wait_for_height(height + num_blocks)
if num_blocks < 0:
raise TypeError(f"Invalid number of blocks to wait for: {num_blocks}")
height: int = cls.get_height()
return cls.wait_for_height(height + num_blocks)

@classmethod
def setup_blockchain(cls, network_type: MoneroNetworkType) -> None:
"""Setup blockchain for integration tests"""
"""
Setup blockchain for integration tests

:param MoneroNetworkType network_type: blockchain network type to setup.
"""
if cls.blockchain_is_ready():
logger.debug("Already setup blockchain")
return

cls.wait_until_blockchain_ready()
spammer = TxSpammer(network_type)
spammer: TxSpammer = TxSpammer(network_type)
spammer.spam()
cls.wait_for_blocks(11)
15 changes: 13 additions & 2 deletions tests/utils/integration_test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from abc import ABC

from time import sleep
from monero import MoneroWallet, MoneroTxWallet, MoneroTxQuery

from .wallet_utils import WalletUtils
Expand Down Expand Up @@ -68,7 +68,14 @@ def fund_wallet_and_wait_for_unlocked(cls, wallet: MoneroWallet) -> list[MoneroT
txs: list[MoneroTxWallet] = WalletUtils.fund_wallet(wallet)
if len(txs) > 0:
# mine blocks to confirm txs
BlockchainUtils.wait_for_blocks(11)
block_height: int = BlockchainUtils.wait_for_blocks(11)

# sync wallet
while wallet.get_height() < block_height:
wallet.sync()
sleep(TestUtils.SYNC_PERIOD_IN_MS / 1000)

# check for txs
query: MoneroTxQuery = MoneroTxQuery()
for tx in txs:
assert tx.hash is not None
Expand All @@ -79,4 +86,8 @@ def fund_wallet_and_wait_for_unlocked(cls, wallet: MoneroWallet) -> list[MoneroT

assert len(txs) == num_txs

# assert txs are unlocked
for tx in txs:
assert tx.is_locked is False

return txs
Loading