diff --git a/docs/design/hbar-limiter.md b/docs/design/hbar-limiter.md index 3ba84649ac..fc7c2c941e 100644 --- a/docs/design/hbar-limiter.md +++ b/docs/design/hbar-limiter.md @@ -121,7 +121,7 @@ flowchart TD ### Supported Projects (EXTENDED tier) and Trusted Partners (PRIVILEGED tier): -**NOTE:** There will be one spending plan per project/partner with a total spending limit, shared amongst a group of users (IP and ETH addresses) linked to that plan. This means that they will share a common total spending limit for the project/partner. +**NOTE:** There will be one spending plan per project/partner with a total spending limit, shared amongst a group of users (IP and EVM addresses) linked to that plan. This means that they will share a common total spending limit for the project/partner. All users associated with a project/partner will be pre-configured in the relay as shown in the @@ -159,13 +159,13 @@ classDiagram class HBarLimitService { -hbarSpendingPlanRepository: HbarSpendingPlanRepository - -ethAddressHbarSpendingPlanRepository: EthAddressHbarSpendingPlanRepository + -evmAddressHbarSpendingPlanRepository: EvmAddressHbarSpendingPlanRepository -ipAddressHbarSpendingPlanRepository: IpAddressHbarSpendingPlanRepository +shouldLimit(txFrom: string, ip?: string) boolean +shouldPreemtivelyLimitFileTransactions(callDataSize: number, fileChunkSize: number, currentNetworkExchangeRateInCents: number) boolean +resetLimiter() void +addExpense(amount: number, txFrom: string, ip?: string) void - -getSpendingPlanOfEthAddress(address: string): HbarSpendingPlan + -getSpendingPlanOfEvmAddress(address: string): HbarSpendingPlan -getSpendingPlanOfIpAddress(ip: string): HbarSpendingPlan -checkTotalSpent() boolean -shouldReset() boolean @@ -202,8 +202,8 @@ classDiagram -timestamp: Date } - class EthAddressHbarSpendingPlan { - -ethAddress: string + class EvmAddressHbarSpendingPlan { + -evmAddress: string -planId: string } @@ -237,11 +237,11 @@ classDiagram +addToAmountSpent(id: string, amount: number): Promise } - class EthAddressHbarSpendingPlanRepository { + class EvmAddressHbarSpendingPlanRepository { -cache: CacheService - +findByAddress(ethAddress: string): Promise - +save(ethAddressPlan: EthAddressHbarSpendingPlan): Promise - +delete(ethAddress: string): Promise + +findByAddress(evmAddress: string): Promise + +save(evmAddressPlan: EvmAddressHbarSpendingPlan): Promise + +delete(evmAddress: string): Promise } class IpAddressHbarSpendingPlanRepository { @@ -259,11 +259,11 @@ classDiagram HbarSpendingPlan --> SubscriptionTier : could be one of the types HbarSpendingPlan --> HbarSpendingRecord : stores history of - EthAddressHbarSpendingPlan --> HbarSpendingPlan : links an ETH address to + EvmAddressHbarSpendingPlan --> HbarSpendingPlan : links an EVM address to IpAddressHbarSpendingPlan --> HbarSpendingPlan : links an IP address to HbarSpendingPlanRepository --> CacheService : uses - EthAddressHbarSpendingPlanRepository --> CacheService : uses + EvmAddressHbarSpendingPlanRepository --> CacheService : uses IpAddressHbarSpendingPlanRepository --> CacheService : uses ``` ### Support flexible alerting mechanisms for spending thresholds @@ -320,9 +320,9 @@ c. Current day's usage (increase limits if overall usage is low) ### Pre-populating the Cache with Spending Plans for Supported Projects and Partner Projects -The following configurations will be used to automatically populate the cache with `HbarSpendingPlan`, `EthAddressHbarSpendingPlan`, and `IPAddressHbarSpendingPlan` entries for the outlined supported projects and partner projects on every start-up of the relay. +The following configurations will be used to automatically populate the cache with `HbarSpendingPlan`, `EvmAddressHbarSpendingPlan`, and `IPAddressHbarSpendingPlan` entries for the outlined supported projects and partner projects on every start-up of the relay. -All other users (ETH and IP addresses which are not specified in the configuration file) will be treated as "general users" and will be assigned a basic `HbarSpendingPlan` on their first request and their ETH address and IP address will be linked to that plan for all subsequent requests. +All other users (ETH and IP addresses which are not specified in the configuration file) will be treated as "general users" and will be assigned a basic `HbarSpendingPlan` on their first request and their EVM address and IP address will be linked to that plan for all subsequent requests. ### JSON Configuration File @@ -337,20 +337,20 @@ The default filename for the configuration file is `spendingPlansConfig.json`, b { "id": "c758c095-342c-4607-9db5-867d7e90ab9d", "name": "partner name", - "ethAddresses": ["0x123", "0x124"], + "evmAddresses": ["0x123", "0x124"], "ipAddresses": ["127.0.0.1", "128.0.0.1"], "subscriptionTier": "PRIVILEGED" }, { "id": "a68488b0-6f7d-44a0-87c1-774ad64615f2", - "name": "some other partner that has given us only eth addresses", - "ethAddresses": ["0x125", "0x126"], + "name": "some other partner that has given us only evm addresses", + "evmAddresses": ["0x125", "0x126"], "subscriptionTier": "PRIVILEGED" }, { "id": "af13d6ed-d676-4d33-8b9d-cf05d1ad7134", "name": "supported project name", - "ethAddresses": ["0x127", "0x128"], + "evmAddresses": ["0x127", "0x128"], "ipAddresses": ["129.0.0.1", "130.0.0.1"], "subscriptionTier": "EXTENDED" }, @@ -366,7 +366,7 @@ The default filename for the configuration file is `spendingPlansConfig.json`, b #### Important notes - The `id` field is **strictly required** for each supported project or partner project. It is used as a unique identifier and as key in the cache and also for reference in the logs. We recommend using a UUID for this field, but any unique string will work. - The `name` field is used just for reference and can be any string. It is not used in the cache or for any other purpose, only for better readability in the logs on start-up of the relay when the spending plans are being configured. -- The `ethAddresses` and `ipAddresses` fields are arrays of strings containing the ETH addresses and IP addresses associated with the supported project or partner project. **At least one** of these two fields must be present and contain **at least one entry**. +- The `evmAddresses` and `ipAddresses` fields are arrays of strings containing the EVM addresses and IP addresses associated with the supported project or partner project. **At least one** of these two fields must be present and contain **at least one entry**. - The `subscriptionTier` field is also **required**. It is an enum with the following possible values: `BASIC`, `EXTENDED`, and `PRIVILEGED`. On every start-up, the relay will check if these entries are already populated in the cache. If not, it will populate them accordingly. @@ -386,7 +386,7 @@ The JSON file can also be updated over time to add new partners or supported pro { "id": "0b054498-5c48-4402-aad4-b9b455f33457", "name": "new partner name", - "ethAddresses": ["0x129", "0x130"], + "evmAddresses": ["0x129", "0x130"], "ipAddresses": ["133.0.0.1"], "subscriptionTier": "PRIVILEGED" } @@ -397,7 +397,7 @@ The JSON file can also be updated over time to add new partners or supported pro If some of the pre-configured plans are removed them from the JSON file, they will be considered "obsolete" and removed from the cache on the next start-up of the relay. -You can also add new ETH addresses or IP addresses to existing plans by updating the JSON file. +You can also add new EVM addresses or IP addresses to existing plans by updating the JSON file. ```javascript [ @@ -406,14 +406,14 @@ You can also add new ETH addresses or IP addresses to existing plans by updating { "id": "c758c095-342c-4607-9db5-867d7e90ab9d", "name": "partner name", - "ethAddresses": ["0x123", "0x124", ""], + "evmAddresses": ["0x123", "0x124", ""], "ipAddresses": ["127.0.0.1", "128.0.0.1", "", ""], "subscriptionTier": "PRIVILEGED", } ] ``` -Or if you remove any existing ETH addresses or IP addresses from the JSON file, only those will be removed from the cache on the next start-up. +Or if you remove any existing EVM addresses or IP addresses from the JSON file, only those will be removed from the cache on the next start-up. ```javascript [ @@ -422,7 +422,7 @@ Or if you remove any existing ETH addresses or IP addresses from the JSON file, { "id": "c758c095-342c-4607-9db5-867d7e90ab9d", "name": "partner name", - "ethAddresses": ["0x123"], // removed "0x124" + "evmAddresses": ["0x123"], // removed "0x124" "ipAddresses": ["127.0.0.1"], // removed "128.0.0.1" "subscriptionTier": "PRIVILEGED", } diff --git a/packages/relay/src/lib/config/hbarSpendingPlanConfigService.ts b/packages/relay/src/lib/config/hbarSpendingPlanConfigService.ts index 02f4a72e1e..bbb6bd4b5b 100644 --- a/packages/relay/src/lib/config/hbarSpendingPlanConfigService.ts +++ b/packages/relay/src/lib/config/hbarSpendingPlanConfigService.ts @@ -18,17 +18,18 @@ * */ -import fs from 'fs'; +import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; import findConfig from 'find-config'; -import { isValidSpendingPlanConfig, SpendingPlanConfig } from '../types/spendingPlanConfig'; +import fs from 'fs'; +import { Logger } from 'pino'; + +import { EvmAddressHbarSpendingPlanRepository } from '../db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository'; import { HbarSpendingPlanRepository } from '../db/repositories/hbarLimiter/hbarSpendingPlanRepository'; -import { EthAddressHbarSpendingPlanRepository } from '../db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository'; import { IPAddressHbarSpendingPlanRepository } from '../db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository'; -import { RequestDetails } from '../types'; -import { Logger } from 'pino'; -import { SubscriptionTier } from '../db/types/hbarLimiter/subscriptionTier'; import { IDetailedHbarSpendingPlan } from '../db/types/hbarLimiter/hbarSpendingPlan'; -import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; +import { SubscriptionTier } from '../db/types/hbarLimiter/subscriptionTier'; +import { RequestDetails } from '../types'; +import { isValidSpendingPlanConfig, SpendingPlanConfig } from '../types/spendingPlanConfig'; /** * Service for managing pre-configured {@link HbarSpendingPlan} entities. @@ -54,13 +55,13 @@ export class HbarSpendingPlanConfigService { * @constructor * @param {Logger} logger - The logger instance. * @param {HbarSpendingPlanRepository} hbarSpendingPlanRepository - The repository for HBAR spending plans. - * @param {EthAddressHbarSpendingPlanRepository} ethAddressHbarSpendingPlanRepository - The repository for ETH address associations. + * @param {EvmAddressHbarSpendingPlanRepository} evmAddressHbarSpendingPlanRepository - The repository for EVM address associations. * @param {IPAddressHbarSpendingPlanRepository} ipAddressHbarSpendingPlanRepository - The repository for IP address associations. */ constructor( private readonly logger: Logger, private readonly hbarSpendingPlanRepository: HbarSpendingPlanRepository, - private readonly ethAddressHbarSpendingPlanRepository: EthAddressHbarSpendingPlanRepository, + private readonly evmAddressHbarSpendingPlanRepository: EvmAddressHbarSpendingPlanRepository, private readonly ipAddressHbarSpendingPlanRepository: IPAddressHbarSpendingPlanRepository, ) {} @@ -73,17 +74,17 @@ export class HbarSpendingPlanConfigService { public static getPreconfiguredSpendingPlanKeys(logger: Logger): Set { try { const { collectionKey: hbarSpendingPlanKey } = HbarSpendingPlanRepository; - const { collectionKey: ethAddressHbarSpendingPlanKey } = EthAddressHbarSpendingPlanRepository; + const { collectionKey: evmAddressHbarSpendingPlanKey } = EvmAddressHbarSpendingPlanRepository; const { collectionKey: ipAddressHbarSpendingPlanKey } = IPAddressHbarSpendingPlanRepository; return new Set( this.loadSpendingPlansConfig(logger).flatMap((plan) => { - const { id, ethAddresses = [], ipAddresses = [] } = plan; + const { id, evmAddresses = [], ipAddresses = [] } = plan; return [ `${hbarSpendingPlanKey}:${id}`, `${hbarSpendingPlanKey}:${id}:amountSpent`, `${hbarSpendingPlanKey}:${id}:spendingHistory`, - ...ethAddresses.map((ethAddress) => `${ethAddressHbarSpendingPlanKey}:${ethAddress.trim().toLowerCase()}`), + ...evmAddresses.map((evmAddress) => `${evmAddressHbarSpendingPlanKey}:${evmAddress.trim().toLowerCase()}`), ...ipAddresses.map((ipAddress) => `${ipAddressHbarSpendingPlanKey}:${ipAddress}`), ]; }), @@ -201,7 +202,7 @@ export class HbarSpendingPlanConfigService { `Deleting HBAR spending plan with ID "${id}", as it is no longer in the spending plan configuration...`, ); await this.hbarSpendingPlanRepository.delete(id, requestDetails); - await this.ethAddressHbarSpendingPlanRepository.deleteAllByPlanId( + await this.evmAddressHbarSpendingPlanRepository.deleteAllByPlanId( id, 'populatePreconfiguredSpendingPlans', requestDetails, @@ -257,51 +258,51 @@ export class HbarSpendingPlanConfigService { `Updating associations for HBAR spending plan '${planConfig.name}' with ID ${planConfig.id}...`, ); } - await this.deleteObsoleteEthAddressAssociations(planConfig, requestDetails); + await this.deleteObsoleteEvmAddressAssociations(planConfig, requestDetails); await this.deleteObsoleteIpAddressAssociations(planConfig, requestDetails); - await this.updateEthAddressAssociations(planConfig, requestDetails); + await this.updateEvmAddressAssociations(planConfig, requestDetails); await this.updateIpAddressAssociations(planConfig, requestDetails); } } /** - * Updates the associations of an HBAR spending plan with ETH addresses. + * Updates the associations of an HBAR spending plan with EVM addresses. * * @param {SpendingPlanConfig} planConfig - The spending plan configuration. * @param {RequestDetails} requestDetails - The details of the current request. * @returns {Promise} - A promise that resolves when the operation is complete. * @private */ - private async updateEthAddressAssociations( + private async updateEvmAddressAssociations( planConfig: SpendingPlanConfig, requestDetails: RequestDetails, ): Promise { - const currentEthAddresses = await this.ethAddressHbarSpendingPlanRepository + const currentEvmAddresses = await this.evmAddressHbarSpendingPlanRepository .findAllByPlanId(planConfig.id, 'populatePreconfiguredSpendingPlans', requestDetails) - .then((ethAddressPlans) => ethAddressPlans.map((plan) => plan.ethAddress)); + .then((evmAddressPlans) => evmAddressPlans.map((plan) => plan.evmAddress)); - const addressesToDelete = currentEthAddresses.filter( - (ethAddress) => !planConfig.ethAddresses?.includes(ethAddress), + const addressesToDelete = currentEvmAddresses.filter( + (evmAddress) => !planConfig.evmAddresses?.includes(evmAddress), ); await Promise.all( - addressesToDelete.map(async (ethAddress) => { - await this.ethAddressHbarSpendingPlanRepository.delete(ethAddress, requestDetails); + addressesToDelete.map(async (evmAddress) => { + await this.evmAddressHbarSpendingPlanRepository.delete(evmAddress, requestDetails); this.logger.info( - `Removed association between ETH address ${ethAddress} and HBAR spending plan '${planConfig.name}'`, + `Removed association between EVM address ${evmAddress} and HBAR spending plan '${planConfig.name}'`, ); }), ); const addressesToAdd = - planConfig.ethAddresses?.filter((ethAddress) => !currentEthAddresses.includes(ethAddress)) || []; + planConfig.evmAddresses?.filter((evmAddress) => !currentEvmAddresses.includes(evmAddress)) || []; await Promise.all( - addressesToAdd.map(async (ethAddress) => { - await this.ethAddressHbarSpendingPlanRepository.save( - { ethAddress, planId: planConfig.id }, + addressesToAdd.map(async (evmAddress) => { + await this.evmAddressHbarSpendingPlanRepository.save( + { evmAddress, planId: planConfig.id }, requestDetails, this.TTL, ); - this.logger.info(`Associated HBAR spending plan '${planConfig.name}' with ETH address ${ethAddress}`); + this.logger.info(`Associated HBAR spending plan '${planConfig.name}' with EVM address ${evmAddress}`); }), ); } @@ -344,28 +345,28 @@ export class HbarSpendingPlanConfigService { } /** - * Deletes obsolete ETH address associations from the cache. + * Deletes obsolete EVM address associations from the cache. * - * For example, if an ETH address is associated with a plan different from the one in the {@link SPENDING_PLANS_CONFIG}, + * For example, if an EVM address is associated with a plan different from the one in the {@link SPENDING_PLANS_CONFIG}, * the association is deleted from the cache to allow the new association from the configuration file to take effect. * * @param {SpendingPlanConfig} planConfig - The spending plan configuration. * @param {RequestDetails} requestDetails - The details of the current request. * @private */ - private async deleteObsoleteEthAddressAssociations(planConfig: SpendingPlanConfig, requestDetails: RequestDetails) { - for (const ethAddress of planConfig.ethAddresses || []) { - const exists = await this.ethAddressHbarSpendingPlanRepository.existsByAddress(ethAddress, requestDetails); + private async deleteObsoleteEvmAddressAssociations(planConfig: SpendingPlanConfig, requestDetails: RequestDetails) { + for (const evmAddress of planConfig.evmAddresses || []) { + const exists = await this.evmAddressHbarSpendingPlanRepository.existsByAddress(evmAddress, requestDetails); if (exists) { - const ethAddressPlan = await this.ethAddressHbarSpendingPlanRepository.findByAddress( - ethAddress, + const evmAddressPlan = await this.evmAddressHbarSpendingPlanRepository.findByAddress( + evmAddress, requestDetails, ); - if (ethAddressPlan.planId !== planConfig.id) { + if (evmAddressPlan.planId !== planConfig.id) { this.logger.info( - `Deleting association between ETH address ${ethAddress} and HBAR spending plan '${planConfig.name}'`, + `Deleting association between EVM address ${evmAddress} and HBAR spending plan '${planConfig.name}'`, ); - await this.ethAddressHbarSpendingPlanRepository.delete(ethAddress, requestDetails); + await this.evmAddressHbarSpendingPlanRepository.delete(evmAddress, requestDetails); } } } diff --git a/packages/relay/src/lib/db/entities/hbarLimiter/ethAddressHbarSpendingPlan.ts b/packages/relay/src/lib/db/entities/hbarLimiter/evmAddressHbarSpendingPlan.ts similarity index 72% rename from packages/relay/src/lib/db/entities/hbarLimiter/ethAddressHbarSpendingPlan.ts rename to packages/relay/src/lib/db/entities/hbarLimiter/evmAddressHbarSpendingPlan.ts index 94a5cdf7cc..d3c34cd933 100644 --- a/packages/relay/src/lib/db/entities/hbarLimiter/ethAddressHbarSpendingPlan.ts +++ b/packages/relay/src/lib/db/entities/hbarLimiter/evmAddressHbarSpendingPlan.ts @@ -18,14 +18,14 @@ * */ -import { IEthAddressHbarSpendingPlan } from '../../types/hbarLimiter/ethAddressHbarSpendingPlan'; +import { IEvmAddressHbarSpendingPlan } from '../../types/hbarLimiter/evmAddressHbarSpendingPlan'; -export class EthAddressHbarSpendingPlan implements IEthAddressHbarSpendingPlan { - ethAddress: string; +export class EvmAddressHbarSpendingPlan implements IEvmAddressHbarSpendingPlan { + evmAddress: string; planId: string; - constructor(data: IEthAddressHbarSpendingPlan) { - this.ethAddress = data.ethAddress; + constructor(data: IEvmAddressHbarSpendingPlan) { + this.evmAddress = data.evmAddress; this.planId = data.planId; } } diff --git a/packages/relay/src/lib/db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository.ts b/packages/relay/src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository.ts similarity index 57% rename from packages/relay/src/lib/db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository.ts rename to packages/relay/src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository.ts index 98e85a38a0..19fc01f841 100644 --- a/packages/relay/src/lib/db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository.ts +++ b/packages/relay/src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository.ts @@ -18,15 +18,16 @@ * */ -import { CacheService } from '../../../services/cacheService/cacheService'; import { Logger } from 'pino'; -import { IEthAddressHbarSpendingPlan } from '../../types/hbarLimiter/ethAddressHbarSpendingPlan'; -import { EthAddressHbarSpendingPlanNotFoundError } from '../../types/hbarLimiter/errors'; -import { EthAddressHbarSpendingPlan } from '../../entities/hbarLimiter/ethAddressHbarSpendingPlan'; + +import { CacheService } from '../../../services/cacheService/cacheService'; import { RequestDetails } from '../../../types'; +import { EvmAddressHbarSpendingPlan } from '../../entities/hbarLimiter/evmAddressHbarSpendingPlan'; +import { EvmAddressHbarSpendingPlanNotFoundError } from '../../types/hbarLimiter/errors'; +import { IEvmAddressHbarSpendingPlan } from '../../types/hbarLimiter/evmAddressHbarSpendingPlan'; -export class EthAddressHbarSpendingPlanRepository { - public static readonly collectionKey = 'ethAddressHbarSpendingPlan'; +export class EvmAddressHbarSpendingPlanRepository { + public static readonly collectionKey = 'evmAddressHbarSpendingPlan'; /** * The cache service used for storing data. @@ -46,44 +47,44 @@ export class EthAddressHbarSpendingPlanRepository { } /** - * Checks if an {@link EthAddressHbarSpendingPlan} exists for an ETH address. + * Checks if an {@link EvmAddressHbarSpendingPlan} exists for an EVM address. * - * @param {string} ethAddress - The ETH address to check for. + * @param {string} evmAddress - The EVM address to check for. * @param {RequestDetails} requestDetails - The request details for logging and tracking. * @returns {Promise} - A promise that resolves with a boolean indicating if the plan exists. */ - async existsByAddress(ethAddress: string, requestDetails: RequestDetails): Promise { - const key = this.getKey(ethAddress); - const addressPlan = await this.cache.getAsync(key, 'existsByAddress', requestDetails); + async existsByAddress(evmAddress: string, requestDetails: RequestDetails): Promise { + const key = this.getKey(evmAddress); + const addressPlan = await this.cache.getAsync(key, 'existsByAddress', requestDetails); return !!addressPlan; } /** - * Finds all ETH addresses associated with a spending plan. + * Finds all EVM addresses associated with a spending plan. * @param {string} planId - The ID of the spending plan to search for. * @param {string} callingMethod - The method calling this function. * @param {RequestDetails} requestDetails - The request details for logging and tracking. - * @returns {Promise} - A promise that resolves with an array of associated plans. + * @returns {Promise} - A promise that resolves with an array of associated plans. */ async findAllByPlanId( planId: string, callingMethod: string, requestDetails: RequestDetails, - ): Promise { - const ethAddressPlans: EthAddressHbarSpendingPlan[] = []; + ): Promise { + const evmAddressPlans: EvmAddressHbarSpendingPlan[] = []; const key = this.getKey('*'); const keys = await this.cache.keys(key, callingMethod, requestDetails); for (const key of keys) { - const addressPlan = await this.cache.getAsync(key, callingMethod, requestDetails); + const addressPlan = await this.cache.getAsync(key, callingMethod, requestDetails); if (addressPlan?.planId === planId) { - ethAddressPlans.push(new EthAddressHbarSpendingPlan(addressPlan)); + evmAddressPlans.push(new EvmAddressHbarSpendingPlan(addressPlan)); } } - return ethAddressPlans; + return evmAddressPlans; } /** - * Deletes all ETH addresses associated with a spending plan. + * Deletes all EVM addresses associated with a spending plan. * @param planId - The ID of the spending plan to search for. * @param callingMethod - The method calling this function. * @param requestDetails - The request details for logging and tracking. @@ -92,11 +93,11 @@ export class EthAddressHbarSpendingPlanRepository { const key = this.getKey('*'); const keys = await this.cache.keys(key, callingMethod, requestDetails); for (const key of keys) { - const addressPlan = await this.cache.getAsync(key, callingMethod, requestDetails); + const addressPlan = await this.cache.getAsync(key, callingMethod, requestDetails); if (addressPlan?.planId === planId) { if (this.logger.isLevelEnabled('trace')) { this.logger.trace( - `${requestDetails.formattedRequestId} Removing ETH address ${addressPlan.ethAddress} from HbarSpendingPlan with ID ${planId}`, + `${requestDetails.formattedRequestId} Removing EVM address ${addressPlan.evmAddress} from HbarSpendingPlan with ID ${planId}`, ); } await this.cache.delete(key, callingMethod, requestDetails); @@ -105,70 +106,70 @@ export class EthAddressHbarSpendingPlanRepository { } /** - * Finds an {@link EthAddressHbarSpendingPlan} for an ETH address. + * Finds an {@link EvmAddressHbarSpendingPlan} for an EVM address. * - * @param {string} ethAddress - The ETH address to search for. + * @param {string} evmAddress - The EVM address to search for. * @param {RequestDetails} requestDetails - The request details for logging and tracking. - * @returns {Promise} - The associated plan for the ETH address. + * @returns {Promise} - The associated plan for the EVM address. */ - async findByAddress(ethAddress: string, requestDetails: RequestDetails): Promise { - const key = this.getKey(ethAddress); - const addressPlan = await this.cache.getAsync(key, 'findByAddress', requestDetails); + async findByAddress(evmAddress: string, requestDetails: RequestDetails): Promise { + const key = this.getKey(evmAddress); + const addressPlan = await this.cache.getAsync(key, 'findByAddress', requestDetails); if (!addressPlan) { - throw new EthAddressHbarSpendingPlanNotFoundError(ethAddress); + throw new EvmAddressHbarSpendingPlanNotFoundError(evmAddress); } if (this.logger.isLevelEnabled('trace')) { this.logger.trace( - `${requestDetails.formattedRequestId} Retrieved link between ETH address ${ethAddress} and HbarSpendingPlan with ID ${addressPlan.planId}`, + `${requestDetails.formattedRequestId} Retrieved link between EVM address ${evmAddress} and HbarSpendingPlan with ID ${addressPlan.planId}`, ); } - return new EthAddressHbarSpendingPlan(addressPlan); + return new EvmAddressHbarSpendingPlan(addressPlan); } /** - * Saves an {@link EthAddressHbarSpendingPlan} to the cache, linking the plan to the ETH address. + * Saves an {@link EvmAddressHbarSpendingPlan} to the cache, linking the plan to the EVM address. * - * @param {IEthAddressHbarSpendingPlan} addressPlan - The plan to save. + * @param {IEvmAddressHbarSpendingPlan} addressPlan - The plan to save. * @param {RequestDetails} requestDetails - The request details for logging and tracking. * @param {number} ttl - The time-to-live for the cache entry. - * @returns {Promise} - A promise that resolves when the ETH address is linked to the plan. + * @returns {Promise} - A promise that resolves when the EVM address is linked to the plan. */ - async save(addressPlan: IEthAddressHbarSpendingPlan, requestDetails: RequestDetails, ttl: number): Promise { - const key = this.getKey(addressPlan.ethAddress); + async save(addressPlan: IEvmAddressHbarSpendingPlan, requestDetails: RequestDetails, ttl: number): Promise { + const key = this.getKey(addressPlan.evmAddress); await this.cache.set(key, addressPlan, 'save', requestDetails, ttl); if (this.logger.isLevelEnabled('trace')) { this.logger.trace( - `${requestDetails.formattedRequestId} Linked ETH address ${addressPlan.ethAddress} to HbarSpendingPlan with ID ${addressPlan.planId}`, + `${requestDetails.formattedRequestId} Linked EVM address ${addressPlan.evmAddress} to HbarSpendingPlan with ID ${addressPlan.planId}`, ); } } /** - * Deletes an {@link EthAddressHbarSpendingPlan} from the cache, unlinking the plan from the ETH address. + * Deletes an {@link EvmAddressHbarSpendingPlan} from the cache, unlinking the plan from the EVM address. * - * @param {string} ethAddress - The ETH address to unlink the plan from. + * @param {string} evmAddress - The EVM address to unlink the plan from. * @param {RequestDetails} requestDetails - The request details for logging and tracking. - * @returns {Promise} - A promise that resolves when the ETH address is unlinked from the plan. + * @returns {Promise} - A promise that resolves when the EVM address is unlinked from the plan. */ - async delete(ethAddress: string, requestDetails: RequestDetails): Promise { - const key = this.getKey(ethAddress); - const ethAddressPlan = await this.cache.getAsync(key, 'delete', requestDetails); + async delete(evmAddress: string, requestDetails: RequestDetails): Promise { + const key = this.getKey(evmAddress); + const evmAddressPlan = await this.cache.getAsync(key, 'delete', requestDetails); await this.cache.delete(key, 'delete', requestDetails); - const errorMessage = ethAddressPlan - ? `Removed ETH address ${ethAddress} from HbarSpendingPlan with ID ${ethAddressPlan.planId}` - : `Trying to remove ETH address ${ethAddress}, which is not linked to a spending plan`; + const errorMessage = evmAddressPlan + ? `Removed EVM address ${evmAddress} from HbarSpendingPlan with ID ${evmAddressPlan.planId}` + : `Trying to remove EVM address ${evmAddress}, which is not linked to a spending plan`; if (this.logger.isLevelEnabled('trace')) { this.logger.trace(`${requestDetails.formattedRequestId} ${errorMessage}`); } } /** - * Gets the cache key for an {@link EthAddressHbarSpendingPlan}. + * Gets the cache key for an {@link EvmAddressHbarSpendingPlan}. * - * @param {string} ethAddress - The ETH address to get the key for. + * @param {string} evmAddress - The EVM address to get the key for. * @private */ - private getKey(ethAddress: string): string { - return `${EthAddressHbarSpendingPlanRepository.collectionKey}:${ethAddress?.trim().toLowerCase()}`; + private getKey(evmAddress: string): string { + return `${EvmAddressHbarSpendingPlanRepository.collectionKey}:${evmAddress?.trim().toLowerCase()}`; } } diff --git a/packages/relay/src/lib/db/types/hbarLimiter/errors.ts b/packages/relay/src/lib/db/types/hbarLimiter/errors.ts index bacfd0562d..7edd3d2df1 100644 --- a/packages/relay/src/lib/db/types/hbarLimiter/errors.ts +++ b/packages/relay/src/lib/db/types/hbarLimiter/errors.ts @@ -32,10 +32,10 @@ export class HbarSpendingPlanNotActiveError extends Error { } } -export class EthAddressHbarSpendingPlanNotFoundError extends Error { - constructor(ethAddress: string) { - super(`EthAddressHbarSpendingPlan with address ${ethAddress} not found`); - this.name = 'EthAddressHbarSpendingPlanNotFoundError'; +export class EvmAddressHbarSpendingPlanNotFoundError extends Error { + constructor(evmAddress: string) { + super(`EvmAddressHbarSpendingPlan with address ${evmAddress} not found`); + this.name = 'EvmAddressHbarSpendingPlanNotFoundError'; } } diff --git a/packages/relay/src/lib/db/types/hbarLimiter/ethAddressHbarSpendingPlan.ts b/packages/relay/src/lib/db/types/hbarLimiter/evmAddressHbarSpendingPlan.ts similarity index 90% rename from packages/relay/src/lib/db/types/hbarLimiter/ethAddressHbarSpendingPlan.ts rename to packages/relay/src/lib/db/types/hbarLimiter/evmAddressHbarSpendingPlan.ts index e537dff1a1..ab02fdadeb 100644 --- a/packages/relay/src/lib/db/types/hbarLimiter/ethAddressHbarSpendingPlan.ts +++ b/packages/relay/src/lib/db/types/hbarLimiter/evmAddressHbarSpendingPlan.ts @@ -18,7 +18,7 @@ * */ -export interface IEthAddressHbarSpendingPlan { - ethAddress: string; +export interface IEvmAddressHbarSpendingPlan { + evmAddress: string; planId: string; } diff --git a/packages/relay/src/lib/relay.ts b/packages/relay/src/lib/relay.ts index a2b37d3e2e..061dd8909d 100644 --- a/packages/relay/src/lib/relay.ts +++ b/packages/relay/src/lib/relay.ts @@ -18,30 +18,31 @@ * */ -import { Logger } from 'pino'; -import { NetImpl } from './net'; -import { EthImpl } from './eth'; -import { Utils } from '../utils'; -import { Poller } from './poller'; -import { Web3Impl } from './web3'; -import EventEmitter from 'events'; -import constants from './constants'; +import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; import { Client, Hbar } from '@hashgraph/sdk'; -import { RequestDetails } from './types'; -import { prepend0x } from '../formatters'; -import { MirrorNodeClient } from './clients'; +import EventEmitter from 'events'; +import { Logger } from 'pino'; import { Gauge, Registry } from 'prom-client'; + +import { prepend0x } from '../formatters'; import { Eth, Net, Relay, Subs, Web3 } from '../index'; -import HAPIService from './services/hapiService/hapiService'; -import { HbarLimitService } from './services/hbarLimitService'; -import { SubscriptionController } from './subscriptionController'; -import MetricService from './services/metricService/metricService'; -import { CacheService } from './services/cacheService/cacheService'; -import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; +import { Utils } from '../utils'; +import { MirrorNodeClient } from './clients'; import { HbarSpendingPlanConfigService } from './config/hbarSpendingPlanConfigService'; +import constants from './constants'; +import { EvmAddressHbarSpendingPlanRepository } from './db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository'; import { HbarSpendingPlanRepository } from './db/repositories/hbarLimiter/hbarSpendingPlanRepository'; import { IPAddressHbarSpendingPlanRepository } from './db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository'; -import { EthAddressHbarSpendingPlanRepository } from './db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository'; +import { EthImpl } from './eth'; +import { NetImpl } from './net'; +import { Poller } from './poller'; +import { CacheService } from './services/cacheService/cacheService'; +import HAPIService from './services/hapiService/hapiService'; +import { HbarLimitService } from './services/hbarLimitService'; +import MetricService from './services/metricService/metricService'; +import { SubscriptionController } from './subscriptionController'; +import { RequestDetails } from './types'; +import { Web3Impl } from './web3'; export class RelayImpl implements Relay { /** @@ -145,7 +146,7 @@ export class RelayImpl implements Relay { this.cacheService, logger.child({ name: 'hbar-spending-plan-repository' }), ); - const ethAddressHbarSpendingPlanRepository = new EthAddressHbarSpendingPlanRepository( + const evmAddressHbarSpendingPlanRepository = new EvmAddressHbarSpendingPlanRepository( this.cacheService, logger.child({ name: 'evm-address-spending-plan-repository' }), ); @@ -155,7 +156,7 @@ export class RelayImpl implements Relay { ); const hbarLimitService = new HbarLimitService( hbarSpendingPlanRepository, - ethAddressHbarSpendingPlanRepository, + evmAddressHbarSpendingPlanRepository, ipAddressHbarSpendingPlanRepository, logger.child({ name: 'hbar-rate-limit' }), register, @@ -201,7 +202,7 @@ export class RelayImpl implements Relay { this.hbarSpendingPlanConfigService = new HbarSpendingPlanConfigService( logger.child({ name: 'hbar-spending-plan-config-service' }), hbarSpendingPlanRepository, - ethAddressHbarSpendingPlanRepository, + evmAddressHbarSpendingPlanRepository, ipAddressHbarSpendingPlanRepository, ); diff --git a/packages/relay/src/lib/services/hbarLimitService/IHbarLimitService.ts b/packages/relay/src/lib/services/hbarLimitService/IHbarLimitService.ts index 0018024e6a..87fcb7fb84 100644 --- a/packages/relay/src/lib/services/hbarLimitService/IHbarLimitService.ts +++ b/packages/relay/src/lib/services/hbarLimitService/IHbarLimitService.ts @@ -26,10 +26,10 @@ export interface IHbarLimitService { mode: string, methodName: string, txConstructorName: string, - ethAddress: string, + evmAddress: string, requestDetails: RequestDetails, estimatedTxFee?: number, ): Promise; - addExpense(cost: number, ethAddress: string, requestDetails: RequestDetails, ipAddress?: string): Promise; + addExpense(cost: number, evmAddress: string, requestDetails: RequestDetails, ipAddress?: string): Promise; isEnabled(): boolean; } diff --git a/packages/relay/src/lib/services/hbarLimitService/index.ts b/packages/relay/src/lib/services/hbarLimitService/index.ts index 0acea72767..e12cfa14fc 100644 --- a/packages/relay/src/lib/services/hbarLimitService/index.ts +++ b/packages/relay/src/lib/services/hbarLimitService/index.ts @@ -18,17 +18,18 @@ * */ +import { Hbar } from '@hashgraph/sdk'; import { Logger } from 'pino'; import { Counter, Gauge, Registry } from 'prom-client'; -import { IHbarLimitService } from './IHbarLimitService'; -import { SubscriptionTier } from '../../db/types/hbarLimiter/subscriptionTier'; -import { IDetailedHbarSpendingPlan } from '../../db/types/hbarLimiter/hbarSpendingPlan'; + +import constants from '../../constants'; +import { EvmAddressHbarSpendingPlanRepository } from '../../db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository'; import { HbarSpendingPlanRepository } from '../../db/repositories/hbarLimiter/hbarSpendingPlanRepository'; -import { EthAddressHbarSpendingPlanRepository } from '../../db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository'; import { IPAddressHbarSpendingPlanRepository } from '../../db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository'; +import { IDetailedHbarSpendingPlan } from '../../db/types/hbarLimiter/hbarSpendingPlan'; +import { SubscriptionTier } from '../../db/types/hbarLimiter/subscriptionTier'; import { RequestDetails } from '../../types'; -import constants from '../../constants'; -import { Hbar } from '@hashgraph/sdk'; +import { IHbarLimitService } from './IHbarLimitService'; export class HbarLimitService implements IHbarLimitService { static readonly TIER_LIMITS: Record = { @@ -86,7 +87,7 @@ export class HbarLimitService implements IHbarLimitService { constructor( private readonly hbarSpendingPlanRepository: HbarSpendingPlanRepository, - private readonly ethAddressHbarSpendingPlanRepository: EthAddressHbarSpendingPlanRepository, + private readonly evmAddressHbarSpendingPlanRepository: EvmAddressHbarSpendingPlanRepository, private readonly ipAddressHbarSpendingPlanRepository: IPAddressHbarSpendingPlanRepository, private readonly logger: Logger, private readonly register: Registry, @@ -181,12 +182,12 @@ export class HbarLimitService implements IHbarLimitService { } /** - * Checks if the given eth address or ip address should be limited. + * Checks if the given evm address or ip address should be limited. * * @param {string} mode - The mode of the transaction or request. * @param {string} methodName - The name of the method being invoked. * @param {string} txConstructorName - The name of the transaction constructor associated with the transaction. - * @param {string} ethAddress - The eth address to check. + * @param {string} evmAddress - The evm address to check. * @param {RequestDetails} requestDetails The request details for logging and tracking. * @param {number} [estimatedTxFee] - The total estimated transaction fee, default to 0. * @returns {Promise} - A promise that resolves with a boolean indicating if the address should be limited. @@ -195,7 +196,7 @@ export class HbarLimitService implements IHbarLimitService { mode: string, methodName: string, txConstructorName: string, - ethAddress: string, + evmAddress: string, requestDetails: RequestDetails, estimatedTxFee: number = 0, ): Promise { @@ -208,20 +209,20 @@ export class HbarLimitService implements IHbarLimitService { return true; } - if (!ethAddress && !ipAddress) { + if (!evmAddress && !ipAddress) { this.logger.warn( - `${requestDetails.formattedRequestId} No eth address or ip address provided, cannot check if address should be limited.`, + `${requestDetails.formattedRequestId} No evm address or ip address provided, cannot check if address should be limited.`, ); return false; } - const user = `(ethAddress=${ethAddress})`; + const user = `(evmAddress=${evmAddress})`; if (this.logger.isLevelEnabled('trace')) { this.logger.trace(`${requestDetails.formattedRequestId} Checking if ${user} should be limited...`); } - let spendingPlan = await this.getSpendingPlan(ethAddress, requestDetails); + let spendingPlan = await this.getSpendingPlan(evmAddress, requestDetails); if (!spendingPlan) { - // Create a basic spending plan if none exists for the eth address or ip address - spendingPlan = await this.createBasicSpendingPlan(ethAddress, requestDetails); + // Create a basic spending plan if none exists for the evm address or ip address + spendingPlan = await this.createBasicSpendingPlan(evmAddress, requestDetails); } const spendingLimit = HbarLimitService.TIER_LIMITS[spendingPlan.subscriptionTier].toTinybars(); @@ -252,11 +253,11 @@ export class HbarLimitService implements IHbarLimitService { /** * Add expense to the remaining budget and update the spending plan if applicable. * @param {number} cost - The cost of the expense. - * @param {string} ethAddress - The Ethereum address to add the expense to. + * @param {string} evmAddress - The Ethereum address to add the expense to. * @param {RequestDetails} requestDetails The request details for logging and tracking. * @returns {Promise} - A promise that resolves when the expense has been added. */ - async addExpense(cost: number, ethAddress: string, requestDetails: RequestDetails): Promise { + async addExpense(cost: number, evmAddress: string, requestDetails: RequestDetails): Promise { if (!this.isEnabled()) { return; } @@ -266,21 +267,21 @@ export class HbarLimitService implements IHbarLimitService { this.hbarLimitRemainingGauge.set(newRemainingBudget.toNumber()); const ipAddress = requestDetails.ipAddress; - if (!ethAddress && !ipAddress) { + if (!evmAddress && !ipAddress) { if (this.logger.isLevelEnabled('trace')) { - this.logger.trace('Cannot add expense to a spending plan without an eth address or ip address'); + this.logger.trace('Cannot add expense to a spending plan without an evm address or ip address'); } return; } - let spendingPlan = await this.getSpendingPlan(ethAddress, requestDetails); + let spendingPlan = await this.getSpendingPlan(evmAddress, requestDetails); if (!spendingPlan) { - if (ethAddress) { - // Create a basic spending plan if none exists for the eth address - spendingPlan = await this.createBasicSpendingPlan(ethAddress, requestDetails); + if (evmAddress) { + // Create a basic spending plan if none exists for the evm address + spendingPlan = await this.createBasicSpendingPlan(evmAddress, requestDetails); } else { this.logger.warn( - `${requestDetails.formattedRequestId} Cannot add expense to a spending plan without an eth address or ip address`, + `${requestDetails.formattedRequestId} Cannot add expense to a spending plan without an evm address or ip address`, ); return; } @@ -431,24 +432,24 @@ export class HbarLimitService implements IHbarLimitService { } /** - * Gets the spending plan for the given eth address or ip address. - * @param {string} ethAddress - The eth address to get the spending plan for. + * Gets the spending plan for the given evm address or ip address. + * @param {string} evmAddress - The evm address to get the spending plan for. * @param {RequestDetails} requestDetails - The request details for logging and tracking. * @returns {Promise} - A promise that resolves with the spending plan or null if none exists. * @private */ private async getSpendingPlan( - ethAddress: string, + evmAddress: string, requestDetails: RequestDetails, ): Promise { const ipAddress = requestDetails.ipAddress; - if (ethAddress) { + if (evmAddress) { try { - return await this.getSpendingPlanByEthAddress(ethAddress, requestDetails); + return await this.getSpendingPlanByEvmAddress(evmAddress, requestDetails); } catch (error) { this.logger.warn( error, - `${requestDetails.formattedRequestId} Failed to get spending plan for eth address '${ethAddress}'`, + `${requestDetails.formattedRequestId} Failed to get spending plan for evm address '${evmAddress}'`, ); } } @@ -464,21 +465,21 @@ export class HbarLimitService implements IHbarLimitService { } /** - * Gets the spending plan for the given eth address. - * @param {string} ethAddress - The eth address to get the spending plan for. + * Gets the spending plan for the given evm address. + * @param {string} evmAddress - The evm address to get the spending plan for. * @param {RequestDetails} requestDetails - The request details for logging and tracking. * @returns {Promise} - A promise that resolves with the spending plan. * @private */ - private async getSpendingPlanByEthAddress( - ethAddress: string, + private async getSpendingPlanByEvmAddress( + evmAddress: string, requestDetails: RequestDetails, ): Promise { - const ethAddressHbarSpendingPlan = await this.ethAddressHbarSpendingPlanRepository.findByAddress( - ethAddress, + const evmAddressHbarSpendingPlan = await this.evmAddressHbarSpendingPlanRepository.findByAddress( + evmAddress, requestDetails, ); - return this.hbarSpendingPlanRepository.findByIdWithDetails(ethAddressHbarSpendingPlan.planId, requestDetails); + return this.hbarSpendingPlanRepository.findByIdWithDetails(evmAddressHbarSpendingPlan.planId, requestDetails); } /** @@ -497,19 +498,19 @@ export class HbarLimitService implements IHbarLimitService { } /** - * Creates a basic spending plan for the given eth address. - * @param {string} ethAddress - The eth address to create the spending plan for. + * Creates a basic spending plan for the given evm address. + * @param {string} evmAddress - The evm address to create the spending plan for. * @param {RequestDetails} requestDetails - The request details for logging and tracking. * @returns {Promise} - A promise that resolves with the created spending plan. - * @throws {Error} - If neither eth address nor IP address is provided. + * @throws {Error} - If neither evm address nor IP address is provided. * @private */ private async createBasicSpendingPlan( - ethAddress: string, + evmAddress: string, requestDetails: RequestDetails, ): Promise { - if (!ethAddress) { - throw new Error('Cannot create a spending plan without an associated eth address'); + if (!evmAddress) { + throw new Error('Cannot create a spending plan without an associated evm address'); } const spendingPlan = await this.hbarSpendingPlanRepository.create( @@ -520,11 +521,11 @@ export class HbarLimitService implements IHbarLimitService { if (this.logger.isLevelEnabled('trace')) { this.logger.trace( - `${requestDetails.formattedRequestId} Linking spending plan with ID ${spendingPlan.id} to eth address ${ethAddress}`, + `${requestDetails.formattedRequestId} Linking spending plan with ID ${spendingPlan.id} to evm address ${evmAddress}`, ); } - await this.ethAddressHbarSpendingPlanRepository.save( - { ethAddress, planId: spendingPlan.id }, + await this.evmAddressHbarSpendingPlanRepository.save( + { evmAddress, planId: spendingPlan.id }, requestDetails, this.limitDuration, ); diff --git a/packages/relay/src/lib/types/spendingPlanConfig.ts b/packages/relay/src/lib/types/spendingPlanConfig.ts index 53aaebd928..c3fd2fbd84 100644 --- a/packages/relay/src/lib/types/spendingPlanConfig.ts +++ b/packages/relay/src/lib/types/spendingPlanConfig.ts @@ -38,11 +38,11 @@ export interface SpendingPlanConfig { name: string; /** - * ETH addresses associated with the spending plan. + * EVM addresses associated with the spending plan. * @type {string[]} * @optional */ - ethAddresses?: string[]; + evmAddresses?: string[]; /** * IP addresses associated with the spending plan. @@ -70,7 +70,7 @@ export function isValidSpendingPlanConfig(plan: any): plan is SpendingPlanConfig typeof plan.name === 'string' && typeof plan.subscriptionTier === 'string' && Object.values(SubscriptionTier).includes(plan.subscriptionTier) && - ((Array.isArray(plan.ethAddresses) && plan.ethAddresses.length > 0) || + ((Array.isArray(plan.evmAddresses) && plan.evmAddresses.length > 0) || (Array.isArray(plan.ipAddresses) && plan.ipAddresses.length > 0)) ); } diff --git a/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts b/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts index 2bd86be171..e33f77c8ec 100644 --- a/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts +++ b/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts @@ -18,17 +18,28 @@ * */ -import sinon from 'sinon'; +import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; +import chai, { expect } from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +import findConfig from 'find-config'; import fs from 'fs'; import pino, { Logger } from 'pino'; +import { Registry } from 'prom-client'; +import sinon from 'sinon'; + +import { HbarSpendingPlanConfigService } from '../../../src/lib/config/hbarSpendingPlanConfigService'; +import { EvmAddressHbarSpendingPlanRepository } from '../../../src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository'; import { HbarSpendingPlanRepository } from '../../../src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository'; -import { EthAddressHbarSpendingPlanRepository } from '../../../src/lib/db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository'; import { IPAddressHbarSpendingPlanRepository } from '../../../src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository'; +import { + EvmAddressHbarSpendingPlanNotFoundError, + HbarSpendingPlanNotFoundError, + IPAddressHbarSpendingPlanNotFoundError, +} from '../../../src/lib/db/types/hbarLimiter/errors'; import { SubscriptionTier } from '../../../src/lib/db/types/hbarLimiter/subscriptionTier'; -import chai, { expect } from 'chai'; -import chaiAsPromised from 'chai-as-promised'; -import { SpendingPlanConfig } from '../../../src/lib/types/spendingPlanConfig'; +import { CacheService } from '../../../src/lib/services/cacheService/cacheService'; import { RequestDetails } from '../../../src/lib/types'; +import { SpendingPlanConfig } from '../../../src/lib/types/spendingPlanConfig'; import { overrideEnvsInMochaDescribe, toHex, @@ -36,16 +47,6 @@ import { verifyResult, withOverriddenEnvsInMochaTest, } from '../../helpers'; -import findConfig from 'find-config'; -import { HbarSpendingPlanConfigService } from '../../../src/lib/config/hbarSpendingPlanConfigService'; -import { CacheService } from '../../../src/lib/services/cacheService/cacheService'; -import { Registry } from 'prom-client'; -import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; -import { - EthAddressHbarSpendingPlanNotFoundError, - HbarSpendingPlanNotFoundError, - IPAddressHbarSpendingPlanNotFoundError, -} from '../../../src/lib/db/types/hbarLimiter/errors'; chai.use(chaiAsPromised); @@ -71,14 +72,14 @@ describe('HbarSpendingPlanConfigService', function () { const tests = (hbarSpendingPlansConfigEnv: string) => { let cacheService: CacheService; let hbarSpendingPlanRepository: HbarSpendingPlanRepository; - let ethAddressHbarSpendingPlanRepository: EthAddressHbarSpendingPlanRepository; + let evmAddressHbarSpendingPlanRepository: EvmAddressHbarSpendingPlanRepository; let ipAddressHbarSpendingPlanRepository: IPAddressHbarSpendingPlanRepository; let hbarSpendingPlanConfigService: HbarSpendingPlanConfigService; let loggerSpy: sinon.SinonSpiedInstance; let cacheServiceSpy: sinon.SinonSpiedInstance; let hbarSpendingPlanRepositorySpy: sinon.SinonSpiedInstance; - let ethAddressHbarSpendingPlanRepositorySpy: sinon.SinonSpiedInstance; + let evmAddressHbarSpendingPlanRepositorySpy: sinon.SinonSpiedInstance; let ipAddressHbarSpendingPlanRepositorySpy: sinon.SinonSpiedInstance; overrideEnvsInMochaDescribe({ @@ -94,7 +95,7 @@ describe('HbarSpendingPlanConfigService', function () { cacheService, logger.child({ name: 'hbar-spending-plan-repository' }), ); - ethAddressHbarSpendingPlanRepository = new EthAddressHbarSpendingPlanRepository( + evmAddressHbarSpendingPlanRepository = new EvmAddressHbarSpendingPlanRepository( cacheService, logger.child({ name: 'evm-address-spending-plan-repository' }), ); @@ -105,7 +106,7 @@ describe('HbarSpendingPlanConfigService', function () { hbarSpendingPlanConfigService = new HbarSpendingPlanConfigService( logger, hbarSpendingPlanRepository, - ethAddressHbarSpendingPlanRepository, + evmAddressHbarSpendingPlanRepository, ipAddressHbarSpendingPlanRepository, ); }); @@ -120,7 +121,7 @@ describe('HbarSpendingPlanConfigService', function () { loggerSpy = sinon.spy(logger); cacheServiceSpy = sinon.spy(cacheService); hbarSpendingPlanRepositorySpy = sinon.spy(hbarSpendingPlanRepository); - ethAddressHbarSpendingPlanRepositorySpy = sinon.spy(ethAddressHbarSpendingPlanRepository); + evmAddressHbarSpendingPlanRepositorySpy = sinon.spy(evmAddressHbarSpendingPlanRepository); ipAddressHbarSpendingPlanRepositorySpy = sinon.spy(ipAddressHbarSpendingPlanRepository); }); @@ -154,7 +155,7 @@ describe('HbarSpendingPlanConfigService', function () { const invalidPlan = { name: 'Plan without ID', subscriptionTier: SubscriptionTier.EXTENDED, - ethAddresses: ['0x123'], + evmAddresses: ['0x123'], }; sinon .stub(HbarSpendingPlanConfigService, 'loadSpendingPlansConfig' as any) @@ -169,7 +170,7 @@ describe('HbarSpendingPlanConfigService', function () { const invalidPlan = { id: 'plan-without-name', subscriptionTier: SubscriptionTier.EXTENDED, - ethAddresses: ['0x123'], + evmAddresses: ['0x123'], }; sinon .stub(HbarSpendingPlanConfigService, 'loadSpendingPlansConfig' as any) @@ -184,7 +185,7 @@ describe('HbarSpendingPlanConfigService', function () { const invalidPlan = { id: 'plan-without-tier', name: 'Plan without tier', - ethAddresses: ['0x123'], + evmAddresses: ['0x123'], }; sinon .stub(HbarSpendingPlanConfigService, 'loadSpendingPlansConfig' as any) @@ -200,7 +201,7 @@ describe('HbarSpendingPlanConfigService', function () { id: 'plan-invalid-tier', name: 'Plan with invalid tier', subscriptionTier: 'INVALID_TIER', - ethAddresses: ['0x123'], + evmAddresses: ['0x123'], }; sinon .stub(HbarSpendingPlanConfigService, 'loadSpendingPlansConfig' as any) @@ -211,7 +212,7 @@ describe('HbarSpendingPlanConfigService', function () { ).to.be.eventually.rejectedWith(`Invalid spending plan configuration: ${JSON.stringify(invalidPlan)}`); }); - it('should throw an error if the configuration file has entry without ethAddresses and ipAddresses', async function () { + it('should throw an error if the configuration file has entry without evmAddresses and ipAddresses', async function () { const invalidPlan = { id: 'plan-without-addresses', name: 'Plan without addresses', @@ -226,12 +227,12 @@ describe('HbarSpendingPlanConfigService', function () { ).to.be.eventually.rejectedWith(`Invalid spending plan configuration: ${JSON.stringify(invalidPlan)}`); }); - it('should throw an error if the configuration file has entry with empty ethAddresses and ipAddresses', async function () { + it('should throw an error if the configuration file has entry with empty evmAddresses and ipAddresses', async function () { const invalidPlan = { id: 'plan-with-empty-addresses', name: 'Plan with empty addresses', subscriptionTier: SubscriptionTier.EXTENDED, - ethAddresses: [], + evmAddresses: [], ipAddresses: [], }; sinon @@ -254,9 +255,9 @@ describe('HbarSpendingPlanConfigService', function () { neverExpireTtl, plan.id, ); - for (const ethAddress of plan.ethAddresses || []) { - await ethAddressHbarSpendingPlanRepository.save( - { ethAddress, planId: plan.id }, + for (const evmAddress of plan.evmAddresses || []) { + await evmAddressHbarSpendingPlanRepository.save( + { evmAddress, planId: plan.id }, emptyRequestDetails, neverExpireTtl, ); @@ -270,7 +271,7 @@ describe('HbarSpendingPlanConfigService', function () { } } hbarSpendingPlanRepositorySpy.create.resetHistory(); - ethAddressHbarSpendingPlanRepositorySpy.save.resetHistory(); + evmAddressHbarSpendingPlanRepositorySpy.save.resetHistory(); ipAddressHbarSpendingPlanRepositorySpy.save.resetHistory(); }; @@ -278,7 +279,7 @@ describe('HbarSpendingPlanConfigService', function () { const findObsoleteAssociations = ( oldConfig: SpendingPlanConfig[], newConfig: SpendingPlanConfig[], - fieldName: 'ethAddresses' | 'ipAddresses', + fieldName: 'evmAddresses' | 'ipAddresses', ) => { const obsoleteAssociations: { address: string; oldPlanId: string; newPlanId?: string }[] = []; @@ -315,10 +316,10 @@ describe('HbarSpendingPlanConfigService', function () { active: true, }); - for (const ethAddress of plan.ethAddresses || []) { + for (const evmAddress of plan.evmAddresses || []) { await verifyResult( - () => ethAddressHbarSpendingPlanRepository.findByAddress(ethAddress, emptyRequestDetails), - { ethAddress, planId: plan.id }, + () => evmAddressHbarSpendingPlanRepository.findByAddress(evmAddress, emptyRequestDetails), + { evmAddress, planId: plan.id }, ); } @@ -333,7 +334,7 @@ describe('HbarSpendingPlanConfigService', function () { // If the config has been changed, check for deleted plans and associations which are no longer valid if (newConfig) { const obsoletePlans = oldConfig.filter((oldPlan) => !newConfig.some((plan) => plan.id === oldPlan.id)); - const obsoleteEthAssociations = findObsoleteAssociations(oldConfig, newConfig, 'ethAddresses'); + const obsoleteEthAssociations = findObsoleteAssociations(oldConfig, newConfig, 'evmAddresses'); const obsoleteIpAssociations = findObsoleteAssociations(oldConfig, newConfig, 'ipAddresses'); // Validate non-existence of obsolete plans @@ -346,13 +347,13 @@ describe('HbarSpendingPlanConfigService', function () { ); } - // Validate non-existence of obsolete ETH address associations + // Validate non-existence of obsolete EVM address associations for (const { address, newPlanId } of obsoleteEthAssociations) { await verifyResult( - () => ethAddressHbarSpendingPlanRepository.findByAddress(address, emptyRequestDetails), - newPlanId ? { ethAddress: address, planId: newPlanId } : null, - `EthAddressHbarSpendingPlan with address ${address} not found`, - EthAddressHbarSpendingPlanNotFoundError, + () => evmAddressHbarSpendingPlanRepository.findByAddress(address, emptyRequestDetails), + newPlanId ? { evmAddress: address, planId: newPlanId } : null, + `EvmAddressHbarSpendingPlan with address ${address} not found`, + EvmAddressHbarSpendingPlanNotFoundError, ); } @@ -406,18 +407,18 @@ describe('HbarSpendingPlanConfigService', function () { await hbarSpendingPlanConfigService.populatePreconfiguredSpendingPlans(); - spendingPlansConfig.forEach(({ id, ethAddresses, ipAddresses }) => { - if (ethAddresses) { - ethAddresses.forEach((ethAddress) => { + spendingPlansConfig.forEach(({ id, evmAddresses, ipAddresses }) => { + if (evmAddresses) { + evmAddresses.forEach((evmAddress) => { sinon.assert.calledWith( - ethAddressHbarSpendingPlanRepositorySpy.save, - { ethAddress, planId: id }, + evmAddressHbarSpendingPlanRepositorySpy.save, + { evmAddress, planId: id }, emptyRequestDetails, neverExpireTtl, ); sinon.assert.calledWith( - ethAddressHbarSpendingPlanRepositorySpy.delete, - ethAddress, + evmAddressHbarSpendingPlanRepositorySpy.delete, + evmAddress, emptyRequestDetails, ); }); @@ -445,21 +446,21 @@ describe('HbarSpendingPlanConfigService', function () { id: 'plan-basic', name: 'Basic Plan', subscriptionTier: SubscriptionTier.BASIC, - ethAddresses: ['0x122'], + evmAddresses: ['0x122'], ipAddresses: ['126.0.0.1'], }, { id: 'plan-extended', name: 'Extended Plan', subscriptionTier: SubscriptionTier.EXTENDED, - ethAddresses: ['0x123'], + evmAddresses: ['0x123'], ipAddresses: ['127.0.0.1'], }, { id: 'plan-privileged', name: 'Privileged Plan', subscriptionTier: SubscriptionTier.PRIVILEGED, - ethAddresses: ['0x124'], + evmAddresses: ['0x124'], ipAddresses: ['128.0.0.1'], }, ]; @@ -468,7 +469,7 @@ describe('HbarSpendingPlanConfigService', function () { await hbarSpendingPlanConfigService.populatePreconfiguredSpendingPlans(); expect(hbarSpendingPlanRepositorySpy.delete.calledTwice).to.be.true; - for (const { id, subscriptionTier, ethAddresses, ipAddresses } of obsoletePlans) { + for (const { id, subscriptionTier, evmAddresses, ipAddresses } of obsoletePlans) { if (subscriptionTier === SubscriptionTier.BASIC) { sinon.assert.neverCalledWith(hbarSpendingPlanRepositorySpy.delete, id, emptyRequestDetails); continue; @@ -478,10 +479,10 @@ describe('HbarSpendingPlanConfigService', function () { loggerSpy.info, `Deleting HBAR spending plan with ID "${id}", as it is no longer in the spending plan configuration...`, ); - sinon.assert.calledWithMatch(ethAddressHbarSpendingPlanRepositorySpy.deleteAllByPlanId, id); + sinon.assert.calledWithMatch(evmAddressHbarSpendingPlanRepositorySpy.deleteAllByPlanId, id); sinon.assert.calledWithMatch(ipAddressHbarSpendingPlanRepositorySpy.deleteAllByPlanId, id); - ethAddresses?.forEach((ethAddress) => { - const key = ethAddressHbarSpendingPlanRepository['getKey'](ethAddress); + evmAddresses?.forEach((evmAddress) => { + const key = evmAddressHbarSpendingPlanRepository['getKey'](evmAddress); sinon.assert.calledWithMatch(cacheServiceSpy.delete, key); }); ipAddresses?.forEach((ipAddress) => { @@ -499,18 +500,18 @@ describe('HbarSpendingPlanConfigService', function () { await hbarSpendingPlanConfigService.populatePreconfiguredSpendingPlans(); sinon.assert.notCalled(hbarSpendingPlanRepositorySpy.create); - sinon.assert.notCalled(ethAddressHbarSpendingPlanRepositorySpy.save); + sinon.assert.notCalled(evmAddressHbarSpendingPlanRepositorySpy.save); sinon.assert.notCalled(ipAddressHbarSpendingPlanRepositorySpy.save); await verifySpendingPlans(spendingPlansConfig); }); - it('should save only new associations for ETH addresses', async function () { + it('should save only new associations for EVM addresses', async function () { const newSpendingPlansConfig = spendingPlansConfig.map((plan, index) => ({ id: plan.id, name: plan.name, subscriptionTier: plan.subscriptionTier, - ethAddresses: [toHex(index)].concat(plan.ethAddresses ? plan.ethAddresses : []), + evmAddresses: [toHex(index)].concat(plan.evmAddresses ? plan.evmAddresses : []), ipAddresses: plan.ipAddresses, })); sinon.stub(HbarSpendingPlanConfigService, 'loadSpendingPlansConfig' as any).returns(newSpendingPlansConfig); @@ -520,22 +521,22 @@ describe('HbarSpendingPlanConfigService', function () { spendingPlansConfig.forEach((config, index) => { sinon.assert.calledWith( - ethAddressHbarSpendingPlanRepositorySpy.save, - { ethAddress: toHex(index), planId: config.id }, + evmAddressHbarSpendingPlanRepositorySpy.save, + { evmAddress: toHex(index), planId: config.id }, emptyRequestDetails, neverExpireTtl, ); - if (config.ethAddresses) { - config.ethAddresses.forEach((ethAddress) => { + if (config.evmAddresses) { + config.evmAddresses.forEach((evmAddress) => { sinon.assert.neverCalledWith( - ethAddressHbarSpendingPlanRepositorySpy.save, - { ethAddress, planId: config.id }, + evmAddressHbarSpendingPlanRepositorySpy.save, + { evmAddress, planId: config.id }, emptyRequestDetails, neverExpireTtl, ); sinon.assert.neverCalledWith( - ethAddressHbarSpendingPlanRepositorySpy.delete, - ethAddress, + evmAddressHbarSpendingPlanRepositorySpy.delete, + evmAddress, emptyRequestDetails, ); }); @@ -550,7 +551,7 @@ describe('HbarSpendingPlanConfigService', function () { id: plan.id, name: plan.name, subscriptionTier: plan.subscriptionTier, - ethAddresses: plan.ethAddresses, + evmAddresses: plan.evmAddresses, ipAddresses: [`255.0.0.${index}`].concat(plan.ipAddresses ? plan.ipAddresses : []), })); sinon.stub(HbarSpendingPlanConfigService, 'loadSpendingPlansConfig' as any).returns(newSpendingPlansConfig); @@ -581,12 +582,12 @@ describe('HbarSpendingPlanConfigService', function () { await verifySpendingPlans(spendingPlansConfig, newSpendingPlansConfig); }); - it('should delete obsolete associations for ETH addresses', async function () { + it('should delete obsolete associations for EVM addresses', async function () { const newSpendingPlansConfig = spendingPlansConfig.map((plan) => ({ id: plan.id, name: plan.name, subscriptionTier: plan.subscriptionTier, - ethAddresses: plan.ethAddresses ? [plan.ethAddresses[0]] : [], + evmAddresses: plan.evmAddresses ? [plan.evmAddresses[0]] : [], ipAddresses: plan.ipAddresses, })); sinon.stub(HbarSpendingPlanConfigService, 'loadSpendingPlansConfig' as any).returns(newSpendingPlansConfig); @@ -594,23 +595,23 @@ describe('HbarSpendingPlanConfigService', function () { await hbarSpendingPlanConfigService.populatePreconfiguredSpendingPlans(); - spendingPlansConfig.forEach(({ id, ethAddresses }) => { - if (ethAddresses) { - ethAddresses.forEach((ethAddress, index) => { - sinon.assert.neverCalledWith(ethAddressHbarSpendingPlanRepositorySpy.save, { - ethAddress, + spendingPlansConfig.forEach(({ id, evmAddresses }) => { + if (evmAddresses) { + evmAddresses.forEach((evmAddress, index) => { + sinon.assert.neverCalledWith(evmAddressHbarSpendingPlanRepositorySpy.save, { + evmAddress, planId: id, }); if (index === 0) { sinon.assert.neverCalledWith( - ethAddressHbarSpendingPlanRepositorySpy.delete, - ethAddress, + evmAddressHbarSpendingPlanRepositorySpy.delete, + evmAddress, emptyRequestDetails, ); } else { sinon.assert.calledWith( - ethAddressHbarSpendingPlanRepositorySpy.delete, - ethAddress, + evmAddressHbarSpendingPlanRepositorySpy.delete, + evmAddress, emptyRequestDetails, ); } @@ -626,7 +627,7 @@ describe('HbarSpendingPlanConfigService', function () { id: plan.id, name: plan.name, subscriptionTier: plan.subscriptionTier, - ethAddresses: plan.ethAddresses, + evmAddresses: plan.evmAddresses, ipAddresses: plan.ipAddresses ? [plan.ipAddresses[0]] : [], })); sinon.stub(HbarSpendingPlanConfigService, 'loadSpendingPlansConfig' as any).returns(newSpendingPlansConfig); diff --git a/packages/relay/tests/lib/eth/eth-helpers.ts b/packages/relay/tests/lib/eth/eth-helpers.ts index 9111756dd8..be34e407a8 100644 --- a/packages/relay/tests/lib/eth/eth-helpers.ts +++ b/packages/relay/tests/lib/eth/eth-helpers.ts @@ -19,21 +19,22 @@ */ import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; -import { ConfigServiceTestHelper } from '../../../../config-service/tests/configServiceTestHelper'; -import pino from 'pino'; +import { Hbar } from '@hashgraph/sdk'; import MockAdapter from 'axios-mock-adapter'; +import EventEmitter from 'events'; +import pino from 'pino'; import { register, Registry } from 'prom-client'; -import constants from '../../../src/lib/constants'; -import HAPIService from '../../../src/lib/services/hapiService/hapiService'; + +import { ConfigServiceTestHelper } from '../../../../config-service/tests/configServiceTestHelper'; import { MirrorNodeClient } from '../../../src/lib/clients/mirrorNodeClient'; -import { EthImpl } from '../../../src/lib/eth'; -import EventEmitter from 'events'; -import { EthAddressHbarSpendingPlanRepository } from '../../../src/lib/db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository'; +import constants from '../../../src/lib/constants'; +import { EvmAddressHbarSpendingPlanRepository } from '../../../src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository'; import { HbarSpendingPlanRepository } from '../../../src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository'; import { IPAddressHbarSpendingPlanRepository } from '../../../src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository'; -import { HbarLimitService } from '../../../src/lib/services/hbarLimitService'; -import { Hbar } from '@hashgraph/sdk'; +import { EthImpl } from '../../../src/lib/eth'; import { CacheService } from '../../../src/lib/services/cacheService/cacheService'; +import HAPIService from '../../../src/lib/services/hapiService/hapiService'; +import { HbarLimitService } from '../../../src/lib/services/hbarLimitService'; export function contractResultsByNumberByIndexURL(number: number, index: number): string { return `contracts/results?block.number=${number}&transaction.index=${index}&limit=100&order=asc`; @@ -71,11 +72,11 @@ export function generateEthTestEnv(fixedFeeHistory = false) { const eventEmitter = new EventEmitter(); const hbarSpendingPlanRepository = new HbarSpendingPlanRepository(cacheService, logger); - const ethAddressHbarSpendingPlanRepository = new EthAddressHbarSpendingPlanRepository(cacheService, logger); + const evmAddressHbarSpendingPlanRepository = new EvmAddressHbarSpendingPlanRepository(cacheService, logger); const ipAddressHbarSpendingPlanRepository = new IPAddressHbarSpendingPlanRepository(cacheService, logger); const hbarLimitService = new HbarLimitService( hbarSpendingPlanRepository, - ethAddressHbarSpendingPlanRepository, + evmAddressHbarSpendingPlanRepository, ipAddressHbarSpendingPlanRepository, logger, register, diff --git a/packages/relay/tests/lib/eth/eth_getBalance.spec.ts b/packages/relay/tests/lib/eth/eth_getBalance.spec.ts index 0e9a499a6e..45fcbc27c2 100644 --- a/packages/relay/tests/lib/eth/eth_getBalance.spec.ts +++ b/packages/relay/tests/lib/eth/eth_getBalance.spec.ts @@ -19,12 +19,14 @@ */ import { expect, use } from 'chai'; -import sinon from 'sinon'; import chaiAsPromised from 'chai-as-promised'; +import sinon from 'sinon'; + +import { numberTo0x } from '../../../dist/formatters'; +import { SDKClient } from '../../../src/lib/clients'; import { EthImpl } from '../../../src/lib/eth'; +import { RequestDetails } from '../../../src/lib/types'; import { buildCryptoTransferTransaction, overrideEnvsInMochaDescribe } from '../../helpers'; -import { SDKClient } from '../../../src/lib/clients'; -import { numberTo0x } from '../../../dist/formatters'; import { BLOCK_TIMESTAMP, BLOCK_ZERO, @@ -42,7 +44,6 @@ import { TINYBAR_TO_WEIBAR_COEF_BIGINT, } from './eth-config'; import { balancesByAccountIdByTimestampURL, generateEthTestEnv } from './eth-helpers'; -import { RequestDetails } from '../../../src/lib/types'; use(chaiAsPromised); @@ -51,7 +52,7 @@ let getSdkClientStub: sinon.SinonStub; describe('@ethGetBalance using MirrorNode', async function () { this.timeout(10000); - let { restMock, hapiServiceInstance, ethImpl, cacheService } = generateEthTestEnv(); + const { restMock, hapiServiceInstance, ethImpl, cacheService } = generateEthTestEnv(); const requestDetails = new RequestDetails({ requestId: 'eth_getBalanceTest', ipAddress: '0.0.0.0' }); @@ -673,7 +674,7 @@ describe('@ethGetBalance using MirrorNode', async function () { }); it('blockNumber is not in the latest 15 minutes, mirror node balance for address not found 404 status', async () => { - // random eth address + // random evm address const notFoundEvmAddress = '0x1234567890123456789012345678901234567890'; restMock .onGet(balancesByAccountIdByTimestampURL(notFoundEvmAddress, '1651550386.060890949')) @@ -684,7 +685,7 @@ describe('@ethGetBalance using MirrorNode', async function () { }); it('blockNumber is in the latest 15 minutes, mirror node balance for address not found 404 status', async () => { - // random eth address + // random evm address const notFoundEvmAddress = '0x1234567890123456789012345678901234567890'; const blockTimestamp = '1651560900'; const recentBlockWithinLastfifteen = { diff --git a/packages/relay/tests/lib/ethGetBlockBy.spec.ts b/packages/relay/tests/lib/ethGetBlockBy.spec.ts index d633d36732..56c7b7afc0 100644 --- a/packages/relay/tests/lib/ethGetBlockBy.spec.ts +++ b/packages/relay/tests/lib/ethGetBlockBy.spec.ts @@ -19,26 +19,27 @@ */ import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; +import { Hbar } from '@hashgraph/sdk'; import MockAdapter from 'axios-mock-adapter'; import { expect, use } from 'chai'; import chaiAsPromised from 'chai-as-promised'; +import { EventEmitter } from 'events'; +import pino from 'pino'; import { register, Registry } from 'prom-client'; -import { EthImpl } from '../../src/lib/eth'; + +import { nanOrNumberTo0x, nullableNumberTo0x, numberTo0x, toHash32 } from '../../../../packages/relay/src/formatters'; import { MirrorNodeClient } from '../../src/lib/clients/mirrorNodeClient'; -import pino from 'pino'; -import { EventEmitter } from 'events'; -import { Hbar } from '@hashgraph/sdk'; import constants from '../../src/lib/constants'; +import { EvmAddressHbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository'; +import { HbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository'; +import { IPAddressHbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository'; +import { EthImpl } from '../../src/lib/eth'; import { Log, Transaction } from '../../src/lib/model'; +import { CacheService } from '../../src/lib/services/cacheService/cacheService'; import HAPIService from '../../src/lib/services/hapiService/hapiService'; import { HbarLimitService } from '../../src/lib/services/hbarLimitService'; -import { CacheService } from '../../src/lib/services/cacheService/cacheService'; -import { defaultDetailedContractResults, overrideEnvsInMochaDescribe, useInMemoryRedisServer } from '../helpers'; import { RequestDetails } from '../../src/lib/types'; -import { HbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository'; -import { nanOrNumberTo0x, nullableNumberTo0x, numberTo0x, toHash32 } from '../../../../packages/relay/src/formatters'; -import { IPAddressHbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository'; -import { EthAddressHbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository'; +import { defaultDetailedContractResults, overrideEnvsInMochaDescribe, useInMemoryRedisServer } from '../helpers'; use(chaiAsPromised); @@ -142,11 +143,11 @@ describe('eth_getBlockBy', async function () { const eventEmitter = new EventEmitter(); const hbarSpendingPlanRepository = new HbarSpendingPlanRepository(cacheService, logger); - const ethAddressHbarSpendingPlanRepository = new EthAddressHbarSpendingPlanRepository(cacheService, logger); + const evmAddressHbarSpendingPlanRepository = new EvmAddressHbarSpendingPlanRepository(cacheService, logger); const ipAddressHbarSpendingPlanRepository = new IPAddressHbarSpendingPlanRepository(cacheService, logger); const hbarLimitService = new HbarLimitService( hbarSpendingPlanRepository, - ethAddressHbarSpendingPlanRepository, + evmAddressHbarSpendingPlanRepository, ipAddressHbarSpendingPlanRepository, logger, register, diff --git a/packages/relay/tests/lib/hapiService.spec.ts b/packages/relay/tests/lib/hapiService.spec.ts index 3198bfcd62..5b3d66f9a3 100644 --- a/packages/relay/tests/lib/hapiService.spec.ts +++ b/packages/relay/tests/lib/hapiService.spec.ts @@ -19,21 +19,22 @@ */ import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; -import pino from 'pino'; +import { Client, Hbar } from '@hashgraph/sdk'; import { expect } from 'chai'; import EventEmitter from 'events'; -import { Client, Hbar } from '@hashgraph/sdk'; -import constants from '../../src/lib/constants'; +import pino from 'pino'; import { register, Registry } from 'prom-client'; + import { SDKClient } from '../../src/lib/clients'; -import { RequestDetails } from '../../src/lib/types'; +import constants from '../../src/lib/constants'; +import { EvmAddressHbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository'; +import { HbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository'; +import { IPAddressHbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository'; +import { CacheService } from '../../src/lib/services/cacheService/cacheService'; import HAPIService from '../../src/lib/services/hapiService/hapiService'; import { HbarLimitService } from '../../src/lib/services/hbarLimitService'; -import { CacheService } from '../../src/lib/services/cacheService/cacheService'; +import { RequestDetails } from '../../src/lib/types'; import { overrideEnvsInMochaDescribe, withOverriddenEnvsInMochaTest } from '../helpers'; -import { HbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository'; -import { IPAddressHbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository'; -import { EthAddressHbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository'; const registry = new Registry(); const logger = pino(); @@ -55,11 +56,11 @@ describe('HAPI Service', async function () { cacheService = new CacheService(logger.child({ name: `cache` }), registry); const hbarSpendingPlanRepository = new HbarSpendingPlanRepository(cacheService, logger); - const ethAddressHbarSpendingPlanRepository = new EthAddressHbarSpendingPlanRepository(cacheService, logger); + const evmAddressHbarSpendingPlanRepository = new EvmAddressHbarSpendingPlanRepository(cacheService, logger); const ipAddressHbarSpendingPlanRepository = new IPAddressHbarSpendingPlanRepository(cacheService, logger); hbarLimitService = new HbarLimitService( hbarSpendingPlanRepository, - ethAddressHbarSpendingPlanRepository, + evmAddressHbarSpendingPlanRepository, ipAddressHbarSpendingPlanRepository, logger, register, diff --git a/packages/relay/tests/lib/openrpc.spec.ts b/packages/relay/tests/lib/openrpc.spec.ts index a50d8a24fa..fd832c48d3 100644 --- a/packages/relay/tests/lib/openrpc.spec.ts +++ b/packages/relay/tests/lib/openrpc.spec.ts @@ -19,33 +19,33 @@ */ import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; +import { AccountInfo, Hbar } from '@hashgraph/sdk'; +import { parseOpenRPCDocument, validateOpenRPCDocument } from '@open-rpc/schema-utils-js'; import Ajv from 'ajv'; -import pino from 'pino'; -import Long from 'long'; import axios from 'axios'; -import sinon from 'sinon'; -import { expect } from 'chai'; -import EventEmitter from 'events'; -import { AccountInfo, Hbar } from '@hashgraph/sdk'; import MockAdapter from 'axios-mock-adapter'; import { BigNumber } from 'bignumber.js'; -import { EthImpl } from '../../src/lib/eth'; -import constants from '../../src/lib/constants'; -import { RelayImpl } from '../../src/lib/relay'; +import { expect } from 'chai'; +import EventEmitter from 'events'; +import Long from 'long'; +import pino from 'pino'; import { register, Registry } from 'prom-client'; -import { NOT_FOUND_RES } from './eth/eth-config'; +import sinon from 'sinon'; + +import openRpcSchema from '../../../../docs/openrpc.json'; import { numberTo0x } from '../../src/formatters'; import { SDKClient } from '../../src/lib/clients'; -import { RequestDetails } from '../../src/lib/types'; -import openRpcSchema from '../../../../docs/openrpc.json'; import { MirrorNodeClient } from '../../src/lib/clients/mirrorNodeClient'; -import { HbarLimitService } from '../../src/lib/services/hbarLimitService'; -import ClientService from '../../src/lib/services/hapiService/hapiService'; -import { CacheService } from '../../src/lib/services/cacheService/cacheService'; -import { parseOpenRPCDocument, validateOpenRPCDocument } from '@open-rpc/schema-utils-js'; +import constants from '../../src/lib/constants'; +import { EvmAddressHbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository'; import { HbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository'; import { IPAddressHbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository'; -import { EthAddressHbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository'; +import { EthImpl } from '../../src/lib/eth'; +import { RelayImpl } from '../../src/lib/relay'; +import { CacheService } from '../../src/lib/services/cacheService/cacheService'; +import ClientService from '../../src/lib/services/hapiService/hapiService'; +import { HbarLimitService } from '../../src/lib/services/hbarLimitService'; +import { RequestDetails } from '../../src/lib/types'; import { blockHash, blockNumber, @@ -75,6 +75,7 @@ import { overrideEnvsInMochaDescribe, signedTransactionHash, } from '../helpers'; +import { NOT_FOUND_RES } from './eth/eth-config'; const logger = pino(); const registry = new Registry(); @@ -132,11 +133,11 @@ describe('Open RPC Specification', function () { const eventEmitter = new EventEmitter(); const hbarSpendingPlanRepository = new HbarSpendingPlanRepository(cacheService, logger); - const ethAddressHbarSpendingPlanRepository = new EthAddressHbarSpendingPlanRepository(cacheService, logger); + const evmAddressHbarSpendingPlanRepository = new EvmAddressHbarSpendingPlanRepository(cacheService, logger); const ipAddressHbarSpendingPlanRepository = new IPAddressHbarSpendingPlanRepository(cacheService, logger); const hbarLimitService = new HbarLimitService( hbarSpendingPlanRepository, - ethAddressHbarSpendingPlanRepository, + evmAddressHbarSpendingPlanRepository, ipAddressHbarSpendingPlanRepository, logger, register, diff --git a/packages/relay/tests/lib/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository.spec.ts b/packages/relay/tests/lib/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository.spec.ts similarity index 63% rename from packages/relay/tests/lib/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository.spec.ts rename to packages/relay/tests/lib/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository.spec.ts index 0a9a37d37b..74867b9b67 100644 --- a/packages/relay/tests/lib/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository.spec.ts +++ b/packages/relay/tests/lib/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository.spec.ts @@ -20,25 +20,26 @@ import chai, { expect } from 'chai'; import chaiAsPromised from 'chai-as-promised'; -import sinon from 'sinon'; -import { EthAddressHbarSpendingPlanRepository } from '../../../../src/lib/db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository'; -import { CacheService } from '../../../../src/lib/services/cacheService/cacheService'; -import pino from 'pino'; -import { IEthAddressHbarSpendingPlan } from '../../../../src/lib/db/types/hbarLimiter/ethAddressHbarSpendingPlan'; -import { EthAddressHbarSpendingPlanNotFoundError } from '../../../../src/lib/db/types/hbarLimiter/errors'; import { randomBytes, uuidV4 } from 'ethers'; +import pino from 'pino'; import { Registry } from 'prom-client'; -import { overrideEnvsInMochaDescribe, useInMemoryRedisServer } from '../../../helpers'; +import sinon from 'sinon'; + import { RequestDetails } from '../../../../dist/lib/types'; -import { EthAddressHbarSpendingPlan } from '../../../../src/lib/db/entities/hbarLimiter/ethAddressHbarSpendingPlan'; +import { EvmAddressHbarSpendingPlan } from '../../../../src/lib/db/entities/hbarLimiter/evmAddressHbarSpendingPlan'; +import { EvmAddressHbarSpendingPlanRepository } from '../../../../src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository'; +import { EvmAddressHbarSpendingPlanNotFoundError } from '../../../../src/lib/db/types/hbarLimiter/errors'; +import { IEvmAddressHbarSpendingPlan } from '../../../../src/lib/db/types/hbarLimiter/evmAddressHbarSpendingPlan'; +import { CacheService } from '../../../../src/lib/services/cacheService/cacheService'; +import { overrideEnvsInMochaDescribe, useInMemoryRedisServer } from '../../../helpers'; chai.use(chaiAsPromised); -describe('EthAddressHbarSpendingPlanRepository', function () { +describe('EvmAddressHbarSpendingPlanRepository', function () { const logger = pino(); const registry = new Registry(); const requestDetails = new RequestDetails({ - requestId: 'ethAddressHbarSpendingPlanRepositoryTest', + requestId: 'evmAddressHbarSpendingPlanRepositoryTest', ipAddress: '0.0.0.0', }); const ttl = 86_400_000; // 1 day @@ -46,14 +47,14 @@ describe('EthAddressHbarSpendingPlanRepository', function () { const tests = (isSharedCacheEnabled: boolean) => { let cacheService: CacheService; let cacheServiceSpy: sinon.SinonSpiedInstance; - let repository: EthAddressHbarSpendingPlanRepository; + let repository: EvmAddressHbarSpendingPlanRepository; before(async () => { cacheService = new CacheService(logger.child({ name: 'CacheService' }), registry); cacheServiceSpy = sinon.spy(cacheService); - repository = new EthAddressHbarSpendingPlanRepository( + repository = new EvmAddressHbarSpendingPlanRepository( cacheService, - logger.child({ name: 'EthAddressHbarSpendingPlanRepository' }), + logger.child({ name: 'EvmAddressHbarSpendingPlanRepository' }), ); }); @@ -73,34 +74,34 @@ describe('EthAddressHbarSpendingPlanRepository', function () { describe('existsByAddress', () => { it('returns true if address plan exists', async () => { - const ethAddress = '0x123'; - const addressPlan = new EthAddressHbarSpendingPlan({ ethAddress, planId: uuidV4(randomBytes(16)) }); + const evmAddress = '0x123'; + const addressPlan = new EvmAddressHbarSpendingPlan({ evmAddress, planId: uuidV4(randomBytes(16)) }); await cacheService.set( - `${EthAddressHbarSpendingPlanRepository.collectionKey}:${ethAddress}`, + `${EvmAddressHbarSpendingPlanRepository.collectionKey}:${evmAddress}`, addressPlan, 'test', requestDetails, ); - await expect(repository.existsByAddress(ethAddress, requestDetails)).to.eventually.be.true; + await expect(repository.existsByAddress(evmAddress, requestDetails)).to.eventually.be.true; }); it('returns false if address plan does not exist', async () => { - const ethAddress = '0xnonexistent'; - await expect(repository.existsByAddress(ethAddress, requestDetails)).to.eventually.be.false; + const evmAddress = '0xnonexistent'; + await expect(repository.existsByAddress(evmAddress, requestDetails)).to.eventually.be.false; }); }); describe('findAllByPlanId', () => { it('retrieves all address plans by plan ID', async () => { const planId = uuidV4(randomBytes(16)); - const ethAddressPlans = [ - new EthAddressHbarSpendingPlan({ ethAddress: '0x123', planId }), - new EthAddressHbarSpendingPlan({ ethAddress: '0x456', planId }), + const evmAddressPlans = [ + new EvmAddressHbarSpendingPlan({ evmAddress: '0x123', planId }), + new EvmAddressHbarSpendingPlan({ evmAddress: '0x456', planId }), ]; - for (const plan of ethAddressPlans) { + for (const plan of evmAddressPlans) { await cacheService.set( - `${EthAddressHbarSpendingPlanRepository.collectionKey}:${plan.ethAddress}`, + `${EvmAddressHbarSpendingPlanRepository.collectionKey}:${plan.evmAddress}`, plan, 'test', requestDetails, @@ -108,7 +109,7 @@ describe('EthAddressHbarSpendingPlanRepository', function () { } const result = await repository.findAllByPlanId(planId, 'findAllByPlanId', requestDetails); - expect(result).to.have.deep.members(ethAddressPlans); + expect(result).to.have.deep.members(evmAddressPlans); }); it('returns an empty array if no address plans are found for the plan ID', async () => { @@ -121,11 +122,11 @@ describe('EthAddressHbarSpendingPlanRepository', function () { describe('deleteAllByPlanId', () => { it('deletes all address plans by plan ID', async () => { const planId = uuidV4(randomBytes(16)); - const ethAddresses = ['0x123', '0x456', '0x789']; - for (const ethAddress of ethAddresses) { - const addressPlan = new EthAddressHbarSpendingPlan({ ethAddress, planId }); + const evmAddresses = ['0x123', '0x456', '0x789']; + for (const evmAddress of evmAddresses) { + const addressPlan = new EvmAddressHbarSpendingPlan({ evmAddress, planId }); await cacheService.set( - `${EthAddressHbarSpendingPlanRepository.collectionKey}:${ethAddress}`, + `${EvmAddressHbarSpendingPlanRepository.collectionKey}:${evmAddress}`, addressPlan, 'test', requestDetails, @@ -134,10 +135,10 @@ describe('EthAddressHbarSpendingPlanRepository', function () { await repository.deleteAllByPlanId(planId, 'deleteAllByPlanId', requestDetails); - for (const ethAddress of ethAddresses) { + for (const evmAddress of evmAddresses) { await expect( cacheService.getAsync( - `${EthAddressHbarSpendingPlanRepository.collectionKey}:${ethAddress}`, + `${EvmAddressHbarSpendingPlanRepository.collectionKey}:${evmAddress}`, 'test', requestDetails, ), @@ -153,43 +154,43 @@ describe('EthAddressHbarSpendingPlanRepository', function () { describe('findByAddress', () => { it('retrieves an address plan by address', async () => { - const ethAddress = '0x123'; - const addressPlan: IEthAddressHbarSpendingPlan = { ethAddress, planId: uuidV4(randomBytes(16)) }; + const evmAddress = '0x123'; + const addressPlan: IEvmAddressHbarSpendingPlan = { evmAddress, planId: uuidV4(randomBytes(16)) }; await cacheService.set( - `${EthAddressHbarSpendingPlanRepository.collectionKey}:${ethAddress}`, + `${EvmAddressHbarSpendingPlanRepository.collectionKey}:${evmAddress}`, addressPlan, 'test', requestDetails, ); - const result = await repository.findByAddress(ethAddress, requestDetails); + const result = await repository.findByAddress(evmAddress, requestDetails); expect(result).to.deep.equal(addressPlan); }); it('throws an error if address plan is not found', async () => { - const ethAddress = '0xnonexistent'; - await expect(repository.findByAddress(ethAddress, requestDetails)).to.be.eventually.rejectedWith( - EthAddressHbarSpendingPlanNotFoundError, - `EthAddressHbarSpendingPlan with address ${ethAddress} not found`, + const evmAddress = '0xnonexistent'; + await expect(repository.findByAddress(evmAddress, requestDetails)).to.be.eventually.rejectedWith( + EvmAddressHbarSpendingPlanNotFoundError, + `EvmAddressHbarSpendingPlan with address ${evmAddress} not found`, ); }); }); describe('save', () => { it('saves an address plan successfully', async () => { - const ethAddress = '0x123'; - const addressPlan: IEthAddressHbarSpendingPlan = { ethAddress, planId: uuidV4(randomBytes(16)) }; + const evmAddress = '0x123'; + const addressPlan: IEvmAddressHbarSpendingPlan = { evmAddress, planId: uuidV4(randomBytes(16)) }; await repository.save(addressPlan, requestDetails, ttl); - const result = await cacheService.getAsync( - `${EthAddressHbarSpendingPlanRepository.collectionKey}:${ethAddress}`, + const result = await cacheService.getAsync( + `${EvmAddressHbarSpendingPlanRepository.collectionKey}:${evmAddress}`, 'test', requestDetails, ); expect(result).to.deep.equal(addressPlan); sinon.assert.calledWith( cacheServiceSpy.set, - `${EthAddressHbarSpendingPlanRepository.collectionKey}:${ethAddress}`, + `${EvmAddressHbarSpendingPlanRepository.collectionKey}:${evmAddress}`, addressPlan, 'save', requestDetails, @@ -198,27 +199,27 @@ describe('EthAddressHbarSpendingPlanRepository', function () { }); it('overwrites an existing address plan', async () => { - const ethAddress = '0x123'; - const addressPlan: IEthAddressHbarSpendingPlan = { ethAddress, planId: uuidV4(randomBytes(16)) }; + const evmAddress = '0x123'; + const addressPlan: IEvmAddressHbarSpendingPlan = { evmAddress, planId: uuidV4(randomBytes(16)) }; await cacheService.set( - `${EthAddressHbarSpendingPlanRepository.collectionKey}:${ethAddress}`, + `${EvmAddressHbarSpendingPlanRepository.collectionKey}:${evmAddress}`, addressPlan, 'test', requestDetails, ); const newPlanId = uuidV4(randomBytes(16)); - const newAddressPlan: IEthAddressHbarSpendingPlan = { ethAddress, planId: newPlanId }; + const newAddressPlan: IEvmAddressHbarSpendingPlan = { evmAddress, planId: newPlanId }; await repository.save(newAddressPlan, requestDetails, ttl); - const result = await cacheService.getAsync( - `${EthAddressHbarSpendingPlanRepository.collectionKey}:${ethAddress}`, + const result = await cacheService.getAsync( + `${EvmAddressHbarSpendingPlanRepository.collectionKey}:${evmAddress}`, 'test', requestDetails, ); expect(result).to.deep.equal(newAddressPlan); sinon.assert.calledWith( cacheServiceSpy.set, - `${EthAddressHbarSpendingPlanRepository.collectionKey}:${ethAddress}`, + `${EvmAddressHbarSpendingPlanRepository.collectionKey}:${evmAddress}`, newAddressPlan, 'save', requestDetails, @@ -229,18 +230,18 @@ describe('EthAddressHbarSpendingPlanRepository', function () { describe('delete', () => { it('deletes an address plan successfully', async () => { - const ethAddress = '0x123'; - const addressPlan: IEthAddressHbarSpendingPlan = { ethAddress, planId: uuidV4(randomBytes(16)) }; + const evmAddress = '0x123'; + const addressPlan: IEvmAddressHbarSpendingPlan = { evmAddress, planId: uuidV4(randomBytes(16)) }; await cacheService.set( - `${EthAddressHbarSpendingPlanRepository.collectionKey}:${ethAddress}`, + `${EvmAddressHbarSpendingPlanRepository.collectionKey}:${evmAddress}`, addressPlan, 'test', requestDetails, ); - await repository.delete(ethAddress, requestDetails); - const result = await cacheService.getAsync( - `${EthAddressHbarSpendingPlanRepository.collectionKey}:${ethAddress}`, + await repository.delete(evmAddress, requestDetails); + const result = await cacheService.getAsync( + `${EvmAddressHbarSpendingPlanRepository.collectionKey}:${evmAddress}`, 'test', requestDetails, ); @@ -248,8 +249,8 @@ describe('EthAddressHbarSpendingPlanRepository', function () { }); it('does not throw an error if address plan to delete does not exist', async () => { - const ethAddress = '0xnonexistent'; - await expect(repository.delete(ethAddress, requestDetails)).to.be.fulfilled; + const evmAddress = '0xnonexistent'; + await expect(repository.delete(evmAddress, requestDetails)).to.be.fulfilled; }); }); }; diff --git a/packages/relay/tests/lib/sdkClient.spec.ts b/packages/relay/tests/lib/sdkClient.spec.ts index 0361bc7fd1..46f533aea7 100644 --- a/packages/relay/tests/lib/sdkClient.spec.ts +++ b/packages/relay/tests/lib/sdkClient.spec.ts @@ -51,7 +51,7 @@ import * as sinon from 'sinon'; import { formatTransactionId } from '../../src/formatters'; import { MirrorNodeClient, SDKClient } from '../../src/lib/clients'; import constants from '../../src/lib/constants'; -import { EthAddressHbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository'; +import { EvmAddressHbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository'; import { HbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository'; import { IPAddressHbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository'; import { CacheService } from '../../src/lib/services/cacheService/cacheService'; @@ -120,11 +120,11 @@ describe('SdkClient', async function () { cacheService = new CacheService(logger, registry); const hbarSpendingPlanRepository = new HbarSpendingPlanRepository(cacheService, logger); - const ethAddressHbarSpendingPlanRepository = new EthAddressHbarSpendingPlanRepository(cacheService, logger); + const evmAddressHbarSpendingPlanRepository = new EvmAddressHbarSpendingPlanRepository(cacheService, logger); const ipAddressHbarSpendingPlanRepository = new IPAddressHbarSpendingPlanRepository(cacheService, logger); hbarLimitService = new HbarLimitService( hbarSpendingPlanRepository, - ethAddressHbarSpendingPlanRepository, + evmAddressHbarSpendingPlanRepository, ipAddressHbarSpendingPlanRepository, logger, register, diff --git a/packages/relay/tests/lib/services/hbarLimitService/hbarLimitService.spec.ts b/packages/relay/tests/lib/services/hbarLimitService/hbarLimitService.spec.ts index a1da7c748c..a1e02b1022 100644 --- a/packages/relay/tests/lib/services/hbarLimitService/hbarLimitService.spec.ts +++ b/packages/relay/tests/lib/services/hbarLimitService/hbarLimitService.spec.ts @@ -18,28 +18,29 @@ * */ -import sinon from 'sinon'; -import pino, { Logger } from 'pino'; +import { Hbar } from '@hashgraph/sdk'; import chai, { expect } from 'chai'; -import { randomBytes, uuidV4 } from 'ethers'; import chaiAsPromised from 'chai-as-promised'; -import constants from '../../../../src/lib/constants'; +import { randomBytes, uuidV4 } from 'ethers'; +import { Long } from 'long'; +import pino, { Logger } from 'pino'; import { Counter, Gauge, Registry } from 'prom-client'; -import { HbarLimitService } from '../../../../src/lib/services/hbarLimitService'; -import { SubscriptionTier } from '../../../../src/lib/db/types/hbarLimiter/subscriptionTier'; +import sinon from 'sinon'; + +import constants from '../../../../src/lib/constants'; import { HbarSpendingPlan } from '../../../../src/lib/db/entities/hbarLimiter/hbarSpendingPlan'; +import { EvmAddressHbarSpendingPlanRepository } from '../../../../src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository'; import { HbarSpendingPlanRepository } from '../../../../src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository'; -import { EthAddressHbarSpendingPlanRepository } from '../../../../src/lib/db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository'; import { IPAddressHbarSpendingPlanRepository } from '../../../../src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository'; import { - EthAddressHbarSpendingPlanNotFoundError, + EvmAddressHbarSpendingPlanNotFoundError, HbarSpendingPlanNotActiveError, HbarSpendingPlanNotFoundError, IPAddressHbarSpendingPlanNotFoundError, } from '../../../../src/lib/db/types/hbarLimiter/errors'; +import { SubscriptionTier } from '../../../../src/lib/db/types/hbarLimiter/subscriptionTier'; +import { HbarLimitService } from '../../../../src/lib/services/hbarLimitService'; import { RequestDetails } from '../../../../src/lib/types'; -import { Hbar } from '@hashgraph/sdk'; -import { Long } from 'long'; chai.use(chaiAsPromised); @@ -52,7 +53,7 @@ describe('HBAR Rate Limit Service', function () { const mode = constants.EXECUTION_MODE.TRANSACTION; const methodName = 'testMethod'; const txConstructorName = 'testConstructorName'; - const mockEthAddress = '0x123'; + const mockEvmAddress = '0x123'; const mockIpAddress = 'x.x.x'; const mockEstimatedTxFee = 300; const mockPlanId = uuidV4(randomBytes(16)); @@ -62,18 +63,18 @@ describe('HBAR Rate Limit Service', function () { let hbarLimitService: HbarLimitService; let hbarSpendingPlanRepositoryStub: sinon.SinonStubbedInstance; - let ethAddressHbarSpendingPlanRepositoryStub: sinon.SinonStubbedInstance; + let evmAddressHbarSpendingPlanRepositoryStub: sinon.SinonStubbedInstance; let ipAddressHbarSpendingPlanRepositoryStub: sinon.SinonStubbedInstance; let loggerSpy: sinon.SinonSpiedInstance; beforeEach(function () { loggerSpy = sinon.spy(logger); hbarSpendingPlanRepositoryStub = sinon.createStubInstance(HbarSpendingPlanRepository); - ethAddressHbarSpendingPlanRepositoryStub = sinon.createStubInstance(EthAddressHbarSpendingPlanRepository); + evmAddressHbarSpendingPlanRepositoryStub = sinon.createStubInstance(EvmAddressHbarSpendingPlanRepository); ipAddressHbarSpendingPlanRepositoryStub = sinon.createStubInstance(IPAddressHbarSpendingPlanRepository); hbarLimitService = new HbarLimitService( hbarSpendingPlanRepositoryStub, - ethAddressHbarSpendingPlanRepositoryStub, + evmAddressHbarSpendingPlanRepositoryStub, ipAddressHbarSpendingPlanRepositoryStub, logger, register, @@ -128,7 +129,7 @@ describe('HBAR Rate Limit Service', function () { it('should return tomorrow at midnight', function () { const hbarLimitService = new HbarLimitService( hbarSpendingPlanRepositoryStub, - ethAddressHbarSpendingPlanRepositoryStub, + evmAddressHbarSpendingPlanRepositoryStub, ipAddressHbarSpendingPlanRepositoryStub, logger, register, @@ -175,7 +176,7 @@ describe('HBAR Rate Limit Service', function () { }); describe('shouldLimit', function () { - describe('based on ethAddress', async function () { + describe('based on evmAddress', async function () { it('should return true if the total budget is exceeded', async function () { // @ts-ignore hbarLimitService.remainingBudget = Hbar.fromTinybars(0); @@ -183,7 +184,7 @@ describe('HBAR Rate Limit Service', function () { mode, methodName, txConstructorName, - mockEthAddress, + mockEvmAddress, requestDetails, ); expect(result).to.be.true; @@ -196,40 +197,40 @@ describe('HBAR Rate Limit Service', function () { mode, methodName, txConstructorName, - mockEthAddress, + mockEvmAddress, requestDetails, mockEstimatedTxFee, ); expect(result).to.be.true; }); - it('should create a basic spending plan if none exists for the ethAddress', async function () { + it('should create a basic spending plan if none exists for the evmAddress', async function () { const newSpendingPlan = createSpendingPlan(mockPlanId); - const error = new EthAddressHbarSpendingPlanNotFoundError(mockEthAddress); - ethAddressHbarSpendingPlanRepositoryStub.findByAddress.rejects(error); + const error = new EvmAddressHbarSpendingPlanNotFoundError(mockEvmAddress); + evmAddressHbarSpendingPlanRepositoryStub.findByAddress.rejects(error); hbarSpendingPlanRepositoryStub.create.resolves(newSpendingPlan); - ethAddressHbarSpendingPlanRepositoryStub.save.resolves(); + evmAddressHbarSpendingPlanRepositoryStub.save.resolves(); const result = await hbarLimitService.shouldLimit( mode, methodName, txConstructorName, - mockEthAddress, + mockEvmAddress, requestDetails, ); expect(result).to.be.false; expect(hbarSpendingPlanRepositoryStub.create.calledOnce).to.be.true; - expect(ethAddressHbarSpendingPlanRepositoryStub.save.calledOnce).to.be.true; + expect(evmAddressHbarSpendingPlanRepositoryStub.save.calledOnce).to.be.true; expect( loggerSpy.warn.calledWithMatch( - sinon.match.instanceOf(EthAddressHbarSpendingPlanNotFoundError), - `Failed to get spending plan for eth address '${mockEthAddress}'`, + sinon.match.instanceOf(EvmAddressHbarSpendingPlanNotFoundError), + `Failed to get spending plan for evm address '${mockEvmAddress}'`, ), ).to.be.true; }); - it('should return false if ethAddress and ipAddress is empty string', async function () { + it('should return false if evmAddress and ipAddress is empty string', async function () { const requestDetails = new RequestDetails({ requestId: 'hbarLimterTest', ipAddress: '' }); const result = await hbarLimitService.shouldLimit(mode, methodName, txConstructorName, '', requestDetails); expect(result).to.be.false; @@ -237,8 +238,8 @@ describe('HBAR Rate Limit Service', function () { it('should return true if amountSpent is exactly at the limit', async function () { const spendingPlan = createSpendingPlan(mockPlanId, HbarLimitService.TIER_LIMITS[SubscriptionTier.BASIC]); - ethAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ - ethAddress: mockEthAddress, + evmAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ + evmAddress: mockEvmAddress, planId: mockPlanId, }); hbarSpendingPlanRepositoryStub.findByIdWithDetails.resolves(spendingPlan); @@ -247,7 +248,7 @@ describe('HBAR Rate Limit Service', function () { mode, methodName, txConstructorName, - mockEthAddress, + mockEvmAddress, requestDetails, ); @@ -259,8 +260,8 @@ describe('HBAR Rate Limit Service', function () { mockPlanId, HbarLimitService.TIER_LIMITS[SubscriptionTier.BASIC].toTinybars().sub(1), ); - ethAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ - ethAddress: mockEthAddress, + evmAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ + evmAddress: mockEvmAddress, planId: mockPlanId, }); hbarSpendingPlanRepositoryStub.findByIdWithDetails.resolves(spendingPlan); @@ -269,7 +270,7 @@ describe('HBAR Rate Limit Service', function () { mode, methodName, txConstructorName, - mockEthAddress, + mockEvmAddress, requestDetails, ); @@ -281,8 +282,8 @@ describe('HBAR Rate Limit Service', function () { mockPlanId, HbarLimitService.TIER_LIMITS[SubscriptionTier.BASIC].toTinybars().add(1), ); - ethAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ - ethAddress: mockEthAddress, + evmAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ + evmAddress: mockEvmAddress, planId: mockPlanId, }); hbarSpendingPlanRepositoryStub.findByIdWithDetails.resolves(spendingPlan); @@ -291,7 +292,7 @@ describe('HBAR Rate Limit Service', function () { mode, methodName, txConstructorName, - mockEthAddress, + mockEvmAddress, requestDetails, ); @@ -303,8 +304,8 @@ describe('HBAR Rate Limit Service', function () { mockPlanId, HbarLimitService.TIER_LIMITS[SubscriptionTier.BASIC].toTinybars().sub(mockEstimatedTxFee).add(1), ); - ethAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ - ethAddress: mockEthAddress, + evmAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ + evmAddress: mockEvmAddress, planId: mockPlanId, }); hbarSpendingPlanRepositoryStub.findByIdWithDetails.resolves(spendingPlan); @@ -313,7 +314,7 @@ describe('HBAR Rate Limit Service', function () { mode, methodName, txConstructorName, - mockEthAddress, + mockEvmAddress, requestDetails, mockEstimatedTxFee, ); @@ -326,8 +327,8 @@ describe('HBAR Rate Limit Service', function () { mockPlanId, HbarLimitService.TIER_LIMITS[SubscriptionTier.BASIC].toTinybars().sub(mockEstimatedTxFee).sub(1), ); - ethAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ - ethAddress: mockEthAddress, + evmAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ + evmAddress: mockEvmAddress, planId: mockPlanId, }); hbarSpendingPlanRepositoryStub.findByIdWithDetails.resolves(spendingPlan); @@ -336,7 +337,7 @@ describe('HBAR Rate Limit Service', function () { mode, methodName, txConstructorName, - mockEthAddress, + mockEvmAddress, requestDetails, ); @@ -348,8 +349,8 @@ describe('HBAR Rate Limit Service', function () { mockPlanId, HbarLimitService.TIER_LIMITS[SubscriptionTier.BASIC].toTinybars().sub(mockEstimatedTxFee), ); - ethAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ - ethAddress: mockEthAddress, + evmAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ + evmAddress: mockEvmAddress, planId: mockPlanId, }); hbarSpendingPlanRepositoryStub.findByIdWithDetails.resolves(spendingPlan); @@ -358,7 +359,7 @@ describe('HBAR Rate Limit Service', function () { mode, methodName, txConstructorName, - mockEthAddress, + mockEvmAddress, requestDetails, ); @@ -498,7 +499,7 @@ describe('HBAR Rate Limit Service', function () { describe('disable the rate limiter', function () { const hbarLimitServiceDisabled = new HbarLimitService( hbarSpendingPlanRepositoryStub, - ethAddressHbarSpendingPlanRepositoryStub, + evmAddressHbarSpendingPlanRepositoryStub, ipAddressHbarSpendingPlanRepositoryStub, logger, register, @@ -511,8 +512,8 @@ describe('HBAR Rate Limit Service', function () { mockPlanId, HbarLimitService.TIER_LIMITS[SubscriptionTier.BASIC].toTinybars().sub(mockEstimatedTxFee).add(1), ); - ethAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ - ethAddress: mockEthAddress, + evmAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ + evmAddress: mockEvmAddress, planId: mockPlanId, }); hbarSpendingPlanRepositoryStub.findByIdWithDetails.resolves(spendingPlan); @@ -521,7 +522,7 @@ describe('HBAR Rate Limit Service', function () { mode, methodName, txConstructorName, - mockEthAddress, + mockEvmAddress, requestDetails, mockEstimatedTxFee, ); @@ -531,35 +532,35 @@ describe('HBAR Rate Limit Service', function () { }); it('should return undefined if the rate limiter is disabled and addExpense is called', async function () { - expect(await hbarLimitServiceDisabled.addExpense(100, mockEthAddress, requestDetails)).to.be.undefined; + expect(await hbarLimitServiceDisabled.addExpense(100, mockEvmAddress, requestDetails)).to.be.undefined; }); }); }); describe('getSpendingPlan', function () { - it(`should return null if neither ethAddress nor ipAddress is provided`, async function () { + it(`should return null if neither evmAddress nor ipAddress is provided`, async function () { const ipAddresses = ['']; - const ethAddresses = ['']; - const testCases = ethAddresses.flatMap((ethAddress) => - ipAddresses.map((ipAddress) => ({ ethAddress, ipAddress })), + const evmAddresses = ['']; + const testCases = evmAddresses.flatMap((evmAddress) => + ipAddresses.map((ipAddress) => ({ evmAddress, ipAddress })), ); - for (const { ethAddress, ipAddress } of testCases) { + for (const { evmAddress, ipAddress } of testCases) { // @ts-ignore const requestDetails = new RequestDetails({ requestId: 'hbarLimterTest', ipAddress: ipAddress }); - const result = await hbarLimitService['getSpendingPlan'](ethAddress, requestDetails); + const result = await hbarLimitService['getSpendingPlan'](evmAddress, requestDetails); expect(result).to.be.null; } }); - it('should return spending plan for ethAddress if ethAddress is provided', async function () { + it('should return spending plan for evmAddress if evmAddress is provided', async function () { const spendingPlan = createSpendingPlan(mockPlanId); - ethAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ - ethAddress: mockEthAddress, + evmAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ + evmAddress: mockEvmAddress, planId: mockPlanId, }); hbarSpendingPlanRepositoryStub.findByIdWithDetails.resolves(spendingPlan); - const result = await hbarLimitService['getSpendingPlan'](mockEthAddress, requestDetails); + const result = await hbarLimitService['getSpendingPlan'](mockEvmAddress, requestDetails); expect(result).to.deep.equal(spendingPlan); }); @@ -577,11 +578,11 @@ describe('HBAR Rate Limit Service', function () { expect(result).to.deep.equal(spendingPlan); }); - it('should return null if no spending plan is found for ethAddress', async function () { - const error = new EthAddressHbarSpendingPlanNotFoundError(mockEthAddress); - ethAddressHbarSpendingPlanRepositoryStub.findByAddress.rejects(error); + it('should return null if no spending plan is found for evmAddress', async function () { + const error = new EvmAddressHbarSpendingPlanNotFoundError(mockEvmAddress); + evmAddressHbarSpendingPlanRepositoryStub.findByAddress.rejects(error); - const result = await hbarLimitService['getSpendingPlan'](mockEthAddress, requestDetails); + const result = await hbarLimitService['getSpendingPlan'](mockEvmAddress, requestDetails); expect(result).to.be.null; }); @@ -596,94 +597,94 @@ describe('HBAR Rate Limit Service', function () { }); }); - describe('getSpendingPlanByEthAddress', function () { - const testGetSpendingPlanByEthAddressError = async (error: Error, errorClass: any) => { - const result = hbarLimitService['getSpendingPlanByEthAddress'](mockEthAddress, requestDetails); + describe('getSpendingPlanByEvmAddress', function () { + const testGetSpendingPlanByEvmAddressError = async (error: Error, errorClass: any) => { + const result = hbarLimitService['getSpendingPlanByEvmAddress'](mockEvmAddress, requestDetails); await expect(result).to.be.eventually.rejectedWith(errorClass, error.message); }; - it('should handle error when getSpendingPlanByEthAddress throws an EthAddressHbarSpendingPlanNotFoundError', async function () { - const error = new EthAddressHbarSpendingPlanNotFoundError(mockEthAddress); - ethAddressHbarSpendingPlanRepositoryStub.findByAddress.rejects(error); - await testGetSpendingPlanByEthAddressError(error, EthAddressHbarSpendingPlanNotFoundError); + it('should handle error when getSpendingPlanByEvmAddress throws an EvmAddressHbarSpendingPlanNotFoundError', async function () { + const error = new EvmAddressHbarSpendingPlanNotFoundError(mockEvmAddress); + evmAddressHbarSpendingPlanRepositoryStub.findByAddress.rejects(error); + await testGetSpendingPlanByEvmAddressError(error, EvmAddressHbarSpendingPlanNotFoundError); }); - it('should handle error when getSpendingPlanByEthAddress throws an HbarSpendingPlanNotFoundError', async function () { + it('should handle error when getSpendingPlanByEvmAddress throws an HbarSpendingPlanNotFoundError', async function () { const error = new HbarSpendingPlanNotFoundError(mockPlanId); - ethAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ - ethAddress: mockEthAddress, + evmAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ + evmAddress: mockEvmAddress, planId: mockPlanId, }); hbarSpendingPlanRepositoryStub.findByIdWithDetails.rejects(error); - await testGetSpendingPlanByEthAddressError(error, HbarSpendingPlanNotFoundError); + await testGetSpendingPlanByEvmAddressError(error, HbarSpendingPlanNotFoundError); }); - it('should handle error when getSpendingPlanByEthAddress throws an HbarSpendingPlanNotActiveError', async function () { + it('should handle error when getSpendingPlanByEvmAddress throws an HbarSpendingPlanNotActiveError', async function () { const error = new HbarSpendingPlanNotActiveError(mockPlanId); - ethAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ - ethAddress: mockEthAddress, + evmAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ + evmAddress: mockEvmAddress, planId: mockPlanId, }); hbarSpendingPlanRepositoryStub.findByIdWithDetails.rejects(error); - await testGetSpendingPlanByEthAddressError(error, HbarSpendingPlanNotActiveError); + await testGetSpendingPlanByEvmAddressError(error, HbarSpendingPlanNotActiveError); }); - it('should return the spending plan for the given ethAddress', async function () { + it('should return the spending plan for the given evmAddress', async function () { const spendingPlan = createSpendingPlan(mockPlanId); - ethAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ - ethAddress: mockEthAddress, + evmAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ + evmAddress: mockEvmAddress, planId: mockPlanId, }); hbarSpendingPlanRepositoryStub.findByIdWithDetails.resolves(spendingPlan); - const result = await hbarLimitService['getSpendingPlanByEthAddress'](mockEthAddress, requestDetails); + const result = await hbarLimitService['getSpendingPlanByEvmAddress'](mockEvmAddress, requestDetails); expect(result).to.deep.equal(spendingPlan); }); }); describe('createBasicSpendingPlan', function () { - const testCreateBasicSpendingPlan = async (ethAddress: string, ipAddress?: string) => { + const testCreateBasicSpendingPlan = async (evmAddress: string, ipAddress?: string) => { const requestDetails = new RequestDetails({ requestId: 'hbarLimitServiceTest', ipAddress: ipAddress ?? '' }); const newSpendingPlan = createSpendingPlan(mockPlanId); hbarSpendingPlanRepositoryStub.create.resolves(newSpendingPlan); - ethAddressHbarSpendingPlanRepositoryStub.save.resolves(); + evmAddressHbarSpendingPlanRepositoryStub.save.resolves(); - const promise = hbarLimitService['createBasicSpendingPlan'](ethAddress, requestDetails); + const promise = hbarLimitService['createBasicSpendingPlan'](evmAddress, requestDetails); - if (ethAddress) { + if (evmAddress) { await expect(promise).eventually.to.deep.equal(newSpendingPlan); expect(hbarSpendingPlanRepositoryStub.create.calledOnce).to.be.true; expect(ipAddressHbarSpendingPlanRepositoryStub.save.calledOnce).to.be.false; - expect(ethAddressHbarSpendingPlanRepositoryStub.save.calledOnce).to.be.true; + expect(evmAddressHbarSpendingPlanRepositoryStub.save.calledOnce).to.be.true; } else { - await expect(promise).to.be.rejectedWith('Cannot create a spending plan without an associated eth address'); + await expect(promise).to.be.rejectedWith('Cannot create a spending plan without an associated evm address'); expect(hbarSpendingPlanRepositoryStub.create.calledOnce).to.be.false; expect(ipAddressHbarSpendingPlanRepositoryStub.save.calledOnce).to.be.false; - expect(ethAddressHbarSpendingPlanRepositoryStub.save.calledOnce).to.be.false; + expect(evmAddressHbarSpendingPlanRepositoryStub.save.calledOnce).to.be.false; } }; - it('should create a basic spending plan for the given ethAddress', async function () { - await testCreateBasicSpendingPlan(mockEthAddress); + it('should create a basic spending plan for the given evmAddress', async function () { + await testCreateBasicSpendingPlan(mockEvmAddress); }); - it('should create a basic spending plan and link it only to the given ethAddress, if also an ipAddress is available', async function () { - await testCreateBasicSpendingPlan(mockEthAddress, '127.0.0.1'); + it('should create a basic spending plan and link it only to the given evmAddress, if also an ipAddress is available', async function () { + await testCreateBasicSpendingPlan(mockEvmAddress, '127.0.0.1'); }); - it('should throw an error if no ethAddress is provided', async function () { + it('should throw an error if no evmAddress is provided', async function () { await testCreateBasicSpendingPlan(''); }); }); describe('addExpense', function () { - const testAddExpense = async (ethAddress: string, ipAddress: string, expense: number = 100) => { + const testAddExpense = async (evmAddress: string, ipAddress: string, expense: number = 100) => { const otherPlanOfTheSameTier = createSpendingPlan(uuidV4(randomBytes(16)), 200); const existingSpendingPlan = createSpendingPlan(mockPlanId, 0); - if (ethAddress) { - ethAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ - ethAddress, + if (evmAddress) { + evmAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ + evmAddress, planId: mockPlanId, }); } else if (ipAddress) { @@ -717,7 +718,7 @@ describe('HBAR Rate Limit Service', function () { 'updateAverageAmountSpentPerSubscriptionTier' as any, ); - await hbarLimitService.addExpense(expense, ethAddress, requestDetails); + await hbarLimitService.addExpense(expense, evmAddress, requestDetails); expect(hbarSpendingPlanRepositoryStub.addToAmountSpent.calledOnceWith(mockPlanId, expense)).to.be.true; expect(hbarLimitService['remainingBudget'].toTinybars().toNumber()).to.eq( @@ -735,38 +736,38 @@ describe('HBAR Rate Limit Service', function () { it('should create a basic spending plan if none exists', async function () { const newSpendingPlan = createSpendingPlan(mockPlanId); hbarSpendingPlanRepositoryStub.create.resolves(newSpendingPlan); - ethAddressHbarSpendingPlanRepositoryStub.findByAddress.rejects( - new EthAddressHbarSpendingPlanNotFoundError(mockEthAddress), + evmAddressHbarSpendingPlanRepositoryStub.findByAddress.rejects( + new EvmAddressHbarSpendingPlanNotFoundError(mockEvmAddress), ); - ethAddressHbarSpendingPlanRepositoryStub.save.resolves(); + evmAddressHbarSpendingPlanRepositoryStub.save.resolves(); - await hbarLimitService.addExpense(100, mockEthAddress, requestDetails); + await hbarLimitService.addExpense(100, mockEvmAddress, requestDetails); expect(hbarSpendingPlanRepositoryStub.create.calledOnce).to.be.true; - expect(ethAddressHbarSpendingPlanRepositoryStub.save.calledOnce).to.be.true; + expect(evmAddressHbarSpendingPlanRepositoryStub.save.calledOnce).to.be.true; }); - it('should add the expense to the spending plan and update the remaining budget when both ethAddress and ipAddress are provided', async function () { - await testAddExpense(mockEthAddress, '127.0.0.1'); + it('should add the expense to the spending plan and update the remaining budget when both evmAddress and ipAddress are provided', async function () { + await testAddExpense(mockEvmAddress, '127.0.0.1'); }); - it('should add the expense to the spending plan and update the remaining budget when ethAddress is provided but ipAddress is not', async function () { - await testAddExpense(mockEthAddress, ''); + it('should add the expense to the spending plan and update the remaining budget when evmAddress is provided but ipAddress is not', async function () { + await testAddExpense(mockEvmAddress, ''); }); - it('should add the expense to the spending plan and update the remaining budget when ipAddress is provided but ethAddress is not', async function () { + it('should add the expense to the spending plan and update the remaining budget when ipAddress is provided but evmAddress is not', async function () { await testAddExpense('', '127.0.0.1'); }); it('should handle errors when adding expense fails', async function () { - ethAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ - ethAddress: mockEthAddress, + evmAddressHbarSpendingPlanRepositoryStub.findByAddress.resolves({ + evmAddress: mockEvmAddress, planId: mockPlanId, }); hbarSpendingPlanRepositoryStub.findByIdWithDetails.resolves(createSpendingPlan(mockPlanId)); hbarSpendingPlanRepositoryStub.addToAmountSpent.rejects(new Error('Failed to add expense')); - await expect(hbarLimitService.addExpense(100, mockEthAddress, requestDetails)).to.be.eventually.rejectedWith( + await expect(hbarLimitService.addExpense(100, mockEvmAddress, requestDetails)).to.be.eventually.rejectedWith( 'Failed to add expense', ); }); diff --git a/packages/relay/tests/lib/services/metricService/metricService.spec.ts b/packages/relay/tests/lib/services/metricService/metricService.spec.ts index 3f14d1cf3f..2527f51126 100644 --- a/packages/relay/tests/lib/services/metricService/metricService.spec.ts +++ b/packages/relay/tests/lib/services/metricService/metricService.spec.ts @@ -19,29 +19,30 @@ */ import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; -import pino from 'pino'; -import { expect } from 'chai'; -import * as sinon from 'sinon'; -import EventEmitter from 'events'; +import { AccountId, Client, Hbar, Long, Status, TransactionRecord, TransactionRecordQuery } from '@hashgraph/sdk'; import axios, { AxiosInstance } from 'axios'; import MockAdapter from 'axios-mock-adapter'; -import { Utils } from '../../../../src/utils'; +import { expect } from 'chai'; +import EventEmitter from 'events'; +import pino from 'pino'; import { register, Registry } from 'prom-client'; +import * as sinon from 'sinon'; + +import { MirrorNodeClient, SDKClient } from '../../../../src/lib/clients'; import constants from '../../../../src/lib/constants'; +import { EvmAddressHbarSpendingPlanRepository } from '../../../../src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository'; +import { HbarSpendingPlanRepository } from '../../../../src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository'; +import { IPAddressHbarSpendingPlanRepository } from '../../../../src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository'; +import { CacheService } from '../../../../src/lib/services/cacheService/cacheService'; +import { HbarLimitService } from '../../../../src/lib/services/hbarLimitService'; +import MetricService from '../../../../src/lib/services/metricService/metricService'; +import { IExecuteQueryEventPayload, IExecuteTransactionEventPayload, RequestDetails } from '../../../../src/lib/types'; +import { Utils } from '../../../../src/utils'; import { calculateTxRecordChargeAmount, overrideEnvsInMochaDescribe, withOverriddenEnvsInMochaTest, } from '../../../helpers'; -import { MirrorNodeClient, SDKClient } from '../../../../src/lib/clients'; -import { HbarLimitService } from '../../../../src/lib/services/hbarLimitService'; -import MetricService from '../../../../src/lib/services/metricService/metricService'; -import { CacheService } from '../../../../src/lib/services/cacheService/cacheService'; -import { AccountId, Client, Hbar, Long, Status, TransactionRecord, TransactionRecordQuery } from '@hashgraph/sdk'; -import { IExecuteQueryEventPayload, IExecuteTransactionEventPayload, RequestDetails } from '../../../../src/lib/types'; -import { HbarSpendingPlanRepository } from '../../../../src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository'; -import { IPAddressHbarSpendingPlanRepository } from '../../../../src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository'; -import { EthAddressHbarSpendingPlanRepository } from '../../../../src/lib/db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository'; const registry = new Registry(); const logger = pino(); @@ -145,11 +146,11 @@ describe('Metric Service', function () { const cacheService = new CacheService(logger, registry); const hbarSpendingPlanRepository = new HbarSpendingPlanRepository(cacheService, logger); - const ethAddressHbarSpendingPlanRepository = new EthAddressHbarSpendingPlanRepository(cacheService, logger); + const evmAddressHbarSpendingPlanRepository = new EvmAddressHbarSpendingPlanRepository(cacheService, logger); const ipAddressHbarSpendingPlanRepository = new IPAddressHbarSpendingPlanRepository(cacheService, logger); hbarLimitService = new HbarLimitService( hbarSpendingPlanRepository, - ethAddressHbarSpendingPlanRepository, + evmAddressHbarSpendingPlanRepository, ipAddressHbarSpendingPlanRepository, logger, register, diff --git a/packages/server/tests/acceptance/hbarLimiter.spec.ts b/packages/server/tests/acceptance/hbarLimiter.spec.ts index d7d3e3d27c..dfa6c73574 100644 --- a/packages/server/tests/acceptance/hbarLimiter.spec.ts +++ b/packages/server/tests/acceptance/hbarLimiter.spec.ts @@ -18,41 +18,40 @@ * */ -import fs from 'fs'; +import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; +import { predefined } from '@hashgraph/json-rpc-relay'; +import { EvmAddressHbarSpendingPlanRepository } from '@hashgraph/json-rpc-relay/dist/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository'; +import { HbarSpendingPlanRepository } from '@hashgraph/json-rpc-relay/dist/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository'; +import { IPAddressHbarSpendingPlanRepository } from '@hashgraph/json-rpc-relay/dist/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository'; +import { IDetailedHbarSpendingPlan } from '@hashgraph/json-rpc-relay/dist/lib/db/types/hbarLimiter/hbarSpendingPlan'; +import { SubscriptionTier } from '@hashgraph/json-rpc-relay/dist/lib/db/types/hbarLimiter/subscriptionTier'; +import { CacheService } from '@hashgraph/json-rpc-relay/dist/lib/services/cacheService/cacheService'; +import { HbarLimitService } from '@hashgraph/json-rpc-relay/dist/lib/services/hbarLimitService'; +import { ITransfer, RequestDetails } from '@hashgraph/json-rpc-relay/dist/lib/types'; +import { SpendingPlanConfig } from '@hashgraph/json-rpc-relay/src/lib/types/spendingPlanConfig'; +import { estimateFileTransactionsFee, overrideEnvsInMochaDescribe } from '@hashgraph/json-rpc-relay/tests/helpers'; import { expect } from 'chai'; +import dotenv, { config } from 'dotenv'; +import { BaseContract, ethers } from 'ethers'; +import findConfig from 'find-config'; +import fs from 'fs'; import { resolve } from 'path'; import { Logger } from 'pino'; -import findConfig from 'find-config'; import { Registry } from 'prom-client'; -import dotenv, { config } from 'dotenv'; -import { BaseContract, ethers } from 'ethers'; -import { predefined } from '@hashgraph/json-rpc-relay'; -// Local resources -import { Utils } from '../helpers/utils'; -import Assertions from '../helpers/assertions'; -import testConstants from '../helpers/constants'; -import RelayClient from '../clients/relayClient'; -import MirrorClient from '../clients/mirrorClient'; import MetricsClient from '../clients/metricsClient'; -import { AliasAccount } from '../types/AliasAccount'; -import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; -import { ITransfer, RequestDetails } from '@hashgraph/json-rpc-relay/dist/lib/types'; -import { SpendingPlanConfig } from '@hashgraph/json-rpc-relay/src/lib/types/spendingPlanConfig'; -import { HbarLimitService } from '@hashgraph/json-rpc-relay/dist/lib/services/hbarLimitService'; -import { CacheService } from '@hashgraph/json-rpc-relay/dist/lib/services/cacheService/cacheService'; -import { SubscriptionTier } from '@hashgraph/json-rpc-relay/dist/lib/db/types/hbarLimiter/subscriptionTier'; -import { estimateFileTransactionsFee, overrideEnvsInMochaDescribe } from '@hashgraph/json-rpc-relay/tests/helpers'; -import { IDetailedHbarSpendingPlan } from '@hashgraph/json-rpc-relay/dist/lib/db/types/hbarLimiter/hbarSpendingPlan'; -import { HbarSpendingPlanRepository } from '@hashgraph/json-rpc-relay/dist/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository'; -import { IPAddressHbarSpendingPlanRepository } from '@hashgraph/json-rpc-relay/dist/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository'; -import { EthAddressHbarSpendingPlanRepository } from '@hashgraph/json-rpc-relay/dist/lib/db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository'; - -// Contracts used in tests -import parentContractJson from '../contracts/Parent.json'; +import MirrorClient from '../clients/mirrorClient'; +import RelayClient from '../clients/relayClient'; import EstimateGasContract from '../contracts/EstimateGasContract.json'; import largeContractJson from '../contracts/hbarLimiterContracts/largeSizeContract.json'; import mediumSizeContract from '../contracts/hbarLimiterContracts/mediumSizeContract.json'; +// Contracts used in tests +import parentContractJson from '../contracts/Parent.json'; +import Assertions from '../helpers/assertions'; +import testConstants from '../helpers/constants'; +// Local resources +import { Utils } from '../helpers/utils'; +import { AliasAccount } from '../types/AliasAccount'; config({ path: resolve(__dirname, '../localAcceptance.env') }); const DOT_ENV = dotenv.parse(fs.readFileSync(resolve(__dirname, '../localAcceptance.env'))); @@ -84,7 +83,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { const maxExtendedSpendingLimit = HbarLimitService.TIER_LIMITS.EXTENDED.toTinybars().toNumber(); const maxPrivilegedSpendingLimit = HbarLimitService.TIER_LIMITS.PRIVILEGED.toTinybars().toNumber(); - const ethAddressSpendingPlanRepository = new EthAddressHbarSpendingPlanRepository(cacheService, logger); + const evmAddressSpendingPlanRepository = new EvmAddressHbarSpendingPlanRepository(cacheService, logger); const ipSpendingPlanRepository = new IPAddressHbarSpendingPlanRepository(cacheService, logger); const hbarSpendingPlanRepository = new HbarSpendingPlanRepository( cacheService, @@ -409,7 +408,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { subscriptionTier: SubscriptionTier, accountCounts: number = 1, ) => { - let aliasAccounts: AliasAccount[] = []; + const aliasAccounts: AliasAccount[] = []; const hbarSpendingPlan = await hbarSpendingPlanRepository.create(subscriptionTier, requestDetails, mockTTL); for (let i = 0; i < accountCounts; i++) { @@ -421,14 +420,14 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { ); global.accounts.push(aliasAccount); - await ethAddressSpendingPlanRepository.save( - { ethAddress: aliasAccount.address, planId: hbarSpendingPlan.id }, + await evmAddressSpendingPlanRepository.save( + { evmAddress: aliasAccount.address, planId: hbarSpendingPlan.id }, requestDetails, mockTTL, ); - const plan = await ethAddressSpendingPlanRepository.findByAddress(aliasAccount.address, requestDetails); - expect(plan.ethAddress).to.eq(aliasAccount.address); + const plan = await evmAddressSpendingPlanRepository.findByAddress(aliasAccount.address, requestDetails); + expect(plan.evmAddress).to.eq(aliasAccount.address); expect(plan.planId).to.eq(hbarSpendingPlan.id); const spendingPlan = await hbarSpendingPlanRepository.findByIdWithDetails(plan.planId, requestDetails); expect(spendingPlan.active).to.be.true; @@ -449,7 +448,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { ); for (const plan of basicPlans) { await hbarSpendingPlanRepository.delete(plan.id, requestDetails); - await ethAddressSpendingPlanRepository.deleteAllByPlanId(plan.id, 'before', requestDetails); + await evmAddressSpendingPlanRepository.deleteAllByPlanId(plan.id, 'before', requestDetails); await ipSpendingPlanRepository.deleteAllByPlanId(plan.id, 'before', requestDetails); } }); @@ -466,7 +465,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { ); } - expect(ethAddressSpendingPlanRepository.findByAddress(accounts[2].address, requestDetails)).to.be.rejected; + expect(evmAddressSpendingPlanRepository.findByAddress(accounts[2].address, requestDetails)).to.be.rejected; const gasPrice = await relay.gasPrice(requestId); const transaction = { ...defaultLondonTransactionData, @@ -483,7 +482,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { // awaiting for HBAR limiter to finish updating expenses in the background await Utils.wait(6000); - const ethSpendingPlan = await ethAddressSpendingPlanRepository.findByAddress( + const ethSpendingPlan = await evmAddressSpendingPlanRepository.findByAddress( accounts[2].address, requestDetails, ); @@ -536,7 +535,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { await expect(relay.call(testConstants.ETH_ENDPOINTS.ETH_SEND_RAW_TRANSACTION, [signedTxThird], requestId)) .to.be.fulfilled; - const ethSpendingPlanThird = await ethAddressSpendingPlanRepository.findByAddress( + const ethSpendingPlanThird = await evmAddressSpendingPlanRepository.findByAddress( accounts[1].address, requestDetails, ); @@ -551,7 +550,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { const remainingHbarsBefore = Number(await metrics.get(testConstants.METRICS.REMAINING_HBAR_LIMIT)); //Unlinking the ipAdress, since ipAddress when running tests in CI and locally is the same - expect(ethAddressSpendingPlanRepository.findByAddress(accounts[2].address, requestDetails)).to.be.rejected; + expect(evmAddressSpendingPlanRepository.findByAddress(accounts[2].address, requestDetails)).to.be.rejected; try { for (deploymentCounts = 0; deploymentCounts < 50; deploymentCounts++) { const tx = await deployContract(largeContractJson, accounts[2].wallet); @@ -560,7 +559,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { expectedTxCost ||= await getExpectedCostOfLastLargeTx(largeContractJson.bytecode); if (!hbarSpendingPlan) { - const ethSpendingPlan = await ethAddressSpendingPlanRepository.findByAddress( + const ethSpendingPlan = await evmAddressSpendingPlanRepository.findByAddress( accounts[2].wallet.address, requestDetails, ); @@ -580,7 +579,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { expect(deploymentCounts).to.eq(expectedAmountOfDeployments); if (!hbarSpendingPlan) { - const ethSpendingPlan = await ethAddressSpendingPlanRepository.findByAddress( + const ethSpendingPlan = await evmAddressSpendingPlanRepository.findByAddress( accounts[2].wallet.address, requestDetails, ); @@ -714,14 +713,14 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { expect(hbarSpendingPlan.id).to.eq(expectedPlan.id); expect(hbarSpendingPlan.subscriptionTier).to.eq(expectedPlan.subscriptionTier); - if (expectedPlan.ethAddresses) { - expectedPlan.ethAddresses.forEach(async (evmAddress) => { - const associatedPlanByEVMAddress = await ethAddressSpendingPlanRepository.findByAddress( + if (expectedPlan.evmAddresses) { + expectedPlan.evmAddresses.forEach(async (evmAddress) => { + const associatedPlanByEVMAddress = await evmAddressSpendingPlanRepository.findByAddress( evmAddress, requestDetails, ); expect(associatedPlanByEVMAddress.planId).to.eq(expectedPlan.id); - expect(associatedPlanByEVMAddress.ethAddress).to.eq(evmAddress); + expect(associatedPlanByEVMAddress.evmAddress).to.eq(evmAddress); }); } diff --git a/packages/server/tests/testSpendingPlansConfig.json b/packages/server/tests/testSpendingPlansConfig.json index 0f44431a8c..62c40de363 100644 --- a/packages/server/tests/testSpendingPlansConfig.json +++ b/packages/server/tests/testSpendingPlansConfig.json @@ -2,20 +2,20 @@ { "id": "c758c095-342c-4607-9db5-867d7e90ab9d", "name": "PRIVILEGED_ALPHA", - "ethAddresses": ["0x7d102fe71af42790fe31b126c1f49766376ca2b5"], + "evmAddresses": ["0x7d102fe71af42790fe31b126c1f49766376ca2b5"], "ipAddresses": ["127.0.0.1"], "subscriptionTier": "PRIVILEGED" }, { "id": "a68488b0-6f7d-44a0-87c1-774ad64615f2", "name": "PRIVILEGED_BETA", - "ethAddresses": ["0x40183ec818c1826114767391989ff2eaebc2b91e", "0xcdad5844f865f379bea057fb435aefef38361b68"], + "evmAddresses": ["0x40183ec818c1826114767391989ff2eaebc2b91e", "0xcdad5844f865f379bea057fb435aefef38361b68"], "subscriptionTier": "PRIVILEGED" }, { "id": "af13d6ed-d676-4d33-8b9d-cf05d1ad7134", "name": "EXTENDED_ALPHA", - "ethAddresses": [ + "evmAddresses": [ "0x149294f355f62827748988071de70ab195d0eb23", "0x17b2b8c63fa35402088640e426c6709a254c7ffb", "0x6e5d3858f53fc66727188690946631bde0466b1a" diff --git a/packages/ws-server/tests/acceptance/subscribeNewHeads.spec.ts b/packages/ws-server/tests/acceptance/subscribeNewHeads.spec.ts index d60baf698c..5c207aaa0d 100644 --- a/packages/ws-server/tests/acceptance/subscribeNewHeads.spec.ts +++ b/packages/ws-server/tests/acceptance/subscribeNewHeads.spec.ts @@ -19,23 +19,24 @@ */ // external resources -import WebSocket from 'ws'; -import { ethers } from 'ethers'; -import chai, { expect } from 'chai'; -import { solidity } from 'ethereum-waffle'; +import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; import { predefined } from '@hashgraph/json-rpc-relay/dist'; -import { Utils } from '@hashgraph/json-rpc-server/tests/helpers/utils'; +import MirrorClient from '@hashgraph/json-rpc-server/tests/clients/mirrorClient'; +import RelayClient from '@hashgraph/json-rpc-server/tests/clients/relayClient'; import Assertions from '@hashgraph/json-rpc-server/tests/helpers/assertions'; +import { Utils } from '@hashgraph/json-rpc-server/tests/helpers/utils'; import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount'; -import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; +import chai, { expect } from 'chai'; +import { solidity } from 'ethereum-waffle'; +import { ethers } from 'ethers'; +import WebSocket from 'ws'; + import { WsTestHelper } from '../helper'; -import MirrorClient from '@hashgraph/json-rpc-server/tests/clients/mirrorClient'; -import RelayClient from '@hashgraph/json-rpc-server/tests/clients/relayClient'; chai.use(solidity); const WS_RELAY_URL = `${ConfigService.get('WS_RELAY_URL')}`; -const ethAddressRegex = /^0x[a-fA-F0-9]*$/; +const evmAddressRegex = /^0x[a-fA-F0-9]*$/; function verifyResponse(response: any, done: Mocha.Done, webSocket: any, includeTransactions: boolean) { if (response?.params?.result?.transactions?.length > 0) { @@ -85,7 +86,7 @@ function verifyResponse(response: any, done: Mocha.Done, webSocket: any, include } else { expect(response.params.result).to.have.property('transactions'); expect(response.params.result.transactions).to.have.lengthOf(1); - expect(response.params.result.transactions[0]).to.match(ethAddressRegex); + expect(response.params.result.transactions[0]).to.match(evmAddressRegex); } done(); } catch (error) { diff --git a/spendingPlansConfig.example.json b/spendingPlansConfig.example.json index 4e9a12da85..c2b0be3525 100644 --- a/spendingPlansConfig.example.json +++ b/spendingPlansConfig.example.json @@ -2,20 +2,20 @@ { "id": "c758c095-342c-4607-9db5-867d7e90ab9d", "name": "partner name", - "ethAddresses": ["0x123", "0x124"], + "evmAddresses": ["0x123", "0x124"], "ipAddresses": ["127.0.0.1", "128.0.0.1"], "subscriptionTier": "PRIVILEGED" }, { "id": "a68488b0-6f7d-44a0-87c1-774ad64615f2", - "name": "some other partner that has given us only eth addresses", - "ethAddresses": ["0x125", "0x126"], + "name": "some other partner that has given us only evm addresses", + "evmAddresses": ["0x125", "0x126"], "subscriptionTier": "PRIVILEGED" }, { "id": "af13d6ed-d676-4d33-8b9d-cf05d1ad7134", "name": "supported project name", - "ethAddresses": ["0x127", "0x128"], + "evmAddresses": ["0x127", "0x128"], "ipAddresses": ["129.0.0.1", "130.0.0.1"], "subscriptionTier": "EXTENDED" },