From 523a625bfe928375ec86fb9f0288d108d6d6ac8c Mon Sep 17 00:00:00 2001 From: Curtish Date: Tue, 22 Apr 2025 16:25:53 +0100 Subject: [PATCH] test: remove chai and sinon Signed-off-by: Curtish --- package.json | 8 - src/mercury/Mercury.ts | 8 +- tests/agent/Agent.test.ts | 116 +++++------ tests/agent/didcomm/invitation.test.ts | 15 +- tests/apollo/Apollo.test.ts | 24 +-- tests/castor/PrismDID.test.ts | 184 ++++++++--------- tests/mercury/Mercury.test.ts | 190 +++++------------- tests/mercury/didcomm/SecretsResolver.test.ts | 181 +++++------------ .../anoncreds/PresentationRequest.test.ts | 6 +- tests/plugins/dif/IsCredentialRevoked.test.ts | 7 +- .../oea/sdjwt/PresentationRequest.test.ts | 4 +- tests/pluto/Pluto.Backup.test.ts | 97 +++++---- tests/pollux/Pollux.revocation.test.ts | 39 ++-- 13 files changed, 322 insertions(+), 557 deletions(-) diff --git a/package.json b/package.json index baba11960..999661009 100644 --- a/package.json +++ b/package.json @@ -74,21 +74,15 @@ "@semantic-release/exec": "^6.0.3", "@semantic-release/git": "^10.0.1", "@semantic-release/release-notes-generator": "^10.0.3", - "@types/chai": "^4.3.4", - "@types/chai-as-promised": "^7.1.5", "@types/google-protobuf": "^3.15.6", "@types/jsonld": "^1.5.14", "@types/node": "^18.14.2", "@types/pako": "^2.0.3", - "@types/sinon": "^17.0.3", - "@types/sinon-chai": "^3.2.12", "@typescript-eslint/eslint-plugin": "^5.56.0", "@typescript-eslint/parser": "^5.55.0", "@vitest/browser": "^1.6.0", "@vitest/coverage-istanbul": "^1.6.0", "anoncreds-wasm": "./externals/generated/anoncreds-wasm", - "chai": "^4.3.7", - "chai-as-promised": "^7.1.1", "didcomm-wasm": "./externals/generated/didcomm-wasm", "eslint": "^8.36.0", "eslint-plugin-react": "^7.32.2", @@ -99,8 +93,6 @@ "protoc-gen-ts": "^0.8.7", "rxdb": "^14.17.1", "semantic-release": "^24.0.0", - "sinon": "^18.0.0", - "sinon-chai": "^3.7.0", "tsup": "^8.4.0", "typedoc": "^0.25.2", "typedoc-plugin-external-module-map": "^1.3.2", diff --git a/src/mercury/Mercury.ts b/src/mercury/Mercury.ts index 15dd75727..85920dfd1 100644 --- a/src/mercury/Mercury.ts +++ b/src/mercury/Mercury.ts @@ -30,7 +30,7 @@ export default class Mercury implements MercuryInterface { public castor: Castor, public protocol: DIDCommProtocol, public api: Api - ) { } + ) {} /** * Asynchronously packs a given message object into a string representation. This function may throw an error if the @@ -39,7 +39,7 @@ export default class Mercury implements MercuryInterface { * @param {Domain.Message} message * @returns {Promise} */ - packMessage(message: Domain.Message): Promise { + async packMessage(message: Domain.Message): Promise { const toDid = message.to; const fromDid = message.from; @@ -135,7 +135,7 @@ export default class Mercury implements MercuryInterface { const responseJSON = JSON.stringify(responseBody); return await this.unpackMessage(responseJSON); } catch (err) { - return undefined + return undefined; } } @@ -152,7 +152,7 @@ export default class Mercury implements MercuryInterface { if (typeof did.toString !== "function") { return true; } - return false + return false; } private prepareForwardMessage( diff --git a/tests/agent/Agent.test.ts b/tests/agent/Agent.test.ts index a75087e3d..a66b15169 100644 --- a/tests/agent/Agent.test.ts +++ b/tests/agent/Agent.test.ts @@ -1,8 +1,4 @@ import { vi, describe, it, expect, test, beforeEach, afterEach, MockInstance } from 'vitest'; -import chai from "chai"; -import chaiAsPromised from "chai-as-promised"; -import * as sinon from "sinon"; -import SinonChai from "sinon-chai"; import * as UUIDLib from "@stablelib/uuid"; import Agent from "../../src/edge-agent/Agent"; @@ -50,28 +46,19 @@ import { StartFetchingMessages } from '../../src/edge-agent/didcomm/StartFetchin import { mockTask } from '../testFns'; import { MediatorConnection } from '../../src/edge-agent/connections/didcomm'; - - -chai.use(SinonChai); -chai.use(chaiAsPromised); - let agent: Agent; let apollo: Apollo; let pluto: IPluto; let castor: CastorType; -let sandbox: sinon.SinonSandbox; let store: Pluto.Store; let api: Api; describe("Agent Tests", () => { - let spy: MockInstance; - afterEach(async () => { vi.useRealTimers(); await agent.stop(); - sandbox.restore(); vi.restoreAllMocks(); }); @@ -84,7 +71,6 @@ describe("Agent Tests", () => { close: vi.fn(), })), })); - sandbox = sinon.createSandbox(); apollo = new Apollo(); castor = new Castor(apollo); api = { @@ -139,16 +125,15 @@ describe("Agent Tests", () => { await agent.start(); }); - it("As a developer when a peerDID is created and we have specified to updateKeyList the services are correctly added and updateKeyList is called correctly.", async () => { - const storePeerDID = sandbox.stub(pluto, "storeDID").resolves(); - const createPeerDID = sandbox.spy(castor, "createPeerDID"); - const stubSendMessage = sandbox.stub(agent.mercury, "sendMessage").resolves(); + const storePeerDID = vi.spyOn(pluto, "storeDID").mockResolvedValue(); + const createPeerDID = vi.spyOn(castor, "createPeerDID"); + const stubSendMessage = vi.spyOn(agent.mercury, "sendMessage").mockResolvedValue(Uint8Array.from([])); const peerDID = await agent.createNewPeerDID([], true); - expect(createPeerDID.callCount).to.be.equal(1); - expect(storePeerDID.callCount).to.be.equal(1); + expect(createPeerDID).toHaveBeenCalledOnce(); + expect(storePeerDID).toHaveBeenCalledOnce(); expect(agent.currentMediatorDID).not.equals(null); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion @@ -160,10 +145,9 @@ describe("Agent Tests", () => { new ServiceEndpoint(mediatorDID.toString()) ); - createPeerDID.calledWith([], [expectedService]); - - expect(stubSendMessage).to.have.been.calledOnce; - const msg = stubSendMessage.args.at(0)?.at(0); + expect(createPeerDID).toHaveBeenLastCalledWith(expect.arrayContaining([]), [expectedService]); + expect(stubSendMessage).toHaveBeenCalledOnce(); + const msg = stubSendMessage.mock.calls.at(0)?.at(0); expect(msg).to.be.instanceOf(Message); expect(msg?.body).to.deep.eq({ updates: [{ @@ -180,33 +164,31 @@ describe("Agent Tests", () => { const oob = "https://my.domain.com/path?_oob=eyJpZCI6Ijg5NWYzMWZhLTIyNWUtNDRlNi1hNzkyLWFhN2E0OGY1MjgzYiIsInR5cGUiOiJodHRwczovL2RpZGNvbW0ub3JnL291dC1vZi1iYW5kLzIuMC93cm9uZ1R5cGUiLCJmcm9tIjoiZGlkOnBlZXI6Mi5FejZMU2V6eWtjQmpNS2dHUEVEaDQ0cEM4UWZ1N2NDekpvc1Z1VjRqcDZ4NVk1QkhMLlZ6Nk1rd1JKdDFTbVpwM2FERGhMVW40ZkszM204TExaWFc5MlhUOHZyVUh1NHVwQTYuU2V5SjBJam9pWkcwaUxDSnpJam9pYUhSMGNITTZMeTlyT0hNdFpHVjJMbUYwWVd4aGNISnBjMjB1YVc4dmNISnBjMjB0WVdkbGJuUXZaR2xrWTI5dGJTSXNJbklpT2x0ZExDSmhJanBiSW1ScFpHTnZiVzB2ZGpJaVhYMCIsImJvZHkiOnsiZ29hbF9jb2RlIjoiaW8uYXRhbGFwcmlzbS5jb25uZWN0IiwiZ29hbCI6IkVzdGFibGlzaCBhIHRydXN0IGNvbm5lY3Rpb24gYmV0d2VlbiB0d28gcGVlcnMgdXNpbmcgdGhlIHByb3RvY29sICdodHRwczovL2F0YWxhcHJpc20uaW8vbWVyY3VyeS9jb25uZWN0aW9ucy8xLjAvd3JvbmcnIiwiYWNjZXB0IjpbXX19"; - expect( - agent.parseOOBInvitation(new URL(oob)) - ).to.eventually.be.rejectedWith(AgentError.UnknownInvitationTypeError); + await expect(agent.parseOOBInvitation(new URL(oob))).rejects.toThrowError(AgentError.UnknownInvitationTypeError); }); it("As a developer with a valid invitationMessage I will be sending a Handshake request with the correct information and store the didPair in pluto right after.", async () => { const did = DID.fromString("did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOnsidXJpIjoiaHR0cHM6Ly9tZWRpYXRvci5yb290c2lkLmNsb3VkIiwiYSI6WyJkaWRjb21tL3YyIl19fQ"); const validOOB = "https://my.domain.com/path?_oob=eyJpZCI6Ijg5NWYzMWZhLTIyNWUtNDRlNi1hNzkyLWFhN2E0OGY1MjgzYiIsInR5cGUiOiJodHRwczovL2RpZGNvbW0ub3JnL291dC1vZi1iYW5kLzIuMC9pbnZpdGF0aW9uIiwiZnJvbSI6ImRpZDpwZWVyOjIuRXo2TFNlenlrY0JqTUtnR1BFRGg0NHBDOFFmdTdjQ3pKb3NWdVY0anA2eDVZNUJITC5WejZNa3dSSnQxU21acDNhRERoTFVuNGZLMzNtOExMWlhXOTJYVDh2clVIdTR1cEE2LlNleUowSWpvaVpHMGlMQ0p6SWpvaWFIUjBjSE02THk5ck9ITXRaR1YyTG1GMFlXeGhjSEpwYzIwdWFXOHZjSEpwYzIwdFlXZGxiblF2Wkdsa1kyOXRiU0lzSW5JaU9sdGRMQ0poSWpwYkltUnBaR052YlcwdmRqSWlYWDAiLCJib2R5Ijp7ImdvYWxfY29kZSI6ImlvLmF0YWxhcHJpc20uY29ubmVjdCIsImdvYWwiOiJFc3RhYmxpc2ggYSB0cnVzdCBjb25uZWN0aW9uIGJldHdlZW4gdHdvIHBlZXJzIHVzaW5nIHRoZSBwcm90b2NvbCAnaHR0cHM6Ly9hdGFsYXByaXNtLmlvL21lcmN1cnkvY29ubmVjdGlvbnMvMS4wL3JlcXVlc3QnIiwiYWNjZXB0IjpbXX19"; - sandbox.stub(UUIDLib, "uuid").returns("123456-123456-12356-123456"); - const stubStoreDID = sandbox.stub(agent.pluto, "storeDID").resolves(); - const stubStoreDIDPair = sandbox.stub(agent.pluto, "storeDIDPair").resolves(); - const stubCreateDID = sandbox.stub(agent.castor, "createPeerDID").resolves(did); - const stubSendMessage = sandbox.stub(agent.mercury, "sendMessage").resolves(); + vi.spyOn(UUIDLib, "uuid").mockReturnValue("123456-123456-12356-123456"); + const stubStoreDID = vi.spyOn(agent.pluto, "storeDID").mockResolvedValue(); + const stubStoreDIDPair = vi.spyOn(agent.pluto, "storeDIDPair").mockResolvedValue(); + const stubCreateDID = vi.spyOn(agent.castor, "createPeerDID").mockResolvedValue(did); + const stubSendMessage = vi.spyOn(agent.mercury, "sendMessage").mockResolvedValue(Uint8Array.from([])); const oobInvitation = await agent.parseOOBInvitation(new URL(validOOB)); await agent.acceptInvitation(oobInvitation); - expect(stubStoreDID).to.have.been.calledOnce; - expect(stubStoreDIDPair).to.have.been.calledOnce; - expect(stubCreateDID).to.have.been.calledOnce; - expect(stubSendMessage).to.have.been.calledTwice; + expect(stubStoreDID).toHaveBeenCalledOnce(); + expect(stubStoreDIDPair).toHaveBeenCalledOnce(); + expect(stubCreateDID).toHaveBeenCalledOnce(); + expect(stubSendMessage).toHaveBeenCalledTimes(2); const expectedMsg = { ...HandshakeRequest.fromOutOfBand(oobInvitation, did).makeMessage(), direction: MessageDirection.SENT }; - expect(stubSendMessage.secondCall.args[0]).to.deep.eq(expectedMsg); + expect(stubSendMessage.mock.calls[1][0]).to.deep.eq(expectedMsg); }); it("As a developer with a valid invitationMessage I will be sending a presentation with the correct information, but will fail as it is expired.", async () => { @@ -216,18 +198,16 @@ describe("Agent Tests", () => { const validOOB = "https://my.domain.com/path?_oob=eyJpZCI6IjViMjUwMjIzLWExNDItNDRmYi1hOWJkLWU1MjBlNGI0ZjQzMiIsInR5cGUiOiJodHRwczovL2RpZGNvbW0ub3JnL291dC1vZi1iYW5kLzIuMC9pbnZpdGF0aW9uIiwiZnJvbSI6ImRpZDpwZWVyOjIuRXo2TFNkV0hWQ1BFOHc0NWZETjM4aUh0ZFJ6WGkyTFNqQmRSUjRGTmNOUm12VkNKcy5WejZNa2Z2aUI5S1F1OGlnNVZpeG1HZHM3dmdMNmoyUXNOUGFybkZaanBNQ0E5aHpQLlNleUowSWpvaVpHMGlMQ0p6SWpwN0luVnlhU0k2SW1oMGRIQTZMeTh4T1RJdU1UWTRMakV1TXpjNk9EQTNNQzlrYVdSamIyMXRJaXdpY2lJNlcxMHNJbUVpT2xzaVpHbGtZMjl0YlM5Mk1pSmRmWDAiLCJib2R5Ijp7ImdvYWxfY29kZSI6InByZXNlbnQtdnAiLCJnb2FsIjoiUmVxdWVzdCBwcm9vZiBvZiB2YWNjaW5hdGlvbiBpbmZvcm1hdGlvbiIsImFjY2VwdCI6W119LCJhdHRhY2htZW50cyI6W3siaWQiOiIyYTZmOGM4NS05ZGE3LTRkMjQtOGRhNS0wYzliZDY5ZTBiMDEiLCJtZWRpYV90eXBlIjoiYXBwbGljYXRpb24vanNvbiIsImRhdGEiOnsianNvbiI6eyJpZCI6IjI1NTI5MTBiLWI0NmMtNDM3Yy1hNDdhLTlmODQ5OWI5ZTg0ZiIsInR5cGUiOiJodHRwczovL2RpZGNvbW0uYXRhbGFwcmlzbS5pby9wcmVzZW50LXByb29mLzMuMC9yZXF1ZXN0LXByZXNlbnRhdGlvbiIsImJvZHkiOnsiZ29hbF9jb2RlIjoiUmVxdWVzdCBQcm9vZiBQcmVzZW50YXRpb24iLCJ3aWxsX2NvbmZpcm0iOmZhbHNlLCJwcm9vZl90eXBlcyI6W119LCJhdHRhY2htZW50cyI6W3siaWQiOiJiYWJiNTJmMS05NDUyLTQzOGYtYjk3MC0yZDJjOTFmZTAyNGYiLCJtZWRpYV90eXBlIjoiYXBwbGljYXRpb24vanNvbiIsImRhdGEiOnsianNvbiI6eyJvcHRpb25zIjp7ImNoYWxsZW5nZSI6IjExYzkxNDkzLTAxYjMtNGM0ZC1hYzM2LWIzMzZiYWI1YmRkZiIsImRvbWFpbiI6Imh0dHBzOi8vcHJpc20tdmVyaWZpZXIuY29tIn0sInByZXNlbnRhdGlvbl9kZWZpbml0aW9uIjp7ImlkIjoiMGNmMzQ2ZDItYWY1Ny00Y2E1LTg2Y2EtYTA1NTE1NjZlYzZmIiwiaW5wdXRfZGVzY3JpcHRvcnMiOltdfX19LCJmb3JtYXQiOiJwcmlzbS9qd3QifV0sInRoaWQiOiI1YjI1MDIyMy1hMTQyLTQ0ZmItYTliZC1lNTIwZTRiNGY0MzIiLCJmcm9tIjoiZGlkOnBlZXI6Mi5FejZMU2RXSFZDUEU4dzQ1ZkROMzhpSHRkUnpYaTJMU2pCZFJSNEZOY05SbXZWQ0pzLlZ6Nk1rZnZpQjlLUXU4aWc1Vml4bUdkczd2Z0w2ajJRc05QYXJuRlpqcE1DQTloelAuU2V5SjBJam9pWkcwaUxDSnpJanA3SW5WeWFTSTZJbWgwZEhBNkx5OHhPVEl1TVRZNExqRXVNemM2T0RBM01DOWthV1JqYjIxdElpd2ljaUk2VzEwc0ltRWlPbHNpWkdsa1kyOXRiUzkyTWlKZGZYMCJ9fX1dLCJjcmVhdGVkX3RpbWUiOjE3MjQzMzkxNDQsImV4cGlyZXNfdGltZSI6MTcyNDMzOTQ0NH0"; - const createPeerDID = sandbox.stub(agent, "createNewPeerDID"); - const sendMessage = sandbox.stub(agent.mercury, "sendMessage"); + const createPeerDID = vi.spyOn(agent, "createNewPeerDID"); + const sendMessage = vi.spyOn(agent.mercury, "sendMessage"); - sandbox.stub(UUIDLib, "uuid").returns("123456-123456-12356-123456"); + vi.spyOn(UUIDLib, "uuid").mockReturnValue("123456-123456-12356-123456"); - createPeerDID.resolves(did); - sendMessage.resolves(); + createPeerDID.mockResolvedValue(did); + sendMessage.mockResolvedValue(Uint8Array.from([])); // addConnection.resolves(); - expect( - agent.parseOOBInvitation(new URL(validOOB)) - ).to.eventually.be.rejectedWith(AgentError.InvitationIsInvalidError); + await expect(agent.parseOOBInvitation(new URL(validOOB))).rejects.toThrowError(AgentError.InvitationIsInvalidError); }); }); @@ -244,7 +224,7 @@ describe("Agent Tests", () => { Fixtures.Backup.backups.forEach(backupFixture => { describe(`Backup/Restore :: ${backupFixture.title}`, () => { test("backup", async () => { - sandbox.stub(pluto, "backup").resolves(backupFixture.json); + vi.spyOn(pluto, "backup").mockResolvedValue(backupFixture.json); const jwe = await agent.backup.createJWE(backupFixture.options); expect(jwe).to.be.a("string"); @@ -252,7 +232,7 @@ describe("Agent Tests", () => { }); test("restore", async () => { - const stubRestore = sandbox.stub(pluto, "restore"); + const stubRestore = vi.spyOn(pluto, "restore"); await agent.backup.restore(backupFixture.jwe, backupFixture.options); let backupSchema = backupFixture.json; const excludes = backupFixture.options?.excludes; @@ -262,14 +242,14 @@ describe("Agent Tests", () => { backupSchema.link_secret = excludes.includes('link_secret') ? undefined : backupSchema.link_secret; } const expected = JSON.parse(JSON.stringify(backupSchema)); - expect(stubRestore).to.have.been.calledWith(expected); + expect(stubRestore).toHaveBeenCalledWith(expected); }); test("round trip integration", async () => { // empty db of linksecret (store as any).cleanup(); - sandbox.stub(pluto, "backup").resolves(backupFixture.json); - const spyRestore = sandbox.spy(pluto, "restore"); + vi.spyOn(pluto, "backup").mockResolvedValue(backupFixture.json); + const spyRestore = vi.spyOn(pluto, "restore"); const jwe = await agent.backup.createJWE(backupFixture.options); await agent.backup.restore(jwe, backupFixture.options); @@ -285,7 +265,7 @@ describe("Agent Tests", () => { } // running SERDE to remove nil values, which will happen during backup/restore let expected = JSON.parse(JSON.stringify(backupSchema)); - expect(spyRestore).to.have.been.calledWith(expected); + expect(spyRestore).toHaveBeenCalledWith(expected); }); }); @@ -428,8 +408,7 @@ describe("Agent Tests", () => { it(`CredentialType [${credType}] - not implemented - should throw`, async () => { const offer = createOffer(credType); - expect(agent.prepareRequestCredentialWithIssuer(offer)).to.eventually.be - .rejected; + await expect(agent.prepareRequestCredentialWithIssuer(offer)).rejects.toThrow(); }); } }); @@ -445,7 +424,7 @@ describe("Agent Tests", () => { const result = agent.processIssuedCredentialMessage(issueCredential); - expect(result).to.eventually.be.rejected; + expect(result).rejects.toThrow(); }); describe("JWTCredential", () => { @@ -558,7 +537,7 @@ describe("Agent Tests", () => { ); const sut = agent.processIssuedCredentialMessage(issueCredential); - expect(sut).to.eventually.be.rejected; + expect(sut).rejects.toThrow(); }); }); }); @@ -586,7 +565,7 @@ describe("Agent Tests", () => { ); const sut = agent.createPresentationForRequestProof(request, credential); - expect(sut).to.eventually.be.rejected; + expect(sut).rejects.toThrow(); }); }); @@ -594,9 +573,7 @@ describe("Agent Tests", () => { let stubGetDIDPrivateKeysByDID; beforeEach(() => { - stubGetDIDPrivateKeysByDID = sandbox - .stub(pluto, "getDIDPrivateKeysByDID") - .resolves([Fixtures.Keys.secp256K1.privateKey as any]); + stubGetDIDPrivateKeysByDID = vi.spyOn(pluto, "getDIDPrivateKeysByDID").mockResolvedValue([Fixtures.Keys.secp256K1.privateKey as any]); }); test("JWTCredential + JWTPresentationRequest - returns Presentation", async () => { @@ -640,7 +617,7 @@ describe("Agent Tests", () => { const result = agent.createPresentationForRequestProof(request, credential); - expect(result).to.eventually.be.rejected; + expect(result).rejects.toThrow(); }); test("Credential.subjectDID - invalid - throws", async () => { @@ -661,11 +638,11 @@ describe("Agent Tests", () => { const sut = agent.createPresentationForRequestProof(request, credential); - expect(sut).to.eventually.be.rejected; + expect(sut).rejects.toThrow(); }); test("Credential.subjectDID - doesn't match PrivateKey - throws", async () => { - stubGetDIDPrivateKeysByDID.resolves([]); + stubGetDIDPrivateKeysByDID.mockResolvedValue([]); const credential = new JWTCredential({ iss: "did:test:123", @@ -684,7 +661,7 @@ describe("Agent Tests", () => { const sut = agent.createPresentationForRequestProof(request, credential); - expect(sut).to.eventually.be.rejected; + expect(sut).rejects.toThrow(); }); }); @@ -700,7 +677,7 @@ describe("Agent Tests", () => { const result = agent.createPresentationForRequestProof(request, credential); - expect(result).to.eventually.be.rejected; + expect(result).rejects.toThrow(); }); test("Credential - not matched - throws", async () => { @@ -713,7 +690,7 @@ describe("Agent Tests", () => { const credential = JWTCredential.fromJWS(Fixtures.Credentials.JWT.credentialPayloadEncoded); const result = agent.createPresentationForRequestProof(request, credential); - expect(result).to.eventually.be.rejected; + expect(result).rejects.toThrow(); }); }); }); @@ -789,8 +766,7 @@ describe("Agent Tests", () => { describe("handlePresentation", () => { beforeEach(() => { - sandbox.stub(pluto, "getDIDPrivateKeysByDID") - .resolves([Fixtures.Keys.secp256K1.privateKey]); + vi.spyOn(pluto, "getDIDPrivateKeysByDID").mockResolvedValue([Fixtures.Keys.secp256K1.privateKey]); }); test("JWT", async () => { @@ -828,12 +804,12 @@ describe("Agent Tests", () => { }); // test("Anoncreds", async () => { - // sandbox.stub(pluto, "getLinkSecret").resolves(Fixtures.Credentials.Anoncreds.linkSecret); + // vi.spyOn(pluto, "getLinkSecret").resolves(Fixtures.Credentials.Anoncreds.linkSecret); - // sandbox.stub(pollux as any, "fetchSchema") + // vi.spyOn(pollux as any, "fetchSchema") // .resolves(Fixtures.Credentials.Anoncreds.schema); - // sandbox.stub(pollux as any, "fetchCredentialDefinition") + // vi.spyOn(pollux as any, "fetchCredentialDefinition") // .resolves(Fixtures.Credentials.Anoncreds.credentialDefinition); // const presentationReq = await agent.initiatePresentationRequest(CredentialType.AnonCreds, Fixtures.DIDs.peerDID1, { diff --git a/tests/agent/didcomm/invitation.test.ts b/tests/agent/didcomm/invitation.test.ts index 8a6918207..19d9c1630 100644 --- a/tests/agent/didcomm/invitation.test.ts +++ b/tests/agent/didcomm/invitation.test.ts @@ -1,10 +1,7 @@ import { vi, describe, it, expect, test, beforeEach, afterEach } from 'vitest'; -import chai from "chai"; -import chaiAsPromised from "chai-as-promised"; -import SinonChai from "sinon-chai"; import UUIDLib from "@stablelib/uuid"; import Agent from "../../../src/edge-agent/Agent"; -import { AttachmentDescriptor, DID, Message, MessageDirection, Seed } from "../../../src/domain"; +import { AttachmentDescriptor, DID, MessageDirection, Seed } from "../../../src/domain"; import { HandshakeRequest, OutOfBandInvitation, ProtocolType } from "../../../src"; import { InvitationIsInvalidError } from "../../../src/domain/models/errors/Agent"; import { mockPluto } from "../../fixtures/inmemory/factory"; @@ -13,11 +10,6 @@ import { StartMediator } from '../../../src/edge-agent/didcomm/StartMediator'; import { StartFetchingMessages } from '../../../src/edge-agent/didcomm/StartFetchingMessages'; import { MediatorConnection } from '../../../src/edge-agent/connections/didcomm'; -chai.use(SinonChai); -chai.use(chaiAsPromised); - - - describe("Agent", () => { let agent: Agent; @@ -98,13 +90,12 @@ describe("Agent", () => { expect(result).to.be.instanceOf(OutOfBandInvitation); }); - it("Invitation expired - throws", () => { + it("Invitation expired - throws", async () => { const oob = makeOOB(); oob.expires_time = (Date.now() / 1000) - 10; const url = `https://my.domain.com/path?_oob=${encodeB64(oob)}`; - expect(agent.parseInvitation(url)) - .to.eventually.be.rejectedWith(InvitationIsInvalidError); + await expect(agent.parseInvitation(url)).rejects.toThrow(InvitationIsInvalidError); }); it("Credential Offer Attachment - returns OutOfBandInvitation with attachment", async () => { diff --git a/tests/apollo/Apollo.test.ts b/tests/apollo/Apollo.test.ts index e297dadf5..d839a00fc 100644 --- a/tests/apollo/Apollo.test.ts +++ b/tests/apollo/Apollo.test.ts @@ -1,7 +1,4 @@ import { describe, it, expect, test, beforeEach, afterEach } from 'vitest'; - -import chai, { assert } from "chai"; -import chaiAsPromised from "chai-as-promised"; import Apollo from "../../src/apollo/Apollo"; import { Secp256k1KeyPair } from "../../src/apollo/utils/Secp256k1KeyPair"; import * as ECConfig from "../../src/domain/models/ECConfig"; @@ -31,7 +28,6 @@ import { DerivationAxis } from "../../src/domain/models/derivation/DerivationAxi import ApolloPKG from "@hyperledger/identus-apollo"; const ApolloSDK = ApolloPKG.org.hyperledger.identus.apollo; -chai.use(chaiAsPromised); describe("Apollo", () => { let apollo: Apollo; @@ -107,21 +103,13 @@ describe("Apollo", () => { it(`Should fail when mnemonics is wrong length [${i}]`, () => { const mnemonics = list.slice(0, i); - assert.throws( - () => apollo.createSeed(mnemonics as any, ""), - ApolloError.MnemonicLengthError - ); + expect(() => apollo.createSeed(mnemonics as any, "")).throws(ApolloError.MnemonicLengthError); }); } it("Should test failure when checksum is incorrect", () => { const mnemonicCode = Array(24).fill("abandon") as MnemonicWordList; - assert.throws( - () => { - apollo.createSeed(mnemonicCode, ""); - }, - ApolloError.MnemonicWordError - ); + expect(() => { apollo.createSeed(mnemonicCode, ""); }).throws(ApolloError.MnemonicWordError); }); it("Should compute the right binary seed", () => { @@ -147,9 +135,7 @@ describe("Apollo", () => { "codus", ...Array(20).fill("abandon"), ] as MnemonicWordList; - assert.throws(() => { - apollo.createSeed(mnemonicCode, ""); - }, ApolloError.MnemonicWordError); + expect(() => { apollo.createSeed(mnemonicCode, ""); }).throws(ApolloError.MnemonicWordError); }); }); @@ -454,7 +440,7 @@ describe("Apollo", () => { raw: Fixtures.Keys.ed25519.privateKey.raw }; - assert.throws(() => apollo.restorePrivateKey(key as any), ApolloError.KeyRestoratonFailed); + expect(() => apollo.restorePrivateKey(key as any)).throws(ApolloError.KeyRestoratonFailed); }); }); @@ -498,7 +484,7 @@ describe("Apollo", () => { raw: Fixtures.Keys.ed25519.publicKey.raw }; - assert.throws(() => apollo.restorePublicKey(key as any), ApolloError.KeyRestoratonFailed); + expect(() => apollo.restorePublicKey(key as any)).throws(ApolloError.KeyRestoratonFailed); }); }); }); diff --git a/tests/castor/PrismDID.test.ts b/tests/castor/PrismDID.test.ts index 33d8c2e96..3ee601788 100644 --- a/tests/castor/PrismDID.test.ts +++ b/tests/castor/PrismDID.test.ts @@ -1,7 +1,5 @@ -import chai from "chai"; -import chaiAsPromised from "chai-as-promised"; +import { vi, describe, expect, it, test, beforeEach, afterEach } from 'vitest'; import { base58btc } from "multiformats/bases/base58"; -import { describe, assert, it, expect, test, beforeEach, afterEach } from 'vitest'; import { Authentication, Curve, DIDDocument, getCurveVerificationMethodType, getProtosUsage, getUsageId, JWT_ALG, KeyTypes, PublicKey, Services, Usage, VerificationMethod, VerificationMethods } from "../../src/domain"; import Apollo from "../../src/apollo/Apollo"; import Castor from "../../src/castor/Castor"; @@ -12,12 +10,9 @@ import * as Protos from "../../src/castor/protos/node_models"; import { PrismDIDPublicKey } from "../../src/castor/did/prismDID/PrismDIDPublicKey"; import { ed25519, x25519 } from "../fixtures/keys"; -chai.use(chaiAsPromised); - -const apollo = new Apollo(); -const castor = new Castor(apollo); - describe("PrismDID", () => { + let apollo: Apollo; + let castor: Castor; const secpDid = "did:prism:032e7383265cab026f4bdf8b903f8f78840fefc5b201ccce06fc263f7b3be5df:CskBCsYBEl0KCG1hc3Rlci0wEAFCTwoJc2VjcDI1NmsxEiD9IDIUwFTpO0oFkZbs5niSI7ZtvmDHOgG6w93jyiUI_hog2ZbGuaULlxsyr4CtdA_Es7g74e_buaDAe_mXiTQIfosSZQoQYXV0aGVudGljYXRpb24tMBAEQk8KCXNlY3AyNTZrMRIg_SAyFMBU6TtKBZGW7OZ4kiO2bb5gxzoBusPd48olCP4aINmWxrmlC5cbMq-ArXQPxLO4O-Hv27mgwHv5l4k0CH6L"; const secpMultibase = "zSXxpYB6edvxvWxRTo3kMUoTTQVHpbNnXo2Z1AjLA78iqLdK2kVo5xw9rGg8uoEgmhxYahNur3RvV7HnaktWBqkXt"; const ed25519Did = "did:prism:fc9fcaead407285991cdf1d27819720d8923e96274794c24977045e00b72e4c7:CqUBCqIBEl0KCG1hc3Rlci0wEAFCTwoJc2VjcDI1NmsxEiD9IDIUwFTpO0oFkZbs5niSI7ZtvmDHOgG6w93jyiUI_hog2ZbGuaULlxsyr4CtdA_Es7g74e_buaDAe_mXiTQIfosSQQoQYXV0aGVudGljYXRpb24tMBAESisKB0VkMjU1MTkSIHZuX9hnUeQWh6UcQfG0xJbxP9ICAtqeNODLMfbMCfde"; @@ -25,17 +20,26 @@ describe("PrismDID", () => { const x25519Did = "did:prism:5911e7a69ef3d1af144fa2192190c3576ce8087e2444f93b5b6cf12a71156e5f:CqQBCqEBEl0KCG1hc3Rlci0wEAFCTwoJc2VjcDI1NmsxEiD9IDIUwFTpO0oFkZbs5niSI7ZtvmDHOgG6w93jyiUI_hog2ZbGuaULlxsyr4CtdA_Es7g74e_buaDAe_mXiTQIfosSQAoQYXV0aGVudGljYXRpb24tMBAESioKBlgyNTUxORIg_PjHefFh9H7qH3Vt7MO8VEN-F2PlWcXzdxw6LPkxEGE"; const x25519Multibase = "zJ2VmASEaRF41F4BQSydGNi7zd5ud5YhqXxTKicPGd5FN"; + beforeEach(async () => { + apollo = new Apollo(); + castor = new Castor(apollo); + }); + + afterEach(async () => { + vi.restoreAllMocks(); + }); + describe("PrismDidPublicKey", () => { it("Should create getProtosUsageCorrectly", () => { - expect(getProtosUsage("any" as any)).to.eq(Protos.io.iohk.atala.prism.protos.KeyUsage.UNKNOWN_KEY); - expect(getProtosUsage(Usage.MASTER_KEY)).to.eq(Protos.io.iohk.atala.prism.protos.KeyUsage.MASTER_KEY); - expect(getProtosUsage(Usage.ISSUING_KEY)).to.eq(Protos.io.iohk.atala.prism.protos.KeyUsage.ISSUING_KEY); - expect(getProtosUsage(Usage.KEY_AGREEMENT_KEY)).to.eq(Protos.io.iohk.atala.prism.protos.KeyUsage.KEY_AGREEMENT_KEY); - expect(getProtosUsage(Usage.AUTHENTICATION_KEY)).to.eq(Protos.io.iohk.atala.prism.protos.KeyUsage.AUTHENTICATION_KEY); - expect(getProtosUsage(Usage.REVOCATION_KEY)).to.eq(Protos.io.iohk.atala.prism.protos.KeyUsage.REVOCATION_KEY); - expect(getProtosUsage(Usage.CAPABILITY_INVOCATION_KEY)).to.eq(Protos.io.iohk.atala.prism.protos.KeyUsage.CAPABILITY_INVOCATION_KEY); - expect(getProtosUsage(Usage.CAPABILITY_DELEGATION_KEY)).to.eq(Protos.io.iohk.atala.prism.protos.KeyUsage.CAPABILITY_DELEGATION_KEY); - expect(getProtosUsage(Usage.UNKNOWN_KEY)).to.eq(Protos.io.iohk.atala.prism.protos.KeyUsage.UNKNOWN_KEY); + expect(getProtosUsage("any" as any)).toEqual(Protos.io.iohk.atala.prism.protos.KeyUsage.UNKNOWN_KEY); + expect(getProtosUsage(Usage.MASTER_KEY)).toEqual(Protos.io.iohk.atala.prism.protos.KeyUsage.MASTER_KEY); + expect(getProtosUsage(Usage.ISSUING_KEY)).toEqual(Protos.io.iohk.atala.prism.protos.KeyUsage.ISSUING_KEY); + expect(getProtosUsage(Usage.KEY_AGREEMENT_KEY)).toEqual(Protos.io.iohk.atala.prism.protos.KeyUsage.KEY_AGREEMENT_KEY); + expect(getProtosUsage(Usage.AUTHENTICATION_KEY)).toEqual(Protos.io.iohk.atala.prism.protos.KeyUsage.AUTHENTICATION_KEY); + expect(getProtosUsage(Usage.REVOCATION_KEY)).toEqual(Protos.io.iohk.atala.prism.protos.KeyUsage.REVOCATION_KEY); + expect(getProtosUsage(Usage.CAPABILITY_INVOCATION_KEY)).toEqual(Protos.io.iohk.atala.prism.protos.KeyUsage.CAPABILITY_INVOCATION_KEY); + expect(getProtosUsage(Usage.CAPABILITY_DELEGATION_KEY)).toEqual(Protos.io.iohk.atala.prism.protos.KeyUsage.CAPABILITY_DELEGATION_KEY); + expect(getProtosUsage(Usage.UNKNOWN_KEY)).toEqual(Protos.io.iohk.atala.prism.protos.KeyUsage.UNKNOWN_KEY); }); it("Should create from and to valid key protos", () => { @@ -66,9 +70,9 @@ describe("PrismDID", () => { ); const masterPkProto = masterPk.toProto(); const recoveredPk = PrismDIDPublicKey.fromProto(apollo, masterPkProto); - expect(masterPk.keyData.raw).to.deep.eq(recoveredPk.keyData.raw); - expect(masterPk.usage).to.eq(recoveredPk.usage); - expect(masterPk.id).to.eq(recoveredPk.id); + expect(masterPk.keyData.raw).toStrictEqual(recoveredPk.keyData.raw); + expect(masterPk.usage).toEqual(recoveredPk.usage); + expect(masterPk.id).toEqual(recoveredPk.id); }); const masterPk = new PrismDIDPublicKey( @@ -78,7 +82,7 @@ describe("PrismDID", () => { ); const masterPkProto = masterPk.toProto(); - expect(() => PrismDIDPublicKey.fromProto(apollo, masterPkProto)).to.throw(`16: Invalid key curve: ${unsupportedCurve}. Valid options are: X25519, Ed25519, secp256k1`); + expect(() => PrismDIDPublicKey.fromProto(apollo, masterPkProto)).toThrow(`16: Invalid key curve: ${unsupportedCurve}. Valid options are: X25519, Ed25519, secp256k1`); }); }); @@ -97,29 +101,29 @@ describe("PrismDID", () => { expect(atalaObject.block_content.operations[0].operation.create_did.did_data).toHaveProperty("public_keys"); expect(atalaObject.block_content.operations[0].operation.create_did.did_data.public_keys).toHaveLength(1); expect(atalaObject.block_content.operations[0].operation.create_did.did_data.public_keys[0]).toHaveProperty("id"); - expect(atalaObject.block_content.operations[0].operation.create_did.did_data.public_keys[0].id).to.equal(getUsageId(Usage.MASTER_KEY, 0)); - }) + expect(atalaObject.block_content.operations[0].operation.create_did.did_data.public_keys[0].id).toEqual(getUsageId(Usage.MASTER_KEY, 0)); + }); it("Should create a prismDID from a PublicKey (SECP256K1)", async () => { const result = await castor.createPrismDID(Fixtures.Keys.secp256K1.publicKey, [], [Fixtures.Keys.secp256K1]); - expect(result).not.to.be.null; - expect(result.toString()).to.equal(secpDid); + expect(result).not.toBeNull(); + expect(result.toString()).toEqual(secpDid); }); it("Should create a prismDID from a KeyPair (SECP256K1)", async () => { const result = await castor.createPrismDID(Fixtures.Keys.secp256K1, [], [Fixtures.Keys.secp256K1]); - expect(result).not.to.be.null; - expect(result.toString()).to.equal(secpDid); + expect(result).not.toBeNull(); + expect(result.toString()).toEqual(secpDid); }); it("Should create a prismDID from a KeyPair (Ed25519)", async () => { const result = await castor.createPrismDID(Fixtures.Keys.secp256K1, [], [Fixtures.Keys.ed25519]); - expect(result).not.to.be.null; - expect(result.toString()).to.equal(ed25519Did); + expect(result).not.toBeNull(); + expect(result.toString()).toEqual(ed25519Did); }); it("Should create a prismDID from a KeyPair (X25519)", async () => { const result = await castor.createPrismDID(Fixtures.Keys.secp256K1, [], [Fixtures.Keys.x25519]); - expect(result.toString()).to.equal(x25519Did); + expect(result.toString()).toEqual(x25519Did); }); }); @@ -130,68 +134,68 @@ describe("PrismDID", () => { const didStr = "did:prism:032e7383265cab026f4bdf8b903f8f78840fefc5b201ccce06fc263f7b3be5df:CskBCsYBEl0KCG1hc3Rlci0wEAFCTwoJc2VjcDI1NmsxEiD9IDIUwFTpO0oFkZbs5niSI7ZtvmDHOgG6w93jyiUI_hog2ZbGuaULlxsyr4CtdA_Es7g74e_buaDAe_mXiTQIfosSZQoQYXV0aGVudGljYXRpb24tMBAEQk8KCXNlY3AyNTZrMRIg_SAyFMBU6TtKBZGW7OZ4kiO2bb5gxzoBusPd48olCP4aINmWxrmlC5cbMq-ArXQPxLO4O-Hv27mgwHv5l4k0CH6L"; const sut = await castor.resolveDID(didStr); - expect(sut).to.be.instanceOf(DIDDocument); - expect(sut.id.toString()).to.eq(didStr); - expect(sut.coreProperties).to.be.an("array").to.have.length(4); + expect(sut).toBeInstanceOf(DIDDocument); + expect(sut.id.toString()).toEqual(didStr); + expect(sut.coreProperties).to.be.an("array").toHaveLength(4); const cp0 = sut.coreProperties.at(0) as Authentication; - expect(cp0).to.be.instanceOf(Authentication); + expect(cp0).toBeInstanceOf(Authentication); expect(cp0.urls).to.include(`${didStr}#master-0`); const cp0vm0 = cp0.verificationMethods.at(0); - expect(cp0vm0).to.be.instanceOf(VerificationMethod); - expect(cp0vm0?.controller).to.eq(didStr); - expect(cp0vm0?.id).to.eq(`${didStr}#master-0`); - expect(cp0vm0?.publicKeyJwk).to.be.undefined; - expect(cp0vm0?.publicKeyMultibase).to.eq("zSXxpYB6edvxvWxRTo3kMUoTTQVHpbNnXo2Z1AjLA78iqLdK2kVo5xw9rGg8uoEgmhxYahNur3RvV7HnaktWBqkXt"); - expect(cp0vm0?.type).to.eq("EcdsaSecp256k1VerificationKey2019"); + expect(cp0vm0).toBeInstanceOf(VerificationMethod); + expect(cp0vm0?.controller).toEqual(didStr); + expect(cp0vm0?.id).toEqual(`${didStr}#master-0`); + expect(cp0vm0?.publicKeyJwk).toBeUndefined(); + expect(cp0vm0?.publicKeyMultibase).toEqual("zSXxpYB6edvxvWxRTo3kMUoTTQVHpbNnXo2Z1AjLA78iqLdK2kVo5xw9rGg8uoEgmhxYahNur3RvV7HnaktWBqkXt"); + expect(cp0vm0?.type).toEqual("EcdsaSecp256k1VerificationKey2019"); const cp1 = sut.coreProperties.at(1) as Authentication; - expect(cp1).to.be.instanceOf(Authentication); + expect(cp1).toBeInstanceOf(Authentication); expect(cp1.urls).to.include(`${didStr}#authentication-0`); const cp1vm0 = cp1.verificationMethods.at(0); - expect(cp1vm0).to.be.instanceOf(VerificationMethod); - expect(cp1vm0?.controller).to.eq(didStr); - expect(cp1vm0?.id).to.eq(`${didStr}#authentication-0`); - expect(cp1vm0?.publicKeyJwk).to.be.undefined; - expect(cp1vm0?.publicKeyMultibase).to.eq("zSXxpYB6edvxvWxRTo3kMUoTTQVHpbNnXo2Z1AjLA78iqLdK2kVo5xw9rGg8uoEgmhxYahNur3RvV7HnaktWBqkXt"); - expect(cp1vm0?.type).to.eq("EcdsaSecp256k1VerificationKey2019"); + expect(cp1vm0).toBeInstanceOf(VerificationMethod); + expect(cp1vm0?.controller).toEqual(didStr); + expect(cp1vm0?.id).toEqual(`${didStr}#authentication-0`); + expect(cp1vm0?.publicKeyJwk).toBeUndefined(); + expect(cp1vm0?.publicKeyMultibase).toEqual("zSXxpYB6edvxvWxRTo3kMUoTTQVHpbNnXo2Z1AjLA78iqLdK2kVo5xw9rGg8uoEgmhxYahNur3RvV7HnaktWBqkXt"); + expect(cp1vm0?.type).toEqual("EcdsaSecp256k1VerificationKey2019"); const cp2 = sut.coreProperties.at(2) as Services; - expect(cp2).to.be.instanceOf(Services); - expect(cp2.values).to.be.empty; + expect(cp2).toBeInstanceOf(Services); + expect(cp2.values).toHaveLength(0); // TODO why do we have duplicates of coreProperties 0 & 1 here? const cp3 = sut.coreProperties.at(3) as VerificationMethods; - expect(cp3).to.be.instanceOf(VerificationMethods); - expect(cp3.values).to.have.length(2); + expect(cp3).toBeInstanceOf(VerificationMethods); + expect(cp3.values).toHaveLength(2); const cp3v0 = cp3.values.at(0); - expect(cp3v0).to.be.instanceOf(VerificationMethod); - expect(cp3v0?.controller).to.eq(didStr); - expect(cp3v0?.id).to.eq(`${didStr}#master-0`); - expect(cp3v0?.publicKeyJwk).to.be.undefined; - expect(cp3v0?.publicKeyMultibase).to.eq("zSXxpYB6edvxvWxRTo3kMUoTTQVHpbNnXo2Z1AjLA78iqLdK2kVo5xw9rGg8uoEgmhxYahNur3RvV7HnaktWBqkXt"); - expect(cp3v0?.type).to.eq("EcdsaSecp256k1VerificationKey2019"); + expect(cp3v0).toBeInstanceOf(VerificationMethod); + expect(cp3v0?.controller).toEqual(didStr); + expect(cp3v0?.id).toEqual(`${didStr}#master-0`); + expect(cp3v0?.publicKeyJwk).toBeUndefined(); + expect(cp3v0?.publicKeyMultibase).toEqual("zSXxpYB6edvxvWxRTo3kMUoTTQVHpbNnXo2Z1AjLA78iqLdK2kVo5xw9rGg8uoEgmhxYahNur3RvV7HnaktWBqkXt"); + expect(cp3v0?.type).toEqual("EcdsaSecp256k1VerificationKey2019"); const cp3v1 = cp3.values.at(1); - expect(cp3v1).to.be.instanceOf(VerificationMethod); - expect(cp3v1?.controller).to.eq(didStr); - expect(cp3v1?.id).to.eq(`${didStr}#authentication-0`); - expect(cp3v1?.publicKeyJwk).to.be.undefined; - expect(cp3v1?.publicKeyMultibase).to.eq("zSXxpYB6edvxvWxRTo3kMUoTTQVHpbNnXo2Z1AjLA78iqLdK2kVo5xw9rGg8uoEgmhxYahNur3RvV7HnaktWBqkXt"); - expect(cp3v1?.type).to.eq("EcdsaSecp256k1VerificationKey2019"); + expect(cp3v1).toBeInstanceOf(VerificationMethod); + expect(cp3v1?.controller).toEqual(didStr); + expect(cp3v1?.id).toEqual(`${didStr}#authentication-0`); + expect(cp3v1?.publicKeyJwk).toBeUndefined(); + expect(cp3v1?.publicKeyMultibase).toEqual("zSXxpYB6edvxvWxRTo3kMUoTTQVHpbNnXo2Z1AjLA78iqLdK2kVo5xw9rGg8uoEgmhxYahNur3RvV7HnaktWBqkXt"); + expect(cp3v1?.type).toEqual("EcdsaSecp256k1VerificationKey2019"); }); const masterKeyId = getUsageId(Usage.MASTER_KEY); const authenticationKeyId = getUsageId(Usage.AUTHENTICATION_KEY); const testVerificationMethod = (sut: any, didStr: string, keyId: string, keyMultibase: string, curve: Curve) => { - expect(sut).to.be.instanceOf(VerificationMethod); - expect(sut?.controller).to.eq(didStr); - expect(sut?.id).to.eq(`${didStr}#${keyId}`); - expect(sut?.publicKeyJwk).to.be.undefined; - expect(sut?.publicKeyMultibase).to.eq(keyMultibase); - expect(sut?.type).to.eq(getCurveVerificationMethodType(curve)); + expect(sut).toBeInstanceOf(VerificationMethod); + expect(sut?.controller).toEqual(didStr); + expect(sut?.id).toEqual(`${didStr}#${keyId}`); + expect(sut?.publicKeyJwk).toBeUndefined(); + expect(sut?.publicKeyMultibase).toEqual(keyMultibase); + expect(sut?.type).toEqual(getCurveVerificationMethodType(curve)); }; test("master key", async () => { @@ -202,33 +206,33 @@ describe("PrismDID", () => { ); const sut = await castor.resolveDID(prismDid.toString()); - expect(sut).not.to.be.null; - expect(sut.coreProperties).to.be.an("array").to.have.length(4); + expect(sut).not.toBeNull(); + expect(sut.coreProperties).to.be.an("array").toHaveLength(4); // master key correctly encoded > decoded const masterProp = sut.coreProperties.at(0) as Authentication; - expect(masterProp).to.be.instanceOf(Authentication); - expect(masterProp.urls[0]).to.eq(`${secpDid}#${masterKeyId}`); + expect(masterProp).toBeInstanceOf(Authentication); + expect(masterProp.urls[0]).toEqual(`${secpDid}#${masterKeyId}`); const mastervm0 = masterProp.verificationMethods.at(0); testVerificationMethod(mastervm0, secpDid, masterKeyId, secpMultibase, Curve.SECP256K1); // authentication key correctly encoded > decoded const authProp = sut.coreProperties.at(1) as Authentication; - expect(authProp).to.be.instanceOf(Authentication); - expect(authProp.urls[0]).to.eq(`${secpDid}#${authenticationKeyId}`); + expect(authProp).toBeInstanceOf(Authentication); + expect(authProp.urls[0]).toEqual(`${secpDid}#${authenticationKeyId}`); const authvm0 = authProp.verificationMethods.at(0); testVerificationMethod(authvm0, secpDid, authenticationKeyId, secpMultibase, Curve.SECP256K1); // no services given - so empty const services = sut.coreProperties.at(2) as Services; - expect(services).to.be.instanceOf(Services); - expect(services.values).to.be.empty; + expect(services).toBeInstanceOf(Services); + expect(services.values).toHaveLength(0); // no issuing keys given - so only master and authentication keys duplicated const verificationMethods = sut.coreProperties.at(3) as VerificationMethods; - expect(verificationMethods).to.be.instanceOf(VerificationMethods); - expect(verificationMethods.values).to.have.length(2); + expect(verificationMethods).toBeInstanceOf(VerificationMethods); + expect(verificationMethods.values).toHaveLength(2); const vm0 = verificationMethods.values.at(0); testVerificationMethod(vm0, secpDid, masterKeyId, secpMultibase, Curve.SECP256K1); @@ -243,19 +247,19 @@ describe("PrismDID", () => { const sut = await castor.resolveDID(prismDid.toString()); //Lowering to 5 as we are no longer creating the MasterKey additionally as an Issuing key - expect(sut.coreProperties).to.be.an("array").to.have.length(5); + expect(sut.coreProperties).to.be.an("array").toHaveLength(5); // index 2 & 3 should be issuing keys // no services given - so empty const services = sut.coreProperties.at(3) as Services; - expect(services).to.be.instanceOf(Services); - expect(services.values).to.be.empty; + expect(services).toBeInstanceOf(Services); + expect(services.values).toHaveLength(0); // 2 issuing keys given - 4 total const verificationMethods = sut.coreProperties.at(4) as VerificationMethods; - expect(verificationMethods).to.be.instanceOf(VerificationMethods); - expect(verificationMethods.values).to.have.length(3); + expect(verificationMethods).toBeInstanceOf(VerificationMethods); + expect(verificationMethods.values).toHaveLength(3); const vm0 = verificationMethods.values.at(0); testVerificationMethod(vm0, expectedDid, masterKeyId, secpMultibase, Curve.SECP256K1); @@ -291,7 +295,7 @@ describe("PrismDID", () => { ); expect(resolvedPublicKeyBuffer).to.deep.equal(masterPublicKey.raw); - expect(resolveCreated.id.toString()).to.be.equal(resolvedDID.id.toString()); + expect(resolveCreated.id.toString()).toEqual(resolvedDID.id.toString()); }); it("Create a PrismDID and verify a signature", async () => { @@ -307,7 +311,7 @@ describe("PrismDID", () => { const signature = privateKey.isSignable() && privateKey.sign(Buffer.from(text)); - expect(signature).to.not.be.equal(false); + expect(signature).not.toEqual(false); if (signature) { const result = await castor.verifySignature( @@ -315,7 +319,7 @@ describe("PrismDID", () => { Buffer.from(text), Buffer.from(signature) ); - expect(result).to.be.equal(true); + expect(result).toEqual(true); } }); @@ -339,7 +343,7 @@ describe("PrismDID", () => { const signature = sk.isSignable() && sk.sign(Buffer.from(text)); - expect(signature).to.not.be.equal(false); + expect(signature).not.toEqual(false); if (signature) { const result = await castor.verifySignature( @@ -347,7 +351,7 @@ describe("PrismDID", () => { Buffer.from(text), Buffer.from(signature) ); - expect(result).to.be.equal(true); + expect(result).toEqual(true); } }); @@ -370,7 +374,7 @@ describe("PrismDID", () => { ); resolvedPublicKeyBuffer.length; - expect(resolvedPublicKeyBuffer.length).to.be.equal( + expect(resolvedPublicKeyBuffer.length).toEqual( ECConfig.PUBLIC_KEY_BYTE_SIZE ); }); diff --git a/tests/mercury/Mercury.test.ts b/tests/mercury/Mercury.test.ts index 5d782a2a3..7eb3de7cc 100644 --- a/tests/mercury/Mercury.test.ts +++ b/tests/mercury/Mercury.test.ts @@ -1,97 +1,41 @@ import { vi, describe, it, expect, test, beforeEach, afterEach } from 'vitest'; -/* eslint-disable @typescript-eslint/no-unused-vars */ -/* eslint-disable no-unused-vars */ -import chai from "chai"; -import chaiAsPromised from "chai-as-promised"; - -import * as sinon from "sinon"; -import SinonChai from "sinon-chai"; -import { - Api, - DID, - DIDDocument, - KeyPair, - Message, - PublicKey, - Service, - ServiceEndpoint, - Services, -} from "../../src/domain"; +import { Api, DID, Message } from "../../src/domain"; import * as Domain from "../../src/domain"; import { MercuryError } from "../../src/domain/models/Errors"; import { DIDCommProtocol } from "../../src/mercury/DIDCommProtocol"; import Mercury from "../../src/mercury/Mercury"; import { Castor } from "../../src/domain/buildingBlocks/Castor"; -chai.use(SinonChai); -chai.use(chaiAsPromised); - describe("Mercury", () => { - let sandbox: sinon.SinonSandbox; - let ctx: { - castor: Castor; - httpManager: Api; - didProtocol: DIDCommProtocol; - mercury: Mercury; - }; + let castor: Castor; + let httpManager: Api; + let didProtocol: DIDCommProtocol; + let mercury: Mercury; beforeEach(() => { - sandbox = sinon.createSandbox(); - }); + castor = { + parseDID: vi.fn(), + resolveDID: vi.fn(), + } as any; - afterEach(() => { - sandbox.restore(); - }); + httpManager = { request: async () => new Domain.ApiResponse(new Uint8Array(), 200) }; - const makeTestContext = (message?: Message) => { - const castor: Castor = { - parseDID(did: string): DID { - throw new Error("Method not implemented."); - }, - createPrismDID( - masterPublicKey: PublicKey, - services?: Service[] | undefined - ): Promise { - throw new Error("Method not implemented."); - }, - createPeerDID(keyPairs: KeyPair[], services: Service[]): Promise { - throw new Error("Method not implemented."); - }, - resolveDID(did: string): Promise { - throw new Error("Method not implemented."); - }, - verifySignature( - did: DID, - challenge: Uint8Array, - signature: Uint8Array - ): Promise { - throw new Error("Method not implemented."); - }, - getEcnumbasis(did: DID, keyPair: KeyPair): string { - throw new Error("Method not implemented."); - }, - }; - const httpManager: Api = { - request: async () => new Domain.ApiResponse(new Uint8Array(), 200), - }; - const didProtocol: DIDCommProtocol = { + didProtocol = { packEncrypted: async () => "", - unpack: async () => - message || new Message("{}", undefined, "TypeofMessage"), + unpack: async () => new Message("{}", undefined, "TypeofMessage"), }; - const mercury = new Mercury(castor, didProtocol, httpManager); - mercury.castor = castor; - return { castor, httpManager, didProtocol, mercury }; - }; + + mercury = new Mercury(castor, didProtocol, httpManager); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); describe("PackMessage", () => { - it("should call DIDCommProtocol.packEncrypted with [message, message.to, message.from]", () => { - const fromDid = DID.fromString( - "did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOnsidXJpIjoiaHR0cHM6Ly9tZWRpYXRvci5yb290c2lkLmNsb3VkIiwiYSI6WyJkaWRjb21tL3YyIl19fQ" - ); - const toDid = DID.fromString( - "did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOnsidXJpIjoiaHR0cHM6Ly9tZWRpYXRvci5yb290c2lkLmNsb3VkIiwiYSI6WyJkaWRjb21tL3YyIl19fQ" - ); + it("should call DIDCommProtocol.packEncrypted with [message, message.to, message.from]", async () => { + const fromDid = DID.fromString("did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOnsidXJpIjoiaHR0cHM6Ly9tZWRpYXRvci5yb290c2lkLmNsb3VkIiwiYSI6WyJkaWRjb21tL3YyIl19fQ"); + const toDid = DID.fromString("did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOnsidXJpIjoiaHR0cHM6Ly9tZWRpYXRvci5yb290c2lkLmNsb3VkIiwiYSI6WyJkaWRjb21tL3YyIl19fQ"); const message = new Message( "{}", undefined, @@ -100,47 +44,29 @@ describe("Mercury", () => { toDid, [] ); - const ctx = makeTestContext(message); - sandbox.stub(ctx.didProtocol, "packEncrypted"); - ctx.mercury.packMessage(message); + const spy = vi.spyOn(didProtocol, "packEncrypted"); + await mercury.packMessage(message); - expect(ctx.didProtocol.packEncrypted).to.have.been.calledWith( - message, - toDid, - fromDid - ); + expect(spy).toHaveBeenCalledWith(message, toDid, fromDid); }); describe("Errors", () => { - it("should throw error when Messsage.to is not a DID", () => { + it("should throw error when Messsage.to is not a DID", async () => { const message = {} as any; - const ctx = makeTestContext(message); - - expect(() => ctx.mercury.packMessage(message)).to.throw( - MercuryError.NoRecipientDIDSetError - ); - }); - - it("should throw error when Messsage.to is not a DID", () => { - const message = new Message("{}", "", ""); - const ctx = makeTestContext(message); - expect(() => ctx.mercury.packMessage(message)).to.throw( - MercuryError.NoRecipientDIDSetError - ); + await expect(mercury.packMessage(message)).rejects.toThrowError(MercuryError.NoRecipientDIDSetError); }); }); }); describe("UnpackMessage", () => { - it("should call DIDCommProtocol.unpack with [message]", () => { - const ctx = makeTestContext(); + it("should call DIDCommProtocol.unpack with [message]", async () => { const messageString = "someMessageString"; + vi.spyOn(didProtocol, "unpack"); - sandbox.stub(ctx.didProtocol, "unpack"); - ctx.mercury.unpackMessage(messageString); + mercury.unpackMessage(messageString); - expect(ctx.didProtocol.unpack).to.have.been.calledWith(messageString); + await expect(didProtocol.unpack).toHaveBeenCalledWith(messageString); }); }); @@ -149,18 +75,11 @@ describe("Mercury", () => { let toDID; beforeEach(() => { - ctx = makeTestContext(); - fromDID = DID.fromString( - "did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOnsidXJpIjoiaHR0cHM6Ly9tZWRpYXRvci5yb290c2lkLmNsb3VkIiwiYSI6WyJkaWRjb21tL3YyIl19fQ" - ); - toDID = DID.fromString( - "did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOnsidXJpIjoiaHR0cHM6Ly9tZWRpYXRvci5yb290c2lkLmNsb3VkIiwiYSI6WyJkaWRjb21tL3YyIl19fQ" - ); + fromDID = DID.fromString("did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOnsidXJpIjoiaHR0cHM6Ly9tZWRpYXRvci5yb290c2lkLmNsb3VkIiwiYSI6WyJkaWRjb21tL3YyIl19fQ"); + toDID = DID.fromString("did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOnsidXJpIjoiaHR0cHM6Ly9tZWRpYXRvci5yb290c2lkLmNsb3VkIiwiYSI6WyJkaWRjb21tL3YyIl19fQ"); - sandbox.stub(ctx.castor, "parseDID").returns(fromDID); - sandbox - .stub(ctx.httpManager, "request") - .resolves(new Domain.ApiResponse({}, 200)); + vi.spyOn(castor, "parseDID").mockReturnValue(fromDID); + vi.spyOn(httpManager, "request").mockResolvedValue(new Domain.ApiResponse({}, 200)); }); // it("should call HttpManager.postEncrypted with [ServiceEndpoint.uri, packedMessage]", async () => { @@ -178,21 +97,21 @@ describe("Mercury", () => { // new Service("testService", ["DIDCommMessaging"], endpoint), // ]); // sandbox - // .stub(ctx.castor, "resolveDID") + // .stub(castor, "resolveDID") // .resolves(new Domain.DIDDocument(toDID, [services])); - // sandbox.stub(ctx.didProtocol, "packEncrypted").resolves(packedMessage); + // vi.spyOn(didProtocol, "packEncrypted").resolves(packedMessage); - // await ctx.mercury.sendMessage(message); + // await mercury.sendMessage(message); - // expect(ctx.didProtocol.packEncrypted).to.have.been.calledWith( + // expect(didProtocol.packEncrypted).to.have.been.calledWith( // message, // toDID, // fromDID // ); - // expect(ctx.mercury.castor.resolveDID).to.have.been.calledWith( + // expect(mercury.castor.resolveDID).to.have.been.calledWith( // toDID.toString() // ); - // expect(ctx.mercury.api.request).to.have.been.calledWith( + // expect(mercury.api.request).to.have.been.calledWith( // "POST", // endpoint.uri, // new Map(), @@ -205,9 +124,7 @@ describe("Mercury", () => { it("should throw error when Messsage.to is not a DID", async () => { const message = new Message("{}", "", ""); - expect(ctx.mercury.sendMessage(message)).to.eventually.be.rejectedWith( - MercuryError.NoRecipientDIDSetError - ); + await expect(mercury.sendMessage(message)).rejects.toThrowError(MercuryError.NoRecipientDIDSetError); }); it("should throw error when Messsage.to has no valid Service", async () => { @@ -219,35 +136,26 @@ describe("Mercury", () => { fromDID ); - sandbox - .stub(ctx.castor, "resolveDID") - .resolves(new Domain.DIDDocument(toDID, [])); + vi.spyOn(castor, "resolveDID").mockResolvedValue(new Domain.DIDDocument(toDID, [])); - expect(ctx.mercury.sendMessage(message)).to.eventually.be.rejectedWith( - MercuryError.NoValidServiceFoundError - ); + await expect(mercury.sendMessage(message)).rejects.toThrowError(MercuryError.NoValidServiceFoundError); }); }); }); describe("SendMessageParseMessage", () => { it("passes the result of sendMessage to unpackMessage", async () => { - const ctx = makeTestContext(); const message = new Message("{}", undefined, "TypeofMessage"); const returnedMessage = { message: "returnedMessage" }; const unpackedMessage = new Message("{}", undefined, "TypeofMessage"); - sandbox - .stub(ctx.mercury, "sendMessage") - .callsFake(async () => returnedMessage); - sandbox - .stub(ctx.mercury, "unpackMessage") - .callsFake(async () => unpackedMessage); + const spySend = vi.spyOn(mercury, "sendMessage").mockResolvedValue(returnedMessage); + const spyUnpack = vi.spyOn(mercury, "unpackMessage").mockResolvedValue(unpackedMessage); - const result = await ctx.mercury.sendMessageParseMessage(message); + const result = await mercury.sendMessageParseMessage(message); const jsonMessage = JSON.stringify(returnedMessage); - expect(ctx.mercury.sendMessage).to.have.been.calledWith(message); - expect(ctx.mercury.unpackMessage).to.have.been.calledWith(jsonMessage); + expect(spySend).toHaveBeenCalledWith(message); + expect(spyUnpack).toHaveBeenCalledWith(jsonMessage); expect(result).to.equal(unpackedMessage); }); }); diff --git a/tests/mercury/didcomm/SecretsResolver.test.ts b/tests/mercury/didcomm/SecretsResolver.test.ts index 41fe637ef..f73a40c10 100644 --- a/tests/mercury/didcomm/SecretsResolver.test.ts +++ b/tests/mercury/didcomm/SecretsResolver.test.ts @@ -1,116 +1,69 @@ import { vi, describe, it, expect, test, beforeEach, afterEach } from 'vitest'; -import chai from "chai"; -import * as sinon from "sinon"; -import SinonChai from "sinon-chai"; import Apollo from "../../../src/apollo/Apollo"; import Castor from "../../../src/castor/Castor"; -import Pluto from "../../../src/pluto/Pluto"; +import { Pluto } from "../../../src/pluto/Pluto"; import * as Domain from "../../../src/domain"; import { DIDCommSecretsResolver } from "../../../src/mercury/didcomm/SecretsResolver"; -import { Curve, PrivateKey } from "../../../src/domain"; - -chai.use(SinonChai); +import { Curve } from "../../../src/domain"; +import * as Fixtures from "../../fixtures"; describe("Mercury DIDComm SecretsResolver", () => { - let sandbox: sinon.SinonSandbox; + let apollo: Apollo; + let castor: Castor; + let pluto: Pluto; + let secretsResolver: DIDCommSecretsResolver; + beforeEach(() => { - sandbox = sinon.createSandbox(); - }); - afterEach(() => { - sandbox.restore(); - }); + apollo = { + createPrivateKey: vi.fn(), + } as any; - const makeTestContext = () => { - const apollo: Pick = { - createPrivateKey: (parameters: { [name: string]: any }) => { - return new (class extends PrivateKey { - publicKey(): Domain.PublicKey { - return new (class extends Domain.PublicKey { - type: Domain.KeyTypes; - keySpecification: Map; - size: number; - raw: Uint8Array = new Uint8Array(); - getEncoded(): Uint8Array { - return this.raw; - } - })(); - } - type: Domain.KeyTypes; - keySpecification: Map; - size: number; - raw: Uint8Array = new Uint8Array(); - getEncoded(): Uint8Array { - return this.raw; - } - })(); - }, - getPrivateJWKJson: (id) => `${id}`, - }; - - const castor: Pick = { + castor = { getEcnumbasis: (did, publicKey) => `${publicKey.curve}`, resolveDID: async () => ({}) as Domain.DIDDocument, - }; + } as any; - const pluto: Pick = { + pluto = { getAllPeerDIDs: async () => [], - }; + } as any; - const secretsResolver = new DIDCommSecretsResolver( - apollo as Apollo, - castor as Castor, - pluto as Pluto - ); + secretsResolver = new DIDCommSecretsResolver(apollo, castor, pluto); + }); - return { apollo, castor, pluto, secretsResolver }; - }; + afterEach(() => { + vi.restoreAllMocks(); + }); describe("find_secrets", () => { it("should return matched secret", async () => { - const ctx = makeTestContext(); - const did = Domain.DID.fromString( - "did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOnsidXJpIjoiaHR0cHM6Ly9tZWRpYXRvci5yb290c2lkLmNsb3VkIiwiYSI6WyJkaWRjb21tL3YyIl19fQ" - ); + const did = Domain.DID.fromString("did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOnsidXJpIjoiaHR0cHM6Ly9tZWRpYXRvci5yb290c2lkLmNsb3VkIiwiYSI6WyJkaWRjb21tL3YyIl19fQ"); const secret = did.toString(); + // TODO: update when PeerDID Types are fixed + vi.spyOn(pluto, "getAllPeerDIDs").mockResolvedValue([{ did: secret } as any]); - sandbox.stub(ctx.pluto, "getAllPeerDIDs").resolves([ - // TODO: update when PeerDID Types are fixed - { did: secret } as any, - ]); - - const result = await ctx.secretsResolver.find_secrets([secret]); + const result = await secretsResolver.find_secrets([secret]); expect(result).to.have.lengthOf(1); expect(result).to.contain(secret); }); it("should return matched secret - no duplicates", async () => { - const ctx = makeTestContext(); - const did = Domain.DID.fromString( - "did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOnsidXJpIjoiaHR0cHM6Ly9tZWRpYXRvci5yb290c2lkLmNsb3VkIiwiYSI6WyJkaWRjb21tL3YyIl19fQ" - ); + const did = Domain.DID.fromString("did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOnsidXJpIjoiaHR0cHM6Ly9tZWRpYXRvci5yb290c2lkLmNsb3VkIiwiYSI6WyJkaWRjb21tL3YyIl19fQ"); const secret = did.toString(); + vi.spyOn(pluto, "getAllPeerDIDs").mockResolvedValue([{ did: secret }, { did: secret }] as any); - sandbox - .stub(ctx.pluto, "getAllPeerDIDs") - .resolves([{ did: secret } as any, { did: secret } as any]); - - const result = await ctx.secretsResolver.find_secrets([secret]); + const result = await secretsResolver.find_secrets([secret]); expect(result).to.have.lengthOf(1); expect(result).to.eql([secret]); }); it("should return empty array with unmatched secret", async () => { - const ctx = makeTestContext(); - const did = Domain.DID.fromString( - "did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOnsidXJpIjoiaHR0cHM6Ly9tZWRpYXRvci5yb290c2lkLmNsb3VkIiwiYSI6WyJkaWRjb21tL3YyIl19fQ" - ); + const did = Domain.DID.fromString("did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOnsidXJpIjoiaHR0cHM6Ly9tZWRpYXRvci5yb290c2lkLmNsb3VkIiwiYSI6WyJkaWRjb21tL3YyIl19fQ"); const secret = did.toString(); + vi.spyOn(pluto, "getAllPeerDIDs").mockResolvedValue([]); - sandbox.stub(ctx.pluto, "getAllPeerDIDs").resolves([]); - - const result = await ctx.secretsResolver.find_secrets([secret]); + const result = await secretsResolver.find_secrets([secret]); expect(result).to.have.lengthOf(0); }); @@ -118,10 +71,7 @@ describe("Mercury DIDComm SecretsResolver", () => { describe("get_secret", () => { it("should return matched secret", async () => { - const ctx = makeTestContext(); - const did = Domain.DID.fromString( - "did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOnsidXJpIjoiaHR0cHM6Ly9tZWRpYXRvci5yb290c2lkLmNsb3VkIiwiYSI6WyJkaWRjb21tL3YyIl19fQ" - ); + const did = Domain.DID.fromString("did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOnsidXJpIjoiaHR0cHM6Ly9tZWRpYXRvci5yb290c2lkLmNsb3VkIiwiYSI6WyJkaWRjb21tL3YyIl19fQ"); const secret = did.toString(); const publicKeyJwk: Domain.PublicKeyJWK = { crv: Domain.Curve.X25519, @@ -130,63 +80,38 @@ describe("Mercury DIDComm SecretsResolver", () => { x: Buffer.from(new Uint8Array()).toString("base64url"), }; const ecnum = "ecnum123"; + const privateKey = Fixtures.Keys.x25519.privateKey; const peerDid = { did: secret, curve: Curve.X25519, privateKeys: [ { keyCurve: { - curve: Curve.X25519, + curve: privateKey.curve }, - value: new Uint8Array(), + value: privateKey.getEncoded(), }, ], } as any; - sandbox.stub(ctx.pluto, "getAllPeerDIDs").resolves([peerDid]); - - sandbox - .stub(ctx.castor, "resolveDID") - .resolves( - new Domain.DIDDocument(did, [ - new Domain.VerificationMethods([ - new Domain.VerificationMethod( - secret, - "controller", - "type", - publicKeyJwk - ), - ]), - ]) - ); - - sandbox.stub(ctx.apollo, "createPrivateKey").returns( - new (class extends PrivateKey { - publicKey(): Domain.PublicKey { - return new (class extends Domain.PublicKey { - type: Domain.KeyTypes; - keySpecification: Map; - size: number; - raw: Uint8Array = new Uint8Array(); - getEncoded(): Uint8Array { - return this.raw; - } - })(); - } - type: Domain.KeyTypes; - keySpecification: Map; - size: number; - raw: Uint8Array = new Uint8Array(); - getEncoded(): Uint8Array { - return this.raw; - } - })() + vi.spyOn(pluto, "getAllPeerDIDs").mockResolvedValue([peerDid]); + vi.spyOn(castor, "resolveDID").mockResolvedValue( + new Domain.DIDDocument(did, [ + new Domain.VerificationMethods([ + new Domain.VerificationMethod( + secret, + "controller", + "JsonWebKey2020", + publicKeyJwk + ), + ]), + ]) ); - sandbox.stub(ctx.castor, "getEcnumbasis").returns(ecnum); + vi.spyOn(castor, "getEcnumbasis").mockReturnValue(ecnum); + vi.spyOn(apollo, "createPrivateKey").mockReturnValue(privateKey); - const result = await ctx.secretsResolver.get_secret(secret); - const [privateKey] = peerDid.privateKeys; + const result = await secretsResolver.get_secret(secret); expect(result).not.to.be.null; expect(result).to.eql({ @@ -195,22 +120,20 @@ describe("Mercury DIDComm SecretsResolver", () => { privateKeyJwk: { crv: peerDid.curve, kty: "OKP", - d: privateKey.value.toString(), + d: peerDid.privateKeys[0].value.toString(), x: publicKeyJwk.x as any, }, }); }); it("should return null when unmatched secret", async () => { - const ctx = makeTestContext(); const did = Domain.DID.fromString( "did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOnsidXJpIjoiaHR0cHM6Ly9tZWRpYXRvci5yb290c2lkLmNsb3VkIiwiYSI6WyJkaWRjb21tL3YyIl19fQ" ); const secret = did.toString(); + vi.spyOn(pluto, "getAllPeerDIDs").mockResolvedValue([]); - sandbox.stub(ctx.pluto, "getAllPeerDIDs").resolves([]); - - const result = await ctx.secretsResolver.get_secret(secret); + const result = await secretsResolver.get_secret(secret); expect(result).to.be.null; }); diff --git a/tests/plugins/anoncreds/PresentationRequest.test.ts b/tests/plugins/anoncreds/PresentationRequest.test.ts index d4a92dd85..c741ea8a0 100644 --- a/tests/plugins/anoncreds/PresentationRequest.test.ts +++ b/tests/plugins/anoncreds/PresentationRequest.test.ts @@ -228,7 +228,7 @@ describe("Plugins - Anoncreds", () => { const sut = ctx.run(new PresentationRequest({ credential, presentationRequest })); - expect(sut).rejects.toThrowError("AnoncredsError Error: Invalid structure\nCaused by: Predicate is not satisfied\n"); + await expect(sut).rejects.toThrowError("AnoncredsError Error: Invalid structure\nCaused by: Predicate is not satisfied\n"); }); test("Should Reject Creating an Anoncreds Presentation Submission using an invalid presentationDefinition", async () => { @@ -236,7 +236,7 @@ describe("Plugins - Anoncreds", () => { const sut = ctx.run(new PresentationRequest({ credential, presentationRequest: null as any })); - expect(sut).rejects.toThrowError('Invalid Presentation definition error'); + await expect(sut).rejects.toThrowError('Invalid Presentation definition error'); }); test("Should Reject Creating an Anoncreds Presentation Submission using a wrong JWT Credential", async () => { @@ -270,7 +270,7 @@ describe("Plugins - Anoncreds", () => { const sut = ctx.run(new PresentationRequest({ credential, presentationRequest })); - expect(sut).rejects.toThrowError('Required a valid Anoncreds Credential for Anoncreds Presentation submission'); + await expect(sut).rejects.toThrowError('Required a valid Anoncreds Credential for Anoncreds Presentation submission'); }); }); }); diff --git a/tests/plugins/dif/IsCredentialRevoked.test.ts b/tests/plugins/dif/IsCredentialRevoked.test.ts index 8a13fa29c..4bbe04c92 100644 --- a/tests/plugins/dif/IsCredentialRevoked.test.ts +++ b/tests/plugins/dif/IsCredentialRevoked.test.ts @@ -5,7 +5,6 @@ import * as Fixtures from "../../fixtures"; import { Apollo, JWTCredential, SDJWTCredential } from '../../../src'; import { IsCredentialRevoked } from '../../../src/plugins/internal/dif/IsCredentialRevoked'; import { Api, ApiResponse, Curve, KeyTypes } from '../../../src/domain'; -import { VerificationKeyType } from '../../../src/castor/types'; import { JWT_VC_PROPS } from '../../../src/pollux/models/JWTVerifiableCredential'; @@ -112,7 +111,7 @@ describe("Plugins - DIF", () => { const credential = SDJWTCredential.fromJWS(Fixtures.Credentials.SDJWT.credentialPayloadEncoded); const sut = ctx.run(new IsCredentialRevoked({ credential: credential as any })); - expect(sut).rejects.toThrowError(`Only JWT Credential are supported`); + await expect(sut).rejects.toThrowError(`Only JWT Credential are supported`); }); //* @@ -151,7 +150,7 @@ describe("Plugins - DIF", () => { const sut = ctx.run(new IsCredentialRevoked({ credential: credential as any })); - expect(sut).rejects.toThrowError(`CredentialStatus revocation type not supported`); + await expect(sut).rejects.toThrowError(`CredentialStatus revocation type not supported`); }); it("Should throw an error if the credential status proof contains an invalid verificationMethod", async () => { @@ -185,7 +184,6 @@ describe("Plugins - DIF", () => { const sut = ctx.run(new IsCredentialRevoked({ credential })); await expect(sut).rejects.toThrowError(`CredentialStatus proof invalid verificationMethod`); - }); it("should throw an error if no jwk is provided", async () => { @@ -288,7 +286,6 @@ describe("Plugins - DIF", () => { const sut = ctx.run(new IsCredentialRevoked({ credential })); await expect(sut).rejects.toThrowError("Err Invalid JWK kty: undefined, should be EC"); - }); it("Should throw an error if a wrong key curve is used", async () => { diff --git a/tests/plugins/oea/sdjwt/PresentationRequest.test.ts b/tests/plugins/oea/sdjwt/PresentationRequest.test.ts index d75bd2d09..7f032f8b1 100644 --- a/tests/plugins/oea/sdjwt/PresentationRequest.test.ts +++ b/tests/plugins/oea/sdjwt/PresentationRequest.test.ts @@ -53,7 +53,7 @@ describe("Plugins - OEA", () => { const sut = ctx.run(new PresentationRequest({ credential, presentationRequest })); - expect(sut).rejects.toThrowError(CannotFindDIDPrivateKey); + await expect(sut).rejects.toThrowError(CannotFindDIDPrivateKey); }); test("Ed25519 privateKey not found - throws", async () => { @@ -63,7 +63,7 @@ describe("Plugins - OEA", () => { const sut = ctx.run(new PresentationRequest({ credential, presentationRequest })); - expect(sut).rejects.toThrowError(CannotFindDIDPrivateKey); + await expect(sut).rejects.toThrowError(CannotFindDIDPrivateKey); }); }); }); diff --git a/tests/pluto/Pluto.Backup.test.ts b/tests/pluto/Pluto.Backup.test.ts index b5f19e623..b517b6d46 100644 --- a/tests/pluto/Pluto.Backup.test.ts +++ b/tests/pluto/Pluto.Backup.test.ts @@ -1,9 +1,4 @@ -import { describe, it, expect, test, beforeEach } from 'vitest'; - -import chai from "chai"; -import chaiAsPromised from "chai-as-promised"; -chai.use(chaiAsPromised); - +import { describe, it, expect, test, beforeEach, afterEach, vi } from 'vitest'; import * as Domain from "../../src/domain"; import * as Fixtures from "../fixtures"; import { mockPluto } from "../fixtures/inmemory/factory"; @@ -19,6 +14,10 @@ describe("Pluto", () => { await instance.start(); }); + afterEach(async () => { + vi.restoreAllMocks(); + }); + Fixtures.Backup.backups.forEach(backupFixture => { const version = backupFixture.json.version; @@ -137,7 +136,7 @@ describe("Pluto", () => { messages: [], link_secret: undefined, }); - + const result = await instance.getAllCredentials(); expect(result).to.be.an("array").to.have.length(1); const sut = result[0] as JWTCredential; @@ -160,7 +159,7 @@ describe("Pluto", () => { expect(sut.termsOfUse).to.deep.eq(Fixtures.Backup.credentialJWT.termsOfUse); expect(sut.type).to.deep.eq(Fixtures.Backup.credentialJWT.type); }); - + test("credentials - Anoncreds", async () => { await instance.restore({ credentials: [ @@ -176,7 +175,7 @@ describe("Pluto", () => { messages: [], link_secret: undefined, }); - + const result = await instance.getAllCredentials(); expect(result).to.be.an("array").to.have.length(1); const sut = result[0] as AnonCredsCredential; @@ -190,7 +189,7 @@ describe("Pluto", () => { expect(sut.schemaId).to.eq(Fixtures.Backup.credentialAnoncreds.schemaId); expect(sut.subject).to.eq(Fixtures.Backup.credentialAnoncreds.subject); }); - + test("dids", async () => { await instance.restore({ credentials: [], @@ -203,13 +202,13 @@ describe("Pluto", () => { messages: [], link_secret: undefined, }); - + const result = await (instance as any).Repositories.DIDs.get(); - + expect(result).to.be.an("array").to.have.length(1); expect(result[0].toString()).to.eq(Fixtures.Backup.hostDID.toString()); }); - + test("did_pairs", async () => { const name = "test-did-pairs"; await instance.restore({ @@ -227,15 +226,15 @@ describe("Pluto", () => { messages: [], link_secret: undefined, }); - + const result = await instance.getAllDidPairs(); - + expect(result).to.be.an("array").to.have.length(1); expect(result[0].host.toString()).to.eq(Fixtures.Backup.hostDID.toString()); expect(result[0].receiver.toString()).to.eq(Fixtures.Backup.targetDID.toString()); expect(result[0].name).to.eq(name); }); - + test("keys", async () => { await instance.restore({ credentials: [], @@ -251,9 +250,9 @@ describe("Pluto", () => { messages: [], link_secret: undefined, }); - + const result = await (instance as any).Repositories.Keys.get(); - + expect(result).to.be.an("array").to.have.length(1); expect(result[0].curve).to.eq(Fixtures.Backup.secpPrivateKey.curve); expect(result[0].index).to.eq(Fixtures.Backup.secpPrivateKey.index); @@ -276,9 +275,9 @@ describe("Pluto", () => { ], link_secret: undefined, }); - + const result = await instance.getAllMessages(); - + expect(result).to.be.an("array").to.have.length(1); const msg = result.at(0)!; expect(msg.ack).to.deep.eq(Fixtures.Backup.message.ack); @@ -310,70 +309,70 @@ describe("Pluto", () => { messages: [], link_secret: secret, }); - + const result = await instance.getLinkSecret(); - + expect(result).to.be.instanceOf(Domain.LinkSecret); expect(result?.secret).to.eq(secret); }); } - + describe("Store not empty - throws", () => { it("Credentials", async () => { await instance.storeCredential(Fixtures.Backup.credentialJWT); - expect(instance.restore(backupFixture.json)).eventually.rejected; + await expect(instance.restore(backupFixture.json)).rejects.toThrow(); }); - + it("DIDs", async () => { await instance.storeDIDPair(Fixtures.Backup.hostDID, Fixtures.Backup.targetDID, Fixtures.Backup.pairAlias); - expect(instance.restore(backupFixture.json)).eventually.rejected; + await expect(instance.restore(backupFixture.json)).rejects.toThrow(); }); - + it("Keys", async () => { await instance.storeDID(Fixtures.Backup.hostDID, Fixtures.Backup.peerDIDKeys); - expect(instance.restore(backupFixture.json)).eventually.rejected; + await expect(instance.restore(backupFixture.json)).rejects.toThrow(); }); - + if (version == "0.0.1") { it("LinkSecret", async () => { await instance.storeLinkSecret(Fixtures.Backup.linkSecret); - expect(instance.restore(backupFixture.json)).eventually.rejected; + await expect(instance.restore(backupFixture.json)).rejects.toThrow(); }); - + it("Messages", async () => { await instance.storeMessage(Fixtures.Backup.message); - expect(instance.restore(backupFixture.json)).eventually.rejected; + await expect(instance.restore(backupFixture.json)).rejects.toThrow(); }); } }); }); - + describe(`Round trip ${backupFixture.title}`, () => { test("Restore -> Backup", async () => { await instance.restore(backupFixture.json); - + const backup = await instance.backup(version); - + expect(backup.credentials).to.have.length(backupFixture.json.credentials.length); expect(backup.credentials).to.have.deep.members(backupFixture.json.credentials); - + expect(backup.dids).to.have.length(backupFixture.json.dids.length); expect(backup.dids).to.have.deep.members(backupFixture.json.dids); - + expect(backup.did_pairs).to.have.length(backupFixture.json.did_pairs.length); expect(backup.did_pairs).to.have.deep.members(backupFixture.json.did_pairs); - + expect(backup.keys).to.have.length(backupFixture.json.keys.length); expect(backup.keys).to.have.deep.members(backupFixture.json.keys); - + if (backup.version == "0.0.1" && backupFixture.json.version == "0.0.1") { expect(backup.messages).to.have.length(backupFixture.json.messages.length); expect(backup.messages).to.have.deep.members(backupFixture.json.messages); expect(backup.link_secret).to.eq(backupFixture.json.link_secret); } - + }); - + test("Backup -> Restore", async () => { await instance.storeCredential(Fixtures.Backup.credentialJWT); await instance.storeCredential(Fixtures.Backup.credentialAnoncreds); @@ -384,15 +383,15 @@ describe("Pluto", () => { await instance.storeMessage(Fixtures.Backup.message); await instance.storeMediator(Fixtures.Backup.mediator); } - + const backup = await instance.backup(version); - + expect(backup).not.to.be.null; - + const sut = mockPluto(); await sut.start(); await sut.restore(backup); - + const credentials = await sut.getAllCredentials(); const dids = await sut.getAllPeerDIDs(); const didPairs = await sut.getAllDidPairs(); @@ -400,12 +399,12 @@ describe("Pluto", () => { const mediators = await sut.getAllMediators(); const messages = await sut.getAllMessages(); const linksecret = await sut.getLinkSecret(); - + expect(dids).not.to.be.null; - + expect(credentials).to.have.length(2); // expect(credentials.map(x => (x as any).toStorable())).to.have.deep.members([Fixtures.Backup.credentialAnoncreds.toStorable(), Fixtures.Backup.credentialJWT.toStorable()]); - + expect(dids).to.have.length(2); expect(didPairs).to.have.length(1); expect(keys).to.have.length(1); @@ -413,7 +412,7 @@ describe("Pluto", () => { expect(mediators).to.have.length(1); expect(messages).to.have.length(1); } - + }); }); diff --git a/tests/pollux/Pollux.revocation.test.ts b/tests/pollux/Pollux.revocation.test.ts index 403c5a461..40ea1c4ea 100644 --- a/tests/pollux/Pollux.revocation.test.ts +++ b/tests/pollux/Pollux.revocation.test.ts @@ -1,26 +1,15 @@ -import { vi, describe, it, beforeEach, afterEach } from 'vitest'; -import { expect } from 'chai'; - +import { vi, describe, expect, it, beforeEach, afterEach } from 'vitest'; import { Api, ApiResponse, Curve, KeyTypes } from "../../src/domain"; import { JWTCredential, JWT_VC_PROPS } from "../../src/pollux/models/JWTVerifiableCredential"; import Apollo from "../../src/apollo/Apollo"; import { base64 } from "multiformats/bases/base64"; -import { VerificationKeyType } from "../../src/castor/types"; import * as Fixtures from "../fixtures"; import { SDJWTCredential } from "../../src/pollux/models/SDJWTVerifiableCredential"; import DIFPlugin from "../../src/plugins/internal/dif"; - -import SinonChai from "sinon-chai"; - -import chai from "chai"; -import chaiAsPromised from "chai-as-promised"; -import { Agent } from '../../src'; import { Task } from '../../src/utils'; import { RunProtocol } from '../../src/edge-agent/helpers/RunProtocol'; import { PluginManager } from '../../src/plugins'; -chai.use(SinonChai); -chai.use(chaiAsPromised); const revocableJWTCredential = `eyJhbGciOiJFUzI1NksifQ.eyJpc3MiOiJkaWQ6cHJpc206YmM5ZGFhZWFmMGFkNjczZjVkNTViM2I2NjEyYTE2NTNiYzcyYWMxNjU5Y2VmYTgxYzZlZWY0NWMxZjcyMTYzOTpDcmtCQ3JZQkVqb0tCbUYxZEdndE1SQUVTaTRLQ1hObFkzQXlOVFpyTVJJaEFqRDNnM3ctcHNnRXZQcUJxUDJmVjhPQXAwQ0l3WjVYU3FhMU9OWU1HOGRQRWpzS0IybHpjM1ZsTFRFUUFrb3VDZ2x6WldOd01qVTJhekVTSVFQRGNPbm9BV25YODBhZnA2aVVEZUl6ZUViMXMySFVPUEo5TEpRRTd1RzdYeEk3Q2dkdFlYTjBaWEl3RUFGS0xnb0pjMlZqY0RJMU5tc3hFaUVDc3luYTRsbkw3anhfSnctTXUtUjd3UUppSnhCNGpnMWUwODN1Q252amNhSSIsInN1YiI6ImRpZDpwcmlzbTozZjBiNDQ5NjI3NmI3NGEzMTU3ZmRiOTEwODU5MDExYjhjZWQwNjU1ZGYyNWU3ZjgwNTAyZjE0OGU2NmM1NGU4OkN0OEJDdHdCRW5RS0gyRjFkR2hsYm5ScFkyRjBhVzl1WVhWMGFHVnVkR2xqWVhScGIyNUxaWGtRQkVKUENnbHpaV053TWpVMmF6RVNJS0ZpZjRlcnNMOFF2SFF2VmxXUEFNaHFPNmwzbXZSbUp5ZlRFRTYzZzI2MEdpRG9PNS1KRzR3Z1JkZk1LcXlqZnp2ek9sSXRsNDNsdDQ0Z21TMWxtaFpKZUJKa0NnOXRZWE4wWlhKdFlYTjBaWEpMWlhrUUFVSlBDZ2x6WldOd01qVTJhekVTSUtGaWY0ZXJzTDhRdkhRdlZsV1BBTWhxTzZsM212Um1KeWZURUU2M2cyNjBHaURvTzUtSkc0d2dSZGZNS3F5amZ6dnpPbEl0bDQzbHQ0NGdtUzFsbWhaSmVBIiwibmJmIjoxNzE1MDA2OTY4LCJ2YyI6eyJjcmVkZW50aWFsU3ViamVjdCI6eyJlbWFpbEFkZHJlc3MiOiJjb3Jwb3JhdGVAZG9tYWluLmNvbSIsImRyaXZpbmdDbGFzcyI6MSwiZHJpdmluZ0xpY2Vuc2VJRCI6IkVTLTEyMzQ1Njc4OTAiLCJpZCI6ImRpZDpwcmlzbTozZjBiNDQ5NjI3NmI3NGEzMTU3ZmRiOTEwODU5MDExYjhjZWQwNjU1ZGYyNWU3ZjgwNTAyZjE0OGU2NmM1NGU4OkN0OEJDdHdCRW5RS0gyRjFkR2hsYm5ScFkyRjBhVzl1WVhWMGFHVnVkR2xqWVhScGIyNUxaWGtRQkVKUENnbHpaV053TWpVMmF6RVNJS0ZpZjRlcnNMOFF2SFF2VmxXUEFNaHFPNmwzbXZSbUp5ZlRFRTYzZzI2MEdpRG9PNS1KRzR3Z1JkZk1LcXlqZnp2ek9sSXRsNDNsdDQ0Z21TMWxtaFpKZUJKa0NnOXRZWE4wWlhKdFlYTjBaWEpMWlhrUUFVSlBDZ2x6WldOd01qVTJhekVTSUtGaWY0ZXJzTDhRdkhRdlZsV1BBTWhxTzZsM212Um1KeWZURUU2M2cyNjBHaURvTzUtSkc0d2dSZGZNS3F5amZ6dnpPbEl0bDQzbHQ0NGdtUzFsbWhaSmVBIiwiZGF0ZU9mSXNzdWFuY2UiOiIyMDIzLTAxLTAxVDAyOjAyOjAyWiJ9LCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIl0sIkBjb250ZXh0IjpbImh0dHBzOlwvXC93d3cudzMub3JnXC8yMDE4XC9jcmVkZW50aWFsc1wvdjEiXSwiY3JlZGVudGlhbFN0YXR1cyI6eyJzdGF0dXNQdXJwb3NlIjoiUmV2b2NhdGlvbiIsInN0YXR1c0xpc3RJbmRleCI6MSwiaWQiOiJodHRwOlwvXC8xOTIuMTY4LjE1NC4yMDU6ODAwMFwvcHJpc20tYWdlbnRcL2NyZWRlbnRpYWwtc3RhdHVzXC8xYzE1Yjk2My1kYzRkLTQ3NjUtYjc1Mi01M2EzZmQxZjE4MzMjMSIsInR5cGUiOiJTdGF0dXNMaXN0MjAyMUVudHJ5Iiwic3RhdHVzTGlzdENyZWRlbnRpYWwiOiJodHRwOlwvXC8xOTIuMTY4LjE1NC4yMDU6ODAwMFwvcHJpc20tYWdlbnRcL2NyZWRlbnRpYWwtc3RhdHVzXC8xYzE1Yjk2My1kYzRkLTQ3NjUtYjc1Mi01M2EzZmQxZjE4MzMifX19.NxuJoiEgSnGs7suM5cxDq3tZ6ZYVDAscnKBuAXghW0KD9MhSr1vBUo9F6y0YkjhHBY4Y_gTGnIMBwgLYjcNVKw`; vi.mock("pako"); @@ -153,7 +142,7 @@ describe("Pollux", () => { data: { credential } })); - await expect(sut).to.eventually.rejectedWith(`Only JWT Credential are supported`); + await expect(sut).rejects.toThrow(`Only JWT Credential are supported`); }); it("Should throw an error if we try to use a credential which an unsupported type ", async () => { @@ -197,7 +186,7 @@ describe("Pollux", () => { data: { credential } })); - await expect(sut).to.eventually.rejectedWith(`CredentialStatus revocation type not supported`); + await expect(sut).rejects.toThrow(`CredentialStatus revocation type not supported`); const sut2 = testCtx.run(new RunProtocol({ type: "revocation-check", @@ -205,7 +194,7 @@ describe("Pollux", () => { data: { credential: JWTCredential.fromJWS(revocableJWTCredential) } })); - await expect(sut2).to.eventually.rejectedWith(`CredentialStatus response revocation type not supported`); + await expect(sut2).rejects.toThrow(`CredentialStatus response revocation type not supported`); }); it("Should throw an error if the credential status proof contains an invalid verificationMethod", async () => { @@ -245,7 +234,7 @@ describe("Pollux", () => { })); await expect(sut) - .to.eventually.rejectedWith(`CredentialStatus proof invalid verificationMethod`); + .rejects.toThrow(`CredentialStatus proof invalid verificationMethod`); }); @@ -286,7 +275,7 @@ describe("Pollux", () => { })); await expect(sut) - .to.eventually.rejectedWith("No public jwk provided"); + .rejects.toThrow("No public jwk provided"); }); it("should throw an eror if a wrong verificationMethod type is used", async () => { @@ -326,7 +315,7 @@ describe("Pollux", () => { })); await expect(sut) - .to.eventually.rejectedWith("Err Only EcdsaSecp256k1VerificationKey2019 is supported"); + .rejects.toThrow("Err Only EcdsaSecp256k1VerificationKey2019 is supported"); }); @@ -368,7 +357,7 @@ describe("Pollux", () => { })); await expect(sut) - .to.eventually.rejectedWith("Err Invalid JWK kty: undefined, should be EC"); + .rejects.toThrow("Err Invalid JWK kty: undefined, should be EC"); }); @@ -409,7 +398,7 @@ describe("Pollux", () => { })); await expect(sut) - .to.eventually.rejectedWith("Err Invalid JWK crv: undefined, should be secp256k1"); + .rejects.toThrow("Err Invalid JWK crv: undefined, should be secp256k1"); }); it("Should throw an eror if an invalid verificationKey is used", async () => { @@ -454,7 +443,7 @@ describe("Pollux", () => { })); await expect(sut) - .to.eventually.rejectedWith("CredentialStatus proof invalid verifying key"); + .rejects.toThrow("CredentialStatus proof invalid verifying key"); }); it("Should throw an error if the status jwt is invalid", async () => { @@ -495,7 +484,7 @@ describe("Pollux", () => { })); await expect(sut) - .to.eventually.rejectedWith("Credential status jwt is invalid"); + .rejects.toThrow("Credential status jwt is invalid"); }); it("should throw an error if wrong signature is used", async () => { @@ -554,7 +543,7 @@ describe("Pollux", () => { })); await expect(sut) - .to.eventually.rejectedWith("CredentialStatus invalid signature"); + .rejects.toThrow("CredentialStatus invalid signature"); }); it("Should throw an error if we cannot decode the revocation registry correctly ", async () => { @@ -603,7 +592,7 @@ describe("Pollux", () => { })); await expect(sut) - .to.eventually.rejectedWith(`Couldn't ungzip base64 encoded list, err: whatever`); + .rejects.toThrow(`Couldn't ungzip base64 encoded list, err: whatever`); }); @@ -644,6 +633,6 @@ describe("Pollux", () => { })); await expect(sut) - .to.eventually.rejectedWith("CredentialStatus proof type not supported"); + .rejects.toThrow("CredentialStatus proof type not supported"); }); });