From 021a5c911638b1d19e56414cdfc56e17b072dad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolfo=20Pietro=20Calabr=C3=B2?= <33911400+rodolfopietro97@users.noreply.github.com> Date: Fri, 31 May 2024 14:08:47 +0200 Subject: [PATCH] fix: switch json.stringify function (#931) * fix: switch json.stringify function * fix: solved WS issue --- .../sdk-hardhat-integration/scripts/deploy.ts | 3 +- .../scripts/temp_test_ethers.ts | 37 ------------------- docs/contracts.md | 2 +- docs/encoding.md | 2 +- .../contracts/contract-function-call.ts | 3 +- docs/examples/encoding/contract.ts | 3 +- docs/examples/encoding/rlp.ts | 3 +- docs/examples/evm-extension/evm-extension.ts | 9 +++-- docs/examples/transactions/simulation.ts | 3 +- packages/core/src/contract/coder.ts | 9 ++++- .../keystore/cryptography/ethers/keystore.ts | 11 ++++-- .../cryptography/experimental/keystore.ts | 4 +- packages/core/src/utils/const/abi.ts | 8 ++-- packages/core/tests/abi/abi.unit.test.ts | 7 ++-- packages/core/tests/abi/fixture.ts | 11 ++++-- packages/core/tests/bloom/bloom.unit.test.ts | 10 +++-- .../core/tests/keystore/keystore.unit.test.ts | 7 ++-- packages/core/tests/rlp/helpers.unit.test.ts | 28 +++++++------- .../transaction-assertions.unit.test.ts | 9 +++-- .../core/tests/utils/data/data.unit.test.ts | 11 +++--- .../network/solo-seeding/thor-solo-seeding.ts | 3 +- .../hardhat-provider/hardhat-provider.ts | 14 ++++--- .../debug_traceCall/debug_traceCall.ts | 24 +++++++----- .../debug_traceTransaction.ts | 24 +++++++----- .../eth_blockNumber/eth_blockNumber.ts | 8 +++- .../methods-map/methods/eth_call/eth_call.ts | 12 ++++-- .../methods/eth_chainId/eth_chainId.ts | 16 ++++++-- .../eth_estimateGas/eth_estimateGas.ts | 12 ++++-- .../methods/eth_getBalance/eth_getBalance.ts | 12 ++++-- .../eth_getBlockByHash/eth_getBlockByHash.ts | 12 ++++-- .../eth_getBlockByNumber.ts | 16 +++++--- .../methods/eth_getCode/eth_getCode.ts | 12 ++++-- .../methods/eth_getLogs/eth_getLogs.ts | 14 +++++-- .../eth_getStorageAt/eth_getStorageAt.ts | 12 ++++-- .../eth_getTransactionByHash.ts | 12 ++++-- .../eth_getTransactionReceipt.ts | 12 ++++-- .../eth_sendRawTransaction.ts | 12 ++++-- .../eth_sendTransaction.ts | 12 ++++-- .../methods/eth_subscribe/eth_subscribe.ts | 12 ++++-- .../methods/eth_syncing/eth_syncing.ts | 8 +++- .../eth_unsubscribe/eth_unsubscribe.ts | 8 +++- .../methods-map/methods/evm_mine/evm_mine.ts | 8 +++- packages/network/tests/built-in-fixture.ts | 6 ++- packages/network/tests/fixture.ts | 3 +- .../contracts/contract.erc20.solo.test.ts | 2 +- .../tests/thor-client/gas/gas.solo.test.ts | 5 ++- .../transactions-thorest.solo.test.ts | 16 ++++---- .../tests/utils/http/http-client.solo.test.ts | 6 +-- .../utils/http/http-client.testnet.test.ts | 11 ++++-- .../subscriptions.testnet.test.ts | 15 ++++---- .../tests/utils/thorest/helpers.unit.test.ts | 3 +- 51 files changed, 322 insertions(+), 200 deletions(-) delete mode 100644 apps/sdk-hardhat-integration/scripts/temp_test_ethers.ts diff --git a/apps/sdk-hardhat-integration/scripts/deploy.ts b/apps/sdk-hardhat-integration/scripts/deploy.ts index ef9b5ff8d..4a468ad1f 100644 --- a/apps/sdk-hardhat-integration/scripts/deploy.ts +++ b/apps/sdk-hardhat-integration/scripts/deploy.ts @@ -1,4 +1,5 @@ import { ethers } from 'hardhat'; +import { stringifyData } from '@vechain/sdk-errors'; async function main(): Promise { const signer = (await ethers.getSigners())[0]; @@ -12,7 +13,7 @@ async function main(): Promise { console.log( 'Contract deployment with the following transaction:', - JSON.stringify(txResponse) + stringifyData(txResponse) ); } diff --git a/apps/sdk-hardhat-integration/scripts/temp_test_ethers.ts b/apps/sdk-hardhat-integration/scripts/temp_test_ethers.ts deleted file mode 100644 index 96058fd3d..000000000 --- a/apps/sdk-hardhat-integration/scripts/temp_test_ethers.ts +++ /dev/null @@ -1,37 +0,0 @@ -async function main(): Promise { - // console.log('Chain ID', await ethers.provider.send('eth_chainId', [])); - // console.log( - // 'pluto', - // await ethers.getSigner('0x0000000000000000000000000000456E65726779') - // ); - // const vechainHelloWorldWithNonEmptyConstructor = - // await ethers.deployContract( - // 'VechainHelloWorldWithNonEmptyConstructor', - // [10], - // { - // from: (await ethers.getSigners())[0].address, - // value: ethers.parseEther('0.1') - // } - // ); - // - // const vechainHelloWorld = await ethers.deployContract( - // 'VechainHelloWorld', - // [], - // { - // from: (await ethers.getSigners())[0].address - // } - // ); - // - // await vechainHelloWorldWithNonEmptyConstructor.waitForDeployment(); - // - // console.log( - // `VechainHelloWorld deployed to ${JSON.stringify(vechainHelloWorld)}` - // ); -} - -// We recommend this pattern to be able to use async/await everywhere -// and properly handle errors. -main().catch((error) => { - console.error(error); - process.exitCode = 1; -}); diff --git a/docs/contracts.md b/docs/contracts.md index 3ac77ff38..fd3ade882 100644 --- a/docs/contracts.md +++ b/docs/contracts.md @@ -38,7 +38,7 @@ After deploying a smart contract, interacting with its functions is the next ste ```typescript { name=contract-function-call, category=example } // 1 - Init a simple contract ABI -const contractABI = JSON.stringify([ +const contractABI = stringifyData([ { constant: false, inputs: [ diff --git a/docs/encoding.md b/docs/encoding.md index 9720a9c74..6423b8cfe 100644 --- a/docs/encoding.md +++ b/docs/encoding.md @@ -53,7 +53,7 @@ The contract interface is used to provide a higher level of abstraction to allow ```typescript { name=contract, category=example } // 1 - Create a new function -const contractABI = JSON.stringify([ +const contractABI = stringifyData([ { constant: false, inputs: [ diff --git a/docs/examples/contracts/contract-function-call.ts b/docs/examples/contracts/contract-function-call.ts index f40c166aa..3714a4a53 100644 --- a/docs/examples/contracts/contract-function-call.ts +++ b/docs/examples/contracts/contract-function-call.ts @@ -1,10 +1,11 @@ import { clauseBuilder, coder, type FunctionFragment } from '@vechain/sdk-core'; import { expect } from 'expect'; +import { stringifyData } from '@vechain/sdk-errors'; // START_SNIPPET: ContractFunctionCallSnippet // 1 - Init a simple contract ABI -const contractABI = JSON.stringify([ +const contractABI = stringifyData([ { constant: false, inputs: [ diff --git a/docs/examples/encoding/contract.ts b/docs/examples/encoding/contract.ts index 22ff843e6..4debf27e3 100644 --- a/docs/examples/encoding/contract.ts +++ b/docs/examples/encoding/contract.ts @@ -1,11 +1,12 @@ import { coder } from '@vechain/sdk-core'; import { expect } from 'expect'; +import { stringifyData } from '@vechain/sdk-errors'; // START_SNIPPET: ContractSnippet // 1 - Create a new function -const contractABI = JSON.stringify([ +const contractABI = stringifyData([ { constant: false, inputs: [ diff --git a/docs/examples/encoding/rlp.ts b/docs/examples/encoding/rlp.ts index 1e4e5a6e0..3db04a4f3 100644 --- a/docs/examples/encoding/rlp.ts +++ b/docs/examples/encoding/rlp.ts @@ -1,5 +1,6 @@ import { RLP_CODER } from '@vechain/sdk-core'; import { expect } from 'expect'; +import { stringifyData } from '@vechain/sdk-errors'; // START_SNIPPET: RlpSnippet @@ -35,4 +36,4 @@ const obj = rlp.decodeObject(data); expect(data.toString('hex')).toBe( 'd7947567d83b7b8d80addcb281a71d54fc7b3364ffed0a80' ); -expect(JSON.stringify(obj)).toBe(JSON.stringify(clause)); +expect(stringifyData(obj)).toBe(stringifyData(clause)); diff --git a/docs/examples/evm-extension/evm-extension.ts b/docs/examples/evm-extension/evm-extension.ts index ca3255cdf..df58dba57 100644 --- a/docs/examples/evm-extension/evm-extension.ts +++ b/docs/examples/evm-extension/evm-extension.ts @@ -1,9 +1,10 @@ -import { FunctionFragment, coder } from '@vechain/sdk-core'; -import { ThorClient } from '@vechain/sdk-network' +import { coder, type FunctionFragment } from '@vechain/sdk-core'; +import { ThorClient } from '@vechain/sdk-network'; import { expect } from 'expect'; +import { stringifyData } from '@vechain/sdk-errors'; // ABI of the `TestingContract` smart contract -const TESTING_CONTRACT_ABI = JSON.stringify([ +const TESTING_CONTRACT_ABI = stringifyData([ { inputs: [ { @@ -794,4 +795,4 @@ const totalSupply = await thorSoloClient.contracts.executeCall( // END_SNIPPET: EVMExtensionSnippet // Check the result -expect(totalSupply).toStrictEqual([10000000000000000000000000000n]); \ No newline at end of file +expect(totalSupply).toStrictEqual([10000000000000000000000000000n]); diff --git a/docs/examples/transactions/simulation.ts b/docs/examples/transactions/simulation.ts index 3ab8d78bc..d490f5a43 100644 --- a/docs/examples/transactions/simulation.ts +++ b/docs/examples/transactions/simulation.ts @@ -1,6 +1,7 @@ import { expect } from 'expect'; import { ThorClient } from '@vechain/sdk-network'; import { clauseBuilder, unitsUtils } from '@vechain/sdk-core'; +import { stringifyData } from '@vechain/sdk-errors'; // START_SNIPPET: SimulationSnippet @@ -107,4 +108,4 @@ const expected2 = [ ]; // 3 - Check the result -expect(JSON.stringify(simulatedTx2)).toStrictEqual(JSON.stringify(expected2)); +expect(stringifyData(simulatedTx2)).toStrictEqual(stringifyData(expected2)); diff --git a/packages/core/src/contract/coder.ts b/packages/core/src/contract/coder.ts index af8a72036..247f37186 100644 --- a/packages/core/src/contract/coder.ts +++ b/packages/core/src/contract/coder.ts @@ -1,5 +1,10 @@ import { Interface as EthersInterface, type InterfaceAbi } from 'ethers'; -import { ABI, buildError, ERROR_CODES } from '@vechain/sdk-errors'; +import { + ABI, + buildError, + ERROR_CODES, + stringifyData +} from '@vechain/sdk-errors'; import type { BytesLike, Interface, Log, Result } from '../abi'; import { abi } from '../abi'; @@ -36,7 +41,7 @@ function encodeFunctionInput( ERROR_CODES.ABI.INVALID_DATA_TO_ENCODE, `Method 'encodeFunctionInput' failed while encoding input for function '${functionName}'. ` + `Input must match ABI specifications and be correctly formatted.\n` + - `Parameters: ${JSON.stringify(functionData)}.\n` + + `Parameters: ${stringifyData(functionData)}.\n` + `Ethers' error message: ${(e as Error).message}.`, { functionName, functionData }, e diff --git a/packages/core/src/keystore/cryptography/ethers/keystore.ts b/packages/core/src/keystore/cryptography/ethers/keystore.ts index 0f85d229b..7f0d1f54f 100644 --- a/packages/core/src/keystore/cryptography/ethers/keystore.ts +++ b/packages/core/src/keystore/cryptography/ethers/keystore.ts @@ -3,7 +3,12 @@ */ import { ethers } from 'ethers'; import { type Keystore, type KeystoreAccount } from '../../types'; -import { assert, buildError, KEYSTORE } from '@vechain/sdk-errors'; +import { + assert, + buildError, + KEYSTORE, + stringifyData +} from '@vechain/sdk-errors'; import { secp256k1 } from '../../../secp256k1'; import { addressUtils } from '../../../address'; import { Hex0x } from '../../../utils'; @@ -76,7 +81,7 @@ async function decrypt( try { return (await ethers.decryptKeystoreJson( - JSON.stringify(keystore), + stringifyData(keystore), password )) as KeystoreAccount; } catch (e) { @@ -100,7 +105,7 @@ async function decrypt( * @returns A boolean indicating whether the keystore is valid or not. */ function isValid(keystore: Keystore): boolean { - return ethers.isKeystoreJson(JSON.stringify(keystore)); + return ethers.isKeystoreJson(stringifyData(keystore)); } /** diff --git a/packages/core/src/keystore/cryptography/experimental/keystore.ts b/packages/core/src/keystore/cryptography/experimental/keystore.ts index a3d95a38b..18f3846e1 100644 --- a/packages/core/src/keystore/cryptography/experimental/keystore.ts +++ b/packages/core/src/keystore/cryptography/experimental/keystore.ts @@ -4,7 +4,7 @@ * encryption, decryption, and validation functionality. */ import * as utils from '@noble/curves/abstract/utils'; -import { assert, KEYSTORE } from '@vechain/sdk-errors'; +import { assert, KEYSTORE, stringifyData } from '@vechain/sdk-errors'; import { ctr } from '@noble/ciphers/aes'; import { scrypt } from '@noble/hashes/scrypt'; import { type Keystore, type KeystoreAccount } from '../../types'; @@ -550,7 +550,7 @@ function decryptKeystore( */ function isValid(keystore: Keystore): boolean { try { - const copy = JSON.parse(JSON.stringify(keystore)) as Keystore; + const copy = JSON.parse(stringifyData(keystore)) as Keystore; if ( copy.crypto.cipher.toLowerCase() === KEYSTORE_CRYPTO_CIPHER && copy.crypto.kdf.toLowerCase() === KEYSTORE_CRYPTO_KDF && diff --git a/packages/core/src/utils/const/abi.ts b/packages/core/src/utils/const/abi.ts index e94fe886a..dd16c050d 100644 --- a/packages/core/src/utils/const/abi.ts +++ b/packages/core/src/utils/const/abi.ts @@ -1,9 +1,11 @@ +import { stringifyData } from '@vechain/sdk-errors'; + /** * ABI of the Params built-in contract. * * @link see [params.sol](https://docs.vechain.org/developer-resources/built-in-contracts#params-sol) */ -const PARAMS_ABI = JSON.stringify([ +const PARAMS_ABI = stringifyData([ { constant: false, inputs: [ @@ -79,7 +81,7 @@ const PARAMS_ABI = JSON.stringify([ * * @see [VIP 180](https://github.com/vechain/VIPs/blob/master/vips/VIP-180.md) */ -const VIP180_ABI = JSON.stringify([ +const VIP180_ABI = stringifyData([ { constant: true, inputs: [], @@ -338,7 +340,7 @@ const VIP180_ABI = JSON.stringify([ } ]); -const ERC721_ABI = JSON.stringify([ +const ERC721_ABI = stringifyData([ { inputs: [], stateMutability: 'nonpayable', diff --git a/packages/core/tests/abi/abi.unit.test.ts b/packages/core/tests/abi/abi.unit.test.ts index 8c1a46ecf..5ae05de42 100644 --- a/packages/core/tests/abi/abi.unit.test.ts +++ b/packages/core/tests/abi/abi.unit.test.ts @@ -16,7 +16,8 @@ import { InvalidAbiDataToEncodeError, InvalidAbiEventError, InvalidAbiFormatTypeError, - InvalidAbiFunctionError + InvalidAbiFunctionError, + stringifyData } from '@vechain/sdk-errors'; /** @@ -432,7 +433,7 @@ describe('Abi - Function & Event', () => { topicsEventTestCases.forEach( ({ event, valuesToEncode, expectedTopics }) => { test(`Encode Event topics - ${ - typeof event === 'string' ? event : JSON.stringify(event) + typeof event === 'string' ? event : stringifyData(event) }`, () => { const ev = new abi.Event(event); @@ -448,7 +449,7 @@ describe('Abi - Function & Event', () => { */ invalidTopicsEventTestCases.forEach( ({ event, valuesToEncode, expectedError }) => { - test(`Encode Event topics - ${JSON.stringify(event)}`, () => { + test(`Encode Event topics - ${stringifyData(event)}`, () => { const ev = new abi.Event(event); expect(() => diff --git a/packages/core/tests/abi/fixture.ts b/packages/core/tests/abi/fixture.ts index fde427028..1ba81acc9 100644 --- a/packages/core/tests/abi/fixture.ts +++ b/packages/core/tests/abi/fixture.ts @@ -1,6 +1,9 @@ import { addressUtils, Hex0x } from '../../src'; import { generateRandomValidAddress } from '../fixture'; -import { InvalidAbiDataToEncodeError } from '@vechain/sdk-errors'; +import { + InvalidAbiDataToEncodeError, + stringifyData +} from '@vechain/sdk-errors'; /** * Simple functions fixtures @@ -438,7 +441,7 @@ const encodedDecodedInvalidValues = [ } ]; -const contractABI = JSON.stringify([ +const contractABI = stringifyData([ { constant: false, inputs: [ @@ -469,7 +472,7 @@ const contractABI = JSON.stringify([ } ]); -const contractABIWithEvents = JSON.stringify([ +const contractABIWithEvents = stringifyData([ { constant: false, inputs: [ @@ -517,7 +520,7 @@ const contractABIWithEvents = JSON.stringify([ } ]); -const contractStorageABI = JSON.stringify([ +const contractStorageABI = stringifyData([ { inputs: [], name: 'getValue', diff --git a/packages/core/tests/bloom/bloom.unit.test.ts b/packages/core/tests/bloom/bloom.unit.test.ts index 3915e6595..afbff0f53 100644 --- a/packages/core/tests/bloom/bloom.unit.test.ts +++ b/packages/core/tests/bloom/bloom.unit.test.ts @@ -2,7 +2,11 @@ import * as utils from '@noble/curves/abstract/utils'; import { describe, expect, test } from '@jest/globals'; import { bloom, Hex } from '../../src'; import { bloomKTestCases } from './fixture'; -import { InvalidBloomError, InvalidKError } from '../../../errors'; +import { + InvalidBloomError, + InvalidKError, + stringifyData +} from '../../../errors'; /** * Bloom filter tests @@ -286,8 +290,8 @@ describe('Bloom Filter', () => { expect(filter.bits.byteLength).toBe(25); expect(filter.k).toBe(k); - expect(JSON.stringify(filter.bits)).toBe( - JSON.stringify( + expect(stringifyData(filter.bits)).toBe( + stringifyData( utils.hexToBytes( 'a4d641159d68d829345f86f40d50676cf042f6265072075a94' ) diff --git a/packages/core/tests/keystore/keystore.unit.test.ts b/packages/core/tests/keystore/keystore.unit.test.ts index 592b0e2b6..2fe78753f 100644 --- a/packages/core/tests/keystore/keystore.unit.test.ts +++ b/packages/core/tests/keystore/keystore.unit.test.ts @@ -10,7 +10,8 @@ import { encryptionPassword } from './fixture'; import { InvalidKeystoreError, InvalidKeystorePasswordError, - InvalidSecp256k1PrivateKeyError + InvalidSecp256k1PrivateKeyError, + stringifyData } from '@vechain/sdk-errors'; /** @@ -125,7 +126,7 @@ import { ); // Verify keystore -> False - const invalidKeystore: string = JSON.stringify({ + const invalidKeystore: string = stringifyData({ ...myKeystore, version: 4 }); @@ -157,7 +158,7 @@ import { expect(keystore.isValid(myKeystore)).toBe(true); // Verify keystore -> False - const invalidKeystore: string = JSON.stringify({ + const invalidKeystore: string = stringifyData({ ...myKeystore, version: 4 }); diff --git a/packages/core/tests/rlp/helpers.unit.test.ts b/packages/core/tests/rlp/helpers.unit.test.ts index b1291920a..61d7f0fbe 100644 --- a/packages/core/tests/rlp/helpers.unit.test.ts +++ b/packages/core/tests/rlp/helpers.unit.test.ts @@ -1,15 +1,15 @@ import { describe, expect, test } from '@jest/globals'; import { - assertValidNumericKindBuffer, - validateNumericKindData, - assertValidHexBlobKindData, - assertValidHexBlobKindBuffer, - assertFixedHexBlobKindData, - assertFixedHexBlobKindBuffer, assertCompactFixedHexBlobBuffer, + assertFixedHexBlobKindBuffer, + assertFixedHexBlobKindData, + assertValidHexBlobKindBuffer, + assertValidHexBlobKindData, + assertValidNumericKindBuffer, decodeBufferToHexWithLeadingZeros, encodeBigIntToBuffer, - Hex + Hex, + validateNumericKindData } from '../../src'; import { invalidCompactFixedHexBlobKindBufferTestCases, @@ -19,15 +19,15 @@ import { invalidHexBlobKindDataTestCases, invalidNumberTestCases, invalidNumericBufferTestCases, + validateNumberTestCases, validCompactFixedHexBlobKindBufferTestCases, validFixedHexBlobKindBufferTestCases, validFixedHexBlobKindDataTestCases, validHexBlobKindBufferTestCases, validHexBlobKindDataTestCases, - validNumericBufferTestCases, - validateNumberTestCases + validNumericBufferTestCases } from './helpers.fixture'; -import { InvalidRLPError } from '@vechain/sdk-errors'; +import { InvalidRLPError, stringifyData } from '@vechain/sdk-errors'; /** * Test suite for BigInt helper functions @@ -95,7 +95,7 @@ describe('NumericKind helpers', () => { * asserting that the function throws an error with a corresponding message. */ invalidNumberTestCases.forEach(({ number, context }) => { - test(`should throw error when data is invalid ${JSON.stringify( + test(`should throw error when data is invalid ${stringifyData( number )}`, () => { expect(() => { @@ -193,7 +193,7 @@ describe('HexBlobKind helpers', () => { }); invalidHexBlobKindBufferTestCases.forEach(({ buffer, context }) => { - test(`should throw error when buffer is invalid ${JSON.stringify( + test(`should throw error when buffer is invalid ${stringifyData( buffer )}`, () => { expect(() => { @@ -255,7 +255,7 @@ describe('FixedHexBlobKind helpers', () => { invalidFixedHexBlobKindBufferTestCases.forEach( ({ buffer, context, bytes }) => { - test(`should throw error when buffer is invalid ${JSON.stringify( + test(`should throw error when buffer is invalid ${stringifyData( buffer )}`, () => { expect(() => { @@ -289,7 +289,7 @@ describe('CompactFixedHexBlobKind helpers', () => { invalidCompactFixedHexBlobKindBufferTestCases.forEach( ({ buffer, context, bytes }) => { - test(`should throw error when buffer is invalid ${JSON.stringify( + test(`should throw error when buffer is invalid ${stringifyData( buffer )}`, () => { expect(() => { diff --git a/packages/core/tests/utils/assertions/transaction-assertions.unit.test.ts b/packages/core/tests/utils/assertions/transaction-assertions.unit.test.ts index bea063dcd..602b02be4 100644 --- a/packages/core/tests/utils/assertions/transaction-assertions.unit.test.ts +++ b/packages/core/tests/utils/assertions/transaction-assertions.unit.test.ts @@ -8,7 +8,10 @@ import { Hex, secp256k1 } from '../../../src'; -import { InvalidSecp256k1PrivateKeyError } from '@vechain/sdk-errors'; +import { + InvalidSecp256k1PrivateKeyError, + stringifyData +} from '@vechain/sdk-errors'; /** * Transaction assertions @@ -88,7 +91,7 @@ describe('Transaction assertions', () => { */ transactionAssertionsTests.assertIsSignedTransaction.valid.forEach( ({ value }) => { - test(`should not throw error for assertIsSignedTransaction of ${JSON.stringify( + test(`should not throw error for assertIsSignedTransaction of ${stringifyData( value )}`, () => { // Expect assertIsSignedTransaction to not throw @@ -104,7 +107,7 @@ describe('Transaction assertions', () => { */ transactionAssertionsTests.assertIsSignedTransaction.invalid.forEach( ({ value }) => { - test(`should throw error for assertIsSignedTransaction of ${JSON.stringify( + test(`should throw error for assertIsSignedTransaction of ${stringifyData( value )}`, () => { // Expect assertIsSignedTransaction to throw diff --git a/packages/core/tests/utils/data/data.unit.test.ts b/packages/core/tests/utils/data/data.unit.test.ts index 10c4a6b29..cc47d3c62 100644 --- a/packages/core/tests/utils/data/data.unit.test.ts +++ b/packages/core/tests/utils/data/data.unit.test.ts @@ -7,6 +7,7 @@ import { invalidEncodeBytes32StringTestCases, isNumericTestCases } from './fixture'; +import { stringifyData } from '../../../../errors'; /** * Hex data tests @@ -21,7 +22,7 @@ describe('dataUtils', () => { * Test cases for decodeBytes32String function. */ decodeBytes32StringTestCases.forEach(({ value, expected }) => { - test(`should return ${expected} for ${JSON.stringify( + test(`should return ${expected} for ${stringifyData( value )}`, () => { expect(dataUtils.decodeBytes32String(value)).toBe(expected); @@ -33,7 +34,7 @@ describe('dataUtils', () => { */ invalidDecodeBytes32StringTestCases.forEach( ({ value, expectedError }) => { - test(`should throw for ${JSON.stringify(value)}`, () => { + test(`should throw for ${stringifyData(value)}`, () => { expect(() => dataUtils.decodeBytes32String(value) ).toThrowError(expectedError); @@ -51,7 +52,7 @@ describe('dataUtils', () => { */ encodeBytes32StringTestCases.forEach( ({ value, zeroPadding, expected }) => { - test(`should return ${expected} for ${JSON.stringify( + test(`should return ${expected} for ${stringifyData( value )}`, () => { expect( @@ -66,7 +67,7 @@ describe('dataUtils', () => { */ invalidEncodeBytes32StringTestCases.forEach( ({ value, zeroPadding, expectedError }) => { - test(`should throw for ${JSON.stringify(value)}`, () => { + test(`should throw for ${stringifyData(value)}`, () => { expect(() => dataUtils.encodeBytes32String(value, zeroPadding) ).toThrowError(expectedError); @@ -83,7 +84,7 @@ describe('dataUtils', () => { * Test cases for isNumeric function. */ isNumericTestCases.forEach(({ value, expected }) => { - test(`should return ${expected} for ${JSON.stringify( + test(`should return ${expected} for ${stringifyData( value )}`, () => { expect(dataUtils.isNumeric(value)).toBe(expected); diff --git a/packages/network/solo-seeding/thor-solo-seeding.ts b/packages/network/solo-seeding/thor-solo-seeding.ts index 328904de9..a02921f62 100644 --- a/packages/network/solo-seeding/thor-solo-seeding.ts +++ b/packages/network/solo-seeding/thor-solo-seeding.ts @@ -14,6 +14,7 @@ import { expect } from '@jest/globals'; import { TESTING_CONTRACT_BYTECODE } from './const'; import { ALL_ACCOUNTS, soloUrl } from '../tests/fixture'; import * as ethers from 'ethers'; +import { stringifyData } from '@vechain/sdk-errors'; /** * Constructs clauses for transferring VTHO tokens. @@ -475,7 +476,7 @@ const seedThorSolo = async (): Promise => { ALL_ACCOUNTS[4].address ); - console.log('Deploy contract simulation: ', JSON.stringify(simulations)); + console.log('Deploy contract simulation: ', stringifyData(simulations)); const resp = await thorSoloClient.transactions.sendTransaction(deployTx); diff --git a/packages/network/src/provider/providers/hardhat-provider/hardhat-provider.ts b/packages/network/src/provider/providers/hardhat-provider/hardhat-provider.ts index 54cdcfb10..785e6728d 100644 --- a/packages/network/src/provider/providers/hardhat-provider/hardhat-provider.ts +++ b/packages/network/src/provider/providers/hardhat-provider/hardhat-provider.ts @@ -1,6 +1,10 @@ import { VeChainProvider } from '../vechain-provider'; import type { EIP1193RequestArguments } from '../../eip1193'; -import { getJSONRPCErrorCode, JSONRPC } from '@vechain/sdk-errors'; +import { + getJSONRPCErrorCode, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import { VeChainSDKLogger } from '@vechain/sdk-logging'; import { type BuildHardhatErrorFunction, @@ -126,9 +130,9 @@ class HardhatVeChainProvider extends VeChainProvider { VeChainSDKLogger('log').log({ title: `Sending request - ${args.method}`, messages: [ - `params: ${JSON.stringify(args.params)}`, - `accounts: ${JSON.stringify(accounts)}`, - `delegator: ${JSON.stringify(delegator)}`, + `params: ${stringifyData(args.params)}`, + `accounts: ${stringifyData(accounts)}`, + `delegator: ${stringifyData(delegator)}`, `url: ${this.thorClient.httpClient.baseURL}` ] }); @@ -144,7 +148,7 @@ class HardhatVeChainProvider extends VeChainProvider { if (this.debug) { VeChainSDKLogger('log').log({ title: `Get request - ${args.method} result`, - messages: [`result: ${JSON.stringify(result)}`] + messages: [`result: ${stringifyData(result)}`] }); } diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/debug_traceCall/debug_traceCall.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/debug_traceCall/debug_traceCall.ts index 1ab7e86a3..45f19a189 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/debug_traceCall/debug_traceCall.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/debug_traceCall/debug_traceCall.ts @@ -1,15 +1,21 @@ -import { type ThorClient } from '../../../../../../thor-client'; -import { assert, buildProviderError, DATA, JSONRPC } from '@vechain/sdk-errors'; +import { + type ThorClient, + type TraceReturnType, + type TracerName +} from '../../../../../../thor-client'; +import { + assert, + buildProviderError, + DATA, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import { debugFormatter, type TracerReturnTypeRPC -} from '../../../../formatter/debug'; +} from '../../../../formatter'; import { type TraceCallRPC, type TransactionObjectInput } from './types'; -import { - type TraceReturnType, - type TracerName -} from '../../../../../../thor-client/debug'; /** * RPC Method debug_traceCall implementation @@ -96,11 +102,11 @@ const debugTraceCall = async ( throw buildProviderError( JSONRPC.INTERNAL_ERROR, `Method 'debug_traceCall' failed: Error while debug tracer call\n - Params: ${JSON.stringify(params)}\n + Params: ${stringifyData(params)}\n URL: ${thorClient.httpClient.baseURL}`, { params, - innerError: JSON.stringify(e) + innerError: stringifyData(e) } ); } diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/debug_traceTransaction/debug_traceTransaction.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/debug_traceTransaction/debug_traceTransaction.ts index 92acd9ee8..d8f4aa9c5 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/debug_traceTransaction/debug_traceTransaction.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/debug_traceTransaction/debug_traceTransaction.ts @@ -1,16 +1,22 @@ -import { type ThorClient } from '../../../../../../thor-client'; -import { assert, buildProviderError, DATA, JSONRPC } from '@vechain/sdk-errors'; +import { + type ThorClient, + type TraceReturnType, + type TracerName +} from '../../../../../../thor-client'; +import { + assert, + buildProviderError, + DATA, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import { assertValidTransactionID } from '@vechain/sdk-core'; import { ethGetTransactionReceipt } from '../eth_getTransactionReceipt'; import { type TraceOptionsRPC } from './types'; import { debugFormatter, type TracerReturnTypeRPC -} from '../../../../formatter/debug'; -import { - type TraceReturnType, - type TracerName -} from '../../../../../../thor-client/debug'; +} from '../../../../formatter'; /** * RPC Method debug_traceTransaction implementation @@ -85,11 +91,11 @@ const debugTraceTransaction = async ( throw buildProviderError( JSONRPC.INTERNAL_ERROR, `Method 'debug_traceTransaction' failed: Error while debug transaction tracer\n - Params: ${JSON.stringify(params)}\n + Params: ${stringifyData(params)}\n URL: ${thorClient.httpClient.baseURL}`, { params, - innerError: JSON.stringify(e) + innerError: stringifyData(e) } ); } diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_blockNumber/eth_blockNumber.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_blockNumber/eth_blockNumber.ts index 711f13110..a3d676de1 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_blockNumber/eth_blockNumber.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_blockNumber/eth_blockNumber.ts @@ -1,4 +1,8 @@ -import { JSONRPC, buildProviderError } from '@vechain/sdk-errors'; +import { + buildProviderError, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import { type ThorClient } from '../../../../../../thor-client'; /** @@ -26,7 +30,7 @@ const ethBlockNumber = async (thorClient: ThorClient): Promise => { `Method 'eth_blockNumber' failed: Error while getting the latest block number.\n URL: ${thorClient.httpClient.baseURL}`, { - innerError: JSON.stringify(e) + innerError: stringifyData(e) } ); } diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_call/eth_call.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_call/eth_call.ts index bc10b3b36..205add39f 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_call/eth_call.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_call/eth_call.ts @@ -1,4 +1,10 @@ -import { assert, buildProviderError, DATA, JSONRPC } from '@vechain/sdk-errors'; +import { + assert, + buildProviderError, + DATA, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import { getCorrectBlockNumberRPCToVechain } from '../../../../const'; import { type TransactionObjectInput } from './types'; import { type BlockQuantityInputRPC } from '../../../types'; @@ -77,11 +83,11 @@ const ethCall = async ( throw buildProviderError( JSONRPC.INTERNAL_ERROR, `Method 'eth_call' failed: Error while simulating transaction\n - Params: ${JSON.stringify(params)}\n + Params: ${stringifyData(params)}\n URL: ${thorClient.httpClient.baseURL}`, { params, - innerError: JSON.stringify(e) + innerError: stringifyData(e) } ); } diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_chainId/eth_chainId.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_chainId/eth_chainId.ts index 007dbeb99..64fe2457f 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_chainId/eth_chainId.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_chainId/eth_chainId.ts @@ -1,5 +1,9 @@ import { type ThorClient } from '../../../../../../thor-client'; -import { buildProviderError, JSONRPC } from '@vechain/sdk-errors'; +import { + buildProviderError, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import { CHAIN_ID } from '../../../../const'; import { networkInfo } from '@vechain/sdk-core'; @@ -18,8 +22,12 @@ const ethChainId = async (thorClient: ThorClient): Promise => { const genesisBlock = await thorClient.blocks.getGenesisBlock(); if (genesisBlock?.id === null || genesisBlock?.id === undefined) { - throw new Error( - `The genesis block id is null.\n\tgenesisBlock: ${JSON.stringify(genesisBlock)}` + throw buildProviderError( + JSONRPC.INVALID_PARAMS, + `The genesis block id is null or undefined. Unable to get the chain id.`, + { + block: genesisBlock + } ); } @@ -35,7 +43,7 @@ const ethChainId = async (thorClient: ThorClient): Promise => { `Method 'eth_chainId' failed: Error while getting the chain id.\n URL: ${thorClient.httpClient.baseURL}`, { - innerError: JSON.stringify(e) + innerError: stringifyData(e) } ); } diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_estimateGas/eth_estimateGas.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_estimateGas/eth_estimateGas.ts index 0e5713089..0d71dfd5c 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_estimateGas/eth_estimateGas.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_estimateGas/eth_estimateGas.ts @@ -1,4 +1,10 @@ -import { assert, buildProviderError, DATA, JSONRPC } from '@vechain/sdk-errors'; +import { + assert, + buildProviderError, + DATA, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import { type TransactionObjectInput } from './types'; import { type SimulateTransactionClause, @@ -76,10 +82,10 @@ const ethEstimateGas = async ( `Method 'eth_estimateGas' failed: Error while calculating gas for ${ params[0] as string } transaction\n - Params: ${JSON.stringify(params)}\n`, + Params: ${stringifyData(params)}\n`, { params, - innerError: JSON.stringify(e) + innerError: stringifyData(e) } ); } diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getBalance/eth_getBalance.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getBalance/eth_getBalance.ts index dd94794a6..acf148a0d 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getBalance/eth_getBalance.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getBalance/eth_getBalance.ts @@ -1,5 +1,11 @@ import { type ThorClient } from '../../../../../../thor-client'; -import { assert, buildProviderError, DATA, JSONRPC } from '@vechain/sdk-errors'; +import { + assert, + buildProviderError, + DATA, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import type { BlockQuantityInputRPC } from '../../../types'; import { getCorrectBlockNumberRPCToVechain } from '../../../../const'; @@ -52,11 +58,11 @@ const ethGetBalance = async ( `Method 'eth_getBalance' failed: Error while getting the account's balance for the following address: ${ params[0] as string }\n - Params: ${JSON.stringify(params)}\n + Params: ${stringifyData(params)}\n URL: ${thorClient.httpClient.baseURL}`, { params, - innerError: JSON.stringify(e) + innerError: stringifyData(e) } ); } diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getBlockByHash/eth_getBlockByHash.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getBlockByHash/eth_getBlockByHash.ts index f23afd952..c6c72a2c2 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getBlockByHash/eth_getBlockByHash.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getBlockByHash/eth_getBlockByHash.ts @@ -1,5 +1,11 @@ import { type ThorClient } from '../../../../../../thor-client'; -import { assert, buildProviderError, DATA, JSONRPC } from '@vechain/sdk-errors'; +import { + assert, + buildProviderError, + DATA, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import { type BlocksRPC } from '../../../../formatter'; import { Hex0x } from '@vechain/sdk-core'; import { ethGetBlockByNumber } from '../eth_getBlockByNumber'; @@ -41,11 +47,11 @@ const ethGetBlockByHash = async ( `Method 'eth_getBlockByHash' failed: Error while getting block ${ params[0] as string }\n - Params: ${JSON.stringify(params)}\n + Params: ${stringifyData(params)}\n URL: ${thorClient.httpClient.baseURL}`, { params, - innerError: JSON.stringify(e) + innerError: stringifyData(e) } ); } diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getBlockByNumber/eth_getBlockByNumber.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getBlockByNumber/eth_getBlockByNumber.ts index 3e7075a63..d0b2ebb38 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getBlockByNumber/eth_getBlockByNumber.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getBlockByNumber/eth_getBlockByNumber.ts @@ -1,10 +1,16 @@ import { type ThorClient } from '../../../../../../thor-client'; -import { assert, buildProviderError, DATA, JSONRPC } from '@vechain/sdk-errors'; +import { + assert, + buildProviderError, + DATA, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import { blocksFormatter, type BlocksRPC } from '../../../../formatter'; import { RPCMethodsMap } from '../../../rpc-mapper'; import { - RPC_METHODS, - getCorrectBlockNumberRPCToVechain + getCorrectBlockNumberRPCToVechain, + RPC_METHODS } from '../../../../const'; /** @@ -62,11 +68,11 @@ const ethGetBlockByNumber = async ( `Method 'eth_getBlockByNumber' failed: Error while getting block ${ params[0] as string }\n - Params: ${JSON.stringify(params)}\n + Params: ${stringifyData(params)}\n URL: ${thorClient.httpClient.baseURL}`, { params, - innerError: JSON.stringify(e) + innerError: stringifyData(e) } ); } diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getCode/eth_getCode.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getCode/eth_getCode.ts index a3b8a5c2d..07587ae30 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getCode/eth_getCode.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getCode/eth_getCode.ts @@ -1,5 +1,11 @@ import { type ThorClient } from '../../../../../../thor-client'; -import { assert, buildProviderError, DATA, JSONRPC } from '@vechain/sdk-errors'; +import { + assert, + buildProviderError, + DATA, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import type { BlockQuantityInputRPC } from '../../../types'; import { getCorrectBlockNumberRPCToVechain } from '../../../../const'; @@ -51,11 +57,11 @@ const ethGetCode = async ( `Method 'eth_getCode' failed: Error while getting the account's code for the following address: ${ params[0] as string }\n - Params: ${JSON.stringify(params)}\n + Params: ${stringifyData(params)}\n URL: ${thorClient.httpClient.baseURL}`, { params, - innerError: JSON.stringify(e) + innerError: stringifyData(e) } ); } diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getLogs/eth_getLogs.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getLogs/eth_getLogs.ts index 3b4bf55bc..b7f8d6baa 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getLogs/eth_getLogs.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getLogs/eth_getLogs.ts @@ -1,9 +1,15 @@ -import { assert, buildProviderError, DATA, JSONRPC } from '@vechain/sdk-errors'; +import { + assert, + buildProviderError, + DATA, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import { formatToLogsRPC, getCriteriaSetForInput, type LogsRPC -} from '../../../../formatter/logs'; +} from '../../../../formatter'; import { type CompressedBlockDetail, type EventCriteria, @@ -92,11 +98,11 @@ const ethGetLogs = async ( `Method 'ethGetLogs' failed: Error while getting logs ${ params[0] as string }\n - Params: ${JSON.stringify(params)}\n + Params: ${stringifyData(params)}\n URL: ${thorClient.httpClient.baseURL}`, { params, - innerError: JSON.stringify(e) + innerError: stringifyData(e) } ); } diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getStorageAt/eth_getStorageAt.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getStorageAt/eth_getStorageAt.ts index e2e48e9cc..df003d922 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getStorageAt/eth_getStorageAt.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getStorageAt/eth_getStorageAt.ts @@ -1,5 +1,11 @@ import { Hex0x } from '@vechain/sdk-core'; -import { assert, buildProviderError, DATA, JSONRPC } from '@vechain/sdk-errors'; +import { + assert, + buildProviderError, + DATA, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import { type ThorClient } from '../../../../../../thor-client'; import type { BlockQuantityInputRPC } from '../../../types'; import { getCorrectBlockNumberRPCToVechain } from '../../../../const'; @@ -63,11 +69,11 @@ const ethGetStorageAt = async ( `Method 'eth_getStorageAt' failed: Error while getting the storage slot for the following address: ${ params[0] as string }, and storage position: ${params[1] as string}\n - Params: ${JSON.stringify(params)}\n + Params: ${stringifyData(params)}\n URL: ${thorClient.httpClient.baseURL}`, { params, - innerError: JSON.stringify(e) + innerError: stringifyData(e) } ); } diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getTransactionByHash/eth_getTransactionByHash.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getTransactionByHash/eth_getTransactionByHash.ts index 798751cd3..696144939 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getTransactionByHash/eth_getTransactionByHash.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getTransactionByHash/eth_getTransactionByHash.ts @@ -1,4 +1,10 @@ -import { assert, buildProviderError, DATA, JSONRPC } from '@vechain/sdk-errors'; +import { + assert, + buildProviderError, + DATA, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import { type BlocksRPC, type TransactionRPC, @@ -66,11 +72,11 @@ const ethGetTransactionByHash = async ( `Method 'eth_getTransactionByHash' failed: Error while getting the transaction ${ params[0] as string }\n - Params: ${JSON.stringify(params)}\n + Params: ${stringifyData(params)}\n URL: ${thorClient.httpClient.baseURL}`, { params, - innerError: JSON.stringify(e) + innerError: stringifyData(e) } ); } diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getTransactionReceipt/eth_getTransactionReceipt.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getTransactionReceipt/eth_getTransactionReceipt.ts index 23633714f..6c19406a2 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getTransactionReceipt/eth_getTransactionReceipt.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_getTransactionReceipt/eth_getTransactionReceipt.ts @@ -1,4 +1,10 @@ -import { assert, buildProviderError, DATA, JSONRPC } from '@vechain/sdk-errors'; +import { + assert, + buildProviderError, + DATA, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import { type TransactionReceiptRPC, transactionsFormatter @@ -81,11 +87,11 @@ const ethGetTransactionReceipt = async ( `Method 'eth_getTransactionReceipt' failed: Error while getting the transaction receipt ${ params[0] as string }\n - Params: ${JSON.stringify(params)}\n + Params: ${stringifyData(params)}\n URL: ${thorClient.httpClient.baseURL}`, { params, - innerError: JSON.stringify(e) + innerError: stringifyData(e) } ); } diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_sendRawTransaction/eth_sendRawTransaction.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_sendRawTransaction/eth_sendRawTransaction.ts index 9d127a8bd..5935bc3b8 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_sendRawTransaction/eth_sendRawTransaction.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_sendRawTransaction/eth_sendRawTransaction.ts @@ -1,5 +1,11 @@ import { type ThorClient } from '../../../../../../thor-client'; -import { assert, buildProviderError, DATA, JSONRPC } from '@vechain/sdk-errors'; +import { + assert, + buildProviderError, + DATA, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import { Hex0x } from '@vechain/sdk-core'; import { transactionsFormatter } from '../../../../formatter'; @@ -47,11 +53,11 @@ const ethSendRawTransaction = async ( `Method 'eth_sendRawTransaction' failed: Error while sending the transaction ${ params[0] as string }\n - Params: ${JSON.stringify(params)}\n + Params: ${stringifyData(params)}\n URL: ${thorClient.httpClient.baseURL}`, { params, - innerError: JSON.stringify(e) + innerError: stringifyData(e) } ); } diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_sendTransaction/eth_sendTransaction.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_sendTransaction/eth_sendTransaction.ts index 3f91e96f7..b9286edd7 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_sendTransaction/eth_sendTransaction.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_sendTransaction/eth_sendTransaction.ts @@ -1,5 +1,11 @@ import { type ThorClient } from '../../../../../../thor-client'; -import { assert, buildProviderError, DATA, JSONRPC } from '@vechain/sdk-errors'; +import { + assert, + buildProviderError, + DATA, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import { type VeChainProvider } from '../../../../../providers'; import { type TransactionObjectInput } from './types'; import { type VeChainSigner } from '../../../../../../signer'; @@ -85,11 +91,11 @@ const ethSendTransaction = async ( throw buildProviderError( JSONRPC.INTERNAL_ERROR, `Method 'eth_sendTransaction' failed: Error sending the transaction\n - Params: ${JSON.stringify(params)}\n + Params: ${stringifyData(params)}\n URL: ${thorClient.httpClient.baseURL}`, { params, - innerError: JSON.stringify(e) + innerError: stringifyData(e) } ); } diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_subscribe/eth_subscribe.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_subscribe/eth_subscribe.ts index f4f2f3f17..c1ccbab72 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_subscribe/eth_subscribe.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_subscribe/eth_subscribe.ts @@ -3,7 +3,11 @@ import { type FilterOptions, type VeChainProvider } from '../../../../../providers'; -import { buildProviderError, JSONRPC } from '@vechain/sdk-errors'; +import { + buildProviderError, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import { Hex } from '@vechain/sdk-core'; /** @@ -56,7 +60,7 @@ const ethSubscribe = async ( throw buildProviderError( JSONRPC.INTERNAL_ERROR, `Method 'ethSubscribe' failed: provider not available\n - Params: ${JSON.stringify(params)}\n + Params: ${stringifyData(params)}\n URL: ${thorClient.httpClient.baseURL}`, { params, @@ -71,7 +75,7 @@ const ethSubscribe = async ( throw buildProviderError( JSONRPC.INVALID_PARAMS, `Method 'ethSubscribe' failed: Invalid subscription type param\n - Params: ${JSON.stringify(params)}\n + Params: ${stringifyData(params)}\n URL: ${thorClient.httpClient.baseURL}`, { params @@ -89,7 +93,7 @@ const ethSubscribe = async ( throw buildProviderError( JSONRPC.INTERNAL_ERROR, `Method 'ethSubscribe' failed: Best block not available\n - Params: ${JSON.stringify(params)}\n + Params: ${stringifyData(params)}\n URL: ${thorClient.httpClient.baseURL}`, { params diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_syncing/eth_syncing.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_syncing/eth_syncing.ts index 3050a39fd..ed48d0e70 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_syncing/eth_syncing.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_syncing/eth_syncing.ts @@ -1,4 +1,8 @@ -import { buildProviderError, JSONRPC } from '@vechain/sdk-errors'; +import { + buildProviderError, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import { Quantity } from '@vechain/sdk-core'; import { type CompressedBlockDetail, @@ -81,7 +85,7 @@ const ethSyncing = async ( `Method 'eth_syncing' failed: Error while getting last syncing information\n URL: ${thorClient.httpClient.baseURL}`, { - innerError: JSON.stringify(e) + innerError: stringifyData(e) } ); } diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_unsubscribe/eth_unsubscribe.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_unsubscribe/eth_unsubscribe.ts index c024c711d..e94712a35 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_unsubscribe/eth_unsubscribe.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/eth_unsubscribe/eth_unsubscribe.ts @@ -1,5 +1,9 @@ import type { VeChainProvider } from '../../../../../providers'; -import { buildProviderError, JSONRPC } from '@vechain/sdk-errors'; +import { + buildProviderError, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; /** * Asynchronously unsubscribes from a VeChain event subscription. @@ -33,7 +37,7 @@ const ethUnsubscribe = async ( throw buildProviderError( JSONRPC.INTERNAL_ERROR, `Method 'ethSubscribe' failed: provider not available\n - Params: ${JSON.stringify(params)}`, + Params: ${stringifyData(params)}`, { params, provider diff --git a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/evm_mine/evm_mine.ts b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/evm_mine/evm_mine.ts index 86da04386..51b5cd6aa 100644 --- a/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/evm_mine/evm_mine.ts +++ b/packages/network/src/provider/utils/rpc-mapper/methods-map/methods/evm_mine/evm_mine.ts @@ -1,6 +1,10 @@ import { type ThorClient } from '../../../../../../thor-client'; import { blocksFormatter, type BlocksRPC } from '../../../../formatter'; -import { buildProviderError, JSONRPC } from '@vechain/sdk-errors'; +import { + buildProviderError, + JSONRPC, + stringifyData +} from '@vechain/sdk-errors'; import { RPCMethodsMap } from '../../../rpc-mapper'; import { RPC_METHODS } from '../../../../const'; @@ -37,7 +41,7 @@ const evmMine = async (thorClient: ThorClient): Promise => { `Method 'evm_mine' failed: Error while getting last block\n URL: ${thorClient.httpClient.baseURL}`, { - innerError: JSON.stringify(e) + innerError: stringifyData(e) } ); } diff --git a/packages/network/tests/built-in-fixture.ts b/packages/network/tests/built-in-fixture.ts index 4369cc80f..4aee876f4 100644 --- a/packages/network/tests/built-in-fixture.ts +++ b/packages/network/tests/built-in-fixture.ts @@ -1,3 +1,5 @@ +import { stringifyData } from '@vechain/sdk-errors'; + /** * Address of the Params built-in contract. * @@ -17,7 +19,7 @@ const ENERGY_ADDRESS = '0x0000000000000000000000000000456e65726779'; * * @link see [params.sol](https://docs.vechain.org/developer-resources/built-in-contracts#params-sol) */ -const PARAMS_ABI = JSON.stringify([ +const PARAMS_ABI = stringifyData([ { constant: false, inputs: [ @@ -93,7 +95,7 @@ const PARAMS_ABI = JSON.stringify([ * * @link see [energy.sol](https://docs.vechain.org/developer-resources/built-in-contracts#energy-sol) */ -const ENERGY_ABI = JSON.stringify([ +const ENERGY_ABI = stringifyData([ { constant: true, inputs: [], diff --git a/packages/network/tests/fixture.ts b/packages/network/tests/fixture.ts index 06a7d925d..ce668ab6a 100644 --- a/packages/network/tests/fixture.ts +++ b/packages/network/tests/fixture.ts @@ -4,6 +4,7 @@ import { type SignTransactionOptions } from '../src'; import { secp256k1 } from '../../core'; +import { stringifyData } from '@vechain/sdk-errors'; /** * Url of the mainnet fixture @@ -245,7 +246,7 @@ const TESTING_CONTRACT_BYTECODE = /** * ABI of the `TestingContract` smart contract. */ -const TESTING_CONTRACT_ABI = JSON.stringify([ +const TESTING_CONTRACT_ABI = stringifyData([ { inputs: [ { diff --git a/packages/network/tests/thor-client/contracts/contract.erc20.solo.test.ts b/packages/network/tests/thor-client/contracts/contract.erc20.solo.test.ts index feecc4673..b502b41a3 100644 --- a/packages/network/tests/thor-client/contracts/contract.erc20.solo.test.ts +++ b/packages/network/tests/thor-client/contracts/contract.erc20.solo.test.ts @@ -11,7 +11,7 @@ import { import { soloUrl, TEST_ACCOUNTS } from '../../fixture'; import { deployedERC20Abi, erc20ContractBytecode } from './fixture'; import { addressUtils } from '@vechain/sdk-core'; -import { InvalidAbiFunctionError } from '@vechain/sdk-errors/dist'; +import { InvalidAbiFunctionError } from '@vechain/sdk-errors'; /** * Tests for the ThorClient class, specifically focusing on ERC20 contract-related functionality. diff --git a/packages/network/tests/thor-client/gas/gas.solo.test.ts b/packages/network/tests/thor-client/gas/gas.solo.test.ts index 9c3888c49..ae6fb7698 100644 --- a/packages/network/tests/thor-client/gas/gas.solo.test.ts +++ b/packages/network/tests/thor-client/gas/gas.solo.test.ts @@ -3,6 +3,7 @@ import { estimateGasTestCases, invalidEstimateGasTestCases } from './fixture'; import { ThorClient } from '../../../src'; import { soloUrl } from '../../fixture'; import { generateRandomValidAddress } from '@vechain/sdk-core/tests/fixture'; +import { stringifyData } from '@vechain/sdk-errors'; /** * Gas module tests. @@ -70,9 +71,9 @@ describe('ThorClient - Gas Module', () => { */ invalidEstimateGasTestCases.forEach( ({ clauses, options, expectedError }) => { - test(`Should throw an error with clauses: ${JSON.stringify( + test(`Should throw an error with clauses: ${stringifyData( clauses - )}, options: ${JSON.stringify(options)}`, async () => { + )}, options: ${stringifyData(options)}`, async () => { await expect( thorSoloClient.gas.estimateGas( clauses, diff --git a/packages/network/tests/thor-client/transactions/transactions-thorest.solo.test.ts b/packages/network/tests/thor-client/transactions/transactions-thorest.solo.test.ts index f2a6ae6d4..c86424c21 100644 --- a/packages/network/tests/thor-client/transactions/transactions-thorest.solo.test.ts +++ b/packages/network/tests/thor-client/transactions/transactions-thorest.solo.test.ts @@ -1,8 +1,8 @@ import { beforeEach, describe, expect, test } from '@jest/globals'; -import { TEST_ACCOUNTS, soloUrl } from '../../fixture'; +import { soloUrl, TEST_ACCOUNTS } from '../../fixture'; import { Hex0x, TransactionHandler } from '@vechain/sdk-core'; import { sendTransactionErrors, simulateTransaction } from './fixture-thorest'; -import { InvalidDataTypeError } from '@vechain/sdk-errors'; +import { InvalidDataTypeError, stringifyData } from '@vechain/sdk-errors'; import { ThorClient } from '../../../src'; /** @@ -165,8 +165,8 @@ describe('ThorClient - Transactions Module', () => { * Compare each simulation result with the expected result. */ for (let i = 0; i < simulatedTx.length; i++) { - expect(JSON.stringify(simulatedTx[i])).toStrictEqual( - JSON.stringify(expected.simulationResults[i]) + expect(stringifyData(simulatedTx[i])).toStrictEqual( + stringifyData(expected.simulationResults[i]) ); } }); @@ -191,8 +191,8 @@ describe('ThorClient - Transactions Module', () => { expect(simulatedTx).toHaveLength(1); - expect(JSON.stringify(simulatedTx[0])).toStrictEqual( - JSON.stringify(expected.simulationResults[0]) + expect(stringifyData(simulatedTx[0])).toStrictEqual( + stringifyData(expected.simulationResults[0]) ); }); } @@ -213,8 +213,8 @@ describe('ThorClient - Transactions Module', () => { expect(simulatedTx).toHaveLength(1); - expect(JSON.stringify(simulatedTx[0])).toStrictEqual( - JSON.stringify(expected.simulationResults[0]) + expect(stringifyData(simulatedTx[0])).toStrictEqual( + stringifyData(expected.simulationResults[0]) ); }); } diff --git a/packages/network/tests/utils/http/http-client.solo.test.ts b/packages/network/tests/utils/http/http-client.solo.test.ts index 93aff5746..3233bb580 100644 --- a/packages/network/tests/utils/http/http-client.solo.test.ts +++ b/packages/network/tests/utils/http/http-client.solo.test.ts @@ -2,7 +2,7 @@ import { describe, expect, test } from '@jest/globals'; import { ZERO_ADDRESS, zeroAddressAccountDetails } from './fixture'; import { HttpClient, type HttpParams } from '../../../src'; import { soloUrl, testAccount } from '../../fixture'; -import { HTTPClientError } from '@vechain/sdk-errors'; +import { HTTPClientError, stringifyData } from '@vechain/sdk-errors'; /** * HttpClient class tests. @@ -20,8 +20,8 @@ describe('Test HttpClient class on Solo node', () => { `/accounts/${ZERO_ADDRESS}` ); - expect(JSON.stringify(response)).toEqual( - JSON.stringify(zeroAddressAccountDetails) + expect(stringifyData(response)).toEqual( + stringifyData(zeroAddressAccountDetails) ); }); diff --git a/packages/network/tests/utils/http/http-client.testnet.test.ts b/packages/network/tests/utils/http/http-client.testnet.test.ts index dc4cec90c..d56584a28 100644 --- a/packages/network/tests/utils/http/http-client.testnet.test.ts +++ b/packages/network/tests/utils/http/http-client.testnet.test.ts @@ -2,7 +2,12 @@ import { describe, expect, test } from '@jest/globals'; import { type HttpParams } from '../../../src'; import { testnetGenesisBlock } from './fixture'; import { testAccount, testNetwork } from '../../fixture'; -import { buildError, HTTP_CLIENT, HTTPClientError } from '@vechain/sdk-errors'; +import { + buildError, + HTTP_CLIENT, + HTTPClientError, + stringifyData +} from '@vechain/sdk-errors'; /** * Timeout for each test. @@ -29,8 +34,8 @@ describe('Test HttpClient class on Testnet', () => { ); // Assert that the response matches the expected firstTestnetBlock - expect(JSON.stringify(response)).toEqual( - JSON.stringify(testnetGenesisBlock) + expect(stringifyData(response)).toEqual( + stringifyData(testnetGenesisBlock) ); }, TIMEOUT diff --git a/packages/network/tests/utils/subscriptions/subscriptions.testnet.test.ts b/packages/network/tests/utils/subscriptions/subscriptions.testnet.test.ts index d7e8f8c29..18c5c402a 100644 --- a/packages/network/tests/utils/subscriptions/subscriptions.testnet.test.ts +++ b/packages/network/tests/utils/subscriptions/subscriptions.testnet.test.ts @@ -1,15 +1,16 @@ import { describe, expect, test } from '@jest/globals'; import { - getEventSubscriptionUrlTestCases, + getBeatSubscriptionUrlTestCases, getBlockSubscriptionUrlTestCases, + getEventSubscriptionUrlTestCases, getLegacyBeatSubscriptionUrlTestCases, - getBeatSubscriptionUrlTestCases, getNewTransactionsSubscriptionUrlTestCases, getVETtransfersSubscriptionUrlTestCases, testWebSocketConnection } from './fixture'; import { subscriptions } from '../../../src'; import { testnetUrl } from '../../fixture'; +import { stringifyData } from '@vechain/sdk-errors'; /** * Test suite for the Subscriptions utility methods for getting the subscription URLs @@ -28,7 +29,7 @@ describe('Subscriptions Testnet', () => { getEventSubscriptionUrlTestCases.forEach( ({ event, valuesToEncode, options, expectedURL }) => { test(`getEventSubscriptionUrl: ${ - typeof event === 'string' ? event : JSON.stringify(event) + typeof event === 'string' ? event : stringifyData(event) } with ${valuesToEncode?.toString()}`, async () => { expect( subscriptions.getEventSubscriptionUrl( @@ -54,7 +55,7 @@ describe('Subscriptions Testnet', () => { * Test the getBlockSubscriptionUrl function */ getBlockSubscriptionUrlTestCases.forEach(({ options, expectedURL }) => { - test(`getBlockSubscriptionUrl: ${JSON.stringify( + test(`getBlockSubscriptionUrl: ${stringifyData( options )}`, async () => { expect( @@ -76,7 +77,7 @@ describe('Subscriptions Testnet', () => { */ getLegacyBeatSubscriptionUrlTestCases.forEach( ({ options, expectedURL }) => { - test(`getLegacyBeatSubscriptionUrl: ${JSON.stringify( + test(`getLegacyBeatSubscriptionUrl: ${stringifyData( options )}`, async () => { expect( @@ -96,7 +97,7 @@ describe('Subscriptions Testnet', () => { * Test the getBeatSubscriptionUrl function */ getBeatSubscriptionUrlTestCases.forEach(({ options, expectedURL }) => { - test(`getBeatSubscriptionUrl: ${JSON.stringify( + test(`getBeatSubscriptionUrl: ${stringifyData( options )}`, async () => { expect( @@ -141,7 +142,7 @@ describe('Subscriptions Testnet', () => { */ getVETtransfersSubscriptionUrlTestCases.forEach( ({ options, expectedURL }) => { - test(`getVETtransfersSubscriptionUrl: ${JSON.stringify( + test(`getVETtransfersSubscriptionUrl: ${stringifyData( options )}`, async () => { expect( diff --git a/packages/network/tests/utils/thorest/helpers.unit.test.ts b/packages/network/tests/utils/thorest/helpers.unit.test.ts index 58e447632..fcd78bd7f 100644 --- a/packages/network/tests/utils/thorest/helpers.unit.test.ts +++ b/packages/network/tests/utils/thorest/helpers.unit.test.ts @@ -5,6 +5,7 @@ import { toQueryStringTestCases } from './fixture'; import { sanitizeWebsocketBaseURL, toQueryString } from '../../../src'; +import { stringifyData } from '@vechain/sdk-errors'; /** * Thorest Helpers test suite @@ -16,7 +17,7 @@ describe('Thorest Helpers', () => { * Test the toQueryString function */ toQueryStringTestCases.forEach(({ records, expected }) => { - test(`toQueryString: ${JSON.stringify(records)}`, () => { + test(`toQueryString: ${stringifyData(records)}`, () => { expect(toQueryString(records)).toEqual(expected); }); });