def test_send_work_multicasts_tx_batch_to_delegates(self): ips = [ 'tcp://127.0.0.1:18001', 'tcp://127.0.0.1:18002', 'tcp://127.0.0.1:18003' ] d1w = Wallet() d2w = Wallet() m1w = Wallet() self.authenticator.add_verifying_key(d1w.verifying_key) self.authenticator.add_verifying_key(d2w.verifying_key) self.authenticator.add_verifying_key(m1w.verifying_key) self.authenticator.configure() d1_r = router.Router(socket_id=ips[0], ctx=self.ctx, wallet=d1w, secure=True) d2_r = router.Router(socket_id=ips[1], ctx=self.ctx, wallet=d2w, secure=True) d1_q = router.QueueProcessor() d2_q = router.QueueProcessor() d1_r.add_service(base.WORK_SERVICE, d1_q) d2_r.add_service(base.WORK_SERVICE, d2_q) node = masternode.Masternode( socket_base=ips[2], ctx=self.ctx, wallet=m1w, constitution={ 'masternodes': [m1w.verifying_key], 'delegates': [d1w.verifying_key, d2w.verifying_key] }, driver=self.driver) node.network.peers = { d1w.verifying_key: ips[0], d2w.verifying_key: ips[1], m1w.verifying_key: ips[2] } tasks = asyncio.gather(d1_r.serve(), d2_r.serve(), node.send_work(), stop_server(d1_r, 1), stop_server(d2_r, 1)) self.loop.run_until_complete(tasks) txb1 = d1_q.q.pop(0) txb2 = d2_q.q.pop(0) self.assertDictEqual(txb1, txb2)
def test_broadcast_new_chain_sends_messages_to_all_peers(self): mn_wallet = Wallet() mn_bootnode = 'tcp://127.0.0.1:18001' mn_router = router.Router(wallet=mn_wallet, socket_id=mn_bootnode, ctx=self.ctx, secure=True) dl_wallet = Wallet() dl_bootnode = 'tcp://127.0.0.1:18002' dl_router = router.Router(wallet=dl_wallet, socket_id=dl_bootnode, ctx=self.ctx, secure=True) driver = ContractDriver(driver=InMemDriver()) node = masternode.Masternode(socket_base='tcp://127.0.0.1:18003', ctx=self.ctx, wallet=Wallet(), constitution={ 'masternodes': [mn_wallet.verifying_key], 'delegates': [dl_wallet.verifying_key] }, driver=driver) node.client.set_var(contract='masternodes', variable='S', arguments=['members'], value=[mn_wallet.verifying_key]) node.client.set_var(contract='delegates', variable='S', arguments=['members'], value=[dl_wallet.verifying_key]) node.socket_authenticator.refresh_governance_sockets() node.network.peers = { mn_wallet.verifying_key: mn_bootnode, dl_wallet.verifying_key: dl_bootnode } node.tx_batcher.queue.append('MOCK TX') tasks = asyncio.gather(mn_router.serve(), dl_router.serve(), node.broadcast_new_blockchain_started(), stop_server(mn_router, 0.2), stop_server(dl_router, 0.2)) self.loop.run_until_complete(tasks)
def test_hang_returns_if_not_running(self): driver = ContractDriver(driver=InMemDriver()) node = masternode.Masternode(socket_base='tcp://127.0.0.1:18002', ctx=self.ctx, wallet=Wallet(), constitution={ 'masternodes': [Wallet().verifying_key], 'delegates': [Wallet().verifying_key] }, driver=driver) self.loop.run_until_complete(node.hang())
def test_send_work_returns_if_no_one_online(self): driver = ContractDriver(driver=InMemDriver()) node_wallet = Wallet() node = masternode.Masternode(socket_base='tcp://127.0.0.1:18003', ctx=self.ctx, wallet=node_wallet, constitution={ 'masternodes': [Wallet().verifying_key], 'delegates': [Wallet().verifying_key] }, driver=driver) r = self.loop.run_until_complete(node.send_work()) self.assertFalse(r)
def test_broadcast_new_chain_does_nothing_if_no_tx(self): driver = ContractDriver(driver=InMemDriver()) node = masternode.Masternode(socket_base='tcp://127.0.0.1:18002', ctx=self.ctx, wallet=Wallet(), constitution={ 'masternodes': [Wallet().verifying_key], 'delegates': [Wallet().verifying_key] }, driver=driver) node.client.set_var(contract='masternodes', variable='S', arguments=['members'], value=['stu', 'jeff'])
def test_hang_until_nbn_has_block(self): driver = ContractDriver(driver=InMemDriver()) node = masternode.Masternode(socket_base='tcp://127.0.0.1:18002', ctx=self.ctx, wallet=Wallet(), constitution={ 'masternodes': [Wallet().verifying_key], 'delegates': [Wallet().verifying_key] }, driver=driver) node.running = True async def late_tx(timeout=0.2): await asyncio.sleep(timeout) node.new_block_processor.q.append('MOCK BLOCK') tasks = asyncio.gather(node.hang(), late_tx()) self.loop.run_until_complete(tasks)