Exemplo n.º 1
0
def testManual(do, be, poolNodesStarted, poolTxnStewardData, philCLI,
               connectedToTest, nymAddedOut, attrAddedOut,
               aliceCLI, newKeyringOut, aliceMap,
               tdir, syncLinkOutWithEndpoint, jobCertificateClaimMap,
               syncedInviteAcceptedOutWithoutClaims, transcriptClaimMap,
               reqClaimOut, reqClaimOut1, susanCLI, susanMap):
    eventually.slowFactor = 3

    # Create steward and add nyms and endpoint attributes of all agents
    _, stewardSeed = poolTxnStewardData
    be(philCLI)
    do('new keyring Steward', expect=['New keyring Steward created',
                                      'Active keyring set to "Steward"'])

    mapper = {'seed': stewardSeed.decode()}
    do('new key with seed {seed}', expect=['Key created in keyring Steward'],
       mapper=mapper)
    do('connect test', within=3, expect=connectedToTest)

    # Add nym and endpoint for Faber, Acme and Thrift
    agentIpAddress = "127.0.0.1"
    faberAgentPort = 5555
    acmeAgentPort = 6666
    thriftAgentPort = 7777
    faberEndpoint = "{}:{}".format(agentIpAddress, faberAgentPort)
    acmeEndpoint = "{}:{}".format(agentIpAddress, acmeAgentPort)
    thriftEndpoint = "{}:{}".format(agentIpAddress, thriftAgentPort)

    faberHa = "{}:{}".format(agentIpAddress, faberAgentPort)
    acmeHa = "{}:{}".format(agentIpAddress, acmeAgentPort)
    thriftHa = "{}:{}".format(agentIpAddress, thriftAgentPort)
    faberId = 'FuN98eH2eZybECWkofW6A9BKJxxnTatBCopfUiNxo6ZB'
    acmeId = '7YD5NKn3P4wVJLesAmA1rr7sLPqW9mR1nhFdKD518k21'
    thriftId = '9jegUr9vAMqoqQQUEAiCBYNQDnUbTktQY9nNspxfasZW'
    faberPk = '5hmMA64DDQz5NzGJNVtRzNwpkZxktNQds21q3Wxxa62z'
    acmePk = 'C5eqjU7NMVMGGfGfx2ubvX5H9X346bQt5qeziVAo3naQ'
    thriftPk = 'AGBjYvyM3SFnoiDGAEzkSLHvqyzVkXeMZfKDvdpEsC2x'
    for nym, ha, pk in [(faberId, faberHa, faberPk),
                    (acmeId, acmeHa, acmePk),
                    (thriftId, thriftHa, thriftPk)]:
        m = {'remote': nym, 'endpoint': json.dumps({ENDPOINT:
                                                    {'ha': ha, PUBKEY: pk}})}
        do('send NYM dest={{remote}} role={role}'.format(role=Roles.TRUST_ANCHOR.name),
            within=5,
            expect=nymAddedOut, mapper=m)
        do('send ATTRIB dest={remote} raw={endpoint}', within=5,
           expect=attrAddedOut, mapper=m)

    # Start Faber Agent and Acme Agent

    fMap = faberMap(agentIpAddress, faberAgentPort)
    aMap = acmeMap(agentIpAddress, acmeAgentPort)
    tMap = thriftMap(agentIpAddress, thriftAgentPort)

    agentParams = [
        (create_faber, "Faber College", faberAgentPort,
         buildFaberWallet, bootstrap_faber),
        (create_acme, "Acme Corp", acmeAgentPort,
         buildAcmeWallet, bootstrap_acme),
        (create_thrift, "Thrift Bank", thriftAgentPort,
         buildThriftWallet, bootstrap_thrift)
    ]

    for create_agent_fuc, agentName, agentPort, buildAgentWalletFunc, bootstrap_func in agentParams:
        agent = create_agent_fuc(name=agentName, wallet=buildAgentWalletFunc(),
                                 base_dir_path=tdir, port=agentPort)
        RunnableAgent.run_agent(agent, bootstrap=bootstrap_func(agent), looper=philCLI.looper)

    for p in philCLI.looper.prodables:
        if p.name == 'Faber College':
            faberAgent = p
        if p.name == 'Acme Corp':
            acmeAgent = p
        if p.name == 'Thrift Bank':
            thriftAgent = p

    async def checkTranscriptWritten():
        faberId = faberAgent.wallet.defaultId
        schemaId = ID(SchemaKey("Transcript", "1.2", faberId))
        schema = await faberAgent.issuer.wallet.getSchema(schemaId)
        assert schema
        assert schema.seqId

        issuerPublicKey = await faberAgent.issuer.wallet.getPublicKey(schemaId)
        assert issuerPublicKey  # TODO isinstance(issuerPublicKey, PublicKey)

    async def checkJobCertWritten():
        acmeId = acmeAgent.wallet.defaultId
        schemaId = ID(SchemaKey("Job-Certificate", "0.2", acmeId))
        schema = await acmeAgent.issuer.wallet.getSchema(schemaId)
        assert schema
        assert schema.seqId

        issuerPublicKey = await acmeAgent.issuer.wallet.getPublicKey(schemaId)
        assert issuerPublicKey
        assert issuerPublicKey.seqId

    timeout = waits.expectedTranscriptWritten()
    philCLI.looper.run(eventually(checkTranscriptWritten, timeout=timeout))
    timeout = waits.expectedJobCertWritten()
    philCLI.looper.run(eventually(checkJobCertWritten, timeout=timeout))

    # Defining inner method for closures
    def executeGstFlow(name, userCLI, userMap, be, connectedToTest, do, fMap,
                       aMap, jobCertificateClaimMap, newKeyringOut, reqClaimOut,
                       reqClaimOut1, syncLinkOutWithEndpoint,
                       syncedInviteAcceptedOutWithoutClaims, tMap,
                       transcriptClaimMap):

        async def getPublicKey(wallet, schemaId):
            return await wallet.getPublicKey(schemaId)

        async def getClaim(schemaId):
            return await userCLI.agent.prover.wallet.getClaims(schemaId)

        # Start User cli

        be(userCLI)
        setPromptAndKeyring(do, name, newKeyringOut, userMap)
        do('connect test', within=3, expect=connectedToTest)
        # Accept faber
        do('load sample/faber-invitation.sovrin')
        syncInvite(be, do, userCLI, syncLinkOutWithEndpoint, fMap)
        do('show link faber')
        acceptInvitation(be, do, userCLI, fMap,
                         syncedInviteAcceptedOutWithoutClaims)
        # Request claim
        do('show claim Transcript')
        aliceRequestedTranscriptClaim(be, do, userCLI, transcriptClaimMap,
                                      reqClaimOut,
                                      None,  # Passing None since its not used
                                      None)  # Passing None since its not used

        faberSchemaId = ID(SchemaKey('Transcript', '1.2', fMap['remote']))
        faberIssuerPublicKey = userCLI.looper.run(
            getPublicKey(faberAgent.issuer.wallet, faberSchemaId))
        userFaberIssuerPublicKey = userCLI.looper.run(
            getPublicKey(userCLI.agent.prover.wallet, faberSchemaId))
        assert faberIssuerPublicKey == userFaberIssuerPublicKey

        do('show claim Transcript')
        assert userCLI.looper.run(getClaim(faberSchemaId))

        # Accept acme
        do('load sample/acme-job-application.sovrin')
        syncInvite(be, do, userCLI, syncLinkOutWithEndpoint, aMap)
        acceptInvitation(be, do, userCLI, aMap,
                         syncedInviteAcceptedOutWithoutClaims)
        # Send claim
        do('show claim request Job-Application')
        do('set first_name to Alice')
        do('set last_name to Garcia')
        do('set phone_number to 123-45-6789')
        do('show claim request Job-Application')
        # Passing some args as None since they are not used in the method
        jobApplicationProofSent(be, do, userCLI, aMap, None, None, None)
        do('show claim Job-Certificate')
        # Request new available claims Job-Certificate
        jobCertClaimRequested(be, do, userCLI, None,
                              jobCertificateClaimMap, reqClaimOut1, None)

        acmeSchemaId = ID(SchemaKey('Job-Certificate', '0.2', aMap['remote']))
        acmeIssuerPublicKey = userCLI.looper.run(getPublicKey(
            acmeAgent.issuer.wallet, acmeSchemaId))
        userAcmeIssuerPublicKey = userCLI.looper.run(getPublicKey(
            userCLI.agent.prover.wallet, acmeSchemaId))
        assert acmeIssuerPublicKey == userAcmeIssuerPublicKey

        do('show claim Job-Certificate')
        assert userCLI.looper.run(getClaim(acmeSchemaId))

        # Accept thrift
        do('load sample/thrift-loan-application.sovrin')
        acceptInvitation(be, do, userCLI, tMap,
                         syncedInviteAcceptedOutWithoutClaims)
        # Send proofs
        bankBasicProofSent(be, do, userCLI, tMap, None)

        thriftAcmeIssuerPublicKey = userCLI.looper.run(getPublicKey(
            thriftAgent.issuer.wallet, acmeSchemaId))
        assert acmeIssuerPublicKey == thriftAcmeIssuerPublicKey
        passed = False
        try:
            bankKYCProofSent(be, do, userCLI, tMap, None)
            passed = True
        except:
            thriftFaberIssuerPublicKey = userCLI.looper.run(getPublicKey(
                thriftAgent.issuer.wallet, faberSchemaId))
            assert faberIssuerPublicKey == thriftFaberIssuerPublicKey
        assert passed

    executeGstFlow("Alice", aliceCLI, aliceMap, be, connectedToTest, do, fMap,
                   aMap, jobCertificateClaimMap, newKeyringOut, reqClaimOut,
                   reqClaimOut1, syncLinkOutWithEndpoint,
                   syncedInviteAcceptedOutWithoutClaims, tMap,
                   transcriptClaimMap)

    aliceCLI.looper.runFor(3)
Exemplo n.º 2
0
def testManual(do, be, poolNodesStarted, poolTxnStewardData, philCLI,
               connectedToTest, nymAddedOut, attrAddedOut, schemaAdded,
               issuerKeyAdded, aliceCLI, newKeyringOut, aliceMap, tdir,
               syncLinkOutWithEndpoint, jobCertificateClaimMap,
               syncedInviteAcceptedOutWithoutClaims, transcriptClaimMap,
               reqClaimOut, reqClaimOut1, susanCLI, susanMap):
    eventually.slowFactor = 3

    # Create steward and add nyms and endpoint atttributes of all agents
    _, stewardSeed = poolTxnStewardData
    be(philCLI)
    do('new keyring Steward',
       expect=[
           'New keyring Steward created', 'Active keyring set to "Steward"'
       ])

    mapper = {'seed': stewardSeed.decode()}
    do('new key with seed {seed}',
       expect=['Key created in keyring Steward'],
       mapper=mapper)
    do('connect test', within=3, expect=connectedToTest)

    # Add nym and endpoint for Faber, Acme and Thrift
    agentIpAddress = "127.0.0.1"
    faberAgentPort = 5555
    acmeAgentPort = 6666
    thriftAgentPort = 7777
    faberEndpoint = "{}:{}".format(agentIpAddress, faberAgentPort)
    acmeEndpoint = "{}:{}".format(agentIpAddress, acmeAgentPort)
    thriftEndpoint = "{}:{}".format(agentIpAddress, thriftAgentPort)

    for nym, ep in [
        ('FuN98eH2eZybECWkofW6A9BKJxxnTatBCopfUiNxo6ZB', faberEndpoint),
        ('7YD5NKn3P4wVJLesAmA1rr7sLPqW9mR1nhFdKD518k21', acmeEndpoint),
        ('9jegUr9vAMqoqQQUEAiCBYNQDnUbTktQY9nNspxfasZW', thriftEndpoint)
    ]:
        m = {'target': nym, 'endpoint': json.dumps({ENDPOINT: ep})}
        do('send NYM dest={target} role=SPONSOR',
           within=3,
           expect=nymAddedOut,
           mapper=m)
        do('send ATTRIB dest={target} raw={endpoint}',
           within=3,
           expect=attrAddedOut,
           mapper=m)

    # Start Faber Agent and Acme Agent

    fMap = faberMap(agentIpAddress, faberAgentPort)
    aMap = acmeMap(agentIpAddress, acmeAgentPort)
    tMap = thriftMap(agentIpAddress, thriftAgentPort)

    agentParams = [
        (FaberAgent, "Faber College", faberAgentPort, buildFaberWallet),
        (AcmeAgent, "Acme Corp", acmeAgentPort, buildAcmeWallet),
        (ThriftAgent, "Thrift Bank", thriftAgentPort, buildThriftWallet)
    ]

    for agentCls, agentName, agentPort, buildAgentWalletFunc in \
            agentParams:
        agentCls.getPassedArgs = lambda _: (agentPort, )
        createAndRunAgent(agentCls, agentName, buildAgentWalletFunc(), tdir,
                          agentPort, philCLI.looper, TestClient)

    for p in philCLI.looper.prodables:
        if p.name == 'Faber College':
            faberAgent = p
        if p.name == 'Acme Corp':
            acmeAgent = p
        if p.name == 'Thrift Bank':
            thriftAgent = p

    async def checkTranscriptWritten():
        faberId = faberAgent.wallet.defaultId
        schemaId = ID(SchemaKey("Transcript", "1.2", faberId))
        schema = await faberAgent.issuer.wallet.getSchema(schemaId)
        assert schema
        assert schema.seqId

        issuerKey = faberAgent.issuer.wallet.getPublicKey(schemaId)
        assert issuerKey

    async def checkJobCertWritten():
        acmeId = acmeAgent.wallet.defaultId
        schemaId = ID(SchemaKey("Job-Certificate", "0.2", acmeId))
        schema = await acmeAgent.issuer.wallet.getSchema(schemaId)
        assert schema
        assert schema.seqId

        issuerKey = await acmeAgent.issuer.wallet.getPublicKey(schemaId)
        assert issuerKey
        assert issuerKey.seqId

    philCLI.looper.run(eventually(checkTranscriptWritten, timeout=10))
    philCLI.looper.run(eventually(checkJobCertWritten, timeout=10))

    # Defining inner method for closures
    def executeGstFlow(name, userCLI, userMap, be, connectedToTest, do, fMap,
                       aMap, jobCertificateClaimMap, newKeyringOut,
                       reqClaimOut, reqClaimOut1, syncLinkOutWithEndpoint,
                       syncedInviteAcceptedOutWithoutClaims, tMap,
                       transcriptClaimMap):
        async def getPublicKey(wallet, schemaId):
            return await wallet.getPublicKey(schemaId)

        async def getClaim(schemaId):
            return userCLI.agent.prover.wallet.getClaims(schemaId)

        # Start User cli

        be(userCLI)
        setPromptAndKeyring(do, name, newKeyringOut, userMap)
        do('connect test', within=3, expect=connectedToTest)
        # Accept faber
        do('load sample/faber-invitation.sovrin')
        syncInvite(be, do, userCLI, syncLinkOutWithEndpoint, fMap)
        do('show link faber')
        acceptInvitation(be, do, userCLI, fMap,
                         syncedInviteAcceptedOutWithoutClaims)
        # Request claim
        do('show claim Transcript')
        aliceRequestedTranscriptClaim(
            be,
            do,
            userCLI,
            transcriptClaimMap,
            reqClaimOut,
            None,  # Passing None since its not used
            None)  # Passing None since its not used

        faberSchemaId = ID(SchemaKey('Transcript', '1.2', fMap['target']))
        faberIssuerKey = userCLI.looper.run(
            getPublicKey(faberAgent.issuer.wallet, faberSchemaId))
        userFaberIssuerKey = userCLI.looper.run(
            getPublicKey(userCLI.agent.prover.wallet, faberSchemaId))
        assert faberIssuerKey == userFaberIssuerKey

        do('show claim Transcript')
        assert userCLI.looper.run(getClaim(faberSchemaId))

        # Accept acme
        do('load sample/acme-job-application.sovrin')
        syncInvite(be, do, userCLI, syncLinkOutWithEndpoint, aMap)
        acceptInvitation(be, do, userCLI, aMap,
                         syncedInviteAcceptedOutWithoutClaims)
        # Send claim
        do('show claim request Job-Application')
        do('set first_name to Alice')
        do('set last_name to Garcia')
        do('set phone_number to 123-45-6789')
        do('show claim request Job-Application')
        # Passing some args as None since they are not used in the method
        jobApplicationClaimSent(be, do, userCLI, aMap, None, None, None)
        do('show claim Job-Certificate')
        # Request new available claims Job-Certificate
        jobCertClaimRequested(be, do, userCLI, None, jobCertificateClaimMap,
                              reqClaimOut1, None)

        acmeSchemaId = ID(SchemaKey('Job-Certificate', '0.2', aMap['target']))
        acmeIssuerKey = userCLI.looper.run(
            getPublicKey(acmeAgent.issuer.wallet, acmeSchemaId))
        userAcmeIssuerKey = userCLI.looper.run(
            getPublicKey(userCLI.agent.prover.wallet, acmeSchemaId))
        assert acmeIssuerKey == userAcmeIssuerKey

        do('show claim Job-Certificate')
        assert userCLI.looper.run(getClaim(acmeSchemaId))

        # Accept thrift
        do('load sample/thrift-loan-application.sovrin')
        acceptInvitation(be, do, userCLI, tMap,
                         syncedInviteAcceptedOutWithoutClaims)
        # Send claims
        bankBasicClaimSent(be, do, userCLI, tMap, None)

        thriftAcmeIssuerKey = userCLI.looper.run(
            getPublicKey(thriftAgent.issuer.wallet, acmeSchemaId))
        assert acmeIssuerKey == thriftAcmeIssuerKey
        passed = False
        try:
            bankKYCClaimSent(be, do, userCLI, tMap, None)
            passed = True
        except:
            thriftFaberIssuerKey = userCLI.looper.run(
                getPublicKey(thriftAgent.issuer.wallet, faberSchemaId))
            assert faberIssuerKey == thriftFaberIssuerKey
        assert passed

    executeGstFlow("Alice", aliceCLI, aliceMap, be, connectedToTest, do, fMap,
                   aMap, jobCertificateClaimMap, newKeyringOut, reqClaimOut,
                   reqClaimOut1, syncLinkOutWithEndpoint,
                   syncedInviteAcceptedOutWithoutClaims, tMap,
                   transcriptClaimMap)

    aliceCLI.looper.runFor(3)

    executeGstFlow("Susan", susanCLI, susanMap, be, connectedToTest, do, fMap,
                   aMap, jobCertificateClaimMap, newKeyringOut, reqClaimOut,
                   reqClaimOut1, syncLinkOutWithEndpoint,
                   syncedInviteAcceptedOutWithoutClaims, tMap,
                   transcriptClaimMap)
def testManual(do, be, poolNodesStarted, poolTxnStewardData, philCli,
               connectedToTest, nymAddedOut, attrAddedOut, aliceCLI,
               newKeyringOut, aliceMap, tdir, syncLinkOutWithEndpoint,
               jobCertificateClaimMap, syncedInviteAcceptedOutWithoutClaims,
               transcriptClaimMap, reqClaimOut, reqClaimOut1, susanCLI,
               susanMap):
    eventually.slowFactor = 3

    # Create steward and add nyms and endpoint attributes of all agents
    _, stewardSeed = poolTxnStewardData
    be(philCli)
    do('new keyring Steward',
       expect=[
           'New keyring Steward created', 'Active keyring set to "Steward"'
       ])

    mapper = {'seed': stewardSeed.decode()}
    do('new key with seed {seed}',
       expect=['Key created in keyring Steward'],
       mapper=mapper)
    do('connect test', within=3, expect=connectedToTest)

    # Add nym and endpoint for Faber, Acme and Thrift
    agentIpAddress = "127.0.0.1"
    faberAgentPort = 5555
    acmeAgentPort = 6666
    thriftAgentPort = 7777
    faberEndpoint = "{}:{}".format(agentIpAddress, faberAgentPort)
    acmeEndpoint = "{}:{}".format(agentIpAddress, acmeAgentPort)
    thriftEndpoint = "{}:{}".format(agentIpAddress, thriftAgentPort)

    faberHa = "{}:{}".format(agentIpAddress, faberAgentPort)
    acmeHa = "{}:{}".format(agentIpAddress, acmeAgentPort)
    thriftHa = "{}:{}".format(agentIpAddress, thriftAgentPort)
    faberId = FABER_ID
    acmeId = ACME_ID
    thriftId = THRIFT_ID
    faberVerkey = FABER_VERKEY
    acmeVerkey = ACME_VERKEY
    thriftVerkey = THRIFT_VERKEY
    faberPk = '5hmMA64DDQz5NzGJNVtRzNwpkZxktNQds21q3Wxxa62z'
    acmePk = 'C5eqjU7NMVMGGfGfx2ubvX5H9X346bQt5qeziVAo3naQ'
    thriftPk = 'AGBjYvyM3SFnoiDGAEzkSLHvqyzVkXeMZfKDvdpEsC2x'
    for nym, verkey, ha, pk in [(faberId, faberVerkey, faberHa, faberPk),
                                (acmeId, acmeVerkey, acmeHa, acmePk),
                                (thriftId, thriftVerkey, thriftHa, thriftPk)]:
        m = {
            'remote': nym,
            'remote-verkey': verkey,
            'endpoint': json.dumps({ENDPOINT: {
                'ha': ha,
                PUBKEY: pk
            }})
        }
        do('send NYM dest={{remote}} role={role}'.format(
            role=Roles.TRUST_ANCHOR.name),
           within=5,
           expect=nymAddedOut,
           mapper=m)
        do('send ATTRIB dest={remote} raw={endpoint}',
           within=5,
           expect=attrAddedOut,
           mapper=m)
        do('send NYM dest={{remote}} role={role} verkey={{remote-verkey}}'.
           format(role=Roles.TRUST_ANCHOR.name),
           within=5,
           expect=nymAddedOut,
           mapper=m)

    # Start Faber Agent and Acme Agent

    fMap = faberMap(agentIpAddress, faberAgentPort)
    aMap = acmeMap(agentIpAddress, acmeAgentPort)
    tMap = thriftMap(agentIpAddress, thriftAgentPort)

    agentParams = [(create_faber, "Faber College", faberAgentPort,
                    buildFaberWallet, bootstrap_faber),
                   (create_acme, "Acme Corp", acmeAgentPort, buildAcmeWallet,
                    bootstrap_acme),
                   (create_thrift, "Thrift Bank", thriftAgentPort,
                    buildThriftWallet, bootstrap_thrift)]

    for create_agent_fuc, agentName, agentPort, buildAgentWalletFunc, bootstrap_func in agentParams:
        agent = create_agent_fuc(name=agentName,
                                 wallet=buildAgentWalletFunc(),
                                 base_dir_path=tdir,
                                 port=agentPort)
        RunnableAgent.run_agent(agent,
                                bootstrap=bootstrap_func(agent),
                                looper=philCli.looper)

    for p in philCli.looper.prodables:
        if p.name == 'Faber College':
            faberAgent = p
        if p.name == 'Acme Corp':
            acmeAgent = p
        if p.name == 'Thrift Bank':
            thriftAgent = p

    async def checkTranscriptWritten():
        faberId = faberAgent.wallet.defaultId
        schemaId = ID(SchemaKey("Transcript", "1.2", faberId))
        schema = await faberAgent.issuer.wallet.getSchema(schemaId)
        assert schema
        assert schema.seqId

        issuerPublicKey = await faberAgent.issuer.wallet.getPublicKey(schemaId)
        assert issuerPublicKey  # TODO isinstance(issuerPublicKey, PublicKey)

    async def checkJobCertWritten():
        acmeId = acmeAgent.wallet.defaultId
        schemaId = ID(SchemaKey("Job-Certificate", "0.2", acmeId))
        schema = await acmeAgent.issuer.wallet.getSchema(schemaId)
        assert schema
        assert schema.seqId

        issuerPublicKey = await acmeAgent.issuer.wallet.getPublicKey(schemaId)
        assert issuerPublicKey
        assert issuerPublicKey.seqId

    timeout = waits.expectedTranscriptWritten()
    philCli.looper.run(eventually(checkTranscriptWritten, timeout=timeout))
    timeout = waits.expectedJobCertWritten()
    philCli.looper.run(eventually(checkJobCertWritten, timeout=timeout))

    # Defining inner method for closures
    def executeGstFlow(name, userCLI, userMap, be, connectedToTest, do, fMap,
                       aMap, jobCertificateClaimMap, newKeyringOut,
                       reqClaimOut, reqClaimOut1, syncLinkOutWithEndpoint,
                       syncedInviteAcceptedOutWithoutClaims, tMap,
                       transcriptClaimMap):
        async def getPublicKey(wallet, schemaId):
            return await wallet.getPublicKey(schemaId)

        async def getClaim(schemaId):
            return await userCLI.agent.prover.wallet.getClaimSignature(schemaId
                                                                       )

        # Start User cli

        be(userCLI)
        setPromptAndKeyring(do, name, newKeyringOut, userMap)
        do('connect test', within=3, expect=connectedToTest)
        # Accept faber
        do('load sample/faber-invitation.sovrin')
        syncInvite(be, do, userCLI, syncLinkOutWithEndpoint, fMap)
        do('show link faber')
        acceptInvitation(be, do, userCLI, fMap,
                         syncedInviteAcceptedOutWithoutClaims)
        # Request claim
        do('show claim Transcript')
        aliceRequestedTranscriptClaim(
            be,
            do,
            userCLI,
            transcriptClaimMap,
            reqClaimOut,
            None,  # Passing None since its not used
            None)  # Passing None since its not used

        faberSchemaId = ID(SchemaKey('Transcript', '1.2', fMap['remote']))
        faberIssuerPublicKey = userCLI.looper.run(
            getPublicKey(faberAgent.issuer.wallet, faberSchemaId))
        userFaberIssuerPublicKey = userCLI.looper.run(
            getPublicKey(userCLI.agent.prover.wallet, faberSchemaId))
        assert faberIssuerPublicKey == userFaberIssuerPublicKey

        do('show claim Transcript')
        assert userCLI.looper.run(getClaim(faberSchemaId))

        # Accept acme
        do('load sample/acme-job-application.sovrin')
        syncInvite(be, do, userCLI, syncLinkOutWithEndpoint, aMap)
        acceptInvitation(be, do, userCLI, aMap,
                         syncedInviteAcceptedOutWithoutClaims)
        # Send claim
        do('show claim request Job-Application')
        do('set first_name to Alice')
        do('set last_name to Garcia')
        do('set phone_number to 123-45-6789')
        do('show claim request Job-Application')
        # Passing some args as None since they are not used in the method
        jobApplicationProofSent(be, do, userCLI, aMap, None, None, None)
        do('show claim Job-Certificate')
        # Request new available claims Job-Certificate
        jobCertClaimRequested(be, do, userCLI, None, jobCertificateClaimMap,
                              reqClaimOut1, None)

        acmeSchemaId = ID(SchemaKey('Job-Certificate', '0.2', aMap['remote']))
        acmeIssuerPublicKey = userCLI.looper.run(
            getPublicKey(acmeAgent.issuer.wallet, acmeSchemaId))
        userAcmeIssuerPublicKey = userCLI.looper.run(
            getPublicKey(userCLI.agent.prover.wallet, acmeSchemaId))
        assert acmeIssuerPublicKey == userAcmeIssuerPublicKey

        do('show claim Job-Certificate')
        assert userCLI.looper.run(getClaim(acmeSchemaId))

        # Accept thrift
        do('load sample/thrift-loan-application.sovrin')
        acceptInvitation(be, do, userCLI, tMap,
                         syncedInviteAcceptedOutWithoutClaims)
        # Send proofs
        bankBasicProofSent(be, do, userCLI, tMap, None)

        thriftAcmeIssuerPublicKey = userCLI.looper.run(
            getPublicKey(thriftAgent.issuer.wallet, acmeSchemaId))
        assert acmeIssuerPublicKey == thriftAcmeIssuerPublicKey
        passed = False
        try:
            bankKYCProofSent(be, do, userCLI, tMap, None)
            passed = True
        except:
            thriftFaberIssuerPublicKey = userCLI.looper.run(
                getPublicKey(thriftAgent.issuer.wallet, faberSchemaId))
            assert faberIssuerPublicKey == thriftFaberIssuerPublicKey
        assert passed

    executeGstFlow("Alice", aliceCLI, aliceMap, be, connectedToTest, do, fMap,
                   aMap, jobCertificateClaimMap, newKeyringOut, reqClaimOut,
                   reqClaimOut1, syncLinkOutWithEndpoint,
                   syncedInviteAcceptedOutWithoutClaims, tMap,
                   transcriptClaimMap)

    aliceCLI.looper.runFor(3)
Exemplo n.º 4
0
def testManual(do, be, poolNodesStarted, poolTxnStewardData, philCLI,
               connectedToTest, nymAddedOut, attrAddedOut, schemaAdded,
               claimDefAdded, aliceCLI, newKeyringOut, aliceMap, tdir,
               syncLinkOutWithEndpoint, jobCertificateClaimMap,
               syncedInviteAcceptedOutWithoutClaims, transcriptClaimMap,
               reqClaimOut, reqClaimOut1, susanCLI, susanMap):
    eventually.slowFactor = 3

    # Create steward and add nyms and endpoint attributes of all agents
    _, stewardSeed = poolTxnStewardData
    be(philCLI)
    do('new keyring Steward',
       expect=[
           'New keyring Steward created', 'Active keyring set to "Steward"'
       ])

    mapper = {'seed': stewardSeed.decode()}
    do('new key with seed {seed}',
       expect=['Key created in keyring Steward'],
       mapper=mapper)
    do('connect test', within=3, expect=connectedToTest)

    # Add nym and endpoint for Faber, Acme and Thrift
    agentIpAddress = "127.0.0.1"
    faberAgentPort = 5555
    acmeAgentPort = 6666
    thriftAgentPort = 7777

    faberHa = "{}:{}".format(agentIpAddress, faberAgentPort)
    acmeHa = "{}:{}".format(agentIpAddress, acmeAgentPort)
    thriftHa = "{}:{}".format(agentIpAddress, thriftAgentPort)
    faberId = 'FuN98eH2eZybECWkofW6A9BKJxxnTatBCopfUiNxo6ZB'
    acmeId = '7YD5NKn3P4wVJLesAmA1rr7sLPqW9mR1nhFdKD518k21'
    thriftId = '9jegUr9vAMqoqQQUEAiCBYNQDnUbTktQY9nNspxfasZW'
    faberPk = '5hmMA64DDQz5NzGJNVtRzNwpkZxktNQds21q3Wxxa62z'
    acmePk = 'C5eqjU7NMVMGGfGfx2ubvX5H9X346bQt5qeziVAo3naQ'
    thriftPk = 'AGBjYvyM3SFnoiDGAEzkSLHvqyzVkXeMZfKDvdpEsC2x'
    for nym, ha, pk in [(faberId, faberHa, faberPk), (acmeId, acmeHa, acmePk),
                        (thriftId, thriftHa, thriftPk)]:
        m = {
            'target': nym,
            'endpoint': json.dumps({ENDPOINT: {
                'ha': ha,
                PUBKEY: pk
            }})
        }
        do('send NYM dest={{target}} role={role}'.format(
            role=Roles.TRUST_ANCHOR.name),
           within=5,
           expect=nymAddedOut,
           mapper=m)
        do('send ATTRIB dest={target} raw={endpoint}',
           within=5,
           expect=attrAddedOut,
           mapper=m)

    # Start Faber Agent and Acme Agent
    fMap = faberMap(agentIpAddress, faberAgentPort)
    aMap = acmeMap(agentIpAddress, acmeAgentPort)
    tMap = thriftMap(agentIpAddress, thriftAgentPort)

    agentParams = [
        (FaberAgent, "Faber College", faberAgentPort, buildFaberWallet),
        (AcmeAgent, "Acme Corp", acmeAgentPort, buildAcmeWallet),
        (ThriftAgent, "Thrift Bank", thriftAgentPort, buildThriftWallet)
    ]

    faberAgent, acmeAgent, thriftAgent = None, None, None

    def startAgents():
        for agentCls, agentName, agentPort, buildAgentWalletFunc in \
                agentParams:
            agentCls.getPassedArgs = lambda _: (agentPort, False)
            TestWalletedAgent.createAndRunAgent(agentName, agentCls,
                                                buildAgentWalletFunc(), tdir,
                                                agentPort, philCLI.looper,
                                                TestClient)
        _faberAgent, _acmeAgent, _thriftAgent = None, None, None
        for p in philCLI.looper.prodables:
            if p.name == 'Faber College':
                _faberAgent = p
            if p.name == 'Acme Corp':
                _acmeAgent = p
            if p.name == 'Thrift Bank':
                _thriftAgent = p
        philCLI.looper.runFor(5)
        return _faberAgent, _acmeAgent, _thriftAgent

    def restartAgents():
        for agent in [faberAgent, acmeAgent, thriftAgent]:
            agent.stop()
            philCLI.looper.removeProdable(name=agent.name)
        return startAgents()

    faberAgent, acmeAgent, thriftAgent = startAgents()

    async def checkTranscriptWritten():
        faberId = faberAgent.wallet.defaultId
        schemaId = ID(SchemaKey("Transcript", "1.2", faberId))
        schema = await faberAgent.issuer.wallet.getSchema(schemaId)
        assert schema
        assert schema.seqId

        issuerPublicKey = faberAgent.issuer.wallet.getPublicKey(schemaId)
        assert issuerPublicKey  # TODO isinstance(issuerPublicKey, PublicKey)

    async def checkJobCertWritten():
        acmeId = acmeAgent.wallet.defaultId
        schemaId = ID(SchemaKey("Job-Certificate", "0.2", acmeId))
        schema = await acmeAgent.issuer.wallet.getSchema(schemaId)
        assert schema
        assert schema.seqId

        issuerPublicKey = await acmeAgent.issuer.wallet.getPublicKey(schemaId)
        assert issuerPublicKey
        assert issuerPublicKey.seqId

    timeout = waits.expectedTranscriptWritten()
    philCLI.looper.run(eventually(checkTranscriptWritten, timeout=timeout))
    timeout = waits.expectedJobCertWritten()
    philCLI.looper.run(eventually(checkJobCertWritten, timeout=timeout))

    # Defining inner method for closures
    def executeGstFlow(name, userCLI, userMap, be, connectedToTest, do, fMap,
                       aMap, jobCertificateClaimMap, newKeyringOut,
                       reqClaimOut, reqClaimOut1, syncLinkOutWithEndpoint,
                       syncedInviteAcceptedOutWithoutClaims, tMap,
                       transcriptClaimMap):
        async def getPublicKey(wallet, schemaId):
            return await wallet.getPublicKey(schemaId)

        async def getClaim(schemaId):
            return await userCLI.agent.prover.wallet.getClaims(schemaId)

        # Start User cli

        be(userCLI)
        setPromptAndKeyring(do, name, newKeyringOut, userMap)
        do('connect test', within=3, expect=connectedToTest)
        # Accept faber
        do('load sample/faber-invitation.sovrin')
        syncInvite(be, do, userCLI, syncLinkOutWithEndpoint, fMap)
        do('show link faber')
        acceptInvitation(be, do, userCLI, fMap,
                         syncedInviteAcceptedOutWithoutClaims)

        # TODO: restart agents to test everything still works fine
        # faberAgent, acmeAgent, thriftAgent = restartAgents()

        # Request claim
        do('show claim Transcript')
        aliceRequestedTranscriptClaim(
            be,
            do,
            userCLI,
            transcriptClaimMap,
            reqClaimOut,
            None,  # Passing None since its not used
            None)  # Passing None since its not used

        faberSchemaId = ID(SchemaKey('Transcript', '1.2', fMap['target']))
        faberIssuerPublicKey = userCLI.looper.run(
            getPublicKey(faberAgent.issuer.wallet, faberSchemaId))
        userFaberIssuerPublicKey = userCLI.looper.run(
            getPublicKey(userCLI.agent.prover.wallet, faberSchemaId))
        assert faberIssuerPublicKey == userFaberIssuerPublicKey

        do('show claim Transcript')
        assert userCLI.looper.run(getClaim(faberSchemaId))

        # Accept acme
        do('load sample/acme-job-application.sovrin')
        syncInvite(be, do, userCLI, syncLinkOutWithEndpoint, aMap)
        acceptInvitation(be, do, userCLI, aMap,
                         syncedInviteAcceptedOutWithoutClaims)
        # Send claim
        do('show claim request Job-Application')
        do('set first_name to Alice')
        do('set last_name to Garcia')
        do('set phone_number to 123-45-6789')
        do('show claim request Job-Application')
        # Passing some args as None since they are not used in the method
        jobApplicationProofSent(be, do, userCLI, aMap, None, None, None)

        # TODO: restart agents to test everything still works fine
        # faberAgent, acmeAgent, thriftAgent = restartAgents()

        do('show claim Job-Certificate')
        # Request new available claims Job-Certificate
        jobCertClaimRequested(be, do, userCLI, None, jobCertificateClaimMap,
                              reqClaimOut1, None)

        acmeSchemaId = ID(SchemaKey('Job-Certificate', '0.2', aMap['target']))
        acmeIssuerPublicKey = userCLI.looper.run(
            getPublicKey(acmeAgent.issuer.wallet, acmeSchemaId))
        userAcmeIssuerPublicKey = userCLI.looper.run(
            getPublicKey(userCLI.agent.prover.wallet, acmeSchemaId))
        assert acmeIssuerPublicKey == userAcmeIssuerPublicKey

        do('show claim Job-Certificate')
        assert userCLI.looper.run(getClaim(acmeSchemaId))

        # Accept thrift
        do('load sample/thrift-loan-application.sovrin')
        acceptInvitation(be, do, userCLI, tMap,
                         syncedInviteAcceptedOutWithoutClaims)

        # TODO: restart agents to test everything still works fine
        # faberAgent, acmeAgent, thriftAgent = restartAgents()

        # Send proofs
        bankBasicProofSent(be, do, userCLI, tMap, None)

        thriftAcmeIssuerPublicKey = userCLI.looper.run(
            getPublicKey(thriftAgent.issuer.wallet, acmeSchemaId))
        assert acmeIssuerPublicKey == thriftAcmeIssuerPublicKey
        passed = False
        try:
            bankKYCProofSent(be, do, userCLI, tMap, None)
            passed = True
        except:
            thriftFaberIssuerPublicKey = userCLI.looper.run(
                getPublicKey(thriftAgent.issuer.wallet, faberSchemaId))
            assert faberIssuerPublicKey == thriftFaberIssuerPublicKey
        assert passed

    executeGstFlow("Alice", aliceCLI, aliceMap, be, connectedToTest, do, fMap,
                   aMap, jobCertificateClaimMap, newKeyringOut, reqClaimOut,
                   reqClaimOut1, syncLinkOutWithEndpoint,
                   syncedInviteAcceptedOutWithoutClaims, tMap,
                   transcriptClaimMap)

    # TODO: restart agents to test everything still works fine
    # faberAgent, acmeAgent, thriftAgent = restartAgents()

    executeGstFlow("Susan", susanCLI, susanMap, be, connectedToTest, do, fMap,
                   aMap, jobCertificateClaimMap, newKeyringOut, reqClaimOut,
                   reqClaimOut1, syncLinkOutWithEndpoint,
                   syncedInviteAcceptedOutWithoutClaims, tMap,
                   transcriptClaimMap)