Exemplo n.º 1
0
 def setUp(self):
     super().setUp()
     constants.set_regtest()
     self.data_dir = tempfile.mkdtemp()
     make_dir(os.path.join(self.data_dir, 'forks'))
     self.config = SimpleConfig({'electrum_path': self.data_dir})
     blockchain.blockchains = {}
Exemplo n.º 2
0
    def setUpClass(cls):
        super().setUpClass()
        constants.set_regtest()

        data_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                 "blockchain.json")
        with open(data_file) as f:
            cls.DATA = json.load(f)

        cls.HEADERS = {}
        for i in cls.DATA:
            cls.HEADERS[i] = deserialize_full_header(
                bfh(cls.DATA[i]["header_hex"]), None)
            cls.HEADERS[i]["block_height"] = cls.DATA[i]["height"]
Exemplo n.º 3
0
 def start(self):
     self.logger.info("start")
     user_config = {
         "auto_connect": False,
         "oneserver": True,
         "server": "localhost:" + str(self.electrumx.tcp_port) + ":t",
         "request_initial_sync": False,
         "lightning_listen": "127.0.0.1:" + str(self.port),
     }
     config = simple_config.SimpleConfig(
         user_config, read_user_dir_function=lambda: self.directory)
     constants.set_regtest()
     self.actual = Daemon(config)
     assert self.actual.network.asyncio_loop.is_running()
     wallet_path = self.actual.cmd_runner.create(segwit=True)['path']
     storage = WalletStorage(wallet_path)
     wallet = Wallet(storage)
     wallet.start_network(self.actual.network)
     self.actual.add_wallet(wallet)
Exemplo n.º 4
0
 def setUpClass(cls):
     super().setUpClass()
     constants.set_regtest()
Exemplo n.º 5
0
        self.interface.q.put_nowait({'block_height': 3, 'mock': {'catchup':1, 'check': lambda x: False, 'connect': lambda x: True}})
        self.interface.q.put_nowait({'block_height': 4, 'mock': {'catchup':1, 'check': lambda x: False, 'connect': lambda x: True}})
        ifa = self.interface
        self.assertEqual(('catchup', 5), asyncio.get_event_loop().run_until_complete(ifa.sync_until(8, next_height=4)))
        self.assertEqual(self.interface.q.qsize(), 0)

    def mock_fork(self, bad_header):
        forkpoint = bad_header['block_height']
        b = blockchain.Blockchain(config=self.config, forkpoint=forkpoint, parent=None,
                                  forkpoint_hash=bh2u(sha256(str(forkpoint))), prev_hash=bh2u(sha256(str(forkpoint-1))))
        return b

    def test_chain_false_during_binary(self):
        blockchain.blockchains = {}
        self.interface.q.put_nowait({'block_height': 8, 'mock': {'catchup':1, 'check': lambda x: False, 'connect': lambda x: False}})
        mock_connect = lambda height: height == 3
        self.interface.q.put_nowait({'block_height': 7, 'mock': {'backward':1, 'check': lambda x: False, 'connect': mock_connect}})
        self.interface.q.put_nowait({'block_height': 2, 'mock': {'backward':1, 'check': lambda x: True,  'connect': mock_connect}})
        self.interface.q.put_nowait({'block_height': 4, 'mock': {'binary':1, 'check': lambda x: False, 'fork': self.mock_fork, 'connect': mock_connect}})
        self.interface.q.put_nowait({'block_height': 3, 'mock': {'binary':1, 'check': lambda x: True, 'connect': lambda x: True}})
        self.interface.q.put_nowait({'block_height': 5, 'mock': {'catchup':1, 'check': lambda x: False, 'connect': lambda x: True}})
        self.interface.q.put_nowait({'block_height': 6, 'mock': {'catchup':1, 'check': lambda x: False, 'connect': lambda x: True}})
        ifa = self.interface
        self.assertEqual(('catchup', 7), asyncio.get_event_loop().run_until_complete(ifa.sync_until(8, next_height=6)))
        self.assertEqual(self.interface.q.qsize(), 0)


if __name__=="__main__":
    constants.set_regtest()
    unittest.main()