Skip to content

Commit 1fb33f9

Browse files
authored
Refactoring ts integration tests to get worker url from the parachain (#3041)
1 parent 4ac0aeb commit 1fb33f9

14 files changed

+22
-19
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
NODE_ENV = local
2-
WORKER_ENDPOINT = ws://localhost:2000
32
NODE_ENDPOINT = ws://localhost:9944
43
BINARY_DIR=../../bin
54
LITENTRY_CLI_DIR=../../bin/litentry-cli
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
NODE_ENV = staging
2-
WORKER_ENDPOINT = ws://litentry-worker-1:2011
32
NODE_ENDPOINT = "ws://litentry-node:9912"
43
BINARY_DIR=/usr/local/bin
5-
LITENTRY_CLI_DIR=/usr/local/bin/litentry-cli
4+
LITENTRY_CLI_DIR=/usr/local/bin/litentry-cli

tee-worker/ts-tests/integration-tests/assertion_contracts.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ describe('Test Vc (direct request)', function () {
4040

4141
before(async () => {
4242
context = await initIntegrationTestContext(
43-
process.env.WORKER_ENDPOINT!, // @fixme evil assertion; centralize env access
4443
process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access
4544
);
4645
teeShieldingKey = await getTeeShieldingKey(context);

tee-worker/ts-tests/integration-tests/common/utils/context.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { WsProvider, ApiPromise } from 'parachain-api';
1+
import { WsProvider, ApiPromise, PalletTeebagEnclave } from 'parachain-api';
22
import { cryptoWaitReady } from '@polkadot/util-crypto';
33
import { hexToString } from '@polkadot/util';
44
import WebSocketAsPromised from 'websocket-as-promised';
@@ -27,10 +27,7 @@ export async function initWorkerConnection(endpoint: string): Promise<WebSocketA
2727
return wsp;
2828
}
2929

30-
export async function initIntegrationTestContext(
31-
workerEndpoint: string,
32-
substrateEndpoint: string
33-
): Promise<IntegrationTestContext> {
30+
export async function initIntegrationTestContext(substrateEndpoint: string): Promise<IntegrationTestContext> {
3431
const provider = new WsProvider(substrateEndpoint);
3532
await cryptoWaitReady();
3633

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

4643
const chainIdentifier = api.registry.chainSS58 as number;
4744

45+
const workerEndpoint = await getWorkerEndpoint(api);
4846
const wsp = await initWorkerConnection(workerEndpoint);
4947
const requestId = 1;
5048

@@ -63,6 +61,22 @@ export async function initIntegrationTestContext(
6361
};
6462
}
6563

64+
async function getWorkerEndpoint(api: ApiPromise): Promise<string> {
65+
const registry = await api.query.teebag.enclaveRegistry.entries();
66+
const identityEnclaves = registry.reduce((enclaves, [, enclave]) => {
67+
if (enclave.isEmpty || !enclave.unwrap().workerType.isIdentity) {
68+
return enclaves;
69+
}
70+
return [...enclaves, enclave.unwrap()];
71+
}, [] as PalletTeebagEnclave[]);
72+
73+
if (identityEnclaves.length === 0) {
74+
throw new Error('No identity worker found');
75+
}
76+
77+
return identityEnclaves[Math.floor(Math.random() * identityEnclaves.length)].url.toHuman() as string;
78+
}
79+
6680
export async function getEnclave(api: ApiPromise): Promise<{
6781
mrEnclave: HexString;
6882
teeShieldingKey: KeyObject;

tee-worker/ts-tests/integration-tests/common/utils/integration-setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function describeLitentry(title: string, cb: (context: IntegrationTestCon
2727
before('Starting Litentry(parachain&tee)', async function () {
2828
//env url
2929

30-
const tmp = await initIntegrationTestContext(process.env.WORKER_ENDPOINT!, process.env.NODE_ENDPOINT!);
30+
const tmp = await initIntegrationTestContext(process.env.NODE_ENDPOINT!);
3131
context.mrEnclave = tmp.mrEnclave;
3232
context.api = tmp.api;
3333
context.tee = tmp.tee;

tee-worker/ts-tests/integration-tests/di_bitcoin_identity.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ describe('Test Identity (bitcoin direct invocation)', function () {
6060

6161
before(async () => {
6262
context = await initIntegrationTestContext(
63-
process.env.WORKER_ENDPOINT!, // @fixme evil assertion; centralize env access
6463
process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access
6564
);
6665
teeShieldingKey = await getTeeShieldingKey(context);

tee-worker/ts-tests/integration-tests/di_evm_identity.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ describe('Test Identity (evm direct invocation)', function () {
4848

4949
before(async () => {
5050
context = await initIntegrationTestContext(
51-
process.env.WORKER_ENDPOINT!, // @fixme evil assertion; centralize env access
5251
process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access
5352
);
5453
teeShieldingKey = await getTeeShieldingKey(context);

tee-worker/ts-tests/integration-tests/di_solana_identity.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ describe('Test Identity (solana direct invocation)', function () {
4646

4747
before(async () => {
4848
context = await initIntegrationTestContext(
49-
process.env.WORKER_ENDPOINT!, // @fixme evil assertion; centralize env access
5049
process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access
5150
);
5251
teeShieldingKey = await getTeeShieldingKey(context);

tee-worker/ts-tests/integration-tests/di_substrate_identity.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ describe('Test Identity (direct invocation)', function () {
5757

5858
before(async () => {
5959
context = await initIntegrationTestContext(
60-
process.env.WORKER_ENDPOINT!, // @fixme evil assertion; centralize env access
6160
process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access
6261
);
6362
teeShieldingKey = await getTeeShieldingKey(context);

tee-worker/ts-tests/integration-tests/di_vc.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ describe('Test Vc (direct invocation)', function () {
4040

4141
before(async () => {
4242
context = await initIntegrationTestContext(
43-
process.env.WORKER_ENDPOINT!, // @fixme evil assertion; centralize env access
4443
process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access
4544
);
4645
teeShieldingKey = await getTeeShieldingKey(context);

0 commit comments

Comments
 (0)