Skip to content

test: batch 2 conformity tests #4110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 48 additions & 62 deletions packages/server/tests/acceptance/conformityTests.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
// import {
// JSONSchemaObject,
// MethodObject,
// MethodOrReference,
// OpenrpcDocument,
// } from '@open-rpc/meta-schema';
// import { parseOpenRPCDocument } from '@open-rpc/schema-utils-js';
// import { expect } from 'chai';
import { JSONSchemaObject, MethodObject, MethodOrReference, OpenrpcDocument } from '@open-rpc/meta-schema';
import { parseOpenRPCDocument } from '@open-rpc/schema-utils-js';
import { expect } from 'chai';
import fs from 'fs';
import path from 'path';

// import WebSocket from 'ws';
import openRpcData from '../../../../docs/openrpc.json';
// import CallerContract from '../contracts/Caller.json';
// import LogsContract from '../contracts/Logs.json';
import CallerContract from '../contracts/Caller.json';
import LogsContract from '../contracts/Logs.json';
import {
chainId,
gasLimit,
Expand All @@ -26,9 +21,8 @@
setTransaction1559_2930AndBlockHash,
setTransaction1559AndBlockHash,
setTransaction2930AndBlockHash,
// WS_RELAY_URL,
} from './data/conformity/utils/constants';
// import { TestCases, UpdateParamFunction } from './data/conformity/utils/interfaces';
import { TestCases, UpdateParamFunction } from './data/conformity/utils/interfaces';
import { processFileContent, splitReqAndRes } from './data/conformity/utils/processors';
import {
createContractLegacyTransaction,
Expand All @@ -37,53 +31,45 @@
transaction1559_2930,
transaction2930,
} from './data/conformity/utils/transactions';
import {
getLatestBlockHash,
// sendRequestToRelay,
signAndSendRawTransaction,
} from './data/conformity/utils/utils';
// import { hasResponseFormatIssues, isResponseValid } from './data/conformity/utils/validations';
import { getLatestBlockHash, sendRequestToRelay, signAndSendRawTransaction } from './data/conformity/utils/utils';
import { isResponseValid } from './data/conformity/utils/validations';

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

// let relayOpenRpcData: OpenrpcDocument;
// (async () => {
// relayOpenRpcData = await parseOpenRPCDocument(JSON.stringify(openRpcData));
// })().catch((error) => console.error('Error parsing OpenRPC document:', error));

// const synthesizeTestCases = function (testCases: TestCases, updateParamIfNeeded: UpdateParamFunction) {
// for (const testName in testCases) {
// it(`${testName}`, async function () {
// const isErrorStatusExpected: boolean =
// (testCases[testName]?.status && testCases[testName].status != 200) ||
// !!JSON.parse(testCases[testName].response).error;
// const method = relayOpenRpcData.methods.find(
// (m: MethodOrReference): m is MethodObject => 'name' in m && m.name === testName.split(' ')[0],
// );
// const schema: JSONSchemaObject | undefined =
// method?.result && 'schema' in method.result && typeof method.result.schema === 'object'
// ? method.result.schema
// : undefined;
// try {
// const req = updateParamIfNeeded(testName, JSON.parse(testCases[testName].request));
// const res = await sendRequestToRelay(RELAY_URL, req, false);
// const isResFormatInvalid: boolean = hasResponseFormatIssues(res, JSON.parse(testCases[testName].response));
//
// if (schema && schema.pattern) {
// const check = isResponseValid(schema, res);
// expect(check).to.be.true;
// }
//
// expect(isResFormatInvalid).to.be.false;
// expect(isErrorStatusExpected).to.be.false;
// } catch (e: any) {
// expect(isErrorStatusExpected).to.be.true;
// expect(e?.response?.status).to.equal(testCases[testName].status);
// }
// });
// }
// };
let relayOpenRpcData: OpenrpcDocument;
(async () => {
relayOpenRpcData = await parseOpenRPCDocument(JSON.stringify(openRpcData));
})().catch((error) => console.error('Error parsing OpenRPC document:', error));

const synthesizeTestCases = function (testCases: TestCases, updateParamIfNeeded: UpdateParamFunction) {
for (const testName in testCases) {
it(`${testName}`, async function () {

Check warning on line 47 in packages/server/tests/acceptance/conformityTests.spec.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

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

Method (anonymous) has a cyclomatic complexity of 11 (limit is 8)
const isErrorStatusExpected: boolean =
(testCases[testName]?.status && testCases[testName].status != 200) ||
!!JSON.parse(testCases[testName].response).error;
const method = relayOpenRpcData.methods.find(
(m: MethodOrReference): m is MethodObject => 'name' in m && m.name === testName.split(' ')[0],
);
const schema: JSONSchemaObject | undefined =
method?.result && 'schema' in method.result && typeof method.result.schema === 'object'
? method.result.schema
: undefined;
try {
const req = updateParamIfNeeded(testName, JSON.parse(testCases[testName].request));
const res = await sendRequestToRelay(RELAY_URL, req, false);
if (schema && schema.pattern) {
const check = isResponseValid(schema, res);
expect(check).to.be.true;
}
expect(isErrorStatusExpected).to.be.false;
} catch (e: any) {
expect(isErrorStatusExpected).to.be.true;
expect(e?.response?.status).to.equal(testCases[testName].status);
}
});
}
};

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

let existingBlockFilter: string;
Expand Down Expand Up @@ -222,7 +208,7 @@
synthesizeTestCases(TEST_CASES_BATCH_2, updateParamIfNeeded);
});

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

let txHash: any;
Expand Down Expand Up @@ -254,7 +240,7 @@

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

describe('ws related rpc methods', async function () {
/* describe('ws related rpc methods', async function () {
let webSocket: WebSocket;
let contractAddress: string | null;
let existingFilter: string;
Expand Down Expand Up @@ -340,10 +326,10 @@
};

synthesizeWsTestCases(TEST_CASES_BATCH_3['ws-server'], updateParamIfNeeded);
});
});*/
});

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

let existingCallerContractAddress: string | null;
Expand Down Expand Up @@ -543,12 +529,12 @@
synthesizeTestCases(TEST_CASES_BATCH_4, updateParamIfNeeded);
});

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

const updateParamIfNeeded = (_testName: any, request: any) => request;
synthesizeTestCases(TEST_CASES_BATCH_5, updateParamIfNeeded);
});*/
});
});
Loading