def test_rapid_deployment(): compiler = SolidityCompiler() registry = InMemoryEthereumContractRegistry() allocation_registry = InMemoryAllocationRegistry() interface = BlockchainDeployerInterface(compiler=compiler, registry=registry, provider_uri='tester://pyevm') blockchain = TesterBlockchain(interface=interface, airdrop=False, test_accounts=4) blockchain.ether_airdrop(amount=1000000000) origin, *everyone = blockchain.interface.w3.eth.accounts deployer = Deployer(blockchain=blockchain, deployer_address=origin) deployer_address, *all_yall = deployer.blockchain.interface.w3.eth.accounts # The Big Three (+ Dispatchers) deployer.deploy_network_contracts(miner_secret=os.urandom(32), policy_secret=os.urandom(32)) # User Escrow Proxy deployer.deploy_escrow_proxy(secret=os.urandom(32)) # Deploy User Escrow total_allocations = 100 # Start with some hard-coded cases... allocation_data = [{ 'address': all_yall[1], 'amount': MAX_ALLOWED_LOCKED, 'duration': ONE_YEAR_IN_SECONDS }, { 'address': all_yall[2], 'amount': MIN_ALLOWED_LOCKED, 'duration': ONE_YEAR_IN_SECONDS * 2 }, { 'address': all_yall[3], 'amount': MIN_ALLOWED_LOCKED * 100, 'duration': ONE_YEAR_IN_SECONDS * 3 }] # Pile on the rest for _ in range(total_allocations - len(allocation_data)): random_password = ''.join( random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(16)) acct = w3.eth.account.create(random_password) beneficiary_address = acct.address amount = random.randint(MIN_ALLOWED_LOCKED, MAX_ALLOWED_LOCKED) duration = random.randint(MIN_LOCKED_PERIODS, MAX_MINTING_PERIODS * 3) random_allocation = { 'address': beneficiary_address, 'amount': amount, 'duration': duration } allocation_data.append(random_allocation) deployer.deploy_beneficiary_contracts( allocations=allocation_data, allocation_registry=allocation_registry)
def test_rapid_deployment(token_economics): compiler = SolidityCompiler() allocation_registry = InMemoryAllocationRegistry() blockchain = _TesterBlockchain(eth_airdrop=False, test_accounts=4, compiler=compiler) # TODO: #1092 - TransactingPower blockchain.transacting_power = BlockchainPower( blockchain=blockchain, account=blockchain.etherbase_account) deployer_address = blockchain.etherbase_account deployer = Deployer(blockchain=blockchain, deployer_address=deployer_address) deployer.deploy_network_contracts( staker_secret=STAKING_ESCROW_DEPLOYMENT_SECRET, policy_secret=POLICY_MANAGER_DEPLOYMENT_SECRET, adjudicator_secret=ADJUDICATOR_DEPLOYMENT_SECRET, user_escrow_proxy_secret=USER_ESCROW_PROXY_DEPLOYMENT_SECRET) all_yall = blockchain.unassigned_accounts # Start with some hard-coded cases... allocation_data = [{ 'address': all_yall[1], 'amount': token_economics.maximum_allowed_locked, 'duration': ONE_YEAR_IN_SECONDS }, { 'address': all_yall[2], 'amount': token_economics.minimum_allowed_locked, 'duration': ONE_YEAR_IN_SECONDS * 2 }, { 'address': all_yall[3], 'amount': token_economics.minimum_allowed_locked * 100, 'duration': ONE_YEAR_IN_SECONDS * 3 }] # Pile on the rest for _ in range(NUMBER_OF_ALLOCATIONS_IN_TESTS - len(allocation_data)): random_password = ''.join( random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(16)) acct = w3.eth.account.create(random_password) beneficiary_address = acct.address amount = random.randint(token_economics.minimum_allowed_locked, token_economics.maximum_allowed_locked) duration = random.randint( token_economics.minimum_locked_periods * ONE_YEAR_IN_SECONDS, (token_economics.maximum_locked_periods * ONE_YEAR_IN_SECONDS) * 3) random_allocation = { 'address': beneficiary_address, 'amount': amount, 'duration': duration } allocation_data.append(random_allocation) deployer.deploy_beneficiary_contracts( allocations=allocation_data, allocation_registry=allocation_registry)
def test_rapid_deployment(token_economics, test_registry): compiler = SolidityCompiler() allocation_registry = InMemoryAllocationRegistry() blockchain = _TesterBlockchain(eth_airdrop=False, test_accounts=4, compiler=compiler) # TODO: #1092 - TransactingPower blockchain.transacting_power = TransactingPower(password=INSECURE_DEVELOPMENT_PASSWORD, account=blockchain.etherbase_account) blockchain.transacting_power.activate() deployer_address = blockchain.etherbase_account deployer = ContractAdministrator(deployer_address=deployer_address, registry=test_registry) secrets = dict() for deployer_class in deployer.upgradeable_deployer_classes: secrets[deployer_class.contract_name] = INSECURE_DEVELOPMENT_PASSWORD deployer.deploy_network_contracts(secrets=secrets, emitter=StdoutEmitter()) all_yall = blockchain.unassigned_accounts # Start with some hard-coded cases... allocation_data = [{'beneficiary_address': all_yall[1], 'amount': token_economics.maximum_allowed_locked, 'duration_seconds': ONE_YEAR_IN_SECONDS}, {'beneficiary_address': all_yall[2], 'amount': token_economics.minimum_allowed_locked, 'duration_seconds': ONE_YEAR_IN_SECONDS*2}, {'beneficiary_address': all_yall[3], 'amount': token_economics.minimum_allowed_locked*100, 'duration_seconds': ONE_YEAR_IN_SECONDS*3} ] # Pile on the rest for _ in range(NUMBER_OF_ALLOCATIONS_IN_TESTS - len(allocation_data)): random_password = ''.join(random.SystemRandom().choice(string.ascii_uppercase+string.digits) for _ in range(16)) acct = w3.eth.account.create(random_password) beneficiary_address = acct.address amount = random.randint(token_economics.minimum_allowed_locked, token_economics.maximum_allowed_locked) duration = random.randint(token_economics.minimum_locked_periods*ONE_YEAR_IN_SECONDS, (token_economics.maximum_rewarded_periods*ONE_YEAR_IN_SECONDS)*3) random_allocation = {'beneficiary_address': beneficiary_address, 'amount': amount, 'duration_seconds': duration} allocation_data.append(random_allocation) deployer.deploy_beneficiary_contracts(allocations=allocation_data, allocation_registry=allocation_registry, interactive=False)
def mock_allocation_registry(testerchain, agency_local_registry, token_economics): # Deploy the PreallocationEscrow contract allocation_registry = InMemoryAllocationRegistry() deployer = PreallocationEscrowDeployer(deployer_address=testerchain.etherbase_account, registry=agency_local_registry, allocation_registry=allocation_registry) deployer.deploy() deployer.assign_beneficiary(checksum_address=testerchain.unassigned_accounts[0]) deployer.initial_deposit(value=2 * token_economics.minimum_allowed_locked, duration_seconds=ONE_YEAR_IN_SECONDS) deployer.enroll_principal_contract() return allocation_registry
def test_rapid_deployment(token_economics): compiler = SolidityCompiler() registry = InMemoryEthereumContractRegistry() allocation_registry = InMemoryAllocationRegistry() interface = BlockchainDeployerInterface(compiler=compiler, registry=registry, provider_uri='tester://pyevm') blockchain = TesterBlockchain(interface=interface, airdrop=False, test_accounts=4) deployer_address = blockchain.etherbase_account deployer = Deployer(blockchain=blockchain, deployer_address=deployer_address) # The Big Three (+ Dispatchers) deployer.deploy_network_contracts(miner_secret=MINERS_ESCROW_DEPLOYMENT_SECRET, policy_secret=POLICY_MANAGER_DEPLOYMENT_SECRET, adjudicator_secret=MINING_ADJUDICATOR_DEPLOYMENT_SECRET) # Deploy User Escrow, too (+ Linker) deployer.deploy_escrow_proxy(secret=USER_ESCROW_PROXY_DEPLOYMENT_SECRET) total_allocations = NUMBER_OF_ALLOCATIONS_IN_TESTS all_yall = blockchain.unassigned_accounts # Start with some hard-coded cases... allocation_data = [{'address': all_yall[1], 'amount': token_economics.maximum_allowed_locked, 'duration': ONE_YEAR_IN_SECONDS}, {'address': all_yall[2], 'amount': token_economics.minimum_allowed_locked, 'duration': ONE_YEAR_IN_SECONDS*2}, {'address': all_yall[3], 'amount': token_economics.minimum_allowed_locked*100, 'duration': ONE_YEAR_IN_SECONDS*3} ] # Pile on the rest for _ in range(total_allocations - len(allocation_data)): random_password = ''.join(random.SystemRandom().choice(string.ascii_uppercase+string.digits) for _ in range(16)) acct = w3.eth.account.create(random_password) beneficiary_address = acct.address amount = random.randint(token_economics.minimum_allowed_locked, token_economics.maximum_allowed_locked) duration = random.randint(token_economics.minimum_locked_periods*ONE_YEAR_IN_SECONDS, (token_economics.maximum_locked_periods*ONE_YEAR_IN_SECONDS)*3) random_allocation = {'address': beneficiary_address, 'amount': amount, 'duration': duration} allocation_data.append(random_allocation) deployer.deploy_beneficiary_contracts(allocations=allocation_data, allocation_registry=allocation_registry)
def deployed_blockchain(): # # Interface # compiler = SolidityCompiler() registry = InMemoryEthereumContractRegistry() allocation_registry = InMemoryAllocationRegistry() interface = BlockchainDeployerInterface(compiler=compiler, registry=registry, provider_uri=TEST_PROVIDER_URI) # # Blockchain # blockchain = TesterBlockchain(interface=interface, airdrop=False, test_accounts=5, poa=True) blockchain.ether_airdrop(amount=TESTING_ETH_AIRDROP_AMOUNT) origin, *everyone = blockchain.interface.w3.eth.accounts # # Delpoyer # deployer = Deployer(blockchain=blockchain, deployer_address=origin) deployer_address, *all_yall = deployer.blockchain.interface.w3.eth.accounts # The Big Three (+ Dispatchers) deployer.deploy_network_contracts(miner_secret=os.urandom(32), policy_secret=os.urandom(32)) # User Escrow Proxy deployer.deploy_escrow_proxy(secret=os.urandom(32)) # Start with some hard-coded cases... allocation_data = [{ 'address': all_yall[1], 'amount': MAX_ALLOWED_LOCKED, 'duration': ONE_YEAR_IN_SECONDS }] deployer.deploy_beneficiary_contracts( allocations=allocation_data, allocation_registry=allocation_registry) yield blockchain, deployer_address, registry
def deployed_blockchain(token_economics): # Interface compiler = SolidityCompiler() registry = InMemoryEthereumContractRegistry() allocation_registry = InMemoryAllocationRegistry() interface = BlockchainDeployerInterface(compiler=compiler, registry=registry, provider_uri=TEST_PROVIDER_URI) # Blockchain blockchain = TesterBlockchain(interface=interface, airdrop=True, test_accounts=5, poa=True) deployer_address = blockchain.etherbase_account # Deployer deployer = Deployer(blockchain=blockchain, deployer_address=deployer_address) # The Big Three (+ Dispatchers) deployer.deploy_network_contracts(miner_secret=os.urandom(32), policy_secret=os.urandom(32), adjudicator_secret=os.urandom(32)) # User Escrow Proxy deployer.deploy_escrow_proxy(secret=os.urandom(32)) # Start with some hard-coded cases... all_yall = blockchain.unassigned_accounts allocation_data = [{ 'address': all_yall[1], 'amount': token_economics.maximum_allowed_locked, 'duration': ONE_YEAR_IN_SECONDS }] deployer.deploy_beneficiary_contracts( allocations=allocation_data, allocation_registry=allocation_registry) yield blockchain, deployer_address, registry
""" import maya import os import pytest from eth_tester.exceptions import TransactionFailed from eth_utils import is_checksum_address, to_wei from nucypher.blockchain.eth.agents import PreallocationEscrowAgent from nucypher.blockchain.eth.deployers import PreallocationEscrowDeployer from nucypher.blockchain.eth.registry import InMemoryAllocationRegistry from nucypher.blockchain.eth.token import NU from tests.utils.blockchain import token_airdrop from tests.constants import INSECURE_DEVELOPMENT_PASSWORD TEST_LOCK_DURATION_IN_SECONDS = 60 * 60 * 24 # 1 day TEST_ALLOCATION_REGISTRY = InMemoryAllocationRegistry() @pytest.fixture(scope='module') def allocation_value(token_economics): allocation = token_economics.minimum_allowed_locked * 10 return allocation @pytest.fixture(scope='function') def agent(testerchain, test_registry, allocation_value, agency, mock_transacting_power_activation) -> PreallocationEscrowAgent: deployer_address, beneficiary_address, *everybody_else = testerchain.client.accounts escrow_deployer = PreallocationEscrowDeployer( deployer_address=deployer_address,