mirror of https://github.com/nucypher/nucypher.git
Vladimir needs ETH to set provider public key for tests.
Cleanup Vladimir code to not depend on test.contants.pull/3213/head
parent
22dee9b3b8
commit
f925bc423e
|
@ -11,7 +11,6 @@ from nucypher.config.constants import TEMPORARY_DOMAIN
|
|||
from nucypher.crypto.powers import CryptoPower
|
||||
from nucypher.exceptions import DevelopmentInstallationRequired
|
||||
from nucypher.policy.payment import FreeReencryptions
|
||||
from tests.constants import TEST_ETH_PROVIDER_URI, TESTERCHAIN_CHAIN_ID
|
||||
|
||||
|
||||
class Vladimir(Ursula):
|
||||
|
@ -40,12 +39,16 @@ class Vladimir(Ursula):
|
|||
try:
|
||||
from tests.utils.middleware import EvilMiddleWare
|
||||
except ImportError:
|
||||
raise DevelopmentInstallationRequired(importable_name='tests.utils.middleware.EvilMiddleWare')
|
||||
cls.network_middleware = EvilMiddleWare(eth_provider_uri=TEST_ETH_PROVIDER_URI)
|
||||
raise DevelopmentInstallationRequired(
|
||||
importable_name="tests.utils.middleware.EvilMiddleWare"
|
||||
)
|
||||
blockchain = target_ursula.application_agent.blockchain
|
||||
cls.network_middleware = EvilMiddleWare(
|
||||
eth_provider_uri=blockchain.eth_provider_uri
|
||||
)
|
||||
|
||||
crypto_power = CryptoPower(power_ups=target_ursula._default_crypto_powerups)
|
||||
|
||||
blockchain = target_ursula.application_agent.blockchain
|
||||
cls.attach_transacting_key(blockchain=blockchain)
|
||||
|
||||
# Vladimir does not care about payment.
|
||||
|
@ -53,10 +56,12 @@ class Vladimir(Ursula):
|
|||
bogus_payment_method.provider = Mock()
|
||||
bogus_payment_method.agent = Mock()
|
||||
bogus_payment_method.network = TEMPORARY_DOMAIN
|
||||
bogus_payment_method.agent.blockchain.client.chain_id = TESTERCHAIN_CHAIN_ID
|
||||
bogus_payment_method.agent.blockchain.client.chain_id = (
|
||||
blockchain.client.chain_id
|
||||
)
|
||||
mock.patch(
|
||||
"mock.interfaces.MockBlockchain.client.chain_id",
|
||||
new_callable=mock.PropertyMock(return_value=TESTERCHAIN_CHAIN_ID),
|
||||
new_callable=mock.PropertyMock(return_value=blockchain.client.chain_id),
|
||||
)
|
||||
|
||||
vladimir = cls(is_me=True,
|
||||
|
|
|
@ -3,6 +3,7 @@ import datetime
|
|||
import maya
|
||||
import pytest
|
||||
from eth_account._utils.signing import to_standard_signature_bytes
|
||||
from web3 import Web3
|
||||
|
||||
from nucypher.characters.lawful import Enrico, Ursula
|
||||
from nucypher.characters.unlawful import Vladimir
|
||||
|
@ -12,6 +13,18 @@ from tests.constants import MOCK_ETH_PROVIDER_URI, TEST_ETH_PROVIDER_URI
|
|||
from tests.utils.middleware import NodeIsDownMiddleware
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vladimir_needs_eth(testerchain):
|
||||
# transfer some ETH to Vladimir who needs it to set provider public key
|
||||
tx = {
|
||||
"to": Vladimir.fraud_address,
|
||||
"from": testerchain.etherbase_account,
|
||||
"value": Web3.to_wei("1", "ether"),
|
||||
}
|
||||
txhash = testerchain.w3.eth.send_transaction(tx)
|
||||
_ = testerchain.wait_for_receipt(txhash)
|
||||
|
||||
|
||||
def test_stakers_bond_to_ursulas(ursulas, test_registry, staking_providers):
|
||||
assert len(ursulas) == len(staking_providers)
|
||||
for ursula in ursulas:
|
||||
|
@ -48,7 +61,10 @@ def remote_vladimir(**kwds):
|
|||
return remote_vladimir
|
||||
|
||||
|
||||
def test_vladimir_cannot_verify_interface_with_ursulas_signing_key(ursulas, test_registry_source_manager):
|
||||
@pytest.mark.usefixtures("vladimir_needs_eth")
|
||||
def test_vladimir_cannot_verify_interface_with_ursulas_signing_key(
|
||||
testerchain, ursulas, test_registry_source_manager
|
||||
):
|
||||
his_target = list(ursulas)[4]
|
||||
|
||||
# Vladimir has his own ether address; he hopes to publish it along with Ursula's details
|
||||
|
@ -73,6 +89,7 @@ def test_vladimir_cannot_verify_interface_with_ursulas_signing_key(ursulas, test
|
|||
vladimir.validate_metadata()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("vladimir_needs_eth")
|
||||
def test_vladimir_uses_his_own_signing_key(alice, ursulas, test_registry):
|
||||
"""
|
||||
Similar to the attack above, but this time Vladimir makes his own interface signature
|
||||
|
@ -108,6 +125,7 @@ def test_vladimir_uses_his_own_signing_key(alice, ursulas, test_registry):
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("vladimir_needs_eth")
|
||||
def test_vladimir_invalidity_without_stake(testerchain, ursulas, alice):
|
||||
his_target = list(ursulas)[4]
|
||||
|
||||
|
|
Loading…
Reference in New Issue