mirror of https://github.com/nucypher/nucypher.git
Add mock_async_hooks fixture for use in tests that mimic the use of async txs.
parent
c5adbfde98
commit
550c59ccb1
|
@ -112,7 +112,9 @@ def test_initiate_ritual(
|
||||||
|
|
||||||
|
|
||||||
@pytest_twisted.inlineCallbacks
|
@pytest_twisted.inlineCallbacks
|
||||||
def test_post_transcript(agent, transcripts, transacting_powers, testerchain, clock):
|
def test_post_transcript(
|
||||||
|
agent, transcripts, transacting_powers, testerchain, clock, mock_async_hooks
|
||||||
|
):
|
||||||
ritual_id = agent.number_of_rituals() - 1
|
ritual_id = agent.number_of_rituals() - 1
|
||||||
|
|
||||||
txs = []
|
txs = []
|
||||||
|
@ -121,6 +123,7 @@ def test_post_transcript(agent, transcripts, transacting_powers, testerchain, cl
|
||||||
ritual_id=ritual_id,
|
ritual_id=ritual_id,
|
||||||
transcript=transcripts[i],
|
transcript=transcripts[i],
|
||||||
transacting_power=transacting_power,
|
transacting_power=transacting_power,
|
||||||
|
async_tx_hooks=mock_async_hooks,
|
||||||
)
|
)
|
||||||
txs.append(async_tx)
|
txs.append(async_tx)
|
||||||
|
|
||||||
|
@ -159,6 +162,7 @@ def test_post_aggregation(
|
||||||
cohort,
|
cohort,
|
||||||
testerchain,
|
testerchain,
|
||||||
clock,
|
clock,
|
||||||
|
mock_async_hooks,
|
||||||
):
|
):
|
||||||
testerchain.tx_machine.start()
|
testerchain.tx_machine.start()
|
||||||
ritual_id = agent.number_of_rituals() - 1
|
ritual_id = agent.number_of_rituals() - 1
|
||||||
|
@ -173,6 +177,7 @@ def test_post_aggregation(
|
||||||
public_key=dkg_public_key,
|
public_key=dkg_public_key,
|
||||||
participant_public_key=participant_public_key,
|
participant_public_key=participant_public_key,
|
||||||
transacting_power=transacting_power,
|
transacting_power=transacting_power,
|
||||||
|
async_tx_hooks=mock_async_hooks,
|
||||||
)
|
)
|
||||||
txs.append(async_tx)
|
txs.append(async_tx)
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,12 @@ import json
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
from unittest.mock import PropertyMock
|
from unittest.mock import PropertyMock
|
||||||
|
|
||||||
import atxm
|
|
||||||
import maya
|
import maya
|
||||||
import pytest
|
import pytest
|
||||||
from click.testing import CliRunner
|
from click.testing import CliRunner
|
||||||
|
@ -22,7 +20,10 @@ from web3 import Web3
|
||||||
|
|
||||||
import tests
|
import tests
|
||||||
from nucypher.blockchain.eth.actors import Operator
|
from nucypher.blockchain.eth.actors import Operator
|
||||||
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
|
from nucypher.blockchain.eth.interfaces import (
|
||||||
|
BlockchainInterface,
|
||||||
|
BlockchainInterfaceFactory,
|
||||||
|
)
|
||||||
from nucypher.blockchain.eth.signers.software import KeystoreSigner
|
from nucypher.blockchain.eth.signers.software import KeystoreSigner
|
||||||
from nucypher.characters.lawful import Enrico, Ursula
|
from nucypher.characters.lawful import Enrico, Ursula
|
||||||
from nucypher.config.characters import (
|
from nucypher.config.characters import (
|
||||||
|
@ -783,12 +784,14 @@ def mock_operator_aggregation_delay(module_mocker):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session", autouse=True)
|
@pytest.fixture
|
||||||
def mock_default_tracker_cache(session_mocker):
|
def mock_async_hooks(mocker):
|
||||||
mock = session_mocker.patch.object(
|
hooks = BlockchainInterface.AsyncTxHooks(
|
||||||
atxm.state._State,
|
on_broadcast=mocker.Mock(),
|
||||||
"_FILEPATH",
|
on_broadcast_failure=mocker.Mock(),
|
||||||
new_callable=session_mocker.PropertyMock,
|
on_fault=mocker.Mock(),
|
||||||
|
on_finalized=mocker.Mock(),
|
||||||
|
on_insufficient_funds=mocker.Mock(),
|
||||||
)
|
)
|
||||||
mock.return_value = Path(tempfile.gettempdir()) / f".test-txs-{time.time()}.json"
|
|
||||||
return mock
|
return hooks
|
||||||
|
|
|
@ -67,7 +67,7 @@ def test_mock_coordinator_initiation(
|
||||||
|
|
||||||
|
|
||||||
def test_mock_coordinator_round_1(
|
def test_mock_coordinator_round_1(
|
||||||
nodes_transacting_powers, coordinator, random_transcript
|
nodes_transacting_powers, coordinator, random_transcript, mock_async_hooks
|
||||||
):
|
):
|
||||||
ritual = coordinator._rituals[0]
|
ritual = coordinator._rituals[0]
|
||||||
assert (
|
assert (
|
||||||
|
@ -84,7 +84,8 @@ def test_mock_coordinator_round_1(
|
||||||
coordinator.post_transcript(
|
coordinator.post_transcript(
|
||||||
ritual_id=0,
|
ritual_id=0,
|
||||||
transcript=transcript,
|
transcript=transcript,
|
||||||
transacting_power=nodes_transacting_powers[node_address]
|
transacting_power=nodes_transacting_powers[node_address],
|
||||||
|
async_tx_hooks=mock_async_hooks,
|
||||||
)
|
)
|
||||||
|
|
||||||
performance = ritual.participants[index]
|
performance = ritual.participants[index]
|
||||||
|
@ -105,6 +106,7 @@ def test_mock_coordinator_round_2(
|
||||||
aggregated_transcript,
|
aggregated_transcript,
|
||||||
dkg_public_key,
|
dkg_public_key,
|
||||||
random_transcript,
|
random_transcript,
|
||||||
|
mock_async_hooks,
|
||||||
):
|
):
|
||||||
ritual = coordinator._rituals[0]
|
ritual = coordinator._rituals[0]
|
||||||
assert (
|
assert (
|
||||||
|
@ -123,7 +125,8 @@ def test_mock_coordinator_round_2(
|
||||||
aggregated_transcript=aggregated_transcript,
|
aggregated_transcript=aggregated_transcript,
|
||||||
public_key=dkg_public_key,
|
public_key=dkg_public_key,
|
||||||
participant_public_key=participant_public_key,
|
participant_public_key=participant_public_key,
|
||||||
transacting_power=nodes_transacting_powers[node_address]
|
transacting_power=nodes_transacting_powers[node_address],
|
||||||
|
async_tx_hooks=mock_async_hooks,
|
||||||
)
|
)
|
||||||
participant_public_keys.append(participant_public_key)
|
participant_public_keys.append(participant_public_key)
|
||||||
if index == len(nodes_transacting_powers) - 1:
|
if index == len(nodes_transacting_powers) - 1:
|
||||||
|
|
Loading…
Reference in New Issue