Exemple #1
0
    def test_acquire_work_if_no_one_connected_returns(self):
        d = Delegate(ctx=self.ctx,
                     socket_base='ipc:///tmp/n1',
                     constitution=constitution,
                     wallet=dw1,
                     overwrite=True)

        self.loop.run_until_complete(d.acquire_work())
Exemple #2
0
    def test_acquire_work_for_one_master_returns_a_single_tx_batch(self):
        mock_master = ComplexMockMasternode(
            ctx=self.ctx,
            delegate_nbn='ipc:///tmp/n1/block_notifications',
            delegate_work='ipc:///tmp/n1/incoming_work',
            wallet=mnw1)

        d = Delegate(ctx=self.ctx,
                     socket_base='ipc:///tmp/n1',
                     constitution=constitution,
                     wallet=dw1,
                     overwrite=True)

        d.running = True

        d.parameters.sockets = {mnw1.verifying_key().hex(): 'ipc:///tmp/n2'}

        args_1 = ('hi', 'hello')
        args_2 = ('howdy', 'yo')
        args_3 = ('yeehaw', 'p')

        mock_master.tx_batcher.queue.extend([
            make_tx(mnw1.verifying_key(), *args_1),
            make_tx(mnw1.verifying_key(), *args_2),
            make_tx(mnw1.verifying_key(), *args_3),
        ])

        async def stop():
            await asyncio.sleep(0.3)
            d.work_inbox.stop()

        tasks = asyncio.gather(d.work_inbox.serve(),
                               mock_master.send_to_work_socket(),
                               d.acquire_work(), stop())

        _, _, r, _ = self.loop.run_until_complete(tasks)
        print(r)
Exemple #3
0
    def test_acquire_work_returns_empty_self_signed_tx_batches_if_timeout_hit(
            self):
        mock_master = ComplexMockMasternode(
            ctx=self.ctx,
            delegate_nbn='ipc:///tmp/n1/block_notifications',
            delegate_work='ipc:///tmp/n1/incoming_work',
            wallet=mnw1)

        mock_master_2 = ComplexMockMasternode(
            ctx=self.ctx,
            delegate_nbn='ipc:///tmp/n1/block_notifications',
            delegate_work='ipc:///tmp/n1/incoming_work',
            wallet=mnw2,
            ipc='n3')

        d = Delegate(ctx=self.ctx,
                     socket_base='ipc:///tmp/n1',
                     constitution=constitution2,
                     wallet=dw1,
                     overwrite=True)

        d.running = True

        d.parameters.sockets = {
            mnw1.verifying_key().hex(): 'ipc:///tmp/n2',
            mnw2.verifying_key().hex(): 'ipc:///tmp/n3',
            mnw3.verifying_key().hex(): 'ipc:///'
        }

        args_1 = ('hi', 'hello')
        args_2 = ('howdy', 'yo')
        args_3 = ('yeehaw', 'p')

        mock_master.tx_batcher.queue.extend([
            make_tx(mnw1.verifying_key(), *args_1),
            make_tx(mnw1.verifying_key(), *args_2),
            make_tx(mnw1.verifying_key(), *args_3),
        ])

        ### TXS for master 2
        args_4 = ('aaa', 'bbb')
        args_5 = ('123', 'xxx')
        args_6 = ('456', 'zzz')

        mock_master_2.tx_batcher.queue.extend([
            make_tx(mnw2.verifying_key(), *args_4),
            make_tx(mnw2.verifying_key(), *args_5),
            make_tx(mnw2.verifying_key(), *args_6),
        ])

        async def stop():
            await asyncio.sleep(0.3)
            d.work_inbox.stop()

        tasks = asyncio.gather(d.work_inbox.serve(),
                               mock_master.send_to_work_socket(),
                               mock_master_2.send_to_work_socket(),
                               d.acquire_work(), stop())

        _, _, _, r, _ = self.loop.run_until_complete(tasks)
        print(r[0])
        print(r[1])
        print(r[2])