def test_get_latest_block_height(self): storage.set_latest_block_height(1337, self.b.driver) vk = Wallet() w = Wallet() self.authenticator.add_verifying_key(vk.verifying_key) self.authenticator.add_verifying_key(w.verifying_key) self.authenticator.configure() mn_bootnode = 'tcp://127.0.0.1:18001' mn_router = router.Router(socket_id=mn_bootnode, ctx=self.ctx, secure=True, wallet=vk) mn_router.add_service(base.BLOCK_SERVICE, self.b) async def send_msg(): res = await base.get_latest_block_height(ip=mn_bootnode, vk=vk.verifying_key, wallet=w, ctx=self.ctx) return res tasks = asyncio.gather(mn_router.serve(), send_msg(), stop_server(mn_router, 1)) _, res, _ = self.loop.run_until_complete(tasks) self.assertEqual(res, 1337)
def test_service_returns_block_height_if_proper_message(self): storage.set_latest_block_height(1337, self.b.driver) msg = {'name': base.GET_HEIGHT, 'arg': None} res = self.loop.run_until_complete(self.b.process_message(msg)) self.assertEqual(res, 1337)
def test_catchup_with_nbn_added(self): driver = ContractDriver(driver=InMemDriver()) mn_bootnode = 'tcp://127.0.0.1:18001' mn_wallet = Wallet() mn_router = router.Router(socket_id=mn_bootnode, ctx=self.ctx, secure=True, wallet=mn_wallet) mn_router.add_service(base.BLOCK_SERVICE, self.b) nw = Wallet() dlw = Wallet() node = base.Node(socket_base='tcp://127.0.0.1:18002', ctx=self.ctx, wallet=nw, constitution={ 'masternodes': [mn_wallet.verifying_key], 'delegates': [dlw.verifying_key] }, driver=driver) self.authenticator.add_verifying_key(mn_wallet.verifying_key) self.authenticator.add_verifying_key(nw.verifying_key) self.authenticator.add_verifying_key(dlw.verifying_key) self.authenticator.configure() blocks = generate_blocks(4) self.blocks.store_block(blocks[0]) self.blocks.store_block(blocks[1]) self.blocks.store_block(blocks[2]) storage.set_latest_block_height(3, self.driver) node.new_block_processor.q.append(blocks[3]) tasks = asyncio.gather( mn_router.serve(), node.catchup('tcp://127.0.0.1:18001', mn_wallet.verifying_key), stop_server(mn_router, 1)) self.loop.run_until_complete(tasks) self.assertEqual(storage.get_latest_block_height(node.driver), 4)
def test_get_latest_block_num(self): storage.set_latest_block_height(1234, self.ws.driver) _, response = self.ws.app.test_client.get('/latest_block_num') self.assertDictEqual(response.json, {'latest_block_number': 1234})
def test_get_latest_block_height_correct_after_set(self): storage.set_latest_block_height(123, self.driver) h = storage.get_latest_block_height(self.driver) self.assertEqual(h, 123)
def test_start_boots_up_normally(self): # This MN will also provide 'catch up' services mn_bootnode = 'tcp://127.0.0.1:18001' mn_wallet = Wallet() mn_router = router.Router(socket_id=mn_bootnode, ctx=self.ctx, secure=True, wallet=mn_wallet) mn_network = network.Network(wallet=mn_wallet, ip_string=mn_bootnode, ctx=self.ctx, router=mn_router) blocks = generate_blocks(4) self.blocks.store_block(blocks[0]) self.blocks.store_block(blocks[1]) self.blocks.store_block(blocks[2]) storage.set_latest_block_height(3, self.driver) mn_router.add_service( base.BLOCK_SERVICE, masternode.BlockService(self.blocks, self.driver)) dl_bootnode = 'tcp://127.0.0.1:18002' dl_wallet = Wallet() dl_router = router.Router(socket_id=dl_bootnode, ctx=self.ctx, secure=True, wallet=dl_wallet) dl_network = network.Network(wallet=dl_wallet, ip_string=dl_bootnode, ctx=self.ctx, router=dl_router) constitution = { 'masternodes': [mn_wallet.verifying_key], 'delegates': [dl_wallet.verifying_key] } bootnodes = { mn_wallet.verifying_key: mn_bootnode, dl_wallet.verifying_key: dl_bootnode } node_w = Wallet() driver = ContractDriver(driver=InMemDriver()) node = base.Node(socket_base='tcp://127.0.0.1:18003', ctx=self.ctx, wallet=node_w, constitution=constitution, driver=driver, store=False, bootnodes=bootnodes) self.authenticator.add_verifying_key(mn_wallet.verifying_key) self.authenticator.add_verifying_key(dl_wallet.verifying_key) self.authenticator.add_verifying_key(node_w.verifying_key) self.authenticator.configure() vks = [mn_wallet.verifying_key, dl_wallet.verifying_key] tasks = asyncio.gather( mn_router.serve(), dl_router.serve(), mn_network.start(bootnodes, vks), dl_network.start(bootnodes, vks), stop_server(mn_router, 0.2), stop_server(dl_router, 0.2), ) self.loop.run_until_complete(tasks) tasks = asyncio.gather(mn_router.serve(), dl_router.serve(), node.start(), stop_server(mn_router, 1), stop_server(dl_router, 1), stop_server(node.router, 1)) self.loop.run_until_complete(tasks) self.assertEqual(storage.get_latest_block_height(node.driver), 3) self.assertEqual(storage.get_latest_block_hash(node.driver), blocks[2]['hash'])