Skip to content

Commit

Permalink
Fixing vc correctness after zombienet merged (#3062)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
0xverin authored Sep 11, 2024
1 parent b1688cb commit 15cd016
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 42 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/verify-correctness-of-vc-content.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
},
"dataProvider": "achainable",
"network": "litentry",
"mockDid": "litentry:substrate:0x5FeEE1E799015A22EbD216d43484FCB3BA88de20",
"mockDid": "litentry:substrate:0x00f160c0e8fff2d4f00ab03e18dced9f2ac52a6b865cda497a33aee5b3fe335b",
"mockWeb3Network": "litentry,polkadot",
"expectedCredentialValue": true
},
Expand All @@ -163,7 +163,7 @@
"payload": {
"Amount": {
"name": "Created over {amount} contracts",
"chain": "Ethereum",
"chain": ["Ethereum"],
"amount": "0"
}
}
Expand All @@ -183,7 +183,7 @@
"payload": {
"Amount": {
"name": "Balance over {amount}",
"chain": "Polkadot",
"chain": ["Polkadot"],
"amount": "0"
}
}
Expand All @@ -203,7 +203,7 @@
"payload": {
"Amount": {
"name": "Balance over {amount}",
"chain": "Ethereum",
"chain": ["Ethereum"],
"amount": "0"
}
}
Expand All @@ -223,7 +223,7 @@
"payload": {
"Amount": {
"name": "Balance over {amount}",
"chain": "Litentry",
"chain": ["Litentry"],
"amount": "0"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"assertion": {
"id": "GenericDiscordRole",
"payload": {
"soraquiz": "attendee"
"soraquiz": "Attendee"
}
},
"dataProvider": "discord",
Expand Down Expand Up @@ -66,7 +66,7 @@
"assertion": {
"id": "GenericDiscordRole",
"payload": {
"soraquiz": "legend"
"contest": "legend"
}
},
"dataProvider": "discord",
Expand All @@ -82,7 +82,7 @@
"assertion": {
"id": "GenericDiscordRole",
"payload": {
"soraquiz": "popularity"
"contest": "popularity"
}
},
"dataProvider": "discord",
Expand All @@ -98,7 +98,7 @@
"assertion": {
"id": "GenericDiscordRole",
"payload": {
"soraquiz": "participant"
"contest": "participant"
}
},
"dataProvider": "discord",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dataProvider": "moralis",
"network": "solana",
"mockDid": "litentry:solana:09b36de0a9862cdbfe3eb023959e97e816e17d846a5762b3c1bfe7b75490c23b",
"mockDid": "litentry:solana:6xJ8xjUu6rY7kQS4kJodG4NcNgMtubUXGbhdBb7gqJMn",
"mockWeb3Network": "solana",
"expectedCredentialValue": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dataProvider": "nodereal",
"network": "ethereum",
"mockDid": "litentry:evm:0x6A9c371dB67992444cA55D32eA4219dd264b8DD3",
"mockDid": "litentry:evm:0x5a973F455898c0A6C812F6A4bBc6678810dd5838",
"mockWeb3Network": "bsc,ethereum",
"expectedCredentialValue": true
},
Expand All @@ -24,7 +24,7 @@
},
"dataProvider": "nodereal",
"network": "ethereum",
"mockDid": "litentry:evm:0x10EF5b7309Bdc639fbE9597EB87a34b27ecDAF0f",
"mockDid": "litentry:evm:0x3bb6849153105C0c4d8D068E7Cb1C365b9b20eB8",
"mockWeb3Network": "bsc,ethereum",
"expectedCredentialValue": true
},
Expand Down
66 changes: 43 additions & 23 deletions tee-worker/ts-tests/integration-tests/vc_correctness.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand All @@ -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 = '';

Expand Down Expand Up @@ -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 ${
Expand All @@ -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) {
Expand Down Expand Up @@ -110,31 +121,40 @@ describe('Test Vc (direct invocation)', function () {
context.api.createType('Option<RequestAesKey>', 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;

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)) {
Expand Down

0 comments on commit 15cd016

Please sign in to comment.