Skip to content

Commit

Permalink
chore: edit acceptance tests
Browse files Browse the repository at this point in the history
Signed-off-by: nikolay <[email protected]>
  • Loading branch information
natanasow committed Sep 11, 2024
1 parent 3927017 commit b6160fa
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 104 deletions.
11 changes: 6 additions & 5 deletions packages/server/tests/acceptance/cacheService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import { expect } from 'chai';
import { CacheService } from '../../../../packages/relay/src/lib/services/cacheService/cacheService';
import { Registry } from 'prom-client';
import { EnvProviderService } from '@hashgraph/json-rpc-relay/src/lib/services/envProviderService';
const registry = new Registry();

const DATA_LABEL_PREFIX = 'acceptance-test-';
Expand Down Expand Up @@ -81,7 +82,7 @@ describe('@cache-service Acceptance Tests for shared cache', function () {
it('Fallsback to local cache for REDIS_ENABLED !== true', async () => {
const dataLabel = `${DATA_LABEL_PREFIX}3`;

process.env.REDIS_ENABLED = 'false';
EnvProviderService.getInstance().dynamicOverride('REDIS_ENABLED', 'false');
const serviceWithDisabledRedis = new CacheService(global.logger, registry);
await new Promise((r) => setTimeout(r, 1000));
expect(serviceWithDisabledRedis.isRedisEnabled()).to.eq(false, 'redis is disabled');
Expand All @@ -91,7 +92,7 @@ describe('@cache-service Acceptance Tests for shared cache', function () {
const dataInLRU = await serviceWithDisabledRedis.getAsync(dataLabel, CALLING_METHOD);
expect(dataInLRU).to.deep.eq(DATA, 'data is stored in local cache');

process.env.REDIS_ENABLED = 'true';
EnvProviderService.getInstance().dynamicOverride('REDIS_ENABLED', 'true');
});

it('Cache set by one instance can be accessed by another', async () => {
Expand All @@ -111,9 +112,9 @@ describe('@cache-service Acceptance Tests for shared cache', function () {
let cacheService;

before(async () => {
currentRedisEnabledEnv = process.env.REDIS_ENABLED;
currentRedisEnabledEnv = EnvProviderService.getInstance().get('REDIS_ENABLED');

process.env.REDIS_ENABLED = 'true';
EnvProviderService.getInstance().dynamicOverride('REDIS_ENABLED', 'true');
cacheService = new CacheService(global.logger, registry);

// disconnect redis client to simulate Redis error
Expand All @@ -122,7 +123,7 @@ describe('@cache-service Acceptance Tests for shared cache', function () {
});

after(async () => {
process.env.REDIS_ENABLED = currentRedisEnabledEnv;
EnvProviderService.getInstance().dynamicOverride('REDIS_ENABLED', currentRedisEnabledEnv);
});

it('test getAsync operation', async () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/server/tests/acceptance/conformityTests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ import Ajv from 'ajv';
import addFormats from 'ajv-formats';
import { signTransaction } from '../../../relay/tests/helpers';
import { expect } from 'chai';
import { config } from 'dotenv';
import WebSocket from 'ws';
import LogsContract from '../contracts/Logs.json';
import CallerContract from '../contracts/Caller.json';
config();

let currentBlockHash;
let legacyTransactionAndBlockHash;
Expand Down
30 changes: 17 additions & 13 deletions packages/server/tests/acceptance/hbarLimiter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,19 @@ import { Utils } from '../helpers/utils';
import { AliasAccount } from '../types/AliasAccount';
import Assertions from '../helpers/assertions';
import testConstants from '../helpers/constants';
import { EnvProviderService } from '@hashgraph/json-rpc-relay/src/lib/services/envProviderService';

// Contracts used in tests
import parentContractJson from '../contracts/Parent.json';
import EstimateGasContract from '../contracts/EstimateGasContract.json';
import largeContractJson from '../contracts/hbarLimiterContracts/largeSizeContract.json';
import mediumSizeContract from '../contracts/hbarLimiterContracts/mediumSizeContract.json';
import { resolve } from 'path';
import { config } from 'dotenv';

config({ path: resolve(__dirname, '../localAcceptance.env') });

describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () {
// @ts-ignore
const { mirrorNode, relay, logger, initialBalance, metrics, relayIsLocal } = global;
const operatorAccount = process.env.OPERATOR_ID_MAIN;
const fileAppendChunkSize = Number(process.env.FILE_APPEND_CHUNK_SIZE) || 5120;
const operatorAccount = EnvProviderService.getInstance().get('OPERATOR_ID_MAIN');
const fileAppendChunkSize = Number(EnvProviderService.getInstance().get('FILE_APPEND_CHUNK_SIZE')) || 5120;

// The following tests exhaust the hbar limit, so they should only be run against a local relay
if (relayIsLocal) {
Expand Down Expand Up @@ -130,7 +127,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () {
const accounts: AliasAccount[] = [];
const defaultLondonTransactionData = {
value: Utils.add0xPrefix(Utils.toHex(ethers.parseUnits('1', 10))), // 1 tinybar
chainId: Number(process.env.CHAIN_ID || 0),
chainId: Number(EnvProviderService.getInstance().get('CHAIN_ID') || 0),
maxPriorityFeePerGas: Assertions.defaultGasPrice,
maxFeePerGas: Assertions.defaultGasPrice,
gasLimit: 3_000_000,
Expand All @@ -149,7 +146,11 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () {
requestIdPrefix = Utils.formatRequestIdMessage(requestId);

logger.info(`${requestIdPrefix} Creating accounts`);
logger.info(`${requestIdPrefix} HBAR_RATE_LIMIT_TINYBAR: ${process.env.HBAR_RATE_LIMIT_TINYBAR}`);
logger.info(
`${requestIdPrefix} HBAR_RATE_LIMIT_TINYBAR: ${EnvProviderService.getInstance().get(
'HBAR_RATE_LIMIT_TINYBAR',
)}`,
);

const initialAccount: AliasAccount = global.accounts[0];

Expand All @@ -174,7 +175,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () {

describe('Remaining HBAR Limit', () => {
before(() => {
process.env.GET_RECORD_DEFAULT_TO_CONSENSUS_NODE = 'true';
EnvProviderService.getInstance().dynamicOverride('GET_RECORD_DEFAULT_TO_CONSENSUS_NODE', 'true');
});

it('should execute "eth_sendRawTransaction" without triggering HBAR rate limit exceeded', async function () {
Expand Down Expand Up @@ -244,8 +245,11 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () {
it('Should preemtively check the rate limit before submitting EthereumTransaction', async function () {
const remainingHbarsBefore = Number(await metrics.get(testConstants.METRICS.REMAINING_HBAR_LIMIT));

process.env.HBAR_RATE_LIMIT_PREEMTIVE_CHECK = 'true';
process.env.HOT_FIX_FILE_APPEND_FEE = (remainingHbarsBefore - 100000000).toString();
EnvProviderService.getInstance().dynamicOverride('HBAR_RATE_LIMIT_PREEMTIVE_CHECK', 'true');
EnvProviderService.getInstance().dynamicOverride(
'HOT_FIX_FILE_APPEND_FEE',
(remainingHbarsBefore - 100000000).toString(),
);

try {
const largeContract = await Utils.deployContract(
Expand All @@ -256,11 +260,11 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () {
await largeContract.waitForDeployment();

expect(true).to.be.false;
} catch (e) {
} catch (e: any) {
expect(e.message).to.contain(predefined.HBAR_RATE_LIMIT_PREEMTIVE_EXCEEDED.message);
}

delete process.env.HBAR_RATE_LIMIT_PREEMTIVE_CHECK;
EnvProviderService.getInstance().remove('HBAR_RATE_LIMIT_PREEMTIVE_CHECK');
});

it('HBAR limiter is updated within acceptable tolerance range in relation to actual spent amount by the relay operator', async function () {
Expand Down
37 changes: 18 additions & 19 deletions packages/server/tests/acceptance/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
// External resources
import chai from 'chai';
import dotenv from 'dotenv';
import path from 'path';
import pino from 'pino';
import chaiAsPromised from 'chai-as-promised';
Expand Down Expand Up @@ -48,13 +47,13 @@ import constants from '@hashgraph/json-rpc-relay/dist/lib/constants';
import { Utils } from '../helpers/utils';
import { AliasAccount } from '../types/AliasAccount';
import { setServerTimeout } from '../../src/koaJsonRpc/lib/utils';
import { EnvProviderService } from '@hashgraph/json-rpc-relay/src/lib/services/envProviderService';

chai.use(chaiAsPromised);
dotenv.config({ path: path.resolve(__dirname, '../../../.env') });

const testLogger = pino({
name: 'hedera-json-rpc-relay',
level: process.env.LOG_LEVEL || 'trace',
level: EnvProviderService.getInstance().get('LOG_LEVEL') || 'trace',
transport: {
target: 'pino-pretty',
options: {
Expand All @@ -65,14 +64,14 @@ const testLogger = pino({
});
const logger = testLogger.child({ name: 'rpc-acceptance-test' });

const NETWORK = process.env.HEDERA_NETWORK || '';
const OPERATOR_KEY = process.env.OPERATOR_KEY_MAIN || '';
const OPERATOR_ID = process.env.OPERATOR_ID_MAIN || '';
const MIRROR_NODE_URL = process.env.MIRROR_NODE_URL || '';
const NETWORK = EnvProviderService.getInstance().get('HEDERA_NETWORK') || '';
const OPERATOR_KEY = EnvProviderService.getInstance().get('OPERATOR_KEY_MAIN') || '';
const OPERATOR_ID = EnvProviderService.getInstance().get('OPERATOR_ID_MAIN') || '';
const MIRROR_NODE_URL = EnvProviderService.getInstance().get('MIRROR_NODE_URL') || '';
const LOCAL_RELAY_URL = 'http://localhost:7546';
const RELAY_URL = process.env.E2E_RELAY_HOST || LOCAL_RELAY_URL;
const CHAIN_ID = process.env.CHAIN_ID || '0x12a';
const INITIAL_BALANCE = process.env.INITIAL_BALANCE || '5000000000';
const RELAY_URL = EnvProviderService.getInstance().get('E2E_RELAY_HOST') || LOCAL_RELAY_URL;
const CHAIN_ID = EnvProviderService.getInstance().get('CHAIN_ID') || '0x12a';
const INITIAL_BALANCE = EnvProviderService.getInstance().get('INITIAL_BALANCE') || '5000000000';
let startOperatorBalance: Hbar;
global.relayIsLocal = RELAY_URL === LOCAL_RELAY_URL;

Expand Down Expand Up @@ -105,19 +104,19 @@ describe('RPC Server Acceptance Tests', function () {
};

// leak detection middleware
if (process.env.MEMWATCH_ENABLED === 'true') {
if (EnvProviderService.getInstance().get('MEMWATCH_ENABLED') === 'true') {
Utils.captureMemoryLeaks(new GCProfiler());
}

before(async () => {
// configuration details
logger.info('Acceptance Tests Configurations successfully loaded');
logger.info(`LOCAL_NODE: ${process.env.LOCAL_NODE}`);
logger.info(`CHAIN_ID: ${process.env.CHAIN_ID}`);
logger.info(`HEDERA_NETWORK: ${process.env.HEDERA_NETWORK}`);
logger.info(`OPERATOR_ID_MAIN: ${process.env.OPERATOR_ID_MAIN}`);
logger.info(`MIRROR_NODE_URL: ${process.env.MIRROR_NODE_URL}`);
logger.info(`E2E_RELAY_HOST: ${process.env.E2E_RELAY_HOST}`);
logger.info(`LOCAL_NODE: ${EnvProviderService.getInstance().get('LOCAL_NODE')}`);
logger.info(`CHAIN_ID: ${EnvProviderService.getInstance().get('CHAIN_ID')}`);
logger.info(`HEDERA_NETWORK: ${EnvProviderService.getInstance().get('HEDERA_NETWORK')}`);
logger.info(`OPERATOR_ID_MAIN: ${EnvProviderService.getInstance().get('OPERATOR_ID_MAIN')}`);
logger.info(`MIRROR_NODE_URL: ${EnvProviderService.getInstance().get('MIRROR_NODE_URL')}`);
logger.info(`E2E_RELAY_HOST: ${EnvProviderService.getInstance().get('E2E_RELAY_HOST')}`);

if (global.relayIsLocal) {
runLocalRelay();
Expand Down Expand Up @@ -197,7 +196,7 @@ describe('RPC Server Acceptance Tests', function () {
relayServer.close();
}

if (process.env.TEST_WS_SERVER === 'true' && global.socketServer !== undefined) {
if (EnvProviderService.getInstance().get('TEST_WS_SERVER') === 'true' && global.socketServer !== undefined) {
global.socketServer.close();
}
}
Expand All @@ -209,7 +208,7 @@ describe('RPC Server Acceptance Tests', function () {
relayServer = app.listen({ port: constants.RELAY_PORT });
setServerTimeout(relayServer);

if (process.env.TEST_WS_SERVER === 'true') {
if (EnvProviderService.getInstance().get('TEST_WS_SERVER') === 'true') {
logger.info(`Start ws-server on port ${constants.WEB_SOCKET_PORT}`);
global.socketServer = wsApp.listen({ port: constants.WEB_SOCKET_PORT });
}
Expand Down
7 changes: 5 additions & 2 deletions packages/server/tests/acceptance/rateLimiter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import Assertions from '../helpers/assertions';
import testConstants from '../../tests/helpers/constants';
import relayConstants from '../../../../packages/relay/src/lib/constants';
import { EnvProviderService } from '@hashgraph/json-rpc-relay/src/lib/services/envProviderService';

describe('@ratelimiter Rate Limiters Acceptance Tests', function () {
this.timeout(480 * 1000); // 480 seconds
Expand All @@ -33,9 +34,11 @@ describe('@ratelimiter Rate Limiters Acceptance Tests', function () {
let requestId: string;

const TIER_2_RATE_LIMIT =
(process.env.TIER_2_RATE_LIMIT as unknown as number) || relayConstants.DEFAULT_RATE_LIMIT.TIER_2;
(EnvProviderService.getInstance().get('TIER_2_RATE_LIMIT') as unknown as number) ||
relayConstants.DEFAULT_RATE_LIMIT.TIER_2;
const LIMIT_DURATION =
(process.env.LIMIT_DURATION as unknown as number) || relayConstants.DEFAULT_RATE_LIMIT.DURATION;
(EnvProviderService.getInstance().get('LIMIT_DURATION') as unknown as number) ||
relayConstants.DEFAULT_RATE_LIMIT.DURATION;

describe('RPC Rate Limiter Acceptance Tests', () => {
const sendMultipleRequests = async (method: string, params: any[], threshold: number) => {
Expand Down
7 changes: 4 additions & 3 deletions packages/server/tests/acceptance/rpc_batch1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import basicContract from '../../tests/contracts/Basic.json';

// Errors and constants from local resources
import { predefined } from '../../../relay/src/lib/errors/JsonRpcError';
import { EnvProviderService } from '@hashgraph/json-rpc-relay/src/lib/services/envProviderService';
import Constants from '../../../relay/src/lib/constants';
import RelayCalls from '../../tests/helpers/constants';

Expand All @@ -58,7 +59,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
let account2Address: string;
let expectedGasPrice: string;

const CHAIN_ID = process.env.CHAIN_ID || '0x12a';
const CHAIN_ID = EnvProviderService.getInstance().get('CHAIN_ID') || '0x12a';
const INCORRECT_CHAIN_ID = 999;
const GAS_PRICE_TOO_LOW = '0x1';
const GAS_PRICE_REF = '0x123456';
Expand Down Expand Up @@ -411,7 +412,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
it('should be able to return more than 2 logs with limit of 2 logs per request', async () => {
//for the purpose of the test, we are settings limit to 2, and fetching all.
//setting mirror node limit to 2 for this test only
process.env['MIRROR_NODE_LIMIT_PARAM'] = '2';
EnvProviderService.getInstance().dynamicOverride('MIRROR_NODE_LIMIT_PARAM', '2');
// calculate blocks behind latest, so we can fetch logs from the past.
// if current block is less than 10, we will fetch logs from the beginning otherwise we will fetch logs from 10 blocks behind latest
const currentBlock = Number(await relay.call(RelayCalls.ETH_ENDPOINTS.ETH_BLOCK_NUMBER, [], requestId));
Expand Down Expand Up @@ -722,7 +723,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
type: 1,
};

const gasPriceDeviation = parseFloat(process.env.TEST_GAS_PRICE_DEVIATION ?? '0.2');
const gasPriceDeviation = parseFloat(EnvProviderService.getInstance().get('TEST_GAS_PRICE_DEVIATION') ?? '0.2');

it('@release should execute "eth_getTransactionByBlockHashAndIndex"', async function () {
const response = await relay.call(
Expand Down
13 changes: 10 additions & 3 deletions packages/server/tests/acceptance/rpc_batch2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { predefined } from '@hashgraph/json-rpc-relay';
import { EthImpl } from '@hashgraph/json-rpc-relay/dist/lib/eth';
import { numberTo0x } from '@hashgraph/json-rpc-relay/dist/formatters';
import { ContractId, Hbar, HbarUnit } from '@hashgraph/sdk';
import { EnvProviderService } from '@hashgraph/json-rpc-relay/src/lib/services/envProviderService';

// Assertions from local resources
import Assertions from '../helpers/assertions';
Expand Down Expand Up @@ -64,7 +65,7 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
let createChildTx: ethers.ContractTransactionResponse;
let accounts0StartBalance: bigint;

const CHAIN_ID = process.env.CHAIN_ID || 0;
const CHAIN_ID = EnvProviderService.getInstance().get('CHAIN_ID') || 0;
const ONE_TINYBAR = Utils.add0xPrefix(Utils.toHex(ethers.parseUnits('1', 10)));
const ONE_WEIBAR = Utils.add0xPrefix(Utils.toHex(ethers.parseUnits('1', 18)));

Expand Down Expand Up @@ -416,7 +417,10 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
it('@release should call eth_gasPrice', async function () {
const res = await relay.call(RelayCalls.ETH_ENDPOINTS.ETH_GAS_PRICE, [], requestId);
expect(res).to.exist;
if (process.env.LOCAL_NODE && process.env.LOCAL_NODE !== 'false') {
if (
EnvProviderService.getInstance().get('LOCAL_NODE') &&
EnvProviderService.getInstance().get('LOCAL_NODE') !== 'false'
) {
expect(res).be.equal(expectedGasPrice);
} else {
expect(Number(res)).to.be.gt(0);
Expand Down Expand Up @@ -1061,7 +1065,10 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
});

// Only run the following tests against a local node since they only work with the genesis account
if (process.env.LOCAL_NODE && process.env.LOCAL_NODE !== 'false') {
if (
EnvProviderService.getInstance().get('LOCAL_NODE') &&
EnvProviderService.getInstance().get('LOCAL_NODE') !== 'false'
) {
describe('Gas Price related RPC endpoints', () => {
let lastBlockBeforeUpdate;
let lastBlockAfterUpdate;
Expand Down
15 changes: 8 additions & 7 deletions packages/server/tests/acceptance/rpc_batch3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import chai, { expect } from 'chai';
import chaiExclude from 'chai-exclude';
import Constants from '@hashgraph/json-rpc-relay/dist/lib/constants';
import { ContractId } from '@hashgraph/sdk';
import { EnvProviderService } from '@hashgraph/json-rpc-relay/src/lib/services/envProviderService';

// Assertions and constants from local resources
import Assertions from '../helpers/assertions';
Expand Down Expand Up @@ -63,7 +64,7 @@ describe('@api-batch-3 RPC Server Acceptance Tests', function () {
let mirrorPrimaryAccount: ethers.Wallet;
let mirrorSecondaryAccount: ethers.Wallet;

const CHAIN_ID = process.env.CHAIN_ID || 0;
const CHAIN_ID = EnvProviderService.getInstance().get('CHAIN_ID') || 0;
const ONE_TINYBAR = Utils.add0xPrefix(Utils.toHex(ethers.parseUnits('1', 10)));

let reverterContract: ethers.Contract;
Expand Down Expand Up @@ -535,8 +536,8 @@ describe('@api-batch-3 RPC Server Acceptance Tests', function () {

// value is processed only when eth_call goes through the mirror node
if (
process.env.ETH_CALL_DEFAULT_TO_CONSENSUS_NODE &&
process.env.ETH_CALL_DEFAULT_TO_CONSENSUS_NODE === 'false'
EnvProviderService.getInstance().get('ETH_CALL_DEFAULT_TO_CONSENSUS_NODE') &&
EnvProviderService.getInstance().get('ETH_CALL_DEFAULT_TO_CONSENSUS_NODE') === 'false'
) {
it('010 Should call msgValue', async function () {
const callData = {
Expand Down Expand Up @@ -601,7 +602,7 @@ describe('@api-batch-3 RPC Server Acceptance Tests', function () {
};

// Since we want the http status code, we need to perform the call using a client http request instead of using the relay instance directly
const testClientPort = process.env.E2E_SERVER_PORT || '7546';
const testClientPort = EnvProviderService.getInstance().get('E2E_SERVER_PORT') || '7546';
const testClient = Axios.create({
baseURL: 'http://localhost:' + testClientPort,
responseType: 'json' as const,
Expand Down Expand Up @@ -1970,12 +1971,12 @@ describe('@api-batch-3 RPC Server Acceptance Tests', function () {
let PREV_BATCH_REQUESTS_ENABLED: string | undefined;

before(async () => {
PREV_BATCH_REQUESTS_ENABLED = process.env.BATCH_REQUESTS_ENABLED;
process.env.BATCH_REQUESTS_ENABLED = 'true';
PREV_BATCH_REQUESTS_ENABLED = EnvProviderService.getInstance().get('BATCH_REQUESTS_ENABLED');
EnvProviderService.getInstance().dynamicOverride('BATCH_REQUESTS_ENABLED', 'true');
});

after(async () => {
process.env.BATCH_REQUESTS_ENABLED = PREV_BATCH_REQUESTS_ENABLED;
EnvProviderService.getInstance().dynamicOverride('BATCH_REQUESTS_ENABLED', PREV_BATCH_REQUESTS_ENABLED);
});

it('Should return a batch of requests', async function () {
Expand Down
Loading

0 comments on commit b6160fa

Please sign in to comment.