Beispiel #1
0
    def test_acquire_work_2_masters_gathers_tx_batches_pads_work_and_waits_if_missing(
            self):
        ips = ['tcp://127.0.0.1:18001', 'tcp://127.0.0.1:18002']

        dw = Wallet()
        mw = Wallet()
        mw2 = Wallet()

        self.authenticator.add_verifying_key(mw.verifying_key)
        self.authenticator.add_verifying_key(dw.verifying_key)
        self.authenticator.configure()

        mn = masternode.Masternode(socket_base=ips[0],
                                   ctx=self.ctx,
                                   wallet=mw,
                                   constitution={
                                       'masternodes':
                                       [mw.verifying_key, mw2.verifying_key],
                                       'delegates': [dw.verifying_key]
                                   },
                                   driver=ContractDriver(driver=InMemDriver()))

        dl = delegate.Delegate(socket_base=ips[1],
                               ctx=self.ctx,
                               wallet=dw,
                               constitution={
                                   'masternodes':
                                   [mw.verifying_key, mw2.verifying_key],
                                   'delegates': [dw.verifying_key]
                               },
                               driver=ContractDriver(driver=InMemDriver()))

        peers = {
            mw.verifying_key: ips[0],
            dw.verifying_key: ips[1],
            mw2.verifying_key: 'tpc://127.0.0.1:18003'
        }

        mn.network.peers = peers
        dl.network.peers = peers

        tasks = asyncio.gather(
            mn.router.serve(),
            dl.router.serve(),
            mn.send_work(),
            dl.acquire_work(),
            stop_server(mn.router, 1),
            stop_server(dl.router, 1),
        )

        _, _, _, w, _, _ = self.loop.run_until_complete(tasks)

        self.assertEqual(len(w), 2)
        self.assertEqual(w[0]['sender'], mw.verifying_key)

        self.assertEqual(w[1]['sender'], mw2.verifying_key)
        self.assertEqual(w[1]['input_hash'], mw2.verifying_key)
        self.assertEqual(w[1]['signature'], '0' * 128)
Beispiel #2
0
    def test_masternode_delegate_single_loop_works(self):
        ips = [
            'tcp://127.0.0.1:18001',
            'tcp://127.0.0.1:18002'
        ]

        dw = Wallet()
        mw = Wallet()

        self.authenticator.add_verifying_key(mw.verifying_key)
        self.authenticator.add_verifying_key(dw.verifying_key)
        self.authenticator.configure()

        mn = masternode.Masternode(
            socket_base=ips[0],
            ctx=self.ctx,
            wallet=mw,
            constitution={
                'masternodes': [mw.verifying_key],
                'delegates': [dw.verifying_key]
            },
            driver=ContractDriver(driver=InMemDriver())
        )

        dl = delegate.Delegate(
            socket_base=ips[1],
            ctx=self.ctx,
            wallet=dw,
            constitution={
                'masternodes': [mw.verifying_key],
                'delegates': [dw.verifying_key]
            },
            driver=ContractDriver(driver=InMemDriver())
        )

        peers = {
            mw.verifying_key: ips[0],
            dw.verifying_key: ips[1]
        }

        mn.network.peers = peers
        dl.network.peers = peers

        tasks = asyncio.gather(
            mn.router.serve(),
            dl.router.serve(),
            mn.loop(),
            dl.loop(),
            stop_server(mn.router, 1),
            stop_server(dl.router, 1),
        )

        self.loop.run_until_complete(tasks)
Beispiel #3
0
    def test_process_new_work_processes_tx_batch(self):
        ips = ['tcp://127.0.0.1:18001', 'tcp://127.0.0.1:18002']

        dw = Wallet()
        mw = Wallet()

        self.authenticator.add_verifying_key(mw.verifying_key)
        self.authenticator.add_verifying_key(dw.verifying_key)
        self.authenticator.configure()

        mn = masternode.Masternode(socket_base=ips[0],
                                   ctx=self.ctx,
                                   wallet=mw,
                                   constitution={
                                       'masternodes': [mw.verifying_key],
                                       'delegates': [dw.verifying_key]
                                   },
                                   driver=ContractDriver(driver=InMemDriver()))

        mnq = router.QueueProcessor()
        mn.router.add_service(base.CONTENDER_SERVICE, mnq)

        dl = delegate.Delegate(socket_base=ips[1],
                               ctx=self.ctx,
                               wallet=dw,
                               constitution={
                                   'masternodes': [mw.verifying_key],
                                   'delegates': [dw.verifying_key]
                               },
                               driver=ContractDriver(driver=InMemDriver()))

        peers = {mw.verifying_key: ips[0], dw.verifying_key: ips[1]}

        mn.network.peers = peers
        dl.network.peers = peers

        tasks = asyncio.gather(
            mn.router.serve(),
            dl.router.serve(),
            mn.send_work(),
            dl.process_new_work(),
            stop_server(mn.router, 1),
            stop_server(dl.router, 1),
        )

        self.loop.run_until_complete(tasks)

        sbc = mnq.q.pop(0)

        self.assertEqual(len(sbc), 1)
        self.assertEqual(sbc[0]['previous'], '0' * 64)
        self.assertEqual(sbc[0]['signer'], dw.verifying_key)
Beispiel #4
0
    async def start(self):
        assert self.ready_to_start, 'Not ready to start!'

        self.obj = masternode.Masternode(
            socket_base=self.ip,
            ctx=self.ctx,
            wallet=self.wallet,
            constitution=self.constitution,
            bootnodes=self.bootnodes,
            blocks=self.blocks,
            driver=self.driver,
            webserver_port=self.webserver_port,
            genesis_path=self.genesis_path,
            nonces=self.nonces
        )

        await self.obj.start()
        self.started = True
Beispiel #5
0
    def test_masternode_delegate_single_loop_updates_block_num(self):
        ips = [
            'tcp://127.0.0.1:18001',
            'tcp://127.0.0.1:18002'
        ]

        dw = Wallet()
        mw = Wallet()

        self.authenticator.add_verifying_key(mw.verifying_key)
        self.authenticator.add_verifying_key(dw.verifying_key)
        self.authenticator.configure()

        mnd = ContractDriver(driver=InMemDriver())
        mn = masternode.Masternode(
            socket_base=ips[0],
            ctx=self.ctx,
            wallet=mw,
            constitution={
                'masternodes': [mw.verifying_key],
                'delegates': [dw.verifying_key]
            },
            driver=mnd
        )
        sender = Wallet()
        mnd.set_var(contract='currency', variable='balances', arguments=[sender.verifying_key], value=1_000_000)

        dld = ContractDriver(driver=InMemDriver())
        dld.set_var(contract='currency', variable='balances', arguments=[sender.verifying_key], value=1_000_000)
        dl = delegate.Delegate(
            socket_base=ips[1],
            ctx=self.ctx,
            wallet=dw,
            constitution={
                'masternodes': [mw.verifying_key],
                'delegates': [dw.verifying_key]
            },
            driver=dld
        )

        tx = transaction.build_transaction(
            wallet=sender,
            contract='currency',
            function='transfer',
            kwargs={
                'amount': 1338,
                'to': 'jeff'
            },
            stamps=5000,
            nonce=0,
            processor=mw.verifying_key
        )

        tx_decoded = decode(tx)
        mn.tx_batcher.queue.append(tx_decoded)

        peers = {
            mw.verifying_key: ips[0],
            dw.verifying_key: ips[1]
        }

        mn.network.peers = peers
        dl.network.peers = peers

        tasks = asyncio.gather(
            mn.router.serve(),
            dl.router.serve(),
            mn.loop(),
            dl.loop(),
            stop_server(mn.router, 1),
            stop_server(dl.router, 1),
        )

        self.loop.run_until_complete(tasks)

        dh = storage.get_latest_block_height(dld)
        mh = storage.get_latest_block_height(mnd)

        self.assertEqual(dh, 1)
        self.assertEqual(mh, 1)