예제 #1
0
def clientstack(tdir, looper, alpha_handler):
    names = ['ClientA', 'Alpha']
    genKeys(tdir, names)
    aseed = randomSeed()
    cseed = randomSeed()

    stackParams = {
        "name": names[0],
        "ha": genHa(),
        "auto": 2,
        "basedirpath": tdir
    }
    timer = MockTimer(0)
    client = ClientZStack(stackParams, alpha_handler.handle, cseed, False,
                          timer=timer)

    stackParams = {
        "name": names[1],
        "ha": genHa(),
        "auto": 2,
        "basedirpath": tdir
    }
    timer = MockTimer(0)
    alpha = SimpleZStack(stackParams, alpha_handler, aseed, True,
                         timer=timer)

    amotor = SMotor(alpha)
    looper.add(amotor)

    cmotor = SMotor(client)
    looper.add(cmotor)
    return alpha, client
예제 #2
0
def testUnrestricted2ZStackCommunication(tdir, looper):
    """
    Create 2 ZStack and make them send and receive messages.
    Both stacks allow communication even when keys are not shared
    :return:
    """
    names = ['Alpha', 'Beta']
    alphaP = Printer(names[0])
    betaP = Printer(names[1])
    alpha = ZStack(names[0],
                   ha=genHa(),
                   basedirpath=tdir,
                   msgHandler=alphaP.print,
                   restricted=False,
                   seed=randomSeed())
    beta = ZStack(names[1],
                  ha=genHa(),
                  basedirpath=tdir,
                  msgHandler=betaP.print,
                  restricted=False,
                  seed=randomSeed())

    prepStacks(looper, alpha, beta, connect=True, useKeys=True)
    alpha.send({'greetings': 'hi'}, beta.name)
    beta.send({'greetings': 'hello'}, alpha.name)

    looper.run(eventually(chkPrinted, alphaP, {'greetings': 'hello'}))
    looper.run(eventually(chkPrinted, betaP, {'greetings': 'hi'}))
예제 #3
0
def testSimpleZStacksMsgs(tdir, looper):
    names = ['Alpha', 'Beta']
    genKeys(tdir, names)
    names = ['Alpha', 'Beta']
    aseed = randomSeed()
    bseed = randomSeed()

    size = 100000
    msg = json.dumps({'random': randomSeed(size).decode()}).encode()

    def aHandler(m):
        str_m = "{}".format(m)
        print('{} printing... {}'.format(names[0], str_m[:100]))
        d, _ = m
        print('Message size is {}'.format(len(d['random'])))
        assert len(d['random']) == size

    def bHandler(m):
        print(beta.msgHandler)
        a = m[1]
        try:
            beta.listener.send_multipart([a, msg], flags=zmq.NOBLOCK)
        except zmq.Again:
            return False
        str_m = "{}".format(m)
        print('{} printing... {}'.format(names[1], str_m[:100]))

    stackParams = {
        "name": names[0],
        "ha": genHa(),
        "auto": 2,
        "basedirpath": tdir
    }
    alpha = SimpleZStack(stackParams, aHandler, aseed, False)

    stackParams = {
        "name": names[1],
        "ha": genHa(),
        "auto": 2,
        "basedirpath": tdir
    }
    beta = SimpleZStack(stackParams, bHandler, bseed, True)

    amotor = SMotor(alpha)
    looper.add(amotor)

    bmotor = SMotor(beta)
    looper.add(bmotor)

    alpha.connect(name=beta.name,
                  ha=beta.ha,
                  verKeyRaw=beta.verKeyRaw,
                  publicKeyRaw=beta.publicKeyRaw)

    looper.runFor(0.25)
    alpha.send({'greetings': 'hi'}, beta.name)
    looper.runFor(1)
def testSimpleZStacksMsgs(tdir, looper):
    names = ['Alpha', 'Beta']
    genKeys(tdir, names)
    names = ['Alpha', 'Beta']
    aseed = randomSeed()
    bseed = randomSeed()

    size = 100000
    msg = json.dumps({'random': randomSeed(size).decode()}).encode()

    def aHandler(m):
        str_m = "{}".format(m)
        print('{} printing... {}'.format(names[0], str_m[:100]))
        d, _ = m
        print('Message size is {}'.format(len(d['random'])))
        assert len(d['random']) == size

    def bHandler(m):
        print(beta.msgHandler)
        a = m[1]
        try:
            beta.listener.send_multipart([a, msg],
                                         flags=zmq.NOBLOCK)
        except zmq.Again:
            return False
        str_m = "{}".format(m)
        print('{} printing... {}'.format(names[1], str_m[:100]))

    stackParams = {
        "name": names[0],
        "ha": genHa(),
        "auto": 2,
        "basedirpath": tdir
    }
    alpha = SimpleZStack(stackParams, aHandler, aseed, False)

    stackParams = {
        "name": names[1],
        "ha": genHa(),
        "auto": 2,
        "basedirpath": tdir
    }
    beta = SimpleZStack(stackParams, bHandler, bseed, True)

    amotor = SMotor(alpha)
    looper.add(amotor)

    bmotor = SMotor(beta)
    looper.add(bmotor)

    alpha.connect(name=beta.name, ha=beta.ha,
                  verKeyRaw=beta.verKeyRaw, publicKeyRaw=beta.publicKeyRaw)

    looper.runFor(0.25)
    alpha.send({'greetings': 'hi'}, beta.name)
    looper.runFor(1)
예제 #5
0
def test_queue_size_limit_set(tdir, tconf):
    stack = ZStack("Alpha", ha=genHa(), basedirpath=tdir, msgHandler=None,
                   restricted=False, seed=randomSeed(), config=tconf)
    stack.start()
    assert stack.listener.get_hwm() == 0
    stack.stop()

    queue_size = 100
    stack = ZStack("Alpha", ha=genHa(), basedirpath=tdir, msgHandler=None,
                   restricted=False, seed=randomSeed(), config=tconf, queue_size=queue_size)
    stack.start()
    assert stack.listener.get_hwm() == queue_size
    stack.stop()
예제 #6
0
    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]

        config_helper = PNodeConfigHelper(name,
                                          self.config,
                                          chroot=self.tmpdir)

        seed = randomSeed()
        if self.keyshare:
            learnKeysFromOthers(config_helper.keys_dir, name,
                                self.nodes.values())

        testNodeClass = self.testNodeClass
        node = self.enter_context(
            testNodeClass(name=name,
                          ha=ha,
                          cliname=cliname,
                          cliha=cliha,
                          config_helper=config_helper,
                          primaryDecider=self.primaryDecider,
                          pluginPaths=self.pluginPaths,
                          seed=seed))

        if self.keyshare:
            tellKeysToOthers(node, self.nodes.values())

        self.nodes[name] = node
        self.__dict__[name] = node
        return node
예제 #7
0
def testNode(pluginManager, tdir):
    name = randomText(20)
    nodeReg = genNodeReg(names=[name])
    ha, cliname, cliha = nodeReg[name]
    return TestNode(name=name, ha=ha, cliname=cliname, cliha=cliha,
                    nodeRegistry=copy(nodeReg), basedirpath=tdir,
                    primaryDecider=None, pluginPaths=None, seed=randomSeed())
예제 #8
0
def testMessageQuota(tdir, looper):
    names = ['Alpha', 'Beta']
    genKeys(tdir, names)
    alphaP = Printer(names[0])
    receivedMessages = []
    betaMshHandler = makeHandler(receivedMessages)

    alpha = ZStack(names[0],
                   ha=genHa(),
                   basedirpath=tdir,
                   msgHandler=alphaP.print,
                   restricted=True)
    beta = ZStack(names[1],
                  ha=genHa(),
                  basedirpath=tdir,
                  msgHandler=betaMshHandler,
                  restricted=True,
                  onlyListener=True)

    prepStacks(looper, alpha, beta, connect=True, useKeys=True)

    messages = []
    numMessages = 100 * beta.listenerQuota
    for i in range(numMessages):
        msg = json.dumps({'random': randomSeed().decode()}).encode()
        messages.append(json.loads(msg.decode()))
        alpha.send(msg, beta.name)

    looper.runFor(2)
    assert messages == receivedMessages
예제 #9
0
def initNodeKeysForBothStacks(name,
                              keys_dir,
                              sigseed,
                              *,
                              use_bls=True,
                              override=False):
    # `sigseed` is initialised to keep the seed same for both stacks.
    # Both node and client stacks need to have same keys
    if not sigseed:
        sigseed = sigseed or randomSeed()
        print("Generating keys for random seed", sigseed)
    else:
        print("Generating keys for provided seed", sigseed)

    node_stack_name = name
    client_stack_name = node_stack_name + CLIENT_STACK_SUFFIX
    print("Init local keys for client-stack")
    initLocalKeys(client_stack_name,
                  keys_dir,
                  sigseed,
                  use_bls=False,
                  override=override)
    print("Init local keys for node-stack")
    keys = initLocalKeys(node_stack_name,
                         keys_dir,
                         sigseed,
                         use_bls=use_bls,
                         override=override)
    return keys
예제 #10
0
def testMessageQuota(tdir, looper):
    names = ['Alpha', 'Beta']
    genKeys(tdir, names)
    alphaP = Printer(names[0])
    betaMsgHandler = CollectingMsgsHandler()

    alpha = ZStack(names[0],
                   ha=genHa(),
                   basedirpath=tdir,
                   msgHandler=alphaP.print,
                   restricted=True)
    beta = ZStack(names[1],
                  ha=genHa(),
                  basedirpath=tdir,
                  msgHandler=betaMsgHandler.handler,
                  restricted=True,
                  onlyListener=True)

    prepStacks(looper, alpha, beta, connect=True, useKeys=True)

    messages = []
    numMessages = 150 * beta.listenerQuota
    for i in range(numMessages):
        msg = json.dumps({'random': randomSeed().decode()}).encode()
        if alpha.send(msg, beta.name):
            messages.append(json.loads(msg.decode()))

    def checkAllReceived():
        assert len(messages) == len(betaMsgHandler.receivedMessages)
        assert messages == betaMsgHandler.receivedMessages

    looper.run(eventually(checkAllReceived, retryWait=0.5, timeout=5))
예제 #11
0
def philCli(be, do, philCLI, trusteeCli, poolTxnData):

    be(philCLI)

    do('prompt Phil', expect=prompt_is('Phil'))

    do('new wallet Phil',
       expect=['New wallet Phil created', 'Active wallet set to "Phil"'])

    phil_seed = randomSeed()
    phil_signer = DidSigner(seed=phil_seed)

    mapper = {'seed': phil_seed.decode(), 'idr': phil_signer.identifier}
    do('new key with seed {seed}',
       expect=[
           'Key created in wallet Phil', 'DID for key is {idr}',
           'Current DID set to {idr}'
       ],
       mapper=mapper)

    addNym(be,
           do,
           trusteeCli,
           phil_signer.identifier,
           verkey=phil_signer.verkey,
           role=Roles.TRUSTEE.name)

    return philCLI
예제 #12
0
    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]

        seed = randomSeed()
        if self.keyshare:
            learnKeysFromOthers(self.tmpdir, name, self.nodes.values())

        testNodeClass = self.testNodeClass
        node = self.enter_context(
            testNodeClass(name=name,
                          ha=ha,
                          cliname=cliname,
                          cliha=cliha,
                          nodeRegistry=copy(self.nodeReg),
                          basedirpath=self.tmpdir,
                          base_data_dir=self.tmpdir,
                          primaryDecider=self.primaryDecider,
                          pluginPaths=self.pluginPaths,
                          seed=seed))

        if self.keyshare:
            tellKeysToOthers(node, self.nodes.values())

        self.nodes[name] = node
        self.__dict__[name] = node
        return node
예제 #13
0
    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]

        config_helper = PNodeConfigHelper(name, self.config, chroot=self.tmpdir)

        seed = randomSeed()
        if self.keyshare:
            learnKeysFromOthers(config_helper.keys_dir, name, self.nodes.values())

        testNodeClass = self.testNodeClass
        node = self.enter_context(
            testNodeClass(name=name,
                          ha=ha,
                          cliname=cliname,
                          cliha=cliha,
                          config_helper=config_helper,
                          primaryDecider=self.primaryDecider,
                          pluginPaths=self.pluginPaths,
                          seed=seed))

        if self.keyshare:
            tellKeysToOthers(node, self.nodes.values())

        self.nodes[name] = node
        self.__dict__[name] = node
        return node
예제 #14
0
def generateNymsData(count):
    signers = [SimpleSigner(seed=randomSeed()) for i in range(count)]
    Nym = namedtuple("Nym", ["seed", "identifier", "verkey"])
    return [
        Nym(signer.seed, signer.identifier, signer.verkey)
        for signer in signers
    ]
예제 #15
0
    def __init__(self,
                 port: int,
                 msgHandler: Callable,
                 name: str = None,
                 basedirpath: str = None,
                 seed=None,
                 onlyListener=False,
                 msgRejectHandler=None):
        stackParams = {
            "name": name or randomString(8),
            "ha": HA("0.0.0.0", port),
            "auth_mode": AuthMode.ALLOW_ANY.value
        }
        if basedirpath:
            stackParams["basedirpath"] = os.path.join(basedirpath, "keys")

        seed = seed or randomSeed()
        SimpleZStack.__init__(self,
                              stackParams,
                              self.tracedMsgHandler,
                              seed=seed,
                              onlyListener=onlyListener,
                              msgRejectHandler=msgRejectHandler)

        self.msgHandler = msgHandler
예제 #16
0
def philCli(be, do, philCLI, trusteeCli, poolTxnData):

    be(philCLI)

    do('prompt Phil', expect=prompt_is('Phil'))

    do('new wallet Phil', expect=['New wallet Phil created',
                                  'Active wallet set to "Phil"'])

    phil_seed = randomSeed()
    phil_signer = DidSigner(seed=phil_seed)

    mapper = {
        'seed': phil_seed.decode(),
        'idr': phil_signer.identifier}
    do('new key with seed {seed}', expect=['Key created in wallet Phil',
                                           'DID for key is {idr}',
                                           'Current DID set to {idr}'],
       mapper=mapper)

    addNym(be, do, trusteeCli,
           phil_signer.identifier,
           verkey=phil_signer.verkey,
           role=Roles.TRUSTEE.name)

    return philCLI
예제 #17
0
def testMessageQuota(set_info_log_level, tdir, looper):
    names = ['Alpha', 'Beta']
    genKeys(tdir, names)
    alphaP = Printer(names[0])
    betaMsgHandler = CollectingMsgsHandler()

    alpha = ZStack(names[0], ha=genHa(), basedirpath=tdir, msgHandler=alphaP.print,
                   restricted=True)
    beta = ZStack(names[1], ha=genHa(), basedirpath=tdir, msgHandler=betaMsgHandler.handler,
                  restricted=True, onlyListener=True)

    prepStacks(looper, alpha, beta, connect=True, useKeys=True)

    messages = []
    numMessages = 150 * beta.listenerQuota
    for i in range(numMessages):
        msg = json.dumps({'random': randomSeed().decode()}).encode()
        if alpha.send(msg, beta.name):
            messages.append(json.loads(msg.decode()))

    def checkAllReceived():
        assert len(messages) == len(betaMsgHandler.receivedMessages)
        assert messages == betaMsgHandler.receivedMessages

    looper.run(eventually(checkAllReceived, retryWait=0.5,
                          timeout=5))
예제 #18
0
def newStewardVals():
    newStewardSeed = randomSeed()

    return {
        'newStewardSeed': newStewardSeed.decode(),
        'newStewardIdr': SimpleSigner(seed=newStewardSeed).identifier,
    }
예제 #19
0
 def create_stack(name, handler=None):
     return ZStack(name,
                   ha=genHa(),
                   basedirpath=tdir,
                   msgHandler=handler,
                   restricted=False,
                   seed=randomSeed(),
                   config=tconf)
예제 #20
0
def newStewardVals():
    newStewardSeed = randomSeed()
    signer = DidSigner(seed=newStewardSeed)
    return {
        'newStewardSeed': newStewardSeed.decode(),
        'newStewardIdr': signer.identifier,
        'newStewardVerkey': signer.verkey
    }
예제 #21
0
def newStewardVals():
    newStewardSeed = randomSeed()
    signer = DidSigner(seed=newStewardSeed)
    return {
        'newStewardSeed': newStewardSeed.decode(),
        'newStewardIdr': signer.identifier,
        'newStewardVerkey': signer.verkey
    }
예제 #22
0
def dummyZStack(tdir, tconf):
    name = 'Alpha'
    alphaP = Printer(name)
    return ZStack(name,
                  ha=genHa(),
                  basedirpath=tdir,
                  msgHandler=alphaP.print,
                  seed=randomSeed(),
                  config=tconf)
예제 #23
0
def initNodeKeysForBothStacks(name, baseDir, sigseed, override=False):
    # `sigseed` is initialised to keep the seed same for both stacks.
    # Both node and client stacks need to have same keys
    sigseed = sigseed or randomSeed()

    nodeStackClass.initLocalKeys(name + CLIENT_STACK_SUFFIX, baseDir, sigseed,
                                 override=override)
    return nodeStackClass.initLocalKeys(name, baseDir, sigseed,
                                        override=override)
예제 #24
0
 async def prod(self, limit) -> int:
     count = 0
     while self.sentMsgCount < self._numMsgs:
         msg = json.dumps({'random': randomSeed().decode()}).encode()
         if self._fromStack.send(msg, self._toName):
             self.sentMsgCount += 1
             count += 1
         else:
             break
     return count
예제 #25
0
 async def prod(self, limit) -> int:
     count = 0
     while self.sentMsgCount < self._numMsgs:
         msg = json.dumps({'random': randomSeed().decode()}).encode()
         if self._fromStack.send(msg, self._toName):
             self.sentMsgCount += 1
             count += 1
         else:
             break
     return count
예제 #26
0
def testUnrestricted2ZStackCommunication(tdir, looper, tconf):
    """
    Create 2 ZStack and make them send and receive messages.
    Both stacks allow communication even when keys are not shared
    :return:
    """
    names = ['Alpha', 'Beta']
    alphaP = Printer(names[0])
    betaP = Printer(names[1])
    alpha = ZStack(names[0], ha=genHa(), basedirpath=tdir, msgHandler=alphaP.print,
                   restricted=False, seed=randomSeed(), config=tconf)
    beta = ZStack(names[1], ha=genHa(), basedirpath=tdir, msgHandler=betaP.print,
                  restricted=False, seed=randomSeed(), config=tconf)

    prepStacks(looper, alpha, beta, connect=True, useKeys=True)
    alpha.send({'greetings': 'hi'}, beta.name)
    beta.send({'greetings': 'hello'}, alpha.name)

    looper.run(eventually(chkPrinted, alphaP, {'greetings': 'hello'}))
    looper.run(eventually(chkPrinted, betaP, {'greetings': 'hi'}))
예제 #27
0
def createEncAndSigKeys(enc_key_dir, sig_key_dir, name, seed=None):
    seed = seed or randomSeed()
    if isinstance(seed, str):
        seed = seed.encode()
    # ATTENTION: Passing `seed` encoded to bytes or not in
    # `crypto_sign_seed_keypair` will generate different keypairs
    verif_key, sig_key = crypto_sign_seed_keypair(seed)
    createCertsFromKeys(sig_key_dir, name, z85.encode(verif_key),
                        z85.encode(sig_key[:32]))
    public_key, secret_key = ep2c(verif_key), es2c(sig_key)
    createCertsFromKeys(enc_key_dir, name, z85.encode(public_key),
                        z85.encode(secret_key))
    return (public_key, secret_key), (verif_key, sig_key)
예제 #28
0
def getNewNodeData():
    newStewardSeed = randomSeed()
    newNodeSeed = randomSeed()
    nodeIp, nodePort = genHa()
    clientIp, clientPort = genHa()

    newNodeData = {
        NODE_IP: nodeIp,
        NODE_PORT: nodePort,
        CLIENT_IP: clientIp,
        CLIENT_PORT: clientPort,
        ALIAS: randomString(6),
        SERVICES: [VALIDATOR]
    }

    return {
        'newStewardSeed': newStewardSeed,
        'newStewardIdr': SimpleSigner(seed=newStewardSeed).identifier,
        'newNodeSeed': newNodeSeed,
        'newNodeIdr': SimpleSigner(seed=newNodeSeed).identifier,
        'newNodeData': newNodeData
    }
예제 #29
0
def testNode(pluginManager, tdir, tconf, node_config_helper_class):
    name = randomText(20)
    nodeReg = genNodeReg(names=[name])
    ha, cliname, cliha = nodeReg[name]
    config_helper = node_config_helper_class(name, tconf, chroot=tdir)
    node = TestNode(name=name, ha=ha, cliname=cliname, cliha=cliha,
                    nodeRegistry=copy(nodeReg),
                    config_helper=config_helper,
                    config=tconf,
                    primaryDecider=None, pluginPaths=None, seed=randomSeed())
    node.start(None)
    yield node
    node.stop()
예제 #30
0
def createEncAndSigKeys(enc_key_dir, sig_key_dir, name, seed=None):
    seed = seed or randomSeed()
    if isinstance(seed, str):
        seed = seed.encode()
    # ATTENTION: Passing `seed` encoded to bytes or not in
    # `crypto_sign_seed_keypair` will generate different keypairs
    verif_key, sig_key = crypto_sign_seed_keypair(seed)
    createCertsFromKeys(sig_key_dir, name, z85.encode(verif_key),
                        z85.encode(sig_key[:32]))
    public_key, secret_key = ep2c(verif_key), es2c(sig_key)
    createCertsFromKeys(enc_key_dir, name, z85.encode(public_key),
                        z85.encode(secret_key))
    return (public_key, secret_key), (verif_key, sig_key)
def stacks(tdir, looper, alpha_handler):
    names = ['Alpha', 'Beta']
    genKeys(tdir, names)
    aseed = randomSeed()
    bseed = randomSeed()

    def bHandler(m):
        msg, a = m
        beta.send(msg, a)

    stackParams = {
        "name": names[0],
        "ha": genHa(),
        "auto": 2,
        "basedirpath": tdir
    }
    timer = MockTimer(0)
    alpha = SimpleZStack(stackParams,
                         alpha_handler.handle,
                         aseed,
                         False,
                         timer=timer)

    stackParams = {
        "name": names[1],
        "ha": genHa(),
        "auto": 2,
        "basedirpath": tdir
    }
    timer = MockTimer(0)
    beta = SimpleZStack(stackParams, bHandler, bseed, True, timer=timer)

    amotor = SMotor(alpha)
    looper.add(amotor)

    bmotor = SMotor(beta)
    looper.add(bmotor)
    return alpha, beta
예제 #32
0
def test_queue_size_limit_set(tdir, tconf):
    stack = ZStack("Alpha",
                   ha=genHa(),
                   basedirpath=tdir,
                   msgHandler=None,
                   restricted=False,
                   seed=randomSeed(),
                   config=tconf)
    stack.start()
    assert stack.listener.get_hwm() == 0
    stack.stop()

    queue_size = 100
    stack = ZStack("Alpha",
                   ha=genHa(),
                   basedirpath=tdir,
                   msgHandler=None,
                   restricted=False,
                   seed=randomSeed(),
                   config=tconf,
                   queue_size=queue_size)
    stack.start()
    assert stack.listener.get_hwm() == queue_size
    stack.stop()
예제 #33
0
    def __init__(self, port: int, msgHandler: Callable,
                 name: str=None, basedirpath: str=None, seed=None,
                 onlyListener=False):
        stackParams = {
            "name": name or randomString(8),
            "ha": HA("0.0.0.0", port),
            "auth_mode": AuthMode.ALLOW_ANY.value
        }
        if basedirpath:
            stackParams["basedirpath"] = basedirpath

        seed = seed or randomSeed()
        SimpleZStack.__init__(self, stackParams, self.tracedMsgHandler,
                              seed=seed, onlyListener=onlyListener)

        self.msgHandler = msgHandler
예제 #34
0
    def __init__(self, port: int, msgHandler: Callable,
                 name: str=None, basedirpath: str=None, seed=None,
                 onlyListener=False):
        stackParams = {
            "name": name or randomString(8),
            "ha": HA("0.0.0.0", port),
            "auto": AutoMode.always
        }
        if basedirpath:
            stackParams["basedirpath"] = basedirpath

        seed = seed or randomSeed()
        SimpleZStack.__init__(self, stackParams, self.baseMsgHandler,
                              seed=seed, onlyListener=onlyListener)

        self.msgHandler = msgHandler
예제 #35
0
def create_local_pool(node_base_dir, cli_base_dir, config=None, node_size=4):
    conf = config or getConfig()

    stewards = []
    node_conf = []
    nodes = []
    genesis_txns = []
    for i in range(node_size):
        w = Wallet("steward")
        s = Steward(wallet=w)
        s.wallet.addIdentifier()

        stewards.append(s)

        node_config_helper = NodeConfigHelper(conf.name,
                                              conf,
                                              chroot=node_base_dir)
        n_config = adict(name='Node' + str(i + 1),
                         basedirpath=node_config_helper.ledger_dir,
                         ha=('127.0.0.1', 9700 + (i * 2)),
                         cliha=('127.0.0.1', 9700 + (i * 2) + 1))

        n_verkey, n_bls_key, n_bls_key_proof = \
            initialize_node_environment(name=n_config.name,
                                        node_config_helper=node_config_helper,
                                        override_keep=True,
                                        sigseed=randomSeed())

        s.set_node(n_config,
                   verkey=n_verkey,
                   blskey=n_bls_key,
                   blsley_proof=n_bls_key_proof)

        node_conf.append(n_config)

        genesis_txns += s.generate_genesis_txns()

    pool = None  # LocalPool(genesis_txns, pool_dir, steward=stewards[0])

    for c in node_conf:
        n = Node(**c)
        pool.add(n)
        nodes.append(n)

    pool.runFor(5)

    return pool
예제 #36
0
def testSendAttribSucceedsForExistingDidDest(be, do, poolNodesStarted,
                                             localTrusteeCli):

    seed = randomSeed()
    idr, verkey = createHalfKeyIdentifierAndAbbrevVerkey(seed=seed)

    userCli = localTrusteeCli
    addNym(be, do, userCli, idr=idr, verkey=verkey)
    newKey(be, do, userCli, seed=seed.decode())

    sendAttribParameters = {'dest': idr, 'raw': json.dumps({'name': 'Alice'})}

    be(userCli)
    do('send ATTRIB dest={dest} raw={raw}',
       mapper=sendAttribParameters,
       expect=ATTRIBUTE_ADDED,
       within=2)
예제 #37
0
def testNode(pluginManager, tdir):
    name = randomText(20)
    nodeReg = genNodeReg(names=[name])
    ha, cliname, cliha = nodeReg[name]
    node = TestNode(name=name,
                    ha=ha,
                    cliname=cliname,
                    cliha=cliha,
                    nodeRegistry=copy(nodeReg),
                    basedirpath=tdir,
                    base_data_dir=tdir,
                    primaryDecider=None,
                    pluginPaths=None,
                    seed=randomSeed())
    node.start(None)
    yield node
    node.stop()
예제 #38
0
def create_local_pool(base_dir, node_size=4):
    conf = getConfig(base_dir)
    pool_dir = os.path.join(base_dir, "pool")

    # TODO: Need to come back to this why we need this cleanup
    shutil.rmtree(pool_dir, ignore_errors=True)

    stewards = []
    node_conf = []
    nodes = []
    genesis_txns = []
    for i in range(node_size):
        w = Wallet("steward")
        s = Steward(wallet=w)
        s.wallet.addIdentifier()

        stewards.append(s)

        n_config = adict(name='Node' + str(i + 1),
                         basedirpath=pool_dir,
                         ha=('127.0.0.1', 9700 + (i * 2)),
                         cliha=('127.0.0.1', 9700 + (i * 2) + 1))

        n_verkey, n_bls_key = initialize_node_environment(
            name=n_config.name,
            base_dir=n_config.basedirpath,
            override_keep=True,
            config=conf,
            sigseed=randomSeed())

        s.set_node(n_config, verkey=n_verkey, blskey=n_bls_key)

        node_conf.append(n_config)

        genesis_txns += s.generate_genesis_txns()

    pool = LocalPool(genesis_txns, pool_dir, steward=stewards[0])

    for c in node_conf:
        n = Node(**c)
        pool.add(n)
        nodes.append(n)

    pool.runFor(5)

    return pool
예제 #39
0
def initNodeKeysForBothStacks(name, keys_dir, sigseed, *, use_bls=True,
                              override=False):
    # `sigseed` is initialised to keep the seed same for both stacks.
    # Both node and client stacks need to have same keys
    if not sigseed:
        sigseed = sigseed or randomSeed()
        print("Generating keys for random seed", sigseed)
    else:
        print("Generating keys for provided seed", sigseed)

    node_stack_name = name
    client_stack_name = node_stack_name + CLIENT_STACK_SUFFIX
    print("Init local keys for client-stack")
    initLocalKeys(client_stack_name, keys_dir, sigseed, use_bls=False, override=override)
    print("Init local keys for node-stack")
    keys = initLocalKeys(node_stack_name, keys_dir, sigseed, use_bls=use_bls, override=override)
    return keys
예제 #40
0
def create_local_pool(base_dir, node_size=4):
    conf = getConfig(base_dir)
    pool_dir = os.path.join(base_dir, "pool")

    # TODO: Need to come back to this why we need this cleanup
    shutil.rmtree(pool_dir, ignore_errors=True)

    stewards = []
    node_conf = []
    nodes = []
    genesis_txns = []
    for i in range(node_size):
        w = Wallet("steward")
        s = Steward(wallet=w)
        s.wallet.addIdentifier()

        stewards.append(s)

        n_config = adict(name='Node'+str(i+1),
                         basedirpath=pool_dir,
                         ha=('127.0.0.1', 9700+(i * 2)),
                         cliha=('127.0.0.1', 9700+(i * 2)+1))

        n_verkey = initialize_node_environment(name=n_config.name,
                                               base_dir=n_config.basedirpath,
                                               override_keep=True,
                                               config=conf,
                                               sigseed=randomSeed())

        s.set_node(n_config, verkey=n_verkey)

        node_conf.append(n_config)

        genesis_txns += s.generate_genesis_txns()

    pool = LocalPool(genesis_txns, pool_dir, steward=stewards[0])

    for c in node_conf:
        n = Node(**c)
        pool.add(n)
        nodes.append(n)

    pool.runFor(5)

    return pool
def testSendAttribFailsForNotExistingCryptonymDest(
        be, do, poolNodesStarted, localTrusteeCli):

    seed = randomSeed()
    cryptonym = createCryptonym(seed=seed)

    userCli = localTrusteeCli
    newKey(be, do, userCli, seed=seed.decode())

    sendAttribParameters = {
        'dest': cryptonym,
        'raw': json.dumps({
            'name': 'Alice'
        })
    }

    be(userCli)
    do('send ATTRIB dest={dest} raw={raw}',
       mapper=sendAttribParameters, expect=ERROR, within=2)
예제 #42
0
def newNodeVals():
    newNodeSeed = randomSeed()
    nodeIp, nodePort = genHa()
    clientIp, clientPort = genHa()

    newNodeData = {
        NODE_IP: nodeIp,
        NODE_PORT: nodePort,
        CLIENT_IP: clientIp,
        CLIENT_PORT: clientPort,
        ALIAS: randomString(6),
        SERVICES: [VALIDATOR]
    }

    return {
        'newNodeSeed': newNodeSeed.decode(),
        'newNodeIdr': SimpleSigner(seed=newNodeSeed).identifier,
        'newNodeData': newNodeData
    }
예제 #43
0
def testSendAttribFailsForNotExistingCryptonymDest(be, do, poolNodesStarted,
                                                   localTrusteeCli):

    seed = randomSeed()
    cryptonym = createCryptonym(seed=seed)

    userCli = localTrusteeCli
    newKey(be, do, userCli, seed=seed.decode())

    sendAttribParameters = {
        'dest': cryptonym,
        'raw': json.dumps({'name': 'Alice'})
    }

    be(userCli)
    do('send ATTRIB dest={dest} raw={raw}',
       mapper=sendAttribParameters,
       expect=ERROR,
       within=2)
예제 #44
0
def newNodeVals():
    newNodeSeed = randomSeed()
    nodeIp, nodePort = genHa()
    clientIp, clientPort = genHa()

    newNodeData = {
        NODE_IP: nodeIp,
        NODE_PORT: nodePort,
        CLIENT_IP: clientIp,
        CLIENT_PORT: clientPort,
        ALIAS: randomString(6),
        SERVICES: [VALIDATOR],
        BLS_KEY: base58.b58encode(randomString(128).encode())
    }

    return {
        'newNodeSeed': newNodeSeed.decode(),
        'newNodeIdr': SimpleSigner(seed=newNodeSeed).identifier,
        'newNodeData': newNodeData
    }
def testSendAttribSucceedsForExistingDidDest(
        be, do, poolNodesStarted, localTrusteeCli):

    seed = randomSeed()
    idr, verkey = createHalfKeyIdentifierAndAbbrevVerkey(seed=seed)

    userCli = localTrusteeCli
    addNym(be, do, userCli, idr=idr, verkey=verkey)
    newKey(be, do, userCli, seed=seed.decode())

    sendAttribParameters = {
        'dest': idr,
        'raw': json.dumps({
            'name': 'Alice'
        })
    }

    be(userCli)
    do('send ATTRIB dest={dest} raw={raw}',
       mapper=sendAttribParameters, expect=ATTRIBUTE_ADDED, within=2)
예제 #46
0
def create_local_pool(node_base_dir, cli_base_dir, config=None, node_size=4):
    conf = config or getConfig()

    stewards = []
    node_conf = []
    nodes = []
    genesis_txns = []
    for i in range(node_size):
        w = Wallet("steward")
        s = Steward(wallet=w)
        s.wallet.addIdentifier()

        stewards.append(s)

        node_config_helper = NodeConfigHelper(conf.name, conf, chroot=node_base_dir)
        n_config = adict(name='Node' + str(i + 1),
                         basedirpath=node_config_helper.ledger_dir,
                         ha=('127.0.0.1', 9700 + (i * 2)),
                         cliha=('127.0.0.1', 9700 + (i * 2) + 1))

        n_verkey, n_bls_key = initialize_node_environment(name=n_config.name,
                                                          node_config_helper=node_config_helper,
                                                          override_keep=True,
                                                          sigseed=randomSeed())

        s.set_node(n_config, verkey=n_verkey, blskey=n_bls_key)

        node_conf.append(n_config)

        genesis_txns += s.generate_genesis_txns()

    pool = None  # LocalPool(genesis_txns, pool_dir, steward=stewards[0])

    for c in node_conf:
        n = Node(**c)
        pool.add(n)
        nodes.append(n)

    pool.runFor(5)

    return pool
예제 #47
0
def dummyZStack(tdir, tconf):
    name = 'Alpha'
    alphaP = Printer(name)
    return ZStack(name, ha=genHa(), basedirpath=tdir,
                  msgHandler=alphaP.print, seed=randomSeed(),
                  config=tconf)
예제 #48
0
 def create_stack(name, handler=None):
     return ZStack(name, ha=genHa(), basedirpath=tdir,
                   msgHandler=handler, restricted=False,
                   seed=randomSeed(), config=tconf)
def ensurePoolIsOperable(be, do, cli):
    randomNymMapper = {
        'remote': SimpleSigner(seed=randomSeed()).identifier
    }
    addAgent(be, do, cli, randomNymMapper, CONNECTED_TO_TEST, NYM_ADDED)
예제 #50
0
def ensurePoolIsOperable(be, do, cli):
    randomNymMapper = {
        'remote': DidSigner(seed=randomSeed()).identifier
    }
    addAgent(be, do, cli, randomNymMapper)