Skip to content

Commit

Permalink
Couple wrapper integration test fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Kovar <miroslavkovar@protonmail.com>
  • Loading branch information
mirgee committed Jul 2, 2021
1 parent 838d8e6 commit 12af876
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion agents/node/vcxagent-core/demo/alice.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async function runAlice (options) {

function _validateMsgs (msgs) {
logger.debug(`Validating messages:\n${JSON.stringify(msgs, null, 2)}`)
assert(msgs.length === 5)
assert(msgs.length === 4)
assert(msgs[0].uid)
assert(msgs[0].statusCode)
assert(msgs[0].decryptedMsg)
Expand Down
6 changes: 3 additions & 3 deletions agents/node/vcxagent-core/demo/faber.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ async function runFaber (options) {
let proofProtocolState = await vcxProof.updateStateV2(connectionToAlice)
logger.debug(`vcxProof = ${JSON.stringify(vcxProof)}`)
logger.debug(`proofState = ${proofProtocolState}`)
while (proofProtocolState !== StateType.Accepted) { // even if revoked credential was used, state should in final state be StateType.Accepted
while (![2, 3].includes(proofProtocolState)) { // even if revoked credential was used, state should in final state be StateType.Accepted
await sleepPromise(2000)
proofProtocolState = await vcxProof.updateStateV2(connectionToAlice)
logger.info(`proofState=${proofProtocolState}`)
if (proofProtocolState === StateType.None) {
logger.error(`Faber proof protocol state is ${StateType.None} which an error has ocurred.`)
if (proofProtocolState === 3) {
logger.error(`Faber proof protocol state is ${3} which an error has ocurred.`)
logger.error(`Serialized proof state = ${JSON.stringify(await vcxProof.serialize())}`)
process.exit(-1)
}
Expand Down
4 changes: 3 additions & 1 deletion agents/node/vcxagent-core/src/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async function createVcxAgent ({ agentName, genesisPath, agencyUrl, seed, usePos
await storageService.saveAgentProvision(agentProvision)
}
const agentProvision = await storageService.loadAgentProvision()
const issuerDid = agentProvision.issuerConfig["institution_did"]

async function agentInitVcx () {
logger.info(`Initializing ${agentName} vcx session.`)
Expand Down Expand Up @@ -93,7 +94,8 @@ async function createVcxAgent ({ agentName, genesisPath, agencyUrl, seed, usePos
loadCredDef: storageService.loadCredentialDefinition,
saveIssuerCredential: storageService.saveCredIssuer,
loadIssuerCredential: storageService.loadCredIssuer,
listIssuerCredentialIds: storageService.listCredIssuerKeys
listIssuerCredentialIds: storageService.listCredIssuerKeys,
issuerDid
})
const serviceCredHolder = createServiceCredHolder({
logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports.createServiceConnections = function createServiceConnections ({ l

async function _progressConnectionToAcceptedState (connection, attemptsThreshold, timeoutMs) {
async function progressToAcceptedState () {
if (await connection.updateState() !== StateType.Accepted) {
if (await connection.updateState() !== 4) {
return { result: undefined, isFinished: false }
} else {
return { result: null, isFinished: true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports.createServiceCredHolder = function createServiceCredHolder ({ log
async function _getOffers (connection, filter, attemptsThreshold, timeoutMs) {
async function findSomeCredOffer () {
let offers = await Credential.getOffers(connection)
logger.info(`Offers: ${offers}`)
if (filter && filter.schemaIdRegex) {
offers = filterOffersBySchema(offers, filter.schemaIdRegex)
}
Expand Down Expand Up @@ -49,7 +50,7 @@ module.exports.createServiceCredHolder = function createServiceCredHolder ({ log
async function waitForCredential (connectionId, holderCredentialId, attemptsThreshold = 10, timeoutMs = 2000) {
const connection = await loadConnection(connectionId)
const credential = await loadHolderCredential(holderCredentialId)
await _progressCredentialToState(credential, connection, StateType.Accepted, attemptsThreshold, timeoutMs)
await _progressCredentialToState(credential, connection, 2, attemptsThreshold, timeoutMs)
logger.info('Credential has been received.')
await saveHolderCredential(holderCredentialId, credential)
return getCredentialData(holderCredentialId)
Expand Down
9 changes: 5 additions & 4 deletions agents/node/vcxagent-core/src/services/service-cred-issuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {
} = require('@hyperledger/node-vcx-wrapper')
const { pollFunction } = require('../common')

module.exports.createServiceCredIssuer = function createServiceCredIssuer ({ logger, loadConnection, loadCredDef, saveIssuerCredential, loadIssuerCredential, listIssuerCredentialIds }) {
module.exports.createServiceCredIssuer = function createServiceCredIssuer ({ logger, loadConnection, loadCredDef, saveIssuerCredential, loadIssuerCredential, listIssuerCredentialIds, issuerDid }) {
async function sendOffer (issuerCredId, connectionId, credDefId, schemaAttrs) {
const connection = await loadConnection(connectionId)
const credDef = await loadCredDef(credDefId)
Expand All @@ -14,7 +14,8 @@ module.exports.createServiceCredIssuer = function createServiceCredIssuer ({ log
sourceId: 'alice_degree',
credDefHandle: credDef.handle,
credentialName: 'cred',
price: '0'
price: '0',
issuerDid
})
logger.info(`Per issuer credential ${issuerCredId}, sending cred offer to connection ${connectionId}`)
await issuerCred.sendOffer(connection)
Expand All @@ -36,7 +37,7 @@ module.exports.createServiceCredIssuer = function createServiceCredIssuer ({ log
const issuerCred = await loadIssuerCredential(issuerCredId)
const connection = await loadConnection(connectionId)
logger.debug('Going to wait until credential request is received.')
await _progressIssuerCredentialToState(issuerCred, connection, StateType.RequestReceived, 10, 2000)
await _progressIssuerCredentialToState(issuerCred, connection, 2, 10, 2000)
await saveIssuerCredential(issuerCredId, issuerCred)
}

Expand All @@ -45,7 +46,7 @@ module.exports.createServiceCredIssuer = function createServiceCredIssuer ({ log
const connection = await loadConnection(connectionId)
const issuerCred = await loadIssuerCredential(issuerCredId)
logger.info('Going to wait until counterparty accepts the credential.')
await _progressIssuerCredentialToState(issuerCred, connection, StateType.Accepted, 10, 2000)
await _progressIssuerCredentialToState(issuerCred, connection, 4, 10, 2000)
await saveIssuerCredential(issuerCredId, issuerCred)
}

Expand Down
4 changes: 2 additions & 2 deletions agents/node/vcxagent-core/src/services/service-prover.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports.createServiceProver = function createServiceProver ({ logger, loa
}
}

const [error, proofRequests] = await pollFunction(findSomeRequests, 'Get credential offer', logger, attemptsThreshold, timeoutMs)
const [error, proofRequests] = await pollFunction(findSomeRequests, 'Get proof request', logger, attemptsThreshold, timeoutMs)
if (error) {
throw Error(`Couldn't find any proof request. ${error}`)
}
Expand Down Expand Up @@ -84,7 +84,7 @@ module.exports.createServiceProver = function createServiceProver ({ logger, loa
await sendDisclosedProof(disclosedProofId, connectionId)
const disclosedProof = await loadDisclosedProof(disclosedProofId)
const connection = await loadConnection(connectionId)
await _progressProofToState(disclosedProof, connection, [StateType.Accepted, StateType.None])
await _progressProofToState(disclosedProof, connection, [2, 3])
const state = await disclosedProof.getState()
await saveDisclosedProof(disclosedProofId, disclosedProof)
return state
Expand Down
3 changes: 2 additions & 1 deletion agents/node/vcxagent-core/src/utils/vcx-workflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ async function provisionAgentInAgency (agentName, genesisPath, agencyUrl, seed,
logger.debug(`Configuring issuer's wallet with seed: ${seed}`)
const issuerConfig = JSON.parse(await configureIssuerWallet(seed))
issuerConfig.institution_name = agentName
logger.debug(`Configured issuer wallet with config: ${JSON.stringify(issuerConfig, null, 2)}`)
logger.debug(`Provisioning agent with config: ${JSON.stringify(agencyConfig, null, 2)}`)
agencyConfig = JSON.parse(await provisionCloudAgent(agencyConfig))
logger.debug(`Provisined agent with config: ${JSON.stringify(agencyConfig, null, 2)}`)
logger.debug(`Provisioned agent with config: ${JSON.stringify(agencyConfig, null, 2)}`)
await closeMainWallet()

return { agencyConfig, issuerConfig, walletConfig }
Expand Down

0 comments on commit 12af876

Please sign in to comment.