def test_set_rate_cache_time(): original = bit.network.rates.DEFAULT_CACHE_TIME set_rate_cache_time(30) updated = bit.network.rates.DEFAULT_CACHE_TIME assert original != updated assert updated == 30 set_rate_cache_time(original)
def test_cache(self): sleep(0.2) start_time = time() set_rate_cache_time(0) currency_to_satoshi_cached(1, 'usd') initial_time = time() - start_time start_time = time() set_rate_cache_time(60) currency_to_satoshi_cached(1, 'usd') cached_time = time() - start_time assert initial_time > cached_time
def test_expires(self): sleep(0.2) set_rate_cache_time(0) currency_to_satoshi_cached(1, 'usd') start_time = time() set_rate_cache_time(60) currency_to_satoshi_cached(1, 'usd') cached_time = time() - start_time sleep(0.2) start_time = time() set_rate_cache_time(0.1) currency_to_satoshi_cached(1, 'usd') update_time = time() - start_time assert update_time > cached_time
import json import requests from common.base_view import BaseView from common import error_msg from common.mylog import logger from bit.network import NetworkAPI from bit.network import get_fee_cached from bit.network import satoshi_to_currency_cached from bit.network import currency_to_satoshi_cached from bit.network.rates import set_rate_cache_time from bit.network.fees import set_fee_cache_time CACHE_TIME = 12 * 60 * 60 set_rate_cache_time(CACHE_TIME) set_fee_cache_time(CACHE_TIME) class BtcView(BaseView): URL = "https://blockchain.info/zh-cn/" def post_action_broadcast(self): if not self.check_input_arguments(["tx_hex"]): return self._response(error_msg.PARAMS_ERROR) try: NetworkAPI.broadcast_tx(self._input.get("tx_hex", None)) except Exception as e: logger.error("broadcast_tx error tx:{0}. error:{1}".format( self._input.get("tx_hex"), e)) self._ret, self._msg = 50001, e