Skip to content

Commit

Permalink
switch testing to run after tsc compile
Browse files Browse the repository at this point in the history
  • Loading branch information
jchartrand committed Jan 12, 2025
1 parent 1ca9abf commit 9b3777e
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 63 deletions.
17 changes: 7 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "0.0.1",
"scripts": {
"build": "npm run clear && tsc -d && tsc -p tsconfig.esm.json",
"build-test": "npm run clear && tsc -p tsconfig.spec.json",
"clear": "rimraf dist/*",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
Expand All @@ -12,7 +13,8 @@
"rebuild": "npm run clear && npm run build",
"test": "npm run lint && npm run test-node",
"test-karma": "karma start karma.conf.js",
"test-node": "cross-env NODE_ENV=test TS_NODE_PROJECT=tsconfig.spec.json TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register --project tsconfig.spec.json 'test/*.ts'"
"test-node-old": "cross-env NODE_ENV=test TS_NODE_PROJECT=tsconfig.spec.json TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register --project tsconfig.spec.json 'test/*.ts'",
"test-node": "npm run build-test && mocha dist/esm/test/*.spec.js && rm -rf dist/esm/test || true"
},
"files": [
"dist",
Expand Down Expand Up @@ -61,23 +63,17 @@
"prettier": "^2.8.1",
"rimraf": "^3.0.2",
"ts-node": "^10.9.1",
"tsx": "^4.19.2",
"typescript": "^4.9.4"
},
"publishConfig": {
"access": "public"
},
"mocha": {
"require": "ts-node/register",
"extension": [
"ts"
],
"spec": "test/**/*.ts"
},
"keywords": [
"dcc"
],
"engines": {
"node": ">=16.0"
"node": ">=18.0"
},
"author": {
"name": "Digital Credentials Consortium",
Expand All @@ -89,5 +85,6 @@
"url": "/~https://github.com/digitalcredentials/isomorphic-lib-template"
},
"homepage": "/~https://github.com/digitalcredentials/isomorphic-lib-template",
"bugs": "/~https://github.com/digitalcredentials/isomorphic-lib-template/issues"
"bugs": "/~https://github.com/digitalcredentials/isomorphic-lib-template/issues",
"type": "module"
}
14 changes: 7 additions & 7 deletions src/Verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
import { Ed25519Signature2020 } from '@digitalcredentials/ed25519-signature-2020';
import * as vc from '@digitalcredentials/vc';
import { securityLoader } from '@digitalcredentials/security-document-loader';
import { getCredentialStatusChecker } from './credentialStatus';
import { addTrustedIssuersToVerificationResponse } from './issuerRegistries';
import { getCredentialStatusChecker } from './credentialStatus.js';
import { addTrustedIssuersToVerificationResponse } from './issuerRegistries.js';

import { Credential } from './types/credential.js';
import { VerificationResponse } from './types/result.js';

import { Credential } from './types/credential';
import { VerificationResponse } from './types/result';

/*
// the new eddsa-rdfc-2022-cryptosuite
import {DataIntegrityProof} from '@digitalbazaar/data-integrity';
import {cryptosuite as eddsaRdfc2022CryptoSuite} from '@digitalbazaar/eddsa-rdfc-2022-cryptosuite';
const suite = new DataIntegrityProof({
const eddsaSuite = new DataIntegrityProof({
cryptosuite: eddsaRdfc2022CryptoSuite
});
*/


const documentLoader = securityLoader({ fetchRemoteContexts: true }).build();
const suite = new Ed25519Signature2020();
Expand Down
2 changes: 1 addition & 1 deletion src/issuerRegistries.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {RegistryClient} from '@digitalcredentials/issuer-registry-client';

Check failure on line 1 in src/issuerRegistries.ts

View workflow job for this annotation

GitHub Actions / test-karma (18.x)

Cannot find module './types/result.js' or its corresponding type declarations.

Check failure on line 1 in src/issuerRegistries.ts

View workflow job for this annotation

GitHub Actions / test-node (18.x)

Cannot find module './types/result.js' or its corresponding type declarations.

Check failure on line 1 in src/issuerRegistries.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

Cannot find module './types/result.js' or its corresponding type declarations.
import { VerificationResponse } from './types/result';
import { VerificationResponse } from './types/result.js';
const registries = new RegistryClient()
const registryNotYetLoaded = true;
/**
Expand Down
22 changes: 12 additions & 10 deletions src/test-fixtures/vc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { v2Expired } from "./verifiableCredentials/v2/v2Expired"
import { v2Revoked } from "./verifiableCredentials/v2/v2Revoked"
import { v2WithValidStatus } from "./verifiableCredentials/v2/v2WithValidStatus"
import { v2ExpiredWithValidStatus } from "./verifiableCredentials/v2/v2ExpiredWithValidStatus"
import { v2NoStatus } from "./verifiableCredentials/v2/v2NoStatus.js"
import { v2Expired } from "./verifiableCredentials/v2/v2Expired.js"
import { v2Revoked } from "./verifiableCredentials/v2/v2Revoked.js"
import { v2WithValidStatus } from "./verifiableCredentials/v2/v2WithValidStatus.js"
import { v2ExpiredWithValidStatus } from "./verifiableCredentials/v2/v2ExpiredWithValidStatus.js"

import { v1WithValidStatus } from "./verifiableCredentials/v1/v1WithValidStatus"
import { v1NoStatus } from "./verifiableCredentials/v1/v1NoStatus"
import { v2NoStatus } from "./verifiableCredentials/v2/v2NoStatus"
import { v1WithValidStatus } from "./verifiableCredentials/v1/v1WithValidStatus.js"
import { v1NoStatus } from "./verifiableCredentials/v1/v1NoStatus.js"
import { v1Expired } from "./verifiableCredentials/v1/v1Expired.js"

const getVCv1 = (): any => {
return JSON.parse(JSON.stringify(v1NoStatus))
Expand Down Expand Up @@ -39,8 +40,8 @@ const getVCv1Tampered = (): any => {
return signedVC1
}

const getExpiredVC1 = (): any => {
return null
const getVCv1Expired = (): any => {
return JSON.parse(JSON.stringify(v1Expired))
}
const getVCv2Expired = (): any => {
return JSON.parse(JSON.stringify(v2Expired))
Expand All @@ -64,13 +65,14 @@ export {
getVCv2Expired,
getVCv2Revoked,
getVCv2Tampered,
getVCv2ValidStatus,
getVCv2ExpiredAndTampered,
getVCv2NoProof,
getVCv2,

getVCv1Expired,
getVCv1Tampered,
getVCv1ValidStatus,
getVCv2ValidStatus,
getVCv1,
getVCv1NoProof
}
82 changes: 50 additions & 32 deletions test/Verify.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import chai from 'chai'
import deepEqualInAnyOrder from 'deep-equal-in-any-order'
import { strict as assert } from 'assert';
import { verifyCredential } from '../src/Verify'
import { getVCv2Expired, getVCv1Tampered, getVCv2ValidStatus, getVCv2Tampered } from '../src/test-fixtures/vc'
import { knownDIDRegistries } from '../.knownDidRegistries';
import { verifyCredential } from '../src/Verify.js'
import { getVCv2Expired, getVCv1Tampered, getVCv1Expired, getVCv1ValidStatus, getVCv2ValidStatus, getVCv2Tampered } from '../src/test-fixtures/vc.js'
import { knownDIDRegistries } from '../.knownDidRegistries.js';

chai.use(deepEqualInAnyOrder);
const {expect} = chai;
Expand Down Expand Up @@ -41,49 +41,67 @@ const expectedResult = {

describe('Verify', () => {
describe('.verifyCredential', () => {

describe('with VC version 1', () => {

describe('returns fatal error', () => {
it('when tampered with', async () => {
const tamperedVC1 : any = getVCv1Tampered()
const result = await verifyCredential({credential: tamperedVC1, reloadIssuerRegistry: true, knownDIDRegistries})
assert.ok(result.verified === false);
})

it('when tampered with', async () => {
const tamperedVC1 : any = getVCv1Tampered()
const result = await verifyCredential({credential: tamperedVC1, reloadIssuerRegistry: true, knownDIDRegistries})
assert.ok(result.verified === false);
})

})

describe('returns as verified', () => {
it('when status is valid', async () => {
const credential : any = getVCv1ValidStatus()
expectedResult.credential = credential;
const result = await verifyCredential({credential, reloadIssuerRegistry: true, knownDIDRegistries})
expect(result).to.deep.equalInAnyOrder(expectedResult) // eslint-disable-line no-use-before-define
})
})

describe('returns as unverified', () => {
it('when expired', async () => {
const credential : any = getVCv1Expired()
const result = await verifyCredential({credential, reloadIssuerRegistry: true, knownDIDRegistries})
assert.ok(result.verified === false);
assert.ok(result.log);
})
})


})

describe('with VC version 2', () => {

describe('returns fatal error', () => {
it('when tampered with', async () => {
const tamperedVC2 : any = getVCv2Tampered()
const result = await verifyCredential({credential: tamperedVC2, reloadIssuerRegistry: true, knownDIDRegistries})
// console.log("result returned from verifyCredential call:")
// console.log(JSON.stringify(result,null,2))
assert.ok(result.verified === false);
//expect(result.verified).to.be.true
})
})

})

it('verifies with valid status', async () => {
const credential : any = getVCv2ValidStatus()
expectedResult.credential = credential;
const result = await verifyCredential({credential, reloadIssuerRegistry: true, knownDIDRegistries})
//console.log("result returned from verifyCredential call:")
//console.log(JSON.stringify(result,null,2))
expect(result.verified).to.be.true
expect(result.credential).to.eql(credential)
expect(result).to.deep.equalInAnyOrder(expectedResult) // eslint-disable-line no-use-before-define
})
describe('returns as verified', () => {
it('when status is valid', async () => {
const credential : any = getVCv2ValidStatus()
expectedResult.credential = credential;
const result = await verifyCredential({credential, reloadIssuerRegistry: true, knownDIDRegistries})
expect(result).to.deep.equalInAnyOrder(expectedResult) // eslint-disable-line no-use-before-define
})
})

it('returns unverified when expired', async () => {
const expiredVC2 : any = getVCv2Expired()
const result = await verifyCredential({credential: expiredVC2, reloadIssuerRegistry: true, knownDIDRegistries})
//console.log("result returned from verifyCredential call:")
// console.log(JSON.stringify(result,null,2))
assert.ok(result.verified === false);
assert.ok(result.log);
//expect(result.verified).to.be.true
})
describe('returns as unverified', () => {
it('when expired', async () => {
const credential : any = getVCv2Expired()
const result = await verifyCredential({credential, reloadIssuerRegistry: true, knownDIDRegistries})
assert.ok(result.verified === false);
assert.ok(result.log);
})
})
})
})
})
6 changes: 3 additions & 3 deletions tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
"strict": true,
"target": "es2022",
"lib": ["es2022", "dom"],
"module": "commonjs",
"module": "es2022",
"moduleResolution": "node",
"esModuleInterop": true,
"outDir": "dist/esm",
"noImplicitAny": true,
"removeComments": false,
Expand All @@ -20,8 +19,9 @@
},
"include": [
"src/**/*",
"test/**/*",
".eslintrc.js",
"karma.conf.js"
],
"exclude": ["node_modules", "dist", "test"]
"exclude": ["node_modules", "dist"]
}

0 comments on commit 9b3777e

Please sign in to comment.