def test_find_by_public_key_returns_a_new_wallet_if_does_not_exist(redis): address = "AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof" key = "wallets:address:{}".format(address).encode() public_key = "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325" manager = WalletManager() wallet = manager.find_by_public_key(public_key) assert wallet.address == address assert wallet.public_key == public_key # find_by_public_key saves the wallet as it adds public_key to it keys = redis.keys("*") assert keys == [key]
def test_find_by_public_key_returns_existing_wallet(redis): address = "AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof" public_key = "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325" key = "wallets:address:{}".format(address).encode() manager = WalletManager() redis.set(key, Wallet({"address": address, "public_key": public_key}).to_json()) wallet = manager.find_by_public_key(public_key) assert wallet.address == address assert wallet.public_key == public_key keys = redis.keys("*") assert keys == [key]