Skip to content

Commit 97cda1d

Browse files
mtp onchain test for balance cred req
1 parent aa13e0d commit 97cda1d

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

tests/handlers/contract-request.test.ts

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import { expect } from 'chai';
5555
import { CredentialStatusResolverRegistry } from '../../src/credentials';
5656
import { RHSResolver } from '../../src/credentials';
5757
import { ethers, JsonRpcProvider, Signer } from 'ethers';
58-
import { RPC_URL } from '../helpers';
58+
import { RHS_URL, RPC_URL } from '../helpers';
5959

6060
describe('contract-request', () => {
6161
let idWallet: IdentityWallet;
@@ -306,7 +306,7 @@ describe('contract-request', () => {
306306
});
307307

308308
// SKIPPED : integration test
309-
it.skip('contract request flow - integration test', async () => {
309+
it.only('contract request flow - integration test', async () => {
310310
const stateEthConfig = defaultEthConnectionConfig;
311311
stateEthConfig.url = rpcUrl;
312312
stateEthConfig.contractAddress = '0x1a4cC30f2aA0377b0c3bc9848766D90cb4404124';
@@ -373,12 +373,12 @@ describe('contract-request', () => {
373373

374374
const claimReq: CredentialRequest = {
375375
credentialSchema:
376-
'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/KYCAgeCredential-v3.json',
377-
type: 'KYCAgeCredential',
376+
'https://gist.githubusercontent.com/ilya-korotya/e10cd79a8cc26ab6e40400a11838617e/raw/575edc33d485e2a4c806baad97e21117f3c90a9f/non-merklized-non-zero-balance.json',
377+
type: 'Balance',
378378
credentialSubject: {
379379
id: userDID.string(),
380-
birthday: 19960424,
381-
documentType: 99
380+
address: '0x12323',
381+
balance: '3'
382382
},
383383
expiration: 2793526400,
384384
revocationOpts: {
@@ -388,26 +388,48 @@ describe('contract-request', () => {
388388
};
389389
const issuerCred = await idWallet.issueCredential(issuerDID, claimReq);
390390

391+
391392
await credWallet.save(issuerCred);
392393

394+
const res = await idWallet.addCredentialsToMerkleTree([issuerCred], issuerDID);
395+
await idWallet.publishStateToRHS(issuerDID, RHS_URL);
396+
397+
const ethSigner = new ethers.Wallet(walletKey, dataStorage.states.getRpcProvider());
398+
399+
const txId = await proofService.transitState(
400+
issuerDID,
401+
res.oldTreeState,
402+
true,
403+
dataStorage.states,
404+
ethSigner
405+
);
406+
407+
const credsWithIden3MTPProof = await idWallet.generateIden3SparseMerkleTreeProof(
408+
issuerDID,
409+
res.credentials,
410+
txId
411+
);
412+
413+
await credWallet.saveAll(credsWithIden3MTPProof);
414+
393415
const proofReq: ZeroKnowledgeProofRequest = {
394-
id: 200,
395-
circuitId: CircuitId.AtomicQuerySigV2OnChain,
416+
id: 2,
417+
circuitId: CircuitId.AtomicQueryMTPV2OnChain,
396418
optional: false,
397419
query: {
398420
allowedIssuers: ['*'],
399421
type: claimReq.type,
400422
context:
401-
'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json-ld/kyc-v3.json-ld',
423+
'https://gist.githubusercontent.com/ilya-korotya/660496c859f8d31a7d2a92ca5e970967/raw/6b5fc14fe630c17bfa52e05e08fdc8394c5ea0ce/non-merklized-non-zero-balance.jsonld',
402424
credentialSubject: {
403-
birthday: {
404-
$lt: 20020101
425+
balance: {
426+
$gt: 1
405427
}
406428
}
407429
}
408430
};
409431

410-
const contractAddress = '0x2b23e5cF70D133fFaA7D8ba61E1bAC4637253880';
432+
const contractAddress = '0xf702DB17F987ed751f360b3A54F5d9dEFE2B06F9';
411433
const conf = defaultEthConnectionConfig;
412434
conf.contractAddress = contractAddress;
413435
conf.url = rpcUrl;
@@ -437,7 +459,6 @@ describe('contract-request', () => {
437459
body: ciRequestBody
438460
};
439461

440-
const ethSigner = new ethers.Wallet(walletKey);
441462

442463
const challenge = BytesHelper.bytesToInt(hexToBytes(ethSigner.address));
443464

0 commit comments

Comments
 (0)