Skip to content

Commit 13e8db2

Browse files
test: batch 2 conformity tests (#3823)
Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas@arianelabs.com>
1 parent d39d19a commit 13e8db2

File tree

1 file changed

+48
-62
lines changed

1 file changed

+48
-62
lines changed

packages/server/tests/acceptance/conformityTests.spec.ts

Lines changed: 48 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
// import {
3-
// JSONSchemaObject,
4-
// MethodObject,
5-
// MethodOrReference,
6-
// OpenrpcDocument,
7-
// } from '@open-rpc/meta-schema';
8-
// import { parseOpenRPCDocument } from '@open-rpc/schema-utils-js';
9-
// import { expect } from 'chai';
2+
import { JSONSchemaObject, MethodObject, MethodOrReference, OpenrpcDocument } from '@open-rpc/meta-schema';
3+
import { parseOpenRPCDocument } from '@open-rpc/schema-utils-js';
4+
import { expect } from 'chai';
105
import fs from 'fs';
116
import path from 'path';
127

138
// import WebSocket from 'ws';
149
import openRpcData from '../../../../docs/openrpc.json';
15-
// import CallerContract from '../contracts/Caller.json';
16-
// import LogsContract from '../contracts/Logs.json';
10+
import CallerContract from '../contracts/Caller.json';
11+
import LogsContract from '../contracts/Logs.json';
1712
import {
1813
chainId,
1914
gasLimit,
@@ -26,9 +21,8 @@ import {
2621
setTransaction1559_2930AndBlockHash,
2722
setTransaction1559AndBlockHash,
2823
setTransaction2930AndBlockHash,
29-
// WS_RELAY_URL,
3024
} from './data/conformity/utils/constants';
31-
// import { TestCases, UpdateParamFunction } from './data/conformity/utils/interfaces';
25+
import { TestCases, UpdateParamFunction } from './data/conformity/utils/interfaces';
3226
import { processFileContent, splitReqAndRes } from './data/conformity/utils/processors';
3327
import {
3428
createContractLegacyTransaction,
@@ -37,53 +31,45 @@ import {
3731
transaction1559_2930,
3832
transaction2930,
3933
} from './data/conformity/utils/transactions';
40-
import {
41-
getLatestBlockHash,
42-
// sendRequestToRelay,
43-
signAndSendRawTransaction,
44-
} from './data/conformity/utils/utils';
45-
// import { hasResponseFormatIssues, isResponseValid } from './data/conformity/utils/validations';
34+
import { getLatestBlockHash, sendRequestToRelay, signAndSendRawTransaction } from './data/conformity/utils/utils';
35+
import { isResponseValid } from './data/conformity/utils/validations';
4636

4737
const directoryPath = path.resolve(__dirname, '../../../../node_modules/execution-apis/tests');
4838
const overwritesDirectoryPath = path.resolve(__dirname, 'data/conformity/overwrites');
4939

50-
// let relayOpenRpcData: OpenrpcDocument;
51-
// (async () => {
52-
// relayOpenRpcData = await parseOpenRPCDocument(JSON.stringify(openRpcData));
53-
// })().catch((error) => console.error('Error parsing OpenRPC document:', error));
54-
55-
// const synthesizeTestCases = function (testCases: TestCases, updateParamIfNeeded: UpdateParamFunction) {
56-
// for (const testName in testCases) {
57-
// it(`${testName}`, async function () {
58-
// const isErrorStatusExpected: boolean =
59-
// (testCases[testName]?.status && testCases[testName].status != 200) ||
60-
// !!JSON.parse(testCases[testName].response).error;
61-
// const method = relayOpenRpcData.methods.find(
62-
// (m: MethodOrReference): m is MethodObject => 'name' in m && m.name === testName.split(' ')[0],
63-
// );
64-
// const schema: JSONSchemaObject | undefined =
65-
// method?.result && 'schema' in method.result && typeof method.result.schema === 'object'
66-
// ? method.result.schema
67-
// : undefined;
68-
// try {
69-
// const req = updateParamIfNeeded(testName, JSON.parse(testCases[testName].request));
70-
// const res = await sendRequestToRelay(RELAY_URL, req, false);
71-
// const isResFormatInvalid: boolean = hasResponseFormatIssues(res, JSON.parse(testCases[testName].response));
72-
//
73-
// if (schema && schema.pattern) {
74-
// const check = isResponseValid(schema, res);
75-
// expect(check).to.be.true;
76-
// }
77-
//
78-
// expect(isResFormatInvalid).to.be.false;
79-
// expect(isErrorStatusExpected).to.be.false;
80-
// } catch (e: any) {
81-
// expect(isErrorStatusExpected).to.be.true;
82-
// expect(e?.response?.status).to.equal(testCases[testName].status);
83-
// }
84-
// });
85-
// }
86-
// };
40+
let relayOpenRpcData: OpenrpcDocument;
41+
(async () => {
42+
relayOpenRpcData = await parseOpenRPCDocument(JSON.stringify(openRpcData));
43+
})().catch((error) => console.error('Error parsing OpenRPC document:', error));
44+
45+
const synthesizeTestCases = function (testCases: TestCases, updateParamIfNeeded: UpdateParamFunction) {
46+
for (const testName in testCases) {
47+
it(`${testName}`, async function () {
48+
const isErrorStatusExpected: boolean =
49+
(testCases[testName]?.status && testCases[testName].status != 200) ||
50+
!!JSON.parse(testCases[testName].response).error;
51+
const method = relayOpenRpcData.methods.find(
52+
(m: MethodOrReference): m is MethodObject => 'name' in m && m.name === testName.split(' ')[0],
53+
);
54+
const schema: JSONSchemaObject | undefined =
55+
method?.result && 'schema' in method.result && typeof method.result.schema === 'object'
56+
? method.result.schema
57+
: undefined;
58+
try {
59+
const req = updateParamIfNeeded(testName, JSON.parse(testCases[testName].request));
60+
const res = await sendRequestToRelay(RELAY_URL, req, false);
61+
if (schema && schema.pattern) {
62+
const check = isResponseValid(schema, res);
63+
expect(check).to.be.true;
64+
}
65+
expect(isErrorStatusExpected).to.be.false;
66+
} catch (e: any) {
67+
expect(isErrorStatusExpected).to.be.true;
68+
expect(e?.response?.status).to.equal(testCases[testName].status);
69+
}
70+
});
71+
}
72+
};
8773

8874
/**
8975
* To run the Ethereum Execution API tests as defined in the repository ethereum/execution-apis, it’s necessary
@@ -152,7 +138,7 @@ describe('@api-conformity', async function () {
152138
//
153139
// These test suites must be un-skipped. The code requires refactoring to resolve the
154140
// static analysis issues before they can be re-enabled.
155-
/* describe.skip('@conformity-batch-2 Ethereum execution apis tests', async function () {
141+
describe('@conformity-batch-2 Ethereum execution apis tests', async function () {
156142
this.timeout(240 * 1000);
157143

158144
let existingBlockFilter: string;
@@ -222,7 +208,7 @@ describe('@api-conformity', async function () {
222208
synthesizeTestCases(TEST_CASES_BATCH_2, updateParamIfNeeded);
223209
});
224210

225-
describe.skip('@conformity-batch-3 Ethereum execution apis tests', async function () {
211+
describe('@conformity-batch-3 Ethereum execution apis tests', async function () {
226212
this.timeout(240 * 1000);
227213

228214
let txHash: any;
@@ -254,7 +240,7 @@ describe('@api-conformity', async function () {
254240

255241
synthesizeTestCases(TEST_CASES_BATCH_3['server'], updateParamIfNeeded);
256242

257-
describe('ws related rpc methods', async function () {
243+
/* describe('ws related rpc methods', async function () {
258244
let webSocket: WebSocket;
259245
let contractAddress: string | null;
260246
let existingFilter: string;
@@ -340,10 +326,10 @@ describe('@api-conformity', async function () {
340326
};
341327
342328
synthesizeWsTestCases(TEST_CASES_BATCH_3['ws-server'], updateParamIfNeeded);
343-
});
329+
});*/
344330
});
345331

346-
describe.skip('@conformity-batch-4 Ethereum execution apis tests', async function () {
332+
describe('@conformity-batch-4 Ethereum execution apis tests', async function () {
347333
this.timeout(240 * 1000);
348334

349335
let existingCallerContractAddress: string | null;
@@ -543,12 +529,12 @@ describe('@api-conformity', async function () {
543529
synthesizeTestCases(TEST_CASES_BATCH_4, updateParamIfNeeded);
544530
});
545531

546-
describe.skip('@conformity-batch-5 Ethereum execution apis tests', async function () {
532+
describe('@conformity-batch-5 Ethereum execution apis tests', async function () {
547533
this.timeout(240 * 1000);
548534
// eslint-disable-next-line @typescript-eslint/no-var-requires
549535
const TEST_CASES_BATCH_5 = require('./data/conformity-tests-batch-5.json');
550536

551537
const updateParamIfNeeded = (_testName: any, request: any) => request;
552538
synthesizeTestCases(TEST_CASES_BATCH_5, updateParamIfNeeded);
553-
});*/
539+
});
554540
});

0 commit comments

Comments
 (0)