Skip to content

Commit

Permalink
Refactor/remove mocks (#1005)
Browse files Browse the repository at this point in the history
* Removed mocks from aries_vcx_core

* Removed global issuer DID in libvcx_core

* Removed mocks from aries_vcx

* Added usage of issuerDid in node agent functions

* Fixed seed and restored test in node JS wrapper

---------

Signed-off-by: Bogdan Mircea <mirceapetrebogdan@gmail.com>
  • Loading branch information
bobozaur authored Oct 4, 2023
1 parent ff6a060 commit 59938d7
Show file tree
Hide file tree
Showing 117 changed files with 1,071 additions and 2,924 deletions.
23 changes: 2 additions & 21 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -438,25 +438,6 @@ jobs:
run: |
RUST_TEST_THREADS=1 cargo test -p did_doc -p did_parser -p did_resolver -p did_resolver_registry -p did_resolver_sov -p did_resolver_web -p did_doc_sov -p did_key -p did_peer --test "*"
test-node-wrapper:
needs: workflow-setup
if: ${{ needs.workflow-setup.outputs.SKIP_CI != 'true' }}
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [18.x]
steps:
- name: "Git checkout"
uses: actions/checkout@v3
- name: "Setup NodeJS libvcx testing environment"
uses: ./.github/actions/setup-testing-nodejs
with:
rust-toolchain-version: ${{ env.RUST_TOOLCHAIN_VERSON }}
skip-docker-setup: true
node-version: ${{ matrix.node-version }}
- name: "Run tests"
run: cd wrappers/node && npm run test

test-integration-node-wrapper:
needs: workflow-setup
if: ${{ needs.workflow-setup.outputs.SKIP_CI != 'true' }}
Expand Down Expand Up @@ -613,7 +594,7 @@ jobs:
- test-integration-libvcx
- test-integration-aries-vcx
- test-integration-aries-vcx-mysql
- test-node-wrapper
# - test-node-wrapper
- test-integration-node-wrapper
- workflow-setup
- build-napi
Expand All @@ -637,7 +618,7 @@ jobs:
- test-integration-libvcx
- test-integration-aries-vcx
- test-integration-aries-vcx-mysql
- test-node-wrapper
# - test-node-wrapper
- test-integration-node-wrapper
if: ${{ needs.workflow-setup.outputs.RELEASE == 'true' || needs.workflow-setup.outputs.PRERELEASE == 'true' }}
outputs:
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions agents/node/vcxagent-core/demo/faber.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const mkdirp = require('mkdirp')

const tailsDir = '/tmp/tails'

async function runFaber (options) {
async function runFaber(options) {
logger.info(`Starting Faber. Revocation enabled=${options.revocation}`)
mkdirp.sync(tailsDir)
initRustLogger(process.env.RUST_LOG || 'vcx=error')
Expand Down Expand Up @@ -49,10 +49,10 @@ async function runFaber (options) {
await vcxAgent.acceptTaa()
}

const schemaId = await vcxAgent.serviceLedgerSchema.createSchema(getSampleSchemaData())
await sleep(500)
const vcxCredDef = await vcxAgent.serviceLedgerCredDef.createCredentialDefinitionV2(schemaId, getFaberCredDefName(), true, 'tag1')
const issuerDid = vcxAgent.getInstitutionDid()
const schemaId = await vcxAgent.serviceLedgerSchema.createSchema(getSampleSchemaData(), issuerDid)
await sleep(500)
const vcxCredDef = await vcxAgent.serviceLedgerCredDef.createCredentialDefinitionV2(issuerDid, schemaId, getFaberCredDefName(), true, 'tag1')
const { revReg, revRegId } = await vcxAgent.serviceLedgerRevReg.createRevocationRegistry(issuerDid, await vcxCredDef.getCredDefId(), 1, tailsDir, 5, testTailsUrl)

await vcxAgent.serviceConnections.inviterConnectionCreateAndAccept(connectionId, (invitationString) => {
Expand Down Expand Up @@ -89,7 +89,7 @@ async function runFaber (options) {
logger.info('Faber is revoking issued credential')
await vcxAgent.serviceCredIssuer.revokeCredentialLocal(issuerCredId)
logger.info('Faber is publishing revocation')
await revReg.publishRevocations()
await revReg.publishRevocations(issuerDid)
}

logger.info('#19 Create a Proof object')
Expand Down Expand Up @@ -195,7 +195,7 @@ const usage = [
}
]

function areOptionsValid (_options) {
function areOptionsValid(_options) {
return true
}

Expand Down
15 changes: 6 additions & 9 deletions agents/node/vcxagent-core/src/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const { createServiceLedgerRevocationRegistry } = require('./services/service-re
const { provisionAgentInAgency } = require('./utils/vcx-workflows')
const {
createAgencyClientForMainWallet,
initIssuerConfig,
openMainWallet,
openMainPool,
vcxUpdateWebhookUrl,
Expand All @@ -25,7 +24,7 @@ const { createStorageService } = require('./storage/storage-service')
const { waitUntilAgencyIsReady, getAgencyConfig } = require('./common')
const path = require('path')

async function createVcxAgent ({ agentName, genesisPath, agencyUrl, seed, walletExtraConfigs, endpointInfo, logger }) {
async function createVcxAgent({ agentName, genesisPath, agencyUrl, seed, walletExtraConfigs, endpointInfo, logger }) {
genesisPath = genesisPath || path.join(__dirname, '/../resources/docker.txn')

await waitUntilAgencyIsReady(agencyUrl, logger)
Expand All @@ -39,12 +38,10 @@ async function createVcxAgent ({ agentName, genesisPath, agencyUrl, seed, wallet
const agentProvision = await storageService.loadAgentProvision()
const issuerDid = agentProvision.issuerConfig.institution_did

async function agentInitVcx () {
async function agentInitVcx() {
logger.info(`Initializing ${agentName} vcx session.`)

logger.silly(`Using following agent provision to initialize VCX settings ${JSON.stringify(agentProvision, null, 2)}`)
logger.silly('Initializing issuer config')
await initIssuerConfig(agentProvision.issuerConfig)
logger.silly('Opening main wallet')
await openMainWallet(agentProvision.walletConfig)
logger.silly('Creating cloud agency config')
Expand All @@ -53,25 +50,25 @@ async function createVcxAgent ({ agentName, genesisPath, agencyUrl, seed, wallet
await openMainPool({ genesis_path: genesisPath })
}

async function agentShutdownVcx () {
async function agentShutdownVcx() {
logger.debug(`Shutting down ${agentName} vcx session.`)
shutdownVcx()
}

async function updateWebhookUrl (webhookUrl) {
async function updateWebhookUrl(webhookUrl) {
logger.info(`Updating webhook url to ${webhookUrl}`)
await vcxUpdateWebhookUrl({ webhookUrl })
}

async function acceptTaa () {
async function acceptTaa() {
const taa = await getLedgerAuthorAgreement()
const taaJson = JSON.parse(taa)
const acceptanceMechanism = Object.keys(taaJson.aml)[0]
logger.info(`Accepting TAA using mechanism ${acceptanceMechanism}`)
await setActiveTxnAuthorAgreementMeta(taaJson.text, taaJson.version, acceptanceMechanism)
}

function getInstitutionDid () {
function getInstitutionDid() {
return issuerDid
}

Expand Down
11 changes: 6 additions & 5 deletions agents/node/vcxagent-core/src/services/service-ledger-creddef.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const { CredentialDef } = require('@hyperledger/node-vcx-wrapper')

module.exports.createServiceLedgerCredDef = function createServiceLedgerCredDef ({ logger, saveCredDef, loadCredDef, listCredDefIds }) {
async function createCredentialDefinitionV2 (schemaId, credDefId, supportRevocation, tag = 'tag1') {
module.exports.createServiceLedgerCredDef = function createServiceLedgerCredDef({ logger, saveCredDef, loadCredDef, listCredDefIds }) {
async function createCredentialDefinitionV2(issuerDid, schemaId, credDefId, supportRevocation, tag = 'tag1') {
const data = {
issuerDid,
supportRevocation,
schemaId,
sourceId: credDefId,
Expand All @@ -16,19 +17,19 @@ module.exports.createServiceLedgerCredDef = function createServiceLedgerCredDef
return credDef
}

async function listIds () {
async function listIds() {
return listCredDefIds()
}

async function printInfo (credDefIds) {
async function printInfo(credDefIds) {
for (const id of credDefIds) {
const credDef = await loadCredDef(id)
const serCredDef = credDef.serialize()
logger.info(`Credential definition ${id}: ${JSON.stringify(serCredDef)}`)
}
}

async function getCredDefId (credDefId) {
async function getCredDefId(credDefId) {
const credDef = await loadCredDef(credDefId)
logger.info(`Getting credDefId for credential definition ${credDefId}`)
return credDef.getCredDefId()
Expand Down
10 changes: 5 additions & 5 deletions agents/node/vcxagent-core/src/services/service-ledger-schema.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const { Schema } = require('@hyperledger/node-vcx-wrapper')

module.exports.createServiceLedgerSchema = function createServiceLedgerSchema ({ logger, saveSchema, loadSchema, listSchemaIds }) {
async function createSchema (schemaData) {
module.exports.createServiceLedgerSchema = function createServiceLedgerSchema({ logger, saveSchema, loadSchema, listSchemaIds }) {
async function createSchema(schemaData, issuerDid) {
logger.info(`Creating a new schema on the ledger: ${JSON.stringify(schemaData, null, 2)}`)

const schema = await Schema.create(schemaData)
const schema = await Schema.create(schemaData, issuerDid)
const schemaId = await schema.getSchemaId()
await saveSchema(schemaId, schema)
return schemaId
}

async function listIds () {
async function listIds() {
return listSchemaIds()
}

async function printInfo (schemaIds) {
async function printInfo(schemaIds) {
for (const id of schemaIds) {
const serSchema = await loadSchema(id)
logger.info(`Schema ${id}: ${JSON.stringify(serSchema)}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ module.exports.createServiceLedgerRevocationRegistry = function createServiceLed
return { revReg: newRevReg, revRegId: newRevRegId }
}

async function publishRevocations (revRegId) {
async function publishRevocations (revRegId, submittderDid) {
logger.info(`Publishing revocations for revocation registry ${revRegId}`)
const revReg = await loadRevReg(revRegId)
await revReg.publishRevocations()
await revReg.publishRevocations(submittderDid)
}

async function getTailsFile (credDefId) {
Expand Down
Loading

0 comments on commit 59938d7

Please sign in to comment.