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
|
||||
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
|
||||
|
||||
txs = []
|
||||
|
@ -121,6 +123,7 @@ def test_post_transcript(agent, transcripts, transacting_powers, testerchain, cl
|
|||
ritual_id=ritual_id,
|
||||
transcript=transcripts[i],
|
||||
transacting_power=transacting_power,
|
||||
async_tx_hooks=mock_async_hooks,
|
||||
)
|
||||
txs.append(async_tx)
|
||||
|
||||
|
@ -159,6 +162,7 @@ def test_post_aggregation(
|
|||
cohort,
|
||||
testerchain,
|
||||
clock,
|
||||
mock_async_hooks,
|
||||
):
|
||||
testerchain.tx_machine.start()
|
||||
ritual_id = agent.number_of_rituals() - 1
|
||||
|
@ -173,6 +177,7 @@ def test_post_aggregation(
|
|||
public_key=dkg_public_key,
|
||||
participant_public_key=participant_public_key,
|
||||
transacting_power=transacting_power,
|
||||
async_tx_hooks=mock_async_hooks,
|
||||
)
|
||||
txs.append(async_tx)
|
||||
|
||||
|
|
|
@ -3,14 +3,12 @@ import json
|
|||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import time
|
||||
from datetime import timedelta
|
||||
from functools import partial
|
||||
from pathlib import Path
|
||||
from typing import Tuple
|
||||
from unittest.mock import PropertyMock
|
||||
|
||||
import atxm
|
||||
import maya
|
||||
import pytest
|
||||
from click.testing import CliRunner
|
||||
|
@ -22,7 +20,10 @@ from web3 import Web3
|
|||
|
||||
import tests
|
||||
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.characters.lawful import Enrico, Ursula
|
||||
from nucypher.config.characters import (
|
||||
|
@ -783,12 +784,14 @@ def mock_operator_aggregation_delay(module_mocker):
|
|||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def mock_default_tracker_cache(session_mocker):
|
||||
mock = session_mocker.patch.object(
|
||||
atxm.state._State,
|
||||
"_FILEPATH",
|
||||
new_callable=session_mocker.PropertyMock,
|
||||
@pytest.fixture
|
||||
def mock_async_hooks(mocker):
|
||||
hooks = BlockchainInterface.AsyncTxHooks(
|
||||
on_broadcast=mocker.Mock(),
|
||||
on_broadcast_failure=mocker.Mock(),
|
||||
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(
|
||||
nodes_transacting_powers, coordinator, random_transcript
|
||||
nodes_transacting_powers, coordinator, random_transcript, mock_async_hooks
|
||||
):
|
||||
ritual = coordinator._rituals[0]
|
||||
assert (
|
||||
|
@ -84,7 +84,8 @@ def test_mock_coordinator_round_1(
|
|||
coordinator.post_transcript(
|
||||
ritual_id=0,
|
||||
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]
|
||||
|
@ -105,6 +106,7 @@ def test_mock_coordinator_round_2(
|
|||
aggregated_transcript,
|
||||
dkg_public_key,
|
||||
random_transcript,
|
||||
mock_async_hooks,
|
||||
):
|
||||
ritual = coordinator._rituals[0]
|
||||
assert (
|
||||
|
@ -123,7 +125,8 @@ def test_mock_coordinator_round_2(
|
|||
aggregated_transcript=aggregated_transcript,
|
||||
public_key=dkg_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)
|
||||
if index == len(nodes_transacting_powers) - 1:
|
||||
|
|
Loading…
Reference in New Issue