def _make_agency(testerchain, test_registry, token_economics, deployer_transacting_power): transacting_power = deployer_transacting_power token_deployer = NucypherTokenDeployer(economics=token_economics, registry=test_registry) token_deployer.deploy(transacting_power=transacting_power) staking_escrow_deployer = StakingEscrowDeployer(economics=token_economics, registry=test_registry) staking_escrow_deployer.deploy(deployment_mode=INIT, transacting_power=transacting_power) policy_manager_deployer = PolicyManagerDeployer(economics=token_economics, registry=test_registry) policy_manager_deployer.deploy(transacting_power=transacting_power) adjudicator_deployer = AdjudicatorDeployer(economics=token_economics, registry=test_registry) adjudicator_deployer.deploy(transacting_power=transacting_power) staking_interface_deployer = StakingInterfaceDeployer( economics=token_economics, registry=test_registry) staking_interface_deployer.deploy(transacting_power=transacting_power) worklock_deployer = WorklockDeployer(economics=token_economics, registry=test_registry) worklock_deployer.deploy(transacting_power=transacting_power) staking_escrow_deployer = StakingEscrowDeployer(economics=token_economics, registry=test_registry) staking_escrow_deployer.deploy(deployment_mode=FULL, transacting_power=transacting_power) # Set additional parameters minimum, default, maximum = FEE_RATE_RANGE policy_agent = policy_manager_deployer.make_agent() txhash = policy_agent.contract.functions.setFeeRateRange( minimum, default, maximum).transact() testerchain.wait_for_receipt(txhash)
def test_upgradeability(temp_dir_path): # Prepare remote source for compilation download_github_dir(GITHUB_SOURCE_LINK, temp_dir_path) # Prepare the blockchain BlockchainDeployerInterface.SOURCES = [ SourceBundle(base_path=SOLIDITY_SOURCE_ROOT), SourceBundle(base_path=Path(temp_dir_path)) ] provider_uri = 'tester://pyevm/2' # TODO: Testerchain caching Issues try: blockchain_interface = BlockchainDeployerInterface( provider_uri=provider_uri, gas_strategy='free') blockchain_interface.connect() origin = blockchain_interface.client.accounts[0] BlockchainInterfaceFactory.register_interface( interface=blockchain_interface) transacting_power = TransactingPower( password=INSECURE_DEVELOPMENT_PASSWORD, signer=Web3Signer(blockchain_interface.client), account=origin) economics = make_token_economics(blockchain_interface) # Check contracts with multiple versions contract_name = AdjudicatorDeployer.contract_name skip_adjudicator_test = skip_test(blockchain_interface, contract_name) contract_name = StakingEscrowDeployer.contract_name skip_staking_escrow_test = skip_test(blockchain_interface, contract_name) contract_name = PolicyManagerDeployer.contract_name skip_policy_manager_test = skip_test(blockchain_interface, contract_name) if not skip_adjudicator_test and not skip_staking_escrow_test and not skip_policy_manager_test: return # Prepare master version of contracts and upgrade to the latest registry = InMemoryContractRegistry() token_deployer = NucypherTokenDeployer(registry=registry, economics=economics) token_deployer.deploy(transacting_power=transacting_power) staking_escrow_deployer = StakingEscrowDeployer(registry=registry, economics=economics) staking_escrow_deployer.deploy(deployment_mode=constants.INIT, transacting_power=transacting_power) policy_manager_deployer = PolicyManagerDeployer(registry=registry, economics=economics) deploy_base_contract(blockchain_interface, policy_manager_deployer, transacting_power=transacting_power, skipt_test=skip_policy_manager_test) adjudicator_deployer = AdjudicatorDeployer(registry=registry, economics=economics) deploy_base_contract(blockchain_interface, adjudicator_deployer, transacting_power=transacting_power, skipt_test=skip_adjudicator_test) if skip_staking_escrow_test: worklock_deployer = WorklockDeployer(registry=registry, economics=economics) worklock_deployer.deploy(transacting_power=transacting_power) staking_escrow_deployer = StakingEscrowDeployer(registry=registry, economics=economics) deploy_base_contract(blockchain_interface, staking_escrow_deployer, transacting_power=transacting_power, skipt_test=skip_staking_escrow_test) if not skip_staking_escrow_test: # TODO prepare at least one staker before calling upgrade staking_escrow_deployer.upgrade( transacting_power=transacting_power, contract_version="latest", confirmations=0) if not skip_policy_manager_test: policy_manager_deployer.upgrade( transacting_power=transacting_power, contract_version="latest", confirmations=0) if not skip_adjudicator_test: adjudicator_deployer.upgrade(transacting_power=transacting_power, contract_version="latest", confirmations=0) finally: # Unregister interface # TODO: Move to method? with contextlib.suppress(KeyError): del BlockchainInterfaceFactory._interfaces[provider_uri]
def _make_agency( testerchain, test_registry, token_economics ) -> Tuple[NucypherTokenAgent, StakingEscrowAgent, PolicyManagerAgent]: """ Launch the big three contracts on provided chain, make agents for each and return them. """ # Mock TransactingPower Consumption (Deployer) testerchain.transacting_power = TransactingPower( password=INSECURE_DEVELOPMENT_PASSWORD, signer=Web3Signer(client=testerchain.client), account=testerchain.etherbase_account) testerchain.transacting_power.activate() origin = testerchain.etherbase_account token_deployer = NucypherTokenDeployer(deployer_address=origin, economics=token_economics, registry=test_registry) token_deployer.deploy() staking_escrow_deployer = StakingEscrowDeployer(deployer_address=origin, economics=token_economics, registry=test_registry, test_mode=True) staking_escrow_deployer.deploy() policy_manager_deployer = PolicyManagerDeployer(deployer_address=origin, economics=token_economics, registry=test_registry) policy_manager_deployer.deploy() adjudicator_deployer = AdjudicatorDeployer(deployer_address=origin, economics=token_economics, registry=test_registry) adjudicator_deployer.deploy() staking_interface_deployer = StakingInterfaceDeployer( deployer_address=origin, economics=token_economics, registry=test_registry) staking_interface_deployer.deploy() worklock_deployer = WorklockDeployer(deployer_address=origin, economics=token_economics, registry=test_registry) worklock_deployer.deploy() token_agent = token_deployer.make_agent() # 1 Token staking_agent = staking_escrow_deployer.make_agent() # 2 Staking Escrow policy_agent = policy_manager_deployer.make_agent() # 3 Policy Agent _adjudicator_agent = adjudicator_deployer.make_agent() # 4 Adjudicator _worklock_agent = worklock_deployer.make_agent() # 5 Worklock # Set additional parameters minimum, default, maximum = FEE_RATE_RANGE txhash = policy_agent.contract.functions.setFeeRateRange( minimum, default, maximum).transact() _receipt = testerchain.wait_for_receipt(txhash) # TODO: Get rid of returning these agents here. # What's important is deploying and creating the first agent for each contract, # and since agents are singletons, in tests it's only necessary to call the agent # constructor again to receive the existing agent. # # For example: # staking_agent = StakingEscrowAgent() # # This is more clear than how we currently obtain an agent instance in tests: # _, staking_agent, _ = agency # # Other advantages is that it's closer to how agents should be use (i.e., there # are no fixtures IRL) and it's more extensible (e.g., AdjudicatorAgent) return token_agent, staking_agent, policy_agent
def test_upgradeability(temp_dir_path): # Prepare remote source for compilation download_github_dir(GITHUB_SOURCE_LINK, temp_dir_path) # Prepare the blockchain BlockchainDeployerInterface.SOURCES = [ SourceBundle(base_path=SOLIDITY_SOURCE_ROOT), SourceBundle(base_path=Path(temp_dir_path)) ] provider_uri = 'tester://pyevm/2' # TODO: Testerchain caching Issues try: blockchain_interface = BlockchainDeployerInterface( provider_uri=provider_uri, gas_strategy='free') blockchain_interface.connect() origin = blockchain_interface.client.accounts[0] BlockchainInterfaceFactory.register_interface( interface=blockchain_interface) blockchain_interface.transacting_power = TransactingPower( password=INSECURE_DEVELOPMENT_PASSWORD, account=origin) blockchain_interface.transacting_power.activate() economics = make_token_economics(blockchain_interface) # Check contracts with multiple versions raw_contracts = blockchain_interface._raw_contract_cache contract_name = AdjudicatorDeployer.contract_name test_adjudicator = len(raw_contracts[contract_name]) > 1 contract_name = StakingEscrowDeployer.contract_name test_staking_escrow = len(raw_contracts[contract_name]) > 1 contract_name = PolicyManagerDeployer.contract_name test_policy_manager = len(raw_contracts[contract_name]) > 1 if not test_adjudicator and not test_staking_escrow and not test_policy_manager: return # Prepare master version of contracts and upgrade to the latest registry = InMemoryContractRegistry() token_deployer = NucypherTokenDeployer(registry=registry, deployer_address=origin, economics=economics) token_deployer.deploy() staking_escrow_deployer = StakingEscrowDeployer( registry=registry, deployer_address=origin, economics=economics) deploy_earliest_contract(blockchain_interface, staking_escrow_deployer) policy_manager_deployer = None if test_staking_escrow or test_policy_manager: policy_manager_deployer = PolicyManagerDeployer( registry=registry, deployer_address=origin, economics=economics) deploy_earliest_contract(blockchain_interface, policy_manager_deployer) adjudicator_deployer = None if test_staking_escrow or test_adjudicator: adjudicator_deployer = AdjudicatorDeployer(registry=registry, deployer_address=origin, economics=economics) deploy_earliest_contract(blockchain_interface, adjudicator_deployer) if test_staking_escrow: worklock_deployer = WorklockDeployer(registry=registry, deployer_address=origin, economics=economics) worklock_deployer.deploy() # TODO prepare at least one staker before calling upgrade staking_escrow_deployer.upgrade(contract_version="latest", confirmations=0) if test_policy_manager: policy_manager_deployer.upgrade(contract_version="latest", confirmations=0) if test_adjudicator: adjudicator_deployer.upgrade(contract_version="latest", confirmations=0) finally: # Unregister interface # TODO: Move to method? with contextlib.suppress(KeyError): del BlockchainInterfaceFactory._interfaces[provider_uri]