def test_deploy_script( web3, contracts_manager, utils_contract, faucet_private_key, faucet_address, get_random_privkey, ): # normal deployment gas_limit = 5900000 deployer = ContractDeployer( web3=web3, private_key=faucet_private_key, gas_limit=gas_limit, gas_price=1, wait=10, ) res = deploy_raiden_contracts(deployer, ) assert CONTRACT_ENDPOINT_REGISTRY in res assert CONTRACT_TOKEN_NETWORK_REGISTRY in res assert CONTRACT_SECRET_REGISTRY in res # check that it fails if sender has no eth deployer = ContractDeployer( web3=web3, private_key=get_random_privkey(), gas_limit=gas_limit, gas_price=1, wait=10, ) with pytest.raises(ValidationError): deploy_raiden_contracts(deployer, )
def test_deploy_script_register( web3: Web3, channel_participant_deposit_limit: int, token_network_deposit_limit: int, deployed_raiden_info: DeployedContracts, token_address: HexAddress, ) -> None: """ Run token register function used in the deployment script This checks if register_token_network() works correctly in the happy case, to make sure no code dependencies have been changed, affecting the deployment script. This does not check however that the cli command works correctly. """ # normal deployment gas_limit = 5860000 deployer = ContractDeployer(web3=web3, private_key=FAUCET_PRIVATE_KEY, gas_limit=gas_limit, gas_price=1, wait=10) deployed_contracts_raiden = deployed_raiden_info token_registry_abi = deployer.contract_manager.get_contract_abi( CONTRACT_TOKEN_NETWORK_REGISTRY) token_registry_address = deployed_contracts_raiden["contracts"][ CONTRACT_TOKEN_NETWORK_REGISTRY]["address"] token_network_address = deployer.register_token_network( token_registry_abi=token_registry_abi, token_registry_address=token_registry_address, token_address=token_address, channel_participant_deposit_limit=channel_participant_deposit_limit, token_network_deposit_limit=token_network_deposit_limit, ) assert token_network_address is not None assert isinstance(token_network_address, str)
def test_deploy_script_raiden_0_37_0( deployer_0_37_0: ContractDeployer, ) -> None: """Checks that `verify_deployment_data` works fine with older contracts.""" data = deployer_0_37_0.deploy_raiden_contracts( max_num_of_token_networks=1, reuse_secret_registry_from_deploy_file=None, settle_timeout_min=DEPLOY_SETTLE_TIMEOUT_MIN, settle_timeout_max=DEPLOY_SETTLE_TIMEOUT_MAX, ) deployer_0_37_0.verify_deployment_data(deployment_data=data)
def test_red_eyes_deployer(web3: Web3) -> None: """ A smoke test for deploying RedEyes version contracts """ deployer = ContractDeployer( web3=web3, private_key=FAUCET_PRIVATE_KEY, gas_limit=GAS_LIMIT, gas_price=1, wait=10, contracts_version="0.4.0", ) deployer.deploy_raiden_contracts(max_num_of_token_networks=None)
def test_store_and_verify_raiden( fs_reload_deployer: FakeFilesystem, deployed_raiden_info: DeployedContracts, deployer: ContractDeployer, ) -> None: """ Store some raiden contract deployment information and verify them """ fs_reload_deployer.add_real_directory( contracts_precompiled_path(version=None).parent) deployed_contracts_info = deployed_raiden_info deployer.store_and_verify_deployment_info_raiden( deployed_contracts_info=deployed_contracts_info) deployer.store_and_verify_deployment_info_raiden( deployed_contracts_info=deployed_contracts_info)
def test_deploy_script_token( web3, faucet_private_key, get_random_privkey, ): """ Run test token deployment function used in the deployment script This checks if deploy_token_contract() works correctly in the happy case, to make sure no code dependencies have been changed, affecting the deployment script. This does not check however that the cli command works correctly. """ # normal deployment gas_limit = 5900000 token_type = 'CustomToken' deployer = ContractDeployer( web3=web3, private_key=faucet_private_key, gas_limit=gas_limit, gas_price=1, wait=10, ) deployed_token = deploy_token_contract( deployer, token_supply=10000000, token_decimals=18, token_name='TestToken', token_symbol='TTT', token_type=token_type, ) assert deployed_token[token_type] is not None assert isinstance(deployed_token[token_type], T_Address) # check that it fails if sender has no eth deployer = ContractDeployer( web3=web3, private_key=get_random_privkey(), gas_limit=gas_limit, gas_price=1, wait=10, ) with pytest.raises(ValidationError): deploy_token_contract( deployer, token_supply=10000000, token_decimals=18, token_name='TestToken', token_symbol='TTT', token_type='CustomToken', )
def test_store_and_verify_raiden(fs_reload_deployer, web3): """ Store some raiden contract deployment information and verify them """ fs_reload_deployer.add_real_directory( contracts_precompiled_path(version=None, ).parent) gas_limit = 5860000 deployer = ContractDeployer( web3=web3, private_key=FAUCET_PRIVATE_KEY, gas_limit=gas_limit, gas_price=1, wait=10, contracts_version=None, ) deployed_contracts_info = deploy_raiden_contracts( deployer=deployer, max_num_of_token_networks=30, ) store_and_verify_deployment_info_raiden( contracts_version=None, deployer=deployer, deployed_contracts_info=deployed_contracts_info, save_info=False, ) store_and_verify_deployment_info_raiden( contracts_version=None, deployer=deployer, deployed_contracts_info=deployed_contracts_info, save_info=True, )
def deployed_raiden_info(deployer: ContractDeployer) -> DeployedContracts: return deployer.deploy_raiden_contracts( max_num_of_token_networks=1, reuse_secret_registry_from_deploy_file=None, settle_timeout_min=DEPLOY_SETTLE_TIMEOUT_MIN, settle_timeout_max=DEPLOY_SETTLE_TIMEOUT_MAX, )
def test_alderaan_deployer(web3: Web3) -> None: """A smoke test for deploying Alderaan version contracts""" deployer = ContractDeployer( web3=web3, private_key=FAUCET_PRIVATE_KEY, gas_limit=GAS_LIMIT, gas_price=1, wait=10, contracts_version=ALDERAAN_VERSION, ) deployer.deploy_raiden_contracts( max_num_of_token_networks=2, reuse_secret_registry_from_deploy_file=None, settle_timeout_min=DEPLOY_SETTLE_TIMEOUT_MIN, settle_timeout_max=DEPLOY_SETTLE_TIMEOUT_MAX, )
def test_deploy_services_reuse_service_registry( deployer: ContractDeployer, deployed_service_info: DeployedContracts, token_address: HexAddress, token_network_registry_contract: Contract, ) -> None: """Run deploy_service_contracts with a previous ServiceRegistry deployment data""" with NamedTemporaryFile() as previous_deployment_file: previous_deployment_file.write( bytearray(json.dumps(deployed_service_info), "ascii")) previous_deployment_file.flush() new_deployment = deployer.deploy_service_contracts( token_address=token_address, user_deposit_whole_balance_limit=DEPOSIT_LIMIT, service_registry_controller=DEPLOYER_ADDRESS, initial_service_deposit_price=SERVICE_DEPOSIT // 2, service_deposit_bump_numerator=6, service_deposit_bump_denominator=5, decay_constant=200 * SECONDS_PER_DAY, min_price=1000, registration_duration=180 * SECONDS_PER_DAY, token_network_registry_address=token_network_registry_contract. address, reuse_service_registry_from_deploy_file=Path( previous_deployment_file.name), ) assert (new_deployment["contracts"][CONTRACT_SERVICE_REGISTRY] == deployed_service_info["contracts"][CONTRACT_SERVICE_REGISTRY]) assert (new_deployment["contracts"][CONTRACT_ONE_TO_N] != deployed_service_info["contracts"][CONTRACT_ONE_TO_N])
def deployer_0_4_0(web3: Web3) -> ContractDeployer: return ContractDeployer( web3=web3, private_key=FAUCET_PRIVATE_KEY, gas_limit=GAS_LIMIT, gas_price=1, wait=10, contracts_version="0.4.0", )
def deployer(web3): return ContractDeployer( web3=web3, private_key=FAUCET_PRIVATE_KEY, gas_limit=GAS_LIMIT, gas_price=1, wait=10, contracts_version=None, )
def token_address(deployer: ContractDeployer) -> DeployedContract: token_type = "CustomToken" deployed_token = deployer.deploy_token_contract( token_supply=TOKEN_SUPPLY, token_decimals=18, token_name="TestToken", token_symbol="TTT", token_type=token_type, ) return deployed_token[token_type]
def test_store_and_verify_services( fs_reload_deployer: FakeFilesystem, deployer: ContractDeployer, deployed_service_info: DeployedContracts, token_address: HexAddress, ) -> None: """ Store some service contract deployment information and verify them """ fs_reload_deployer.add_real_directory( contracts_precompiled_path(version=None).parent) deployed_contracts_info = deployed_service_info deployer.verify_service_contracts_deployment_data( token_address=token_address, deployed_contracts_info=deployed_contracts_info, user_deposit_whole_balance_limit=DEPOSIT_LIMIT, ) deployer.store_and_verify_deployment_info_services( token_address=token_address, deployed_contracts_info=deployed_contracts_info, user_deposit_whole_balance_limit=DEPOSIT_LIMIT, )
def test_deploy_service_0_37_0( deployer_0_37_0: ContractDeployer, token_address: HexAddress, token_network_registry_contract: Contract, ) -> None: with pytest.raises(RuntimeError, match="older service contracts is not supported"): deployer_0_37_0.deploy_service_contracts( token_address=token_address, user_deposit_whole_balance_limit=DEPOSIT_LIMIT, service_registry_controller=DEPLOYER_ADDRESS, initial_service_deposit_price=SERVICE_DEPOSIT // 2, service_deposit_bump_numerator=6, service_deposit_bump_denominator=5, decay_constant=200 * SECONDS_PER_DAY, min_price=1000, registration_duration=180 * SECONDS_PER_DAY, token_network_registry_address=token_network_registry_contract. address, )
def test_deploy_script_register_unexpected_limits( web3, token_network_deposit_limit, channel_participant_deposit_limit, token_address, deployed_raiden_info, ): """ Run token register function used in the deployment script without the expected channel participant deposit limit. """ deployer = ContractDeployer( web3=web3, private_key=FAUCET_PRIVATE_KEY, gas_limit=GAS_LIMIT, gas_price=1, wait=10, contracts_version="0.4.0", ) token_registry_abi = deployer.contract_manager.get_contract_abi( CONTRACT_TOKEN_NETWORK_REGISTRY ) token_registry_address = deployed_raiden_info["contracts"][CONTRACT_TOKEN_NETWORK_REGISTRY][ "address" ] with pytest.raises(ValueError): deployer.register_token_network( token_registry_abi=token_registry_abi, token_registry_address=token_registry_address, token_address=token_address, channel_participant_deposit_limit=None, token_network_deposit_limit=token_network_deposit_limit, ) with pytest.raises(ValueError): deployer.register_token_network( token_registry_abi=token_registry_abi, token_registry_address=token_registry_address, token_address=token_address, channel_participant_deposit_limit=channel_participant_deposit_limit, token_network_deposit_limit=None, ) with pytest.raises(ValueError): deployer.register_token_network( token_registry_abi=token_registry_abi, token_registry_address=token_registry_address, token_address=token_address, channel_participant_deposit_limit=channel_participant_deposit_limit, token_network_deposit_limit=token_network_deposit_limit, )
def test_deploy_script_register( web3, channel_participant_deposit_limit, token_network_deposit_limit, ): """ Run token register function used in the deployment script This checks if register_token_network() works correctly in the happy case, to make sure no code dependencies have been changed, affecting the deployment script. This does not check however that the cli command works correctly. """ # normal deployment gas_limit = 5860000 token_type = 'CustomToken' deployer = ContractDeployer( web3=web3, private_key=FAUCET_PRIVATE_KEY, gas_limit=gas_limit, gas_price=1, wait=10, ) deployed_contracts_raiden = deploy_raiden_contracts( deployer=deployer, max_num_of_token_networks=1, ) deployed_token = deploy_token_contract( deployer, token_supply=10000000, token_decimals=18, token_name='TestToken', token_symbol='TTT', token_type=token_type, ) token_address = deployed_token[token_type] token_registry_abi = deployer.contract_manager.get_contract_abi( CONTRACT_TOKEN_NETWORK_REGISTRY, ) token_registry_address = deployed_contracts_raiden['contracts'][ CONTRACT_TOKEN_NETWORK_REGISTRY]['address'] token_network_address = register_token_network( web3=web3, caller=deployer.owner, token_registry_abi=token_registry_abi, token_registry_address=token_registry_address, token_registry_version=contract_version_string(version=None), token_address=token_address, channel_participant_deposit_limit=channel_participant_deposit_limit, token_network_deposit_limit=token_network_deposit_limit, ) assert token_network_address is not None assert isinstance(token_network_address, T_Address)
def test_deploy_script_service( web3, deployed_service_info, token_address, ): """ Run deploy_service_contracts() used in the deployment script This checks if deploy_service_contracts() works correctly in the happy case. """ gas_limit = 5860000 deployer = ContractDeployer( web3=web3, private_key=FAUCET_PRIVATE_KEY, gas_limit=gas_limit, gas_price=1, wait=10, ) token_supply = 10000000 assert isinstance(token_address, T_Address) deposit_limit = token_supply // 2 deployed_service_contracts = deployed_service_info deployer._verify_service_contracts_deployment_data( token_address=token_address, user_deposit_whole_balance_limit=deposit_limit, deployment_data=deployed_service_contracts, ) deployed_info_fail = deepcopy(deployed_service_contracts) deployed_info_fail['contracts_version'] = '0.0.0' with pytest.raises(AssertionError): deployer._verify_service_contracts_deployment_data( token_address=token_address, user_deposit_whole_balance_limit=deposit_limit, deployment_data=deployed_info_fail, ) def test_missing_deployment(contract_name): deployed_info_fail = deepcopy(deployed_service_contracts) deployed_info_fail['contracts'][ contract_name ]['address'] = EMPTY_ADDRESS with pytest.raises(AssertionError): deployer._verify_service_contracts_deployment_data( token_address=token_address, user_deposit_whole_balance_limit=deposit_limit, deployment_data=deployed_info_fail, ) for contract_name in [ CONTRACT_SERVICE_REGISTRY, CONTRACT_MONITORING_SERVICE, CONTRACT_ONE_TO_N, CONTRACT_USER_DEPOSIT, ]: test_missing_deployment(contract_name)
def deployed_service_info( deployer: ContractDeployer, token_address: HexAddress, token_network_registry_contract: Contract, ) -> DeployedContracts: return deployer.deploy_service_contracts( token_address=token_address, user_deposit_whole_balance_limit=DEPOSIT_LIMIT, service_registry_controller=DEPLOYER_ADDRESS, initial_service_deposit_price=SERVICE_DEPOSIT // 2, service_deposit_bump_numerator=6, service_deposit_bump_denominator=5, decay_constant=200 * SECONDS_PER_DAY, min_price=1000, registration_duration=180 * SECONDS_PER_DAY, token_network_registry_address=token_network_registry_contract.address, )
def test_deploy_script_token(web3: Web3) -> None: """Run test token deployment function used in the deployment script This checks if deploy_token_contract() works correctly in the happy case, to make sure no code dependencies have been changed, affecting the deployment script. This does not check however that the cli command works correctly. """ # normal deployment token_type = "CustomToken" gas_limit = 5860000 deployer = ContractDeployer( web3=web3, private_key=FAUCET_PRIVATE_KEY, gas_limit=gas_limit, gas_price=1, wait=10, ) deployed_token = deployer.deploy_token_contract( token_supply=10000000, token_decimals=18, token_name="TestToken", token_symbol="TTT", token_type=token_type, ) assert deployed_token[token_type] is not None assert isinstance(deployed_token[token_type], str) # check that it fails if sender has no eth deployer = ContractDeployer( web3=web3, private_key=get_random_privkey(), gas_limit=gas_limit, gas_price=1, wait=10, ) with pytest.raises(ValidationError): deployer.deploy_token_contract( token_supply=10000000, token_decimals=18, token_name="TestToken", token_symbol="TTT", token_type="CustomToken", )
def test_deploy_raiden_reuse_secret_registry( deployer: ContractDeployer, deployed_raiden_info: DeployedContracts) -> None: """Run deploy_raiden_contracts with a previous SecretRegistry deployment data""" with NamedTemporaryFile() as previous_deployment_file: previous_deployment_file.write( bytearray(json.dumps(deployed_raiden_info), "ascii")) previous_deployment_file.flush() new_deployment = deployer.deploy_raiden_contracts( 1, reuse_secret_registry_from_deploy_file=Path( previous_deployment_file.name), settle_timeout_min=DEPLOY_SETTLE_TIMEOUT_MIN, settle_timeout_max=DEPLOY_SETTLE_TIMEOUT_MAX, ) assert (new_deployment["contracts"][CONTRACT_SECRET_REGISTRY] == deployed_raiden_info["contracts"][CONTRACT_SECRET_REGISTRY]) assert ( new_deployment["contracts"][CONTRACT_TOKEN_NETWORK_REGISTRY] != deployed_raiden_info["contracts"][CONTRACT_TOKEN_NETWORK_REGISTRY])
def test_store_and_verify_services(fs_reload_deployer, web3, custom_token_factory): """ Store some service contract deployment information and verify them """ fs_reload_deployer.add_real_directory( contracts_precompiled_path(version=None, ).parent) gas_limit = 5860000 deployer = ContractDeployer( web3=web3, private_key=FAUCET_PRIVATE_KEY, gas_limit=gas_limit, gas_price=1, wait=10, contracts_version=None, ) token_address = custom_token_factory().address whole_limit = 3000 deployed_contracts_info = deploy_service_contracts( deployer=deployer, token_address=token_address, user_deposit_whole_balance_limit=whole_limit, ) store_and_verify_deployment_info_services( token_address=token_address, contracts_version=None, deployer=deployer, deployed_contracts_info=deployed_contracts_info, save_info=False, user_deposit_whole_limit=whole_limit, ) store_and_verify_deployment_info_services( token_address=token_address, contracts_version=None, deployer=deployer, deployed_contracts_info=deployed_contracts_info, save_info=True, user_deposit_whole_limit=whole_limit, )
def test_deploy_script_register_without_limit( token_address: HexAddress, deployer_0_4_0: ContractDeployer, deployed_raiden_info_0_4_0: DeployedContracts, ) -> None: """ Run token register function used in the deployment script This checks if register_token_network() works correctly in the happy case for 0.4.0 version, to make sure no code dependencies have been changed, affecting the deployment script. This does not check however that the cli command works correctly. """ token_registry_abi = deployer_0_4_0.contract_manager.get_contract_abi( CONTRACT_TOKEN_NETWORK_REGISTRY) token_registry_address = deployed_raiden_info_0_4_0["contracts"][ CONTRACT_TOKEN_NETWORK_REGISTRY]["address"] token_network_address = deployer_0_4_0.register_token_network( token_registry_abi=token_registry_abi, token_registry_address=token_registry_address, token_address=token_address, channel_participant_deposit_limit=None, token_network_deposit_limit=None, ) assert token_network_address is not None assert isinstance(token_network_address, str)
def test_deploy_script_register_missing_limits( token_network_deposit_limit: int, channel_participant_deposit_limit: int, deployed_raiden_info: DeployedContracts, token_address: HexAddress, deployer: ContractDeployer, ) -> None: """ Run token register function used in the deployment script without the expected channel participant deposit limit. """ token_registry_abi = deployer.contract_manager.get_contract_abi( CONTRACT_TOKEN_NETWORK_REGISTRY) token_registry_address = deployed_raiden_info["contracts"][ CONTRACT_TOKEN_NETWORK_REGISTRY]["address"] with pytest.raises(ValueError): deployer.register_token_network( token_registry_abi=token_registry_abi, token_registry_address=token_registry_address, token_address=token_address, channel_participant_deposit_limit=None, token_network_deposit_limit=token_network_deposit_limit, ) with pytest.raises(ValueError): deployer.register_token_network( token_registry_abi=token_registry_abi, token_registry_address=token_registry_address, token_address=token_address, channel_participant_deposit_limit=channel_participant_deposit_limit, token_network_deposit_limit=None, ) with pytest.raises(ValueError): deployer.register_token_network( token_registry_abi=token_registry_abi, token_registry_address=token_registry_address, token_address=token_address, channel_participant_deposit_limit=None, token_network_deposit_limit=None, )
def deployed_raiden_info_0_4_0( deployer_0_4_0: ContractDeployer) -> DeployedContracts: return deployer_0_4_0.deploy_raiden_contracts( max_num_of_token_networks=None)
def deployed_raiden_info(deployer: ContractDeployer) -> DeployedContracts: return deployer.deploy_raiden_contracts(max_num_of_token_networks=1)
def test_deploy_script_service(web3: Web3, deployed_service_info: DeployedContracts, token_address: HexAddress) -> None: """ Run deploy_service_contracts() used in the deployment script This checks if deploy_service_contracts() works correctly in the happy case. """ gas_limit = 5860000 deployer = ContractDeployer(web3=web3, private_key=FAUCET_PRIVATE_KEY, gas_limit=gas_limit, gas_price=1, wait=10) token_supply = 10000000 assert isinstance(token_address, str) deposit_limit = token_supply // 2 deployed_service_contracts = deployed_service_info deployer.verify_service_contracts_deployment_data( token_address=token_address, user_deposit_whole_balance_limit=deposit_limit, deployed_contracts_info=deployed_service_contracts, ) with pytest.raises(RuntimeError): assert EMPTY_ADDRESS != token_address deployer.verify_service_contracts_deployment_data( token_address=EMPTY_ADDRESS, user_deposit_whole_balance_limit=deposit_limit, deployed_contracts_info=deployed_service_contracts, ) deployed_info_fail = deepcopy(deployed_service_contracts) deployed_info_fail["contracts_version"] = "0.0.0" with pytest.raises(RuntimeError): deployer.verify_service_contracts_deployment_data( token_address=token_address, user_deposit_whole_balance_limit=deposit_limit, deployed_contracts_info=deployed_info_fail, ) deployed_info_fail = deepcopy(deployed_service_contracts) deployed_info_fail["chain_id"] = deployed_service_contracts["chain_id"] + 1 with pytest.raises(RuntimeError): deployer.verify_service_contracts_deployment_data( token_address=token_address, user_deposit_whole_balance_limit=deposit_limit, deployed_contracts_info=deployed_info_fail, ) deployed_info_fail = deepcopy(deployed_service_contracts) deployed_info_fail["contracts"][CONTRACT_SERVICE_REGISTRY][ "constructor_arguments"] = [EMPTY_ADDRESS] with pytest.raises(RuntimeError): deployer.verify_service_contracts_deployment_data( token_address=token_address, user_deposit_whole_balance_limit=deposit_limit, deployed_contracts_info=deployed_info_fail, ) deployed_info_fail = deepcopy(deployed_service_contracts) original = deployed_info_fail["contracts"][CONTRACT_USER_DEPOSIT][ "constructor_arguments"] deployed_info_fail["contracts"][CONTRACT_USER_DEPOSIT][ "constructor_arguments"] += original with pytest.raises(RuntimeError): deployer.verify_service_contracts_deployment_data( token_address=token_address, user_deposit_whole_balance_limit=deposit_limit, deployed_contracts_info=deployed_info_fail, ) deployed_info_fail = deepcopy(deployed_service_contracts) deployed_info_fail["contracts"][CONTRACT_USER_DEPOSIT][ "constructor_arguments"][0] = EMPTY_ADDRESS with pytest.raises(RuntimeError): deployer.verify_service_contracts_deployment_data( token_address=token_address, user_deposit_whole_balance_limit=deposit_limit, deployed_contracts_info=deployed_info_fail, ) deployed_info_fail = deepcopy(deployed_service_contracts) deployed_info_fail["contracts"][CONTRACT_USER_DEPOSIT][ "constructor_arguments"][1] = (deposit_limit + 1) with pytest.raises(RuntimeError): deployer.verify_service_contracts_deployment_data( token_address=token_address, user_deposit_whole_balance_limit=deposit_limit, deployed_contracts_info=deployed_info_fail, ) deployed_info_fail = deepcopy(deployed_service_contracts) original = deployed_info_fail["contracts"][CONTRACT_MONITORING_SERVICE][ "constructor_arguments"] deployed_info_fail["contracts"][CONTRACT_MONITORING_SERVICE][ "constructor_arguments"] += original with pytest.raises(RuntimeError): deployer.verify_service_contracts_deployment_data( token_address=token_address, user_deposit_whole_balance_limit=deposit_limit, deployed_contracts_info=deployed_info_fail, ) deployed_info_fail = deepcopy(deployed_service_contracts) deployed_info_fail["contracts"][CONTRACT_MONITORING_SERVICE][ "constructor_arguments"][0] = EMPTY_ADDRESS with pytest.raises(RuntimeError): deployer.verify_service_contracts_deployment_data( token_address=token_address, user_deposit_whole_balance_limit=deposit_limit, deployed_contracts_info=deployed_info_fail, ) deployed_info_fail = deepcopy(deployed_service_contracts) deployed_info_fail["contracts"][CONTRACT_MONITORING_SERVICE][ "constructor_arguments"][2] = EMPTY_ADDRESS with pytest.raises(RuntimeError): deployer.verify_service_contracts_deployment_data( token_address=token_address, user_deposit_whole_balance_limit=deposit_limit, deployed_contracts_info=deployed_info_fail, ) deployed_info_fail = deepcopy(deployed_service_contracts) deployed_info_fail["contracts"][CONTRACT_ONE_TO_N][ "constructor_arguments"][0] = EMPTY_ADDRESS with pytest.raises(RuntimeError): deployer.verify_service_contracts_deployment_data( token_address=token_address, user_deposit_whole_balance_limit=deposit_limit, deployed_contracts_info=deployed_info_fail, ) deployed_info_fail = deepcopy(deployed_service_contracts) deployed_info_fail["contracts"][CONTRACT_ONE_TO_N][ "constructor_arguments"][1] = EMPTY_ADDRESS with pytest.raises(RuntimeError): deployer.verify_service_contracts_deployment_data( token_address=token_address, user_deposit_whole_balance_limit=deposit_limit, deployed_contracts_info=deployed_info_fail, ) deployed_info_fail = deepcopy(deployed_service_contracts) original = deployed_info_fail["contracts"][CONTRACT_ONE_TO_N][ "constructor_arguments"] deployed_info_fail["contracts"][CONTRACT_ONE_TO_N][ "constructor_arguments"] += original with pytest.raises(RuntimeError): deployer.verify_service_contracts_deployment_data( token_address=token_address, user_deposit_whole_balance_limit=deposit_limit, deployed_contracts_info=deployed_info_fail, ) def test_missing_deployment(contract_name: str) -> None: deployed_info_fail = deepcopy(deployed_service_contracts) deployed_info_fail["contracts"][contract_name][ "address"] = EMPTY_ADDRESS with pytest.raises(RuntimeError): deployer.verify_service_contracts_deployment_data( token_address=token_address, user_deposit_whole_balance_limit=deposit_limit, deployed_contracts_info=deployed_info_fail, ) for contract_name in [ CONTRACT_SERVICE_REGISTRY, CONTRACT_MONITORING_SERVICE, CONTRACT_ONE_TO_N, CONTRACT_USER_DEPOSIT, ]: test_missing_deployment(contract_name)
def test_deploy_script_raiden( web3, version: Optional[str], max_num_of_token_networks: Optional[int], deployer, deployed_raiden_info, ): """ Run raiden contracts deployment function and tamper with deployed_contracts_info This checks if deploy_raiden_contracts() works correctly in the happy case, to make sure no code dependencies have been changed, affecting the deployment script. This does not check however that the cli command works correctly. This also tampers with deployed_contracts_info to make sure an error is raised in verify_deployed_contracts() """ deployed_contracts_info = deployed_raiden_info deployer._verify_deployment_data( deployment_data=deployed_contracts_info, ) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail['contracts_version'] = '0.0.0' with pytest.raises(AssertionError): deployer._verify_deployment_data( deployment_data=deployed_contracts_info_fail, ) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail['chain_id'] = 0 with pytest.raises(AssertionError): deployer._verify_deployment_data( deployment_data=deployed_contracts_info_fail, ) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail['contracts'][ CONTRACT_ENDPOINT_REGISTRY ]['address'] = EMPTY_ADDRESS with pytest.raises(AssertionError): deployer._verify_deployment_data( deployed_contracts_info_fail, ) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail['contracts'][CONTRACT_SECRET_REGISTRY]['address'] = EMPTY_ADDRESS with pytest.raises(AssertionError): deployer._verify_deployment_data( deployed_contracts_info_fail, ) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail['contracts'][ CONTRACT_TOKEN_NETWORK_REGISTRY ]['address'] = EMPTY_ADDRESS with pytest.raises(AssertionError): deployer._verify_deployment_data( deployed_contracts_info_fail, ) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail['contracts'][CONTRACT_ENDPOINT_REGISTRY]['block_number'] = 0 with pytest.raises(AssertionError): deployer._verify_deployment_data( deployed_contracts_info_fail, ) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail['contracts'][CONTRACT_SECRET_REGISTRY]['block_number'] = 0 with pytest.raises(AssertionError): deployer._verify_deployment_data( deployed_contracts_info_fail, ) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail['contracts'][CONTRACT_TOKEN_NETWORK_REGISTRY]['block_number'] = 0 with pytest.raises(AssertionError): deployer._verify_deployment_data( deployed_contracts_info_fail, ) # check that it fails if sender has no eth deployer = ContractDeployer( web3=web3, private_key=get_random_privkey(), gas_limit=GAS_LIMIT, gas_price=1, wait=10, ) with pytest.raises(ValidationError): deploy_raiden_contracts(deployer, 1)
def test_deploy_script_raiden(web3: Web3, deployer: ContractDeployer, deployed_raiden_info: DeployedContracts) -> None: """ Run raiden contracts deployment function and tamper with deployed_contracts_info This checks if deploy_raiden_contracts() works correctly in the happy case, to make sure no code dependencies have been changed, affecting the deployment script. This does not check however that the cli command works correctly. This also tampers with deployed_contracts_info to make sure an error is raised in verify_deployed_contracts() """ deployed_contracts_info = deployed_raiden_info deployer.verify_deployment_data(deployment_data=deployed_contracts_info) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail["contracts_version"] = "0.0.0" with pytest.raises(RuntimeError): deployer.verify_deployment_data( deployment_data=deployed_contracts_info_fail) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail["chain_id"] = 0 with pytest.raises(RuntimeError): deployer.verify_deployment_data( deployment_data=deployed_contracts_info_fail) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail["contracts"][CONTRACT_SECRET_REGISTRY][ "address"] = EMPTY_ADDRESS with pytest.raises(RuntimeError): deployer.verify_deployment_data(deployed_contracts_info_fail) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail["contracts"][CONTRACT_SECRET_REGISTRY][ "address"] = EMPTY_ADDRESS with pytest.raises(RuntimeError): deployer.verify_deployment_data(deployed_contracts_info_fail) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail["contracts"][CONTRACT_TOKEN_NETWORK_REGISTRY][ "address"] = EMPTY_ADDRESS with pytest.raises(RuntimeError): deployer.verify_deployment_data(deployed_contracts_info_fail) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail["contracts"][CONTRACT_SECRET_REGISTRY][ "block_number"] = 0 with pytest.raises(RuntimeError): deployer.verify_deployment_data(deployed_contracts_info_fail) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail["contracts"][CONTRACT_SECRET_REGISTRY][ "block_number"] = 0 with pytest.raises(RuntimeError): deployer.verify_deployment_data(deployed_contracts_info_fail) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail["contracts"][CONTRACT_TOKEN_NETWORK_REGISTRY][ "block_number"] = 0 with pytest.raises(RuntimeError): deployer.verify_deployment_data(deployed_contracts_info_fail) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail["contracts"][CONTRACT_TOKEN_NETWORK_REGISTRY][ "gas_cost"] = 0 with pytest.raises(RuntimeError): deployer.verify_deployment_data(deployed_contracts_info_fail) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail["contracts"][CONTRACT_TOKEN_NETWORK_REGISTRY][ "address"] = EMPTY_ADDRESS with pytest.raises(RuntimeError): deployer.verify_deployment_data(deployed_contracts_info_fail) deployed_contracts_info_fail = deepcopy(deployed_contracts_info) deployed_contracts_info_fail["contracts_version"] = "0.4.0" with pytest.raises(RuntimeError): deployer.verify_deployment_data(deployed_contracts_info_fail) # check that it fails if sender has no eth deployer = ContractDeployer(web3=web3, private_key=get_random_privkey(), gas_limit=GAS_LIMIT, gas_price=1, wait=10) with pytest.raises(ValidationError): deployer.deploy_raiden_contracts(1)
def deployed_service_info(deployer: ContractDeployer, token_address: HexAddress) -> DeployedContracts: return deployer.deploy_service_contracts( token_address=token_address, user_deposit_whole_balance_limit=DEPOSIT_LIMIT)