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 deprecation_test_setup(deployer, token_amount): deployed_contracts = deploy_raiden_contracts(deployer)['contracts'] token_network_registry_abi = deployer.contract_manager.get_contract_abi( CONTRACT_TOKEN_NETWORK_REGISTRY, ) token_network_registry = deployer.web3.eth.contract( abi=token_network_registry_abi, address=deployed_contracts[CONTRACT_TOKEN_NETWORK_REGISTRY]['address'], ) token_decimals = 18 multiplier = 10**token_decimals token_supply = 10**6 * multiplier token_amount = int(token_amount * multiplier) deployed_token = deploy_token_contract( deployer, token_supply, token_decimals, 'TestToken', 'TTT', CONTRACT_CUSTOM_TOKEN, ) token_address = deployed_token[CONTRACT_CUSTOM_TOKEN] token_abi = deployer.contract_manager.get_contract_abi( CONTRACT_CUSTOM_TOKEN) token_contract = deployer.web3.eth.contract( abi=token_abi, address=token_address, ) # Mint some tokens for the owner txhash = token_contract.functions.mint(token_amount).transact( deployer.transaction, ) log.debug(f'Minting tokens txHash={encode_hex(txhash)}') check_succesful_tx(deployer.web3, txhash, deployer.wait) assert token_contract.functions.balanceOf( deployer.owner).call() >= token_amount abi = deployer.contract_manager.get_contract_abi( CONTRACT_TOKEN_NETWORK_REGISTRY) token_network_address = register_token_network( web3=deployer.web3, caller=deployer.owner, token_registry_abi=abi, token_registry_address=deployed_contracts[ CONTRACT_TOKEN_NETWORK_REGISTRY]['address'], token_address=token_address, wait=deployer.wait, ) token_network_abi = deployer.contract_manager.get_contract_abi( CONTRACT_TOKEN_NETWORK) token_network = deployer.web3.eth.contract( abi=token_network_abi, address=token_network_address, ) log.info( f'Registered the token and created a TokenNetwork contract at {token_network_address}.', ) txhash = token_contract.functions.approve(token_network.address, token_amount).transact( deployer.transaction, ) log.debug( f'Approving tokens for the TokenNetwork contract txHash={encode_hex(txhash)}' ) check_succesful_tx(deployer.web3, txhash, deployer.wait) assert token_contract.functions.allowance( deployer.owner, token_network.address, ).call() >= token_amount log.info( f'Approved {token_amount} tokens for the TokenNetwork contract ' f'from owner {deployer.owner}.', ) return (token_network_registry, token_network, token_contract)
def main(keystore_file: str, password: str, rpc_url: str, development: bool): web3 = Web3(HTTPProvider(rpc_url, request_kwargs={'timeout': 60})) web3.middleware_stack.inject(geth_poa_middleware, layer=0) contract_version = '0.4.0' channel_participant_deposit_limit = None token_network_deposit_limit = None max_num_of_networks = None if development: contract_version = None channel_participant_deposit_limit = UNLIMITED token_network_deposit_limit = UNLIMITED max_num_of_networks = 500 with open(keystore_file, 'r') as keystore: encrypted_key = keystore.read() private_key = web3.eth.account.decrypt(encrypted_key, password) account = Account.privateKeyToAccount(private_key) if private_key is None: print('No private key found') exit(1) owner = account.address if web3.eth.getBalance(owner) == 0: print('Account with insuficient funds.') exit(1) deployer = ContractDeployer( web3=web3, private_key=private_key, gas_limit=GAS_LIMIT, gas_price=GAS_PRICE, wait=10, contracts_version=contract_version, ) print('Deploying raiden contracts') deployed_contract_info = deploy_raiden_contracts( deployer=deployer, max_num_of_token_networks=max_num_of_networks, ) deployed_contracts = { contract_name: info['address'] for contract_name, info in deployed_contract_info['contracts'].items() } print('Deploying test token contract') tokens = TOKEN_SUPPLY * (10**TOKEN_DECIMALS) deployed_token = deploy_token_contract(deployer, tokens, TOKEN_DECIMALS, 'TestToken', 'TTT') abi = deployer.contract_manager.get_contract_abi( CONTRACT_TOKEN_NETWORK_REGISTRY) token_address = deployed_token['CustomToken'] expected_version = contract_version_string( deployer.contract_version_string()) print('Registering test token contract') register_token_network( web3=web3, caller=deployer.owner, token_registry_abi=abi, token_registry_address=deployed_contracts[ CONTRACT_TOKEN_NETWORK_REGISTRY], token_address=token_address, token_registry_version=expected_version, channel_participant_deposit_limit=channel_participant_deposit_limit, token_network_deposit_limit=token_network_deposit_limit, contracts_version=deployer.contract_version_string(), ) print(f'Token Deployed at: {token_address}') print(json.dumps(deployed_contracts, indent=4)) print('done')