def chain_fixture(scope="module"): # create a new account and fill it with some money ACCOUNT = Account.generate() ACCOUNT_1 = Account.generate() # used by for oracles # set the key folder as environment variables genesis = Account.from_private_key_string(PRIVATE_KEY) # Instantiate the node client for the tests NODE_CLI = NodeClient(Config( external_url=NODE_URL, internal_url=NODE_URL_DEBUG, # network_id=NETWORK_ID, blocking_mode=True, debug=True, )) NODE_CLI.spend(genesis, ACCOUNT.get_address(), 5000000000000000000000) # 5000AE a = NODE_CLI.get_account_by_pubkey(pubkey=ACCOUNT.get_address()) print(f"Test account is {ACCOUNT.get_address()} with balance {a.balance}") NODE_CLI.spend(genesis, ACCOUNT_1.get_address(), 5000000000000000000000) # 5000AE a = NODE_CLI.get_account_by_pubkey(pubkey=ACCOUNT_1.get_address()) print(f"Test account (1) is {ACCOUNT_1.get_address()} with balance {a.balance}") return namedtupled.map({"NODE_CLI": NODE_CLI, "ALICE": ACCOUNT, "BOB": ACCOUNT_1}, _nt_name="TestData")
def test_signing_get_address(): a = Account.from_private_key_string( '3960180c89e27fcc1559f631d664a4b56b569aa5768ba827ddc9ba9616fecd9d8134464ef14b1433790e259d40b6ad8ca39f397a2bbc5261eeba1018a67ce35a') assert(a.get_address() == 'ak_yuMB5S3yiTwRVJC1NcNEGppcGAbq26qFWNJTCJWnLqoihCpCG') assert(a.get_address(format=identifiers.ACCOUNT_API_FORMAT) == 'ak_yuMB5S3yiTwRVJC1NcNEGppcGAbq26qFWNJTCJWnLqoihCpCG') assert(a.get_address(format=identifiers.ACCOUNT_API_FORMAT) != 'ak_xuMB5S3yiTwRVJC1NcNEGppcGAbq26qFWNJTCJWnLqoihCpCG') assert(a.get_address(format=identifiers.ACCOUNT_SOFIA_FORMAT) == '0x8134464ef14b1433790e259d40b6ad8ca39f397a2bbc5261eeba1018a67ce35a') assert(a.get_address(format=identifiers.ACCOUNT_SOFIA_FORMAT) != '8134464ef14b1433790e259d40b6ad8ca39f397a2bbc5261eeba1018a67ce35a') assert(a.get_address(format=identifiers.ACCOUNT_RAW_FORMAT) == b'\x814FN\xf1K\x143y\x0e%\x9d@\xb6\xad\x8c\xa3\x9f9z+\xbcRa\xee\xba\x10\x18\xa6|\xe3Z') assert(a.get_address(format=identifiers.ACCOUNT_RAW_FORMAT) != b'\x814FN\xf1K\x143y\x0e%\x9d@\xb6\x00\x8c\xa3\x9f9z+\xbcRa\xee\xba\x10\x18\xa6|\xe3Z')
def rest_faucet(recipient_address): """top up an account""" amount = int(os.environ.get('TOPUP_AMOUNT', 250)) ttl = int(os.environ.get('TX_TTL', 100)) try: # validate the address logging.info(f"Top up request for {recipient_address}") if not is_valid_hash(recipient_address, prefix='ak'): return jsonify({"message": "The provided account is not valid"}), 400 # genesys key bank_wallet_key = os.environ.get('FAUCET_ACCOUNT_PRIV_KEY') kp = Account.from_private_key_string(bank_wallet_key) # target node Config.set_defaults( Config( external_url=os.environ.get('EPOCH_URL', "https://sdk-testnet.aepps.com"), internal_url=os.environ.get('EPOCH_URL_DEBUG', "https://sdk-testnet.aepps.com"), network_id=os.environ.get('NETWORK_ID', "ae_devnet"), )) # payload payload = os.environ.get('TX_PAYLOAD', "Faucet Tx") # execute the spend transaction client = EpochClient() _, _, _, tx = client.spend(kp, recipient_address, amount, payload=payload, tx_ttl=ttl) balance = client.get_account_by_pubkey( pubkey=recipient_address).balance logging.info( f"Top up accont {recipient_address} of {amount} tx_ttl: {ttl} tx_hash: {tx} completed" ) # telegram bot notifications enable_telegaram = os.environ.get('TELEGRAM_API_TOKEN', False) if enable_telegaram: token = os.environ.get('TELEGRAM_API_TOKEN', None) chat_id = os.environ.get('TELEGRAM_CHAT_ID', None) node = os.environ.get('EPOCH_URL', "https://sdk-testnet.aepps.com").replace( "https://", "") if token is None or chat_id is None: logging.warning( f"missing chat_id ({chat_id}) or token {token} for telegram integration" ) bot = telegram.Bot(token=token) bot.send_message( chat_id=chat_id, text= f"Account `{recipient_address}` credited with {amount} tokens on `{node}`. (tx hash: `{tx}`)", parse_mode=telegram.ParseMode.MARKDOWN) return jsonify({"tx_hash": tx, "balance": balance}) except OpenAPIClientException as e: logging.error( f"Api error: top up accont {recipient_address} of {amount} failed with error", e) return jsonify({ "message": "The node is temporarily unavailable, contact aepp-dev[at]aeternity.com" }), 503 except Exception as e: logging.error( f"Generic error: top up accont {recipient_address} of {amount} failed with error", e) return jsonify({ "message": "Unknow error, please contact contact aepp-dev[at]aeternity.com" }), 500