Esempio n. 1
0
def test_eth_ticker(
        empty_proxy: PaywalledProxy,
        session: Session,
        sender_privkey: str,
        receiver_privkey: str,
        monkeypatch: MonkeyPatch
):
    def get_patched(*args, **kwargs):
        body = {
            'mid': '682.435', 'bid': '682.18', 'ask': '682.69', 'last_price': '683.16',
            'low': '532.97', 'high': '684.0', 'volume': '724266.25906224',
            'timestamp': '1513167820.721733'
        }
        return jsonify(body)

    monkeypatch.setattr(PaywalledProxyUrl, 'get', get_patched)

    ETHTickerProxy(receiver_privkey, proxy=empty_proxy)
    ticker = ETHTickerClient(sender_privkey, session=session, poll_interval=0.5)

    def post():
        ticker.close()

        assert ticker.pricevar.get() == '683.16 USD'
        assert len(session.client.get_open_channels()) == 0
        ticker.success = True

    session.close_channel_on_exit = True
    ticker.success = False
    ticker.root.after(1500, post)
    ticker.run()
    assert ticker.success
Esempio n. 2
0
def test_eth_ticker(
    doggo_proxy: PaywalledProxy,
    default_http_client: DefaultHTTPClient,
    sender_privkey: str,
    receiver_privkey: str,
):
    proxy = ETHTickerProxy(receiver_privkey, proxy=doggo_proxy)
    ticker = ETHTickerClient(sender_privkey, httpclient=default_http_client)

    def post():
        ticker.close()
        proxy.stop()

        # This test fails if ETH price is below 100 USD. But why even bother anymore if it does?
        assert float(ticker.pricevar.get().split()[0]) > 100
        client = default_http_client.client
        assert len(client.get_open_channels()) == 0

    ticker.root.after(6000, post)
    ticker.run()