def test_set_fee_cache_time(): original = bit.network.fees.DEFAULT_CACHE_TIME set_fee_cache_time(30) updated = bit.network.fees.DEFAULT_CACHE_TIME assert original != updated assert updated == 30 set_fee_cache_time(original)
def test_hour(self): sleep(0.2) start_time = time() set_fee_cache_time(0) get_fee_cached(fast=False) initial_time = time() - start_time start_time = time() set_fee_cache_time(600) get_fee_cached(fast=False) cached_time = time() - start_time assert initial_time > cached_time
def test_expires(self): sleep(0.2) set_fee_cache_time(0) get_fee_cached() start_time = time() set_fee_cache_time(600) get_fee_cached() cached_time = time() - start_time sleep(0.2) start_time = time() set_fee_cache_time(0.1) get_fee_cached() update_time = time() - start_time assert update_time > cached_time
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 return self._response()