Skip to content

Commit

Permalink
format and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Oct 28, 2024
1 parent f5d820d commit 3289c5e
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/proof/provers/inputs-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] },
Expand Down
96 changes: 96 additions & 0 deletions tests/handlers/contract-request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,102 @@ describe('contract-request', () => {
expect((ciResponse as Map<string, ZeroKnowledgeProofResponse>).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;
Expand Down

0 comments on commit 3289c5e

Please sign in to comment.