From dfb609579e33fadea1028d271a97b3e39f90a3c8 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Mon, 15 Jan 2024 18:38:29 +0800 Subject: [PATCH 01/32] revert data-provider-tests --- .../data-provider-tests/config.example.json | 3 ++ .../data-provider-tests/index.ts | 54 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tee-worker/ts-tests/integration-tests/data-provider-tests/config.example.json create mode 100644 tee-worker/ts-tests/integration-tests/data-provider-tests/index.ts diff --git a/tee-worker/ts-tests/integration-tests/data-provider-tests/config.example.json b/tee-worker/ts-tests/integration-tests/data-provider-tests/config.example.json new file mode 100644 index 0000000000..0e5a82534a --- /dev/null +++ b/tee-worker/ts-tests/integration-tests/data-provider-tests/config.example.json @@ -0,0 +1,3 @@ +{ + "vip3":"0x12312312312312" +} \ No newline at end of file diff --git a/tee-worker/ts-tests/integration-tests/data-provider-tests/index.ts b/tee-worker/ts-tests/integration-tests/data-provider-tests/index.ts new file mode 100644 index 0000000000..4b511ec9a4 --- /dev/null +++ b/tee-worker/ts-tests/integration-tests/data-provider-tests/index.ts @@ -0,0 +1,54 @@ +import { randomBytes, KeyObject } from 'crypto'; +import { step } from 'mocha-steps'; +import { assert } from 'chai'; +import { u8aToHex, bufferToU8a } from '@polkadot/util'; +import { buildIdentityFromKeypair, initIntegrationTestContext, PolkadotSigner } from './common/utils'; +import { assertIsInSidechainBlock, assertVc } from './common/utils/assertion'; +import { + getSidechainNonce, + createSignedTrustedCallLinkIdentity, + getTeeShieldingKey, + sendRequestFromTrustedCall, + createSignedTrustedCallRequestVc, +} from './common/di-utils'; // @fixme move to a better place +import { buildIdentityHelper, buildValidations } from './common/utils'; +import type { IntegrationTestContext } from './common/common-types'; +import { aesKey } from './common/call'; +import { CorePrimitivesIdentity } from 'parachain-api'; +import { subscribeToEventsWithExtHash } from './common/transactions'; +import { defaultAssertions, unconfiguredAssertions } from './common/utils/vc-helper'; +import { LitentryValidationData, Web3Network } from 'parachain-api'; +import { Vec } from '@polkadot/types'; + +describe('Test Vc (direct invocation)', function () { + let context: IntegrationTestContext = undefined as any; + let teeShieldingKey: KeyObject = undefined as any; + let aliceSubstrateIdentity: CorePrimitivesIdentity = undefined as any; + + // Alice links: + // - a `mock_user` twitter + // - alice's evm identity + // - alice's bitcoin identity] + // + // We need this linking to not have empty eligible identities for any vc request + const linkIdentityRequestParams: { + nonce: number; + identity: CorePrimitivesIdentity; + validation: LitentryValidationData; + networks: Vec; + }[] = []; + this.timeout(6000000); + + before(async () => { + context = await initIntegrationTestContext( + process.env.WORKER_ENDPOINT!, // @fixme evil assertion; centralize env access + process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access + ); + teeShieldingKey = await getTeeShieldingKey(context); + aliceSubstrateIdentity = await buildIdentityFromKeypair( + new PolkadotSigner(context.substrateWallet.alice), + context + ); + }); + +}); From d92434132d2ee8b3b1a927dab9c61954cb490921 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Thu, 18 Jan 2024 20:14:14 +0800 Subject: [PATCH 02/32] fix CorePrimitivesIdentity imports --- .../data-provider-tests/index.ts | 54 ----------- .../data-provider-tests/vip3.test.ts | 89 +++++++++++++++++++ .../ts-tests/integration-tests/package.json | 3 +- 3 files changed, 91 insertions(+), 55 deletions(-) delete mode 100644 tee-worker/ts-tests/integration-tests/data-provider-tests/index.ts create mode 100644 tee-worker/ts-tests/integration-tests/data-provider-tests/vip3.test.ts diff --git a/tee-worker/ts-tests/integration-tests/data-provider-tests/index.ts b/tee-worker/ts-tests/integration-tests/data-provider-tests/index.ts deleted file mode 100644 index 4b511ec9a4..0000000000 --- a/tee-worker/ts-tests/integration-tests/data-provider-tests/index.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { randomBytes, KeyObject } from 'crypto'; -import { step } from 'mocha-steps'; -import { assert } from 'chai'; -import { u8aToHex, bufferToU8a } from '@polkadot/util'; -import { buildIdentityFromKeypair, initIntegrationTestContext, PolkadotSigner } from './common/utils'; -import { assertIsInSidechainBlock, assertVc } from './common/utils/assertion'; -import { - getSidechainNonce, - createSignedTrustedCallLinkIdentity, - getTeeShieldingKey, - sendRequestFromTrustedCall, - createSignedTrustedCallRequestVc, -} from './common/di-utils'; // @fixme move to a better place -import { buildIdentityHelper, buildValidations } from './common/utils'; -import type { IntegrationTestContext } from './common/common-types'; -import { aesKey } from './common/call'; -import { CorePrimitivesIdentity } from 'parachain-api'; -import { subscribeToEventsWithExtHash } from './common/transactions'; -import { defaultAssertions, unconfiguredAssertions } from './common/utils/vc-helper'; -import { LitentryValidationData, Web3Network } from 'parachain-api'; -import { Vec } from '@polkadot/types'; - -describe('Test Vc (direct invocation)', function () { - let context: IntegrationTestContext = undefined as any; - let teeShieldingKey: KeyObject = undefined as any; - let aliceSubstrateIdentity: CorePrimitivesIdentity = undefined as any; - - // Alice links: - // - a `mock_user` twitter - // - alice's evm identity - // - alice's bitcoin identity] - // - // We need this linking to not have empty eligible identities for any vc request - const linkIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - validation: LitentryValidationData; - networks: Vec; - }[] = []; - this.timeout(6000000); - - before(async () => { - context = await initIntegrationTestContext( - process.env.WORKER_ENDPOINT!, // @fixme evil assertion; centralize env access - process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access - ); - teeShieldingKey = await getTeeShieldingKey(context); - aliceSubstrateIdentity = await buildIdentityFromKeypair( - new PolkadotSigner(context.substrateWallet.alice), - context - ); - }); - -}); diff --git a/tee-worker/ts-tests/integration-tests/data-provider-tests/vip3.test.ts b/tee-worker/ts-tests/integration-tests/data-provider-tests/vip3.test.ts new file mode 100644 index 0000000000..dddd8c7632 --- /dev/null +++ b/tee-worker/ts-tests/integration-tests/data-provider-tests/vip3.test.ts @@ -0,0 +1,89 @@ +import { randomBytes, KeyObject } from 'crypto'; +import { step } from 'mocha-steps'; +import { assert } from 'chai'; +import { u8aToHex, bufferToU8a } from '@polkadot/util'; +import { buildIdentityFromKeypair, initIntegrationTestContext, PolkadotSigner } from '../common/utils'; +import { assertIsInSidechainBlock, assertVc } from '../common/utils/assertion'; +import { + getSidechainNonce, + createSignedTrustedCallLinkIdentity, + getTeeShieldingKey, + sendRequestFromTrustedCall, + createSignedTrustedCallRequestVc, +} from '../common/di-utils'; // @fixme move to a better place +import type { IntegrationTestContext } from '../common/common-types'; +import { CorePrimitivesIdentity } from 'parachain-api'; +import { LitentryValidationData, Web3Network } from 'parachain-api'; +import { Vec } from '@polkadot/types'; + + +const assertion = { + VIP3MembershipCard:'gold' +} +describe('Test Vc (direct invocation)', function () { + let context: IntegrationTestContext = undefined as any; + let teeShieldingKey: KeyObject = undefined as any; + let aliceSubstrateIdentity: CorePrimitivesIdentity = undefined as any; + + // Alice links: + // - a `mock_user` twitter + // - alice's evm identity + // - alice's bitcoin identity] + // + // We need this linking to not have empty eligible identities for any vc request + const linkIdentityRequestParams: { + nonce: number; + identity: CorePrimitivesIdentity; + validation: LitentryValidationData; + networks: Vec; + }[] = []; + this.timeout(6000000); + + before(async () => { + context = await initIntegrationTestContext( + process.env.WORKER_ENDPOINT!, // @fixme evil assertion; centralize env access + process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access + ); + teeShieldingKey = await getTeeShieldingKey(context); + aliceSubstrateIdentity = await buildIdentityFromKeypair( + new PolkadotSigner(context.substrateWallet.alice), + context + ); + }); + + step(`request vc`, async function () { + console.log(aliceSubstrateIdentity.toHuman()); + + // let currentNonce = (await getSidechainNonce(context, teeShieldingKey, aliceSubstrateIdentity)).toNumber(); + // const getNextNonce = () => currentNonce++; + // const nonce = getNextNonce(); + // const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; + // // console.log(`request vc ${Object.keys(assertion)[0]} for Alice ... Assertion description: ${description}`); + // const eventsPromise = subscribeToEventsWithExtHash(requestIdentifier, context); + + // const requestVcCall = await createSignedTrustedCallRequestVc( + // context.api, + // context.mrEnclave, + // context.api.createType('Index', nonce), + // new PolkadotSigner(context.substrateWallet.alice), + // aliceSubstrateIdentity, + // context.api.createType('Assertion', assertion).toHex(), + // context.api.createType('Option', aesKey).toHex(), + // requestIdentifier + // ); + + // const res = await sendRequestFromTrustedCall(context, teeShieldingKey, requestVcCall); + // await assertIsInSidechainBlock(`${Object.keys(assertion)[0]} requestVcCall`, res); + // const events = await eventsPromise; + // const vcIssuedEvents = events + // .map(({ event }) => event) + // .filter(({ section, method }) => section === 'vcManagement' && method === 'VCIssued'); + + // assert.equal( + // vcIssuedEvents.length, + // 1, + // `vcIssuedEvents.length != 1, please check the ${Object.keys(assertion)[0]} call` + // ); + // await assertVc(context, aliceSubstrateIdentity, res.value); + }) +}); diff --git a/tee-worker/ts-tests/integration-tests/package.json b/tee-worker/ts-tests/integration-tests/package.json index 40ecbaaf8f..1738686c3d 100644 --- a/tee-worker/ts-tests/integration-tests/package.json +++ b/tee-worker/ts-tests/integration-tests/package.json @@ -20,7 +20,8 @@ "test-ii-vc:local": "pnpm exec eslint . && pnpm exec cross-env NODE_ENV=local mocha --exit --sort -r ts-node/register --loader=ts-node/esm 'ii_vc.test.ts'", "test-ii-vc:staging": "pnpm exec eslint . && pnpm exec cross-env NODE_ENV=staging mocha --exit --sort -r ts-node/register --loader=ts-node/esm 'ii_vc.test.ts'", "test-ii-batch:local": "pnpm exec eslint . && pnpm exec cross-env NODE_ENV=local mocha --exit --sort -r ts-node/register --loader=ts-node/esm 'ii_batch.test.ts'", - "test-ii-batch:staging": "pnpm exec eslint . && pnpm exec cross-env NODE_ENV=staging mocha --exit --sort -r ts-node/register --loader=ts-node/esm 'ii_batch.test.ts'" + "test-ii-batch:staging": "pnpm exec eslint . && pnpm exec cross-env NODE_ENV=staging mocha --exit --sort -r ts-node/register --loader=ts-node/esm 'ii_batch.test.ts'", + "test-data-provider:local": "pnpm exec eslint . && pnpm exec cross-env NODE_ENV=local mocha --exit --sort -r ts-node/register --loader=ts-node/esm 'data-provider-tests/vip3.test.ts'" }, "dependencies": { "@noble/ed25519": "^1.7.3", From f09fef4b173ff56b053d5c3f3830994f1fbcb534 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Wed, 24 Jan 2024 08:50:20 +0000 Subject: [PATCH 03/32] Restore the data-provider test. --- .../integration-tests/data-provider.test.ts | 94 +++++++++++++++++++ .../ts-tests/integration-tests/package.json | 2 +- 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 tee-worker/ts-tests/integration-tests/data-provider.test.ts diff --git a/tee-worker/ts-tests/integration-tests/data-provider.test.ts b/tee-worker/ts-tests/integration-tests/data-provider.test.ts new file mode 100644 index 0000000000..41c00f343d --- /dev/null +++ b/tee-worker/ts-tests/integration-tests/data-provider.test.ts @@ -0,0 +1,94 @@ +import { randomBytes, KeyObject } from 'crypto'; +import { step } from 'mocha-steps'; +import { assert } from 'chai'; +import { u8aToHex, bufferToU8a } from '@polkadot/util'; +import { buildIdentityFromKeypair, initIntegrationTestContext, PolkadotSigner } from './common/utils'; +import { assertIsInSidechainBlock, assertVc } from './common/utils/assertion'; +import { + getSidechainNonce, + createSignedTrustedCallLinkIdentity, + getTeeShieldingKey, + sendRequestFromTrustedCall, + createSignedTrustedCallRequestVc, +} from './common/di-utils'; // @fixme move to a better place +import type { IntegrationTestContext } from './common/common-types'; +import { CorePrimitivesIdentity } from 'parachain-api'; +import { LitentryValidationData, Web3Network } from 'parachain-api'; +import { Vec } from '@polkadot/types'; + + +const assertion = { + VIP3MembershipCard:'gold' +} +describe('Test Vc (direct invocation)', function () { + let context: IntegrationTestContext = undefined as any; + let teeShieldingKey: KeyObject = undefined as any; + let aliceSubstrateIdentity: CorePrimitivesIdentity = undefined as any; + // const client= process.env.BINARY_DIR+'/litentry-cli'; + // Alice links: + // - a `mock_user` twitter + // - alice's evm identity + // - alice's bitcoin identity] + // + // We need this linking to not have empty eligible identities for any vc request + const linkIdentityRequestParams: { + nonce: number; + identity: CorePrimitivesIdentity; + validation: LitentryValidationData; + networks: Vec; + }[] = []; + this.timeout(6000000); + + before(async () => { + context = await initIntegrationTestContext( + process.env.WORKER_ENDPOINT!, // @fixme evil assertion; centralize env access + process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access + ); + teeShieldingKey = await getTeeShieldingKey(context); + aliceSubstrateIdentity = await buildIdentityFromKeypair( + new PolkadotSigner(context.substrateWallet.alice), + context + ); + }); + + step(`create idGrapgh via cli`, async function () { + + // console.log(client); + + }); + step(`request vc`, async function () { + console.log(aliceSubstrateIdentity.toHuman()); + + // let currentNonce = (await getSidechainNonce(context, teeShieldingKey, aliceSubstrateIdentity)).toNumber(); + // const getNextNonce = () => currentNonce++; + // const nonce = getNextNonce(); + // const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; + // // console.log(`request vc ${Object.keys(assertion)[0]} for Alice ... Assertion description: ${description}`); + // const eventsPromise = subscribeToEventsWithExtHash(requestIdentifier, context); + + // const requestVcCall = await createSignedTrustedCallRequestVc( + // context.api, + // context.mrEnclave, + // context.api.createType('Index', nonce), + // new PolkadotSigner(context.substrateWallet.alice), + // aliceSubstrateIdentity, + // context.api.createType('Assertion', assertion).toHex(), + // context.api.createType('Option', aesKey).toHex(), + // requestIdentifier + // ); + + // const res = await sendRequestFromTrustedCall(context, teeShieldingKey, requestVcCall); + // await assertIsInSidechainBlock(`${Object.keys(assertion)[0]} requestVcCall`, res); + // const events = await eventsPromise; + // const vcIssuedEvents = events + // .map(({ event }) => event) + // .filter(({ section, method }) => section === 'vcManagement' && method === 'VCIssued'); + + // assert.equal( + // vcIssuedEvents.length, + // 1, + // `vcIssuedEvents.length != 1, please check the ${Object.keys(assertion)[0]} call` + // ); + // await assertVc(context, aliceSubstrateIdentity, res.value); + }) +}); diff --git a/tee-worker/ts-tests/integration-tests/package.json b/tee-worker/ts-tests/integration-tests/package.json index 1738686c3d..8d2977a5ec 100644 --- a/tee-worker/ts-tests/integration-tests/package.json +++ b/tee-worker/ts-tests/integration-tests/package.json @@ -21,7 +21,7 @@ "test-ii-vc:staging": "pnpm exec eslint . && pnpm exec cross-env NODE_ENV=staging mocha --exit --sort -r ts-node/register --loader=ts-node/esm 'ii_vc.test.ts'", "test-ii-batch:local": "pnpm exec eslint . && pnpm exec cross-env NODE_ENV=local mocha --exit --sort -r ts-node/register --loader=ts-node/esm 'ii_batch.test.ts'", "test-ii-batch:staging": "pnpm exec eslint . && pnpm exec cross-env NODE_ENV=staging mocha --exit --sort -r ts-node/register --loader=ts-node/esm 'ii_batch.test.ts'", - "test-data-provider:local": "pnpm exec eslint . && pnpm exec cross-env NODE_ENV=local mocha --exit --sort -r ts-node/register --loader=ts-node/esm 'data-provider-tests/vip3.test.ts'" + "test-data-provider:local": "pnpm exec eslint . && pnpm exec cross-env NODE_ENV=local mocha --exit --sort -r ts-node/register --loader=ts-node/esm 'data-provider.test.ts'" }, "dependencies": { "@noble/ed25519": "^1.7.3", From 56034732934cbd32fbe250ad1d8374626e09cd39 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Wed, 24 Jan 2024 12:20:25 +0000 Subject: [PATCH 04/32] remove vipp3 test file --- .../data-provider-tests/config.example.json | 3 - .../data-provider-tests/vip3.test.ts | 89 ------------------- .../integration-tests/data-provider.test.ts | 80 +++++++++++------ 3 files changed, 53 insertions(+), 119 deletions(-) delete mode 100644 tee-worker/ts-tests/integration-tests/data-provider-tests/config.example.json delete mode 100644 tee-worker/ts-tests/integration-tests/data-provider-tests/vip3.test.ts diff --git a/tee-worker/ts-tests/integration-tests/data-provider-tests/config.example.json b/tee-worker/ts-tests/integration-tests/data-provider-tests/config.example.json deleted file mode 100644 index 0e5a82534a..0000000000 --- a/tee-worker/ts-tests/integration-tests/data-provider-tests/config.example.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "vip3":"0x12312312312312" -} \ No newline at end of file diff --git a/tee-worker/ts-tests/integration-tests/data-provider-tests/vip3.test.ts b/tee-worker/ts-tests/integration-tests/data-provider-tests/vip3.test.ts deleted file mode 100644 index dddd8c7632..0000000000 --- a/tee-worker/ts-tests/integration-tests/data-provider-tests/vip3.test.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { randomBytes, KeyObject } from 'crypto'; -import { step } from 'mocha-steps'; -import { assert } from 'chai'; -import { u8aToHex, bufferToU8a } from '@polkadot/util'; -import { buildIdentityFromKeypair, initIntegrationTestContext, PolkadotSigner } from '../common/utils'; -import { assertIsInSidechainBlock, assertVc } from '../common/utils/assertion'; -import { - getSidechainNonce, - createSignedTrustedCallLinkIdentity, - getTeeShieldingKey, - sendRequestFromTrustedCall, - createSignedTrustedCallRequestVc, -} from '../common/di-utils'; // @fixme move to a better place -import type { IntegrationTestContext } from '../common/common-types'; -import { CorePrimitivesIdentity } from 'parachain-api'; -import { LitentryValidationData, Web3Network } from 'parachain-api'; -import { Vec } from '@polkadot/types'; - - -const assertion = { - VIP3MembershipCard:'gold' -} -describe('Test Vc (direct invocation)', function () { - let context: IntegrationTestContext = undefined as any; - let teeShieldingKey: KeyObject = undefined as any; - let aliceSubstrateIdentity: CorePrimitivesIdentity = undefined as any; - - // Alice links: - // - a `mock_user` twitter - // - alice's evm identity - // - alice's bitcoin identity] - // - // We need this linking to not have empty eligible identities for any vc request - const linkIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - validation: LitentryValidationData; - networks: Vec; - }[] = []; - this.timeout(6000000); - - before(async () => { - context = await initIntegrationTestContext( - process.env.WORKER_ENDPOINT!, // @fixme evil assertion; centralize env access - process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access - ); - teeShieldingKey = await getTeeShieldingKey(context); - aliceSubstrateIdentity = await buildIdentityFromKeypair( - new PolkadotSigner(context.substrateWallet.alice), - context - ); - }); - - step(`request vc`, async function () { - console.log(aliceSubstrateIdentity.toHuman()); - - // let currentNonce = (await getSidechainNonce(context, teeShieldingKey, aliceSubstrateIdentity)).toNumber(); - // const getNextNonce = () => currentNonce++; - // const nonce = getNextNonce(); - // const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - // // console.log(`request vc ${Object.keys(assertion)[0]} for Alice ... Assertion description: ${description}`); - // const eventsPromise = subscribeToEventsWithExtHash(requestIdentifier, context); - - // const requestVcCall = await createSignedTrustedCallRequestVc( - // context.api, - // context.mrEnclave, - // context.api.createType('Index', nonce), - // new PolkadotSigner(context.substrateWallet.alice), - // aliceSubstrateIdentity, - // context.api.createType('Assertion', assertion).toHex(), - // context.api.createType('Option', aesKey).toHex(), - // requestIdentifier - // ); - - // const res = await sendRequestFromTrustedCall(context, teeShieldingKey, requestVcCall); - // await assertIsInSidechainBlock(`${Object.keys(assertion)[0]} requestVcCall`, res); - // const events = await eventsPromise; - // const vcIssuedEvents = events - // .map(({ event }) => event) - // .filter(({ section, method }) => section === 'vcManagement' && method === 'VCIssued'); - - // assert.equal( - // vcIssuedEvents.length, - // 1, - // `vcIssuedEvents.length != 1, please check the ${Object.keys(assertion)[0]} call` - // ); - // await assertVc(context, aliceSubstrateIdentity, res.value); - }) -}); diff --git a/tee-worker/ts-tests/integration-tests/data-provider.test.ts b/tee-worker/ts-tests/integration-tests/data-provider.test.ts index 41c00f343d..2e71f00091 100644 --- a/tee-worker/ts-tests/integration-tests/data-provider.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-provider.test.ts @@ -15,16 +15,17 @@ import type { IntegrationTestContext } from './common/common-types'; import { CorePrimitivesIdentity } from 'parachain-api'; import { LitentryValidationData, Web3Network } from 'parachain-api'; import { Vec } from '@polkadot/types'; - +import { spawn } from 'child_process'; +import { aesKey } from './common/call'; const assertion = { - VIP3MembershipCard:'gold' -} + VIP3MembershipCard: 'gold', +}; describe('Test Vc (direct invocation)', function () { let context: IntegrationTestContext = undefined as any; let teeShieldingKey: KeyObject = undefined as any; let aliceSubstrateIdentity: CorePrimitivesIdentity = undefined as any; - // const client= process.env.BINARY_DIR+'/litentry-cli'; + const client = process.env.BINARY_DIR + '/litentry-cli'; // Alice links: // - a `mock_user` twitter // - alice's evm identity @@ -51,34 +52,59 @@ describe('Test Vc (direct invocation)', function () { ); }); - step(`create idGrapgh via cli`, async function () { + step(`create idGrapgh via cli`, async function () { + // console.log(process.argv); + + // const evmIndex = process.argv.indexOf('--evm'); + // if (evmIndex > -1) { + // const evmAddress = process.argv[evmIndex + 1]; + // console.log(evmAddress); + // } - // console.log(client); + // todo: check idgrpah ,if exist, skip, else create + const aliceAddressFormat = '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d'; + const command = `${client}`; + const args = [ + 'trusted', + '-d', + 'link-identity', + `did: litentry: substrate:${aliceAddressFormat}`, + 'did: litentry: evm: 0x651614cA9097C5ba189Ef85e7851Ef9cff592B2c', + ]; + + const child = spawn(command, args); + // console.log(child); + + child.on('error', (error) => { + console.error(`spawn error: ${error}`); + }); + child.on('close', (code) => { + console.log(`child process exited with code ${code}`); + }); }); + step(`request vc`, async function () { - console.log(aliceSubstrateIdentity.toHuman()); - - // let currentNonce = (await getSidechainNonce(context, teeShieldingKey, aliceSubstrateIdentity)).toNumber(); - // const getNextNonce = () => currentNonce++; - // const nonce = getNextNonce(); - // const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - // // console.log(`request vc ${Object.keys(assertion)[0]} for Alice ... Assertion description: ${description}`); + let currentNonce = (await getSidechainNonce(context, teeShieldingKey, aliceSubstrateIdentity)).toNumber(); + const getNextNonce = () => currentNonce++; + const nonce = getNextNonce(); + const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; + // console.log(`request vc ${Object.keys(assertion)[0]} for Alice ... Assertion description: ${description}`); // const eventsPromise = subscribeToEventsWithExtHash(requestIdentifier, context); - // const requestVcCall = await createSignedTrustedCallRequestVc( - // context.api, - // context.mrEnclave, - // context.api.createType('Index', nonce), - // new PolkadotSigner(context.substrateWallet.alice), - // aliceSubstrateIdentity, - // context.api.createType('Assertion', assertion).toHex(), - // context.api.createType('Option', aesKey).toHex(), - // requestIdentifier - // ); + const requestVcCall = await createSignedTrustedCallRequestVc( + context.api, + context.mrEnclave, + context.api.createType('Index', nonce), + new PolkadotSigner(context.substrateWallet.alice), + aliceSubstrateIdentity, + context.api.createType('Assertion', assertion).toHex(), + context.api.createType('Option', aesKey).toHex(), + requestIdentifier + ); - // const res = await sendRequestFromTrustedCall(context, teeShieldingKey, requestVcCall); - // await assertIsInSidechainBlock(`${Object.keys(assertion)[0]} requestVcCall`, res); + const res = await sendRequestFromTrustedCall(context, teeShieldingKey, requestVcCall); + await assertIsInSidechainBlock(`${Object.keys(assertion)[0]} requestVcCall`, res); // const events = await eventsPromise; // const vcIssuedEvents = events // .map(({ event }) => event) @@ -89,6 +115,6 @@ describe('Test Vc (direct invocation)', function () { // 1, // `vcIssuedEvents.length != 1, please check the ${Object.keys(assertion)[0]} call` // ); - // await assertVc(context, aliceSubstrateIdentity, res.value); - }) + await assertVc(context, aliceSubstrateIdentity, res.value); + }); }); From f884970e10d5fc3ff2b93506485bd89ad4751c65 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Wed, 24 Jan 2024 12:22:48 +0000 Subject: [PATCH 05/32] debug vcPayloadJson --- .../ts-tests/integration-tests/common/utils/assertion.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tee-worker/ts-tests/integration-tests/common/utils/assertion.ts b/tee-worker/ts-tests/integration-tests/common/utils/assertion.ts index a9cf3176ca..2a10f8688c 100644 --- a/tee-worker/ts-tests/integration-tests/common/utils/assertion.ts +++ b/tee-worker/ts-tests/integration-tests/common/utils/assertion.ts @@ -272,6 +272,9 @@ export async function assertVc(context: IntegrationTestContext, subject: CorePri // step 4 // extrac proof and vc without proof json const vcPayloadJson = JSON.parse(decryptVcPayload); + + console.log("vcPayloadJson: ", vcPayloadJson); + const { proof, ...vcWithoutProof } = vcPayloadJson; // step 5 From 23e886c259ab6d396ce5aae88ced1b8d4bec4952 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Thu, 25 Jan 2024 14:09:02 +0000 Subject: [PATCH 06/32] refactor credential definitions --- .../config/data-providers.ts | 47 ++++ .../credential-definitions/config/networks.ts | 18 ++ .../credential-definitions/config/types.ts | 25 +++ .../common/credential-definitions/index.ts | 7 + .../vip3/vip3-membership-card-gold.ts | 21 ++ .../vip3/vip3-membership-card-sliver.ts | 11 + .../common/utils/assertion.ts | 4 +- .../integration-tests/data-provider.test.ts | 67 ++---- .../ts-tests/integration-tests/package.json | 3 +- tee-worker/ts-tests/pnpm-lock.yaml | 207 ++++++++++++++++-- 10 files changed, 345 insertions(+), 65 deletions(-) create mode 100644 tee-worker/ts-tests/integration-tests/common/credential-definitions/config/data-providers.ts create mode 100644 tee-worker/ts-tests/integration-tests/common/credential-definitions/config/networks.ts create mode 100644 tee-worker/ts-tests/integration-tests/common/credential-definitions/config/types.ts create mode 100644 tee-worker/ts-tests/integration-tests/common/credential-definitions/index.ts create mode 100644 tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts create mode 100644 tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/data-providers.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/data-providers.ts new file mode 100644 index 0000000000..12a562da87 --- /dev/null +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/data-providers.ts @@ -0,0 +1,47 @@ +export type DataProvider = { + id: string; + name: string; + url: string; +}; + +export const litentry: DataProvider = { + id: 'litentry-tee-worker', + name: 'Litentry TEE Worker', + url: 'https://litentry.com/', +}; + +export const litentryIndexer: DataProvider = { + id: 'litentry-indexer', + name: 'Litentry Indexer', + url: 'https://litentry.com/', +}; + +export const discord: DataProvider = { + id: 'discord-api', + name: 'Discord Official API', + url: 'https://discord.com/build', +}; + +export const achainable: DataProvider = { + id: 'achainable-api', + name: 'Achainable', + url: 'https://www.achainable.com/', +}; + +export const twitter: DataProvider = { + id: 'twitter-api', + name: 'Twitter Official API', + url: 'https://developer.twitter.com/', +}; + +export const oneBlock: DataProvider = { + id: 'one-block', + name: 'OneBlock+', + url: 'https://linktr.ee/oneblock_', +}; + +export const vip3: DataProvider = { + id: 'vip3', + name: 'VIP3', + url: 'https://dappapi.vip3.io/', +} \ No newline at end of file diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/networks.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/networks.ts new file mode 100644 index 0000000000..d696c9c08a --- /dev/null +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/networks.ts @@ -0,0 +1,18 @@ + +export enum Networks { + ethereum='Ethereum', + bsc='Bsc', + litentry='Litentry', + polkadot='Polkadot', + kusama='Kusama', + twitter='Twitter', + discord='Discord', + // ... +} + +export enum AccountNetworks{ + substrate='substrate', + evm='evm', + // ... +} + diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/types.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/types.ts new file mode 100644 index 0000000000..63c4ddd86b --- /dev/null +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/types.ts @@ -0,0 +1,25 @@ + +import { CorePrimitivesAssertion,CorePrimitivesNetworkWeb3Network } from "parachain-api"; +import type { Codec } from '@polkadot/types-codec/types'; +import type { U8aLike } from '@polkadot/util/types'; +import { DataProvider } from "./data-providers"; + + +type AssertionGenericPayload = + | string + | Array + | Record; + +export interface CredentialDefinition { + id: string; + name: string; + description: string; + assertion: { + id: CorePrimitivesAssertion['type'], + payload: AssertionGenericPayload + }; + dataProvider: DataProvider; + network: CorePrimitivesNetworkWeb3Network['type'], + mockDid: string; + mockWeb3Network: string; +} \ No newline at end of file diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/index.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/index.ts new file mode 100644 index 0000000000..7e4dd2ec79 --- /dev/null +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/index.ts @@ -0,0 +1,7 @@ +import { vip3MembershipCardGold } from './vip3/vip3-membership-card-gold' +import { vip3MembershipCardSliver } from './vip3/vip3-membership-card-sliver' + +export const credentialDefinitionMap = { + "vip3-membership-card-gold": vip3MembershipCardGold, + "vip3-membership-card-sliver": vip3MembershipCardSliver, +} \ No newline at end of file diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts new file mode 100644 index 0000000000..6fdb386922 --- /dev/null +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts @@ -0,0 +1,21 @@ +import { HexString } from '@polkadot/util/types' +import * as dataProviders from '../config/data-providers' +import { Networks, AccountNetworks } from "../config/networks" +import {CredentialDefinition} from '../config/types' + +const mockAddress: HexString = '0x651614cA9097C5ba189Ef85e7851Ef9cff592B2b' +export const vip3MembershipCardGold:CredentialDefinition = { + id: 'vip3-membership-card-gold', + name: 'VIP3 Membership Card Gold', + description: 'VIP3 Membership Card Gold', + assertion: { + id:"Vip3MembershipCard", + payload: 'Gold', + }, + dataProvider: dataProviders.vip3, + network: Networks['ethereum'], + + // mock data for link-identity via cli + mockDid: `litentry:${AccountNetworks['evm']}:${mockAddress}`, + mockWeb3Network: `${Networks['bsc']},${Networks['ethereum']}` +} \ No newline at end of file diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts new file mode 100644 index 0000000000..344a5cecb0 --- /dev/null +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts @@ -0,0 +1,11 @@ +import * as dataProviders from '../config/data-providers' + +export const vip3MembershipCardSliver = { + id: 'vip3-membership-card-sliver', + name: 'VIP3 Membership Card Sliver', + description: 'VIP3 Membership Card Sliver', + assertion: { + VIP3MembershipCard: 'sliver', + }, + dataProvider:dataProviders.vip3, +} \ No newline at end of file diff --git a/tee-worker/ts-tests/integration-tests/common/utils/assertion.ts b/tee-worker/ts-tests/integration-tests/common/utils/assertion.ts index 2a10f8688c..ca817e4892 100644 --- a/tee-worker/ts-tests/integration-tests/common/utils/assertion.ts +++ b/tee-worker/ts-tests/integration-tests/common/utils/assertion.ts @@ -273,8 +273,8 @@ export async function assertVc(context: IntegrationTestContext, subject: CorePri // extrac proof and vc without proof json const vcPayloadJson = JSON.parse(decryptVcPayload); - console.log("vcPayloadJson: ", vcPayloadJson); - + console.log('vcPayloadJson: ', vcPayloadJson); + const { proof, ...vcWithoutProof } = vcPayloadJson; // step 5 diff --git a/tee-worker/ts-tests/integration-tests/data-provider.test.ts b/tee-worker/ts-tests/integration-tests/data-provider.test.ts index 2e71f00091..af6a153dae 100644 --- a/tee-worker/ts-tests/integration-tests/data-provider.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-provider.test.ts @@ -17,27 +17,15 @@ import { LitentryValidationData, Web3Network } from 'parachain-api'; import { Vec } from '@polkadot/types'; import { spawn } from 'child_process'; import { aesKey } from './common/call'; +import { $ as zx } from 'zx'; -const assertion = { - VIP3MembershipCard: 'gold', -}; +import {credentialDefinitionMap} from './common/credential-definitions' describe('Test Vc (direct invocation)', function () { let context: IntegrationTestContext = undefined as any; let teeShieldingKey: KeyObject = undefined as any; let aliceSubstrateIdentity: CorePrimitivesIdentity = undefined as any; const client = process.env.BINARY_DIR + '/litentry-cli'; - // Alice links: - // - a `mock_user` twitter - // - alice's evm identity - // - alice's bitcoin identity] - // - // We need this linking to not have empty eligible identities for any vc request - const linkIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - validation: LitentryValidationData; - networks: Vec; - }[] = []; + const aliceAddressFormat = '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d'; this.timeout(6000000); before(async () => { @@ -52,6 +40,7 @@ describe('Test Vc (direct invocation)', function () { ); }); + step(`create idGrapgh via cli`, async function () { // console.log(process.argv); @@ -61,37 +50,30 @@ describe('Test Vc (direct invocation)', function () { // console.log(evmAddress); // } - // todo: check idgrpah ,if exist, skip, else create - const aliceAddressFormat = '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d'; - const command = `${client}`; - const args = [ - 'trusted', - '-d', - 'link-identity', - `did: litentry: substrate:${aliceAddressFormat}`, - 'did: litentry: evm: 0x651614cA9097C5ba189Ef85e7851Ef9cff592B2c', - ]; - - const child = spawn(command, args); - // console.log(child); + + // check idgraph if identity exist + + + // try { + // const linkResult = await zx`${client} trusted -d link-identity did:litentry:substrate:${aliceAddressFormat} did:litentry:evm:0x651614cA9097C5ba189Ef85e7851Ef9cff592B2b bsc,ethereum`; + // console.log(linkResult); + + // } catch (error: any) { + // console.log(`Exit code: ${error.exitCode}`); + // console.log(`Error: ${error.stderr}`); + // } - child.on('error', (error) => { - console.error(`spawn error: ${error}`); - }); - child.on('close', (code) => { - console.log(`child process exited with code ${code}`); - }); }); step(`request vc`, async function () { + const assertion = { + [credentialDefinitionMap['vip3-membership-card-gold'].assertion.id]: credentialDefinitionMap['vip3-membership-card-gold'].assertion.payload + } let currentNonce = (await getSidechainNonce(context, teeShieldingKey, aliceSubstrateIdentity)).toNumber(); const getNextNonce = () => currentNonce++; const nonce = getNextNonce(); const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - // console.log(`request vc ${Object.keys(assertion)[0]} for Alice ... Assertion description: ${description}`); - // const eventsPromise = subscribeToEventsWithExtHash(requestIdentifier, context); - const requestVcCall = await createSignedTrustedCallRequestVc( context.api, context.mrEnclave, @@ -102,19 +84,8 @@ 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 events = await eventsPromise; - // const vcIssuedEvents = events - // .map(({ event }) => event) - // .filter(({ section, method }) => section === 'vcManagement' && method === 'VCIssued'); - - // assert.equal( - // vcIssuedEvents.length, - // 1, - // `vcIssuedEvents.length != 1, please check the ${Object.keys(assertion)[0]} call` - // ); await assertVc(context, aliceSubstrateIdentity, res.value); }); }); diff --git a/tee-worker/ts-tests/integration-tests/package.json b/tee-worker/ts-tests/integration-tests/package.json index 17b0f7411a..9e132ee276 100644 --- a/tee-worker/ts-tests/integration-tests/package.json +++ b/tee-worker/ts-tests/integration-tests/package.json @@ -50,7 +50,8 @@ "scale-ts": "^0.2.11", "sidechain-api": "file:../../client-api/sidechain-api", "websocket-as-promised": "^2.0.1", - "ws": "^8.8.1" + "ws": "^8.8.1", + "zx": "^7.2.3" }, "devDependencies": { "@ethersproject/providers": "^5.7.2", diff --git a/tee-worker/ts-tests/pnpm-lock.yaml b/tee-worker/ts-tests/pnpm-lock.yaml index da37548f54..edaf43607f 100644 --- a/tee-worker/ts-tests/pnpm-lock.yaml +++ b/tee-worker/ts-tests/pnpm-lock.yaml @@ -97,6 +97,9 @@ importers: ws: specifier: ^8.8.1 version: 8.14.2 + zx: + specifier: ^7.2.3 + version: 7.2.3 devDependencies: '@ethersproject/providers': specifier: ^5.7.2 @@ -797,12 +800,10 @@ packages: dependencies: '@nodelib/fs.stat': 2.0.5 run-parallel: 1.2.0 - dev: true /@nodelib/fs.stat@2.0.5: resolution: {integrity: sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==} engines: {node: '>= 8'} - dev: true /@nodelib/fs.walk@1.2.8: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} @@ -810,7 +811,6 @@ packages: dependencies: '@nodelib/fs.scandir': 2.1.5 fastq: 1.15.0 - dev: true /@polkadot/api-augment@10.9.1: resolution: {integrity: sha512-kRZZvCFVcN4hAH4dJ+Qzfdy27/4EEq3oLDf3ihj0LTVrAezSWcKPGE3EVFy+Mn6Lo4SUc7RVyoKvIUhSk2l4Dg==} @@ -1287,21 +1287,52 @@ packages: resolution: {integrity: sha512-VOVRLM1mBxIRxydiViqPcKn6MIxZytrbMpd6RJLIWKxUNr3zux8no0Oc7kJx0WAPIitgZ0gkrDS+btlqQpubpw==} dev: true + /@types/fs-extra@11.0.4: + resolution: {integrity: sha512-yTbItCNreRooED33qjunPthRcSjERP1r4MqCZc7wv0u2sUkzTFp45tgUfS5+r7FrZPdmCCNflLhVSP/o+SemsQ==} + dependencies: + '@types/jsonfile': 6.1.4 + '@types/node': 20.7.1 + dev: false + /@types/json-schema@7.0.13: resolution: {integrity: sha512-RbSSoHliUbnXj3ny0CNFOoxrIDV6SUGyStHsvDqosw6CkdPV8TtWGlfecuK4ToyMEAql6pzNxgCFKanovUzlgQ==} dev: true + /@types/jsonfile@6.1.4: + resolution: {integrity: sha512-D5qGUYwjvnNNextdU59/+fI+spnwtTFmyQP0h+PfIOSkNfpU6AOICUOkm4i0OnSk+NyjdPJrxCDro0sJsWlRpQ==} + dependencies: + '@types/node': 20.7.1 + dev: false + + /@types/minimist@1.2.5: + resolution: {integrity: sha512-hov8bUuiLiyFPGyFPE1lwWhmzYbirOXQNNo40+y3zow8aFVTeyn3VWL0VFFfdNddA8S4Vf0Tc062rzyNr7Paag==} + dev: false + /@types/mocha@10.0.2: resolution: {integrity: sha512-NaHL0+0lLNhX6d9rs+NSt97WH/gIlRHmszXbQ/8/MV/eVcFNdeJ/GYhrFuUc8K7WuPhRhTSdMkCp8VMzhUq85w==} dev: true + /@types/node@18.19.9: + resolution: {integrity: sha512-oZFKlC8l5YtzGQNT4zC2PiSSKzQVZ8bAwwd+EYdPLtyk0nSEq6O16SkK+rkkT2eflDAbormJgEF3QnH3oDrTSw==} + dependencies: + undici-types: 5.26.5 + dev: false + /@types/node@20.7.1: resolution: {integrity: sha512-LT+OIXpp2kj4E2S/p91BMe+VgGX2+lfO+XTpfXhh+bCk2LkQtHZSub8ewFBMGP5ClysPjTDFa4sMI8Q3n4T0wg==} + /@types/ps-tree@1.1.6: + resolution: {integrity: sha512-PtrlVaOaI44/3pl3cvnlK+GxOM3re2526TJvPvh7W+keHIXdV4TE0ylpPBAcvFQCbGitaTXwL9u+RF7qtVeazQ==} + dev: false + /@types/semver@7.5.3: resolution: {integrity: sha512-OxepLK9EuNEIPxWNME+C6WwbRAOOI2o2BaQEGzz5Lu2e4Z5eDnEo+/aVEDMIXywoJitJ7xWd641wrGLZdtwRyw==} dev: true + /@types/which@3.0.3: + resolution: {integrity: sha512-2C1+XoY0huExTbs8MQv1DuS5FS86+SEjdM9F/+GS61gg5Hqbtj8ZiDSx8MfWcyei907fIPbfPGCOrNUTnVHY1g==} + dev: false + /@types/ws@8.5.6: resolution: {integrity: sha512-8B5EO9jLVCy+B58PLHvLDuOD8DRVMgQzq8d55SjLCOn9kqGyqOvy27exVaTio1q1nX5zLu8/6N0n2ThSxOM6tg==} dependencies: @@ -1671,6 +1702,11 @@ packages: ansi-styles: 4.3.0 supports-color: 7.2.0 + /chalk@5.3.0: + resolution: {integrity: sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==} + engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} + dev: false + /check-error@1.0.3: resolution: {integrity: sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg==} dependencies: @@ -1811,7 +1847,6 @@ packages: engines: {node: '>=8'} dependencies: path-type: 4.0.0 - dev: true /doctrine@3.0.0: resolution: {integrity: sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==} @@ -1825,6 +1860,10 @@ packages: engines: {node: '>=12'} dev: true + /duplexer@0.1.2: + resolution: {integrity: sha512-jtD6YG370ZCIi/9GTaJKQxWTZD045+4R4hTk/x1UyoqadyJ9x9CgSi1RlVDQF8U2sxLLSnFkCaMihqljHIWgMg==} + dev: false + /ecurve@1.0.6: resolution: {integrity: sha512-/BzEjNfiSuB7jIWKcS/z8FK9jNjmEWvUV2YZ4RLSmcDtP7Lq0m6FvDuSnJpBlDpGRpfRQeTLGLBI8H+kEv0r+w==} dependencies: @@ -2060,6 +2099,18 @@ packages: - utf-8-validate dev: true + /event-stream@3.3.4: + resolution: {integrity: sha512-QHpkERcGsR0T7Qm3HNJSyXKEEj8AHNxkY3PK8TS2KJvQ7NiSHe3DDpwVKKtoYprL/AreyzFBeIkBIWChAqn60g==} + dependencies: + duplexer: 0.1.2 + from: 0.1.7 + map-stream: 0.1.0 + pause-stream: 0.0.11 + split: 0.3.3 + stream-combiner: 0.0.4 + through: 2.3.8 + dev: false + /eventemitter3@4.0.7: resolution: {integrity: sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==} requiresBuild: true @@ -2082,7 +2133,6 @@ packages: glob-parent: 5.1.2 merge2: 1.4.1 micromatch: 4.0.5 - dev: true /fast-json-stable-stringify@2.1.0: resolution: {integrity: sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==} @@ -2096,7 +2146,6 @@ packages: resolution: {integrity: sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==} dependencies: reusify: 1.0.4 - dev: true /fetch-blob@3.2.0: resolution: {integrity: sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==} @@ -2156,6 +2205,19 @@ packages: fetch-blob: 3.2.0 dev: false + /from@0.1.7: + resolution: {integrity: sha512-twe20eF1OxVxp/ML/kq2p1uc6KvFK/+vs8WjEbeKmV2He22MKm7YF2ANIt+EOqhJ5L3K/SuuPhk0hWQDjOM23g==} + dev: false + + /fs-extra@11.2.0: + resolution: {integrity: sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==} + engines: {node: '>=14.14'} + dependencies: + graceful-fs: 4.2.11 + jsonfile: 6.1.0 + universalify: 2.0.1 + dev: false + /fs.realpath@1.0.0: resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==} @@ -2184,6 +2246,11 @@ packages: resolution: {integrity: sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==} dev: false + /fx@31.0.0: + resolution: {integrity: sha512-OoeYSPKqNKmfnH4s+rGYI0c8OZmqqOOXsUtqy0YyHqQQoQSDiDs3m3M9uXKx5OQR+jDx7/FhYqpO3kl/As/xgg==} + hasBin: true + dev: false + /get-caller-file@2.0.5: resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==} engines: {node: 6.* || 8.* || >= 10.*} @@ -2268,12 +2335,27 @@ packages: slash: 3.0.0 dev: true + /globby@13.2.2: + resolution: {integrity: sha512-Y1zNGV+pzQdh7H39l9zgB4PJqjRNqydvdYCDG4HFXM4XuvSaQQlEc91IU1yALL8gUTDomgBAfz3XJdmUS+oo0w==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dependencies: + dir-glob: 3.0.1 + fast-glob: 3.3.1 + ignore: 5.2.4 + merge2: 1.4.1 + slash: 4.0.0 + dev: false + /gopd@1.0.1: resolution: {integrity: sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==} dependencies: get-intrinsic: 1.2.1 dev: false + /graceful-fs@4.2.11: + resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} + dev: false + /graphemer@1.4.0: resolution: {integrity: sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==} dev: true @@ -2349,7 +2431,6 @@ packages: /ignore@5.2.4: resolution: {integrity: sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==} engines: {node: '>= 4'} - dev: true /import-fresh@3.3.0: resolution: {integrity: sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==} @@ -2516,7 +2597,6 @@ packages: /isexe@2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} - dev: true /js-base64@3.7.5: resolution: {integrity: sha512-3MEt5DTINKqfScXKfJFrRbxkrnk2AxPWGBL/ycjz4dK8iqiSJ06UxD8jh8xuh6p10TX4t2+7FsBYVxxQbMg+qA==} @@ -2556,6 +2636,14 @@ packages: resolution: {integrity: sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==} dev: false + /jsonfile@6.1.0: + resolution: {integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==} + dependencies: + universalify: 2.0.1 + optionalDependencies: + graceful-fs: 4.2.11 + dev: false + /keyv@4.5.3: resolution: {integrity: sha512-QCiSav9WaX1PgETJ+SpNnx2PRRapJ/oRSXM4VO5OGYGSjrxbKPVFVhB3l2OCbLCk329N8qyAtsJjSjvVBWzEug==} dependencies: @@ -2607,10 +2695,13 @@ packages: resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} dev: true + /map-stream@0.1.0: + resolution: {integrity: sha512-CkYQrPYZfWnu/DAmVCpTSX/xHpKZ80eKh2lAkyA6AJTef6bW+6JpbQZN5rofum7da+SyN1bi5ctTm+lTfcCW3g==} + dev: false + /merge2@1.4.1: resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==} engines: {node: '>= 8'} - dev: true /micro-base58@0.5.1: resolution: {integrity: sha512-iwqAmg66VjB2LA3BcUxyrOyqck4HLLtSzKnx2VQSnN5piQji598N15P8RRx2d6lPvJ98B1b0cl2VbvQeFeWdig==} @@ -2622,7 +2713,6 @@ packages: dependencies: braces: 3.0.2 picomatch: 2.3.1 - dev: true /minimalistic-assert@1.0.1: resolution: {integrity: sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==} @@ -2721,6 +2811,15 @@ packages: engines: {node: '>=10.5.0'} dev: false + /node-fetch@3.3.1: + resolution: {integrity: sha512-cRVc/kyto/7E5shrWca1Wsea4y6tL9iYJE5FBCius3JQfb/4P4I295PfhgbJQBLTx6lATE4z+wK0rPM4VS2uow==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dependencies: + data-uri-to-buffer: 4.0.1 + fetch-blob: 3.2.0 + formdata-polyfill: 4.0.10 + dev: false + /node-fetch@3.3.2: resolution: {integrity: sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -2811,11 +2910,16 @@ packages: /path-type@4.0.0: resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==} engines: {node: '>=8'} - dev: true /pathval@1.1.1: resolution: {integrity: sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==} + /pause-stream@0.0.11: + resolution: {integrity: sha512-e3FBlXLmN/D1S+zHzanP4E/4Z60oFAa3O051qt1pxa7DEJWKAyil6upYVXCWadEnuoqa4Pkc9oUx9zsxYeRv8A==} + dependencies: + through: 2.3.8 + dev: false + /picomatch@2.3.1: resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} engines: {node: '>=8.6'} @@ -2857,13 +2961,20 @@ packages: engines: {node: '>= 8'} dev: false + /ps-tree@1.2.0: + resolution: {integrity: sha512-0VnamPPYHl4uaU/nSFeZZpR21QAWRz+sRv4iW9+v/GS/J5U5iZB5BNN6J0RMoOvdx2gWM2+ZFMIm58q24e4UYA==} + engines: {node: '>= 0.10'} + hasBin: true + dependencies: + event-stream: 3.3.4 + dev: false + /punycode@2.3.0: resolution: {integrity: sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==} engines: {node: '>=6'} /queue-microtask@1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} - dev: true /randombytes@2.1.0: resolution: {integrity: sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==} @@ -2902,7 +3013,6 @@ packages: /reusify@1.0.4: resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} engines: {iojs: '>=1.0.0', node: '>=0.10.0'} - dev: true /rimraf@3.0.2: resolution: {integrity: sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==} @@ -2915,7 +3025,6 @@ packages: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} dependencies: queue-microtask: 1.2.3 - dev: true /rxjs@7.8.1: resolution: {integrity: sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==} @@ -2999,6 +3108,11 @@ packages: engines: {node: '>=8'} dev: true + /slash@4.0.0: + resolution: {integrity: sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==} + engines: {node: '>=12'} + dev: false + /smoldot@1.0.4: resolution: {integrity: sha512-N3TazI1C4GGrseFH/piWyZCCCRJTRx2QhDfrUKRT4SzILlW5m8ayZ3QTKICcz1C/536T9cbHHJyP7afxI6Mi1A==} requiresBuild: true @@ -3016,6 +3130,18 @@ packages: engines: {node: '>=0.10.0'} dev: false + /split@0.3.3: + resolution: {integrity: sha512-wD2AeVmxXRBoX44wAycgjVpMhvbwdI2aZjCkvfNcH1YqHQvJVa1duWc73OyVGJUc05fhFaTZeQ/PYsrmyH0JVA==} + dependencies: + through: 2.3.8 + dev: false + + /stream-combiner@0.0.4: + resolution: {integrity: sha512-rT00SPnTVyRsaSz5zgSPma/aHSOic5U1prhYdRy5HS2kTZviFpmDgzilbtsJsxiroqACmayynDN/9VzIbX5DOw==} + dependencies: + duplexer: 0.1.2 + dev: false + /string-width@4.2.3: resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} engines: {node: '>=8'} @@ -3075,6 +3201,10 @@ packages: resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==} dev: true + /through@2.3.8: + resolution: {integrity: sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==} + dev: false + /to-regex-range@5.0.1: resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==} engines: {node: '>=8.0'} @@ -3207,6 +3337,15 @@ packages: which-boxed-primitive: 1.0.2 dev: false + /undici-types@5.26.5: + resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} + dev: false + + /universalify@2.0.1: + resolution: {integrity: sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==} + engines: {node: '>= 10.0.0'} + dev: false + /uri-js@4.4.1: resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} dependencies: @@ -3221,6 +3360,11 @@ packages: engines: {node: '>= 8'} dev: false + /webpod@0.0.2: + resolution: {integrity: sha512-cSwwQIeg8v4i3p4ajHhwgR7N6VyxAf+KYSSsY6Pd3aETE+xEU4vbitz7qQkB0I321xnhDdgtxuiSfk5r/FVtjg==} + hasBin: true + dev: false + /websocket-as-promised@2.0.1: resolution: {integrity: sha512-ePV26D/D37ughXU9j+DjGmwUbelWJrC/vi+6GK++fRlBJmS7aU9T8ABu47KFF0O7r6XN2NAuqJRpegbUwXZxQg==} engines: {node: '>=6'} @@ -3260,6 +3404,14 @@ packages: isexe: 2.0.0 dev: true + /which@3.0.1: + resolution: {integrity: sha512-XA1b62dzQzLfaEOSQFTCOd5KFf/1VSzZo7/7TUjnya6u0vGGKzU96UQBZTAThCb2j4/xjBAyii1OhRLJEivHvg==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} + hasBin: true + dependencies: + isexe: 2.0.0 + dev: false + /wordwrap@1.0.0: resolution: {integrity: sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==} dev: false @@ -3312,6 +3464,11 @@ packages: resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} dev: true + /yaml@2.3.4: + resolution: {integrity: sha512-8aAvwVUSHpfEqTQ4w/KMlf3HcRdt50E5ODIQJBw1fQ5RL34xabzxtUlzTXVqc4rkZsPbvrXKWnABCD7kWSmocA==} + engines: {node: '>= 14'} + dev: false + /yargs-parser@20.2.4: resolution: {integrity: sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==} engines: {node: '>=10'} @@ -3368,6 +3525,28 @@ packages: resolution: {integrity: sha512-EjIevzuJRiRPbVH4mGc8nApb/lVLKVpmUhAaR5R5doKGfAnGJ6Gr3CViAVjP+4FWSxCsybeWQdcgCtbX+7oZug==} dev: false + /zx@7.2.3: + resolution: {integrity: sha512-QODu38nLlYXg/B/Gw7ZKiZrvPkEsjPN3LQ5JFXM7h0JvwhEdPNNl+4Ao1y4+o3CLNiDUNcwzQYZ4/Ko7kKzCMA==} + engines: {node: '>= 16.0.0'} + hasBin: true + dependencies: + '@types/fs-extra': 11.0.4 + '@types/minimist': 1.2.5 + '@types/node': 18.19.9 + '@types/ps-tree': 1.1.6 + '@types/which': 3.0.3 + chalk: 5.3.0 + fs-extra: 11.2.0 + fx: 31.0.0 + globby: 13.2.2 + minimist: 1.2.8 + node-fetch: 3.3.1 + ps-tree: 1.2.0 + webpod: 0.0.2 + which: 3.0.1 + yaml: 2.3.4 + dev: false + file:../client-api/parachain-api: resolution: {directory: ../client-api/parachain-api, type: directory} name: '@litentry/parachain-api' From 934de08c91eccb97936c75003a59068d83f78c2d Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Thu, 25 Jan 2024 14:40:30 +0000 Subject: [PATCH 07/32] format --- .../integration-tests/.env.local.example | 3 +- .../config/data-providers.ts | 44 ++++++++-------- .../credential-definitions/config/networks.ts | 24 ++++----- .../credential-definitions/config/types.ts | 21 +++----- .../common/credential-definitions/index.ts | 10 ++-- .../vip3/vip3-membership-card-gold.ts | 18 +++---- .../vip3/vip3-membership-card-sliver.ts | 19 +++++-- .../integration-tests/data-provider.test.ts | 51 +++++++------------ 8 files changed, 89 insertions(+), 101 deletions(-) diff --git a/tee-worker/ts-tests/integration-tests/.env.local.example b/tee-worker/ts-tests/integration-tests/.env.local.example index 846607efed..b5c06ecc40 100644 --- a/tee-worker/ts-tests/integration-tests/.env.local.example +++ b/tee-worker/ts-tests/integration-tests/.env.local.example @@ -1,3 +1,4 @@ NODE_ENV = local WORKER_ENDPOINT = wss://localhost:2000 -NODE_ENDPOINT = ws://localhost:9944 \ No newline at end of file +NODE_ENDPOINT = ws://localhost:9944 +BINARY_DIR=../../bin diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/data-providers.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/data-providers.ts index 12a562da87..fe69d4d3c4 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/data-providers.ts +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/data-providers.ts @@ -1,47 +1,47 @@ export type DataProvider = { - id: string; - name: string; - url: string; + id: string; + name: string; + url: string; }; export const litentry: DataProvider = { - id: 'litentry-tee-worker', - name: 'Litentry TEE Worker', - url: 'https://litentry.com/', + id: 'litentry-tee-worker', + name: 'Litentry TEE Worker', + url: 'https://litentry.com/', }; export const litentryIndexer: DataProvider = { - id: 'litentry-indexer', - name: 'Litentry Indexer', - url: 'https://litentry.com/', + id: 'litentry-indexer', + name: 'Litentry Indexer', + url: 'https://litentry.com/', }; export const discord: DataProvider = { - id: 'discord-api', - name: 'Discord Official API', - url: 'https://discord.com/build', + id: 'discord-api', + name: 'Discord Official API', + url: 'https://discord.com/build', }; export const achainable: DataProvider = { - id: 'achainable-api', - name: 'Achainable', - url: 'https://www.achainable.com/', + id: 'achainable-api', + name: 'Achainable', + url: 'https://www.achainable.com/', }; export const twitter: DataProvider = { - id: 'twitter-api', - name: 'Twitter Official API', - url: 'https://developer.twitter.com/', + id: 'twitter-api', + name: 'Twitter Official API', + url: 'https://developer.twitter.com/', }; export const oneBlock: DataProvider = { - id: 'one-block', - name: 'OneBlock+', - url: 'https://linktr.ee/oneblock_', + id: 'one-block', + name: 'OneBlock+', + url: 'https://linktr.ee/oneblock_', }; export const vip3: DataProvider = { id: 'vip3', name: 'VIP3', url: 'https://dappapi.vip3.io/', -} \ No newline at end of file +}; diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/networks.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/networks.ts index d696c9c08a..9bbcfc1c65 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/networks.ts +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/networks.ts @@ -1,18 +1,16 @@ - -export enum Networks { - ethereum='Ethereum', - bsc='Bsc', - litentry='Litentry', - polkadot='Polkadot', - kusama='Kusama', - twitter='Twitter', - discord='Discord', +export enum Networks { + ethereum = 'Ethereum', + bsc = 'Bsc', + litentry = 'Litentry', + polkadot = 'Polkadot', + kusama = 'Kusama', + twitter = 'Twitter', + discord = 'Discord', // ... } -export enum AccountNetworks{ - substrate='substrate', - evm='evm', +export enum AccountNetworks { + substrate = 'substrate', + evm = 'evm', // ... } - diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/types.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/types.ts index 63c4ddd86b..a231cdc8ef 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/types.ts +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/types.ts @@ -1,25 +1,20 @@ - -import { CorePrimitivesAssertion,CorePrimitivesNetworkWeb3Network } from "parachain-api"; +import { CorePrimitivesAssertion, CorePrimitivesNetworkWeb3Network } from 'parachain-api'; import type { Codec } from '@polkadot/types-codec/types'; import type { U8aLike } from '@polkadot/util/types'; -import { DataProvider } from "./data-providers"; - +import { DataProvider } from './data-providers'; -type AssertionGenericPayload = - | string - | Array - | Record; +type AssertionGenericPayload = string | Array | Record; -export interface CredentialDefinition { +export interface CredentialDefinition { id: string; name: string; description: string; assertion: { - id: CorePrimitivesAssertion['type'], - payload: AssertionGenericPayload + id: CorePrimitivesAssertion['type']; + payload: AssertionGenericPayload; }; dataProvider: DataProvider; - network: CorePrimitivesNetworkWeb3Network['type'], + network: CorePrimitivesNetworkWeb3Network['type']; mockDid: string; mockWeb3Network: string; -} \ No newline at end of file +} diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/index.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/index.ts index 7e4dd2ec79..79d29c2d14 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/index.ts +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/index.ts @@ -1,7 +1,7 @@ -import { vip3MembershipCardGold } from './vip3/vip3-membership-card-gold' -import { vip3MembershipCardSliver } from './vip3/vip3-membership-card-sliver' +import { vip3MembershipCardGold } from './vip3/vip3-membership-card-gold'; +import { vip3MembershipCardSliver } from './vip3/vip3-membership-card-sliver'; export const credentialDefinitionMap = { - "vip3-membership-card-gold": vip3MembershipCardGold, - "vip3-membership-card-sliver": vip3MembershipCardSliver, -} \ No newline at end of file + 'vip3-membership-card-gold': vip3MembershipCardGold, + 'vip3-membership-card-sliver': vip3MembershipCardSliver, +}; diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts index 6fdb386922..d14ac951df 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts @@ -1,15 +1,15 @@ -import { HexString } from '@polkadot/util/types' -import * as dataProviders from '../config/data-providers' -import { Networks, AccountNetworks } from "../config/networks" -import {CredentialDefinition} from '../config/types' +import { HexString } from '@polkadot/util/types'; +import * as dataProviders from '../config/data-providers'; +import { Networks, AccountNetworks } from '../config/networks'; +import { CredentialDefinition } from '../config/types'; -const mockAddress: HexString = '0x651614cA9097C5ba189Ef85e7851Ef9cff592B2b' -export const vip3MembershipCardGold:CredentialDefinition = { +const mockAddress: HexString = '0x651614cA9097C5ba189Ef85e7851Ef9cff592B2c'; +export const vip3MembershipCardGold: CredentialDefinition = { id: 'vip3-membership-card-gold', name: 'VIP3 Membership Card Gold', description: 'VIP3 Membership Card Gold', assertion: { - id:"Vip3MembershipCard", + id: 'Vip3MembershipCard', payload: 'Gold', }, dataProvider: dataProviders.vip3, @@ -17,5 +17,5 @@ export const vip3MembershipCardGold:CredentialDefinition = { // mock data for link-identity via cli mockDid: `litentry:${AccountNetworks['evm']}:${mockAddress}`, - mockWeb3Network: `${Networks['bsc']},${Networks['ethereum']}` -} \ No newline at end of file + mockWeb3Network: `${Networks['bsc']},${Networks['ethereum']}`, +}; diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts index 344a5cecb0..b871a05708 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts @@ -1,11 +1,20 @@ -import * as dataProviders from '../config/data-providers' +import { HexString } from '@polkadot/util/types'; +import * as dataProviders from '../config/data-providers'; +import { AccountNetworks, Networks } from '../config/networks'; +import { CredentialDefinition } from '../config/types'; -export const vip3MembershipCardSliver = { +const mockAddress: HexString = '0x651614cA9097C5ba189Ef85e7851Ef9cff592B2b'; +export const vip3MembershipCardSliver: CredentialDefinition = { id: 'vip3-membership-card-sliver', name: 'VIP3 Membership Card Sliver', description: 'VIP3 Membership Card Sliver', assertion: { - VIP3MembershipCard: 'sliver', + id: 'Vip3MembershipCard', + payload: 'sliver', }, - dataProvider:dataProviders.vip3, -} \ No newline at end of file + dataProvider: dataProviders.vip3, + network: Networks['ethereum'], + // mock data for link-identity via cli + mockDid: `litentry:${AccountNetworks['evm']}:${mockAddress}`, + mockWeb3Network: `${Networks['bsc']},${Networks['ethereum']}`, +}; diff --git a/tee-worker/ts-tests/integration-tests/data-provider.test.ts b/tee-worker/ts-tests/integration-tests/data-provider.test.ts index af6a153dae..521ba12a2d 100644 --- a/tee-worker/ts-tests/integration-tests/data-provider.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-provider.test.ts @@ -1,25 +1,20 @@ import { randomBytes, KeyObject } from 'crypto'; import { step } from 'mocha-steps'; import { assert } from 'chai'; -import { u8aToHex, bufferToU8a } from '@polkadot/util'; -import { buildIdentityFromKeypair, initIntegrationTestContext, PolkadotSigner } from './common/utils'; +import { buildIdentityFromKeypair, initIntegrationTestContext, PolkadotSigner, sleep } from './common/utils'; import { assertIsInSidechainBlock, assertVc } from './common/utils/assertion'; import { getSidechainNonce, - createSignedTrustedCallLinkIdentity, getTeeShieldingKey, sendRequestFromTrustedCall, createSignedTrustedCallRequestVc, } from './common/di-utils'; // @fixme move to a better place import type { IntegrationTestContext } from './common/common-types'; import { CorePrimitivesIdentity } from 'parachain-api'; -import { LitentryValidationData, Web3Network } from 'parachain-api'; -import { Vec } from '@polkadot/types'; -import { spawn } from 'child_process'; import { aesKey } from './common/call'; import { $ as zx } from 'zx'; -import {credentialDefinitionMap} from './common/credential-definitions' +import { credentialDefinitionMap } from './common/credential-definitions'; describe('Test Vc (direct invocation)', function () { let context: IntegrationTestContext = undefined as any; let teeShieldingKey: KeyObject = undefined as any; @@ -29,10 +24,7 @@ describe('Test Vc (direct invocation)', function () { this.timeout(6000000); before(async () => { - context = await initIntegrationTestContext( - process.env.WORKER_ENDPOINT!, // @fixme evil assertion; centralize env access - process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access - ); + context = await initIntegrationTestContext(process.env.WORKER_ENDPOINT!, process.env.NODE_ENDPOINT!); teeShieldingKey = await getTeeShieldingKey(context); aliceSubstrateIdentity = await buildIdentityFromKeypair( new PolkadotSigner(context.substrateWallet.alice), @@ -40,36 +32,29 @@ describe('Test Vc (direct invocation)', function () { ); }); - step(`create idGrapgh via cli`, async function () { - // console.log(process.argv); + // todo: get process args from command line - // const evmIndex = process.argv.indexOf('--evm'); - // if (evmIndex > -1) { - // const evmAddress = process.argv[evmIndex + 1]; - // console.log(evmAddress); - // } + try { + const linkResult = await zx`${client} trusted -d link-identity did:litentry:substrate:${aliceAddressFormat}\ + did:${credentialDefinitionMap['vip3-membership-card-gold'].mockDid}\ + ${credentialDefinitionMap['vip3-membership-card-gold'].mockWeb3Network}`; - // todo: check idgrpah ,if exist, skip, else create - - // check idgraph if identity exist - - - // try { - // const linkResult = await zx`${client} trusted -d link-identity did:litentry:substrate:${aliceAddressFormat} did:litentry:evm:0x651614cA9097C5ba189Ef85e7851Ef9cff592B2b bsc,ethereum`; - // console.log(linkResult); - - // } catch (error: any) { - // console.log(`Exit code: ${error.exitCode}`); - // console.log(`Error: ${error.stderr}`); - // } + console.log(linkResult); + } catch (error: any) { + console.log(`Exit code: ${error.exitCode}`); + console.log(`Error: ${error.stderr}`); + } + await sleep(10); + // todo: listen to event }); step(`request vc`, async function () { const assertion = { - [credentialDefinitionMap['vip3-membership-card-gold'].assertion.id]: credentialDefinitionMap['vip3-membership-card-gold'].assertion.payload - } + [credentialDefinitionMap['vip3-membership-card-gold'].assertion.id]: + credentialDefinitionMap['vip3-membership-card-gold'].assertion.payload, + }; let currentNonce = (await getSidechainNonce(context, teeShieldingKey, aliceSubstrateIdentity)).toNumber(); const getNextNonce = () => currentNonce++; const nonce = getNextNonce(); From 568f33657c4891260a3a07a51c1e55ddfaff6190 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Thu, 25 Jan 2024 14:55:26 +0000 Subject: [PATCH 08/32] add event listening --- .../vip3/vip3-membership-card-gold.ts | 2 +- .../ts-tests/integration-tests/data-provider.test.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts index d14ac951df..2b4546e392 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts @@ -3,7 +3,7 @@ import * as dataProviders from '../config/data-providers'; import { Networks, AccountNetworks } from '../config/networks'; import { CredentialDefinition } from '../config/types'; -const mockAddress: HexString = '0x651614cA9097C5ba189Ef85e7851Ef9cff592B2c'; +const mockAddress: HexString = '0x651614cA9097C5ba189Ef85e7851Ef9cff592B22'; export const vip3MembershipCardGold: CredentialDefinition = { id: 'vip3-membership-card-gold', name: 'VIP3 Membership Card Gold', diff --git a/tee-worker/ts-tests/integration-tests/data-provider.test.ts b/tee-worker/ts-tests/integration-tests/data-provider.test.ts index 521ba12a2d..286dfb92c7 100644 --- a/tee-worker/ts-tests/integration-tests/data-provider.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-provider.test.ts @@ -13,16 +13,16 @@ import type { IntegrationTestContext } from './common/common-types'; import { CorePrimitivesIdentity } from 'parachain-api'; import { aesKey } from './common/call'; import { $ as zx } from 'zx'; - import { credentialDefinitionMap } from './common/credential-definitions'; +import { subscribeToEventsWithExtHash } from './common/transactions'; describe('Test Vc (direct invocation)', function () { let context: IntegrationTestContext = undefined as any; let teeShieldingKey: KeyObject = undefined as any; let aliceSubstrateIdentity: CorePrimitivesIdentity = undefined as any; const client = process.env.BINARY_DIR + '/litentry-cli'; const aliceAddressFormat = '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d'; + const reqExtHash = '0x0000000000000000000000000000000000000000000000000000000000000000'; this.timeout(6000000); - before(async () => { context = await initIntegrationTestContext(process.env.WORKER_ENDPOINT!, process.env.NODE_ENDPOINT!); teeShieldingKey = await getTeeShieldingKey(context); @@ -34,6 +34,7 @@ describe('Test Vc (direct invocation)', function () { step(`create idGrapgh via cli`, async function () { // todo: get process args from command line + const eventsPromise = subscribeToEventsWithExtHash(reqExtHash, context); try { const linkResult = await zx`${client} trusted -d link-identity did:litentry:substrate:${aliceAddressFormat}\ @@ -44,9 +45,11 @@ describe('Test Vc (direct invocation)', function () { } catch (error: any) { console.log(`Exit code: ${error.exitCode}`); console.log(`Error: ${error.stderr}`); + throw error; } - await sleep(10); + const events = (await eventsPromise).map(({ event }) => event); + assert.equal(events.length, 1); // todo: listen to event }); From c6504e2020f02d9fdbf6c70404d85da34d927f7d Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Thu, 25 Jan 2024 14:58:47 +0000 Subject: [PATCH 09/32] complete vip3 tests --- tee-worker/ts-tests/integration-tests/data-provider.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tee-worker/ts-tests/integration-tests/data-provider.test.ts b/tee-worker/ts-tests/integration-tests/data-provider.test.ts index 286dfb92c7..73c693947d 100644 --- a/tee-worker/ts-tests/integration-tests/data-provider.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-provider.test.ts @@ -1,7 +1,7 @@ import { randomBytes, KeyObject } from 'crypto'; import { step } from 'mocha-steps'; import { assert } from 'chai'; -import { buildIdentityFromKeypair, initIntegrationTestContext, PolkadotSigner, sleep } from './common/utils'; +import { buildIdentityFromKeypair, initIntegrationTestContext, PolkadotSigner } from './common/utils'; import { assertIsInSidechainBlock, assertVc } from './common/utils/assertion'; import { getSidechainNonce, @@ -32,6 +32,8 @@ describe('Test Vc (direct invocation)', function () { ); }); + + // todo: test in parallel or another way step(`create idGrapgh via cli`, async function () { // todo: get process args from command line const eventsPromise = subscribeToEventsWithExtHash(reqExtHash, context); @@ -50,7 +52,6 @@ describe('Test Vc (direct invocation)', function () { const events = (await eventsPromise).map(({ event }) => event); assert.equal(events.length, 1); - // todo: listen to event }); step(`request vc`, async function () { From 6738c7982496c826e65ab93bb452c22b5758fe6e Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Thu, 25 Jan 2024 14:59:49 +0000 Subject: [PATCH 10/32] fix vip3MembershipCardSliver --- .../credential-definitions/vip3/vip3-membership-card-sliver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts index b871a05708..c315c56d55 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts @@ -10,7 +10,7 @@ export const vip3MembershipCardSliver: CredentialDefinition = { description: 'VIP3 Membership Card Sliver', assertion: { id: 'Vip3MembershipCard', - payload: 'sliver', + payload: 'Sliver', }, dataProvider: dataProviders.vip3, network: Networks['ethereum'], From d2ec75723394f09f254c01e0133e712dfe079ea0 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Fri, 26 Jan 2024 08:22:32 +0000 Subject: [PATCH 11/32] add to ci.yml --- .github/workflows/ci.yml | 2 + tee-worker/docker/lit-data-providers-test.yml | 24 ++++ .../achainable/token-holder-dot.ts | 31 +++++ .../achainable/token-holder-eth.ts | 31 +++++ .../credential-definitions/config/types.ts | 1 + .../common/credential-definitions/index.ts | 11 +- .../vip3/vip3-membership-card-gold.ts | 5 +- .../vip3/vip3-membership-card-sliver.ts | 14 ++- .../common/utils/assertion.ts | 2 - .../integration-tests/data-provider.test.ts | 80 ------------- .../integration-tests/data-providers.test.ts | 111 ++++++++++++++++++ .../ts-tests/integration-tests/package.json | 3 +- 12 files changed, 222 insertions(+), 93 deletions(-) create mode 100644 tee-worker/docker/lit-data-providers-test.yml create mode 100644 tee-worker/ts-tests/integration-tests/common/credential-definitions/achainable/token-holder-dot.ts create mode 100644 tee-worker/ts-tests/integration-tests/common/credential-definitions/achainable/token-holder-eth.ts delete mode 100644 tee-worker/ts-tests/integration-tests/data-provider.test.ts create mode 100644 tee-worker/ts-tests/integration-tests/data-providers.test.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cfe52a969b..57bb7a606d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -708,6 +708,8 @@ jobs: - test_name: lit-ii-identity-multiworker-test - test_name: lit-ii-vc-multiworker-test - test_name: lit-resume-worker + - test_name: lit-data-providers-test + steps: - uses: actions/checkout@v4 diff --git a/tee-worker/docker/lit-data-providers-test.yml b/tee-worker/docker/lit-data-providers-test.yml new file mode 100644 index 0000000000..9d674e0c71 --- /dev/null +++ b/tee-worker/docker/lit-data-providers-test.yml @@ -0,0 +1,24 @@ +services: + lit-di-bitcoin-identity-test: + image: litentry/litentry-cli:latest + container_name: litentry-data-providers-test + volumes: + - ../ts-tests:/ts-tests + - ../client-api:/client-api + - ../cli:/usr/local/worker-cli + build: + context: .. + dockerfile: build.Dockerfile + target: deployed-client + depends_on: + litentry-node: + condition: service_healthy + litentry-worker-1: + condition: service_healthy + networks: + - litentry-test-network + entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh test-data-providers-test 2>&1' " + restart: "no" +networks: + litentry-test-network: + driver: bridge diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/achainable/token-holder-dot.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/achainable/token-holder-dot.ts new file mode 100644 index 0000000000..9780b06f7b --- /dev/null +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/achainable/token-holder-dot.ts @@ -0,0 +1,31 @@ +import { HexString } from '@polkadot/util/types'; +import * as dataProviders from '../config/data-providers'; +import { Networks, AccountNetworks } from '../config/networks'; +import { CredentialDefinition } from '../config/types'; + +// https://polkadot.subscan.io/tools/format_transform +const mockAddress: HexString = '0xf20107661944f8a00a418d864292885767a2942e92abb5d3cdaf243fe065c171'; +export const tokenHolderDot: CredentialDefinition = { + id: 'token-holder-dot', + name: 'DOT Holder', + description: `The number of DOT tokens you hold > 0`, + assertion: { + id: 'Achainable', + payload: { + Amount: { + name: 'Balance over {amount}', + chain: 'Polkadot', + amount: '0', + }, + }, + }, + dataProvider: dataProviders.achainable, + network: Networks['polkadot'], + + // mock data for link-identity via cli + // https://github.com/litentry/litentry-parachain/blob/dev/tee-worker/cli/src/trusted_base_cli/commands/litentry/link_identity.rs + mockDid: `litentry:${AccountNetworks['substrate']}:${mockAddress}`, + mockWeb3Network: `${Networks['litentry']},${Networks['kusama']}`, + + expectedCredentialValue: true, +}; diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/achainable/token-holder-eth.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/achainable/token-holder-eth.ts new file mode 100644 index 0000000000..5bc801bb4e --- /dev/null +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/achainable/token-holder-eth.ts @@ -0,0 +1,31 @@ +import { HexString } from '@polkadot/util/types'; +import * as dataProviders from '../config/data-providers'; +import { Networks, AccountNetworks } from '../config/networks'; +import { CredentialDefinition } from '../config/types'; + +// https://polkadot.subscan.io/tools/format_transform +const mockAddress: HexString = '0xbB613509f2590ca489863551E7A27E89B863A8BD'; +export const tokenHolderEth: CredentialDefinition = { + id: 'token-holder-eth', + name: 'ETH Holder', + description: `The number of ETH tokens you hold > 0`, + assertion: { + id: 'Achainable', + payload: { + Amount: { + name: 'Balance over {amount}', + chain: 'Ethereum', + amount: '0', + }, + }, + }, + dataProvider: dataProviders.achainable, + network: Networks['ethereum'], + + // mock data for link-identity via cli + // https://github.com/litentry/litentry-parachain/blob/dev/tee-worker/cli/src/trusted_base_cli/commands/litentry/link_identity.rs + mockDid: `litentry:${AccountNetworks['evm']}:${mockAddress}`, + mockWeb3Network: `${Networks['bsc']},${Networks['ethereum']}`, + + expectedCredentialValue: true, +}; diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/types.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/types.ts index a231cdc8ef..132d712647 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/types.ts +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/types.ts @@ -17,4 +17,5 @@ export interface CredentialDefinition { network: CorePrimitivesNetworkWeb3Network['type']; mockDid: string; mockWeb3Network: string; + expectedCredentialValue: boolean; } diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/index.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/index.ts index 79d29c2d14..b484bbe4a2 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/index.ts +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/index.ts @@ -1,7 +1,10 @@ import { vip3MembershipCardGold } from './vip3/vip3-membership-card-gold'; -import { vip3MembershipCardSliver } from './vip3/vip3-membership-card-sliver'; - -export const credentialDefinitionMap = { +import { vip3MembershipCardSilver } from './vip3/vip3-membership-card-sliver'; +import { tokenHolderDot } from './achainable/token-holder-dot'; +import { tokenHolderEth } from './achainable/token-holder-eth'; +export const credentialDefinitionMap: any = { 'vip3-membership-card-gold': vip3MembershipCardGold, - 'vip3-membership-card-sliver': vip3MembershipCardSliver, + 'vip3-membership-card-silver': vip3MembershipCardSilver, + // 'token-holder-dot': tokenHolderDot, + // 'token-holder-eth': tokenHolderEth, }; diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts index 2b4546e392..50df3a6169 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts @@ -3,7 +3,7 @@ import * as dataProviders from '../config/data-providers'; import { Networks, AccountNetworks } from '../config/networks'; import { CredentialDefinition } from '../config/types'; -const mockAddress: HexString = '0x651614cA9097C5ba189Ef85e7851Ef9cff592B22'; +const mockAddress: HexString = '0x651614cA9097C5ba189Ef85e7851Ef9cff592B2c'; export const vip3MembershipCardGold: CredentialDefinition = { id: 'vip3-membership-card-gold', name: 'VIP3 Membership Card Gold', @@ -16,6 +16,9 @@ export const vip3MembershipCardGold: CredentialDefinition = { network: Networks['ethereum'], // mock data for link-identity via cli + // https://github.com/litentry/litentry-parachain/blob/dev/tee-worker/cli/src/trusted_base_cli/commands/litentry/link_identity.rs mockDid: `litentry:${AccountNetworks['evm']}:${mockAddress}`, mockWeb3Network: `${Networks['bsc']},${Networks['ethereum']}`, + + expectedCredentialValue: true, }; diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts index c315c56d55..2002027636 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts @@ -3,18 +3,22 @@ import * as dataProviders from '../config/data-providers'; import { AccountNetworks, Networks } from '../config/networks'; import { CredentialDefinition } from '../config/types'; -const mockAddress: HexString = '0x651614cA9097C5ba189Ef85e7851Ef9cff592B2b'; -export const vip3MembershipCardSliver: CredentialDefinition = { - id: 'vip3-membership-card-sliver', +const mockAddress: HexString = '0x651614cA9097C5ba189Ef85e7851Ef9cff592B2c'; +export const vip3MembershipCardSilver: CredentialDefinition = { + id: 'vip3-membership-card-silver', name: 'VIP3 Membership Card Sliver', - description: 'VIP3 Membership Card Sliver', + description: 'VIP3 Membership Card Silver', assertion: { id: 'Vip3MembershipCard', - payload: 'Sliver', + payload: 'Silver', }, dataProvider: dataProviders.vip3, network: Networks['ethereum'], + // mock data for link-identity via cli + // https://github.com/litentry/litentry-parachain/blob/dev/tee-worker/cli/src/trusted_base_cli/commands/litentry/link_identity.rs mockDid: `litentry:${AccountNetworks['evm']}:${mockAddress}`, mockWeb3Network: `${Networks['bsc']},${Networks['ethereum']}`, + + expectedCredentialValue: true, }; diff --git a/tee-worker/ts-tests/integration-tests/common/utils/assertion.ts b/tee-worker/ts-tests/integration-tests/common/utils/assertion.ts index ca817e4892..fee60cc199 100644 --- a/tee-worker/ts-tests/integration-tests/common/utils/assertion.ts +++ b/tee-worker/ts-tests/integration-tests/common/utils/assertion.ts @@ -273,8 +273,6 @@ export async function assertVc(context: IntegrationTestContext, subject: CorePri // extrac proof and vc without proof json const vcPayloadJson = JSON.parse(decryptVcPayload); - console.log('vcPayloadJson: ', vcPayloadJson); - const { proof, ...vcWithoutProof } = vcPayloadJson; // step 5 diff --git a/tee-worker/ts-tests/integration-tests/data-provider.test.ts b/tee-worker/ts-tests/integration-tests/data-provider.test.ts deleted file mode 100644 index 73c693947d..0000000000 --- a/tee-worker/ts-tests/integration-tests/data-provider.test.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { randomBytes, KeyObject } from 'crypto'; -import { step } from 'mocha-steps'; -import { assert } from 'chai'; -import { buildIdentityFromKeypair, initIntegrationTestContext, PolkadotSigner } from './common/utils'; -import { assertIsInSidechainBlock, assertVc } from './common/utils/assertion'; -import { - getSidechainNonce, - getTeeShieldingKey, - sendRequestFromTrustedCall, - createSignedTrustedCallRequestVc, -} from './common/di-utils'; // @fixme move to a better place -import type { IntegrationTestContext } from './common/common-types'; -import { CorePrimitivesIdentity } from 'parachain-api'; -import { aesKey } from './common/call'; -import { $ as zx } from 'zx'; -import { credentialDefinitionMap } from './common/credential-definitions'; -import { subscribeToEventsWithExtHash } from './common/transactions'; -describe('Test Vc (direct invocation)', function () { - let context: IntegrationTestContext = undefined as any; - let teeShieldingKey: KeyObject = undefined as any; - let aliceSubstrateIdentity: CorePrimitivesIdentity = undefined as any; - const client = process.env.BINARY_DIR + '/litentry-cli'; - const aliceAddressFormat = '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d'; - const reqExtHash = '0x0000000000000000000000000000000000000000000000000000000000000000'; - this.timeout(6000000); - before(async () => { - context = await initIntegrationTestContext(process.env.WORKER_ENDPOINT!, process.env.NODE_ENDPOINT!); - teeShieldingKey = await getTeeShieldingKey(context); - aliceSubstrateIdentity = await buildIdentityFromKeypair( - new PolkadotSigner(context.substrateWallet.alice), - context - ); - }); - - - // todo: test in parallel or another way - step(`create idGrapgh via cli`, async function () { - // todo: get process args from command line - const eventsPromise = subscribeToEventsWithExtHash(reqExtHash, context); - - try { - const linkResult = await zx`${client} trusted -d link-identity did:litentry:substrate:${aliceAddressFormat}\ - did:${credentialDefinitionMap['vip3-membership-card-gold'].mockDid}\ - ${credentialDefinitionMap['vip3-membership-card-gold'].mockWeb3Network}`; - - console.log(linkResult); - } 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); - }); - - step(`request vc`, async function () { - const assertion = { - [credentialDefinitionMap['vip3-membership-card-gold'].assertion.id]: - credentialDefinitionMap['vip3-membership-card-gold'].assertion.payload, - }; - let currentNonce = (await getSidechainNonce(context, teeShieldingKey, aliceSubstrateIdentity)).toNumber(); - const getNextNonce = () => currentNonce++; - const nonce = getNextNonce(); - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const requestVcCall = await createSignedTrustedCallRequestVc( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - new PolkadotSigner(context.substrateWallet.alice), - aliceSubstrateIdentity, - context.api.createType('Assertion', assertion).toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier - ); - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, requestVcCall); - await assertIsInSidechainBlock(`${Object.keys(assertion)[0]} requestVcCall`, res); - await assertVc(context, aliceSubstrateIdentity, res.value); - }); -}); diff --git a/tee-worker/ts-tests/integration-tests/data-providers.test.ts b/tee-worker/ts-tests/integration-tests/data-providers.test.ts new file mode 100644 index 0000000000..492a258e77 --- /dev/null +++ b/tee-worker/ts-tests/integration-tests/data-providers.test.ts @@ -0,0 +1,111 @@ +import { randomBytes, KeyObject } from 'crypto'; +import { step } from 'mocha-steps'; +import { assert } from 'chai'; +import { buildIdentityFromKeypair, decryptWithAes, initIntegrationTestContext, PolkadotSigner } from './common/utils'; +import { assertIsInSidechainBlock, assertVc } from './common/utils/assertion'; +import { + getSidechainNonce, + getTeeShieldingKey, + sendRequestFromTrustedCall, + createSignedTrustedCallRequestVc, +} from './common/di-utils'; // @fixme move to a better place +import type { IntegrationTestContext } from './common/common-types'; +import { CorePrimitivesIdentity, RequestVCResult } from 'parachain-api'; +import { aesKey } from './common/call'; +import { $ as zx } from 'zx'; +import { credentialDefinitionMap } from './common/credential-definitions'; +import { subscribeToEventsWithExtHash } from './common/transactions'; +describe('Test Vc (direct invocation)', function () { + let context: IntegrationTestContext = undefined as any; + let teeShieldingKey: KeyObject = undefined as any; + let aliceSubstrateIdentity: CorePrimitivesIdentity = undefined as any; + const client = process.env.BINARY_DIR + '/litentry-cli'; + const aliceAddressFormat = '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d'; + const reqExtHash = '0x0000000000000000000000000000000000000000000000000000000000000000'; + let argvId = ''; + this.timeout(6000000); + before(async () => { + context = await initIntegrationTestContext(process.env.WORKER_ENDPOINT!, process.env.NODE_ENDPOINT!); + teeShieldingKey = await getTeeShieldingKey(context); + aliceSubstrateIdentity = await buildIdentityFromKeypair( + new PolkadotSigner(context.substrateWallet.alice), + context + ); + }); + + // usage example: + // pnpm run test-data-providers:local --id=vip3-membership-card-gold for single test + // pnpm run test-data-providers:local for all tests + const argv = process.argv.indexOf('--id'); + argvId = process.argv[argv + 1]; + // eslint-disable-next-line no-prototype-builtins + if (argvId && credentialDefinitionMap.hasOwnProperty(argvId)) { + step(`linking identity-${credentialDefinitionMap[argvId].mockAddress} via cli`, async function () { + const eventsPromise = subscribeToEventsWithExtHash(reqExtHash, context); + try { + await zx`${client} trusted -d link-identity did:litentry:substrate:${aliceAddressFormat}\ + did:${credentialDefinitionMap[argvId].mockDid}\ + ${credentialDefinitionMap[argvId].mockWeb3Network}`; + } 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); + }); + } else { + Object.keys(credentialDefinitionMap).forEach((id) => { + step(`linking identity-${credentialDefinitionMap[id].mockAddress} via cli`, async function () { + const eventsPromise = subscribeToEventsWithExtHash(reqExtHash, context); + try { + await zx`${client} trusted -d link-identity did:litentry:substrate:${aliceAddressFormat}\ + did:${credentialDefinitionMap[id].mockDid}\ + ${credentialDefinitionMap[id].mockWeb3Network}`; + } 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); + }); + }); + } + + Object.keys(credentialDefinitionMap).forEach((id) => { + step(`request vc for ${credentialDefinitionMap[id]}`, async function () { + const assertion = { + [credentialDefinitionMap[id].assertion.id]: credentialDefinitionMap[id].assertion.payload, + }; + console.log(assertion); + + let currentNonce = (await getSidechainNonce(context, teeShieldingKey, aliceSubstrateIdentity)).toNumber(); + const getNextNonce = () => currentNonce++; + const nonce = getNextNonce(); + const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; + const requestVcCall = await createSignedTrustedCallRequestVc( + context.api, + context.mrEnclave, + context.api.createType('Index', nonce), + new PolkadotSigner(context.substrateWallet.alice), + aliceSubstrateIdentity, + context.api.createType('Assertion', assertion).toHex(), + 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) as unknown as RequestVCResult; + const decryptVcPayload = decryptWithAes(aesKey, vcResults.vc_payload, 'utf-8').replace('0x', ''); + const vcPayloadJson = JSON.parse(decryptVcPayload); + + assert.equal( + vcPayloadJson.credentialSubject.values[0], + credentialDefinitionMap[id].expectedCredentialValue + ); + }); + }); +}); diff --git a/tee-worker/ts-tests/integration-tests/package.json b/tee-worker/ts-tests/integration-tests/package.json index 9e132ee276..1e5f3dd9a7 100644 --- a/tee-worker/ts-tests/integration-tests/package.json +++ b/tee-worker/ts-tests/integration-tests/package.json @@ -19,7 +19,8 @@ "test-ii-vc:staging": "pnpm exec eslint . && pnpm exec cross-env NODE_ENV=staging mocha --exit --sort -r ts-node/register --loader=ts-node/esm 'ii_vc.test.ts'", "test-ii-batch:local": "pnpm exec eslint . && pnpm exec cross-env NODE_ENV=local mocha --exit --sort -r ts-node/register --loader=ts-node/esm 'ii_batch.test.ts'", "test-ii-batch:staging": "pnpm exec eslint . && pnpm exec cross-env NODE_ENV=staging mocha --exit --sort -r ts-node/register --loader=ts-node/esm 'ii_batch.test.ts'", - "test-data-provider:local": "pnpm exec eslint . && pnpm exec cross-env NODE_ENV=local mocha --exit --sort -r ts-node/register --loader=ts-node/esm 'data-provider.test.ts'" + "test-data-providers:local": "pnpm exec eslint . && pnpm exec cross-env NODE_ENV=local mocha --exit --sort -r ts-node/register --loader=ts-node/esm 'data-providers.test.ts'", + "test-data-providers:staging": "pnpm exec eslint . && pnpm exec cross-env NODE_ENV=staging mocha --exit --sort -r ts-node/register --loader=ts-node/esm 'data-providers.test.ts'" }, "dependencies": { "@noble/ed25519": "^1.7.3", From e51c132b8e5949944d71cd978640f013437e4975 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Fri, 26 Jan 2024 08:55:20 +0000 Subject: [PATCH 12/32] fix ci --- .github/workflows/ci.yml | 3 +-- tee-worker/docker/lit-data-providers-test.yml | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57bb7a606d..99cb9eedb0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -625,6 +625,7 @@ jobs: - test_name: lit-parentchain-nonce - test_name: lit-ii-batch-test - test_name: lit-test-stress-script + - test_name: lit-data-providers-test steps: - uses: actions/checkout@v4 @@ -708,8 +709,6 @@ jobs: - test_name: lit-ii-identity-multiworker-test - test_name: lit-ii-vc-multiworker-test - test_name: lit-resume-worker - - test_name: lit-data-providers-test - steps: - uses: actions/checkout@v4 diff --git a/tee-worker/docker/lit-data-providers-test.yml b/tee-worker/docker/lit-data-providers-test.yml index 9d674e0c71..be0ee66ed4 100644 --- a/tee-worker/docker/lit-data-providers-test.yml +++ b/tee-worker/docker/lit-data-providers-test.yml @@ -1,5 +1,5 @@ services: - lit-di-bitcoin-identity-test: + lit-data-providers-test: image: litentry/litentry-cli:latest container_name: litentry-data-providers-test volumes: @@ -17,7 +17,7 @@ services: condition: service_healthy networks: - litentry-test-network - entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh test-data-providers-test 2>&1' " + entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh test-data-providers 2>&1' " restart: "no" networks: litentry-test-network: From 248fb0a41c16d05f5800099aadcfa21f4c00d717 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Fri, 26 Jan 2024 09:42:03 +0000 Subject: [PATCH 13/32] extract and reuse function --- .../integration-tests/data-providers.test.ts | 48 ++++++++----------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/tee-worker/ts-tests/integration-tests/data-providers.test.ts b/tee-worker/ts-tests/integration-tests/data-providers.test.ts index 492a258e77..50c4b430ce 100644 --- a/tee-worker/ts-tests/integration-tests/data-providers.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-providers.test.ts @@ -2,7 +2,7 @@ import { randomBytes, KeyObject } from 'crypto'; import { step } from 'mocha-steps'; import { assert } from 'chai'; import { buildIdentityFromKeypair, decryptWithAes, initIntegrationTestContext, PolkadotSigner } from './common/utils'; -import { assertIsInSidechainBlock, assertVc } from './common/utils/assertion'; +import { assertIsInSidechainBlock } from './common/utils/assertion'; import { getSidechainNonce, getTeeShieldingKey, @@ -38,38 +38,32 @@ describe('Test Vc (direct invocation)', function () { // pnpm run test-data-providers:local for all tests const argv = process.argv.indexOf('--id'); argvId = process.argv[argv + 1]; + + async function linkIdentityViaCli(id: string) { + const eventsPromise = subscribeToEventsWithExtHash(reqExtHash, context); + try { + await zx`${client} trusted -d link-identity did:litentry:substrate:${aliceAddressFormat}\ + did:${credentialDefinitionMap[id].mockDid}\ + ${credentialDefinitionMap[id].mockWeb3Network}`; + } 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); + } + // eslint-disable-next-line no-prototype-builtins if (argvId && credentialDefinitionMap.hasOwnProperty(argvId)) { - step(`linking identity-${credentialDefinitionMap[argvId].mockAddress} via cli`, async function () { - const eventsPromise = subscribeToEventsWithExtHash(reqExtHash, context); - try { - await zx`${client} trusted -d link-identity did:litentry:substrate:${aliceAddressFormat}\ - did:${credentialDefinitionMap[argvId].mockDid}\ - ${credentialDefinitionMap[argvId].mockWeb3Network}`; - } 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); + step(`linking identity-${credentialDefinitionMap[argvId].mockDid} via cli`, async function () { + await linkIdentityViaCli(argvId); }); } else { Object.keys(credentialDefinitionMap).forEach((id) => { step(`linking identity-${credentialDefinitionMap[id].mockAddress} via cli`, async function () { - const eventsPromise = subscribeToEventsWithExtHash(reqExtHash, context); - try { - await zx`${client} trusted -d link-identity did:litentry:substrate:${aliceAddressFormat}\ - did:${credentialDefinitionMap[id].mockDid}\ - ${credentialDefinitionMap[id].mockWeb3Network}`; - } 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); + await linkIdentityViaCli(id); }); }); } From ed722f21386a92b3886d6c66c3ff3d4c0be7dcdd Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Fri, 26 Jan 2024 10:23:25 +0000 Subject: [PATCH 14/32] test cli --- .../ts-tests/integration-tests/data-providers.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tee-worker/ts-tests/integration-tests/data-providers.test.ts b/tee-worker/ts-tests/integration-tests/data-providers.test.ts index 50c4b430ce..455b84d042 100644 --- a/tee-worker/ts-tests/integration-tests/data-providers.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-providers.test.ts @@ -19,7 +19,12 @@ describe('Test Vc (direct invocation)', function () { let context: IntegrationTestContext = undefined as any; let teeShieldingKey: KeyObject = undefined as any; let aliceSubstrateIdentity: CorePrimitivesIdentity = undefined as any; - const client = process.env.BINARY_DIR + '/litentry-cli'; + + // CLIENT="${CLIENT_BIN} -p ${LITENTRY_RPC_PORT} -P ${WORKER_1_PORT} -u ${LITENTRY_RPC_URL} -U ${WORKER_1_URL}" + + const binPath = process.env.BINARY_DIR + '/litentry-cli'; + const client = binPath + ' -p ' + 9912 + ' -P ' + 2011 + ' -u ' + 'ws://litentry-node' + ' -U ' + 'wss://litentry-worker-1'; + const aliceAddressFormat = '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d'; const reqExtHash = '0x0000000000000000000000000000000000000000000000000000000000000000'; let argvId = ''; From 41b613a166bf23519f7099eaf1f6cb49a5a2e48e Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Fri, 26 Jan 2024 10:29:58 +0000 Subject: [PATCH 15/32] format --- tee-worker/ts-tests/integration-tests/data-providers.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tee-worker/ts-tests/integration-tests/data-providers.test.ts b/tee-worker/ts-tests/integration-tests/data-providers.test.ts index 455b84d042..f3417da6e0 100644 --- a/tee-worker/ts-tests/integration-tests/data-providers.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-providers.test.ts @@ -23,8 +23,9 @@ describe('Test Vc (direct invocation)', function () { // CLIENT="${CLIENT_BIN} -p ${LITENTRY_RPC_PORT} -P ${WORKER_1_PORT} -u ${LITENTRY_RPC_URL} -U ${WORKER_1_URL}" const binPath = process.env.BINARY_DIR + '/litentry-cli'; - const client = binPath + ' -p ' + 9912 + ' -P ' + 2011 + ' -u ' + 'ws://litentry-node' + ' -U ' + 'wss://litentry-worker-1'; - + const client = + binPath + ' -p ' + 9912 + ' -P ' + 2011 + ' -u ' + 'ws://litentry-node' + ' -U ' + 'wss://litentry-worker-1'; + const aliceAddressFormat = '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d'; const reqExtHash = '0x0000000000000000000000000000000000000000000000000000000000000000'; let argvId = ''; From e5dd23b7314bf382a41220d02944899df2b14998 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Fri, 26 Jan 2024 11:49:59 +0000 Subject: [PATCH 16/32] remove client config --- .../ts-tests/integration-tests/data-providers.test.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tee-worker/ts-tests/integration-tests/data-providers.test.ts b/tee-worker/ts-tests/integration-tests/data-providers.test.ts index f3417da6e0..30c1de8db4 100644 --- a/tee-worker/ts-tests/integration-tests/data-providers.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-providers.test.ts @@ -22,10 +22,8 @@ describe('Test Vc (direct invocation)', function () { // CLIENT="${CLIENT_BIN} -p ${LITENTRY_RPC_PORT} -P ${WORKER_1_PORT} -u ${LITENTRY_RPC_URL} -U ${WORKER_1_URL}" - const binPath = process.env.BINARY_DIR + '/litentry-cli'; - const client = - binPath + ' -p ' + 9912 + ' -P ' + 2011 + ' -u ' + 'ws://litentry-node' + ' -U ' + 'wss://litentry-worker-1'; - + const client = process.env.BINARY_DIR + '/litentry-cli'; + const aliceAddressFormat = '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d'; const reqExtHash = '0x0000000000000000000000000000000000000000000000000000000000000000'; let argvId = ''; From 79feee12579098914dedcf82298847793b7897b9 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Fri, 26 Jan 2024 11:52:31 +0000 Subject: [PATCH 17/32] format --- tee-worker/ts-tests/integration-tests/data-providers.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tee-worker/ts-tests/integration-tests/data-providers.test.ts b/tee-worker/ts-tests/integration-tests/data-providers.test.ts index 30c1de8db4..b23dbb5a79 100644 --- a/tee-worker/ts-tests/integration-tests/data-providers.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-providers.test.ts @@ -23,7 +23,7 @@ describe('Test Vc (direct invocation)', function () { // CLIENT="${CLIENT_BIN} -p ${LITENTRY_RPC_PORT} -P ${WORKER_1_PORT} -u ${LITENTRY_RPC_URL} -U ${WORKER_1_URL}" const client = process.env.BINARY_DIR + '/litentry-cli'; - + const aliceAddressFormat = '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d'; const reqExtHash = '0x0000000000000000000000000000000000000000000000000000000000000000'; let argvId = ''; From 4a945eec2cdbfc8ca6a5d4749fae03edb67975e8 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Fri, 26 Jan 2024 13:32:43 +0000 Subject: [PATCH 18/32] random substrate wallet --- .../vip3/vip3-membership-card-sliver.ts | 2 +- .../integration-tests/common/helpers.ts | 6 + .../integration-tests/data-providers.test.ts | 123 ++++++++++-------- 3 files changed, 77 insertions(+), 54 deletions(-) diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts index 2002027636..180d6fa9db 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts @@ -3,7 +3,7 @@ import * as dataProviders from '../config/data-providers'; import { AccountNetworks, Networks } from '../config/networks'; import { CredentialDefinition } from '../config/types'; -const mockAddress: HexString = '0x651614cA9097C5ba189Ef85e7851Ef9cff592B2c'; +const mockAddress: HexString = '0x10CdF7F7A32E2F24c853AE6567b75D862Ee2B46f'; export const vip3MembershipCardSilver: CredentialDefinition = { id: 'vip3-membership-card-silver', name: 'VIP3 Membership Card Sliver', diff --git a/tee-worker/ts-tests/integration-tests/common/helpers.ts b/tee-worker/ts-tests/integration-tests/common/helpers.ts index 6d41721001..af685bf982 100644 --- a/tee-worker/ts-tests/integration-tests/common/helpers.ts +++ b/tee-worker/ts-tests/integration-tests/common/helpers.ts @@ -5,6 +5,7 @@ import type { KeyringPair } from '@polkadot/keyring/types'; import type { HexString } from '@polkadot/util/types'; import './config'; import { IntegrationTestContext, JsonRpcRequest } from './common-types'; +import { randomBytes } from 'crypto'; // format and setup const keyring = new Keyring({ type: 'sr25519' }); @@ -71,3 +72,8 @@ export function nextRequestId(context: IntegrationTestContext): number { context.requestId = nextId; return nextId; } + +export function randomSubstrateWallet(): KeyringPair { + const keyring = new Keyring({ type: 'sr25519' }); + return keyring.addFromSeed(randomBytes(32)); +} diff --git a/tee-worker/ts-tests/integration-tests/data-providers.test.ts b/tee-worker/ts-tests/integration-tests/data-providers.test.ts index b23dbb5a79..0e919918d6 100644 --- a/tee-worker/ts-tests/integration-tests/data-providers.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-providers.test.ts @@ -1,7 +1,14 @@ import { randomBytes, KeyObject } from 'crypto'; import { step } from 'mocha-steps'; import { assert } from 'chai'; -import { buildIdentityFromKeypair, decryptWithAes, initIntegrationTestContext, PolkadotSigner } from './common/utils'; +import { + buildIdentityFromKeypair, + decryptWithAes, + initIntegrationTestContext, + PolkadotSigner, + sleep, +} from './common/utils'; +import { randomSubstrateWallet } from './common/helpers'; import { assertIsInSidechainBlock } from './common/utils/assertion'; import { getSidechainNonce, @@ -15,38 +22,44 @@ import { aesKey } from './common/call'; import { $ as zx } from 'zx'; import { credentialDefinitionMap } from './common/credential-definitions'; import { subscribeToEventsWithExtHash } from './common/transactions'; +import { KeyringPair } from '@polkadot/keyring/types'; +import { u8aToHex } from '@polkadot/util'; + describe('Test Vc (direct invocation)', function () { let context: IntegrationTestContext = undefined as any; let teeShieldingKey: KeyObject = undefined as any; - let aliceSubstrateIdentity: CorePrimitivesIdentity = undefined as any; - - // CLIENT="${CLIENT_BIN} -p ${LITENTRY_RPC_PORT} -P ${WORKER_1_PORT} -u ${LITENTRY_RPC_URL} -U ${WORKER_1_URL}" + const substrateIdentities: CorePrimitivesIdentity[] = []; const client = process.env.BINARY_DIR + '/litentry-cli'; - const aliceAddressFormat = '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d'; const reqExtHash = '0x0000000000000000000000000000000000000000000000000000000000000000'; + const keyringPairs: KeyringPair[] = []; let argvId = ''; this.timeout(6000000); before(async () => { context = await initIntegrationTestContext(process.env.WORKER_ENDPOINT!, process.env.NODE_ENDPOINT!); teeShieldingKey = await getTeeShieldingKey(context); - aliceSubstrateIdentity = await buildIdentityFromKeypair( - new PolkadotSigner(context.substrateWallet.alice), - context - ); }); // usage example: - // pnpm run test-data-providers:local --id=vip3-membership-card-gold for single test - // pnpm run test-data-providers:local for all tests + // `pnpm run test-data-providers:local --id=vip3-membership-card-gold` for single test + // `pnpm run test-data-providers:local` for all tests const argv = process.argv.indexOf('--id'); argvId = process.argv[argv + 1]; async function linkIdentityViaCli(id: string) { + const keyringPair = randomSubstrateWallet(); + keyringPairs.push(keyringPair); + const formatAddress = u8aToHex(keyringPair.publicKey); + + const substrateIdentity = (await buildIdentityFromKeypair( + new PolkadotSigner(keyringPair), + context + )) as CorePrimitivesIdentity; + substrateIdentities.push(substrateIdentity); const eventsPromise = subscribeToEventsWithExtHash(reqExtHash, context); try { - await zx`${client} trusted -d link-identity did:litentry:substrate:${aliceAddressFormat}\ + await zx`${client} trusted -d link-identity did:litentry:substrate:${formatAddress}\ did:${credentialDefinitionMap[id].mockDid}\ ${credentialDefinitionMap[id].mockWeb3Network}`; } catch (error: any) { @@ -59,51 +72,55 @@ describe('Test Vc (direct invocation)', function () { assert.equal(events.length, 1); } - // eslint-disable-next-line no-prototype-builtins - if (argvId && credentialDefinitionMap.hasOwnProperty(argvId)) { - step(`linking identity-${credentialDefinitionMap[argvId].mockDid} via cli`, async function () { - await linkIdentityViaCli(argvId); - }); - } else { - Object.keys(credentialDefinitionMap).forEach((id) => { - step(`linking identity-${credentialDefinitionMap[id].mockAddress} via cli`, async function () { - await linkIdentityViaCli(id); - }); - }); - } + async function requestVc(id: string, index: number) { + const assertion = { + [credentialDefinitionMap[id].assertion.id]: credentialDefinitionMap[id].assertion.payload, + }; - Object.keys(credentialDefinitionMap).forEach((id) => { - step(`request vc for ${credentialDefinitionMap[id]}`, async function () { - const assertion = { - [credentialDefinitionMap[id].assertion.id]: credentialDefinitionMap[id].assertion.payload, - }; - console.log(assertion); + let currentNonce = (await getSidechainNonce(context, teeShieldingKey, substrateIdentities[index])).toNumber(); + const getNextNonce = () => currentNonce++; + const nonce = getNextNonce(); + console.log(nonce, substrateIdentities[index].toHuman(), u8aToHex(keyringPairs[index].publicKey)); - let currentNonce = (await getSidechainNonce(context, teeShieldingKey, aliceSubstrateIdentity)).toNumber(); - const getNextNonce = () => currentNonce++; - const nonce = getNextNonce(); - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const requestVcCall = await createSignedTrustedCallRequestVc( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - new PolkadotSigner(context.substrateWallet.alice), - aliceSubstrateIdentity, - context.api.createType('Assertion', assertion).toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier - ); - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, requestVcCall); - await assertIsInSidechainBlock(`${Object.keys(assertion)[0]} requestVcCall`, res); + const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; + const requestVcCall = await createSignedTrustedCallRequestVc( + context.api, + context.mrEnclave, + context.api.createType('Index', nonce), + new PolkadotSigner(keyringPairs[index]), + substrateIdentities[index], + context.api.createType('Assertion', assertion).toHex(), + 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) as unknown as RequestVCResult; - const decryptVcPayload = decryptWithAes(aesKey, vcResults.vc_payload, 'utf-8').replace('0x', ''); - const vcPayloadJson = JSON.parse(decryptVcPayload); + const vcResults = context.api.createType('RequestVCResult', res.value) as unknown as RequestVCResult; + const decryptVcPayload = decryptWithAes(aesKey, vcResults.vc_payload, 'utf-8').replace('0x', ''); + const vcPayloadJson = JSON.parse(decryptVcPayload); - assert.equal( - vcPayloadJson.credentialSubject.values[0], - credentialDefinitionMap[id].expectedCredentialValue + assert.equal(vcPayloadJson.credentialSubject.values[0], credentialDefinitionMap[id].expectedCredentialValue); + } + + // eslint-disable-next-line no-prototype-builtins + if (argvId && credentialDefinitionMap.hasOwnProperty(argvId)) { + step( + `linking identity::${credentialDefinitionMap[argvId].mockDid} via cli and request vc::${credentialDefinitionMap[argvId].id}`, + async function () { + await linkIdentityViaCli(argvId); + await requestVc(argvId, 0); + } + ); + } else { + Object.keys(credentialDefinitionMap).forEach((id, index) => { + step( + `linking identity::${credentialDefinitionMap[id].mockDid} via cli and request vc::${credentialDefinitionMap[id].id}`, + async function () { + await linkIdentityViaCli(id); + await requestVc(id, index); + } ); }); - }); + } }); From f76265a39b63fc172611ab7c59e9c1e4e56a28ee Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Fri, 26 Jan 2024 14:17:38 +0000 Subject: [PATCH 19/32] test client --- tee-worker/ts-tests/integration-tests/data-providers.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tee-worker/ts-tests/integration-tests/data-providers.test.ts b/tee-worker/ts-tests/integration-tests/data-providers.test.ts index 0e919918d6..a6f8feb8c5 100644 --- a/tee-worker/ts-tests/integration-tests/data-providers.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-providers.test.ts @@ -30,7 +30,7 @@ describe('Test Vc (direct invocation)', function () { let teeShieldingKey: KeyObject = undefined as any; const substrateIdentities: CorePrimitivesIdentity[] = []; - const client = process.env.BINARY_DIR + '/litentry-cli'; + const clientDir = process.env.BINARY_DIR + '/litentry-cli'; const reqExtHash = '0x0000000000000000000000000000000000000000000000000000000000000000'; const keyringPairs: KeyringPair[] = []; @@ -59,6 +59,8 @@ describe('Test Vc (direct invocation)', function () { substrateIdentities.push(substrateIdentity); const eventsPromise = subscribeToEventsWithExtHash(reqExtHash, context); try { + // CLIENT = "$CLIENT_BIN -p $NPORT -P $WORKER1PORT -u $NODEURL -U $WORKER1URL" + const client = zx`${clientDir} -p 9912 -P 2011 -u ws://litentry-node -U wss://litentry-worker-1`; await zx`${client} trusted -d link-identity did:litentry:substrate:${formatAddress}\ did:${credentialDefinitionMap[id].mockDid}\ ${credentialDefinitionMap[id].mockWeb3Network}`; From 24a4787861da39aed10c570dc8552ffd0acaefed Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Fri, 26 Jan 2024 15:27:52 +0000 Subject: [PATCH 20/32] fix cli issue --- .../integration-tests/.env.local.example | 2 +- .../integration-tests/data-providers.test.ts | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tee-worker/ts-tests/integration-tests/.env.local.example b/tee-worker/ts-tests/integration-tests/.env.local.example index b5c06ecc40..3c2a4abc4f 100644 --- a/tee-worker/ts-tests/integration-tests/.env.local.example +++ b/tee-worker/ts-tests/integration-tests/.env.local.example @@ -1,4 +1,4 @@ NODE_ENV = local WORKER_ENDPOINT = wss://localhost:2000 NODE_ENDPOINT = ws://localhost:9944 -BINARY_DIR=../../bin +BINARY_DIR=/bin diff --git a/tee-worker/ts-tests/integration-tests/data-providers.test.ts b/tee-worker/ts-tests/integration-tests/data-providers.test.ts index a6f8feb8c5..16c153ca3a 100644 --- a/tee-worker/ts-tests/integration-tests/data-providers.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-providers.test.ts @@ -30,8 +30,7 @@ describe('Test Vc (direct invocation)', function () { let teeShieldingKey: KeyObject = undefined as any; const substrateIdentities: CorePrimitivesIdentity[] = []; - const clientDir = process.env.BINARY_DIR + '/litentry-cli'; - + const clientDir = process.env.LITENTRY_CLI_DIR; const reqExtHash = '0x0000000000000000000000000000000000000000000000000000000000000000'; const keyringPairs: KeyringPair[] = []; let argvId = ''; @@ -46,6 +45,12 @@ describe('Test Vc (direct invocation)', function () { // `pnpm run test-data-providers:local` for all tests const argv = process.argv.indexOf('--id'); argvId = process.argv[argv + 1]; + const { + protocol: workerProtocal, + hostname: workerHostname, + port: workerPort, + } = new URL(process.env.WORKER_ENDPOINT!); + const { protocol: nodeProtocal, hostname: nodeHostname, port: nodePort } = new URL(process.env.NODE_ENDPOINT!); async function linkIdentityViaCli(id: string) { const keyringPair = randomSubstrateWallet(); @@ -60,10 +65,14 @@ describe('Test Vc (direct invocation)', function () { const eventsPromise = subscribeToEventsWithExtHash(reqExtHash, context); try { // CLIENT = "$CLIENT_BIN -p $NPORT -P $WORKER1PORT -u $NODEURL -U $WORKER1URL" - const client = zx`${clientDir} -p 9912 -P 2011 -u ws://litentry-node -U wss://litentry-worker-1`; - await zx`${client} trusted -d link-identity did:litentry:substrate:${formatAddress}\ + const commandPromise = zx`${clientDir} -p ${nodePort} -P ${workerPort} -u ${ + nodeProtocal + nodeHostname + } -U ${workerProtocal + workerHostname}\ + trusted -d link-identity did:litentry:substrate:${formatAddress}\ did:${credentialDefinitionMap[id].mockDid}\ ${credentialDefinitionMap[id].mockWeb3Network}`; + + await commandPromise; } catch (error: any) { console.log(`Exit code: ${error.exitCode}`); console.log(`Error: ${error.stderr}`); From 9d37fc23f6d6d301669825eb513d599d643c4239 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Fri, 26 Jan 2024 16:42:29 +0000 Subject: [PATCH 21/32] fix cli path --- tee-worker/ts-tests/integration-tests/.env.staging | 1 + 1 file changed, 1 insertion(+) diff --git a/tee-worker/ts-tests/integration-tests/.env.staging b/tee-worker/ts-tests/integration-tests/.env.staging index 6b035ce969..5951684479 100644 --- a/tee-worker/ts-tests/integration-tests/.env.staging +++ b/tee-worker/ts-tests/integration-tests/.env.staging @@ -2,3 +2,4 @@ NODE_ENV = staging WORKER_ENDPOINT = wss://litentry-worker-1:2011 NODE_ENDPOINT = "ws://litentry-node:9912" BINARY_DIR=/usr/local/bin +LITENTRY_CLI_DIR=usr/local/bin/litentry-cli \ No newline at end of file From 53843ae42cd64a62bb10d740e10c6b2722c50112 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Fri, 26 Jan 2024 16:46:14 +0000 Subject: [PATCH 22/32] env example --- tee-worker/ts-tests/integration-tests/.env.local.example | 1 + 1 file changed, 1 insertion(+) diff --git a/tee-worker/ts-tests/integration-tests/.env.local.example b/tee-worker/ts-tests/integration-tests/.env.local.example index 3c2a4abc4f..566ba8cce5 100644 --- a/tee-worker/ts-tests/integration-tests/.env.local.example +++ b/tee-worker/ts-tests/integration-tests/.env.local.example @@ -2,3 +2,4 @@ NODE_ENV = local WORKER_ENDPOINT = wss://localhost:2000 NODE_ENDPOINT = ws://localhost:9944 BINARY_DIR=/bin +LITENTRY_CLI_DIR=/bin/litentry-cli From 10292b521276858340bdd25f17a55651773d364e Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Fri, 26 Jan 2024 17:41:12 +0000 Subject: [PATCH 23/32] debug local --- tee-worker/ts-tests/integration-tests/data-providers.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tee-worker/ts-tests/integration-tests/data-providers.test.ts b/tee-worker/ts-tests/integration-tests/data-providers.test.ts index 16c153ca3a..a33db56ef2 100644 --- a/tee-worker/ts-tests/integration-tests/data-providers.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-providers.test.ts @@ -65,6 +65,10 @@ describe('Test Vc (direct invocation)', function () { const eventsPromise = subscribeToEventsWithExtHash(reqExtHash, context); try { // CLIENT = "$CLIENT_BIN -p $NPORT -P $WORKER1PORT -u $NODEURL -U $WORKER1URL" + + await zx`ls /usr/local/` + await zx`ls /usr/local/bin` + const commandPromise = zx`${clientDir} -p ${nodePort} -P ${workerPort} -u ${ nodeProtocal + nodeHostname } -U ${workerProtocal + workerHostname}\ From fb881154019e86faa2efce624a431dfd75ac89f4 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Fri, 26 Jan 2024 17:43:34 +0000 Subject: [PATCH 24/32] format --- tee-worker/ts-tests/integration-tests/data-providers.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tee-worker/ts-tests/integration-tests/data-providers.test.ts b/tee-worker/ts-tests/integration-tests/data-providers.test.ts index a33db56ef2..b7ba2fc8c0 100644 --- a/tee-worker/ts-tests/integration-tests/data-providers.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-providers.test.ts @@ -66,8 +66,8 @@ describe('Test Vc (direct invocation)', function () { try { // CLIENT = "$CLIENT_BIN -p $NPORT -P $WORKER1PORT -u $NODEURL -U $WORKER1URL" - await zx`ls /usr/local/` - await zx`ls /usr/local/bin` + await zx`ls /usr/local/`; + await zx`ls /usr/local/bin`; const commandPromise = zx`${clientDir} -p ${nodePort} -P ${workerPort} -u ${ nodeProtocal + nodeHostname From cd91504a1df7fb592c1663925b8c6d716a2a741d Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Fri, 26 Jan 2024 17:55:13 +0000 Subject: [PATCH 25/32] fix cli path --- tee-worker/ts-tests/integration-tests/.env.staging | 2 +- tee-worker/ts-tests/integration-tests/data-providers.test.ts | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tee-worker/ts-tests/integration-tests/.env.staging b/tee-worker/ts-tests/integration-tests/.env.staging index 5951684479..50124dd6bb 100644 --- a/tee-worker/ts-tests/integration-tests/.env.staging +++ b/tee-worker/ts-tests/integration-tests/.env.staging @@ -2,4 +2,4 @@ NODE_ENV = staging WORKER_ENDPOINT = wss://litentry-worker-1:2011 NODE_ENDPOINT = "ws://litentry-node:9912" BINARY_DIR=/usr/local/bin -LITENTRY_CLI_DIR=usr/local/bin/litentry-cli \ No newline at end of file +LITENTRY_CLI_DIR=/usr/local/bin/litentry-cli \ No newline at end of file diff --git a/tee-worker/ts-tests/integration-tests/data-providers.test.ts b/tee-worker/ts-tests/integration-tests/data-providers.test.ts index b7ba2fc8c0..a246338216 100644 --- a/tee-worker/ts-tests/integration-tests/data-providers.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-providers.test.ts @@ -66,9 +66,6 @@ describe('Test Vc (direct invocation)', function () { try { // CLIENT = "$CLIENT_BIN -p $NPORT -P $WORKER1PORT -u $NODEURL -U $WORKER1URL" - await zx`ls /usr/local/`; - await zx`ls /usr/local/bin`; - const commandPromise = zx`${clientDir} -p ${nodePort} -P ${workerPort} -u ${ nodeProtocal + nodeHostname } -U ${workerProtocal + workerHostname}\ From 1ffd66d55347a6f4790e9416c76492235429fb7e Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Fri, 26 Jan 2024 18:09:54 +0000 Subject: [PATCH 26/32] test mock address --- .../credential-definitions/vip3/vip3-membership-card-sliver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts index 180d6fa9db..61385a1565 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts @@ -3,7 +3,7 @@ import * as dataProviders from '../config/data-providers'; import { AccountNetworks, Networks } from '../config/networks'; import { CredentialDefinition } from '../config/types'; -const mockAddress: HexString = '0x10CdF7F7A32E2F24c853AE6567b75D862Ee2B46f'; +const mockAddress: HexString = '0x10CdF7F7A32E2F24c853AE6567b75D862Ee3B46f'; export const vip3MembershipCardSilver: CredentialDefinition = { id: 'vip3-membership-card-silver', name: 'VIP3 Membership Card Sliver', From 70f825c2f81e3e3724f06b68faf13fd39e423bef Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Fri, 26 Jan 2024 18:33:01 +0000 Subject: [PATCH 27/32] withdraw account test. --- .../credential-definitions/vip3/vip3-membership-card-sliver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts index 61385a1565..180d6fa9db 100644 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts +++ b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts @@ -3,7 +3,7 @@ import * as dataProviders from '../config/data-providers'; import { AccountNetworks, Networks } from '../config/networks'; import { CredentialDefinition } from '../config/types'; -const mockAddress: HexString = '0x10CdF7F7A32E2F24c853AE6567b75D862Ee3B46f'; +const mockAddress: HexString = '0x10CdF7F7A32E2F24c853AE6567b75D862Ee2B46f'; export const vip3MembershipCardSilver: CredentialDefinition = { id: 'vip3-membership-card-silver', name: 'VIP3 Membership Card Sliver', From 0411ac425ddca6b2efcb76f0f43cc1de3aa3a8d5 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Mon, 29 Jan 2024 08:37:55 +0000 Subject: [PATCH 28/32] modefy into json file --- .../common/credential-json/index.ts | 28 +++++++++++++++ .../credential-json/vip3-credential-test.json | 30 ++++++++++++++++ .../integration-tests/data-providers.test.ts | 34 +++++++++---------- 3 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 tee-worker/ts-tests/integration-tests/common/credential-json/index.ts create mode 100644 tee-worker/ts-tests/integration-tests/common/credential-json/vip3-credential-test.json diff --git a/tee-worker/ts-tests/integration-tests/common/credential-json/index.ts b/tee-worker/ts-tests/integration-tests/common/credential-json/index.ts new file mode 100644 index 0000000000..19f9c55267 --- /dev/null +++ b/tee-worker/ts-tests/integration-tests/common/credential-json/index.ts @@ -0,0 +1,28 @@ +import { CorePrimitivesAssertion, CorePrimitivesNetworkWeb3Network } from 'parachain-api'; +import type { Codec } from '@polkadot/types-codec/types'; +import type { U8aLike } from '@polkadot/util/types'; +type DataProvider = { + id: string; + name: string; + url: string; +}; + +type AssertionGenericPayload = string | Array | Record; + +import vip3Json from './vip3-credential-test.json' assert { type: 'json' }; +export const vip3CredentialJson = vip3Json as unknown as CredentialDefinition[]; + +export interface CredentialDefinition { + id: string; + name: string; + description: string; + assertion: { + id: CorePrimitivesAssertion['type']; + payload: AssertionGenericPayload; + }; + dataProvider: DataProvider; + network: CorePrimitivesNetworkWeb3Network['type']; + mockDid: string; + mockWeb3Network: string; + expectedCredentialValue: boolean; +} diff --git a/tee-worker/ts-tests/integration-tests/common/credential-json/vip3-credential-test.json b/tee-worker/ts-tests/integration-tests/common/credential-json/vip3-credential-test.json new file mode 100644 index 0000000000..a4c8573d43 --- /dev/null +++ b/tee-worker/ts-tests/integration-tests/common/credential-json/vip3-credential-test.json @@ -0,0 +1,30 @@ +[ + { + "id": "vip3-membership-card-gold", + "name": "VIP3 Membership Card Gold", + "description": "VIP3 Membership Card Gold", + "assertion": { + "id": "Vip3MembershipCard", + "payload": "Gold" + }, + "dataProvider": "vip3", + "network": "ethereum", + "mockDid": "litentry:evm:0x651614cA9097C5ba189Ef85e7851Ef9cff592B2c", + "mockWeb3Network": "bsc,ethereum", + "expectedCredentialValue": true + }, + { + "id": "vip3-membership-card-silver", + "name": "VIP3 Membership Card Silver", + "description": "VIP3 Membership Card Silver", + "assertion": { + "id": "Vip3MembershipCard", + "payload": "Silver" + }, + "dataProvider": "vip3", + "network": "ethereum", + "mockDid": "litentry:evm:0x10CdF7F7A32E2F24c853AE6567b75D862Ee2B46f", + "mockWeb3Network": "bsc,ethereum", + "expectedCredentialValue": true + } +] diff --git a/tee-worker/ts-tests/integration-tests/data-providers.test.ts b/tee-worker/ts-tests/integration-tests/data-providers.test.ts index a246338216..205fee7cab 100644 --- a/tee-worker/ts-tests/integration-tests/data-providers.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-providers.test.ts @@ -1,13 +1,7 @@ import { randomBytes, KeyObject } from 'crypto'; import { step } from 'mocha-steps'; import { assert } from 'chai'; -import { - buildIdentityFromKeypair, - decryptWithAes, - initIntegrationTestContext, - PolkadotSigner, - sleep, -} from './common/utils'; +import { buildIdentityFromKeypair, decryptWithAes, initIntegrationTestContext, PolkadotSigner } from './common/utils'; import { randomSubstrateWallet } from './common/helpers'; import { assertIsInSidechainBlock } from './common/utils/assertion'; import { @@ -20,11 +14,10 @@ import type { IntegrationTestContext } from './common/common-types'; import { CorePrimitivesIdentity, RequestVCResult } from 'parachain-api'; import { aesKey } from './common/call'; import { $ as zx } from 'zx'; -import { credentialDefinitionMap } from './common/credential-definitions'; import { subscribeToEventsWithExtHash } from './common/transactions'; import { KeyringPair } from '@polkadot/keyring/types'; import { u8aToHex } from '@polkadot/util'; - +import { vip3CredentialJson, CredentialDefinition } from './common/credential-json'; describe('Test Vc (direct invocation)', function () { let context: IntegrationTestContext = undefined as any; let teeShieldingKey: KeyObject = undefined as any; @@ -53,6 +46,8 @@ describe('Test Vc (direct invocation)', function () { const { protocol: nodeProtocal, hostname: nodeHostname, port: nodePort } = new URL(process.env.NODE_ENDPOINT!); async function linkIdentityViaCli(id: string) { + const credentialDefinition = vip3CredentialJson.find((item) => item.id === id) as CredentialDefinition; + const keyringPair = randomSubstrateWallet(); keyringPairs.push(keyringPair); const formatAddress = u8aToHex(keyringPair.publicKey); @@ -70,8 +65,8 @@ describe('Test Vc (direct invocation)', function () { nodeProtocal + nodeHostname } -U ${workerProtocal + workerHostname}\ trusted -d link-identity did:litentry:substrate:${formatAddress}\ - did:${credentialDefinitionMap[id].mockDid}\ - ${credentialDefinitionMap[id].mockWeb3Network}`; + did:${credentialDefinition.mockDid}\ + ${credentialDefinition.mockWeb3Network}`; await commandPromise; } catch (error: any) { @@ -85,8 +80,10 @@ describe('Test Vc (direct invocation)', function () { } async function requestVc(id: string, index: number) { + const credentialDefinition = vip3CredentialJson.find((item) => item.id === id) as CredentialDefinition; + const assertion = { - [credentialDefinitionMap[id].assertion.id]: credentialDefinitionMap[id].assertion.payload, + [credentialDefinition.assertion.id]: credentialDefinition.assertion.payload, }; let currentNonce = (await getSidechainNonce(context, teeShieldingKey, substrateIdentities[index])).toNumber(); @@ -112,22 +109,25 @@ describe('Test Vc (direct invocation)', function () { const decryptVcPayload = decryptWithAes(aesKey, vcResults.vc_payload, 'utf-8').replace('0x', ''); const vcPayloadJson = JSON.parse(decryptVcPayload); - assert.equal(vcPayloadJson.credentialSubject.values[0], credentialDefinitionMap[id].expectedCredentialValue); + assert.equal(vcPayloadJson.credentialSubject.values[0], credentialDefinition.expectedCredentialValue); } // eslint-disable-next-line no-prototype-builtins - if (argvId && credentialDefinitionMap.hasOwnProperty(argvId)) { + if (argvId && vip3CredentialJson.find((item) => item.id === argvId)) { + const credentialDefinition = vip3CredentialJson.find((item) => item.id === argvId) as CredentialDefinition; step( - `linking identity::${credentialDefinitionMap[argvId].mockDid} via cli and request vc::${credentialDefinitionMap[argvId].id}`, + `linking identity::${credentialDefinition.mockDid} via cli and request vc::${credentialDefinition.mockDid}`, async function () { await linkIdentityViaCli(argvId); await requestVc(argvId, 0); } ); } else { - Object.keys(credentialDefinitionMap).forEach((id, index) => { + vip3CredentialJson.forEach(({ id }, index) => { + console.log(id); + step( - `linking identity::${credentialDefinitionMap[id].mockDid} via cli and request vc::${credentialDefinitionMap[id].id}`, + `linking identity::${vip3CredentialJson[index].mockDid} via cli and request vc::${vip3CredentialJson[index].id}`, async function () { await linkIdentityViaCli(id); await requestVc(id, index); From a9e8e19ca4196692a93063431a6e135f0b912a66 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Mon, 29 Jan 2024 08:39:34 +0000 Subject: [PATCH 29/32] delete ts file --- .../achainable/token-holder-dot.ts | 31 ------------ .../achainable/token-holder-eth.ts | 31 ------------ .../config/data-providers.ts | 47 ------------------- .../credential-definitions/config/networks.ts | 16 ------- .../credential-definitions/config/types.ts | 21 --------- .../common/credential-definitions/index.ts | 10 ---- .../vip3/vip3-membership-card-gold.ts | 24 ---------- .../vip3/vip3-membership-card-sliver.ts | 24 ---------- 8 files changed, 204 deletions(-) delete mode 100644 tee-worker/ts-tests/integration-tests/common/credential-definitions/achainable/token-holder-dot.ts delete mode 100644 tee-worker/ts-tests/integration-tests/common/credential-definitions/achainable/token-holder-eth.ts delete mode 100644 tee-worker/ts-tests/integration-tests/common/credential-definitions/config/data-providers.ts delete mode 100644 tee-worker/ts-tests/integration-tests/common/credential-definitions/config/networks.ts delete mode 100644 tee-worker/ts-tests/integration-tests/common/credential-definitions/config/types.ts delete mode 100644 tee-worker/ts-tests/integration-tests/common/credential-definitions/index.ts delete mode 100644 tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts delete mode 100644 tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/achainable/token-holder-dot.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/achainable/token-holder-dot.ts deleted file mode 100644 index 9780b06f7b..0000000000 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/achainable/token-holder-dot.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { HexString } from '@polkadot/util/types'; -import * as dataProviders from '../config/data-providers'; -import { Networks, AccountNetworks } from '../config/networks'; -import { CredentialDefinition } from '../config/types'; - -// https://polkadot.subscan.io/tools/format_transform -const mockAddress: HexString = '0xf20107661944f8a00a418d864292885767a2942e92abb5d3cdaf243fe065c171'; -export const tokenHolderDot: CredentialDefinition = { - id: 'token-holder-dot', - name: 'DOT Holder', - description: `The number of DOT tokens you hold > 0`, - assertion: { - id: 'Achainable', - payload: { - Amount: { - name: 'Balance over {amount}', - chain: 'Polkadot', - amount: '0', - }, - }, - }, - dataProvider: dataProviders.achainable, - network: Networks['polkadot'], - - // mock data for link-identity via cli - // https://github.com/litentry/litentry-parachain/blob/dev/tee-worker/cli/src/trusted_base_cli/commands/litentry/link_identity.rs - mockDid: `litentry:${AccountNetworks['substrate']}:${mockAddress}`, - mockWeb3Network: `${Networks['litentry']},${Networks['kusama']}`, - - expectedCredentialValue: true, -}; diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/achainable/token-holder-eth.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/achainable/token-holder-eth.ts deleted file mode 100644 index 5bc801bb4e..0000000000 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/achainable/token-holder-eth.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { HexString } from '@polkadot/util/types'; -import * as dataProviders from '../config/data-providers'; -import { Networks, AccountNetworks } from '../config/networks'; -import { CredentialDefinition } from '../config/types'; - -// https://polkadot.subscan.io/tools/format_transform -const mockAddress: HexString = '0xbB613509f2590ca489863551E7A27E89B863A8BD'; -export const tokenHolderEth: CredentialDefinition = { - id: 'token-holder-eth', - name: 'ETH Holder', - description: `The number of ETH tokens you hold > 0`, - assertion: { - id: 'Achainable', - payload: { - Amount: { - name: 'Balance over {amount}', - chain: 'Ethereum', - amount: '0', - }, - }, - }, - dataProvider: dataProviders.achainable, - network: Networks['ethereum'], - - // mock data for link-identity via cli - // https://github.com/litentry/litentry-parachain/blob/dev/tee-worker/cli/src/trusted_base_cli/commands/litentry/link_identity.rs - mockDid: `litentry:${AccountNetworks['evm']}:${mockAddress}`, - mockWeb3Network: `${Networks['bsc']},${Networks['ethereum']}`, - - expectedCredentialValue: true, -}; diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/data-providers.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/data-providers.ts deleted file mode 100644 index fe69d4d3c4..0000000000 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/data-providers.ts +++ /dev/null @@ -1,47 +0,0 @@ -export type DataProvider = { - id: string; - name: string; - url: string; -}; - -export const litentry: DataProvider = { - id: 'litentry-tee-worker', - name: 'Litentry TEE Worker', - url: 'https://litentry.com/', -}; - -export const litentryIndexer: DataProvider = { - id: 'litentry-indexer', - name: 'Litentry Indexer', - url: 'https://litentry.com/', -}; - -export const discord: DataProvider = { - id: 'discord-api', - name: 'Discord Official API', - url: 'https://discord.com/build', -}; - -export const achainable: DataProvider = { - id: 'achainable-api', - name: 'Achainable', - url: 'https://www.achainable.com/', -}; - -export const twitter: DataProvider = { - id: 'twitter-api', - name: 'Twitter Official API', - url: 'https://developer.twitter.com/', -}; - -export const oneBlock: DataProvider = { - id: 'one-block', - name: 'OneBlock+', - url: 'https://linktr.ee/oneblock_', -}; - -export const vip3: DataProvider = { - id: 'vip3', - name: 'VIP3', - url: 'https://dappapi.vip3.io/', -}; diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/networks.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/networks.ts deleted file mode 100644 index 9bbcfc1c65..0000000000 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/networks.ts +++ /dev/null @@ -1,16 +0,0 @@ -export enum Networks { - ethereum = 'Ethereum', - bsc = 'Bsc', - litentry = 'Litentry', - polkadot = 'Polkadot', - kusama = 'Kusama', - twitter = 'Twitter', - discord = 'Discord', - // ... -} - -export enum AccountNetworks { - substrate = 'substrate', - evm = 'evm', - // ... -} diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/types.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/types.ts deleted file mode 100644 index 132d712647..0000000000 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/config/types.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { CorePrimitivesAssertion, CorePrimitivesNetworkWeb3Network } from 'parachain-api'; -import type { Codec } from '@polkadot/types-codec/types'; -import type { U8aLike } from '@polkadot/util/types'; -import { DataProvider } from './data-providers'; - -type AssertionGenericPayload = string | Array | Record; - -export interface CredentialDefinition { - id: string; - name: string; - description: string; - assertion: { - id: CorePrimitivesAssertion['type']; - payload: AssertionGenericPayload; - }; - dataProvider: DataProvider; - network: CorePrimitivesNetworkWeb3Network['type']; - mockDid: string; - mockWeb3Network: string; - expectedCredentialValue: boolean; -} diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/index.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/index.ts deleted file mode 100644 index b484bbe4a2..0000000000 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { vip3MembershipCardGold } from './vip3/vip3-membership-card-gold'; -import { vip3MembershipCardSilver } from './vip3/vip3-membership-card-sliver'; -import { tokenHolderDot } from './achainable/token-holder-dot'; -import { tokenHolderEth } from './achainable/token-holder-eth'; -export const credentialDefinitionMap: any = { - 'vip3-membership-card-gold': vip3MembershipCardGold, - 'vip3-membership-card-silver': vip3MembershipCardSilver, - // 'token-holder-dot': tokenHolderDot, - // 'token-holder-eth': tokenHolderEth, -}; diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts deleted file mode 100644 index 50df3a6169..0000000000 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-gold.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { HexString } from '@polkadot/util/types'; -import * as dataProviders from '../config/data-providers'; -import { Networks, AccountNetworks } from '../config/networks'; -import { CredentialDefinition } from '../config/types'; - -const mockAddress: HexString = '0x651614cA9097C5ba189Ef85e7851Ef9cff592B2c'; -export const vip3MembershipCardGold: CredentialDefinition = { - id: 'vip3-membership-card-gold', - name: 'VIP3 Membership Card Gold', - description: 'VIP3 Membership Card Gold', - assertion: { - id: 'Vip3MembershipCard', - payload: 'Gold', - }, - dataProvider: dataProviders.vip3, - network: Networks['ethereum'], - - // mock data for link-identity via cli - // https://github.com/litentry/litentry-parachain/blob/dev/tee-worker/cli/src/trusted_base_cli/commands/litentry/link_identity.rs - mockDid: `litentry:${AccountNetworks['evm']}:${mockAddress}`, - mockWeb3Network: `${Networks['bsc']},${Networks['ethereum']}`, - - expectedCredentialValue: true, -}; diff --git a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts b/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts deleted file mode 100644 index 180d6fa9db..0000000000 --- a/tee-worker/ts-tests/integration-tests/common/credential-definitions/vip3/vip3-membership-card-sliver.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { HexString } from '@polkadot/util/types'; -import * as dataProviders from '../config/data-providers'; -import { AccountNetworks, Networks } from '../config/networks'; -import { CredentialDefinition } from '../config/types'; - -const mockAddress: HexString = '0x10CdF7F7A32E2F24c853AE6567b75D862Ee2B46f'; -export const vip3MembershipCardSilver: CredentialDefinition = { - id: 'vip3-membership-card-silver', - name: 'VIP3 Membership Card Sliver', - description: 'VIP3 Membership Card Silver', - assertion: { - id: 'Vip3MembershipCard', - payload: 'Silver', - }, - dataProvider: dataProviders.vip3, - network: Networks['ethereum'], - - // mock data for link-identity via cli - // https://github.com/litentry/litentry-parachain/blob/dev/tee-worker/cli/src/trusted_base_cli/commands/litentry/link_identity.rs - mockDid: `litentry:${AccountNetworks['evm']}:${mockAddress}`, - mockWeb3Network: `${Networks['bsc']},${Networks['ethereum']}`, - - expectedCredentialValue: true, -}; From 037610094e2b4472698e943bc4aaf6d8a4d6be9f Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Mon, 29 Jan 2024 08:42:26 +0000 Subject: [PATCH 30/32] format --- tee-worker/ts-tests/integration-tests/data-providers.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tee-worker/ts-tests/integration-tests/data-providers.test.ts b/tee-worker/ts-tests/integration-tests/data-providers.test.ts index 205fee7cab..b100b712d7 100644 --- a/tee-worker/ts-tests/integration-tests/data-providers.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-providers.test.ts @@ -60,7 +60,6 @@ describe('Test Vc (direct invocation)', function () { const eventsPromise = subscribeToEventsWithExtHash(reqExtHash, context); try { // CLIENT = "$CLIENT_BIN -p $NPORT -P $WORKER1PORT -u $NODEURL -U $WORKER1URL" - const commandPromise = zx`${clientDir} -p ${nodePort} -P ${workerPort} -u ${ nodeProtocal + nodeHostname } -U ${workerProtocal + workerHostname}\ From dfac63460c8837a6e220e29d2a2ae49d961eb1eb Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Mon, 29 Jan 2024 12:22:47 +0000 Subject: [PATCH 31/32] improve logic --- .../integration-tests/data-providers.test.ts | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/tee-worker/ts-tests/integration-tests/data-providers.test.ts b/tee-worker/ts-tests/integration-tests/data-providers.test.ts index b100b712d7..71acda7a52 100644 --- a/tee-worker/ts-tests/integration-tests/data-providers.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-providers.test.ts @@ -18,6 +18,7 @@ import { subscribeToEventsWithExtHash } from './common/transactions'; import { KeyringPair } from '@polkadot/keyring/types'; import { u8aToHex } from '@polkadot/util'; import { vip3CredentialJson, CredentialDefinition } from './common/credential-json'; +import colors from 'colors'; describe('Test Vc (direct invocation)', function () { let context: IntegrationTestContext = undefined as any; let teeShieldingKey: KeyObject = undefined as any; @@ -46,7 +47,7 @@ describe('Test Vc (direct invocation)', function () { const { protocol: nodeProtocal, hostname: nodeHostname, port: nodePort } = new URL(process.env.NODE_ENDPOINT!); async function linkIdentityViaCli(id: string) { - const credentialDefinition = vip3CredentialJson.find((item) => item.id === id) as CredentialDefinition; + const credentialDefinitions = vip3CredentialJson.find((item) => item.id === id) as CredentialDefinition; const keyringPair = randomSubstrateWallet(); keyringPairs.push(keyringPair); @@ -64,8 +65,8 @@ describe('Test Vc (direct invocation)', function () { nodeProtocal + nodeHostname } -U ${workerProtocal + workerHostname}\ trusted -d link-identity did:litentry:substrate:${formatAddress}\ - did:${credentialDefinition.mockDid}\ - ${credentialDefinition.mockWeb3Network}`; + did:${credentialDefinitions.mockDid}\ + ${credentialDefinitions.mockWeb3Network}`; await commandPromise; } catch (error: any) { @@ -79,10 +80,10 @@ describe('Test Vc (direct invocation)', function () { } async function requestVc(id: string, index: number) { - const credentialDefinition = vip3CredentialJson.find((item) => item.id === id) as CredentialDefinition; + const credentialDefinitions = vip3CredentialJson.find((item) => item.id === id) as CredentialDefinition; const assertion = { - [credentialDefinition.assertion.id]: credentialDefinition.assertion.payload, + [credentialDefinitions.assertion.id]: credentialDefinitions.assertion.payload, }; let currentNonce = (await getSidechainNonce(context, teeShieldingKey, substrateIdentities[index])).toNumber(); @@ -108,23 +109,25 @@ describe('Test Vc (direct invocation)', function () { const decryptVcPayload = decryptWithAes(aesKey, vcResults.vc_payload, 'utf-8').replace('0x', ''); const vcPayloadJson = JSON.parse(decryptVcPayload); - assert.equal(vcPayloadJson.credentialSubject.values[0], credentialDefinition.expectedCredentialValue); + assert.equal(vcPayloadJson.credentialSubject.values[0], credentialDefinitions.expectedCredentialValue); } - // eslint-disable-next-line no-prototype-builtins - if (argvId && vip3CredentialJson.find((item) => item.id === argvId)) { - const credentialDefinition = vip3CredentialJson.find((item) => item.id === argvId) as CredentialDefinition; - step( - `linking identity::${credentialDefinition.mockDid} via cli and request vc::${credentialDefinition.mockDid}`, - async function () { - await linkIdentityViaCli(argvId); - await requestVc(argvId, 0); - } - ); + if (argvId) { + const credentialDefinitions = vip3CredentialJson.find((item) => item.id === argvId) as CredentialDefinition; + if (credentialDefinitions) { + const credentialDefinitions = vip3CredentialJson.find((item) => item.id === argvId) as CredentialDefinition; + step( + `linking identity::${credentialDefinitions.mockDid} via cli and request vc::${credentialDefinitions.mockDid}`, + async function () { + await linkIdentityViaCli(argvId); + await requestVc(argvId, 0); + } + ); + } else { + console.log(colors.red(`credential id: ${argvId} not found`)); + } } else { vip3CredentialJson.forEach(({ id }, index) => { - console.log(id); - step( `linking identity::${vip3CredentialJson[index].mockDid} via cli and request vc::${vip3CredentialJson[index].id}`, async function () { From 5da02c293599190c5385a274e80bc23e316dde45 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Tue, 30 Jan 2024 03:50:17 +0000 Subject: [PATCH 32/32] fix comments --- .../integration-tests/.env.local.example | 4 +- .../integration-tests/data-providers.test.ts | 40 ++++++++----------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/tee-worker/ts-tests/integration-tests/.env.local.example b/tee-worker/ts-tests/integration-tests/.env.local.example index 566ba8cce5..74060ff00f 100644 --- a/tee-worker/ts-tests/integration-tests/.env.local.example +++ b/tee-worker/ts-tests/integration-tests/.env.local.example @@ -1,5 +1,5 @@ NODE_ENV = local WORKER_ENDPOINT = wss://localhost:2000 NODE_ENDPOINT = ws://localhost:9944 -BINARY_DIR=/bin -LITENTRY_CLI_DIR=/bin/litentry-cli +BINARY_DIR=../../bin +LITENTRY_CLI_DIR=../../bin/litentry-cli diff --git a/tee-worker/ts-tests/integration-tests/data-providers.test.ts b/tee-worker/ts-tests/integration-tests/data-providers.test.ts index 71acda7a52..78903f6a7f 100644 --- a/tee-worker/ts-tests/integration-tests/data-providers.test.ts +++ b/tee-worker/ts-tests/integration-tests/data-providers.test.ts @@ -18,7 +18,6 @@ import { subscribeToEventsWithExtHash } from './common/transactions'; import { KeyringPair } from '@polkadot/keyring/types'; import { u8aToHex } from '@polkadot/util'; import { vip3CredentialJson, CredentialDefinition } from './common/credential-json'; -import colors from 'colors'; describe('Test Vc (direct invocation)', function () { let context: IntegrationTestContext = undefined as any; let teeShieldingKey: KeyObject = undefined as any; @@ -28,6 +27,8 @@ describe('Test Vc (direct invocation)', function () { const reqExtHash = '0x0000000000000000000000000000000000000000000000000000000000000000'; const keyringPairs: KeyringPair[] = []; let argvId = ''; + const credentialsJson: CredentialDefinition[] = [...vip3CredentialJson]; + this.timeout(6000000); before(async () => { context = await initIntegrationTestContext(process.env.WORKER_ENDPOINT!, process.env.NODE_ENDPOINT!); @@ -47,16 +48,13 @@ describe('Test Vc (direct invocation)', function () { const { protocol: nodeProtocal, hostname: nodeHostname, port: nodePort } = new URL(process.env.NODE_ENDPOINT!); async function linkIdentityViaCli(id: string) { - const credentialDefinitions = vip3CredentialJson.find((item) => item.id === id) as CredentialDefinition; + const credentialDefinitions = credentialsJson.find((item) => item.id === id) as CredentialDefinition; const keyringPair = randomSubstrateWallet(); keyringPairs.push(keyringPair); const formatAddress = u8aToHex(keyringPair.publicKey); - const substrateIdentity = (await buildIdentityFromKeypair( - new PolkadotSigner(keyringPair), - context - )) as CorePrimitivesIdentity; + const substrateIdentity = await buildIdentityFromKeypair(new PolkadotSigner(keyringPair), context); substrateIdentities.push(substrateIdentity); const eventsPromise = subscribeToEventsWithExtHash(reqExtHash, context); try { @@ -80,7 +78,7 @@ describe('Test Vc (direct invocation)', function () { } async function requestVc(id: string, index: number) { - const credentialDefinitions = vip3CredentialJson.find((item) => item.id === id) as CredentialDefinition; + const credentialDefinitions = credentialsJson.find((item) => item.id === id) as CredentialDefinition; const assertion = { [credentialDefinitions.assertion.id]: credentialDefinitions.assertion.payload, @@ -112,24 +110,20 @@ describe('Test Vc (direct invocation)', function () { assert.equal(vcPayloadJson.credentialSubject.values[0], credentialDefinitions.expectedCredentialValue); } - if (argvId) { - const credentialDefinitions = vip3CredentialJson.find((item) => item.id === argvId) as CredentialDefinition; - if (credentialDefinitions) { - const credentialDefinitions = vip3CredentialJson.find((item) => item.id === argvId) as CredentialDefinition; - step( - `linking identity::${credentialDefinitions.mockDid} via cli and request vc::${credentialDefinitions.mockDid}`, - async function () { - await linkIdentityViaCli(argvId); - await requestVc(argvId, 0); - } - ); - } else { - console.log(colors.red(`credential id: ${argvId} not found`)); - } + if (argvId && credentialsJson.find((item) => item.id === argvId)) { + const credentialDefinitions = credentialsJson.find((item) => item.id === argvId) as CredentialDefinition; + + step( + `linking identity::${credentialDefinitions.mockDid} via cli and request vc::${credentialDefinitions.mockDid}`, + async function () { + await linkIdentityViaCli(argvId); + await requestVc(argvId, 0); + } + ); } else { - vip3CredentialJson.forEach(({ id }, index) => { + credentialsJson.forEach(({ id }, index) => { step( - `linking identity::${vip3CredentialJson[index].mockDid} via cli and request vc::${vip3CredentialJson[index].id}`, + `linking identity::${credentialsJson[index].mockDid} via cli and request vc::${credentialsJson[index].id}`, async function () { await linkIdentityViaCli(id); await requestVc(id, index);