Esempio n. 1
0
def testClientConnectAfterRestart(looper, txnPoolNodeSet, tdirWithPoolTxns):
    cname = "testClient" + randomString(5)
    newClient, _ = genTestClient(tmpdir=tdirWithPoolTxns,
                                 name=cname,
                                 usePoolLedger=True)
    logger.debug("{} starting at {}".format(newClient, newClient.nodestack.ha))
    looper.add(newClient)
    logger.debug("Public keys of client {} {}".format(
        newClient.nodestack.local.priver.keyhex,
        newClient.nodestack.local.priver.pubhex))
    logger.debug("Signer keys of client {} {}".format(
        newClient.nodestack.local.signer.keyhex,
        newClient.nodestack.local.signer.verhex))
    looper.run(newClient.ensureConnectedToNodes())
    newClient.stop()
    looper.removeProdable(newClient)
    newClient, _ = genTestClient(tmpdir=tdirWithPoolTxns,
                                 name=cname,
                                 usePoolLedger=True)
    logger.debug("{} again starting at {}".format(newClient,
                                                  newClient.nodestack.ha))
    looper.add(newClient)
    logger.debug("Public keys of client {} {}".format(
        newClient.nodestack.local.priver.keyhex,
        newClient.nodestack.local.priver.pubhex))
    logger.debug("Signer keys of client {} {}".format(
        newClient.nodestack.local.signer.keyhex,
        newClient.nodestack.local.signer.verhex))
    looper.run(newClient.ensureConnectedToNodes())
Esempio n. 2
0
    async def go(ctx):
        client1 = genTestClient(ctx.nodeset, tmpdir=ctx.tmpdir)

        # remove the client's ability to sign
        assert client1.getSigner()
        client1.signers[client1.defaultIdentifier] = None
        assert not client1.getSigner()

        ctx.looper.add(client1)
        await client1.ensureConnectedToNodes()

        operation = randomOperation()
        request = client1.submit(operation)[0]

        with pytest.raises(AssertionError):
            for node in ctx.nodeset:
                await eventually(
                        checkLastClientReqForNode, node, request,
                        retryWait=1, timeout=10)

        for n in ctx.nodeset:
            params = n.spylog.getLastParams(Node.reportSuspiciousClient)
            frm = params['clientName']
            reason = params['reason']

            assert frm == client1.name
            assert isinstance(reason, EmptySignature)

            params = n.spylog.getLastParams(Node.discard)
            reason = params["reason"]
            (msg, frm) = params["msg"]
            assert msg == request.__dict__
            assert frm == client1.name
            assert isinstance(reason, EmptySignature)
Esempio n. 3
0
def testClientReconnectUsingDifferentHa(looper, txnPoolNodeSet,
                                        tdirWithPoolTxns, poolTxnClientData):
    """
    Client should not be able to connect to nodes even after it has changed
    its HA. Since running on a local environment, only checking change of port.
    Dont know how to change IP.
    :return:
    """
    # TODO: Check for change of IP too
    # name, seed = poolTxnClientData
    # signer = SimpleSigner(seed=seed)
    # name = "testClient96541"
    # ha = genHa()
    # client = genTestClient(txnPoolNodeSet, signer=signer, ha=ha,
    #                        tmpdir=tdirWithPoolTxns, usePoolLedger=True,
    #                        name=name)
    client, wallet = buildPoolClientAndWallet(poolTxnClientData,
                                              tdirWithPoolTxns)
    looper.add(client)
    ensureClientConnectedToNodesAndPoolLedgerSame(looper, client,
                                                  *txnPoolNodeSet)
    basedirpath = client.basedirpath
    looper.removeProdable(client)

    # Removing RAET keep directory otherwise the client will use the same port
    #  since it will a directory of its name in the keep
    shutil.rmtree(os.path.join(basedirpath, client.name), ignore_errors=True)

    ha = genHa()
    client, _ = genTestClient(txnPoolNodeSet, identifier=wallet.defaultId,
                              ha=ha, tmpdir=tdirWithPoolTxns,
                              usePoolLedger=True, name=client.name)
    looper.add(client)
    ensureClientConnectedToNodesAndPoolLedgerSame(looper, client,
                                                  *txnPoolNodeSet)
Esempio n. 4
0
 def makeClient(id):
     client, wallet = genTestClient(nodeSet,
                                    tmpdir=tdir,
                                    name="client-{}".format(id))
     looper.add(client)
     looper.run(client.ensureConnectedToNodes())
     return client, wallet
Esempio n. 5
0
    async def go(ctx):
        client1, wallet = genTestClient(ctx.nodeset, tmpdir=ctx.tmpdir)

        # remove the client's ability to sign
        assert wallet.defaultId
        wallet.defaultId = None
        assert not wallet.defaultId

        ctx.looper.add(client1)
        await client1.ensureConnectedToNodes()

        request = Request(randomOperation())
        request = client1.submitReqs(request)[0]
        with pytest.raises(AssertionError):
            for node in ctx.nodeset:
                await eventually(checkLastClientReqForNode,
                                 node,
                                 request,
                                 retryWait=1,
                                 timeout=10)

        for n in ctx.nodeset:
            params = n.spylog.getLastParams(Node.handleInvalidClientMsg)
            ex = params['ex']
            _, frm = params['wrappedMsg']
            assert isinstance(ex, EmptySignature)
            assert frm == client1.name

            params = n.spylog.getLastParams(Node.discard)
            reason = params["reason"]
            (msg, frm) = params["msg"]
            assert msg == request.__dict__
            assert frm == client1.name
            assert "EmptySignature" in reason
Esempio n. 6
0
    async def go(ctx):
        for n in ctx.nodeset:
            n.nodestack.keep.auto = AutoMode.never

        nodestacksVersion = {k: v.ha for k, v in ctx.nodeset.nodeReg.items()}
        client1 = genTestClient(nodeReg=nodestacksVersion, tmpdir=ctx.tmpdir)
        ctx.looper.add(client1)
        with pytest.raises(NotConnectedToAny):
            await client1.ensureConnectedToNodes()
Esempio n. 7
0
    async def go(ctx):
        for n in ctx.nodeset:
            n.nodestack.keep.auto = AutoMode.never

        nodestacksVersion = {k: v.ha for k, v in ctx.nodeset.nodeReg.items()}
        client1 = genTestClient(nodeReg=nodestacksVersion, tmpdir=ctx.tmpdir)
        ctx.looper.add(client1)
        with pytest.raises(NotConnectedToAny):
            await client1.ensureConnectedToNodes()
Esempio n. 8
0
def testReplyReceivedOnlyByClientWhoSentRequest(looper, nodeSet, tdir, client1,
                                                wallet1):
    newClient, _ = genTestClient(nodeSet, tmpdir=tdir)
    looper.add(newClient)
    looper.run(newClient.ensureConnectedToNodes())
    client1InboxSize = len(client1.inBox)
    newClientInboxSize = len(newClient.inBox)
    sendReqsToNodesAndVerifySuffReplies(looper, wallet1, newClient, 1)
    assert len(client1.inBox) == client1InboxSize
    assert len(newClient.inBox) > newClientInboxSize
Esempio n. 9
0
def testGeneratedRequestSequencing(tdir_for_func):
    """
    Request ids must be generated in an increasing order
    """
    with TestNodeSet(count=4, tmpdir=tdir_for_func) as nodeSet:
        cli = genTestClient(nodeSet, tmpdir=tdir_for_func)
        operation = randomOperation()

        request = cli.createRequest(operation)
        assert request.reqId == 1

        request = cli.createRequest(operation)
        assert request.reqId == 2

        request = cli.createRequest(randomOperation())
        assert request.reqId == 3

        cli2 = genTestClient(nodeSet, tmpdir=tdir_for_func)

        request = cli2.createRequest(operation)
        assert request.reqId == 1
Esempio n. 10
0
def testGeneratedRequestSequencing(tdir_for_func):
    """
    Request ids must be generated in an increasing order
    """
    with TestNodeSet(count=4, tmpdir=tdir_for_func) as nodeSet:
        cli = genTestClient(nodeSet, tmpdir=tdir_for_func)
        operation = randomOperation()

        request = cli.createRequest(operation)
        assert request.reqId == 1

        request = cli.createRequest(operation)
        assert request.reqId == 2

        request = cli.createRequest(randomOperation())
        assert request.reqId == 3

        cli2 = genTestClient(nodeSet, tmpdir=tdir_for_func)

        request = cli2.createRequest(operation)
        assert request.reqId == 1
Esempio n. 11
0
def buildPoolClientAndWallet(clientData,
                             tempDir,
                             clientClass=None,
                             walletClass=None):
    walletClass = walletClass or Wallet
    clientClass = clientClass or TestClient
    name, sigseed = clientData
    w = walletClass(name)
    w.addIdentifier(signer=SimpleSigner(seed=sigseed))
    client, _ = genTestClient(name=name,
                              identifier=w.defaultId,
                              tmpdir=tempDir,
                              usePoolLedger=True,
                              testClientClass=clientClass)
    return client, w
Esempio n. 12
0
    async def go(ctx):
        client1 = genTestClient(ctx.nodeset, tmpdir=ctx.tmpdir)

        # remove the client's ability to sign
        assert client1.getSigner()
        client1.signers[client1.defaultIdentifier] = None
        assert not client1.getSigner()

        ctx.looper.add(client1)
        await client1.ensureConnectedToNodes()

        operation = randomOperation()
        request = client1.submit(operation)[0]

        with pytest.raises(AssertionError):
            for node in ctx.nodeset:
                await eventually(checkLastClientReqForNode,
                                 node,
                                 request,
                                 retryWait=1,
                                 timeout=10)

        for n in ctx.nodeset:
            params = n.spylog.getLastParams(Node.reportSuspiciousClient)
            frm = params['clientName']
            reason = params['reason']

            assert frm == client1.name
            assert isinstance(reason, EmptySignature)

            params = n.spylog.getLastParams(Node.discard)
            reason = params["reason"]
            (msg, frm) = params["msg"]
            assert msg == request.__dict__
            assert frm == client1.name
            assert isinstance(reason, EmptySignature)
Esempio n. 13
0
def poolTxnClient(tdirWithPoolTxns, tdirWithDomainTxns, txnPoolNodeSet):
    return genTestClient(txnPoolNodeSet,
                         tmpdir=tdirWithPoolTxns,
                         usePoolLedger=True)
Esempio n. 14
0
def clientAndWallet1(looper, nodeSet, tdir, up):
    return genTestClient(nodeSet, tmpdir=tdir)
Esempio n. 15
0
def client1(looper, nodeSet, tdir, up):
    client = genTestClient(nodeSet, tmpdir=tdir)
    looper.add(client)
    looper.run(client.ensureConnectedToNodes())
    return client
Esempio n. 16
0
def client1(looper, nodeSet, tdir, up):
    client = genTestClient(nodeSet, tmpdir=tdir)
    looper.add(client)
    looper.run(client.ensureConnectedToNodes())
    return client