예제 #1
0
def plugin():
    pl = PluginLoader(os.path.join(curPath, 'name_age_verification'))
    verPlugins = pl.plugins[PLUGIN_TYPE_VERIFICATION]
    assert len(verPlugins) == 1
    p, = verPlugins
    assert p.__class__.__name__ == 'NameAndAgeVerifier'
    return p
예제 #2
0
파일: helper.py 프로젝트: tomergi/plenum
    def addNode(self, name: str) -> TestNode:

        if name in self.nodes:
            error("{} already added".format(name))

        assert name in self.nodeReg
        ha, cliname, cliha = self.nodeReg[name]

        if self.opVerificationPluginPath:
            pl = PluginLoader(self.opVerificationPluginPath)
            opVerifiers = pl.plugins['VERIFICATION']
        else:
            opVerifiers = None

        testNodeClass = self.testNodeClass
        node = self.enter_context(
            testNodeClass(name=name,
                          ha=ha,
                          cliname=cliname,
                          cliha=cliha,
                          nodeRegistry=copy(self.nodeReg),
                          basedirpath=self.tmpdir,
                          primaryDecider=self.primaryDecider,
                          opVerifiers=opVerifiers))
        self.nodes[name] = node
        self.__dict__[name] = node
        return node
예제 #3
0
def plugin():
    pl = PluginLoader(os.path.join(curPath, 'plugin1'))
    verPlugins = pl.plugins['VERIFICATION']
    assert len(verPlugins) == 1
    p, = verPlugins
    assert p.__class__.__name__ == 'NameAndAgeVerifier'
    return p
예제 #4
0
파일: cli.py 프로젝트: tomergi/plenum
 def _loadPluginDirAction(self, matchedVars):
     if matchedVars.get('load_plugins') == 'load plugins from':
         pluginsPath = matchedVars.get('plugin_dir')
         try:
             self.plugins = PluginLoader(pluginsPath).plugins
         except FileNotFoundError as ex:
             _, err = ex.args
             self.print(err, Token.BoldOrange)
         return True
예제 #5
0
 def _getAllPlugins(allPluginPaths, *types):
     if not allPluginPaths:
         return {}
     else:
         allPlugins = {}
         for path in allPluginPaths:
             pl = PluginLoader(path)
             plugins = pl.plugins
             for key, value in plugins.items():
                 if types and key not in types:
                     continue
                 if key in allPlugins:
                     allPlugins[key].add(value)
                 else:
                     allPlugins[key] = value
         return allPlugins
예제 #6
0
def testBankReqValidationPlugin(looper, nodeSet, client1, wallet1, tdir,
                                pluginVerPath):
    plugin = PluginLoader(pluginVerPath)
    plugin = next(iter(plugin.plugins[PLUGIN_TYPE_VERIFICATION]))
    commonError = "client request invalid: InvalidClientRequest()"
    client2, wallet2 = setupClient(looper, nodeSet, tmpdir=tdir)
    req = submitOp(wallet1, client1, {
        TXN_TYPE: "dummy",
        TARGET_NYM: wallet2.defaultId,
        DATA: {
            AMOUNT: 30
        }
    })

    validTypes = ', '.join(plugin.validTxnTypes)
    update = {
        'reason':
        makeReason(
            commonError, "dummy is not a valid "
            "transaction type, must be "
            "one of {}".format(validTypes))
    }

    coros1 = [
        partial(checkReqNack, client1, node, req.identifier, req.reqId, update)
        for node in nodeSet
    ]

    req = submitOp(wallet1, client1, {
        TXN_TYPE: CREDIT,
        TARGET_NYM: wallet2.defaultId,
    })

    update = {
        'reason':
        makeReason(
            commonError,
            "{} attribute is missing or not in proper format".format(DATA))
    }

    coros2 = [
        partial(checkReqNack, client1, node, req.identifier, req.reqId, update)
        for node in nodeSet
    ]

    req = submitOp(wallet1, client1, {
        TXN_TYPE: CREDIT,
        TARGET_NYM: wallet2.defaultId,
        DATA: "some string"
    })

    update = {
        'reason':
        makeReason(
            commonError,
            "{} attribute is missing or not in proper format".format(DATA))
    }

    coros3 = [
        partial(checkReqNack, client1, node, req.identifier, req.reqId, update)
        for node in nodeSet
    ]

    req = submitOp(wallet1, client1, {
        TXN_TYPE: CREDIT,
        TARGET_NYM: wallet2.defaultId,
        DATA: {
            AMOUNT: -3
        }
    })

    update = {
        'reason':
        makeReason(
            commonError, "{} must be present and should be "
            "a number greater than 0".format(AMOUNT))
    }

    coros4 = [
        partial(checkReqNack, client1, node, req.identifier, req.reqId, update)
        for node in nodeSet
    ]

    timeout = waits.expectedReqAckQuorumTime()
    looper.run(
        eventuallyAll(*(coros1 + coros2 + coros3 + coros4),
                      totalTimeout=timeout))

    req = submitOp(wallet1, client1, {
        TXN_TYPE: CREDIT,
        TARGET_NYM: wallet2.defaultId,
        DATA: {
            AMOUNT: 30
        }
    })

    waitForSufficientRepliesForRequests(looper,
                                        client1,
                                        requests=[req],
                                        fVal=1)
    for n in nodeSet:  # type: Node
        opVerifier, = n.opVerifiers
        assert opVerifier.count == 1
예제 #7
0
def testAuctionReqValidationPlugin(looper, nodeSet, wallet1, client1, tdir,
                                   pluginVerPath):
    # TODO: Test more cases
    plugin = PluginLoader(pluginVerPath)
    plugin = next(iter(plugin.plugins[PLUGIN_TYPE_VERIFICATION]))
    commonError = "client request invalid: InvalidClientRequest()"
    allCoros = []
    op = {TXN_TYPE: "dummy", DATA: {AMOUNT: 30}}
    req = submitOp(wallet1, client1, op)
    validTypes = ', '.join(plugin.validTxnTypes)
    update = {
        'reason':
        makeReason(
            commonError, "dummy is not a valid transaction "
            "type, must be one of {}".format(validTypes))
    }

    allCoros += [
        partial(checkReqNack, client1, node, req.reqId, update)
        for node in nodeSet
    ]

    op = {
        TXN_TYPE: AUCTION_START,
    }
    req = submitOp(wallet1, client1, op)
    update = {
        'reason':
        makeReason(
            commonError,
            "{} attribute is missing or not in proper format".format(DATA))
    }

    allCoros += [
        partial(checkReqNack, client1, node, req.reqId, update)
        for node in nodeSet
    ]

    op = {
        TXN_TYPE: PLACE_BID,
    }
    req = submitOp(wallet1, client1, op)
    update = {
        'reason':
        makeReason(
            commonError,
            "{} attribute is missing or not in proper format".format(DATA))
    }

    allCoros += [
        partial(checkReqNack, client1, node, req.reqId, update)
        for node in nodeSet
    ]

    op = {TXN_TYPE: PLACE_BID, DATA: "some string"}
    req = submitOp(wallet1, client1, op)
    update = {
        'reason':
        makeReason(
            commonError,
            "{} attribute is missing or not in proper format".format(DATA))
    }

    allCoros += [
        partial(checkReqNack, client1, node, req.reqId, update)
        for node in nodeSet
    ]

    op = {TXN_TYPE: PLACE_BID, DATA: {AMOUNT: 453}}
    req = submitOp(wallet1, client1, op)
    update = {'reason': makeReason(commonError, "No id provided for auction")}

    allCoros += [
        partial(checkReqNack, client1, node, req.reqId, update)
        for node in nodeSet
    ]

    op = {TXN_TYPE: AUCTION_START, DATA: {}}
    req = submitOp(wallet1, client1, op)
    update = {'reason': makeReason(commonError, "No id provided for auction")}

    allCoros += [
        partial(checkReqNack, client1, node, req.reqId, update)
        for node in nodeSet
    ]

    op = {TXN_TYPE: AUCTION_END, DATA: {}}
    req = submitOp(wallet1, client1, op)
    update = {'reason': makeReason(commonError, "No id provided for auction")}

    allCoros += [
        partial(checkReqNack, client1, node, req.reqId, update)
        for node in nodeSet
    ]

    auctionId = str(uuid4())

    op = {TXN_TYPE: PLACE_BID, DATA: {ID: auctionId, AMOUNT: -3}}
    req = submitOp(wallet1, client1, op)
    update = {
        'reason':
        makeReason(
            commonError, "{} must be present and should be "
            "a number greater than 0".format(AMOUNT))
    }

    allCoros += [
        partial(checkReqNack, client1, node, req.reqId, update)
        for node in nodeSet
    ]

    looper.run(eventuallyAll(*allCoros, totalTimeout=5))

    for n in nodeSet:  # type: Node
        opVerifier, = n.opVerifiers
        assert opVerifier.count == 0
예제 #8
0
def testPluginWrongPath():
    with pytest.raises(FileNotFoundError):
        pl = PluginLoader("somerandompath")
예제 #9
0
def testPluginEmptyPath():
    with pytest.raises(AssertionError) as exInfo:
        PluginLoader("")
    assert 'path is required' == str(exInfo.value)