tw.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. from .tw_orig import *
  2. if os.getenv('MMGEN_TEST_SUITE_DETERMINISTIC'):
  3. def _time_gen():
  4. """ add a minute to each successive time value """
  5. for i in range(1000000):
  6. yield 1321009871 + (i*60)
  7. _time_iter = _time_gen()
  8. TwUnspentOutputs.date_formatter = {
  9. 'days': lambda rpc,secs: (next(_time_iter) - secs) // 86400,
  10. 'date': lambda rpc,secs: '{}-{:02}-{:02}'.format(*time.gmtime(next(_time_iter))[:3])[2:],
  11. 'date_time': lambda rpc,secs: '{}-{:02}-{:02} {:02}:{:02}'.format(*time.gmtime(next(_time_iter))[:5]),
  12. }
  13. TwAddrList.date_formatter = TwUnspentOutputs.date_formatter
  14. if os.getenv('MMGEN_BOGUS_WALLET_DATA'):
  15. # 1831006505 (09 Jan 2028) = projected time of block 1000000
  16. TwUnspentOutputs.date_formatter['days'] = lambda rpc,secs: (1831006505 - secs) // 86400
  17. async def fake_set_dates(foo,rpc,us):
  18. for o in us:
  19. o.date = 1831006505 - int(9.7 * 60 * (o.confs - 1))
  20. async def fake_get_unspent_rpc(foo):
  21. return json.loads(get_data_from_file(os.getenv('MMGEN_BOGUS_WALLET_DATA')),parse_float=Decimal)
  22. TwUnspentOutputs.set_dates = fake_set_dates
  23. TwUnspentOutputs.get_unspent_rpc = fake_get_unspent_rpc