def test_account_identifier(): account = LocalAccount() assert account.account_identifier() == identifier.encode_account( account.account_address, None, account.hrp) subaddress = identifier.gen_subaddress() assert account.account_identifier(subaddress) == identifier.encode_account( account.account_address, subaddress, account.hrp)
def test_generate_keys(): account = LocalAccount() sig1 = account.private_key.sign(b"test") sig2 = account.compliance_key.sign(b"test") load_account = LocalAccount.from_dict(account.to_dict()) assert sig1 == load_account.private_key.sign(b"test") assert sig2 == load_account.compliance_key.sign(b"test")
def test_decode_account_identifier(): account = LocalAccount() id1 = account.account_identifier() address, subaddress = account.decode_account_identifier(id1) assert address == account.account_address assert subaddress is None subaddress = identifier.gen_subaddress() id2 = account.account_identifier(subaddress) address, subaddress = account.decode_account_identifier(id2) assert address == account.account_address assert subaddress == subaddress
if currency_balance > threshold_amount: print(f"which is enough!") else: print(f"need to refill...") if network_chainid == testnet.CHAIN_ID.value and private_key is None: print( f"running in TESTNET, using faucet to mint {refill_amount} {currency}... ", ) faucet = testnet.Faucet(diem_client) faucet.mint(auth_key, refill_amount, currency) else: # use DD private key to send P2P transaction to the watched account sender_account = LocalAccount( Ed25519PrivateKey.from_private_bytes( bytes.fromhex(private_key))) sender_account_info = diem_client.get_account( sender_account.account_address) sender_account_addr_hex = utils.account_address_hex( sender_account.account_address) script = stdlib.encode_peer_to_peer_with_metadata_script( currency=utils.currency_code(currency), payee=watched_account_addr, amount=refill_amount, metadata=txnmetadata.general_metadata( from_subaddress=utils.account_address_bytes( sender_account.account_address), to_subaddress=utils.account_address_bytes( watched_account_addr),
def create_account(key): return LocalAccount(Ed25519PrivateKey.from_private_bytes(bytes.fromhex(key)))
def get_account(cls, account_name: str = _DEFAULT_ACCOUNT_NAME) -> LocalAccount: return LocalAccount( Ed25519PrivateKey.from_private_bytes(cls._accounts[account_name]))