Skip to content

Commit

Permalink
Merge branch 'main' into feat/mc-payment
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Nov 18, 2024
2 parents 6d18de7 + 5108794 commit e195b0b
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 550 deletions.
577 changes: 107 additions & 470 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"homepage": "https://github.com/0xPolygonID/js-sdk#readme",
"devDependencies": {
"@cspell/eslint-plugin": "^8.14.2",
"@gr2m/fetch-mock": "9.11.0-pull-request-644.1",
"@iden3/eslint-config": "https://github.com/iden3/eslint-config",
"@microsoft/api-documenter": "^7.8.20",
"@microsoft/api-extractor": "^7.9.0",
Expand Down Expand Up @@ -80,6 +79,7 @@
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"mocha": "10.2.0",
"nock": "^14.0.0-beta.15",
"prettier": "^2.7.1",
"rimraf": "^5.0.5",
"rollup": "^4.14.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
registerKeyProvidersInMemoryKMS
} from '../../helpers';
import { DID } from '@iden3/js-iden3-core';
import fetchMock from '@gr2m/fetch-mock';
import { Proof, ZERO_HASH } from '@iden3/js-merkletree';

describe('SparseMerkleTreeProof', () => {
let idWallet: IdentityWallet;
Expand Down Expand Up @@ -51,22 +49,6 @@ describe('SparseMerkleTreeProof', () => {
});
expect(issuerAuthCredential).not.to.be.undefined;
issuerDID = didIssuer;
const mockRevStatus = JSON.stringify({
mtp: new Proof(),
issuer: {
state: ZERO_HASH.hex(),
claimsTreeRoot: ZERO_HASH.hex(),
revocationTreeRoot: ZERO_HASH.hex(),
rootOfRoots: ZERO_HASH.hex()
}
});
fetchMock.spy();
fetchMock.mock(`begin:${walletUrl}`, mockRevStatus);
fetchMock.mock(`begin:${issuerWalletUrl}`, mockRevStatus);
});

afterEach(() => {
fetchMock.restore();
});

it('issue credential', async () => {
Expand Down
93 changes: 57 additions & 36 deletions tests/credentials/credential-validation.test.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/credentials/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const credWithRefreshService = createTestCredential({
expirationDate: '2023-11-11',
issuanceDate: '2022-11-11',
refreshService: {
id: 'http://test-refresh/100',
id: 'http://test-refresh.com/refresh',
type: 'Iden3RefreshService2023'
}
});
Expand Down
14 changes: 7 additions & 7 deletions tests/handlers/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ import {

import * as uuid from 'uuid';
import { expect } from 'chai';
import fetchMock from '@gr2m/fetch-mock';
import path from 'path';
import nock from 'nock';

describe('fetch', () => {
afterEach(() => {
nock.cleanAll();
});

let idWallet: IdentityWallet;
let credWallet: CredentialWallet;

Expand Down Expand Up @@ -143,8 +147,7 @@ describe('fetch', () => {
});

it('fetch credential issued to genesis did', async () => {
fetchMock.spy();
fetchMock.post(agentUrl, JSON.parse(issuanceResponseMock));
nock(agentUrl).post('/').reply(200, issuanceResponseMock);
const { did: userDID, credential: cred } = await createIdentity(idWallet, {
seed: SEED_USER
});
Expand Down Expand Up @@ -182,7 +185,6 @@ describe('fetch', () => {
const w3cCred = W3CCredential.fromJSON(JSON.parse(issuanceResponseMock).body.credential);

expect(Object.entries(res[0]).toString()).to.equal(Object.entries(w3cCred).toString());
fetchMock.restore();
});

it('handle credential fetch and issuance requests', async () => {
Expand Down Expand Up @@ -277,9 +279,7 @@ describe('fetch', () => {
offer,
{}
);
fetchMock.restore();
fetchMock.spy();
fetchMock.post(agentUrl, issuanceResponseMock);
nock(agentUrl).post('/').reply(200, issuanceResponseMock);
expect(await credWallet.list()).to.have.length(4);

const response = await msgHandler.handleMessage(bytes, {});
Expand Down
19 changes: 10 additions & 9 deletions tests/handlers/payment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ import {
PaymentRequestTypeUnion
} from '../../src/iden3comm/types/protocol/payment';
import { Contract, ethers, JsonRpcProvider } from 'ethers';
import fetchMock from '@gr2m/fetch-mock';
import { fail } from 'assert';
import { DIDResolutionResult } from 'did-resolver';
import nock from 'nock';

describe('payment-request handler', () => {
afterEach(() => {
nock.cleanAll();
});

let packageMgr: IPackageManager;
let paymentHandler: IPaymentHandler;
let userDID, issuerDID: DID;
Expand Down Expand Up @@ -532,10 +536,6 @@ describe('payment-request handler', () => {
return Promise.resolve('0x312312334');
};

afterEach(() => {
fetchMock.restore();
});

beforeEach(async () => {
const kms = registerKeyProvidersInMemoryKMS();
const dataStorage = getInMemoryDataStorage(MOCK_STATE_STORAGE);
Expand Down Expand Up @@ -620,8 +620,8 @@ describe('payment-request handler', () => {
issuerDID = DID.parse('did:iden3:polygon:amoy:x6x5sor7zpyZX9yNpm8h1rPBDSN9idaEhDj1Qm8Q9');

agentMessageResponse = createProposal(issuerDID, userDID, []);
fetchMock.spy();
fetchMock.post('https://agent-url.com', JSON.stringify(agentMessageResponse));

nock(agent).post('/').reply(200, JSON.stringify(agentMessageResponse));
});

it('payment-request handler test (Iden3PaymentRequestCryptoV1)', async () => {
Expand Down Expand Up @@ -695,9 +695,10 @@ describe('payment-request handler', () => {
});

it('payment-request handler test with empty agent response', async () => {
fetchMock.post('https://agent-url.com', '', { overwriteRoutes: true });
const newAgent = `${agent}.ua`;
nock(newAgent).post('/').reply(200, '');

const paymentRequest = createPaymentRequest(issuerDID, userDID, agent, [
const paymentRequest = createPaymentRequest(issuerDID, userDID, newAgent, [
paymentReqCryptoV1Info
]);
const msgBytesRequest = await packageManager.pack(
Expand Down
15 changes: 7 additions & 8 deletions tests/handlers/refresh.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PackageManager, RefreshHandler } from '../../src';
import { credWithRefreshService } from '../credentials/mock';
import { initZKPPacker } from '../iden3comm/mock/proving';
import fetchMock from '@gr2m/fetch-mock';
import nock from 'nock';
import { expect } from 'chai';

describe('refresh-service', () => {
Expand All @@ -19,20 +19,19 @@ describe('refresh-service', () => {
refreshedCred.expirationDate = new Date().setMinutes(new Date().getMinutes() + 1);
const refreshedId = 'test1_refreshed';
refreshedCred.id = refreshedId;
fetchMock.spy();
fetchMock.post('http://test-refresh/100', {
body: {

nock('http://test-refresh.com')
.post('/refresh')
.reply(200, {
// CredentialIssuanceMessage
id: 'uuid',
body: {
credential: refreshedCred
}
}
});
});

const newCred = await refreshService.refreshCredential(credToRefresh, { reason: 'expired' });
fetchMock.restore();

nock.cleanAll();
expect(newCred.id).to.be.equal(refreshedId);
});
});

0 comments on commit e195b0b

Please sign in to comment.