mirror of https://github.com/nucypher/nucypher.git
Felix tests passing - Bug fixes for chain syncing and accounts managemtn; Begin the movement to integrate BlockchainPower.
parent
3eeb710c47
commit
db94cb52dd
|
@ -176,6 +176,9 @@ class Blockchain:
|
||||||
|
|
||||||
cls._instance = cls(interface=interface, provider_process=provider_process)
|
cls._instance = cls(interface=interface, provider_process=provider_process)
|
||||||
|
|
||||||
|
# Sync blockchain
|
||||||
|
cls._instance.sync()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
if provider_uri is not None:
|
if provider_uri is not None:
|
||||||
|
@ -189,14 +192,13 @@ class Blockchain:
|
||||||
# but we want to connect using a different registry.
|
# but we want to connect using a different registry.
|
||||||
cls._instance.interface.registry = registry
|
cls._instance.interface.registry = registry
|
||||||
|
|
||||||
# Syn blockchain
|
|
||||||
cls._instance.sync()
|
|
||||||
return cls._instance
|
return cls._instance
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def disconnect(cls):
|
def disconnect(cls):
|
||||||
if cls._instance.__provider_process:
|
if cls._instance is not NO_BLOCKCHAIN_AVAILABLE:
|
||||||
cls._instance.__provider_process.stop()
|
if cls._instance.__provider_process:
|
||||||
|
cls._instance.__provider_process.stop()
|
||||||
|
|
||||||
def get_contract(self, name: str) -> Contract:
|
def get_contract(self, name: str) -> Contract:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -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.banners import MOE_BANNER, FELIX_BANNER, NU_BANNER
|
||||||
from nucypher.characters.base import Character
|
from nucypher.characters.base import Character
|
||||||
from nucypher.config.constants import TEMPLATES_DIR
|
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.keystore.threading import ThreadedSession
|
||||||
from nucypher.network.nodes import FleetStateTracker
|
from nucypher.network.nodes import FleetStateTracker
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ class Felix(Character, NucypherTokenActor):
|
||||||
research and the development of production-ready nucypher dApps.
|
research and the development of production-ready nucypher dApps.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_default_crypto_powerups = [SigningPower] # identity only
|
_default_crypto_powerups = [SigningPower, BlockchainPower]
|
||||||
|
|
||||||
TEMPLATE_NAME = 'felix.html'
|
TEMPLATE_NAME = 'felix.html'
|
||||||
|
|
||||||
|
@ -142,8 +142,7 @@ class Felix(Character, NucypherTokenActor):
|
||||||
BATCH_SIZE = 10 # transactions
|
BATCH_SIZE = 10 # transactions
|
||||||
MULTIPLIER = 0.95 # 5% reduction of previous stake is 0.95, for example
|
MULTIPLIER = 0.95 # 5% reduction of previous stake is 0.95, for example
|
||||||
MINIMUM_DISBURSEMENT = 1e18 # NuNits
|
MINIMUM_DISBURSEMENT = 1e18 # NuNits
|
||||||
ETHER_AIRDROP_AMOUNT = 2e18 # Wei
|
ETHER_AIRDROP_AMOUNT = int(2e18) # Wei
|
||||||
# TRANSACTION_GAS = 40000 # gas TODO
|
|
||||||
|
|
||||||
# Node Discovery
|
# Node Discovery
|
||||||
LEARNING_TIMEOUT = 30 # seconds
|
LEARNING_TIMEOUT = 30 # seconds
|
||||||
|
|
|
@ -136,8 +136,9 @@ def felix(click_config,
|
||||||
# Authenticate
|
# Authenticate
|
||||||
password = click_config.get_password(confirm=False)
|
password = click_config.get_password(confirm=False)
|
||||||
click_config.unlock_keyring(character_configuration=felix_config,
|
click_config.unlock_keyring(character_configuration=felix_config,
|
||||||
password=password,
|
password=password)
|
||||||
client_keyring=not no_password)
|
|
||||||
|
|
||||||
|
|
||||||
# Produce Teacher Ursulas
|
# Produce Teacher Ursulas
|
||||||
teacher_uris = [teacher_uri] if teacher_uri else None
|
teacher_uris = [teacher_uri] if teacher_uri else None
|
||||||
|
|
|
@ -109,11 +109,10 @@ class NucypherClickConfig:
|
||||||
|
|
||||||
def unlock_keyring(self,
|
def unlock_keyring(self,
|
||||||
password: str,
|
password: str,
|
||||||
character_configuration: NodeConfiguration,
|
character_configuration: NodeConfiguration):
|
||||||
client_keyring: bool = True):
|
|
||||||
|
|
||||||
if not self.quiet:
|
if not self.quiet:
|
||||||
self.emit(message='Decrypting keyring...', color='blue')
|
self.emit(message='Decrypting NuCypher keyring...', color='yellow')
|
||||||
|
|
||||||
if character_configuration.dev_mode:
|
if character_configuration.dev_mode:
|
||||||
return True # Dev accounts are always unlocked
|
return True # Dev accounts are always unlocked
|
||||||
|
@ -124,13 +123,11 @@ class NucypherClickConfig:
|
||||||
except CryptoError:
|
except CryptoError:
|
||||||
raise character_configuration.keyring.AuthenticationFailed
|
raise character_configuration.keyring.AuthenticationFailed
|
||||||
|
|
||||||
# # Eth Client Node
|
# Ethereum Client # TODO : Integrate with Powers API
|
||||||
# if client_keyring: # FIXME - YIIKES - move to keyring
|
if not character_configuration.federated_only:
|
||||||
# try:
|
self.emit(message='Decrypting Ethereum Node Keyring...', color='yellow')
|
||||||
# character_configuration.blockchain.interface.unlock_account(address=character_configuration.checksum_public_address,
|
character_configuration.blockchain.interface.unlock_account(address=character_configuration.checksum_public_address,
|
||||||
# password=password)
|
password=password)
|
||||||
# except ValueError as e:
|
|
||||||
# raise # TODO
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def attach_emitter(cls, emitter) -> None:
|
def attach_emitter(cls, emitter) -> None:
|
||||||
|
|
|
@ -44,8 +44,12 @@ from constant_sorrow.constants import KEYRING_LOCKED
|
||||||
from nucypher.config.constants import DEFAULT_CONFIG_ROOT
|
from nucypher.config.constants import DEFAULT_CONFIG_ROOT
|
||||||
from nucypher.crypto.api import generate_self_signed_certificate
|
from nucypher.crypto.api import generate_self_signed_certificate
|
||||||
from nucypher.crypto.constants import BLAKE2B
|
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.network.server import TLSHostingPower
|
||||||
|
from nucypher.blockchain.eth.chains import Blockchain
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FILE_ENCODING = 'utf-8'
|
FILE_ENCODING = 'utf-8'
|
||||||
|
|
||||||
|
@ -500,6 +504,9 @@ class NucypherKeyring:
|
||||||
keying_material = SecretBox(wrap_key).decrypt(key_data['key'])
|
keying_material = SecretBox(wrap_key).decrypt(key_data['key'])
|
||||||
new_cryptopower = power_class(keying_material=keying_material)
|
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:
|
else:
|
||||||
failure_message = "{} is an invalid type for deriving a CryptoPower.".format(power_class.__name__)
|
failure_message = "{} is an invalid type for deriving a CryptoPower.".format(power_class.__name__)
|
||||||
raise ValueError(failure_message)
|
raise ValueError(failure_message)
|
||||||
|
|
|
@ -251,7 +251,7 @@ class NodeConfiguration(ABC):
|
||||||
self.provider_uri = provider_uri or self.DEFAULT_PROVIDER_URI
|
self.provider_uri = provider_uri or self.DEFAULT_PROVIDER_URI
|
||||||
self.provider_process = provider_process or NO_BLOCKCHAIN_CONNECTION
|
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.accounts = NO_BLOCKCHAIN_CONNECTION
|
||||||
self.token_agent = NO_BLOCKCHAIN_CONNECTION
|
self.token_agent = NO_BLOCKCHAIN_CONNECTION
|
||||||
self.miner_agent = NO_BLOCKCHAIN_CONNECTION
|
self.miner_agent = NO_BLOCKCHAIN_CONNECTION
|
||||||
|
@ -292,7 +292,8 @@ class NodeConfiguration(ABC):
|
||||||
def cleanup(self) -> None:
|
def cleanup(self) -> None:
|
||||||
if self.__dev_mode:
|
if self.__dev_mode:
|
||||||
self.__temp_dir.cleanup()
|
self.__temp_dir.cleanup()
|
||||||
self.blockchain.disconnect()
|
if self.blockchain:
|
||||||
|
self.blockchain.disconnect()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def dev_mode(self):
|
def dev_mode(self):
|
||||||
|
|
|
@ -206,6 +206,9 @@ class TesterBlockchain(Blockchain):
|
||||||
self.interface.w3.eth.web3.testing.mine(1)
|
self.interface.w3.eth.web3.testing.mine(1)
|
||||||
self.log.info("Time traveled to {}".format(end_timestamp))
|
self.log.info("Time traveled to {}".format(end_timestamp))
|
||||||
|
|
||||||
|
def sync(self, timeout: int = 0):
|
||||||
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def connect(cls, *args, **kwargs) -> 'TesterBlockchain':
|
def connect(cls, *args, **kwargs) -> 'TesterBlockchain':
|
||||||
interface = BlockchainDeployerInterface(provider_uri=cls._PROVIDER_URI,
|
interface = BlockchainDeployerInterface(provider_uri=cls._PROVIDER_URI,
|
||||||
|
|
|
@ -41,7 +41,7 @@ def test_run_felix(click_runner, testerchain, federated_ursulas, mock_primary_re
|
||||||
'--provider-uri', TEST_PROVIDER_URI,
|
'--provider-uri', TEST_PROVIDER_URI,
|
||||||
'--poa')
|
'--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)
|
result = click_runner.invoke(deploy.deploy, deploy_args, input=user_input, catch_exceptions=False, env=envvars)
|
||||||
assert result.exit_code == 0
|
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):
|
def time_travel(_result):
|
||||||
clock.advance(amount=60)
|
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
|
# Run the callbacks
|
||||||
d = threads.deferToThread(run_felix)
|
d = threads.deferToThread(run_felix)
|
||||||
d.addCallback(request_felix_landing_page)
|
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')
|
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
|
staged_airdrops = Felix._AIRDROP_QUEUE
|
||||||
next_airdrop = staged_airdrops[0]
|
next_airdrop = staged_airdrops[0]
|
||||||
next_airdrop.addCallback(confirm_airdrop)
|
next_airdrop.addCallback(confirm_airdrop)
|
||||||
|
|
Loading…
Reference in New Issue