From 5121de301d4624dfbd023dd6ec97684cd7d0878a Mon Sep 17 00:00:00 2001 From: Clayton Neal Date: Wed, 12 Feb 2025 18:29:15 +0000 Subject: [PATCH 1/2] chore: blk-01 (#1794) * chore: blk-01 --- docker/rpc-proxy/Dockerfile | 9 ++ packages/core/src/vcdm/Revision.ts | 85 ++++++++++-------- .../core/tests/vcdm/Revision.unit.test.ts | 5 +- .../src/available-errors/provider/provider.ts | 11 ++- .../src/provider/utils/const/blocks/blocks.ts | 89 +++++++++++-------- .../src/provider/utils/rpc-mapper/index.ts | 1 - .../rpc-mapper/methods/eth_call/eth_call.ts | 7 +- .../eth_estimateGas/eth_estimateGas.ts | 15 ++-- .../methods/eth_getBalance/eth_getBalance.ts | 9 +- .../eth_getBlockByHash/eth_getBlockByHash.ts | 23 ++++- .../eth_getBlockByNumber.ts | 13 ++- .../eth_getBlockTransactionCountByNumber.ts | 2 +- .../methods/eth_getCode/eth_getCode.ts | 9 +- .../eth_getStorageAt/eth_getStorageAt.ts | 9 +- .../eth_getTransactionByHash.ts | 4 +- .../provider/utils/rpc-mapper/rpc-mapper.ts | 5 +- .../src/provider/utils/rpc-mapper/types.d.ts | 19 ---- .../eth_call/eth_call.mock.solo.test.ts | 34 ++++++- .../rpc-mapper/methods/eth_call/fixture.ts | 22 +---- .../methods/eth_estimateGas/fixture.ts | 20 ++--- .../methods/eth_getBalance/fixture.ts | 5 -- .../methods/eth_getBlockByHash/fixture.ts | 2 +- ...ckTransactionCountByNumber.testnet.test.ts | 35 ++++---- .../fixture.ts | 15 +++- packages/rpc-proxy/README.md | 25 ++++++ .../tests/e2e_rpc_proxy.solo.test.ts | 4 +- 26 files changed, 274 insertions(+), 203 deletions(-) delete mode 100644 packages/network/src/provider/utils/rpc-mapper/types.d.ts diff --git a/docker/rpc-proxy/Dockerfile b/docker/rpc-proxy/Dockerfile index ee39c43a8..739e6db71 100644 --- a/docker/rpc-proxy/Dockerfile +++ b/docker/rpc-proxy/Dockerfile @@ -27,6 +27,15 @@ RUN /bin/sh ./adjust-packages.sh ./ # Stage 2: Serve the app using node FROM node:20.17.0-alpine3.20 AS runner +# Update package list and upgrade OpenSSL +RUN apk update && \ + apk add --no-cache openssl && \ + apk upgrade --no-cache openssl && \ + # Verify OpenSSL installation + openssl version && \ + # Clean up + rm -rf /var/cache/apk/* + # Copy only the built files and essential runtime files from the builder stage ## rpc-proxy COPY --from=builder /app/packages/rpc-proxy/dist /app/packages/rpc-proxy/dist diff --git a/packages/core/src/vcdm/Revision.ts b/packages/core/src/vcdm/Revision.ts index 1ff005da6..92f83903a 100644 --- a/packages/core/src/vcdm/Revision.ts +++ b/packages/core/src/vcdm/Revision.ts @@ -1,46 +1,44 @@ import { InvalidDataType } from '@vechain/sdk-errors'; import { Hex } from './Hex'; -import { HexUInt } from './HexUInt'; import { Txt } from './Txt'; /** - * Represents a revision for a Thor transaction or block. - * - * @remarks The string representation of the revision is always expressed as a number in base 10. + * Represents a revision for a Thor transaction or block + * Revision strings can be one of the following: + * - "best": indicating the best revision + * - "finalized": indicating a finalized revision + * - "next": indicating the next revision + * - "justified": indicating the justified revision + * - A hex string prefixed with "0x" indicating a specific block id + * - A positive number indicating a specific block number * * @extends Txt */ class Revision extends Txt { /** * Regular expression pattern for revision strings. - * Revision strings can be one of the following: - * - "best": indicating the best revision - * - "finalized": indicating a finalized revision - * - A positive numeric string indicating a specific revision * * @type {RegExp} */ - private static readonly REGEX_DECIMAL_REVISION = /^(best|finalized|\d+)$/; + private static readonly VALID_REVISION_REGEX = + /^(best|finalized|next|justified|0x[a-fA-F0-9]+|\d+)$/; /** - * Determines if the given value is valid. - * This is true if the given value is - * - "best" string or {@link Txt}: indicating the best revision; - * - "finalized" string or {@link Txt}: indicating a finalized revision; - * - a positive number; - * - a positive numeric decimal or `0x` prefixed hexadecimal string indicating a specific revision, - * - * @param {bigint | number | string | Hex | Txt} value - The value to be validated. + * Determines if the given value is a valid revision. + * @param {bigint| number | string | Hex} value - The value to be validated. * @returns {boolean} - Returns `true` if the value is valid, `false` otherwise. */ - public static isValid(value: number | string): boolean { + public static isValid(value: bigint | number | string | Hex): boolean { if (typeof value === 'number') { return Number.isInteger(value) && value >= 0; } - return ( - HexUInt.isValid0x(value) || - Revision.REGEX_DECIMAL_REVISION.test(value) - ); + if (typeof value === 'bigint') { + return value >= BigInt(0); + } + if (value instanceof Hex) { + return Revision.isValid(value.bi); + } + return Revision.VALID_REVISION_REGEX.test(value); } /** @@ -59,24 +57,25 @@ class Revision extends Txt { */ public static of(value: bigint | number | string | Uint8Array | Hex): Txt { try { - let txt: string; - if (value instanceof Hex) { - txt = value.bi.toString(); - } else if ( - typeof value === 'bigint' || - typeof value === 'number' || - typeof value === 'string' - ) { - txt = `${value}`; - } else { - txt = Txt.of(value).toString(); + // handle Uint8Array which is needed to extend Txt.of + if (ArrayBuffer.isView(value)) { + const txtValue = Txt.of(value).toString(); + if (Revision.isValid(txtValue)) { + return new Revision(txtValue); + } else { + throw new InvalidDataType('Revision.of', 'not a revision', { + value: `${value}` + }); + } } - if (Revision.isValid(txt)) { - return new Revision(txt); + // handle other types + if (Revision.isValid(value)) { + return new Revision(`${value}`); + } else { + throw new InvalidDataType('Revision.of', 'not a revision', { + value: `${value}` + }); } - throw new InvalidDataType('Revision.of', 'not a revision', { - value: `${value}` - }); } catch (e) { throw new InvalidDataType('Revision.of', 'not a revision', { value: `${value}`, @@ -94,6 +93,16 @@ class Revision extends Txt { * Return the `finalized` revision instance. */ public static readonly FINALIZED: Revision = Revision.of('finalized'); + + /** + * Return the `next` revision instance. + */ + public static readonly NEXT: Revision = Revision.of('next'); + + /** + * Return the `justified` revision instance. + */ + public static readonly JUSTIFIED: Revision = Revision.of('justified'); } export { Revision }; diff --git a/packages/core/tests/vcdm/Revision.unit.test.ts b/packages/core/tests/vcdm/Revision.unit.test.ts index 6fcc610dc..d97f5bfe0 100644 --- a/packages/core/tests/vcdm/Revision.unit.test.ts +++ b/packages/core/tests/vcdm/Revision.unit.test.ts @@ -31,7 +31,7 @@ describe('Revision class tests', () => { expect(Revision.isValid('123.57')).toBeFalsy(); }); - test('Return false for not numeric nor `best` nor `finalized` value', () => { + test('Return false for not numeric not a block tag', () => { expect(Revision.isValid('ABadBabe')).toBeFalsy(); }); @@ -54,6 +54,9 @@ describe('Revision class tests', () => { test('Return true for `finalized` value', () => { expect(Revision.isValid('finalized')).toBeTruthy(); }); + test('Return true for `next` value', () => { + expect(Revision.isValid('next')).toBeTruthy(); + }); }); }); diff --git a/packages/errors/src/available-errors/provider/provider.ts b/packages/errors/src/available-errors/provider/provider.ts index dc96e2364..1606f4111 100644 --- a/packages/errors/src/available-errors/provider/provider.ts +++ b/packages/errors/src/available-errors/provider/provider.ts @@ -118,6 +118,14 @@ class JSONRPCInternalError extends JSONRPCProviderError { } } +/** + * Invalid default block. + * + * WHEN TO USE: + * * When converting default block to vechain revision + */ +class JSONRPCInvalidDefaultBlock extends VechainSDKError {} + /** * Server error. * @@ -143,5 +151,6 @@ export { JSONRPCParseError, JSONRPCProviderError, JSONRPCServerError, - ProviderMethodError + ProviderMethodError, + JSONRPCInvalidDefaultBlock }; diff --git a/packages/network/src/provider/utils/const/blocks/blocks.ts b/packages/network/src/provider/utils/const/blocks/blocks.ts index 465a05bcc..644131438 100644 --- a/packages/network/src/provider/utils/const/blocks/blocks.ts +++ b/packages/network/src/provider/utils/const/blocks/blocks.ts @@ -1,46 +1,59 @@ -import { Hex } from '@vechain/sdk-core'; -import { type BlockQuantityInputRPC } from '../../rpc-mapper/types'; +import { HexUInt, Revision } from '@vechain/sdk-core'; +import { JSONRPCInvalidDefaultBlock } from '@vechain/sdk-errors'; + +type DefaultBlock = + | `0x${string}` + | 'latest' + | 'earliest' + | 'pending' + | 'safe' + | 'finalized'; +const defaultBlockTags: DefaultBlock[] = [ + 'latest', + 'earliest', + 'pending', + 'safe', + 'finalized' +]; /** - * Get the correct block number for the given block number. - * - * @param block - The block tag to get. - * 'latest' or 'earliest' or 'pending' or 'safe' or 'finalized' - * or an object: { blockNumber: number } or { blockHash: string } + * Maps the Ethereum "default block" type to VeChainThor Revision type. + * Ethereum "default block" can be: + * - 'latest' or 'earliest' or 'pending' or 'safe' or 'finalized' + * - a hexadecimal block number + * VeChainThor revision type can be: + * - 'best', 'next', 'justified', 'finalized' + * - a hexadecimal block Id + * - a integer block number * - * @note - * * Currently VeChainThor supports 'earliest', 'latest' and 'finalized' as block tags. - * So 'pending' and 'safe' are converted to 'best' which is the alias for 'latest' and 'finalized' in VeChainThor. + * @param defaultBlock - The Ethereum default block type to convert + * @returns The VeChainThor revision type */ -const getCorrectBlockNumberRPCToVeChain = ( - block: BlockQuantityInputRPC -): string => { - // Tag block number - if (typeof block === 'string') { - // Latest, Finalized, Safe blocks - if ( - block === 'latest' || - block === 'finalized' || - block === 'safe' || - block === 'pending' - ) - // 'best' is the alias for 'latest', 'finalized' and 'safe' in VeChainThor - return 'best'; - - // Earliest block - if (block === 'earliest') return Hex.of(0).toString(); - - // Hex number of block - return block; +const DefaultBlockToRevision = (defaultBlock: DefaultBlock): Revision => { + // if valid hex then return integer block number + if (HexUInt.isValid(defaultBlock)) { + return Revision.of(HexUInt.of(defaultBlock).n.toString()); } - - // Object with block number - if (block.blockNumber !== undefined) { - return Hex.of(block.blockNumber).toString(); + // check if default block is a valid block tag + if (!defaultBlockTags.includes(defaultBlock)) { + const defaultBlockValue = defaultBlock.toString(); + throw new JSONRPCInvalidDefaultBlock( + 'DefaultBlockToRevision', + `Invalid default block: ${defaultBlockValue}`, + defaultBlockValue, + null + ); + } + // map block tag to VeChainThor revision + if (defaultBlock === 'earliest') { + return Revision.of(HexUInt.of(0)); + } else if (defaultBlock === 'safe') { + return Revision.of('justified'); + } else if (defaultBlock === 'finalized') { + return Revision.of('finalized'); + } else { + return Revision.of('best'); } - - // Object with block hash - Default case - return block.blockHash; }; -export { getCorrectBlockNumberRPCToVeChain }; +export { type DefaultBlock, DefaultBlockToRevision }; diff --git a/packages/network/src/provider/utils/rpc-mapper/index.ts b/packages/network/src/provider/utils/rpc-mapper/index.ts index 6a3dce332..91e25752f 100644 --- a/packages/network/src/provider/utils/rpc-mapper/index.ts +++ b/packages/network/src/provider/utils/rpc-mapper/index.ts @@ -1,3 +1,2 @@ export * from './methods'; export * from './rpc-mapper'; -export type * from './types.d'; diff --git a/packages/network/src/provider/utils/rpc-mapper/methods/eth_call/eth_call.ts b/packages/network/src/provider/utils/rpc-mapper/methods/eth_call/eth_call.ts index f7e6cbf80..038004691 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods/eth_call/eth_call.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods/eth_call/eth_call.ts @@ -3,9 +3,8 @@ import { JSONRPCInvalidParams, stringifyData } from '@vechain/sdk-errors'; -import { getCorrectBlockNumberRPCToVeChain } from '../../../const'; +import { type DefaultBlock, DefaultBlockToRevision } from '../../../const'; import { type TransactionObjectInput } from './types'; -import { type BlockQuantityInputRPC } from '../../types'; import { type SimulateTransactionClause, type SimulateTransactionOptions, @@ -41,7 +40,7 @@ const ethCall = async ( try { const [inputOptions, block] = params as [ TransactionObjectInput, - BlockQuantityInputRPC + DefaultBlock ]; // Simulate transaction @@ -54,7 +53,7 @@ const ethCall = async ( } satisfies SimulateTransactionClause ], { - revision: getCorrectBlockNumberRPCToVeChain(block), + revision: DefaultBlockToRevision(block).toString(), gas: inputOptions.gas !== undefined ? parseInt(inputOptions.gas, 16) diff --git a/packages/network/src/provider/utils/rpc-mapper/methods/eth_estimateGas/eth_estimateGas.ts b/packages/network/src/provider/utils/rpc-mapper/methods/eth_estimateGas/eth_estimateGas.ts index 9fd101caf..b8133e80a 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods/eth_estimateGas/eth_estimateGas.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods/eth_estimateGas/eth_estimateGas.ts @@ -8,8 +8,7 @@ import { type SimulateTransactionClause, type ThorClient } from '../../../../../thor-client'; -import { getCorrectBlockNumberRPCToVeChain } from '../../../const'; -import { type BlockQuantityInputRPC } from '../../types'; +import { type DefaultBlock, DefaultBlockToRevision } from '../../../const'; import { RPC_DOCUMENTATION_URL } from '../../../../../utils'; /** @@ -31,7 +30,7 @@ const ethEstimateGas = async ( params: unknown[] ): Promise => { // Input validation - if (![1, 2].includes(params.length) || typeof params[0] !== 'object') + if (params.length !== 2 || typeof params[0] !== 'object') throw new JSONRPCInvalidParams( 'eth_estimateGas', `Invalid input params for "eth_estimateGas" method. See ${RPC_DOCUMENTATION_URL} for details.`, @@ -42,10 +41,11 @@ const ethEstimateGas = async ( // NOTE: The standard requires block parameter. // Here it is ignored and can be added in the future compatibility reasons. // (INPUT CHECK TAKE CARE OF THIS) - const [inputOptions, revision] = params as [ + const [inputOptions, defaultBlock] = params as [ TransactionObjectInput, - BlockQuantityInputRPC? + DefaultBlock ]; + const revision = DefaultBlockToRevision(defaultBlock); const estimatedGas = await thorClient.gas.estimateGas( [ @@ -57,10 +57,7 @@ const ethEstimateGas = async ( ], inputOptions.from, { - revision: - revision !== undefined - ? getCorrectBlockNumberRPCToVeChain(revision) - : undefined + revision: revision.toString() } ); diff --git a/packages/network/src/provider/utils/rpc-mapper/methods/eth_getBalance/eth_getBalance.ts b/packages/network/src/provider/utils/rpc-mapper/methods/eth_getBalance/eth_getBalance.ts index b8a0b5684..5cfda79bb 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods/eth_getBalance/eth_getBalance.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods/eth_getBalance/eth_getBalance.ts @@ -4,10 +4,9 @@ import { JSONRPCInvalidParams, stringifyData } from '@vechain/sdk-errors'; -import type { BlockQuantityInputRPC } from '../../types'; -import { getCorrectBlockNumberRPCToVeChain } from '../../../const'; +import { type DefaultBlock, DefaultBlockToRevision } from '../../../const'; import { RPC_DOCUMENTATION_URL } from '../../../../../utils'; -import { Address, Revision } from '@vechain/sdk-core'; +import { Address } from '@vechain/sdk-core'; /** * RPC Method eth_getBalance implementation @@ -40,13 +39,13 @@ const ethGetBalance = async ( ); try { - const [address, block] = params as [string, BlockQuantityInputRPC]; + const [address, block] = params as [string, DefaultBlock]; // Get the account details const accountDetails = await thorClient.accounts.getAccount( Address.of(address), { - revision: Revision.of(getCorrectBlockNumberRPCToVeChain(block)) + revision: DefaultBlockToRevision(block) } ); diff --git a/packages/network/src/provider/utils/rpc-mapper/methods/eth_getBlockByHash/eth_getBlockByHash.ts b/packages/network/src/provider/utils/rpc-mapper/methods/eth_getBlockByHash/eth_getBlockByHash.ts index 972aed4b1..97eadb1af 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods/eth_getBlockByHash/eth_getBlockByHash.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods/eth_getBlockByHash/eth_getBlockByHash.ts @@ -1,13 +1,13 @@ import { ThorId } from '@vechain/sdk-core'; import { RPC_DOCUMENTATION_URL } from '../../../../../utils'; -import { ethGetBlockByNumber } from '../eth_getBlockByNumber'; import { JSONRPCInternalError, JSONRPCInvalidParams, stringifyData } from '@vechain/sdk-errors'; -import { type BlocksRPC } from '../../../formatter'; +import { blocksFormatter, type BlocksRPC } from '../../../formatter'; import { type ThorClient } from '../../../../../thor-client'; +import { ethChainId } from '../eth_chainId'; /** * RPC Method eth_getBlockByHash implementation @@ -19,6 +19,7 @@ import { type ThorClient } from '../../../../../thor-client'; * * params[0]: The block hash of block to get. * * params[1]: The transaction hydrated detail flag. If true, the block will contain the transaction details, otherwise it will only contain the transaction hashes. * @returns the block at the given block hash formatted to the RPC standard or null if the block does not exist. + * @note Ethereum block hash is passed to Thor as the block id. * @throws {JSONRPCInvalidParams, JSONRPCInternalError} */ const ethGetBlockByHash = async ( @@ -39,8 +40,22 @@ const ethGetBlockByHash = async ( ); try { - // Return the block by number (in this case, the block hash is the block number) - return await ethGetBlockByNumber(thorClient, params); + const [blockHash, isTxDetail] = params as [string, boolean]; + + let chainId: string = '0x0'; + + // If the transaction detail flag is set, we need to get the chain id + if (isTxDetail) { + chainId = await ethChainId(thorClient); + } + + const block = isTxDetail + ? await thorClient.blocks.getBlockExpanded(blockHash) + : await thorClient.blocks.getBlockCompressed(blockHash); + + return block !== null + ? blocksFormatter.formatToRPCStandard(block, chainId) + : null; } catch (e) { throw new JSONRPCInternalError( 'eth_getBlockByHash()', diff --git a/packages/network/src/provider/utils/rpc-mapper/methods/eth_getBlockByNumber/eth_getBlockByNumber.ts b/packages/network/src/provider/utils/rpc-mapper/methods/eth_getBlockByNumber/eth_getBlockByNumber.ts index 01c03b9a2..04c831cc1 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods/eth_getBlockByNumber/eth_getBlockByNumber.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods/eth_getBlockByNumber/eth_getBlockByNumber.ts @@ -5,7 +5,7 @@ import { } from '@vechain/sdk-errors'; import { type ThorClient } from '../../../../../thor-client'; import { RPC_DOCUMENTATION_URL } from '../../../../../utils'; -import { getCorrectBlockNumberRPCToVeChain } from '../../../const'; +import { type DefaultBlock, DefaultBlockToRevision } from '../../../const'; import { blocksFormatter, type BlocksRPC } from '../../../formatter'; import { ethChainId } from '../eth_chainId'; @@ -42,7 +42,8 @@ const ethGetBlockByNumber = async ( ); try { - const [blockNumber, isTxDetail] = params as [string, boolean]; + const [blockNumber, isTxDetail] = params as [DefaultBlock, boolean]; + const revision = DefaultBlockToRevision(blockNumber); let chainId: string = '0x0'; @@ -52,12 +53,8 @@ const ethGetBlockByNumber = async ( } const block = isTxDetail - ? await thorClient.blocks.getBlockExpanded( - getCorrectBlockNumberRPCToVeChain(blockNumber) - ) - : await thorClient.blocks.getBlockCompressed( - getCorrectBlockNumberRPCToVeChain(blockNumber) - ); + ? await thorClient.blocks.getBlockExpanded(revision.toString()) + : await thorClient.blocks.getBlockCompressed(revision.toString()); return block !== null ? blocksFormatter.formatToRPCStandard(block, chainId) diff --git a/packages/network/src/provider/utils/rpc-mapper/methods/eth_getBlockTransactionCountByNumber/eth_getBlockTransactionCountByNumber.ts b/packages/network/src/provider/utils/rpc-mapper/methods/eth_getBlockTransactionCountByNumber/eth_getBlockTransactionCountByNumber.ts index 50749f28b..3440365a5 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods/eth_getBlockTransactionCountByNumber/eth_getBlockTransactionCountByNumber.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods/eth_getBlockTransactionCountByNumber/eth_getBlockTransactionCountByNumber.ts @@ -26,7 +26,7 @@ const ethGetBlockTransactionCountByNumber = async ( { params } ); - const block = await ethGetBlockByNumber(thorClient, [params[0], false]); + const block = await ethGetBlockByNumber(thorClient, [params[0], true]); if (block !== null) return block.transactions.length; return 0; }; diff --git a/packages/network/src/provider/utils/rpc-mapper/methods/eth_getCode/eth_getCode.ts b/packages/network/src/provider/utils/rpc-mapper/methods/eth_getCode/eth_getCode.ts index d1a55c0e7..d0d227bd2 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods/eth_getCode/eth_getCode.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods/eth_getCode/eth_getCode.ts @@ -4,10 +4,9 @@ import { JSONRPCInvalidParams, stringifyData } from '@vechain/sdk-errors'; -import type { BlockQuantityInputRPC } from '../../types'; -import { getCorrectBlockNumberRPCToVeChain } from '../../../const'; +import { type DefaultBlock, DefaultBlockToRevision } from '../../../const'; import { RPC_DOCUMENTATION_URL } from '../../../../../utils'; -import { Address, Revision } from '@vechain/sdk-core'; +import { Address } from '@vechain/sdk-core'; /** * RPC Method eth_getCode implementation @@ -40,13 +39,13 @@ const ethGetCode = async ( ); try { - const [address, block] = params as [string, BlockQuantityInputRPC]; + const [address, block] = params as [string, DefaultBlock]; // Get the account bytecode const bytecode = await thorClient.accounts.getBytecode( Address.of(address), { - revision: Revision.of(getCorrectBlockNumberRPCToVeChain(block)) + revision: DefaultBlockToRevision(block) } ); return bytecode.toString(); diff --git a/packages/network/src/provider/utils/rpc-mapper/methods/eth_getStorageAt/eth_getStorageAt.ts b/packages/network/src/provider/utils/rpc-mapper/methods/eth_getStorageAt/eth_getStorageAt.ts index 3ace9e08d..c515ea9b4 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods/eth_getStorageAt/eth_getStorageAt.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods/eth_getStorageAt/eth_getStorageAt.ts @@ -1,12 +1,11 @@ -import { Address, Revision, ThorId } from '@vechain/sdk-core'; +import { Address, ThorId } from '@vechain/sdk-core'; import { RPC_DOCUMENTATION_URL } from '../../../../../utils'; -import { getCorrectBlockNumberRPCToVeChain } from '../../../const'; +import { type DefaultBlock, DefaultBlockToRevision } from '../../../const'; import { JSONRPCInternalError, JSONRPCInvalidParams, stringifyData } from '@vechain/sdk-errors'; -import type { BlockQuantityInputRPC } from '../../types'; import { type ThorClient } from '../../../../../thor-client'; /** @@ -45,7 +44,7 @@ const ethGetStorageAt = async ( const [address, storagePosition, block] = params as [ string, string, - BlockQuantityInputRPC + DefaultBlock ]; // Get the account details @@ -53,7 +52,7 @@ const ethGetStorageAt = async ( Address.of(address), ThorId.of(storagePosition), { - revision: Revision.of(getCorrectBlockNumberRPCToVeChain(block)) + revision: DefaultBlockToRevision(block) } ); return storage.toString(); diff --git a/packages/network/src/provider/utils/rpc-mapper/methods/eth_getTransactionByHash/eth_getTransactionByHash.ts b/packages/network/src/provider/utils/rpc-mapper/methods/eth_getTransactionByHash/eth_getTransactionByHash.ts index 0ba29ec4a..c5e700ff9 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods/eth_getTransactionByHash/eth_getTransactionByHash.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods/eth_getTransactionByHash/eth_getTransactionByHash.ts @@ -8,7 +8,7 @@ import { RPC_DOCUMENTATION_URL } from '../../../../../utils'; import { type TransactionRPC, transactionsFormatter } from '../../../formatter'; import { getTransactionIndexIntoBlock } from '../../../helpers'; import { ethChainId } from '../eth_chainId'; -import { ethGetBlockByNumber } from '../eth_getBlockByNumber'; +import { ethGetBlockByHash } from '../eth_getBlockByHash'; /** * RPC Method eth_getTransactionByHash implementation @@ -42,7 +42,7 @@ const ethGetTransactionByHash = async ( if (tx === null) return null; // Get the block containing the transaction - const block = await ethGetBlockByNumber(thorClient, [ + const block = await ethGetBlockByHash(thorClient, [ tx.meta.blockID, false ]); diff --git a/packages/network/src/provider/utils/rpc-mapper/rpc-mapper.ts b/packages/network/src/provider/utils/rpc-mapper/rpc-mapper.ts index 209c0e3b2..c991b9263 100644 --- a/packages/network/src/provider/utils/rpc-mapper/rpc-mapper.ts +++ b/packages/network/src/provider/utils/rpc-mapper/rpc-mapper.ts @@ -93,7 +93,10 @@ import { web3ClientVersion, web3Sha3 } from './methods'; -import { type MethodHandlerType } from './types'; + +type MethodHandlerType = ( + params: TParams[] +) => Promise; /** * Map of RPC methods to their implementations with the SDK. diff --git a/packages/network/src/provider/utils/rpc-mapper/types.d.ts b/packages/network/src/provider/utils/rpc-mapper/types.d.ts deleted file mode 100644 index aa31e1586..000000000 --- a/packages/network/src/provider/utils/rpc-mapper/types.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Type for the method handler. - * It is basically a function that takes an array of parameters and returns a promise. - */ -type MethodHandlerType = ( - params: TParams[] -) => Promise; - -/** - * Block type for RPC methods. - * - * It can be a block hash or a block number or a string ('0x...', 'latest', 'earliest', 'pending'). - */ -type BlockQuantityInputRPC = - | string - | { blockHash: string; blockNumber: never } - | { blockHash: never; blockNumber: number }; - -export { type MethodHandlerType, type BlockQuantityInputRPC }; diff --git a/packages/network/tests/provider/rpc-mapper/methods/eth_call/eth_call.mock.solo.test.ts b/packages/network/tests/provider/rpc-mapper/methods/eth_call/eth_call.mock.solo.test.ts index 359c6024a..5d1c1ccda 100644 --- a/packages/network/tests/provider/rpc-mapper/methods/eth_call/eth_call.mock.solo.test.ts +++ b/packages/network/tests/provider/rpc-mapper/methods/eth_call/eth_call.mock.solo.test.ts @@ -10,7 +10,7 @@ import { /** * RPC Mapper integration tests for 'eth_call' method with Solo Network and mocked functionality * - * @group integration/rpc-mapper/methods/eth_call + * @group unit/rpc-mapper/methods/eth_call */ describe('RPC Mapper - eth_call method tests', () => { /** @@ -52,5 +52,37 @@ describe('RPC Mapper - eth_call method tests', () => { ]) ).rejects.toThrowError(JSONRPCInternalError); }); + /** + * Test an invalid default block tag name + */ + test('Should throw `JSONRPCInvalidParams` if the default block parameter is invalid block tag', async () => { + await expect( + RPCMethodsMap(thorClient)[RPC_METHODS.eth_call]([ + { + from: '0x7487d912d03ab9de786278f679592b3730bdd540', + to: '0x3db469a79593dcc67f07DE1869d6682fC1eaf535', + value: '1000000000000000000', + data: '0x' + }, + 'invalid' + ]) + ).rejects.toThrowError(JSONRPCInternalError); + }); + /** + * Test an invalid hexadecimal block number + */ + test('Should throw `JSONRPCInvalidParams` if the default block parameter is invalid block number hex', async () => { + await expect( + RPCMethodsMap(thorClient)[RPC_METHODS.eth_call]([ + { + from: '0x7487d912d03ab9de786278f679592b3730bdd540', + to: '0x3db469a79593dcc67f07DE1869d6682fC1eaf535', + value: '1000000000000000000', + data: '0x' + }, + '0xinvalid' + ]) + ).rejects.toThrowError(JSONRPCInternalError); + }); }); }); diff --git a/packages/network/tests/provider/rpc-mapper/methods/eth_call/fixture.ts b/packages/network/tests/provider/rpc-mapper/methods/eth_call/fixture.ts index f7432ab4d..102b15189 100644 --- a/packages/network/tests/provider/rpc-mapper/methods/eth_call/fixture.ts +++ b/packages/network/tests/provider/rpc-mapper/methods/eth_call/fixture.ts @@ -61,22 +61,8 @@ const positiveCasesFixtures = [ expected: '0x' }, { - description: 'Sends 1 VET to the receiver. (using { blockNumber: 0 } )', - input: [ - { - from: '0x7487d912d03ab9de786278f679592b3730bdd540', - to: '0x3db469a79593dcc67f07DE1869d6682fC1eaf535', - value: '1000000000000000000', - data: '0x' - }, - { - blockNumber: 0 - } - ], - expected: '0x' - }, - { - description: 'Sends 1 VET to the receiver. (using { blockHash: 0x } )', + description: + 'Sends 1 VET to the receiver. (using { blockNumber: 0x0 } )', input: [ { from: '0x7487d912d03ab9de786278f679592b3730bdd540', @@ -84,9 +70,7 @@ const positiveCasesFixtures = [ value: '1000000000000000000', data: '0x' }, - { - blockHash: Hex.of(0).toString() - } + '0x0' ], expected: '0x' }, diff --git a/packages/network/tests/provider/rpc-mapper/methods/eth_estimateGas/fixture.ts b/packages/network/tests/provider/rpc-mapper/methods/eth_estimateGas/fixture.ts index e7ca9182d..6d5bb8af9 100644 --- a/packages/network/tests/provider/rpc-mapper/methods/eth_estimateGas/fixture.ts +++ b/packages/network/tests/provider/rpc-mapper/methods/eth_estimateGas/fixture.ts @@ -30,16 +30,6 @@ const positiveCasesFixtures = [ 'latest' ], expected: '0x45015' - }, - { - description: 'Missing block reference', - input: [ - { - from: '0x37cce5c8bd6141cbe8172b277faa65af5cc83c6a', - data: '0x' - } - ], - expected: '0xcf08' } ]; @@ -61,6 +51,16 @@ const negativeCasesFixtures = [ 'latest' ], expected: JSONRPCInternalError + }, + { + description: 'Missing block reference', + input: [ + { + from: '0x37cce5c8bd6141cbe8172b277faa65af5cc83c6a', + data: '0x' + } + ], + expected: JSONRPCInvalidParams } ]; diff --git a/packages/network/tests/provider/rpc-mapper/methods/eth_getBalance/fixture.ts b/packages/network/tests/provider/rpc-mapper/methods/eth_getBalance/fixture.ts index 024322dab..5508092da 100644 --- a/packages/network/tests/provider/rpc-mapper/methods/eth_getBalance/fixture.ts +++ b/packages/network/tests/provider/rpc-mapper/methods/eth_getBalance/fixture.ts @@ -14,11 +14,6 @@ const ethGetBalanceTestCases = [ params: [THOR_SOLO_ACCOUNTS[0].address, 'latest'], expected: Quantity.of(Units.parseEther('500000000').bi).toString() }, - { - description: 'Should return correct balance of the test account', - params: [THOR_SOLO_ACCOUNTS[0].address, 'best'], - expected: Quantity.of(Units.parseEther('500000000').bi).toString() - }, { description: 'Should return correct balance of the test account before seeding', diff --git a/packages/network/tests/provider/rpc-mapper/methods/eth_getBlockByHash/fixture.ts b/packages/network/tests/provider/rpc-mapper/methods/eth_getBlockByHash/fixture.ts index f7beaf305..71c19d60d 100644 --- a/packages/network/tests/provider/rpc-mapper/methods/eth_getBlockByHash/fixture.ts +++ b/packages/network/tests/provider/rpc-mapper/methods/eth_getBlockByHash/fixture.ts @@ -37,7 +37,7 @@ const ethGetBlockByHashTestCases = [ { description: 'Should get null if block does not exist', params: [ - '0x00000000000000000000000000083d49db800000000000000000000000000000', + '0x00000000851caf3cfdb6e899cf5958bfb1ac3413d346d43539627e6be7ec1b4a', // Invalid block hash for testnet true ], expected: null, diff --git a/packages/network/tests/provider/rpc-mapper/methods/eth_getBlockTransactionCountByNumber/eth_getBlockTransactionCountByNumber.testnet.test.ts b/packages/network/tests/provider/rpc-mapper/methods/eth_getBlockTransactionCountByNumber/eth_getBlockTransactionCountByNumber.testnet.test.ts index 2bf899aed..bb17edb28 100644 --- a/packages/network/tests/provider/rpc-mapper/methods/eth_getBlockTransactionCountByNumber/eth_getBlockTransactionCountByNumber.testnet.test.ts +++ b/packages/network/tests/provider/rpc-mapper/methods/eth_getBlockTransactionCountByNumber/eth_getBlockTransactionCountByNumber.testnet.test.ts @@ -5,8 +5,7 @@ import { TESTNET_URL, ThorClient } from '../../../../../src'; -import { ethGetBlockByHashTestCases } from '../eth_getBlockByHash/fixture'; -import { invalideEthGetBlockTransactionCountByHashTestCases } from './fixture'; +import { validTestCases, invalidTestCases } from './fixture'; /** * RPC Mapper integration tests for 'eth_getBlockTransactionCountByNumber' method @@ -34,16 +33,16 @@ describe('RPC Mapper - eth_getBlockTransactionCountByNumber method tests', () => /** * eth_getBlockTransactionCountByNumber RPC method positive test cases */ - ethGetBlockByHashTestCases.forEach( - ({ description, params, expectedTransactionsLength }) => { + validTestCases.forEach( + ({ description, blockNumberHex, expectedTxCount }) => { test(description, async () => { // Call RPC function const rpcCall = await RPCMethodsMap(thorClient)[ RPC_METHODS.eth_getBlockTransactionCountByNumber - ]([params[0]]); + ]([blockNumberHex]); // Compare the result with the expected value - expect(rpcCall).toStrictEqual(expectedTransactionsLength); + expect(rpcCall).toStrictEqual(expectedTxCount); }); } ); @@ -56,18 +55,16 @@ describe('RPC Mapper - eth_getBlockTransactionCountByNumber method tests', () => /** * Invalid eth_getBlockTransactionCountByNumber RPC method test cases */ - invalideEthGetBlockTransactionCountByHashTestCases.forEach( - ({ description, params, expectedError }) => { - test(description, async () => { - // Call RPC function - await expect( - async () => - await RPCMethodsMap(thorClient)[ - RPC_METHODS.eth_getBlockTransactionCountByNumber - ](params) - ).rejects.toThrowError(expectedError); - }); - } - ); + invalidTestCases.forEach(({ description, params, expectedError }) => { + test(description, async () => { + // Call RPC function + await expect( + async () => + await RPCMethodsMap(thorClient)[ + RPC_METHODS.eth_getBlockTransactionCountByNumber + ](params) + ).rejects.toThrowError(expectedError); + }); + }); }); }); diff --git a/packages/network/tests/provider/rpc-mapper/methods/eth_getBlockTransactionCountByNumber/fixture.ts b/packages/network/tests/provider/rpc-mapper/methods/eth_getBlockTransactionCountByNumber/fixture.ts index 94958aece..f175f6b01 100644 --- a/packages/network/tests/provider/rpc-mapper/methods/eth_getBlockTransactionCountByNumber/fixture.ts +++ b/packages/network/tests/provider/rpc-mapper/methods/eth_getBlockTransactionCountByNumber/fixture.ts @@ -1,9 +1,18 @@ import { JSONRPCInvalidParams } from '@vechain/sdk-errors'; +const validTestCases = [ + { + description: + 'Should return correct transaction count for specific block number', + blockNumberHex: '0x13F6730', + expectedTxCount: 1 + } +]; + /** - * Invalid eth_getBlockByHash RPC method test cases + * Invalid eth_getBlockTransactionCountByNumber RPC method test cases */ -const invalideEthGetBlockTransactionCountByHashTestCases = [ +const invalidTestCases = [ { description: 'Should throw error when invalid params are provided', params: [], @@ -21,4 +30,4 @@ const invalideEthGetBlockTransactionCountByHashTestCases = [ } ]; -export { invalideEthGetBlockTransactionCountByHashTestCases }; +export { invalidTestCases, validTestCases }; diff --git a/packages/rpc-proxy/README.md b/packages/rpc-proxy/README.md index 411784c32..f8dd628d2 100644 --- a/packages/rpc-proxy/README.md +++ b/packages/rpc-proxy/README.md @@ -261,3 +261,28 @@ Below is the support status for JSON RPC methods in VeChain via `sdk-rpc-proxy`. - **Fully Supported**: The method is implemented and works as expected. - **Partially Supported**: The method is implemented but may have limitations or deviations from the Ethereum standard. - **Not Supported**: The method is not implemented or cannot be supported due to protocol constraints. + +## RPC to VeChain Mappings + +The following mappings are performed by the RPC proxy + +| RPC Parameter | VeChain Parameter | +|----------------------------------------|-----------------------| +| block hash | block id | +| latest block | best block | +| safe block | justified block | +| finalized block | finalized block | +| pending block | best block | +| earliest block | block number 0 | + + +## Transaction Coversions + +The method `eth_sendTransaction` requires the input to be a VeChain transaction object, not a Ethereum transaction object +This method signs the transaction using the configured PK, before passing it on to VeChain Thor + +For method `eth_sendRawTransaction` the signed encoded raw transaction parameter must be a vechain transaction object +This method cannot convert a signed Ethereum transaction to a signed VeChain transaction + + + diff --git a/packages/rpc-proxy/tests/e2e_rpc_proxy.solo.test.ts b/packages/rpc-proxy/tests/e2e_rpc_proxy.solo.test.ts index 4ec540ee4..92999a797 100644 --- a/packages/rpc-proxy/tests/e2e_rpc_proxy.solo.test.ts +++ b/packages/rpc-proxy/tests/e2e_rpc_proxy.solo.test.ts @@ -292,9 +292,7 @@ describe('RPC Proxy endpoints', () => { const response = await axios.post(RPC_PROXY_URL, { jsonrpc: '2.0', method: 'eth_getBlockReceipts', - params: [ - '0x0000000008602e7a995c747a3215b426c0c65709480b9e9ac57ad37c3f7d73de' - ], + params: ['0x0'], id: 1 }); From f44714c3be264f594c495617ec693444dfa7e8d4 Mon Sep 17 00:00:00 2001 From: Luca Nicola Debiasi <63785793+lucanicoladebiasi@users.noreply.github.com> Date: Thu, 13 Feb 2025 08:34:02 +0000 Subject: [PATCH 2/2] 1658 bnc part 3 (#1798) * fix: fix BNC... * fix: fix BNC... * fix: fix BNC... * fix: fix BNC... * fix: fix BNC... * fix: fix BNC... * fix: en_7 recommendations... (#1749) * fix: fr9 recommendations * fix: en_1 recommendations * fix: en_1 recommendations * fix: en_2 recommendations... * fix: en_2 recommendations... * fix: en_7 recommendations... * fix: en_7 recommendations... * fix: n_7 recommandations * fix: n_7 recommandations * Merge branch 'main' into 1656-fr9 * Merge branch '1661-en_2' into 1662-en_7 * fix: EN_7 * fix: EN_7 * fix: EN_7 --------- Co-authored-by: Fabio Rigamonti <73019897+fabiorigam@users.noreply.github.com> (cherry picked from commit f52a556c83f3488e279df4746ee2aed164dd6ef1) * fix: BNC (network) * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * fix: BNC 2 network * Update packages/rpc-proxy/src/utils/config-validator/config-validator.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Luca Nicola Debiasi <63785793+lucanicoladebiasi@users.noreply.github.com> * Update packages/rpc-proxy/src/utils/config-validator/config-validator.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Luca Nicola Debiasi <63785793+lucanicoladebiasi@users.noreply.github.com> * fix: BNC 2 network * fix: `BNC` part 2 - network refactor * fix: `BNC` part 2 - network refactor * fix: `BNC` part 2 - network refactor * fix: `BNC` part 2 - network refactor * fix: `BNC` part 3 - rpc-proxy refactor * fix: `BNC` part 3 - rpc-proxy refactor * fix: `BNC` part 3 - rpc-proxy refactor * fix: `BNC` part 3 - rpc-proxy refactor * fix: `BNC` part 3 - rpc-proxy refactor * fix: `BNC` part 2 - openssl fix * fix: `BNC` part 2 - openssl fix * fix: `BNC` part 2 - rpc-proxy README.md amended --------- Signed-off-by: Luca Nicola Debiasi <63785793+lucanicoladebiasi@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../sdk-hardhat-integration/hardhat.config.ts | 5 +- .../hardhat-plugin/tests/helpers/fixture.ts | 15 +++--- packages/rpc-proxy/README.md | 20 ++++---- .../args-validator-and-getter.ts | 30 ++++++------ .../utils/args-validator/args-validator.ts | 47 ++++++++++--------- .../rpc-proxy/src/utils/args/args-options.ts | 17 ++++--- .../rpc-proxy/src/utils/args/args-parser.ts | 4 +- .../rpc-proxy/src/utils/args/env-to-args.ts | 12 +++-- .../config-validator/config-validator.ts | 12 ++--- .../src/utils/validators/validators.ts | 8 ++-- ...ct-proxy-config-gas-payer-private-key.json | 2 +- .../correct-proxy-config-gas-payer-url.json | 2 +- packages/rpc-proxy/tests/fixture.ts | 2 +- .../utils/args/args-options.unit.test.ts | 23 +++++---- .../tests/utils/args/args-parser.unit.test.ts | 43 +++++++++-------- .../env-to-args-positive-cases.unit.test.ts | 8 ++-- .../config-validator.unit.test.ts | 2 +- 17 files changed, 138 insertions(+), 114 deletions(-) diff --git a/apps/sdk-hardhat-integration/hardhat.config.ts b/apps/sdk-hardhat-integration/hardhat.config.ts index dc4ab723d..b762f5bce 100644 --- a/apps/sdk-hardhat-integration/hardhat.config.ts +++ b/apps/sdk-hardhat-integration/hardhat.config.ts @@ -89,7 +89,8 @@ const config: HardhatUserConfig = { }, debug: true, gasPayer: { - delegatorUrl: 'https://sponsor-testnet.vechain.energy/by/269' + gasPayerServiceUrl: + 'https://sponsor-testnet.vechain.energy/by/269' }, enableDelegation: true, gas: 'auto', @@ -115,7 +116,7 @@ const config: HardhatUserConfig = { }, debug: true, gasPayer: { - delegatorPrivateKey: + gasPayerPrivateKey: 'ea5383ac1f9e625220039a4afac6a7f868bf1ad4f48ce3a1dd78bd214ee4ace5' }, enableDelegation: true, diff --git a/packages/hardhat-plugin/tests/helpers/fixture.ts b/packages/hardhat-plugin/tests/helpers/fixture.ts index 1f94e86c1..715f42e78 100644 --- a/packages/hardhat-plugin/tests/helpers/fixture.ts +++ b/packages/hardhat-plugin/tests/helpers/fixture.ts @@ -38,9 +38,10 @@ const createWalletFromHardhatNetworkConfigPositiveCasesFixture = [ '7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa157' ], delegator: { - delegatorPrivateKey: + gasPayerPrivateKey: 'ea5383ac1f9e625220039a4afac6a7f868bf1ad4f48ce3a1dd78bd214ee4ace5', - delegatorUrl: 'https://sponsor-testnet.vechain.energy/by/269' + gasPayerServiceUrl: + 'https://sponsor-testnet.vechain.energy/by/269' } }, expectedAddresses: [ @@ -73,9 +74,10 @@ const createWalletFromHardhatNetworkConfigPositiveCasesFixture = [ '0x7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa157' ], delegator: { - delegatorPrivateKey: + gasPayerPrivateKey: 'ea5383ac1f9e625220039a4afac6a7f868bf1ad4f48ce3a1dd78bd214ee4ace5', - delegatorUrl: 'https://sponsor-testnet.vechain.energy/by/269' + gasPayerServiceUrl: + 'https://sponsor-testnet.vechain.energy/by/269' } }, expectedAddresses: [ @@ -114,9 +116,10 @@ const createWalletFromHardhatNetworkConfigPositiveCasesFixture = [ initialIndex: 0 }, delegator: { - delegatorPrivateKey: + gasPayerPrivateKey: 'ea5383ac1f9e625220039a4afac6a7f868bf1ad4f48ce3a1dd78bd214ee4ace5', - delegatorUrl: 'https://sponsor-testnet.vechain.energy/by/269' + gasPayerServiceUrl: + 'https://sponsor-testnet.vechain.energy/by/269' } }, expectedAddresses: [ diff --git a/packages/rpc-proxy/README.md b/packages/rpc-proxy/README.md index f8dd628d2..2c202c67f 100644 --- a/packages/rpc-proxy/README.md +++ b/packages/rpc-proxy/README.md @@ -88,14 +88,14 @@ So you can run the rpc-proxy with: #### Use delegation - `-e, --enableDelegation`: Whether to enable delegation. -- `--delegatorPrivateKey `: The private key of the delegator. -- `-d, --delegatorUrl `: The URL of the delegator. - - -e.g.- `npx rpc-proxy -e --delegatorPrivateKey 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158` - OR `npx rpc-proxy --enableDelegation --delegatorPrivateKey 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158` - - -e.g.- `npx rpc-proxy -e -d https://sponsor-testnet.vechain.energy/by/...` - OR `npx rpc-proxy --enableDelegation --delegatorUrl https://sponsor-testnet.vechain.energy/by/...` - - **NOTE**: --delegatorPrivateKey and --delegatorUrl are mutually exclusive. - - **NOTE**: if --enableDelegation is used, --delegatorPrivateKey OR --delegatorUrl MUST be used. +- `--gasPayerPrivateKey `: The private key of the gasPayer. +- `-s, --gasPayerServiceUrl `: The URL of the gasPayer. + - -e.g.- `npx rpc-proxy -e --gasPayerPrivateKey 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158` + OR `npx rpc-proxy --enableDelegation --gasPayerPrivateKey 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158` + - -e.g.- `npx rpc-proxy -e -s https://sponsor-testnet.vechain.energy/by/...` + OR `npx rpc-proxy --enableDelegation --gasPayerServiceUrl https://sponsor-testnet.vechain.energy/by/...` + - **NOTE**: --gasPayerPrivateKey and --gasPayerServiceUrl are mutually exclusive. + - **NOTE**: if --enableDelegation is used, --gasPayerPrivateKey OR --gasPayerServiceUrl MUST be used. ## Configuration file @@ -153,7 +153,7 @@ Simple testnet configuration with a gasPayer private key: "initialIndex": 0 }, "gasPayer": { - "delegatorPrivateKey": "8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158" + "gasPayerPrivateKey": "8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158" }, "enableDelegation": true } @@ -171,7 +171,7 @@ Simple testnet configuration with a gasPayer private url: "initialIndex": 0 }, "gasPayer": { - "delegatorUrl": "https://sponsor-testnet.vechain.energy/by/..." + "gasPayerServiceUrl": "https://sponsor-testnet.vechain.energy/by/..." }, "enableDelegation": true } diff --git a/packages/rpc-proxy/src/utils/args-validator/args-validator-and-getter.ts b/packages/rpc-proxy/src/utils/args-validator/args-validator-and-getter.ts index d49b68e64..c6a1e9dc5 100644 --- a/packages/rpc-proxy/src/utils/args-validator/args-validator-and-getter.ts +++ b/packages/rpc-proxy/src/utils/args-validator/args-validator-and-getter.ts @@ -145,31 +145,31 @@ const ArgsValidatorAndGetter = { ): Config => { // Both delegation fields are provided - throw an error if ( - options.delegatorPrivateKey !== undefined && - options.delegatorUrl !== undefined && - options.delegatorPrivateKey !== null && - options.delegatorUrl !== null + options.gasPayerPrivateKey !== undefined && + options.gasPayerServiceUrl !== undefined && + options.gasPayerPrivateKey !== null && + options.gasPayerServiceUrl !== null ) { throw new InvalidCommandLineArguments( 'ArgsValidatorAndGetter.delegation()', - 'Both gasPayer private key and gasPayer URL are provided. Only one can be provided', + 'Both gasPayer private key and gasPayer service URL are provided. Only one can be provided', { - flag: '{--delegatorPrivateKey}, {-d , --delegatorUrl}', - value: `{value not provided for security reason} , {${options.delegatorUrl as string}}` + flag: '{--gasPayerPrivateKey}, {-s , --gasPayerServiceUrl}', + value: `{value not provided for security reason} , {${options.gasPayerServiceUrl as string}}` } ); } // Delegation is made with a private key if ( - options.delegatorPrivateKey !== undefined && - options.delegatorPrivateKey !== null + options.gasPayerPrivateKey !== undefined && + options.gasPayerPrivateKey !== null ) { return { ...currentConfiguration, gasPayer: { - gasPayerPrivateKey: ArgsValidator.delegatorPrivateKey( - options.delegatorPrivateKey as string + gasPayerPrivateKey: ArgsValidator.gasPayerPrivateKey( + options.gasPayerPrivateKey as string ) } }; @@ -177,14 +177,14 @@ const ArgsValidatorAndGetter = { // Delegation is made with a gasPayer URL if ( - options.delegatorUrl !== undefined && - options.delegatorUrl !== null + options.gasPayerServiceUrl !== undefined && + options.gasPayerServiceUrl !== null ) { return { ...currentConfiguration, gasPayer: { - gasPayerServiceUrl: ArgsValidator.delegatorUrl( - options.delegatorUrl as string + gasPayerServiceUrl: ArgsValidator.gasPayerServiceUrl( + options.gasPayerServiceUrl as string ) } }; diff --git a/packages/rpc-proxy/src/utils/args-validator/args-validator.ts b/packages/rpc-proxy/src/utils/args-validator/args-validator.ts index e4a500b15..b09ba5bc9 100644 --- a/packages/rpc-proxy/src/utils/args-validator/args-validator.ts +++ b/packages/rpc-proxy/src/utils/args-validator/args-validator.ts @@ -3,8 +3,8 @@ import { checkValidConfigurationFile } from '../config-validator'; import { isValidAccountsAsListOfPrivateKeys, isValidCount, - isValidDelegatorPrivateKey, - isValidDelegatorUrl, + isValidGasPayerPrivateKey, + isValidGasPayerServiceUrl, isValidMnemonic, isValidPort, isValidUrl @@ -252,54 +252,57 @@ const ArgsValidator = { /** * Delegate configuration - * Validate 'delegatorPrivateKey' configuration field. + * Validate 'gasPayerPrivateKey' configuration field. * - * @param delegatorPrivateKey Delegator private key to validate - * @returns Delegator private key if provided AND valid, null otherwise + * @param gasPayerPrivateKey The gasPayer private key to validate + * @returns The gasPayer private key if provided AND valid, null otherwise */ - delegatorPrivateKey: (delegatorPrivateKey: string): string => { + gasPayerPrivateKey: (gasPayerPrivateKey: string): string => { if ( - !isValidDelegatorPrivateKey(delegatorPrivateKey) || - delegatorPrivateKey === '' + !isValidGasPayerPrivateKey(gasPayerPrivateKey) || + gasPayerPrivateKey === '' ) { throw new InvalidCommandLineArguments( - 'ArgsValidator.delegatorPrivateKey()', + 'ArgsValidator.gasPayerPrivateKey()', 'An invalid gasPayer private key provided.', { - flag: '--delegatorPrivateKey', + flag: '--gasPayerPrivateKey', value: 'Value will not be shown for security reasons' } ); } console.log( - `[rpc-proxy]: Delegator private key provided with command line options` + `[rpc-proxy]: The gasPayer private key provided with command line options` ); - return delegatorPrivateKey; + return gasPayerPrivateKey; }, /* - * Validate 'delgatorUrl' configuration field + * Validate 'gasPayerServiceUrl' configuration field * - * @param delegatorUrl Delegator URL to validate - * @returns Delegator URL if provided AND valid, null otherwise + * @param gasPayerServiceUrl The gasPayer service URL to validate + * @returns The gasPayer service URL if provided AND valid, null otherwise */ - delegatorUrl: (delegatorUrl: string): string => { - if (!isValidDelegatorUrl(delegatorUrl) || delegatorUrl === '') { + gasPayerServiceUrl: (gasPayerServiceUrl: string): string => { + if ( + !isValidGasPayerServiceUrl(gasPayerServiceUrl) || + gasPayerServiceUrl === '' + ) { throw new InvalidCommandLineArguments( - 'ArgsValidator.delegatorUrl()', + 'ArgsValidator.gasPayerServiceUrl()', 'Invalid gasPayer url provided. The parameter must be a valid url', { - flag: '-d , --delegatorUrl', - value: delegatorUrl + flag: '-s , --gasPayerServiceUrl', + value: gasPayerServiceUrl } ); } console.log( - `[rpc-proxy]: Delegator url provided with command line options: ${delegatorUrl}` + `[rpc-proxy]: The gasPayer service url provided with command line options: ${gasPayerServiceUrl}` ); - return delegatorUrl; + return gasPayerServiceUrl; } }; diff --git a/packages/rpc-proxy/src/utils/args/args-options.ts b/packages/rpc-proxy/src/utils/args/args-options.ts index a8418ffdf..0b9a3b148 100644 --- a/packages/rpc-proxy/src/utils/args/args-options.ts +++ b/packages/rpc-proxy/src/utils/args/args-options.ts @@ -15,8 +15,8 @@ import { Command, Option, type OptionValues } from 'commander'; * rpc-proxy {--mnemonicInitialIndex} - Initial index to start deriving accounts from the mnemonic * * rpc-proxy {-e|--enableDelegation} - Enable delegation - * rpc-proxy {--delegatorPrivateKey} - Delegator private key - * rpc-proxy {-d|--delegatorUrl} - Delegator URL + * rpc-proxy {--gasPayerPrivateKey} - The gasPayer private key + * rpc-proxy {-s|--gasPayerServiceUrl} - The gasPayer service URL * * rpc-proxy {-v|--verbose} - Enable verbose logging * @@ -77,17 +77,20 @@ function getOptionsFromCommandLine( // Enable delegation boolean .addOption(new Option('-e, --enableDelegation', 'Enable delegation')) - // Delegator configuration (private key) + // The gasPayer configuration (private key) .addOption( new Option( - '--delegatorPrivateKey ', - 'Delegator private key' + '--gasPayerPrivateKey ', + 'The gasPayer private key' ) ) - // Delegator configuration (url) + // The gasPayer configuration (url) .addOption( - new Option('-d, --delegatorUrl ', 'Delegator URL') + new Option( + '-s, --gasPayerServiceUrl ', + 'The gasPayer service URL' + ) ) // Enable verbose logging diff --git a/packages/rpc-proxy/src/utils/args/args-parser.ts b/packages/rpc-proxy/src/utils/args/args-parser.ts index 6b6b2c1c7..ae9f747c4 100644 --- a/packages/rpc-proxy/src/utils/args/args-parser.ts +++ b/packages/rpc-proxy/src/utils/args/args-parser.ts @@ -86,9 +86,9 @@ function parseAndGetFinalConfig( ) { throw new InvalidCommandLineArguments( '_checkIfConfigurationFileHasCorrectStructure()', - `Invalid configuration: Delegation cannot be enabled without a delegator`, + `Invalid configuration: Delegation cannot be enabled without a gasPayer`, { - flag: '--enableDelegation , --delegatorPrivateKey, --delegatorUrl', + flag: '--enableDelegation , --gasPayerPrivateKey, --gasPayerServiceUrl', value: `${options.enableDelegation}, Not provided, Not provided` } ); diff --git a/packages/rpc-proxy/src/utils/args/env-to-args.ts b/packages/rpc-proxy/src/utils/args/env-to-args.ts index ef4b6bc12..0b3d868f1 100644 --- a/packages/rpc-proxy/src/utils/args/env-to-args.ts +++ b/packages/rpc-proxy/src/utils/args/env-to-args.ts @@ -49,11 +49,15 @@ function getArgsFromEnv(): string[] { 'ENABLE_DELEGATION' ), getCliFieldFromEnv( - '--delegatorPrivateKey', - process.env.DELEGATOR_PRIVATE_KEY, - 'DELEGATOR_PRIVATE_KEY' + '--gasPayerPrivateKey', + process.env.GAS_PAYER_PRIVATE_KEY, + 'GAS_PAYER_PRIVATE_KEY' + ), + getCliFieldFromEnv( + '-s', + process.env.GAS_PAYER_SERVICE_URL, + 'GAS_PAYER_SERVICE_URL' ), - getCliFieldFromEnv('-d', process.env.DELEGATOR_URL, 'DELEGATOR_URL'), getCliFieldFromEnv('-v', process.env.VERBOSE, 'VERBOSE'), getCliFieldFromEnv( '-c', diff --git a/packages/rpc-proxy/src/utils/config-validator/config-validator.ts b/packages/rpc-proxy/src/utils/config-validator/config-validator.ts index 0929fb3ad..974f01008 100644 --- a/packages/rpc-proxy/src/utils/config-validator/config-validator.ts +++ b/packages/rpc-proxy/src/utils/config-validator/config-validator.ts @@ -8,8 +8,8 @@ import type { Config } from '../../types'; import { isValidAccountsAsListOfPrivateKeys, isValidAccountsAsMnemonic, - isValidDelegatorPrivateKey, - isValidDelegatorUrl, + isValidGasPayerPrivateKey, + isValidGasPayerServiceUrl, isValidPort, isValidUrl } from '../validators'; @@ -138,11 +138,11 @@ function _checkIfConfigurationFileHasCorrectStructure(filePath: string): void { // Invalid gasPayer private key if ( configFile.gasPayer.gasPayerPrivateKey !== undefined && - !isValidDelegatorPrivateKey(configFile.gasPayer.gasPayerPrivateKey) + !isValidGasPayerPrivateKey(configFile.gasPayer.gasPayerPrivateKey) ) { throw new InvalidConfigurationFile( '_checkIfConfigurationFileHasCorrectStructure()', - `Invalid delegator private key in configuration file: ${absolutePath}. Delegator private key must be a valid private key`, + `Invalid gasPayer private key in configuration file: ${absolutePath}. The gasPayer private key must be a valid private key`, { filePath } @@ -152,11 +152,11 @@ function _checkIfConfigurationFileHasCorrectStructure(filePath: string): void { // Invalid gasPayer url if ( configFile.gasPayer.gasPayerServiceUrl !== undefined && - !isValidDelegatorUrl(configFile.gasPayer.gasPayerServiceUrl) + !isValidGasPayerServiceUrl(configFile.gasPayer.gasPayerServiceUrl) ) { throw new InvalidConfigurationFile( '_checkIfConfigurationFileHasCorrectStructure()', - `Invalid delegator url in configuration file: ${absolutePath}. Delegator url must be a valid URL`, + `Invalid gasPayer service url in configuration file: ${absolutePath}. DThe gasPayer service url must be a valid URL`, { filePath } diff --git a/packages/rpc-proxy/src/utils/validators/validators.ts b/packages/rpc-proxy/src/utils/validators/validators.ts index fcb7a5cb7..bfbeafa8b 100644 --- a/packages/rpc-proxy/src/utils/validators/validators.ts +++ b/packages/rpc-proxy/src/utils/validators/validators.ts @@ -91,7 +91,7 @@ function isValidAccountsAsMnemonic(account: { * @param url - URL to check * @returns True if the url is valid, false otherwise */ -function isValidDelegatorUrl(url: string): boolean { +function isValidGasPayerServiceUrl(url: string): boolean { return isValidUrl(url); } @@ -100,7 +100,7 @@ function isValidDelegatorUrl(url: string): boolean { * @param privateKey - Private key to check * @returns True if the private key is valid, false otherwise */ -function isValidDelegatorPrivateKey(privateKey: string): boolean { +function isValidGasPayerPrivateKey(privateKey: string): boolean { return isValidAccountsAsListOfPrivateKeys([privateKey]); } @@ -112,6 +112,6 @@ export { isValidCount, isValidInitialIndex, isValidAccountsAsMnemonic, - isValidDelegatorUrl, - isValidDelegatorPrivateKey + isValidGasPayerServiceUrl, + isValidGasPayerPrivateKey }; diff --git a/packages/rpc-proxy/tests/config-files-fixtures/correct-proxy-config-gas-payer-private-key.json b/packages/rpc-proxy/tests/config-files-fixtures/correct-proxy-config-gas-payer-private-key.json index 906ffa786..201bb834c 100644 --- a/packages/rpc-proxy/tests/config-files-fixtures/correct-proxy-config-gas-payer-private-key.json +++ b/packages/rpc-proxy/tests/config-files-fixtures/correct-proxy-config-gas-payer-private-key.json @@ -7,7 +7,7 @@ "initialIndex": 0 }, "gasPayer": { - "delegatorPrivateKey": "8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158" + "gasPayerPrivateKey": "8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158" }, "enableDelegation": false } diff --git a/packages/rpc-proxy/tests/config-files-fixtures/correct-proxy-config-gas-payer-url.json b/packages/rpc-proxy/tests/config-files-fixtures/correct-proxy-config-gas-payer-url.json index aaacb8706..23235098d 100644 --- a/packages/rpc-proxy/tests/config-files-fixtures/correct-proxy-config-gas-payer-url.json +++ b/packages/rpc-proxy/tests/config-files-fixtures/correct-proxy-config-gas-payer-url.json @@ -7,7 +7,7 @@ "initialIndex": 0 }, "gasPayer": { - "delegatorUrl": "https://testnet.vechain.org" + "gasPayerServiceUrl": "https://testnet.vechain.org" }, "enableDelegation": false } diff --git a/packages/rpc-proxy/tests/fixture.ts b/packages/rpc-proxy/tests/fixture.ts index e8e1d6e68..9ea13c858 100644 --- a/packages/rpc-proxy/tests/fixture.ts +++ b/packages/rpc-proxy/tests/fixture.ts @@ -81,7 +81,7 @@ const invalidParametersConfigurationFilePathFixture = { 'invalid-accounts-mnemonics-proxy-config-5.json' ) ], - 'invalid-delegator': [ + 'invalid-gasPayer': [ path.join( _configFilesDirectory, 'invalid-gas-payer-proxy-config-1.json' diff --git a/packages/rpc-proxy/tests/utils/args/args-options.unit.test.ts b/packages/rpc-proxy/tests/utils/args/args-options.unit.test.ts index c06f943d5..85f2fe581 100644 --- a/packages/rpc-proxy/tests/utils/args/args-options.unit.test.ts +++ b/packages/rpc-proxy/tests/utils/args/args-options.unit.test.ts @@ -159,17 +159,17 @@ describe('Args options tests', () => { [ 'path', 'program', - '--delegatorPrivateKey', + '--gasPayerPrivateKey', '8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158' ] ].forEach((args) => { - const delegatorPrivateKeyOption = getOptionsFromCommandLine( + const gasPayerPrivateKeyOption = getOptionsFromCommandLine( '1.0.0', args ); - expect(delegatorPrivateKeyOption).toBeDefined(); - expect(delegatorPrivateKeyOption.delegatorPrivateKey).toBe( + expect(gasPayerPrivateKeyOption).toBeDefined(); + expect(gasPayerPrivateKeyOption.gasPayerPrivateKey).toBe( '8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158' ); }); @@ -181,17 +181,22 @@ describe('Args options tests', () => { test('Should be able to parse the gasPayer URL option', () => { [ // Normal syntax - ['path', 'program', '--delegatorUrl', 'http://localhost:8080'], + [ + 'path', + 'program', + '--gasPayerServiceUrl', + 'http://localhost:8080' + ], // Short syntax - ['path', 'program', '-d', 'http://localhost:8080'] + ['path', 'program', '-s', 'http://localhost:8080'] ].forEach((args) => { - const delegatorUrlOption = getOptionsFromCommandLine( + const gasPayerServiceUrlOption = getOptionsFromCommandLine( '1.0.0', args ); - expect(delegatorUrlOption).toBeDefined(); - expect(delegatorUrlOption.delegatorUrl).toBe( + expect(gasPayerServiceUrlOption).toBeDefined(); + expect(gasPayerServiceUrlOption.gasPayerServiceUrl).toBe( 'http://localhost:8080' ); }); diff --git a/packages/rpc-proxy/tests/utils/args/args-parser.unit.test.ts b/packages/rpc-proxy/tests/utils/args/args-parser.unit.test.ts index 501721aad..592d9a23b 100644 --- a/packages/rpc-proxy/tests/utils/args/args-parser.unit.test.ts +++ b/packages/rpc-proxy/tests/utils/args/args-parser.unit.test.ts @@ -195,7 +195,7 @@ describe('Args parser tests', () => { 'path', 'program', '--enableDelegation', - '--delegatorPrivateKey', + '--gasPayerPrivateKey', '8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158' ], // Short syntax @@ -203,7 +203,7 @@ describe('Args parser tests', () => { 'path', 'program', '-e', - '--delegatorPrivateKey', + '--gasPayerPrivateKey', '8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158' ] ].forEach((args) => { @@ -220,26 +220,31 @@ describe('Args parser tests', () => { }); /** - * Should be able to delegation options from command line arguments (delegatorPrivateKey and delegatorUrl fields) AND get the configuration + * Should be able to delegation options from command line arguments (gasPayerPrivateKey and gasPayerServiceUrl fields) AND get the configuration */ test('Should be able to get the delegation options from command line arguments AND get the configuration', () => { [ - // Delegator private key + // The gasPayer private key // Normal syntax [ 'path', 'program', - '--delegatorPrivateKey', + '--gasPayerPrivateKey', '8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158' ], - // Delegator URL + // The gasPayer service URL // Normal syntax - ['path', 'program', '--delegatorUrl', 'http://localhost:8080'], + [ + 'path', + 'program', + '--gasPayerServiceUrl', + 'http://localhost:8080' + ], // Short syntax - ['path', 'program', '-d', 'http://localhost:8080'] + ['path', 'program', '-s', 'http://localhost:8080'] ].forEach((args) => { // Get options const options = getOptionsFromCommandLine('1.0.0', args); @@ -582,7 +587,7 @@ describe('Args parser tests', () => { }); /** - * Should NOT be able to parse delegation options from command line arguments (delegatorPrivateKey and delegatorUrl fields) AND get the configuration + * Should NOT be able to parse delegation options from command line arguments (gasPayerPrivateKey and gasPayerServiceUrl fields) AND get the configuration */ test('Should be NOT able to parse delegation options from command line arguments AND get the configuration', () => { [ @@ -592,40 +597,40 @@ describe('Args parser tests', () => { [ 'path', 'program', - '--delegatorPrivateKey', + '--gasPayerPrivateKey', '8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158', - '--delegatorUrl', + '--gasPayerServiceUrl', 'http://localhost:8080' ], // Short syntax [ 'path', 'program', - '--delegatorPrivateKey', + '--gasPayerPrivateKey', '8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158', - '-d', + '-s', 'http://localhost:8080' ], // Invalid fields // Normal syntax - ['path', 'program', '--delegatorPrivateKey', 'INVALID'], + ['path', 'program', '--gasPayerPrivateKey', 'INVALID'], // Normal syntax - ['path', 'program', '--delegatorUrl', 'INVALID'], + ['path', 'program', '--gasPayerServiceUrl', 'INVALID'], // Short syntax - ['path', 'program', '-d', 'INVALID'], + ['path', 'program', '-s', 'INVALID'], // Empty fields // Normal syntax - ['path', 'program', '--delegatorPrivateKey', ''], + ['path', 'program', '--gasPayerPrivateKey', ''], // Normal syntax - ['path', 'program', '--delegatorUrl', ''], + ['path', 'program', '--gasPayerServiceUrl', ''], // Short syntax - ['path', 'program', '-d', ''], + ['path', 'program', '-s', ''], // Enable delegation without the gasPayer diff --git a/packages/rpc-proxy/tests/utils/args/env-to-args-positive-cases.unit.test.ts b/packages/rpc-proxy/tests/utils/args/env-to-args-positive-cases.unit.test.ts index b0419b38a..86da520ca 100644 --- a/packages/rpc-proxy/tests/utils/args/env-to-args-positive-cases.unit.test.ts +++ b/packages/rpc-proxy/tests/utils/args/env-to-args-positive-cases.unit.test.ts @@ -17,8 +17,8 @@ describe('Environment variables to command line arguments positive cases', () => process.env.MNEMONIC_COUNT = '10'; process.env.MNEMONIC_INITIAL_INDEX = '0'; process.env.ENABLE_DELEGATION = 'true'; - process.env.DELEGATOR_PRIVATE_KEY = '0x1234567890abcdef'; - process.env.DELEGATOR_URL = 'http://localhost:8669'; + process.env.GAS_PAYER_PRIVATE_KEY = '0x1234567890abcdef'; + process.env.GAS_PAYER_SERVICE_URL = 'http://localhost:8669'; process.env.VERBOSE = 'true'; process.env.CONFIGURATION_FILE = 'config.json'; }); @@ -50,9 +50,9 @@ describe('Environment variables to command line arguments positive cases', () => '0', '-e', 'true', - '--delegatorPrivateKey', + '--gasPayerPrivateKey', '0x1234567890abcdef', - '-d', + '-s', 'http://localhost:8669', '-v', 'true', diff --git a/packages/rpc-proxy/tests/utils/config-validator/config-validator.unit.test.ts b/packages/rpc-proxy/tests/utils/config-validator/config-validator.unit.test.ts index 88734ce35..0499c3884 100644 --- a/packages/rpc-proxy/tests/utils/config-validator/config-validator.unit.test.ts +++ b/packages/rpc-proxy/tests/utils/config-validator/config-validator.unit.test.ts @@ -123,7 +123,7 @@ describe('Configuration file validator', () => { */ test('Should not be able to parse a configuration file with invalid gasPayer', () => { invalidParametersConfigurationFilePathFixture[ - 'invalid-delegator' + 'invalid-gasPayer' ].forEach((filePath) => { console.log(filePath); expect(() => {