Skip to content

Commit

Permalink
Refactoring ts integration tests to get worker url from the parachain (
Browse files Browse the repository at this point in the history
  • Loading branch information
silva-fj authored Sep 4, 2024
1 parent 4ac0aeb commit 1fb33f9
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 19 deletions.
1 change: 0 additions & 1 deletion tee-worker/ts-tests/integration-tests/.env.local.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
NODE_ENV = local
WORKER_ENDPOINT = ws://localhost:2000
NODE_ENDPOINT = ws://localhost:9944
BINARY_DIR=../../bin
LITENTRY_CLI_DIR=../../bin/litentry-cli
3 changes: 1 addition & 2 deletions tee-worker/ts-tests/integration-tests/.env.staging
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
NODE_ENV = staging
WORKER_ENDPOINT = ws://litentry-worker-1:2011
NODE_ENDPOINT = "ws://litentry-node:9912"
BINARY_DIR=/usr/local/bin
LITENTRY_CLI_DIR=/usr/local/bin/litentry-cli
LITENTRY_CLI_DIR=/usr/local/bin/litentry-cli
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe('Test Vc (direct request)', function () {

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);
Expand Down
24 changes: 19 additions & 5 deletions tee-worker/ts-tests/integration-tests/common/utils/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WsProvider, ApiPromise } from 'parachain-api';
import { WsProvider, ApiPromise, PalletTeebagEnclave } from 'parachain-api';
import { cryptoWaitReady } from '@polkadot/util-crypto';
import { hexToString } from '@polkadot/util';
import WebSocketAsPromised from 'websocket-as-promised';
Expand Down Expand Up @@ -27,10 +27,7 @@ export async function initWorkerConnection(endpoint: string): Promise<WebSocketA
return wsp;
}

export async function initIntegrationTestContext(
workerEndpoint: string,
substrateEndpoint: string
): Promise<IntegrationTestContext> {
export async function initIntegrationTestContext(substrateEndpoint: string): Promise<IntegrationTestContext> {
const provider = new WsProvider(substrateEndpoint);
await cryptoWaitReady();

Expand All @@ -45,6 +42,7 @@ export async function initIntegrationTestContext(

const chainIdentifier = api.registry.chainSS58 as number;

const workerEndpoint = await getWorkerEndpoint(api);
const wsp = await initWorkerConnection(workerEndpoint);
const requestId = 1;

Expand All @@ -63,6 +61,22 @@ export async function initIntegrationTestContext(
};
}

async function getWorkerEndpoint(api: ApiPromise): Promise<string> {
const registry = await api.query.teebag.enclaveRegistry.entries();
const identityEnclaves = registry.reduce((enclaves, [, enclave]) => {
if (enclave.isEmpty || !enclave.unwrap().workerType.isIdentity) {
return enclaves;
}
return [...enclaves, enclave.unwrap()];
}, [] as PalletTeebagEnclave[]);

if (identityEnclaves.length === 0) {
throw new Error('No identity worker found');
}

return identityEnclaves[Math.floor(Math.random() * identityEnclaves.length)].url.toHuman() as string;
}

export async function getEnclave(api: ApiPromise): Promise<{
mrEnclave: HexString;
teeShieldingKey: KeyObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function describeLitentry(title: string, cb: (context: IntegrationTestCon
before('Starting Litentry(parachain&tee)', async function () {
//env url

const tmp = await initIntegrationTestContext(process.env.WORKER_ENDPOINT!, process.env.NODE_ENDPOINT!);
const tmp = await initIntegrationTestContext(process.env.NODE_ENDPOINT!);
context.mrEnclave = tmp.mrEnclave;
context.api = tmp.api;
context.tee = tmp.tee;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ describe('Test Identity (bitcoin direct invocation)', function () {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ describe('Test Identity (evm direct invocation)', function () {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ describe('Test Identity (solana direct invocation)', function () {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ describe('Test Identity (direct invocation)', function () {

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);
Expand Down
1 change: 0 additions & 1 deletion tee-worker/ts-tests/integration-tests/di_vc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe('Test Vc (direct invocation)', function () {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ describe('Test Discord Identity (direct invocation)', function () {

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);
Expand Down
1 change: 0 additions & 1 deletion tee-worker/ts-tests/integration-tests/dr_vc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ describe('Test Vc (direct request)', function () {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ describe('Test Twitter Identity (direct invocation)', function () {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Test Vc (direct invocation)', function () {
const errorArray: { id: string; index: number; assertion: any; error: any }[] = [];
this.timeout(6000000);
before(async () => {
context = await initIntegrationTestContext(enclaveEndpoint, nodeEndpoint);
context = await initIntegrationTestContext(nodeEndpoint);
teeShieldingKey = await getTeeShieldingKey(context);
});

Expand Down

0 comments on commit 1fb33f9

Please sign in to comment.