diff --git a/nucypher/blockchain/eth/actors.py b/nucypher/blockchain/eth/actors.py index 56152bcff..845b46295 100644 --- a/nucypher/blockchain/eth/actors.py +++ b/nucypher/blockchain/eth/actors.py @@ -26,7 +26,6 @@ import maya from constant_sorrow.constants import ( CONTRACT_NOT_DEPLOYED, NO_DEPLOYER_ADDRESS, - NO_STAKING_DEVICE, WORKER_NOT_RUNNING ) from eth_tester.exceptions import TransactionFailed @@ -141,7 +140,6 @@ class Deployer(NucypherTokenActor): def __init__(self, blockchain: BlockchainInterface, deployer_address: str = None, - device = NO_STAKING_DEVICE, client_password: str = None, bare: bool = True ) -> None: @@ -162,8 +160,7 @@ class Deployer(NucypherTokenActor): blockchain.transacting_power = TransactingPower(blockchain=blockchain, account=deployer_address, - password=client_password, - device=device) + password=client_password) blockchain.transacting_power.activate() self.log = Logger("Deployment-Actor") diff --git a/nucypher/characters/base.py b/nucypher/characters/base.py index 05ab64b78..137076acf 100644 --- a/nucypher/characters/base.py +++ b/nucypher/characters/base.py @@ -80,6 +80,7 @@ class Character(Learner): keyring_root: str = None, crypto_power: CryptoPower = None, crypto_power_ups: List[CryptoPowerUp] = None, + additional_powers: List[CryptoPower] = None, *args, **kwargs ) -> None: diff --git a/nucypher/characters/lawful.py b/nucypher/characters/lawful.py index 01ddafe76..97702fcde 100644 --- a/nucypher/characters/lawful.py +++ b/nucypher/characters/lawful.py @@ -28,8 +28,7 @@ import requests from bytestring_splitter import BytestringKwargifier, BytestringSplittingError from bytestring_splitter import BytestringSplitter, VariableLengthBytestring from constant_sorrow import constants -from constant_sorrow.constants import INCLUDED_IN_BYTESTRING, PUBLIC_ONLY, FEDERATED_POLICY, STRANGER_ALICE, \ - NO_STAKING_DEVICE +from constant_sorrow.constants import INCLUDED_IN_BYTESTRING, PUBLIC_ONLY, FEDERATED_POLICY, STRANGER_ALICE from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurve from cryptography.hazmat.primitives.serialization import Encoding @@ -90,7 +89,6 @@ class Alice(Character, PolicyAuthor): network_middleware=None, controller=True, policy_agent=None, - device = NO_STAKING_DEVICE, client_password: str = None, *args, **kwargs) -> None: @@ -122,9 +120,9 @@ class Alice(Character, PolicyAuthor): if is_me and not federated_only: # TODO: #289 transacting_power = TransactingPower(account=self.checksum_address, - device=device, + password=client_password, blockchain=self.blockchain) - self._crypto_power.consume_power_up(transacting_power, password=client_password) + self._crypto_power.consume_power_up(transacting_power) PolicyAuthor.__init__(self, blockchain=self.blockchain, @@ -844,8 +842,6 @@ class Ursula(Teacher, Character, Worker): checksum_address: str = None, # Staker address worker_address: str = None, stake_tracker: StakeTracker = None, - staking_agent: StakingEscrowAgent = None, - device = NO_STAKING_DEVICE, client_password: str = None, # Character @@ -895,8 +891,10 @@ class Ursula(Teacher, Character, Worker): if not federated_only: # Access staking node via node's transacting keys - transacting_power = TransactingPower(account=worker_address, device=device, blockchain=self.blockchain) - self._crypto_power.consume_power_up(transacting_power, client_password) + transacting_power = TransactingPower(account=worker_address, + password=client_password, + blockchain=self.blockchain) + self._crypto_power.consume_power_up(transacting_power) # Use blockchain power to substantiate stamp self.substantiate_stamp(client_password=password) diff --git a/nucypher/cli/characters/alice.py b/nucypher/cli/characters/alice.py index 4be466777..c8685f827 100644 --- a/nucypher/cli/characters/alice.py +++ b/nucypher/cli/characters/alice.py @@ -1,12 +1,15 @@ import click from constant_sorrow.constants import NO_BLOCKCHAIN_CONNECTION +from nucypher.blockchain.eth.interfaces import BlockchainInterface +from nucypher.blockchain.eth.registry import EthereumContractRegistry from nucypher.characters.banners import ALICE_BANNER from nucypher.cli import actions, painting, types from nucypher.cli.actions import get_password from nucypher.cli.config import nucypher_click_config from nucypher.cli.types import NETWORK_PORT, EXISTING_READABLE_FILE, EIP55_CHECKSUM_ADDRESS from nucypher.config.characters import AliceConfiguration +from nucypher.crypto.powers import TransactingPower @click.command() @@ -24,6 +27,7 @@ from nucypher.config.characters import AliceConfiguration @click.option('--config-file', help="Path to configuration file", type=EXISTING_READABLE_FILE) @click.option('--provider-uri', help="Blockchain provider's URI", type=click.STRING) @click.option('--sync/--no-sync', default=True) +@click.option('--device/--no-device', default=False) @click.option('--geth', '-G', help="Run using the built-in geth node", is_flag=True) @click.option('--poa', help="Inject POA middleware", is_flag=True, default=None) @click.option('--no-registry', help="Skip importing the default contract registry", is_flag=True) @@ -68,6 +72,7 @@ def alice(click_config, poa, no_registry, registry_filepath, + device, # Alice bob_encrypting_key, @@ -79,7 +84,7 @@ def alice(click_config, rate, duration, expiration, - message_kit + message_kit, ): @@ -168,7 +173,7 @@ def alice(click_config, except FileNotFoundError: return actions.handle_missing_configuration_file(character_config_class=AliceConfiguration, config_file=config_file) - + ALICE = actions.make_cli_character(character_config=alice_config, click_config=click_config, dev=dev, diff --git a/nucypher/cli/characters/felix.py b/nucypher/cli/characters/felix.py index 9c6127248..3f9eadd44 100644 --- a/nucypher/cli/characters/felix.py +++ b/nucypher/cli/characters/felix.py @@ -11,6 +11,7 @@ from nucypher.cli.config import nucypher_click_config from nucypher.cli.types import NETWORK_PORT, EXISTING_READABLE_FILE, EIP55_CHECKSUM_ADDRESS from nucypher.config.characters import FelixConfiguration from nucypher.config.constants import DEFAULT_CONFIG_ROOT +from nucypher.crypto.powers import TransactingPower @click.command() @@ -118,6 +119,11 @@ def felix(click_config, f"Check the filepath or run 'nucypher felix init' to create a new system configuration.") raise click.Abort + transacting_power = TransactingPower(account=felix_config.checksum_address, + device=False, + password=get_password(confirm=False), + blockchain=felix_config.blockchain) + try: # Connect to Blockchain @@ -134,7 +140,9 @@ def felix(click_config, network_middleware=click_config.middleware) # Produce Felix - FELIX = felix_config.produce(domains=network, known_nodes=teacher_nodes) + FELIX = felix_config.produce(domains=network, + known_nodes=teacher_nodes, + additional_power=[transacting_power]) FELIX.make_web_app() # attach web application, but dont start service except Exception as e: diff --git a/nucypher/cli/characters/ursula.py b/nucypher/cli/characters/ursula.py index d574d74f3..81388e92e 100644 --- a/nucypher/cli/characters/ursula.py +++ b/nucypher/cli/characters/ursula.py @@ -18,16 +18,13 @@ along with nucypher. If not, see . import click -import socket - from constant_sorrow.constants import NO_BLOCKCHAIN_CONNECTION from twisted.internet import stdio -from nucypher.blockchain.eth.clients import NuCypherGethDevnetProcess, NuCypherGethGoerliProcess from nucypher.blockchain.eth.token import NU from nucypher.characters.banners import URSULA_BANNER from nucypher.cli import actions, painting -from nucypher.cli.actions import UnknownIPAddress, get_password +from nucypher.cli.actions import get_password from nucypher.cli.config import nucypher_click_config from nucypher.cli.processes import UrsulaCommandProtocol from nucypher.cli.types import ( @@ -36,8 +33,7 @@ from nucypher.cli.types import ( EXISTING_READABLE_FILE, STAKE_DURATION, STAKE_EXTENSION, - STAKE_VALUE, - IPV4_ADDRESS) + STAKE_VALUE) from nucypher.config.characters import UrsulaConfiguration from nucypher.utilities.sandbox.constants import ( TEMPORARY_DOMAIN, @@ -66,6 +62,7 @@ from nucypher.utilities.sandbox.constants import ( @click.option('--config-file', help="Path to configuration file", type=EXISTING_READABLE_FILE) @click.option('--poa', help="Inject POA middleware", is_flag=True, default=None) @click.option('--sync/--no-sync', default=True) +@click.option('--device/--no-device', default=False) @click.option('--geth', '-G', help="Run using the built-in geth node", is_flag=True) @click.option('--provider-uri', help="Blockchain provider's URI", type=click.STRING) @click.option('--no-registry', help="Skip importing the default contract registry", is_flag=True) @@ -105,6 +102,7 @@ def ursula(click_config, list_, divide, sync, + device, interactive, ) -> None: @@ -244,7 +242,6 @@ def ursula(click_config, raise click.BadOptionUsage(option_name='--dev', message=message) return actions.destroy_configuration(character_config=ursula_config, force=force) - # # Make Ursula # diff --git a/nucypher/cli/deploy.py b/nucypher/cli/deploy.py index 07744eddc..d72fbfe12 100644 --- a/nucypher/cli/deploy.py +++ b/nucypher/cli/deploy.py @@ -19,7 +19,6 @@ import time import click import maya -from constant_sorrow.constants import NO_STAKING_DEVICE from nucypher.blockchain.eth.actors import Deployer from nucypher.blockchain.eth.agents import NucypherTokenAgent @@ -42,6 +41,7 @@ from nucypher.config.constants import DEFAULT_CONFIG_ROOT @click.option('--provider-uri', help="Blockchain provider's URI", type=click.STRING) @click.option('--geth', '-G', help="Run using the built-in geth node", is_flag=True) @click.option('--sync/--no-sync', default=True) +@click.option('--device/--no-device', default=True) @click.option('--enode', help="An ethereum bootnode enode address to start learning from", type=click.STRING) @click.option('--config-root', help="Custom configuration directory", type=click.Path()) @click.option('--contract-name', help="Deploy a single contract by name", type=click.STRING) @@ -70,6 +70,7 @@ def deploy(click_config, recipient_address, config_root, sync, + device, force): """Manage contract and registry deployment""" @@ -100,7 +101,6 @@ def deploy(click_config, if registry_filepath is not None: registry = EthereumContractRegistry(registry_filepath=registry_filepath) - # TODO: Move to Deployer with TransactingPower # Deployment-tuned blockchain connection blockchain = BlockchainDeployerInterface(provider_uri=provider_uri, poa=poa, @@ -124,9 +124,12 @@ def deploy(click_config, if not force: click.confirm("Selected {} - Continue?".format(deployer_address), abort=True) + password = None + if not device: + password = get_password(confirm=False) + deployer = Deployer(blockchain=blockchain, - device=NO_STAKING_DEVICE, - client_password=get_password(confirm=False), + client_password=password, deployer_address=deployer_address) # Verify ETH Balance diff --git a/nucypher/crypto/powers.py b/nucypher/crypto/powers.py index 78d4b972b..e2a9ec71e 100644 --- a/nucypher/crypto/powers.py +++ b/nucypher/crypto/powers.py @@ -19,7 +19,7 @@ along with nucypher. If not, see . import inspect from typing import List, Tuple, Optional -from constant_sorrow.constants import NO_STAKING_DEVICE, NO_BLOCKCHAIN_CONNECTION +from constant_sorrow.constants import NO_BLOCKCHAIN_CONNECTION from cytoolz.dicttoolz import dissoc from eth_account._utils.transactions import assert_valid_fields from hexbytes import HexBytes @@ -116,25 +116,18 @@ class TransactingPower(CryptoPowerUp): def __init__(self, blockchain, account: str, - password: str = None, - device=NO_STAKING_DEVICE): + password: str = None): """ Instantiates a TransactingPower for the given checksum_address. """ - if password and (device is not NO_STAKING_DEVICE): - raise ValueError(f"Cannot create a {self.__class__.__name__} with both a client and an device signer.") - self.blockchain = blockchain - if blockchain.is_connected: self.client = blockchain.client else: self.client = NO_BLOCKCHAIN_CONNECTION self.account = account - self.device = device - - self.__activated = False + self.device = True if not password else False self.__password = password self.__unlocked = False @@ -157,30 +150,22 @@ class TransactingPower(CryptoPowerUp): self.unlock_account(password=password) # Unlock self.blockchain.transacting_power = self # Attach self.__password = None # Discard - self.__activated = True # Remember def lock_account(self): - if self.device is not NO_STAKING_DEVICE: - # TODO: Implement TrustedDevice - _result = self.device.lock() + if self.device: + # TODO: Force Disconnect Devices + pass else: _result = self.client.lock_account(address=self.account) self.__unlocked = False def unlock_account(self, password: str = None): - if self.device is not NO_STAKING_DEVICE: - # TODO: Embed in TrustedDevice - ping = 'PING|PONG' - pong = self.device.client.ping(ping) - if not ping == pong: - raise self.device.NoDeviceDetected + if self.device: unlocked = True - else: if self.client is NO_BLOCKCHAIN_CONNECTION: raise self.NoBlockchainConnection unlocked = self.client.unlock_account(address=self.account, password=password) - self.__unlocked = unlocked def sign_message(self, message: bytes) -> bytes: @@ -189,16 +174,7 @@ class TransactingPower(CryptoPowerUp): """ if not self.is_unlocked: raise self.AccountLocked("Failed to unlock account {}".format(self.account)) - - # Hardware Wallet - if self.device is not NO_STAKING_DEVICE: - # TODO: Use a common message signature type from clients and devices - signature = self.device.sign_message(checksum_address=self.account, message=message) - signature = signature.signature - - # Software Wallet - else: - signature = self.client.sign_message(account=self.account, message=message) + signature = self.client.sign_message(account=self.account, message=message) return signature def sign_transaction(self, unsigned_transaction: dict) -> HexBytes: @@ -219,15 +195,8 @@ class TransactingPower(CryptoPowerUp): except TypeError as e: raise self.InvalidSigningRequest(f"Invalid Transaction: '{str(e)}'") - # HW Signer - if self.device is not NO_STAKING_DEVICE: - # TODO: Use a common tx_sign return type from clients and devices - signed_raw_transaction = self.device.sign_eth_transaction(unsigned_transaction=unsigned_transaction, - checksum_address=self.account) - # Web3 Signer - else: - signed_raw_transaction = self.blockchain.client.sign_transaction(transaction=unsigned_transaction, - account=self.account) + signed_raw_transaction = self.blockchain.client.sign_transaction(transaction=unsigned_transaction, + account=self.account) return signed_raw_transaction diff --git a/nucypher/utilities/sandbox/blockchain.py b/nucypher/utilities/sandbox/blockchain.py index 5d08c3a4a..0353ce0ce 100644 --- a/nucypher/utilities/sandbox/blockchain.py +++ b/nucypher/utilities/sandbox/blockchain.py @@ -213,8 +213,10 @@ class TesterBlockchain(BlockchainDeployerInterface): """For use with metric testing scripts""" testerchain = cls(compiler=SolidityCompiler()) - power = TransactingPower(blockchain=testerchain, account=testerchain.etherbase_account) - power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=testerchain.etherbase_account) + power.activate() testerchain.transacting_power = power origin = testerchain.client.etherbase diff --git a/nucypher/utilities/sandbox/ursula.py b/nucypher/utilities/sandbox/ursula.py index 9cc72f3fb..8e3a102fd 100644 --- a/nucypher/utilities/sandbox/ursula.py +++ b/nucypher/utilities/sandbox/ursula.py @@ -23,11 +23,12 @@ from nucypher.blockchain.eth.interfaces import BlockchainInterface from nucypher.blockchain.eth.token import StakeTracker from nucypher.characters.lawful import Ursula from nucypher.config.characters import UrsulaConfiguration +from nucypher.crypto.powers import TransactingPower from nucypher.utilities.sandbox.constants import ( MOCK_KNOWN_URSULAS_CACHE, MOCK_URSULA_STARTING_PORT, NUMBER_OF_URSULAS_IN_DEVELOPMENT_NETWORK, - MOCK_URSULA_DB_FILEPATH) + MOCK_URSULA_DB_FILEPATH, INSECURE_DEVELOPMENT_PASSWORD) def make_federated_ursulas(ursula_config: UrsulaConfiguration, diff --git a/tests/blockchain/eth/contracts/main/adjudicator/conftest.py b/tests/blockchain/eth/contracts/main/adjudicator/conftest.py index 7f3324f38..500e31df9 100644 --- a/tests/blockchain/eth/contracts/main/adjudicator/conftest.py +++ b/tests/blockchain/eth/contracts/main/adjudicator/conftest.py @@ -22,12 +22,15 @@ from web3.contract import Contract from nucypher.blockchain.eth.deployers import DispatcherDeployer from nucypher.crypto.powers import TransactingPower +from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD @pytest.fixture() def escrow(testerchain): # Mock Powerup consumption (Deployer) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=testerchain.etherbase_account) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=testerchain.etherbase_account) testerchain.transacting_power.activate() escrow, _ = testerchain.deploy_contract('StakingEscrowForAdjudicatorMock') return escrow diff --git a/tests/blockchain/eth/entities/actors/test_deployer.py b/tests/blockchain/eth/entities/actors/test_deployer.py index f8d24f0c9..be412d6d2 100644 --- a/tests/blockchain/eth/entities/actors/test_deployer.py +++ b/tests/blockchain/eth/entities/actors/test_deployer.py @@ -48,8 +48,10 @@ def test_rapid_deployment(token_economics): compiler=compiler) # TODO: #1092 - TransactingPower - blockchain.transacting_power = TransactingPower(blockchain=blockchain, account=blockchain.etherbase_account) - blockchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + blockchain.transacting_power = TransactingPower(blockchain=blockchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=blockchain.etherbase_account) + blockchain.transacting_power.activate() deployer_address = blockchain.etherbase_account deployer = Deployer(blockchain=blockchain, deployer_address=deployer_address) diff --git a/tests/blockchain/eth/entities/actors/test_staker.py b/tests/blockchain/eth/entities/actors/test_staker.py index 3c7b61e0a..b78dc39e0 100644 --- a/tests/blockchain/eth/entities/actors/test_staker.py +++ b/tests/blockchain/eth/entities/actors/test_staker.py @@ -43,8 +43,10 @@ def test_staker_locking_tokens(testerchain, agency, staker, token_economics): token_agent, staking_agent, policy_agent = agency # Mock Powerup consumption (Ursula-Staker) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=staker.checksum_address) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=staker.checksum_address) + testerchain.transacting_power.activate() assert NU(token_economics.minimum_allowed_locked, 'NuNit') < staker.token_balance, "Insufficient staker balance" @@ -108,8 +110,10 @@ def test_staker_collects_staking_reward(testerchain, staker, blockchain_ursulas, assert token_agent.get_balance(staker.checksum_address) == initial_balance # Mock Powerup consumption (Ursula-Worker) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=staker.checksum_address) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=staker.checksum_address) + testerchain.transacting_power.activate() staker.initialize_stake(amount=NU(token_economics.minimum_allowed_locked, 'NuNit'), # Lock the minimum amount of tokens lock_periods=int(token_economics.minimum_locked_periods)) # ... for the fewest number of periods @@ -134,8 +138,10 @@ def test_staker_collects_staking_reward(testerchain, staker, blockchain_ursulas, testerchain.time_travel(periods=2) # Mock Powerup consumption (Ursula-Worker) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=staker.checksum_address) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=staker.checksum_address) + testerchain.transacting_power.activate() # Profit! staker.collect_staking_reward() diff --git a/tests/blockchain/eth/entities/agents/test_adjudicator_agent.py b/tests/blockchain/eth/entities/agents/test_adjudicator_agent.py index 47542bb57..4d4b4d9fa 100644 --- a/tests/blockchain/eth/entities/agents/test_adjudicator_agent.py +++ b/tests/blockchain/eth/entities/agents/test_adjudicator_agent.py @@ -59,7 +59,9 @@ def test_adjudicator_slashes(agency, locked_tokens = token_economics.minimum_allowed_locked * 5 # Mock Powerup consumption (Deployer) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=testerchain.etherbase_account) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=testerchain.etherbase_account) testerchain.transacting_power.activate() # The staker receives an initial amount of tokens @@ -68,7 +70,9 @@ def test_adjudicator_slashes(agency, sender_address=testerchain.etherbase_account) # Mock Powerup consumption (Staker) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=staker_account) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=staker_account) testerchain.transacting_power.activate() # Deposit: The staker deposits tokens in the StakingEscrow contract. @@ -100,7 +104,9 @@ def test_adjudicator_slashes(agency, bobby_old_balance = bobby.token_balance # Mock Powerup consumption (Bob) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=bob_account) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=bob_account) testerchain.transacting_power.activate() adjudicator_agent.evaluate_cfrag(evidence=evidence, sender_address=bob_account) diff --git a/tests/blockchain/eth/entities/agents/test_policy_manager_agent.py b/tests/blockchain/eth/entities/agents/test_policy_manager_agent.py index 5e9c4b9a3..f689e4c4c 100644 --- a/tests/blockchain/eth/entities/agents/test_policy_manager_agent.py +++ b/tests/blockchain/eth/entities/agents/test_policy_manager_agent.py @@ -51,8 +51,10 @@ def test_create_policy(testerchain, agency, token_economics): agent = policy_agent # Mock Powerup consumption - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=testerchain.alice_account) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=testerchain.alice_account) + testerchain.transacting_power.activate() policy_id = os.urandom(16) node_addresses = list(staking_agent.sample(quantity=3, duration=1)) @@ -113,15 +115,19 @@ def test_calculate_refund(testerchain, agency, policy_meta): worker = staking_agent.get_worker_from_staker(staker) # Mock Powerup consumption (Ursula-Worker) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=worker) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=worker) + testerchain.transacting_power.activate() testerchain.time_travel(hours=9) _receipt = staking_agent.confirm_activity(worker_address=worker) # Mock Powerup consumption (Alice) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=testerchain.alice_account) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=testerchain.alice_account) + testerchain.transacting_power.activate() receipt = agent.calculate_refund(policy_id=policy_meta.policy_id, author_address=policy_meta.author) assert receipt['status'] == 1, "Transaction Rejected" @@ -148,8 +154,10 @@ def test_collect_policy_reward(testerchain, agency, policy_meta, token_economics worker = staking_agent.get_worker_from_staker(staker) # Mock Powerup consumption (Ursula-Worker) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=worker) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=worker) + testerchain.transacting_power.activate() old_eth_balance = token_agent.blockchain.client.get_balance(staker) @@ -158,8 +166,10 @@ def test_collect_policy_reward(testerchain, agency, policy_meta, token_economics testerchain.time_travel(periods=1) # Mock Powerup consumption (Ursula-Staker) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=staker) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=staker) + testerchain.transacting_power.activate() receipt = agent.collect_policy_reward(collector_address=staker, staker_address=staker) assert receipt['status'] == 1, "Transaction Rejected" diff --git a/tests/blockchain/eth/entities/agents/test_staking_escrow_agent.py b/tests/blockchain/eth/entities/agents/test_staking_escrow_agent.py index dab2962d8..7091c2b1a 100644 --- a/tests/blockchain/eth/entities/agents/test_staking_escrow_agent.py +++ b/tests/blockchain/eth/entities/agents/test_staking_escrow_agent.py @@ -35,8 +35,10 @@ def test_deposit_tokens(testerchain, agency, token_economics): staker_account = testerchain.unassigned_accounts[0] # Mock Powerup consumption (Deployer) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=testerchain.etherbase_account) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=testerchain.etherbase_account) + testerchain.transacting_power.activate() balance = token_agent.get_balance(address=staker_account) assert balance == 0 @@ -47,8 +49,10 @@ def test_deposit_tokens(testerchain, agency, token_economics): sender_address=testerchain.etherbase_account) # Mock Powerup consumption (Ursula-Staker) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=staker_account) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=staker_account) + testerchain.transacting_power.activate() # # Deposit: The staker deposits tokens in the StakingEscrow contract. @@ -168,8 +172,10 @@ def test_confirm_activity(agency, testerchain): staker_account, worker_account, *other = testerchain.unassigned_accounts # Mock Powerup consumption (Ursula-Worker) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=worker_account) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=worker_account) + testerchain.transacting_power.activate() receipt = staking_agent.confirm_activity(worker_address=worker_account) assert receipt['status'] == 1, "Transaction Rejected" @@ -223,8 +229,10 @@ def test_collect_staking_reward(agency, testerchain): testerchain.time_travel(periods=2) # Mock Powerup consumption (Ursula-Staker) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=staker_account) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=staker_account) + testerchain.transacting_power.activate() # Mint _receipt = staking_agent.mint(staker_address=staker_account) diff --git a/tests/blockchain/eth/entities/agents/test_token_agent.py b/tests/blockchain/eth/entities/agents/test_token_agent.py index dd96ce039..5065e9b76 100644 --- a/tests/blockchain/eth/entities/agents/test_token_agent.py +++ b/tests/blockchain/eth/entities/agents/test_token_agent.py @@ -68,8 +68,10 @@ def test_approve_transfer(agent, token_economics): deployer, someone, *everybody_else = testerchain.client.accounts # Mock Powerup consumption - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=someone) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=someone) + testerchain.transacting_power.activate() # Approve receipt = agent.approve_transfer(amount=token_economics.minimum_allowed_locked, @@ -85,8 +87,10 @@ def test_transfer(agent, token_economics): origin, someone, *everybody_else = testerchain.client.accounts # Mock Powerup consumption (Deployer) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=origin) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=origin) + testerchain.transacting_power.activate() old_balance = agent.get_balance(someone) receipt = agent.transfer(amount=token_economics.minimum_allowed_locked, diff --git a/tests/blockchain/eth/entities/agents/test_user_escrow_agent.py b/tests/blockchain/eth/entities/agents/test_user_escrow_agent.py index f9e983fd7..62b3c496d 100644 --- a/tests/blockchain/eth/entities/agents/test_user_escrow_agent.py +++ b/tests/blockchain/eth/entities/agents/test_user_escrow_agent.py @@ -57,8 +57,10 @@ def agent(testerchain, proxy_deployer, allocation_value) -> UserEscrowAgent: deployer_address, beneficiary_address, *everybody_else = testerchain.client.accounts # Mock Powerup consumption (Deployer) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=deployer_address) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=deployer_address) + testerchain.transacting_power.activate() # Escrow escrow_deployer = UserEscrowDeployer(deployer_address=deployer_address, @@ -143,8 +145,10 @@ def test_deposit_and_withdraw_as_staker(testerchain, agent, agency, allocation_v assert token_agent.get_balance(address=agent.contract_address) == allocation_value # Mock Powerup consumption (Beneficiary) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=agent.beneficiary) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=agent.beneficiary) + testerchain.transacting_power.activate() # Move the tokens to the StakingEscrow receipt = agent.deposit_as_staker(value=token_economics.minimum_allowed_locked, periods=token_economics.minimum_locked_periods) @@ -162,8 +166,10 @@ def test_deposit_and_withdraw_as_staker(testerchain, agent, agency, allocation_v assert staking_agent.get_locked_tokens(staker_address=agent.contract_address, periods=token_economics.minimum_locked_periods+1) == 0 # Mock Powerup consumption (Beneficiary-Worker) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=worker) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=worker) + testerchain.transacting_power.activate() for _ in range(token_economics.minimum_locked_periods): staking_agent.confirm_activity(worker_address=worker) @@ -171,8 +177,10 @@ def test_deposit_and_withdraw_as_staker(testerchain, agent, agency, allocation_v testerchain.time_travel(periods=1) # Mock Powerup consumption (Beneficiary) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=agent.beneficiary) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=agent.beneficiary) + testerchain.transacting_power.activate() agent.mint() @@ -195,8 +203,10 @@ def test_collect_policy_reward(testerchain, agent, agency, token_economics): deployer_address, beneficiary_address, author, ursula, *everybody_else = testerchain.client.accounts # Mock Powerup consumption (Beneficiary) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=agent.beneficiary) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=agent.beneficiary) + testerchain.transacting_power.activate() _txhash = agent.deposit_as_staker(value=token_economics.minimum_allowed_locked, periods=token_economics.minimum_locked_periods) @@ -207,8 +217,10 @@ def test_collect_policy_reward(testerchain, agent, agency, token_economics): testerchain.time_travel(periods=1) # Mock Powerup consumption (Alice) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=author) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=author) + testerchain.transacting_power.activate() _txhash = policy_agent.create_policy(policy_id=os.urandom(16), author_address=author, @@ -218,8 +230,10 @@ def test_collect_policy_reward(testerchain, agent, agency, token_economics): node_addresses=[agent.contract_address]) # Mock Powerup consumption (Beneficiary-Worker) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=worker) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=worker) + testerchain.transacting_power.activate() _txhash = staking_agent.confirm_activity(worker_address=worker) testerchain.time_travel(periods=2) @@ -228,8 +242,10 @@ def test_collect_policy_reward(testerchain, agent, agency, token_economics): old_balance = testerchain.client.get_balance(account=agent.beneficiary) # Mock Powerup consumption (Beneficiary) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=agent.beneficiary) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=agent.beneficiary) + testerchain.transacting_power.activate() txhash = agent.collect_policy_reward() assert txhash # TODO @@ -241,8 +257,10 @@ def test_withdraw_tokens(testerchain, agent, agency, allocation_value): deployer_address, beneficiary_address, *everybody_else = testerchain.client.accounts # Mock Powerup consumption (Beneficiary) - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=agent.beneficiary) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=agent.beneficiary) + testerchain.transacting_power.activate() assert token_agent.get_balance(address=agent.contract_address) == agent.unvested_tokens with pytest.raises((TransactionFailed, ValueError)): diff --git a/tests/crypto/test_powers.py b/tests/crypto/test_powers.py index ceed355c4..134a8f17c 100644 --- a/tests/crypto/test_powers.py +++ b/tests/crypto/test_powers.py @@ -14,7 +14,9 @@ def test_transacting_power_sign_message(testerchain): # Manually create a TransactingPower testerchain.connect() eth_address = testerchain.etherbase_account - power = TransactingPower(blockchain=testerchain, account=eth_address) + power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=eth_address) # The default state of the account is locked. # Test a signature without unlocking the account diff --git a/tests/fixtures.py b/tests/fixtures.py index 1e062f040..1d636cd5b 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -293,7 +293,6 @@ def capsule_side_channel(enacted_federated_policy): self.messages = [] self() - return _CapsuleSideChannel() @@ -313,8 +312,12 @@ def federated_alice(alice_federated_test_config): @pytest.fixture(scope="module") -def blockchain_alice(alice_blockchain_test_config): - _alice = alice_blockchain_test_config.produce() +def blockchain_alice(alice_blockchain_test_config, testerchain): + transacting_power = TransactingPower(blockchain=testerchain, + account=alice_blockchain_test_config.checksum_address, + password=INSECURE_DEVELOPMENT_PASSWORD) + transacting_power.activate() + _alice = alice_blockchain_test_config.produce(additional_powers=[transacting_power]) return _alice @@ -325,8 +328,11 @@ def federated_bob(bob_federated_test_config): @pytest.fixture(scope="module") -def blockchain_bob(bob_blockchain_test_config): - _bob = bob_blockchain_test_config.produce() +def blockchain_bob(bob_blockchain_test_config, testerchain): + transacting_power = TransactingPower(blockchain=testerchain, + account=bob_blockchain_test_config.checksum_address, + password=INSECURE_DEVELOPMENT_PASSWORD) + _bob = bob_blockchain_test_config.produce(additional_powers=[transacting_power]) return _bob @@ -370,8 +376,10 @@ def testerchain(): # Mock TransactingPower Consumption (Deployer) testerchain.deployer_address = testerchain.etherbase_account - testerchain.transacting_power = TransactingPower(blockchain=testerchain, account=testerchain.deployer_address) - testerchain.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) + testerchain.transacting_power = TransactingPower(blockchain=testerchain, + password=INSECURE_DEVELOPMENT_PASSWORD, + account=testerchain.deployer_address) + testerchain.transacting_power.activate() yield testerchain testerchain.disconnect()