Felix tests passing - Bug fixes for chain syncing and accounts managemtn; Begin the movement to integrate BlockchainPower.

pull/1040/head
Kieran Prasch 2019-04-30 02:50:45 +03:00
parent 3eeb710c47
commit db94cb52dd
No known key found for this signature in database
GPG Key ID: 199AB839D4125A62
8 changed files with 44 additions and 24 deletions

View File

@ -176,6 +176,9 @@ class Blockchain:
cls._instance = cls(interface=interface, provider_process=provider_process)
# Sync blockchain
cls._instance.sync()
else:
if provider_uri is not None:
@ -189,12 +192,11 @@ class Blockchain:
# but we want to connect using a different registry.
cls._instance.interface.registry = registry
# Syn blockchain
cls._instance.sync()
return cls._instance
@classmethod
def disconnect(cls):
if cls._instance is not NO_BLOCKCHAIN_AVAILABLE:
if cls._instance.__provider_process:
cls._instance.__provider_process.stop()

View File

@ -27,7 +27,7 @@ from nucypher.blockchain.eth.token import NU
from nucypher.characters.banners import MOE_BANNER, FELIX_BANNER, NU_BANNER
from nucypher.characters.base import Character
from nucypher.config.constants import TEMPLATES_DIR
from nucypher.crypto.powers import SigningPower
from nucypher.crypto.powers import SigningPower, BlockchainPower
from nucypher.keystore.threading import ThreadedSession
from nucypher.network.nodes import FleetStateTracker
@ -129,7 +129,7 @@ class Felix(Character, NucypherTokenActor):
research and the development of production-ready nucypher dApps.
"""
_default_crypto_powerups = [SigningPower] # identity only
_default_crypto_powerups = [SigningPower, BlockchainPower]
TEMPLATE_NAME = 'felix.html'
@ -142,8 +142,7 @@ class Felix(Character, NucypherTokenActor):
BATCH_SIZE = 10 # transactions
MULTIPLIER = 0.95 # 5% reduction of previous stake is 0.95, for example
MINIMUM_DISBURSEMENT = 1e18 # NuNits
ETHER_AIRDROP_AMOUNT = 2e18 # Wei
# TRANSACTION_GAS = 40000 # gas TODO
ETHER_AIRDROP_AMOUNT = int(2e18) # Wei
# Node Discovery
LEARNING_TIMEOUT = 30 # seconds

View File

@ -136,8 +136,9 @@ def felix(click_config,
# Authenticate
password = click_config.get_password(confirm=False)
click_config.unlock_keyring(character_configuration=felix_config,
password=password,
client_keyring=not no_password)
password=password)
# Produce Teacher Ursulas
teacher_uris = [teacher_uri] if teacher_uri else None

View File

@ -109,11 +109,10 @@ class NucypherClickConfig:
def unlock_keyring(self,
password: str,
character_configuration: NodeConfiguration,
client_keyring: bool = True):
character_configuration: NodeConfiguration):
if not self.quiet:
self.emit(message='Decrypting keyring...', color='blue')
self.emit(message='Decrypting NuCypher keyring...', color='yellow')
if character_configuration.dev_mode:
return True # Dev accounts are always unlocked
@ -124,13 +123,11 @@ class NucypherClickConfig:
except CryptoError:
raise character_configuration.keyring.AuthenticationFailed
# # Eth Client Node
# if client_keyring: # FIXME - YIIKES - move to keyring
# try:
# character_configuration.blockchain.interface.unlock_account(address=character_configuration.checksum_public_address,
# password=password)
# except ValueError as e:
# raise # TODO
# Ethereum Client # TODO : Integrate with Powers API
if not character_configuration.federated_only:
self.emit(message='Decrypting Ethereum Node Keyring...', color='yellow')
character_configuration.blockchain.interface.unlock_account(address=character_configuration.checksum_public_address,
password=password)
@classmethod
def attach_emitter(cls, emitter) -> None:

View File

@ -44,8 +44,12 @@ from constant_sorrow.constants import KEYRING_LOCKED
from nucypher.config.constants import DEFAULT_CONFIG_ROOT
from nucypher.crypto.api import generate_self_signed_certificate
from nucypher.crypto.constants import BLAKE2B
from nucypher.crypto.powers import SigningPower, DecryptingPower, KeyPairBasedPower, DerivedKeyBasedPower
from nucypher.crypto.powers import SigningPower, DecryptingPower, KeyPairBasedPower, DerivedKeyBasedPower, \
BlockchainPower
from nucypher.network.server import TLSHostingPower
from nucypher.blockchain.eth.chains import Blockchain
FILE_ENCODING = 'utf-8'
@ -500,6 +504,9 @@ class NucypherKeyring:
keying_material = SecretBox(wrap_key).decrypt(key_data['key'])
new_cryptopower = power_class(keying_material=keying_material)
elif power_class is BlockchainPower:
new_cryptopower = power_class(blockchain=Blockchain.connect(), account=self.checksum_address)
else:
failure_message = "{} is an invalid type for deriving a CryptoPower.".format(power_class.__name__)
raise ValueError(failure_message)

View File

@ -251,7 +251,7 @@ class NodeConfiguration(ABC):
self.provider_uri = provider_uri or self.DEFAULT_PROVIDER_URI
self.provider_process = provider_process or NO_BLOCKCHAIN_CONNECTION
self.blockchain = NO_BLOCKCHAIN_CONNECTION
self.blockchain = NO_BLOCKCHAIN_CONNECTION.bool_value(False)
self.accounts = NO_BLOCKCHAIN_CONNECTION
self.token_agent = NO_BLOCKCHAIN_CONNECTION
self.miner_agent = NO_BLOCKCHAIN_CONNECTION
@ -292,6 +292,7 @@ class NodeConfiguration(ABC):
def cleanup(self) -> None:
if self.__dev_mode:
self.__temp_dir.cleanup()
if self.blockchain:
self.blockchain.disconnect()
@property

View File

@ -206,6 +206,9 @@ class TesterBlockchain(Blockchain):
self.interface.w3.eth.web3.testing.mine(1)
self.log.info("Time traveled to {}".format(end_timestamp))
def sync(self, timeout: int = 0):
return True
@classmethod
def connect(cls, *args, **kwargs) -> 'TesterBlockchain':
interface = BlockchainDeployerInterface(provider_uri=cls._PROVIDER_URI,

View File

@ -41,7 +41,7 @@ def test_run_felix(click_runner, testerchain, federated_ursulas, mock_primary_re
'--provider-uri', TEST_PROVIDER_URI,
'--poa')
user_input = '0\n'+'Y\n'+f'{INSECURE_DEVELOPMENT_PASSWORD}\n'*8 # TODO: Use Env Vars
user_input = '0\n' + 'Y\n'*2 + f'{INSECURE_DEVELOPMENT_PASSWORD}\n'*8 + 'DEPLOY' # TODO: Use Env Vars
result = click_runner.invoke(deploy.deploy, deploy_args, input=user_input, catch_exceptions=False, env=envvars)
assert result.exit_code == 0
@ -104,6 +104,13 @@ def test_run_felix(click_runner, testerchain, federated_ursulas, mock_primary_re
def time_travel(_result):
clock.advance(amount=60)
# Record starting ether balance
recipient = testerchain.interface.w3.eth.accounts[-1]
miner = Miner(checksum_address=recipient,
blockchain=testerchain,
is_me=True)
original_eth_balance = miner.eth_balance
# Run the callbacks
d = threads.deferToThread(run_felix)
d.addCallback(request_felix_landing_page)
@ -119,6 +126,9 @@ def test_run_felix(click_runner, testerchain, federated_ursulas, mock_primary_re
assert miner.token_balance == NU(15000, 'NU')
new_eth_balance = original_eth_balance + testerchain.interface.w3.fromWei(Felix.ETHER_AIRDROP_AMOUNT, 'ether')
assert miner.eth_balance == new_eth_balance
staged_airdrops = Felix._AIRDROP_QUEUE
next_airdrop = staged_airdrops[0]
next_airdrop.addCallback(confirm_airdrop)