From 3289c5e05bac96ce8a399874e72c8e1ec49f4333 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Mon, 28 Oct 2024 12:43:55 +0200 Subject: [PATCH] format and unit test --- src/proof/provers/inputs-generator.ts | 10 ++- tests/handlers/contract-request.test.ts | 96 +++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 2 deletions(-) diff --git a/src/proof/provers/inputs-generator.ts b/src/proof/provers/inputs-generator.ts index 82e79a2e..d684d514 100644 --- a/src/proof/provers/inputs-generator.ts +++ b/src/proof/provers/inputs-generator.ts @@ -86,9 +86,15 @@ export const circuitValidator: { [k in CircuitId]: { maxQueriesCount: number; supportedOperations: Operators[] }; } = { [CircuitId.AtomicQueryMTPV2]: { maxQueriesCount: 1, supportedOperations: v2Operations }, - [CircuitId.AtomicQueryMTPV2OnChain]: { maxQueriesCount: 1, supportedOperations: v2OnChainOperations }, + [CircuitId.AtomicQueryMTPV2OnChain]: { + maxQueriesCount: 1, + supportedOperations: v2OnChainOperations + }, [CircuitId.AtomicQuerySigV2]: { maxQueriesCount: 1, supportedOperations: v2Operations }, - [CircuitId.AtomicQuerySigV2OnChain]: { maxQueriesCount: 1, supportedOperations: v2OnChainOperations }, + [CircuitId.AtomicQuerySigV2OnChain]: { + maxQueriesCount: 1, + supportedOperations: v2OnChainOperations + }, [CircuitId.AtomicQueryV3]: { maxQueriesCount: 1, supportedOperations: allOperations }, [CircuitId.AtomicQueryV3OnChain]: { maxQueriesCount: 1, supportedOperations: allOperations }, [CircuitId.AuthV2]: { maxQueriesCount: 0, supportedOperations: [] }, diff --git a/tests/handlers/contract-request.test.ts b/tests/handlers/contract-request.test.ts index 109da2e0..b968a2c8 100644 --- a/tests/handlers/contract-request.test.ts +++ b/tests/handlers/contract-request.test.ts @@ -321,6 +321,102 @@ describe('contract-request', () => { expect((ciResponse as Map).has('txhash1')).to.be.true; }); + it('$noop operator not supported for OnChain V2', async () => { + const { did: userDID, credential: cred } = await idWallet.createIdentity({ + method: DidMethod.Iden3, + blockchain: Blockchain.Polygon, + networkId: NetworkId.Amoy, + seed: seedPhrase, + revocationOpts: { + type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, + id: rhsUrl + } + }); + + expect(cred).not.to.be.undefined; + + const { did: issuerDID, credential: issuerAuthCredential } = await idWallet.createIdentity({ + method: DidMethod.Iden3, + blockchain: Blockchain.Polygon, + networkId: NetworkId.Amoy, + seed: seedPhraseIssuer, + revocationOpts: { + type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, + id: rhsUrl + } + }); + expect(issuerAuthCredential).not.to.be.undefined; + + const claimReq: CredentialRequest = { + credentialSchema: + 'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/KYCAgeCredential-v3.json', + type: 'KYCAgeCredential', + credentialSubject: { + id: userDID.string(), + birthday: 19960424, + documentType: 99 + }, + expiration: 2793526400, + revocationOpts: { + type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, + id: rhsUrl + } + }; + const issuerCred = await idWallet.issueCredential(issuerDID, claimReq); + + await credWallet.save(issuerCred); + + const proofReq: ZeroKnowledgeProofRequest = { + id: 1, + circuitId: CircuitId.AtomicQueryMTPV2OnChain, + optional: false, + query: { + allowedIssuers: ['*'], + type: claimReq.type, + context: + 'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json-ld/kyc-v3.json-ld' + } + }; + + const transactionData: ContractInvokeTransactionData = { + contract_address: '0x134b1be34911e39a8397ec6289782989729807a4', + method_id: 'b68967e2', + chain_id: 80001 + }; + + const ciRequestBody: ContractInvokeRequestBody = { + reason: 'reason', + transaction_data: transactionData, + scope: [proofReq as ZeroKnowledgeProofRequest] + }; + + const id = uuid.v4(); + const ciRequest: ContractInvokeRequest = { + id, + typ: MediaType.PlainMessage, + type: PROTOCOL_MESSAGE_TYPE.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE, + thid: id, + body: ciRequestBody + }; + + const ethSigner = new ethers.Wallet(walletKey); + + const options: ContractInvokeHandlerOptions = { + ethSigner, + challenge: BigInt(112312) + }; + const msgBytes = byteEncoder.encode(JSON.stringify(ciRequest)); + + try { + await contractRequestHandler.handleContractInvokeRequest(userDID, msgBytes, options); + expect.fail(); + } catch (err: unknown) { + expect((err as Error).message).to.be.eq( + `operator $noop is not supported by credentialAtomicQueryMTPV2OnChain` + ); + } + }); + // SKIPPED : integration test it.skip('contract request flow - integration test', async () => { const stateEthConfig = defaultEthConnectionConfig;