def test_nucypher_deploy_allocation_contracts(click_runner, testerchain, registry_filepath, mock_allocation_infile, token_economics): # # Main # deploy_command = ('allocations', '--registry-infile', registry_filepath, '--allocation-infile', mock_allocation_infile.filepath, '--allocation-outfile', MOCK_ALLOCATION_REGISTRY_FILEPATH, '--provider', TEST_PROVIDER_URI, '--poa') account_index = '0\n' yes = 'Y\n' user_input = account_index + yes + yes result = click_runner.invoke(deploy, deploy_command, input=user_input, catch_exceptions=False) assert result.exit_code == 0 # ensure that a pre-allocation recipient has the allocated token quantity. beneficiary = testerchain.client.accounts[-1] allocation_registry = AllocationRegistry( filepath=MOCK_ALLOCATION_REGISTRY_FILEPATH) registry = LocalContractRegistry(filepath=registry_filepath) user_escrow_agent = UserEscrowAgent( registry=registry, beneficiary=beneficiary, allocation_registry=allocation_registry) assert user_escrow_agent.unvested_tokens == token_economics.minimum_allowed_locked
def test_nucypher_deploy_allocations(testerchain, click_runner, mock_allocation_infile, token_economics): deploy_command = ( 'allocations', '--registry-infile', MOCK_REGISTRY_FILEPATH, '--allocation-infile', MOCK_ALLOCATION_INFILE, '--allocation-outfile', MOCK_ALLOCATION_REGISTRY_FILEPATH, '--provider-uri', TEST_PROVIDER_URI, '--poa', ) user_input = 'Y\n' * 2 result = click_runner.invoke(deploy, deploy_command, input=user_input, catch_exceptions=False) assert result.exit_code == 0 # ensure that a pre-allocation recipient has the allocated token quantity. beneficiary = testerchain.interface.w3.eth.accounts[-1] allocation_registry = AllocationRegistry( registry_filepath=MOCK_ALLOCATION_REGISTRY_FILEPATH) user_escrow_agent = UserEscrowAgent( beneficiary=beneficiary, allocation_registry=allocation_registry) assert user_escrow_agent.unvested_tokens == token_economics.maximum_allowed_locked
def agent(testerchain, proxy_deployer) -> UserEscrowAgent: deployer_address, beneficiary_address, *everybody_else = testerchain.interface.w3.eth.accounts # Escrow escrow_deployer = UserEscrowDeployer( deployer_address=deployer_address, allocation_registry=TEST_ALLOCATION_REGISTRY) _txhash = escrow_deployer.deploy() escrow_deployer.initial_deposit(value=TEST_ALLOCATION, duration=TEST_DURATION) assert escrow_deployer.contract.functions.getLockedTokens().call( ) == TEST_ALLOCATION escrow_deployer.assign_beneficiary(beneficiary_address=beneficiary_address) escrow_deployer.enroll_principal_contract() assert escrow_deployer.contract.functions.getLockedTokens().call( ) == TEST_ALLOCATION _agent = escrow_deployer.make_agent() _direct_agent = UserEscrowAgent( blockchain=testerchain, allocation_registry=TEST_ALLOCATION_REGISTRY, beneficiary=beneficiary_address) assert _direct_agent == _agent assert _direct_agent.contract.abi == _agent.contract.abi assert _direct_agent.contract.address == _agent.contract.address assert _agent.principal_contract.address == escrow_deployer.contract.address assert _agent.principal_contract.abi == escrow_deployer.contract.abi assert _direct_agent.contract.abi == escrow_deployer.contract.abi assert _direct_agent.contract.address == escrow_deployer.contract.address yield _agent TEST_ALLOCATION_REGISTRY.clear()
def test_nucypher_deploy_allocation_contracts(click_runner, testerchain, deploy_user_input, mock_primary_registry_filepath, mock_allocation_infile, token_economics): # Simulate "Reconnection" real_attach_provider = BlockchainDeployerInterface._attach_provider cached_blockchain = BlockchainDeployerInterface.reconnect() registry = cached_blockchain.registry assert registry.filepath == mock_primary_registry_filepath def attach_cached_provider(interface, *args, **kwargs): cached_provider = cached_blockchain.provider real_attach_provider(interface, provider=cached_provider) BlockchainDeployerInterface._attach_provider = attach_cached_provider # # Main # deploy_command = ('allocations', '--registry-infile', MOCK_REGISTRY_FILEPATH, '--allocation-infile', mock_allocation_infile.filepath, '--allocation-outfile', MOCK_ALLOCATION_REGISTRY_FILEPATH, '--provider-uri', TEST_PROVIDER_URI, '--poa') account_index = '0\n' yes = 'Y\n' node_password = f'{INSECURE_DEVELOPMENT_PASSWORD}\n' user_input = account_index + yes + node_password + yes result = click_runner.invoke(deploy, deploy_command, input=user_input, catch_exceptions=False) assert result.exit_code == 0 # ensure that a pre-allocation recipient has the allocated token quantity. beneficiary = testerchain.client.accounts[-1] allocation_registry = AllocationRegistry( registry_filepath=MOCK_ALLOCATION_REGISTRY_FILEPATH) user_escrow_agent = UserEscrowAgent( blockchain=cached_blockchain, beneficiary=beneficiary, allocation_registry=allocation_registry) assert user_escrow_agent.unvested_tokens == token_economics.minimum_allowed_locked # # Tear Down # # Destroy existing blockchain testerchain.disconnect()
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, password=INSECURE_DEVELOPMENT_PASSWORD, account=deployer_address) testerchain.transacting_power.activate() # Escrow escrow_deployer = UserEscrowDeployer( deployer_address=deployer_address, blockchain=testerchain, allocation_registry=TEST_ALLOCATION_REGISTRY) _txhash = escrow_deployer.deploy() escrow_deployer.initial_deposit(value=allocation_value, duration=TEST_DURATION) assert escrow_deployer.contract.functions.getLockedTokens().call( ) == allocation_value escrow_deployer.assign_beneficiary(beneficiary_address=beneficiary_address) escrow_deployer.enroll_principal_contract() assert escrow_deployer.contract.functions.getLockedTokens().call( ) == allocation_value _agent = escrow_deployer.make_agent() _direct_agent = UserEscrowAgent( blockchain=testerchain, allocation_registry=TEST_ALLOCATION_REGISTRY, beneficiary=beneficiary_address) assert _direct_agent == _agent assert _direct_agent.contract.abi == _agent.contract.abi assert _direct_agent.contract.address == _agent.contract.address assert _agent.principal_contract.address == escrow_deployer.contract.address assert _agent.principal_contract.abi == escrow_deployer.contract.abi assert _direct_agent.contract.abi == escrow_deployer.contract.abi assert _direct_agent.contract.address == escrow_deployer.contract.address yield _agent TEST_ALLOCATION_REGISTRY.clear()
def test_nucypher_deploy_allocation_contracts(click_runner, testerchain, deploy_user_input, mock_primary_registry_filepath, mock_allocation_infile, token_economics): TesterBlockchain.sever_connection() Agency.clear() if os.path.isfile(MOCK_ALLOCATION_REGISTRY_FILEPATH): os.remove(MOCK_ALLOCATION_REGISTRY_FILEPATH) assert not os.path.isfile(MOCK_ALLOCATION_REGISTRY_FILEPATH) # We start with a blockchain node, and nothing else... if os.path.isfile(mock_primary_registry_filepath): os.remove(mock_primary_registry_filepath) assert not os.path.isfile(mock_primary_registry_filepath) command = ['contracts', '--registry-outfile', mock_primary_registry_filepath, '--provider-uri', TEST_PROVIDER_URI, '--poa', '--no-sync'] user_input = deploy_user_input result = click_runner.invoke(deploy, command, input=user_input, catch_exceptions=False) assert result.exit_code == 0 # # Main # deploy_command = ('allocations', '--registry-infile', MOCK_REGISTRY_FILEPATH, '--allocation-infile', mock_allocation_infile.filepath, '--allocation-outfile', MOCK_ALLOCATION_REGISTRY_FILEPATH, '--provider-uri', 'tester://pyevm', '--poa') account_index = '0\n' yes = 'Y\n' node_password = f'{INSECURE_DEVELOPMENT_PASSWORD}\n' user_input = account_index + yes + node_password + yes result = click_runner.invoke(deploy, deploy_command, input=user_input, catch_exceptions=False) assert result.exit_code == 0 # ensure that a pre-allocation recipient has the allocated token quantity. beneficiary = testerchain.interface.w3.eth.accounts[-1] allocation_registry = AllocationRegistry(registry_filepath=MOCK_ALLOCATION_REGISTRY_FILEPATH) user_escrow_agent = UserEscrowAgent(beneficiary=beneficiary, allocation_registry=allocation_registry) assert user_escrow_agent.unvested_tokens == token_economics.minimum_allowed_locked # # Tear Down # # Destroy existing blockchain BlockchainInterface.disconnect()
def paint_deployer_contract_inspection(emitter, administrator) -> None: blockchain = BlockchainInterfaceFactory.get_interface() token_agent = ContractAgency.get_agent(NucypherTokenAgent, registry=administrator.registry) sep = '-' * 45 emitter.echo(sep) contract_payload = f""" * Web3 Provider ==================================================================== Provider URI ............. {blockchain.provider_uri} Registry ................ {administrator.registry.filepath} * Standard Deployments ===================================================================== NucypherToken ........... {token_agent.contract_address} ~ Ethers ............ {Web3.fromWei(blockchain.client.get_balance(token_agent.contract_address), 'ether')} ETH ~ Tokens ............ {NU.from_nunits(token_agent.get_balance(token_agent.contract_address))}""" emitter.echo(contract_payload) banner = """ * Proxy-Contract Deployments =====================================================================""" emitter.echo(banner) for contract_deployer_class in administrator.dispatched_upgradeable_deployer_classes: try: bare_contract = blockchain.get_contract_by_name( name=contract_deployer_class.contract_name, proxy_name=DispatcherDeployer.contract_name, registry=administrator.registry, use_proxy_address=False) dispatcher_deployer = DispatcherDeployer( registry=administrator.registry, target_contract=bare_contract, deployer_address=administrator.deployer_address, bare=True) # acquire agency for the dispatcher itself. agent = contract_deployer_class.agency( registry=administrator.registry, contract=bare_contract) proxy_payload = f""" {agent.contract_name} .... {bare_contract.address} ~ Owner .............. {bare_contract.functions.owner().call()} ~ Ethers ............. {Web3.fromWei(blockchain.client.get_balance(dispatcher_deployer.contract_address), 'ether')} ETH ~ Tokens ............. {NU.from_nunits(token_agent.get_balance(dispatcher_deployer.contract_address))} ~ Dispatcher ......... {dispatcher_deployer.contract_address} ~ Owner .......... {dispatcher_deployer.contract.functions.owner().call()} ~ Target ......... {dispatcher_deployer.contract.functions.target().call()} ~ Ethers ......... {Web3.fromWei(blockchain.client.get_balance(dispatcher_deployer.contract_address), 'ether')} ETH ~ Tokens ......... {NU.from_nunits(token_agent.get_balance(dispatcher_deployer.contract_address))}""" emitter.echo(proxy_payload) emitter.echo(sep, nl=False) except BaseContractRegistry.UnknownContract: message = f"\n{contract_deployer_class.contract_name} is not enrolled in {administrator.registry.filepath}" emitter.echo(message, color='yellow') emitter.echo(sep, nl=False) try: # # UserEscrowProxy # user_escrow_proxy_agent = UserEscrowAgent.UserEscrowProxyAgent( registry=administrator.registry) bare_contract = blockchain.get_contract_by_name( name=user_escrow_proxy_agent.contract_name, proxy_name=LibraryLinkerDeployer.contract_name, use_proxy_address=False, registry=administrator.registry) linker_deployer = LibraryLinkerDeployer( registry=administrator.registry, target_contract=bare_contract, deployer_address=administrator.deployer_address, bare=True) # acquire agency for the dispatcher itself. user_escrow_payload = f""" UserEscrowProxy .......... {bare_contract.address} ~ LibraryLinker ...... {linker_deployer.contract.address} ~ Owner .......... {linker_deployer.contract.functions.owner().call()} ~ Target ......... {linker_deployer.contract.functions.target().call()}""" emitter.echo(user_escrow_payload) emitter.echo(sep) except BaseContractRegistry.UnknownContract: message = f"\nUserEscrowProxy is not enrolled in {administrator.registry.filepath}" emitter.echo(message, color='yellow') return