From 15cd0167c4dcd3d9b8a8ed7d930e127b66a17b7c Mon Sep 17 00:00:00 2001 From: 0xverin <104152026+0xverin@users.noreply.github.com> Date: Thu, 12 Sep 2024 02:47:53 +0800 Subject: [PATCH] Fixing vc correctness after zombienet merged (#3062) * Launch parachain network * remove litentry-parachain.build.yml * fix request issues on tee-dev * update accounts * fix solana * fix solana one more * update polkadot-governance-participation * fix dc&&achainable * uncomment * fix one more * add eventsPromise * fmt * remove event listening --- .../verify-correctness-of-vc-content.yml | 9 +-- .../common/credential-json/achainable.json | 10 +-- .../common/credential-json/discord.json | 8 +-- .../common/credential-json/moralis.json | 2 +- .../common/credential-json/nodereal.json | 4 +- .../integration-tests/vc_correctness.test.ts | 66 ++++++++++++------- 6 files changed, 57 insertions(+), 42 deletions(-) diff --git a/.github/workflows/verify-correctness-of-vc-content.yml b/.github/workflows/verify-correctness-of-vc-content.yml index 5780606830..f39c35fcbd 100644 --- a/.github/workflows/verify-correctness-of-vc-content.yml +++ b/.github/workflows/verify-correctness-of-vc-content.yml @@ -36,14 +36,9 @@ jobs: - name: Enable corepack and pnpm run: corepack enable && corepack enable pnpm - - name: Generate parachain artefacts + - name: Launch parachain network run: | - ./tee-worker/scripts/litentry/generate_parachain_artefacts.sh - - - name: Build litentry parachain docker images - run: | - cd tee-worker/docker - docker compose -f litentry-parachain.build.yml build + make launch-network-litentry - name: Run vc correctness tests run: | diff --git a/tee-worker/ts-tests/integration-tests/common/credential-json/achainable.json b/tee-worker/ts-tests/integration-tests/common/credential-json/achainable.json index f6a78dfe07..b3907e5e3d 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-json/achainable.json +++ b/tee-worker/ts-tests/integration-tests/common/credential-json/achainable.json @@ -150,7 +150,7 @@ }, "dataProvider": "achainable", "network": "litentry", - "mockDid": "litentry:substrate:0x5FeEE1E799015A22EbD216d43484FCB3BA88de20", + "mockDid": "litentry:substrate:0x00f160c0e8fff2d4f00ab03e18dced9f2ac52a6b865cda497a33aee5b3fe335b", "mockWeb3Network": "litentry,polkadot", "expectedCredentialValue": true }, @@ -163,7 +163,7 @@ "payload": { "Amount": { "name": "Created over {amount} contracts", - "chain": "Ethereum", + "chain": ["Ethereum"], "amount": "0" } } @@ -183,7 +183,7 @@ "payload": { "Amount": { "name": "Balance over {amount}", - "chain": "Polkadot", + "chain": ["Polkadot"], "amount": "0" } } @@ -203,7 +203,7 @@ "payload": { "Amount": { "name": "Balance over {amount}", - "chain": "Ethereum", + "chain": ["Ethereum"], "amount": "0" } } @@ -223,7 +223,7 @@ "payload": { "Amount": { "name": "Balance over {amount}", - "chain": "Litentry", + "chain": ["Litentry"], "amount": "0" } } diff --git a/tee-worker/ts-tests/integration-tests/common/credential-json/discord.json b/tee-worker/ts-tests/integration-tests/common/credential-json/discord.json index 3f3f28c2f4..54f7a396a6 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-json/discord.json +++ b/tee-worker/ts-tests/integration-tests/common/credential-json/discord.json @@ -34,7 +34,7 @@ "assertion": { "id": "GenericDiscordRole", "payload": { - "soraquiz": "attendee" + "soraquiz": "Attendee" } }, "dataProvider": "discord", @@ -66,7 +66,7 @@ "assertion": { "id": "GenericDiscordRole", "payload": { - "soraquiz": "legend" + "contest": "legend" } }, "dataProvider": "discord", @@ -82,7 +82,7 @@ "assertion": { "id": "GenericDiscordRole", "payload": { - "soraquiz": "popularity" + "contest": "popularity" } }, "dataProvider": "discord", @@ -98,7 +98,7 @@ "assertion": { "id": "GenericDiscordRole", "payload": { - "soraquiz": "participant" + "contest": "participant" } }, "dataProvider": "discord", diff --git a/tee-worker/ts-tests/integration-tests/common/credential-json/moralis.json b/tee-worker/ts-tests/integration-tests/common/credential-json/moralis.json index f38e9816c5..27a6ac07bc 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-json/moralis.json +++ b/tee-worker/ts-tests/integration-tests/common/credential-json/moralis.json @@ -9,7 +9,7 @@ }, "dataProvider": "moralis", "network": "solana", - "mockDid": "litentry:solana:09b36de0a9862cdbfe3eb023959e97e816e17d846a5762b3c1bfe7b75490c23b", + "mockDid": "litentry:solana:6xJ8xjUu6rY7kQS4kJodG4NcNgMtubUXGbhdBb7gqJMn", "mockWeb3Network": "solana", "expectedCredentialValue": true } diff --git a/tee-worker/ts-tests/integration-tests/common/credential-json/nodereal.json b/tee-worker/ts-tests/integration-tests/common/credential-json/nodereal.json index 0c99a8094a..1f7364b4cb 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-json/nodereal.json +++ b/tee-worker/ts-tests/integration-tests/common/credential-json/nodereal.json @@ -10,7 +10,7 @@ }, "dataProvider": "nodereal", "network": "ethereum", - "mockDid": "litentry:evm:0x6A9c371dB67992444cA55D32eA4219dd264b8DD3", + "mockDid": "litentry:evm:0x5a973F455898c0A6C812F6A4bBc6678810dd5838", "mockWeb3Network": "bsc,ethereum", "expectedCredentialValue": true }, @@ -24,7 +24,7 @@ }, "dataProvider": "nodereal", "network": "ethereum", - "mockDid": "litentry:evm:0x10EF5b7309Bdc639fbE9597EB87a34b27ecDAF0f", + "mockDid": "litentry:evm:0x3bb6849153105C0c4d8D068E7Cb1C365b9b20eB8", "mockWeb3Network": "bsc,ethereum", "expectedCredentialValue": true }, diff --git a/tee-worker/ts-tests/integration-tests/vc_correctness.test.ts b/tee-worker/ts-tests/integration-tests/vc_correctness.test.ts index 1eaf33bd47..f8f96af1b4 100644 --- a/tee-worker/ts-tests/integration-tests/vc_correctness.test.ts +++ b/tee-worker/ts-tests/integration-tests/vc_correctness.test.ts @@ -3,23 +3,25 @@ import { step } from 'mocha-steps'; import { assert } from 'chai'; import { decryptWithAes, initIntegrationTestContext, PolkadotSigner } from './common/utils'; import { randomSubstrateWallet } from './common/helpers'; -import { assertIsInSidechainBlock } from './common/utils/assertion'; +import { assertIsInSidechainBlock, assertVc } from './common/utils/assertion'; import { getSidechainNonce, getTeeShieldingKey, sendRequestFromTrustedCall, createSignedTrustedCallRequestVc, + createSignedTrustedGetterIdGraph, + sendAesRequestFromGetter, + decodeIdGraph, } from './common/di-utils'; // @fixme move to a better place import type { IntegrationTestContext } from './common/common-types'; -import { CorePrimitivesIdentity } from 'parachain-api'; +import { CorePrimitivesIdentity, WorkerRpcReturnValue } from 'parachain-api'; import { aesKey } from './common/call'; import { $ as zx } from 'zx'; -import { subscribeToEventsWithExtHash } from './common/transactions'; import { KeyringPair } from '@polkadot/keyring/types'; -import { u8aToHex } from '@polkadot/util'; +import { hexToU8a, u8aToHex } from '@polkadot/util'; import { CredentialDefinition, credentialsJson } from './common/credential-json'; import { byId } from '@litentry/chaindata'; - +import { sleep } from './common/utils'; // Change this to the environment you want to test const chain = byId['litentry-dev']; @@ -29,7 +31,7 @@ describe('Test Vc (direct invocation)', function () { const substrateIdentities: CorePrimitivesIdentity[] = []; const clientDir = process.env.LITENTRY_CLI_DIR; - const reqExtHash = '0x0000000000000000000000000000000000000000000000000000000000000000'; + const keyringPairs: KeyringPair[] = []; let argvId = ''; @@ -64,7 +66,7 @@ describe('Test Vc (direct invocation)', function () { const formatAddress = u8aToHex(keyringPair.publicKey); const substrateIdentity = await new PolkadotSigner(keyringPair).getIdentity(context); substrateIdentities.push(substrateIdentity); - const eventsPromise = subscribeToEventsWithExtHash(reqExtHash, context); + try { // CLIENT = "$CLIENT_BIN -p $NPORT -P $WORKER1PORT -u $NODEURL -U $WORKER1URL" const commandPromise = zx`${clientDir} -p ${teeDevNodePort} -P ${teeDevWorkerPort} -u ${ @@ -75,14 +77,23 @@ describe('Test Vc (direct invocation)', function () { ${credentialDefinitions.mockWeb3Network}`; await commandPromise; + + const idGraphGetter = await createSignedTrustedGetterIdGraph( + context.api, + new PolkadotSigner(keyringPair), + substrateIdentity + ); + const res = await sendAesRequestFromGetter(context, teeShieldingKey, hexToU8a(aesKey), idGraphGetter); + + const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); + + assert.lengthOf(idGraph, 2, 'idGraph length should be 2'); } catch (error: any) { console.log(`Exit code: ${error.exitCode}`); console.log(`Error: ${error.stderr}`); + throw error; } - - const events = (await eventsPromise).map(({ event }) => event); - assert.equal(events.length, 1); } async function requestVc(id: string, index: number) { @@ -110,19 +121,26 @@ describe('Test Vc (direct invocation)', function () { context.api.createType('Option', aesKey).toHex(), requestIdentifier ); - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, requestVcCall); - await assertIsInSidechainBlock(`${Object.keys(assertion)[0]} requestVcCall`, res); - - const vcResults = context.api.createType('RequestVCResult', res.value); - const decryptVcPayload = decryptWithAes(aesKey, vcResults.vc_payload, 'utf-8').replace('0x', ''); - const vcPayloadJson = JSON.parse(decryptVcPayload); - console.log('vcPayload: ', vcPayloadJson); - - assert.equal( - vcPayloadJson.credentialSubject.values[0], - credentialDefinitions.expectedCredentialValue, - "credential value doesn't match, please check the credential json expectedCredentialValue" + + const onMessageReceived = async (res: WorkerRpcReturnValue) => { + const vcresponse = context.api.createType('RequestVcResultOrError', res.value); + console.log(`vcresponse len: ${vcresponse.len}, idx: ${vcresponse.idx}`); + if (vcresponse.result.isOk) await assertVc(context, substrateIdentities[index], vcresponse.result.asOk); + const decryptVcPayload = decryptWithAes(aesKey, vcresponse.vc_payload, 'utf-8').replace('0x', ''); + const vcPayloadJson = JSON.parse(decryptVcPayload); + assert.equal( + vcPayloadJson.credentialSubject.values[0], + credentialDefinitions.expectedCredentialValue, + "credential value doesn't match, please check the credential json expectedCredentialValue" + ); + }; + const callResults = await sendRequestFromTrustedCall( + context, + teeShieldingKey, + requestVcCall, + onMessageReceived ); + await assertIsInSidechainBlock(`${Object.keys(assertion)[0]} requestVcCall`, callResults); } catch (error) { // Sometimes unstable dataprovider can cause interruptions in the testing process. We expect errors in the test to be stored and specific error information to be thrown out after the end. const credentialDefinitions = credentialsJson.find((item) => item.id === id) as CredentialDefinition; @@ -130,11 +148,13 @@ describe('Test Vc (direct invocation)', function () { errorArray.push({ id: id, index: index, - assertion: credentialDefinitions.assertion.payload, + assertion: JSON.stringify(credentialDefinitions.assertion), error: error, }); console.error(`Error in requestVc for id ${id} at index ${index}:`, error); } + // sometime the previous nonce change hasn't been persisted in the sidechain state while next request is already coming + await sleep(12); } if (argvId && credentialsJson.find((item) => item.id === argvId)) {