From 090766ad8483581617b33afe7dd1b146749c41dc Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Tue, 23 Jul 2024 09:44:18 +0000 Subject: [PATCH 1/3] adding subscribeToEventsWithExtHash --- .../ts-tests/integration-tests/dr_vc.test.ts | 168 +++++++++--------- 1 file changed, 88 insertions(+), 80 deletions(-) diff --git a/tee-worker/ts-tests/integration-tests/dr_vc.test.ts b/tee-worker/ts-tests/integration-tests/dr_vc.test.ts index 7ea4164b4f..b9a011c5b1 100644 --- a/tee-worker/ts-tests/integration-tests/dr_vc.test.ts +++ b/tee-worker/ts-tests/integration-tests/dr_vc.test.ts @@ -17,6 +17,8 @@ import type { CorePrimitivesIdentity, WorkerRpcReturnValue } from 'parachain-api import { mockBatchAssertion } from './common/utils/vc-helper'; import type { LitentryValidationData, Web3Network } from 'parachain-api'; import type { Vec, Bytes } from '@polkadot/types'; +import { subscribeToEventsWithExtHash } from './common/transactions'; +import { assert } from 'chai'; describe('Test Vc (direct request)', function () { let context: IntegrationTestContext = undefined as any; @@ -46,86 +48,86 @@ describe('Test Vc (direct request)', function () { aliceSubstrateIdentity = await context.web3Wallets.substrate.Alice.getIdentity(context); }); - step('linking identities (alice)', async function () { - let currentNonce = (await getSidechainNonce(context, aliceSubstrateIdentity)).toNumber(); - const getNextNonce = () => currentNonce++; - - const twitterNonce = getNextNonce(); - const twitterIdentity = await buildIdentityHelper('mock_user', 'Twitter', context); - const twitterValidation = await buildWeb2Validation({ - identityType: 'Twitter', - context, - signerIdentitity: aliceSubstrateIdentity, - linkIdentity: twitterIdentity, - verificationType: 'PublicTweet', - validationNonce: twitterNonce, - }); - const twitterNetworks = context.api.createType('Vec', []); - linkIdentityRequestParams.push({ - nonce: twitterNonce, - identity: twitterIdentity, - validation: twitterValidation, - networks: twitterNetworks, - }); - - const evmNonce = getNextNonce(); - - const evmIdentity = await context.web3Wallets.evm.Alice.getIdentity(context); - const evmValidation = await buildValidations( - context, - aliceSubstrateIdentity, - evmIdentity, - evmNonce, - 'ethereum', - context.web3Wallets.evm.Alice - ); - const evmNetworks = context.api.createType('Vec', ['Ethereum', 'Bsc']); - linkIdentityRequestParams.push({ - nonce: evmNonce, - identity: evmIdentity, - validation: evmValidation, - networks: evmNetworks, - }); - - const bitcoinNonce = getNextNonce(); - - const bitcoinIdentity = await context.web3Wallets.bitcoin.Alice.getIdentity(context); - console.log('bitcoin id: ', bitcoinIdentity.toHuman()); - const bitcoinValidation = await buildValidations( - context, - aliceSubstrateIdentity, - bitcoinIdentity, - bitcoinNonce, - 'bitcoin', - context.web3Wallets.bitcoin.Alice - ); - const bitcoinNetworks = context.api.createType('Vec', ['BitcoinP2tr']); - linkIdentityRequestParams.push({ - nonce: bitcoinNonce, - identity: bitcoinIdentity, - validation: bitcoinValidation, - networks: bitcoinNetworks, - }); - - for (const { nonce, identity, validation, networks } of linkIdentityRequestParams) { - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const linkIdentityCall = await createSignedTrustedCallLinkIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.substrate.Alice, - aliceSubstrateIdentity, - identity.toHex(), - validation.toHex(), - networks.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, linkIdentityCall); - await assertIsInSidechainBlock('linkIdentityCall', res); - } - }); + // step('linking identities (alice)', async function () { + // let currentNonce = (await getSidechainNonce(context, aliceSubstrateIdentity)).toNumber(); + // const getNextNonce = () => currentNonce++; + + // const twitterNonce = getNextNonce(); + // const twitterIdentity = await buildIdentityHelper('mock_user', 'Twitter', context); + // const twitterValidation = await buildWeb2Validation({ + // identityType: 'Twitter', + // context, + // signerIdentitity: aliceSubstrateIdentity, + // linkIdentity: twitterIdentity, + // verificationType: 'PublicTweet', + // validationNonce: twitterNonce, + // }); + // const twitterNetworks = context.api.createType('Vec', []); + // linkIdentityRequestParams.push({ + // nonce: twitterNonce, + // identity: twitterIdentity, + // validation: twitterValidation, + // networks: twitterNetworks, + // }); + + // const evmNonce = getNextNonce(); + + // const evmIdentity = await context.web3Wallets.evm.Alice.getIdentity(context); + // const evmValidation = await buildValidations( + // context, + // aliceSubstrateIdentity, + // evmIdentity, + // evmNonce, + // 'ethereum', + // context.web3Wallets.evm.Alice + // ); + // const evmNetworks = context.api.createType('Vec', ['Ethereum', 'Bsc']); + // linkIdentityRequestParams.push({ + // nonce: evmNonce, + // identity: evmIdentity, + // validation: evmValidation, + // networks: evmNetworks, + // }); + + // const bitcoinNonce = getNextNonce(); + + // const bitcoinIdentity = await context.web3Wallets.bitcoin.Alice.getIdentity(context); + // console.log('bitcoin id: ', bitcoinIdentity.toHuman()); + // const bitcoinValidation = await buildValidations( + // context, + // aliceSubstrateIdentity, + // bitcoinIdentity, + // bitcoinNonce, + // 'bitcoin', + // context.web3Wallets.bitcoin.Alice + // ); + // const bitcoinNetworks = context.api.createType('Vec', ['BitcoinP2tr']); + // linkIdentityRequestParams.push({ + // nonce: bitcoinNonce, + // identity: bitcoinIdentity, + // validation: bitcoinValidation, + // networks: bitcoinNetworks, + // }); + + // for (const { nonce, identity, validation, networks } of linkIdentityRequestParams) { + // const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; + // const linkIdentityCall = await createSignedTrustedCallLinkIdentity( + // context.api, + // context.mrEnclave, + // context.api.createType('Index', nonce), + // context.web3Wallets.substrate.Alice, + // aliceSubstrateIdentity, + // identity.toHex(), + // validation.toHex(), + // networks.toHex(), + // context.api.createType('Option', aesKey).toHex(), + // requestIdentifier + // ); + + // const res = await sendRequestFromTrustedCall(context, teeShieldingKey, linkIdentityCall); + // await assertIsInSidechainBlock('linkIdentityCall', res); + // } + // }); mockBatchAssertion.forEach(({ description, assertion }) => { step(`request vc payload: ${JSON.stringify(assertion)} (alice)`, async function () { @@ -171,6 +173,7 @@ describe('Test Vc (direct request)', function () { if (vcresponse.result.isOk) await assertVc(context, aliceSubstrateIdentity, vcresponse.result.asOk); }; + const eventsPromise = subscribeToEventsWithExtHash(requestIdentifier, context); // the +res+ below is the last message with "do_watch: false" property and we may not need it at all const res = await sendRequestFromTrustedCall( context, @@ -180,6 +183,11 @@ describe('Test Vc (direct request)', function () { onMessageReceived ); + console.log(res.toHuman()); + + const events = (await eventsPromise).map(({ event }) => event); + assert.equal(events.length, Array.isArray(assertion) ? assertion.length : 1); + // @todo: assert batch vc response }); }); From 034b4aa2ac2f106f18c4bcd1e3a2ae5663f0b6a5 Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Tue, 23 Jul 2024 09:45:55 +0000 Subject: [PATCH 2/3] uncomment --- .../ts-tests/integration-tests/dr_vc.test.ts | 160 +++++++++--------- 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/tee-worker/ts-tests/integration-tests/dr_vc.test.ts b/tee-worker/ts-tests/integration-tests/dr_vc.test.ts index b9a011c5b1..0a38d8c587 100644 --- a/tee-worker/ts-tests/integration-tests/dr_vc.test.ts +++ b/tee-worker/ts-tests/integration-tests/dr_vc.test.ts @@ -48,86 +48,86 @@ describe('Test Vc (direct request)', function () { aliceSubstrateIdentity = await context.web3Wallets.substrate.Alice.getIdentity(context); }); - // step('linking identities (alice)', async function () { - // let currentNonce = (await getSidechainNonce(context, aliceSubstrateIdentity)).toNumber(); - // const getNextNonce = () => currentNonce++; - - // const twitterNonce = getNextNonce(); - // const twitterIdentity = await buildIdentityHelper('mock_user', 'Twitter', context); - // const twitterValidation = await buildWeb2Validation({ - // identityType: 'Twitter', - // context, - // signerIdentitity: aliceSubstrateIdentity, - // linkIdentity: twitterIdentity, - // verificationType: 'PublicTweet', - // validationNonce: twitterNonce, - // }); - // const twitterNetworks = context.api.createType('Vec', []); - // linkIdentityRequestParams.push({ - // nonce: twitterNonce, - // identity: twitterIdentity, - // validation: twitterValidation, - // networks: twitterNetworks, - // }); - - // const evmNonce = getNextNonce(); - - // const evmIdentity = await context.web3Wallets.evm.Alice.getIdentity(context); - // const evmValidation = await buildValidations( - // context, - // aliceSubstrateIdentity, - // evmIdentity, - // evmNonce, - // 'ethereum', - // context.web3Wallets.evm.Alice - // ); - // const evmNetworks = context.api.createType('Vec', ['Ethereum', 'Bsc']); - // linkIdentityRequestParams.push({ - // nonce: evmNonce, - // identity: evmIdentity, - // validation: evmValidation, - // networks: evmNetworks, - // }); - - // const bitcoinNonce = getNextNonce(); - - // const bitcoinIdentity = await context.web3Wallets.bitcoin.Alice.getIdentity(context); - // console.log('bitcoin id: ', bitcoinIdentity.toHuman()); - // const bitcoinValidation = await buildValidations( - // context, - // aliceSubstrateIdentity, - // bitcoinIdentity, - // bitcoinNonce, - // 'bitcoin', - // context.web3Wallets.bitcoin.Alice - // ); - // const bitcoinNetworks = context.api.createType('Vec', ['BitcoinP2tr']); - // linkIdentityRequestParams.push({ - // nonce: bitcoinNonce, - // identity: bitcoinIdentity, - // validation: bitcoinValidation, - // networks: bitcoinNetworks, - // }); - - // for (const { nonce, identity, validation, networks } of linkIdentityRequestParams) { - // const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - // const linkIdentityCall = await createSignedTrustedCallLinkIdentity( - // context.api, - // context.mrEnclave, - // context.api.createType('Index', nonce), - // context.web3Wallets.substrate.Alice, - // aliceSubstrateIdentity, - // identity.toHex(), - // validation.toHex(), - // networks.toHex(), - // context.api.createType('Option', aesKey).toHex(), - // requestIdentifier - // ); - - // const res = await sendRequestFromTrustedCall(context, teeShieldingKey, linkIdentityCall); - // await assertIsInSidechainBlock('linkIdentityCall', res); - // } - // }); + step('linking identities (alice)', async function () { + let currentNonce = (await getSidechainNonce(context, aliceSubstrateIdentity)).toNumber(); + const getNextNonce = () => currentNonce++; + + const twitterNonce = getNextNonce(); + const twitterIdentity = await buildIdentityHelper('mock_user', 'Twitter', context); + const twitterValidation = await buildWeb2Validation({ + identityType: 'Twitter', + context, + signerIdentitity: aliceSubstrateIdentity, + linkIdentity: twitterIdentity, + verificationType: 'PublicTweet', + validationNonce: twitterNonce, + }); + const twitterNetworks = context.api.createType('Vec', []); + linkIdentityRequestParams.push({ + nonce: twitterNonce, + identity: twitterIdentity, + validation: twitterValidation, + networks: twitterNetworks, + }); + + const evmNonce = getNextNonce(); + + const evmIdentity = await context.web3Wallets.evm.Alice.getIdentity(context); + const evmValidation = await buildValidations( + context, + aliceSubstrateIdentity, + evmIdentity, + evmNonce, + 'ethereum', + context.web3Wallets.evm.Alice + ); + const evmNetworks = context.api.createType('Vec', ['Ethereum', 'Bsc']); + linkIdentityRequestParams.push({ + nonce: evmNonce, + identity: evmIdentity, + validation: evmValidation, + networks: evmNetworks, + }); + + const bitcoinNonce = getNextNonce(); + + const bitcoinIdentity = await context.web3Wallets.bitcoin.Alice.getIdentity(context); + console.log('bitcoin id: ', bitcoinIdentity.toHuman()); + const bitcoinValidation = await buildValidations( + context, + aliceSubstrateIdentity, + bitcoinIdentity, + bitcoinNonce, + 'bitcoin', + context.web3Wallets.bitcoin.Alice + ); + const bitcoinNetworks = context.api.createType('Vec', ['BitcoinP2tr']); + linkIdentityRequestParams.push({ + nonce: bitcoinNonce, + identity: bitcoinIdentity, + validation: bitcoinValidation, + networks: bitcoinNetworks, + }); + + for (const { nonce, identity, validation, networks } of linkIdentityRequestParams) { + const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; + const linkIdentityCall = await createSignedTrustedCallLinkIdentity( + context.api, + context.mrEnclave, + context.api.createType('Index', nonce), + context.web3Wallets.substrate.Alice, + aliceSubstrateIdentity, + identity.toHex(), + validation.toHex(), + networks.toHex(), + context.api.createType('Option', aesKey).toHex(), + requestIdentifier + ); + + const res = await sendRequestFromTrustedCall(context, teeShieldingKey, linkIdentityCall); + await assertIsInSidechainBlock('linkIdentityCall', res); + } + }); mockBatchAssertion.forEach(({ description, assertion }) => { step(`request vc payload: ${JSON.stringify(assertion)} (alice)`, async function () { From 838c921bd32211ce0bd22ef1a623d49fe933035b Mon Sep 17 00:00:00 2001 From: Verin1005 Date: Tue, 23 Jul 2024 09:46:29 +0000 Subject: [PATCH 3/3] remove console --- tee-worker/ts-tests/integration-tests/dr_vc.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/tee-worker/ts-tests/integration-tests/dr_vc.test.ts b/tee-worker/ts-tests/integration-tests/dr_vc.test.ts index 0a38d8c587..f24ca0f724 100644 --- a/tee-worker/ts-tests/integration-tests/dr_vc.test.ts +++ b/tee-worker/ts-tests/integration-tests/dr_vc.test.ts @@ -183,8 +183,6 @@ describe('Test Vc (direct request)', function () { onMessageReceived ); - console.log(res.toHuman()); - const events = (await eventsPromise).map(({ event }) => event); assert.equal(events.length, Array.isArray(assertion) ? assertion.length : 1);