From c541a290793e72f98fc37a8abe0420cd41f23219 Mon Sep 17 00:00:00 2001 From: AlirezaHaghshenas Date: Fri, 6 Oct 2023 13:07:16 -0700 Subject: [PATCH] replace JSON.stringify with a safe stringify (#2690) * fix: replace JSON.stringify with a safe stringify * chore: rollback safe stringify in doc files --- .../src/lib/TestContainer.svelte | 2 +- apps/taquito-test-dapp/src/tests.ts | 10 +- example/deploy-docs-live-code-contracts.ts | 9 +- example/encode-michelson.ts | 5 +- example/example-bigmap-keys-as-deep-pair.ts | 3 +- example/example-bigmap-keys-as-pair.ts | 3 +- ...16-contract-origination-hostile-strings.ts | 3 +- example/example-tzip-16-on-chain-one.ts | 3 +- example/example-tzip-16-on-chain-two.ts | 3 +- example/example-tzip-16-storage.ts | 3 +- example/example-tzip-16.ts | 3 +- ...ct-increase-paid-storage-operation.spec.ts | 3 +- .../contract-lambda-view.spec.ts | 3 +- .../contract-override-estimate.spec.ts | 3 +- integration-tests/contract-permits.spec.ts | 5 +- ...act-update-consensus-key-operation.spec.ts | 3 +- integration-tests/pack.spec.ts | 3 +- integration-tests/prepare-operation.spec.ts | 3 +- integration-tests/rpc-nodes.spec.ts | 3 +- .../sandbox-drain-delegate-operation.spec.ts | 3 +- .../tzip16-metadata-view.spec.ts | 7 +- ...adata-on-itself-and-fetch-metadata.spec.ts | 3 +- ...adata-on-itself-and-fetch-metadata.spec.ts | 3 +- ...et-increase-paid-storage-operation.spec.ts | 3 +- package-lock.json | 30 +- .../src/taquito-beacon-wallet.ts | 4 +- packages/taquito-core/package.json | 6 + packages/taquito-core/src/errors.ts | 7 +- packages/taquito-core/src/taquito-core.ts | 3 + packages/taquito-core/test/errors.spec.ts | 3 +- .../src/taquito-http-utils.ts | 3 +- .../src/michelson/codec.ts | 4 +- .../src/schema/operation.ts | 4 +- packages/taquito-michel-codec/src/binary.ts | 57 +- .../src/micheline-emitter.ts | 3 +- .../src/micheline-parser.ts | 2 +- .../src/michelson-typecheck.ts | 45 +- .../src/michelson-validator.ts | 5 +- .../taquito-michel-codec/test/binary.spec.ts | 5 +- .../test/global-constant.spec.ts | 17 +- .../src/michelson-map.ts | 10 +- .../src/schema/errors.ts | 20 +- .../src/schema/storage.ts | 3 +- .../src/tokens/bigmap.ts | 5 +- .../src/tokens/bls12-381-fr.ts | 3 +- .../src/tokens/bls12-381-g1.ts | 3 +- .../src/tokens/bls12-381-g2.ts | 3 +- .../src/tokens/chain-id.ts | 3 +- .../src/tokens/chest-key.ts | 3 +- .../src/tokens/chest.ts | 3 +- .../src/tokens/comparable/address.ts | 11 +- .../src/tokens/comparable/int.ts | 3 +- .../src/tokens/comparable/key_hash.ts | 7 +- .../src/tokens/comparable/nat.ts | 5 +- .../tokens/comparable/tx_rollup_l2_address.ts | 11 +- .../src/tokens/contract.ts | 7 +- .../src/tokens/createToken.ts | 4 +- .../src/tokens/list.ts | 7 +- .../src/tokens/map.ts | 3 +- .../src/tokens/never.ts | 7 +- .../src/tokens/or.ts | 9 +- .../src/tokens/pair.ts | 6 +- .../src/tokens/sapling-state.ts | 7 +- .../tokens/sapling-transaction-deprecated.ts | 5 +- .../src/tokens/sapling-transaction.ts | 9 +- .../src/tokens/set.ts | 3 +- .../src/rpc-client-modules/rpc-cache.ts | 6 +- packages/taquito-rpc/test/rpc-cache.spec.ts | 5 +- packages/taquito-sapling/src/errors.ts | 4 +- .../test/sapling-state/sapling-state.spec.ts | 3 +- packages/taquito-signer/test/ecdsa.spec.ts | 537 +++++++++--------- packages/taquito-signer/test/ed25519.spec.ts | 274 ++++----- .../src/viewKind/michelson-storage-view.ts | 4 +- .../taquito/src/batch/rpc-batch-provider.ts | 5 +- .../contract-on-chain-view.ts | 4 +- packages/taquito/src/contract/errors.ts | 4 +- packages/taquito/src/injector/helper.ts | 3 +- packages/taquito/src/operations/errors.ts | 4 +- packages/taquito/src/wallet/wallet.ts | 5 +- .../contract/rpc-contract-provider.spec.ts | 7 +- .../test/parser/michel-codec-parser.spec.ts | 13 +- .../test/prepare/prepare-provider.spec.ts | 5 +- .../taquito/test/wallet/operation.spec.ts | 3 +- 83 files changed, 702 insertions(+), 634 deletions(-) diff --git a/apps/taquito-test-dapp/src/lib/TestContainer.svelte b/apps/taquito-test-dapp/src/lib/TestContainer.svelte index e033197c96..4c0dff3d61 100644 --- a/apps/taquito-test-dapp/src/lib/TestContainer.svelte +++ b/apps/taquito-test-dapp/src/lib/TestContainer.svelte @@ -325,7 +325,7 @@

{testResult.title}

{#each Object.entries(testResult.body) as [name, res]} -

{name}: {JSON.stringify(res)}

+

{name}: {stringify(res)}

{/each}
{/if} diff --git a/apps/taquito-test-dapp/src/tests.ts b/apps/taquito-test-dapp/src/tests.ts index 0904733abf..0103798ed2 100644 --- a/apps/taquito-test-dapp/src/tests.ts +++ b/apps/taquito-test-dapp/src/tests.ts @@ -281,7 +281,7 @@ const signPayload = async ( }; } catch (error) { console.log(error); - return { success: false, opHash: "", output: JSON.stringify(error) }; + return { success: false, opHash: "", output: stringify(error) }; } }; @@ -311,7 +311,7 @@ const signPayloadAndSend = async ( sigDetails: { input, formattedInput, bytes: payload.payload } }; } catch (error) { - return { success: false, opHash: "", output: JSON.stringify(error) }; + return { success: false, opHash: "", output: stringify(error) }; } }; @@ -330,11 +330,11 @@ const signFailingNoop = async ( success: true, opHash: "", output: signedPayload.signature, - sigDetails: { input, bytes: '03' + signedPayload.bytes, formattedInput: JSON.stringify(signedPayload.signedContent) }, + sigDetails: { input, bytes: '03' + signedPayload.bytes, formattedInput: stringify(signedPayload.signedContent) }, }; } catch (error) { console.log(error); - return { success: false, opHash: "", output: JSON.stringify(error) }; + return { success: false, opHash: "", output: stringify(error) }; } }; @@ -369,7 +369,7 @@ const verifySignatureWithTaquito = async ( throw "Forged signature is incorrect"; } } catch (error) { - return { success: false, opHash: "", output: JSON.stringify(error) }; + return { success: false, opHash: "", output: stringify(error) }; } }; diff --git a/example/deploy-docs-live-code-contracts.ts b/example/deploy-docs-live-code-contracts.ts index 7c342ce18f..3029171997 100644 --- a/example/deploy-docs-live-code-contracts.ts +++ b/example/deploy-docs-live-code-contracts.ts @@ -30,6 +30,7 @@ import { contractMap8pairs } from './data/contractMap8pairs'; import { char2Bytes } from '@taquito/utils'; import { fa2Contract } from '../integration-tests/data/fa2_contract'; import BigNumber from 'bignumber.js'; +import { stringify } from '@taquito/core'; const provider = 'https://ghostnet.ecadinfra.com/'; @@ -179,7 +180,7 @@ async function originateTheContracts() { contract_catalogue.forEach((value, key) => { jsonObject[key] = value; }); - console.log(JSON.stringify(jsonObject)); + console.log(stringify(jsonObject)); } } @@ -584,7 +585,7 @@ async function originateTzip16Storage() { const metadataBigMap = new MichelsonMap(); metadataBigMap.set('', char2Bytes('tezos-storage:here')); - metadataBigMap.set('here', char2Bytes(JSON.stringify(metadataJSON))); + metadataBigMap.set('here', char2Bytes(stringify(metadataJSON))); const tacoShopStorageMap = new MichelsonMap(); @@ -696,7 +697,7 @@ async function originateTzip16OnChainJSON() { try { const metadataBigMAp = new MichelsonMap(); metadataBigMAp.set('', char2Bytes('tezos-storage:here')); - metadataBigMAp.set('here', char2Bytes(JSON.stringify(metadataViewsExample1))); + metadataBigMAp.set('here', char2Bytes(stringify(metadataViewsExample1))); const op = await tezos.contract.originate({ code: contractCode, @@ -719,7 +720,7 @@ async function originateTzip16OnChainMultiply() { try { const metadataBigMAp = new MichelsonMap(); metadataBigMAp.set('', char2Bytes('tezos-storage:here')); - metadataBigMAp.set('here', char2Bytes(JSON.stringify(metadataViewsExample2))); + metadataBigMAp.set('here', char2Bytes(stringify(metadataViewsExample2))); const op = await tezos.contract.originate({ code: contractCode, diff --git a/example/encode-michelson.ts b/example/encode-michelson.ts index d581b1c566..a8b33d5a5d 100644 --- a/example/encode-michelson.ts +++ b/example/encode-michelson.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { Parser } from '@taquito/michel-codec' const example = async () => { @@ -15,11 +16,11 @@ const example = async () => { console.log('Example 1') const exp1 = p.parseMichelineExpression(ex1) - console.log(JSON.stringify(exp1)) + console.log(stringify(exp1)) console.log('Example 2') const exp2 = p.parseMichelineExpression(ex2) - console.log(JSON.stringify(exp2)) + console.log(stringify(exp2)) } catch (ex) { console.log(ex) diff --git a/example/example-bigmap-keys-as-deep-pair.ts b/example/example-bigmap-keys-as-deep-pair.ts index e2834963fc..2e352a996b 100644 --- a/example/example-bigmap-keys-as-deep-pair.ts +++ b/example/example-bigmap-keys-as-deep-pair.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { Parser } from '@taquito/michel-codec' import { Schema } from '@taquito/michelson-encoder'; @@ -19,7 +20,7 @@ const example = async () => { const parsed_storage: any = p.parseMichelineExpression(example_storage_in_michelson ) const schema = new Schema(parsed_storage); - console.log(JSON.stringify(schema.ExtractSchema(), null, 2)) + console.log(stringify(schema.ExtractSchema(), null, 2)) } catch (ex) { console.log(ex) } diff --git a/example/example-bigmap-keys-as-pair.ts b/example/example-bigmap-keys-as-pair.ts index 23e0e4d4cb..b4e0904a12 100644 --- a/example/example-bigmap-keys-as-pair.ts +++ b/example/example-bigmap-keys-as-pair.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { Parser } from '@taquito/michel-codec' import { Schema } from '@taquito/michelson-encoder'; @@ -19,7 +20,7 @@ const example = async () => { const parsed_storage: any = p.parseMichelineExpression(example_storage_in_michelson ) const schema = new Schema(parsed_storage); - console.log(JSON.stringify(schema.ExtractSchema(), null, 2)) + console.log(stringify(schema.ExtractSchema(), null, 2)) } catch (ex) { console.log(ex) } diff --git a/example/example-tzip-16-contract-origination-hostile-strings.ts b/example/example-tzip-16-contract-origination-hostile-strings.ts index f60e486533..85f3ef4134 100644 --- a/example/example-tzip-16-contract-origination-hostile-strings.ts +++ b/example/example-tzip-16-contract-origination-hostile-strings.ts @@ -3,6 +3,7 @@ import { char2Bytes } from '@taquito/utils'; import { tacoContractTzip16 } from "../integration-tests/data/modified-taco-contract" import { MichelsonMap } from "@taquito/taquito"; import { InMemorySigner } from '@taquito/signer'; +import { stringify } from '@taquito/core'; async function example() { const provider = 'https://ghostnet.ecadinfra.com'; @@ -34,7 +35,7 @@ async function example() { const metadataBigMAp = new MichelsonMap(); metadataBigMAp.set("", char2Bytes('tezos-storage:here')); - metadataBigMAp.set("here", char2Bytes(JSON.stringify(metadataJSON))) + metadataBigMAp.set("here", char2Bytes(stringify(metadataJSON))) const tacoShopStorageMap = new MichelsonMap(); diff --git a/example/example-tzip-16-on-chain-one.ts b/example/example-tzip-16-on-chain-one.ts index ee666a80b6..78d6d86530 100644 --- a/example/example-tzip-16-on-chain-one.ts +++ b/example/example-tzip-16-on-chain-one.ts @@ -2,6 +2,7 @@ import { MichelsonMap, TezosToolkit } from '@taquito/taquito'; import { contractCode, metadataViewsExample1 } from '../integration-tests/data/metadataViews'; import { char2Bytes } from '@taquito/utils'; import { InMemorySigner } from '@taquito/signer'; +import { stringify } from '@taquito/core'; async function example() { const provider = 'https://ghostnet.ecadinfra.com'; @@ -14,7 +15,7 @@ async function example() { const metadataBigMAp = new MichelsonMap(); metadataBigMAp.set("", char2Bytes('tezos-storage:here')); - metadataBigMAp.set("here", char2Bytes(JSON.stringify(metadataViewsExample1))) + metadataBigMAp.set("here", char2Bytes(stringify(metadataViewsExample1))) const op = await tezos.contract.originate({ code: contractCode, diff --git a/example/example-tzip-16-on-chain-two.ts b/example/example-tzip-16-on-chain-two.ts index f5c76f943b..6c071c160d 100644 --- a/example/example-tzip-16-on-chain-two.ts +++ b/example/example-tzip-16-on-chain-two.ts @@ -2,6 +2,7 @@ import { MichelsonMap, TezosToolkit } from '@taquito/taquito'; import { InMemorySigner } from '@taquito/signer'; import { contractCode, metadataViewsExample2 } from '../integration-tests/data/metadataViews'; import { char2Bytes } from '@taquito/utils'; +import { stringify } from '@taquito/core'; async function example() { const provider = 'https://ghostnet.ecadinfra.com'; @@ -14,7 +15,7 @@ async function example() { const metadataBigMAp = new MichelsonMap(); metadataBigMAp.set("", char2Bytes('tezos-storage:here')); - metadataBigMAp.set("here", char2Bytes(JSON.stringify(metadataViewsExample2))) + metadataBigMAp.set("here", char2Bytes(stringify(metadataViewsExample2))) const op = await tezos.contract.originate({ code: contractCode, diff --git a/example/example-tzip-16-storage.ts b/example/example-tzip-16-storage.ts index 1293e00d86..dd7ebefd93 100644 --- a/example/example-tzip-16-storage.ts +++ b/example/example-tzip-16-storage.ts @@ -2,6 +2,7 @@ import { MichelsonMap, TezosToolkit } from '@taquito/taquito'; import { tacoContractTzip16 } from "../integration-tests/data/modified-taco-contract" import { char2Bytes } from '@taquito/utils'; import { InMemorySigner } from '@taquito/signer'; +import { stringify } from '@taquito/core'; async function example() { const provider = 'https://ghostnet.ecadinfra.com'; @@ -25,7 +26,7 @@ async function example() { const metadataBigMap = new MichelsonMap(); metadataBigMap.set("", char2Bytes('tezos-storage:here')); - metadataBigMap.set("here", char2Bytes(JSON.stringify(metadataJSON))) + metadataBigMap.set("here", char2Bytes(stringify(metadataJSON))) // Ligo Taco shop contract modified to include metadata in storage // https://ide.ligolang.org/p/-uS469slzUlSm1zwNqHl1A diff --git a/example/example-tzip-16.ts b/example/example-tzip-16.ts index 6c96dfe3d6..e529fc5bd6 100644 --- a/example/example-tzip-16.ts +++ b/example/example-tzip-16.ts @@ -1,3 +1,4 @@ +import { stringify } from "@taquito/core"; import { TezosToolkit } from "@taquito/taquito"; import { tzip16, Tzip16Module } from '@taquito/tzip16'; @@ -8,7 +9,7 @@ async function example() { tezos.addExtension(new Tzip16Module()); const contract = await tezos.contract.at("KT1JZVozQHLZN7TaACnX6NGBxUkhNjn6tmTB", tzip16) const metadata = await contract.tzip16().getMetadata(); - console.log(JSON.stringify(metadata, null, 2)); + console.log(stringify(metadata, null, 2)); } catch (ex) { console.error(ex); diff --git a/integration-tests/contract-increase-paid-storage-operation.spec.ts b/integration-tests/contract-increase-paid-storage-operation.spec.ts index f39f4f571a..84ea964c98 100644 --- a/integration-tests/contract-increase-paid-storage-operation.spec.ts +++ b/integration-tests/contract-increase-paid-storage-operation.spec.ts @@ -1,6 +1,7 @@ import { CONFIGS } from './config'; import { OpKind } from '@taquito/taquito'; import { ligoSample } from './data/ligo-simple-contract'; +import { stringify } from '@taquito/core'; CONFIGS().forEach(({ lib, rpc, setup }) => { @@ -27,7 +28,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => { simpleContractAddress = op.contractAddress!; } catch(e) { - console.log(JSON.stringify(e)); + console.log(stringify(e)); } done(); }); diff --git a/integration-tests/contract-lambda-view.spec.ts b/integration-tests/contract-lambda-view.spec.ts index 214e772e43..e0d016c4c8 100644 --- a/integration-tests/contract-lambda-view.spec.ts +++ b/integration-tests/contract-lambda-view.spec.ts @@ -3,10 +3,11 @@ import { CONFIGS } from './config'; import { tzip7Contract } from './data/tzip_7_contract'; import { testContract } from './data/test_lambda_view'; import { fa2Contract } from './data/fa2_contract'; +import { stringify } from '@taquito/core'; CONFIGS().forEach(({ lib, rpc, setup }) => { const Tezos = lib; - const toJSON = (x: any) => JSON.parse(JSON.stringify(x)); + const toJSON = (x: any) => JSON.parse(stringify(x)); describe(`Test contract with lambda view trough contract api using: ${rpc}`, () => { beforeEach(async done => { diff --git a/integration-tests/contract-override-estimate.spec.ts b/integration-tests/contract-override-estimate.spec.ts index 3c29eddcc8..3d2bc6d345 100644 --- a/integration-tests/contract-override-estimate.spec.ts +++ b/integration-tests/contract-override-estimate.spec.ts @@ -1,3 +1,4 @@ +import { stringify } from "@taquito/core"; import { CONFIGS } from "./config"; import { InvalidEstimateValueError } from '@taquito/taquito'; @@ -14,7 +15,7 @@ CONFIGS().forEach(({ lib, rpc, setup, createAddress }) => { const account = await createAddress(); pkh = await account.signer.publicKeyHash(); } catch(e) { - console.log(JSON.stringify(e)); + console.log(stringify(e)); } done(); diff --git a/integration-tests/contract-permits.spec.ts b/integration-tests/contract-permits.spec.ts index 82a3ea0743..5c6849f599 100644 --- a/integration-tests/contract-permits.spec.ts +++ b/integration-tests/contract-permits.spec.ts @@ -6,6 +6,7 @@ import { permit_fa12_smartpy } from './data/permit_fa12_smartpy'; import { buf2hex, char2Bytes, hex2buf } from '@taquito/utils'; import { tzip16, Tzip16Module } from '@taquito/tzip16'; import { packDataBytes } from "@taquito/michel-codec" +import { stringify } from '@taquito/core'; const blake = require('blakejs'); const bob_address = 'tz1Xk7HkSwHv6dTEgR7E2WC2yFj4cyyuj2Gh'; @@ -329,9 +330,9 @@ CONFIGS().forEach(({ lib, rpc, setup, createAddress }) => { try { await fail_contract.methods.transfer(bootstrap3_address, bootstrap4_address, 1).send(); } catch (errors) { - let jsonStr: string = JSON.stringify(errors); + let jsonStr: string = stringify(errors); let jsonObj = JSON.parse(jsonStr); - let error_code = JSON.stringify(jsonObj.errors[1].with.int); + let error_code = stringify(jsonObj.errors[1].with.int); expect((error_code = '26')); } diff --git a/integration-tests/contract-update-consensus-key-operation.spec.ts b/integration-tests/contract-update-consensus-key-operation.spec.ts index c057af3afb..38bcec7549 100644 --- a/integration-tests/contract-update-consensus-key-operation.spec.ts +++ b/integration-tests/contract-update-consensus-key-operation.spec.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { CONFIGS } from './config'; CONFIGS().forEach(({ lib, rpc, setup, createAddress }) => { @@ -21,7 +22,7 @@ CONFIGS().forEach(({ lib, rpc, setup, createAddress }) => { await register.confirmation(); } catch(e) { - console.log(JSON.stringify(e)); + console.log(stringify(e)); } done(); diff --git a/integration-tests/pack.spec.ts b/integration-tests/pack.spec.ts index 846453e133..d503f1c4e4 100644 --- a/integration-tests/pack.spec.ts +++ b/integration-tests/pack.spec.ts @@ -4,6 +4,7 @@ import { MichelsonType, MichelsonData, ProtocolID, packDataBytes } from "@taquit import { MichelsonV1Expression } from "@taquito/rpc"; import fs from "fs"; import path from "path"; +import { stringify } from "@taquito/core"; interface TypedTestData { type?: MichelsonType; @@ -29,7 +30,7 @@ CONFIGS().forEach(({ rpc, protocol }) => { describe("Test pack", () => { for (const s of src) { const def = (s.proto === undefined || s.proto === protocol) ? test : test.skip; - def(`Verify that .pack for local pack will return same result as for network pack: ${JSON.stringify(s.data)} (${rpc})`, async done => { + def(`Verify that .pack for local pack will return same result as for network pack: ${stringify(s.data)} (${rpc})`, async done => { const local = packDataBytes(s.data, s.type); const rpcResult = await Tezos.rpc.packData({ data: s.data, type: s.type as MichelsonV1Expression }, { block: "head" }) expect(local.bytes).toEqual(rpcResult.packed); diff --git a/integration-tests/prepare-operation.spec.ts b/integration-tests/prepare-operation.spec.ts index ad127adeef..c6dade1525 100644 --- a/integration-tests/prepare-operation.spec.ts +++ b/integration-tests/prepare-operation.spec.ts @@ -2,6 +2,7 @@ import { OperationContentsBallot, OperationContentsTransaction } from '@taquito/ import { OpKind } from '@taquito/taquito'; import { CONFIGS } from './config'; import { LocalForger } from '@taquito/local-forging'; +import { stringify } from '@taquito/core'; CONFIGS().forEach(({ lib, setup, protocol, createAddress }) => { const Tezos = lib; @@ -26,7 +27,7 @@ CONFIGS().forEach(({ lib, setup, protocol, createAddress }) => { contractAddress = op.contractAddress!; } catch(e: any) { - console.log('Unable to originate contract: ', JSON.stringify(e)); + console.log('Unable to originate contract: ', stringify(e)); } done(); diff --git a/integration-tests/rpc-nodes.spec.ts b/integration-tests/rpc-nodes.spec.ts index a90cb9042d..091688ac6e 100644 --- a/integration-tests/rpc-nodes.spec.ts +++ b/integration-tests/rpc-nodes.spec.ts @@ -5,6 +5,7 @@ import { encodeExpr } from '@taquito/utils'; import { Schema } from '@taquito/michelson-encoder'; import { tokenBigmapCode, tokenBigmapStorage } from './data/token_bigmap'; import { ticketCode, ticketStorage } from './data/code_with_ticket'; +import { stringify } from '@taquito/core'; CONFIGS().forEach( ({ @@ -38,7 +39,7 @@ CONFIGS().forEach( const ticketCallOp = await ticketContract.methods.auto_call(1).send(); await ticketCallOp.confirmation(); } catch (e) { - console.log('Failed to originate ticket contract', JSON.stringify(e)); + console.log('Failed to originate ticket contract', stringify(e)); } done(); diff --git a/integration-tests/sandbox-drain-delegate-operation.spec.ts b/integration-tests/sandbox-drain-delegate-operation.spec.ts index bbe51c5e27..9051788792 100644 --- a/integration-tests/sandbox-drain-delegate-operation.spec.ts +++ b/integration-tests/sandbox-drain-delegate-operation.spec.ts @@ -1,5 +1,6 @@ import { TezosToolkit } from "@taquito/taquito"; import { CONFIGS, sleep } from "./config"; +import { stringify } from "@taquito/core"; CONFIGS().forEach(({ lib, rpc, protocol, setup, createAddress }) => { const Tezos = lib; @@ -36,7 +37,7 @@ CONFIGS().forEach(({ lib, rpc, protocol, setup, createAddress }) => { await sleep(((constants.preserved_cycles + 2) * constants.blocks_per_cycle * (constants.minimal_block_delay!.toNumber())) * 1000); } catch (e) { - console.log(JSON.stringify(e)); + console.log(stringify(e)); } done(); }) diff --git a/integration-tests/tzip16-metadata-view.spec.ts b/integration-tests/tzip16-metadata-view.spec.ts index 2d4cb83e59..8baa08ff60 100644 --- a/integration-tests/tzip16-metadata-view.spec.ts +++ b/integration-tests/tzip16-metadata-view.spec.ts @@ -2,6 +2,7 @@ import { CONFIGS } from './config'; import { MichelsonMap } from '@taquito/taquito'; import { tzip16, Tzip16Module, char2Bytes } from '@taquito/tzip16'; import { contractCode, metadataViewsExample1, metadataViewsExample2 } from './data/metadataViews'; +import { stringify } from '@taquito/core'; CONFIGS().forEach(({ lib, rpc, setup }) => { const Tezos = lib; @@ -17,7 +18,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => { const metadataBigMAp = new MichelsonMap(); metadataBigMAp.set("", char2Bytes('tezos-storage:here')); - metadataBigMAp.set("here", char2Bytes(JSON.stringify(metadataViewsExample1))) + metadataBigMAp.set("here", char2Bytes(stringify(metadataViewsExample1))) const op = await Tezos.contract.originate({ code: contractCode, @@ -62,7 +63,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => { const metadataBigMAp = new MichelsonMap(); metadataBigMAp.set("", char2Bytes('tezos-storage:here')); - metadataBigMAp.set("here", char2Bytes(JSON.stringify(metadataViewsExample2))) + metadataBigMAp.set("here", char2Bytes(stringify(metadataViewsExample2))) const op = await Tezos.contract.originate({ code: contractCode, @@ -92,7 +93,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => { expect(viewCallBalanceResult.toString()).toEqual('0'); const viewIdentityResult = await metadataViews['the-identity']().executeView(1, 'test', 200000); - expect(JSON.stringify(viewIdentityResult)).toEqual(`{"arg_zero":"1","arg_one_result":"test","arg_two":"200000"}`); + expect(stringify(viewIdentityResult)).toEqual(`{"arg_zero":"1","arg_one_result":"test","arg_two":"200000"}`); const viewContractAddressResult = await metadataViews['get-contract-address']().executeView(); expect(viewContractAddressResult.toString()).toEqual(contractAddress); diff --git a/integration-tests/tzip16-originate-contracts-with-metadata-on-itself-and-fetch-metadata.spec.ts b/integration-tests/tzip16-originate-contracts-with-metadata-on-itself-and-fetch-metadata.spec.ts index a075f9b647..567531b6cc 100644 --- a/integration-tests/tzip16-originate-contracts-with-metadata-on-itself-and-fetch-metadata.spec.ts +++ b/integration-tests/tzip16-originate-contracts-with-metadata-on-itself-and-fetch-metadata.spec.ts @@ -2,6 +2,7 @@ import { CONFIGS } from "./config"; import { tzip16, Tzip16Module, char2Bytes } from '@taquito/tzip16'; import { tacoContractTzip16 } from "./data/modified-taco-contract" import { MichelsonMap } from "@taquito/taquito"; +import { stringify } from "@taquito/core"; CONFIGS().forEach(({ lib, rpc, setup }) => { const Tezos = lib; @@ -30,7 +31,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => { const metadataBigMap = new MichelsonMap(); metadataBigMap.set("", char2Bytes('tezos-storage:here')); - metadataBigMap.set("here", char2Bytes(JSON.stringify(metadataJSON))) + metadataBigMap.set("here", char2Bytes(stringify(metadataJSON))) // Ligo Taco shop contract modified to include metadata in storage // https://ide.ligolang.org/p/-uS469slzUlSm1zwNqHl1A diff --git a/integration-tests/tzip16-originate-wallets-with-metadata-on-itself-and-fetch-metadata.spec.ts b/integration-tests/tzip16-originate-wallets-with-metadata-on-itself-and-fetch-metadata.spec.ts index 6634e07a66..6493a16aa5 100644 --- a/integration-tests/tzip16-originate-wallets-with-metadata-on-itself-and-fetch-metadata.spec.ts +++ b/integration-tests/tzip16-originate-wallets-with-metadata-on-itself-and-fetch-metadata.spec.ts @@ -2,6 +2,7 @@ import { CONFIGS } from "./config"; import { tzip16, Tzip16Module, char2Bytes } from '@taquito/tzip16'; import { tacoContractTzip16 } from "./data/modified-taco-contract" import { MichelsonMap } from "@taquito/taquito"; +import { stringify } from "@taquito/core"; CONFIGS().forEach(({ lib, rpc, setup }) => { const Tezos = lib; @@ -30,7 +31,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => { const metadataBigMAp = new MichelsonMap(); metadataBigMAp.set("", char2Bytes('tezos-storage:here')); - metadataBigMAp.set("here", char2Bytes(JSON.stringify(metadataJSON))) + metadataBigMAp.set("here", char2Bytes(stringify(metadataJSON))) // Ligo Taco shop contract modified to include metadata in storage // https://ide.ligolang.org/p/-uS469slzUlSm1zwNqHl1A diff --git a/integration-tests/wallet-increase-paid-storage-operation.spec.ts b/integration-tests/wallet-increase-paid-storage-operation.spec.ts index ffe26375b4..e9fa5f4f6b 100644 --- a/integration-tests/wallet-increase-paid-storage-operation.spec.ts +++ b/integration-tests/wallet-increase-paid-storage-operation.spec.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { CONFIGS } from './config'; CONFIGS().forEach(({ lib, rpc, setup }) => { @@ -25,7 +26,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => { simpleContractAddress = (await op.contract()).address } catch(e) { - console.log(JSON.stringify(e)); + console.log(stringify(e)); } done(); }); diff --git a/package-lock.json b/package-lock.json index 42a7627aed..e0a5c45dc4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6234,6 +6234,12 @@ "integrity": "sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==", "dev": true }, + "node_modules/@types/json-stringify-safe": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@types/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", + "integrity": "sha512-fSRMt/jgdsBMPHoJ0GxivTdmo2HhBhubqLssKIsu9NgtvCZJ0haHjo24tfU/0nrkYZKbyTLw5GoTxWg8ExzIsw==", + "dev": true + }, "node_modules/@types/minimatch": { "version": "3.0.5", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.5.tgz", @@ -16969,8 +16975,7 @@ "node_modules/json-stringify-safe": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", - "integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==", - "dev": true + "integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==" }, "node_modules/json5": { "version": "2.2.3", @@ -26579,6 +26584,12 @@ "name": "@taquito/core", "version": "17.3.1", "license": "Apache-2.0", + "dependencies": { + "json-stringify-safe": "^5.0.1" + }, + "devDependencies": { + "@types/json-stringify-safe": "^5.0.1" + }, "engines": { "node": ">=16" } @@ -32146,7 +32157,11 @@ } }, "@taquito/core": { - "version": "file:packages/taquito-core" + "version": "file:packages/taquito-core", + "requires": { + "@types/json-stringify-safe": "*", + "json-stringify-safe": "^5.0.1" + } }, "@taquito/example": { "version": "file:example", @@ -33199,6 +33214,12 @@ "integrity": "sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==", "dev": true }, + "@types/json-stringify-safe": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@types/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", + "integrity": "sha512-fSRMt/jgdsBMPHoJ0GxivTdmo2HhBhubqLssKIsu9NgtvCZJ0haHjo24tfU/0nrkYZKbyTLw5GoTxWg8ExzIsw==", + "dev": true + }, "@types/minimatch": { "version": "3.0.5", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.5.tgz", @@ -41628,8 +41649,7 @@ "json-stringify-safe": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", - "integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==", - "dev": true + "integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==" }, "json5": { "version": "2.2.3", diff --git a/packages/taquito-beacon-wallet/src/taquito-beacon-wallet.ts b/packages/taquito-beacon-wallet/src/taquito-beacon-wallet.ts index 8035ed6329..e8ba8bf087 100644 --- a/packages/taquito-beacon-wallet/src/taquito-beacon-wallet.ts +++ b/packages/taquito-beacon-wallet/src/taquito-beacon-wallet.ts @@ -25,7 +25,7 @@ import { WalletTransferParams, } from '@taquito/taquito'; import { buf2hex, hex2buf, mergebuf } from '@taquito/utils'; -import { UnsupportedActionError } from '@taquito/core'; +import { UnsupportedActionError, stringify } from '@taquito/core'; export { VERSION } from './version'; export { BeaconWalletNotInitialized, MissingRequiredScopes } from './errors'; @@ -218,7 +218,7 @@ export class BeaconWallet implements WalletProvider { return SigningType.OPERATION; } } - throw new Error(`Invalid watermark ${JSON.stringify(watermark)}`); + throw new Error(`Invalid watermark ${stringify(watermark)}`); } async getPK() { diff --git a/packages/taquito-core/package.json b/packages/taquito-core/package.json index 34dc6a735d..6f8eb5c8c6 100644 --- a/packages/taquito-core/package.json +++ b/packages/taquito-core/package.json @@ -59,5 +59,11 @@ "collectCoverageFrom": [ "src/**/*.{js,ts}" ] + }, + "dependencies": { + "json-stringify-safe": "^5.0.1" + }, + "devDependencies": { + "@types/json-stringify-safe": "^5.0.1" } } diff --git a/packages/taquito-core/src/errors.ts b/packages/taquito-core/src/errors.ts index 49b5aca469..9018ba0442 100644 --- a/packages/taquito-core/src/errors.ts +++ b/packages/taquito-core/src/errors.ts @@ -1,6 +1,9 @@ // ========================================================================================== // parent error classes for Taquito // ========================================================================================== + +import { stringify } from './taquito-core'; + /** * @category Error * @description Parent error class all taquito errors to extend from @@ -136,9 +139,9 @@ export class InvalidViewParameterError extends ParameterValidationError { ) { super(); this.name = 'InvalidViewParameterError'; - this.message = `Invalid view arguments ${JSON.stringify( + this.message = `Invalid view arguments ${stringify( args - )} received for name "${viewName}" expecting one of the following signatures ${JSON.stringify( + )} received for name "${viewName}" expecting one of the following signatures ${stringify( sigs )}.`; } diff --git a/packages/taquito-core/src/taquito-core.ts b/packages/taquito-core/src/taquito-core.ts index 5ff782cf5a..f54c0922a4 100644 --- a/packages/taquito-core/src/taquito-core.ts +++ b/packages/taquito-core/src/taquito-core.ts @@ -3,4 +3,7 @@ * @module @taquito/core */ +import stringify from 'json-stringify-safe'; + export * from './errors'; +export { stringify }; diff --git a/packages/taquito-core/test/errors.spec.ts b/packages/taquito-core/test/errors.spec.ts index e084b7d16b..205f42c10b 100644 --- a/packages/taquito-core/test/errors.spec.ts +++ b/packages/taquito-core/test/errors.spec.ts @@ -22,6 +22,7 @@ import { InvalidOperationKindError, DeprecationError, ProhibitedActionError, + stringify, } from '../src/taquito-core'; describe('parent errors classes', () => { @@ -144,7 +145,7 @@ describe('common error classes', () => { expect(error).toBeInstanceOf(ParameterValidationError); expect(error).toBeInstanceOf(InvalidViewParameterError); expect(error.message).toContain( - `Invalid view arguments "bar" received for name "foo" expecting one of the following signatures ${JSON.stringify( + `Invalid view arguments "bar" received for name "foo" expecting one of the following signatures ${stringify( { parameter: 'nat', result: 'nat' } )}` ); diff --git a/packages/taquito-http-utils/src/taquito-http-utils.ts b/packages/taquito-http-utils/src/taquito-http-utils.ts index a56f8b3623..0d09cfd9ac 100644 --- a/packages/taquito-http-utils/src/taquito-http-utils.ts +++ b/packages/taquito-http-utils/src/taquito-http-utils.ts @@ -7,6 +7,7 @@ import fetchAdapter from './fetch-adapter'; import { STATUS_CODE } from './status_code'; import axios from 'axios'; import { HttpRequestFailed, HttpResponseError } from './errors'; +import { stringify } from '@taquito/core'; const isNode = typeof process !== 'undefined' && !!process?.versions?.node; @@ -113,7 +114,7 @@ export class HttpBackend { let errorData; if (typeof err.response.data === 'object') { - errorData = JSON.stringify(err.response.data); + errorData = stringify(err.response.data); } else { errorData = err.response.data; } diff --git a/packages/taquito-local-forging/src/michelson/codec.ts b/packages/taquito-local-forging/src/michelson/codec.ts index b7cd2517b6..dca033c5af 100644 --- a/packages/taquito-local-forging/src/michelson/codec.ts +++ b/packages/taquito-local-forging/src/michelson/codec.ts @@ -5,7 +5,7 @@ import { Encoder } from '../taquito-local-forging'; import { opMappingReverse, opMapping } from '../constants'; import { pad } from '../utils'; import { UnexpectedMichelsonValueError } from '../errors'; -import { InvalidHexStringError } from '@taquito/core'; +import { InvalidHexStringError, stringify } from '@taquito/core'; export type PrimValue = { prim: string; args?: MichelsonValue[]; annots?: string[] }; export type BytesValue = { bytes: string }; @@ -67,7 +67,7 @@ export const valueEncoder: Encoder = (value: MichelsonValue) => return intEncoder(value); } - throw new UnexpectedMichelsonValueError(JSON.stringify(value)); + throw new UnexpectedMichelsonValueError(stringify(value)); }; export const valueDecoder: Decoder = (value: Uint8ArrayConsumer) => { diff --git a/packages/taquito-local-forging/src/schema/operation.ts b/packages/taquito-local-forging/src/schema/operation.ts index 54563bc1ce..fca9c6d7b2 100644 --- a/packages/taquito-local-forging/src/schema/operation.ts +++ b/packages/taquito-local-forging/src/schema/operation.ts @@ -1,7 +1,7 @@ import { Decoder } from '../decoder'; import { Uint8ArrayConsumer } from '../uint8array-consumer'; import { CODEC, kindMapping, kindMappingReverse } from '../constants'; -import { InvalidOperationKindError } from '@taquito/core'; +import { InvalidOperationKindError, stringify } from '@taquito/core'; import { OperationDecodingError, OperationEncodingError, @@ -241,7 +241,7 @@ export const schemaEncoder = if (!Array.isArray(values)) { throw new OperationEncodingError( - `Invalid operation value "${JSON.stringify( + `Invalid operation value "${stringify( values )}" of key "${key}, expected value to be Array.` ); diff --git a/packages/taquito-michel-codec/src/binary.ts b/packages/taquito-michel-codec/src/binary.ts index 158a8861a3..d8900cf9da 100644 --- a/packages/taquito-michel-codec/src/binary.ts +++ b/packages/taquito-michel-codec/src/binary.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { BytesLiteral, Expr, IntLiteral, Prim } from './micheline'; import { MichelsonTypeID, @@ -754,7 +755,7 @@ const getWriteTransformFunc = (t: MichelsonType): WriteTransformFunc => { if (isPairType(t)) { return (d: Expr) => { if (!isPairData(d)) { - throw new MichelsonTypeError(t, `pair expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `pair expected: ${stringify(d)}`, d); } assertDataListIfAny(d); // combs aren't used in pack format @@ -775,7 +776,7 @@ const getWriteTransformFunc = (t: MichelsonType): WriteTransformFunc => { case 'or': return (d: Expr) => { if (!isOrData(d)) { - throw new MichelsonTypeError(t, `or expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `or expected: ${stringify(d)}`, d); } return [ d, @@ -788,7 +789,7 @@ const getWriteTransformFunc = (t: MichelsonType): WriteTransformFunc => { case 'option': return (d: Expr) => { if (!isOptionData(d)) { - throw new MichelsonTypeError(t, `option expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `option expected: ${stringify(d)}`, d); } return [ d, @@ -808,7 +809,7 @@ const getWriteTransformFunc = (t: MichelsonType): WriteTransformFunc => { case 'set': return (d: Expr) => { if (!Array.isArray(d)) { - throw new MichelsonTypeError(t, `${t.prim} expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `${t.prim} expected: ${stringify(d)}`, d); } return [ d, @@ -823,7 +824,7 @@ const getWriteTransformFunc = (t: MichelsonType): WriteTransformFunc => { case 'map': return (d: Expr) => { if (!Array.isArray(d)) { - throw new MichelsonTypeError(t, `map expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `map expected: ${stringify(d)}`, d); } return [ d, @@ -831,11 +832,7 @@ const getWriteTransformFunc = (t: MichelsonType): WriteTransformFunc => { for (const _elt of d) { yield (elt: Expr) => { if (!('prim' in elt) || elt.prim !== 'Elt') { - throw new MichelsonTypeError( - t, - `map element expected: ${JSON.stringify(elt)}`, - elt - ); + throw new MichelsonTypeError(t, `map element expected: ${stringify(elt)}`, elt); } return [ elt, @@ -854,7 +851,7 @@ const getWriteTransformFunc = (t: MichelsonType): WriteTransformFunc => { case 'chain_id': return (d: Expr) => { if (!('bytes' in d) && !('string' in d)) { - throw new MichelsonTypeError(t, `chain id expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `chain id expected: ${stringify(d)}`, d); } let bytes: BytesLiteral; if ('string' in d) { @@ -872,7 +869,7 @@ const getWriteTransformFunc = (t: MichelsonType): WriteTransformFunc => { case 'signature': return (d: Expr) => { if (!('bytes' in d) && !('string' in d)) { - throw new MichelsonTypeError(t, `signature expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `signature expected: ${stringify(d)}`, d); } let bytes: BytesLiteral; if ('string' in d) { @@ -896,7 +893,7 @@ const getWriteTransformFunc = (t: MichelsonType): WriteTransformFunc => { case 'key_hash': return (d: Expr) => { if (!('bytes' in d) && !('string' in d)) { - throw new MichelsonTypeError(t, `key hash expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `key hash expected: ${stringify(d)}`, d); } let bytes: BytesLiteral; if ('string' in d) { @@ -921,7 +918,7 @@ const getWriteTransformFunc = (t: MichelsonType): WriteTransformFunc => { case 'key': return (d: Expr) => { if (!('bytes' in d) && !('string' in d)) { - throw new MichelsonTypeError(t, `public key expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `public key expected: ${stringify(d)}`, d); } let bytes: BytesLiteral; if ('string' in d) { @@ -946,7 +943,7 @@ const getWriteTransformFunc = (t: MichelsonType): WriteTransformFunc => { case 'address': return (d: Expr) => { if (!('bytes' in d) && !('string' in d)) { - throw new MichelsonTypeError(t, `address expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `address expected: ${stringify(d)}`, d); } let bytes: BytesLiteral; if ('string' in d) { @@ -976,7 +973,7 @@ const getWriteTransformFunc = (t: MichelsonType): WriteTransformFunc => { case 'timestamp': return (d: Expr) => { if (!('string' in d) && !('int' in d)) { - throw new MichelsonTypeError(t, `timestamp expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `timestamp expected: ${stringify(d)}`, d); } let int: IntLiteral; if ('string' in d) { @@ -1095,7 +1092,7 @@ const getReadTransformFuncs = (t: MichelsonType): ReadTransformFuncs => { return [ (d: Expr) => { if (!isPairData(d)) { - throw new MichelsonTypeError(t, `pair expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `pair expected: ${stringify(d)}`, d); } const tc = unpackComb('pair', t); return (function* () { @@ -1113,7 +1110,7 @@ const getReadTransformFuncs = (t: MichelsonType): ReadTransformFuncs => { return [ (d: Expr) => { if (!isOrData(d)) { - throw new MichelsonTypeError(t, `or expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `or expected: ${stringify(d)}`, d); } return (function* () { yield getReadTransformFuncs(t.args[d.prim === 'Left' ? 0 : 1]); @@ -1126,7 +1123,7 @@ const getReadTransformFuncs = (t: MichelsonType): ReadTransformFuncs => { return [ (d: Expr) => { if (!isOptionData(d)) { - throw new MichelsonTypeError(t, `option expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `option expected: ${stringify(d)}`, d); } return (function* () { // TODO: refactor and remove ts-ignore @@ -1145,7 +1142,7 @@ const getReadTransformFuncs = (t: MichelsonType): ReadTransformFuncs => { return [ (d: Expr) => { if (!Array.isArray(d)) { - throw new MichelsonTypeError(t, `${t.prim} expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `${t.prim} expected: ${stringify(d)}`, d); } return (function* () { while (true) { @@ -1160,18 +1157,14 @@ const getReadTransformFuncs = (t: MichelsonType): ReadTransformFuncs => { return [ (d: Expr): IterableIterator => { if (!Array.isArray(d)) { - throw new MichelsonTypeError(t, `map expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `map expected: ${stringify(d)}`, d); } return (function* (): Generator { while (true) { yield [ (elt: Expr) => { if (!('prim' in elt) || elt.prim !== 'Elt') { - throw new MichelsonTypeError( - t, - `map element expected: ${JSON.stringify(elt)}`, - elt - ); + throw new MichelsonTypeError(t, `map element expected: ${stringify(elt)}`, elt); } return (function* () { for (const a of t.args) { @@ -1192,7 +1185,7 @@ const getReadTransformFuncs = (t: MichelsonType): ReadTransformFuncs => { () => [][Symbol.iterator](), (d: Expr) => { if (!('bytes' in d) && !('string' in d)) { - throw new MichelsonTypeError(t, `chain id expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `chain id expected: ${stringify(d)}`, d); } if ('string' in d) { return d; @@ -1210,7 +1203,7 @@ const getReadTransformFuncs = (t: MichelsonType): ReadTransformFuncs => { () => [][Symbol.iterator](), (d: Expr) => { if (!('bytes' in d) && !('string' in d)) { - throw new MichelsonTypeError(t, `signature expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `signature expected: ${stringify(d)}`, d); } if ('string' in d) { return d; @@ -1228,7 +1221,7 @@ const getReadTransformFuncs = (t: MichelsonType): ReadTransformFuncs => { () => [][Symbol.iterator](), (d: Expr) => { if (!('bytes' in d) && !('string' in d)) { - throw new MichelsonTypeError(t, `key hash expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `key hash expected: ${stringify(d)}`, d); } if ('string' in d) { return d; @@ -1251,7 +1244,7 @@ const getReadTransformFuncs = (t: MichelsonType): ReadTransformFuncs => { () => [][Symbol.iterator](), (d: Expr) => { if (!('bytes' in d) && !('string' in d)) { - throw new MichelsonTypeError(t, `public key expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `public key expected: ${stringify(d)}`, d); } if ('string' in d) { return d; @@ -1271,7 +1264,7 @@ const getReadTransformFuncs = (t: MichelsonType): ReadTransformFuncs => { () => [][Symbol.iterator](), (d: Expr) => { if (!('bytes' in d) && !('string' in d)) { - throw new MichelsonTypeError(t, `address expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `address expected: ${stringify(d)}`, d); } if ('string' in d) { return d; @@ -1294,7 +1287,7 @@ const getReadTransformFuncs = (t: MichelsonType): ReadTransformFuncs => { () => [][Symbol.iterator](), (d: Expr) => { if (!('int' in d) && !('string' in d)) { - throw new MichelsonTypeError(t, `address expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `address expected: ${stringify(d)}`, d); } if ('string' in d) { return d; diff --git a/packages/taquito-michel-codec/src/micheline-emitter.ts b/packages/taquito-michel-codec/src/micheline-emitter.ts index f52a1910c4..282274438a 100644 --- a/packages/taquito-michel-codec/src/micheline-emitter.ts +++ b/packages/taquito-michel-codec/src/micheline-emitter.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { Expr, Prim, sourceReference } from './micheline'; export interface FormatOptions { @@ -65,7 +66,7 @@ function emitExpr(node: Expr, f: Formatter, foldMacros: boolean): string { if (Array.isArray(node)) { return emitSeq(node, f, foldMacros); } else if ('string' in node) { - return JSON.stringify(node.string); + return stringify(node.string); } else if ('int' in node) { return node.int; } else if ('bytes' in node) { diff --git a/packages/taquito-michel-codec/src/micheline-parser.ts b/packages/taquito-michel-codec/src/micheline-parser.ts index 2846e0f3ee..aba0dc5c31 100644 --- a/packages/taquito-michel-codec/src/micheline-parser.ts +++ b/packages/taquito-michel-codec/src/micheline-parser.ts @@ -108,7 +108,7 @@ export interface ParserOptions extends ProtocolOptions { * const p = new Parser(); * * const exp = p.parseMichelineExpression(src); - * console.log(JSON.stringify(exp)); + * console.log(stringify(exp)); * ``` */ export class Parser { diff --git a/packages/taquito-michel-codec/src/michelson-typecheck.ts b/packages/taquito-michel-codec/src/michelson-typecheck.ts index 0b105c0afc..e410b76eee 100644 --- a/packages/taquito-michel-codec/src/michelson-typecheck.ts +++ b/packages/taquito-michel-codec/src/michelson-typecheck.ts @@ -49,6 +49,7 @@ import { assertDataListIfAny, } from './michelson-validator'; import { ParserOptions } from './micheline-parser'; +import { stringify } from '@taquito/core'; export interface Context extends ParserOptions { contract?: MichelsonContract; @@ -302,7 +303,7 @@ function _compareMichelsonData(t: MichelsonType, a: MichelsonData, b: MichelsonD // Unlikely, types are expected to be verified before the function call throw new MichelsonTypeError( t, - `${typeID(t)}: not comparable values: ${JSON.stringify(a)}, ${JSON.stringify(b)}`, + `${typeID(t)}: not comparable values: ${stringify(a)}, ${stringify(b)}`, undefined ); } @@ -330,7 +331,7 @@ function assertDataValidInternal(d: MichelsonData, t: MichelsonType, ctx: Contex assertDataValidInternal(dc.args[1], tc.args[1], ctx); return; } - throw new MichelsonTypeError(t, `pair expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `pair expected: ${stringify(d)}`, d); } switch (t.prim) { @@ -339,20 +340,20 @@ function assertDataValidInternal(d: MichelsonData, t: MichelsonType, ctx: Contex if ('int' in d && isDecimal(d.int)) { return; } - throw new MichelsonTypeError(t, `integer value expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `integer value expected: ${stringify(d)}`, d); case 'nat': case 'mutez': if ('int' in d && isNatural(d.int)) { return; } - throw new MichelsonTypeError(t, `natural value expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `natural value expected: ${stringify(d)}`, d); case 'string': if ('string' in d) { return; } - throw new MichelsonTypeError(t, `string value expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `string value expected: ${stringify(d)}`, d); case 'bytes': case 'bls12_381_g1': @@ -360,13 +361,13 @@ function assertDataValidInternal(d: MichelsonData, t: MichelsonType, ctx: Contex if ('bytes' in d && parseBytes(d.bytes) !== null) { return; } - throw new MichelsonTypeError(t, `bytes value expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `bytes value expected: ${stringify(d)}`, d); case 'bool': if ('prim' in d && (d.prim === 'True' || d.prim === 'False')) { return; } - throw new MichelsonTypeError(t, `boolean value expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `boolean value expected: ${stringify(d)}`, d); case 'key_hash': if ( @@ -387,13 +388,13 @@ function assertDataValidInternal(d: MichelsonData, t: MichelsonType, ctx: Contex // ignore message } } - throw new MichelsonTypeError(t, `key hash expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `key hash expected: ${stringify(d)}`, d); case 'timestamp': if (('string' in d || 'int' in d) && parseDate(d) !== null) { return; } - throw new MichelsonTypeError(t, `timestamp expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `timestamp expected: ${stringify(d)}`, d); case 'address': if ('string' in d) { @@ -424,7 +425,7 @@ function assertDataValidInternal(d: MichelsonData, t: MichelsonType, ctx: Contex // ignore message } } - throw new MichelsonTypeError(t, `address expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `address expected: ${stringify(d)}`, d); case 'key': if ( @@ -441,13 +442,13 @@ function assertDataValidInternal(d: MichelsonData, t: MichelsonType, ctx: Contex // ignore message } } - throw new MichelsonTypeError(t, `public key expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `public key expected: ${stringify(d)}`, d); case 'unit': if ('prim' in d && d.prim === 'Unit') { return; } - throw new MichelsonTypeError(t, `unit value expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `unit value expected: ${stringify(d)}`, d); case 'signature': if ( @@ -463,7 +464,7 @@ function assertDataValidInternal(d: MichelsonData, t: MichelsonType, ctx: Contex ) { return; } - throw new MichelsonTypeError(t, `signature expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `signature expected: ${stringify(d)}`, d); case 'chain_id': if ('bytes' in d || 'string' in d) { @@ -472,7 +473,7 @@ function assertDataValidInternal(d: MichelsonData, t: MichelsonType, ctx: Contex return; } } - throw new MichelsonTypeError(t, `chain id expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `chain id expected: ${stringify(d)}`, d); // Complex types case 'option': @@ -484,7 +485,7 @@ function assertDataValidInternal(d: MichelsonData, t: MichelsonType, ctx: Contex return; } } - throw new MichelsonTypeError(t, `option expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `option expected: ${stringify(d)}`, d); case 'list': case 'set': @@ -495,7 +496,7 @@ function assertDataValidInternal(d: MichelsonData, t: MichelsonType, ctx: Contex } return; } - throw new MichelsonTypeError(t, `${t.prim} expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `${t.prim} expected: ${stringify(d)}`, d); case 'or': if ('prim' in d) { @@ -507,7 +508,7 @@ function assertDataValidInternal(d: MichelsonData, t: MichelsonType, ctx: Contex return; } } - throw new MichelsonTypeError(t, `union (or) expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `union (or) expected: ${stringify(d)}`, d); case 'lambda': if (isFunction(d)) { const ret = functionTypeInternal(d, [t.args[0]], ctx); @@ -520,7 +521,7 @@ function assertDataValidInternal(d: MichelsonData, t: MichelsonType, ctx: Contex assertScalarTypesEqual(t.args[1], ret[0]); return; } - throw new MichelsonTypeError(t, `function expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `function expected: ${stringify(d)}`, d); case 'map': case 'big_map': @@ -528,26 +529,26 @@ function assertDataValidInternal(d: MichelsonData, t: MichelsonType, ctx: Contex //let prev: MichelsonMapElt | undefined; for (const v of d) { if (!('prim' in v) || v.prim !== 'Elt') { - throw new MichelsonTypeError(t, `map elements expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `map elements expected: ${stringify(d)}`, d); } assertDataValidInternal(v.args[0], t.args[0], ctx); assertDataValidInternal(v.args[1], t.args[1], ctx); } return; } - throw new MichelsonTypeError(t, `${t.prim} expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `${t.prim} expected: ${stringify(d)}`, d); case 'bls12_381_fr': if (('int' in d && isDecimal(d.int)) || ('bytes' in d && parseBytes(d.bytes) !== null)) { return; } - throw new MichelsonTypeError(t, `BLS12-381 element expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `BLS12-381 element expected: ${stringify(d)}`, d); case 'sapling_state': if (Array.isArray(d)) { return; } - throw new MichelsonTypeError(t, `sapling state expected: ${JSON.stringify(d)}`, d); + throw new MichelsonTypeError(t, `sapling state expected: ${stringify(d)}`, d); case 'ticket': assertDataValidInternal( diff --git a/packages/taquito-michel-codec/src/michelson-validator.ts b/packages/taquito-michel-codec/src/michelson-validator.ts index 58382e647e..32e3729838 100644 --- a/packages/taquito-michel-codec/src/michelson-validator.ts +++ b/packages/taquito-michel-codec/src/michelson-validator.ts @@ -11,6 +11,7 @@ import { MichelsonTypeID, MichelsonSimpleComparableTypeID, } from './michelson-types'; +import { stringify } from '@taquito/core'; // Michelson validator @@ -886,9 +887,9 @@ export function assertDataListIfAny(d: MichelsonData): d is MichelsonData[] { for (const v of d) { if ('prim' in v) { if (isInstruction(v)) { - throw new MichelsonError(d, `Instruction outside of a lambda: ${JSON.stringify(d)}`); + throw new MichelsonError(d, `Instruction outside of a lambda: ${stringify(d)}`); } else if (v.prim === 'Elt') { - throw new MichelsonError(d, `Elt item outside of a map literal: ${JSON.stringify(d)}`); + throw new MichelsonError(d, `Elt item outside of a map literal: ${stringify(d)}`); } } } diff --git a/packages/taquito-michel-codec/test/binary.spec.ts b/packages/taquito-michel-codec/test/binary.spec.ts index 361cb995c6..42dbdd7335 100644 --- a/packages/taquito-michel-codec/test/binary.spec.ts +++ b/packages/taquito-michel-codec/test/binary.spec.ts @@ -4,6 +4,7 @@ import path from 'path'; import { MichelsonData, MichelsonType, ProtocolID } from '../src/michelson-types'; import { packData, unpackData } from '../src/binary'; import { parseHex } from '../src/utils'; +import { stringify } from '@taquito/core'; interface TypedTestData { type?: MichelsonType; @@ -22,7 +23,7 @@ describe('Binary', () => { describe('pack', () => { for (const s of src) { - it(JSON.stringify(s.data), () => { + it(stringify(s.data), () => { const p = packData(s.data, s.type); expect(p).toEqual(parseHex(s.packed)); }); @@ -30,7 +31,7 @@ describe('Binary', () => { }); describe('unpack', () => { for (const s of src) { - it(JSON.stringify(s.data), () => { + it(stringify(s.data), () => { const ex = unpackData(parseHex(s.packed), s.type); expect(ex).toEqual(s.expect || s.data); }); diff --git a/packages/taquito-michel-codec/test/global-constant.spec.ts b/packages/taquito-michel-codec/test/global-constant.spec.ts index 48ffc07843..ff7caa617d 100644 --- a/packages/taquito-michel-codec/test/global-constant.spec.ts +++ b/packages/taquito-michel-codec/test/global-constant.spec.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { Parser, ParserOptions } from '../src/micheline-parser'; import { globalConstant, @@ -29,17 +30,17 @@ describe('Expand global constants', () => { it('Should expand global constants in script using parseSequence', () => { expect( - JSON.stringify( + stringify( p.parseSequence( script(globalConstant('constantHashInt'), globalConstant('constantHashDrop')) ) ) - ).toEqual(JSON.stringify(scriptJSON(registeredIntExprJSON, registeredDropExprJSON))); + ).toEqual(stringify(scriptJSON(registeredIntExprJSON, registeredDropExprJSON))); }); it('Should expand global constants in script using parseList', () => { expect( - JSON.stringify( + stringify( p.parseList( `IF_LEFT { IF_LEFT { SWAP ; SUB } { ADD } } { ${globalConstant( 'constantHashDrop' @@ -47,7 +48,7 @@ describe('Expand global constants', () => { ) ) ).toEqual( - JSON.stringify({ + stringify({ prim: 'IF_LEFT', args: [ [ @@ -70,13 +71,13 @@ describe('Expand global constants', () => { it('Should expand global constants in script using parseMichelineExpression', () => { expect( - JSON.stringify( + stringify( p.parseMichelineExpression( `(or (${globalConstant('constantHashInt')}) (${globalConstant('constantHashInt')}))` ) ) ).toEqual( - JSON.stringify({ + stringify({ prim: 'or', args: [registeredIntExprJSON, registeredIntExprJSON], }) @@ -85,9 +86,9 @@ describe('Expand global constants', () => { it('Should expand global constants in script using parseScript', () => { expect( - JSON.stringify( + stringify( p.parseScript(script(globalConstant('constantHashInt'), globalConstant('constantHashDrop'))) ) - ).toEqual(JSON.stringify(scriptJSON(registeredIntExprJSON, registeredDropExprJSON))); + ).toEqual(stringify(scriptJSON(registeredIntExprJSON, registeredDropExprJSON))); }); }); diff --git a/packages/taquito-michelson-encoder/src/michelson-map.ts b/packages/taquito-michelson-encoder/src/michelson-map.ts index c9edbe978e..5e74615c84 100644 --- a/packages/taquito-michelson-encoder/src/michelson-map.ts +++ b/packages/taquito-michelson-encoder/src/michelson-map.ts @@ -10,7 +10,7 @@ import { TaquitoError } from '@taquito/core'; export class InvalidMapTypeError extends TaquitoError { constructor(public readonly mapType: any, public readonly reason: string) { super(); - this.message = `The map type '${JSON.stringify(mapType)}' is invalid. Reason: ${reason}.`; + this.message = `The map type '${stringify(mapType)}' is invalid. Reason: ${reason}.`; this.name = 'InvalidMapTypeError'; } } @@ -60,11 +60,11 @@ export class MapTypecheckError extends TaquitoError { public readonly reason: any ) { super(); - this.message = `The ${objectType} provided: ${JSON.stringify( + this.message = `The ${objectType} provided: ${stringify( value - )} is not compatible with the expected michelson type: ${JSON.stringify( - type - )}. Reason: ${JSON.stringify(reason)}.`; + )} is not compatible with the expected michelson type: ${stringify(type)}. Reason: ${stringify( + reason + )}.`; this.name = 'MapTypecheckError'; } } diff --git a/packages/taquito-michelson-encoder/src/schema/errors.ts b/packages/taquito-michelson-encoder/src/schema/errors.ts index 289225e30d..d7b8b1a017 100644 --- a/packages/taquito-michelson-encoder/src/schema/errors.ts +++ b/packages/taquito-michelson-encoder/src/schema/errors.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { InvalidViewParameterError, TaquitoError } from '@taquito/core'; +import { InvalidViewParameterError, TaquitoError, stringify } from '@taquito/core'; /** * @category Error @@ -15,9 +15,9 @@ export class ParameterEncodingError extends InvalidViewParameterError { ) { super(viewName, sigs, args, cause); this.name = 'ParameterEncodingError'; - this.message = `Could not encode parameter ${JSON.stringify( + this.message = `Could not encode parameter ${stringify( args - )} received for name "${viewName}" expecting one of the following signatures ${JSON.stringify( + )} received for name "${viewName}" expecting one of the following signatures ${stringify( sigs )}`; } @@ -35,7 +35,7 @@ export class InvalidScriptError extends TaquitoError { if (reason) { message += ` Reason: ${reason}.`; } - message += `Script: ${JSON.stringify(script)}`; + message += `Script: ${stringify(script)}`; this.message = message; } } @@ -52,7 +52,7 @@ export class InvalidRpcResponseError extends TaquitoError { if (reason) { message += ` Reason: ${reason}.`; } - message += ` Received: ${JSON.stringify(script)}`; + message += ` Received: ${stringify(script)}`; this.message = message; } } @@ -92,9 +92,9 @@ export class BigMapEncodingError extends TaquitoError { public readonly value: any ) { super(); - this.message = `Unable to encode the big map ${obj}. Schema is: ${JSON.stringify( + this.message = `Unable to encode the big map ${obj}. Schema is: ${stringify( schema - )}. The ${obj} is: ${JSON.stringify(value)}. Error details: ${details}`; + )}. The ${obj} is: ${stringify(value)}. Error details: ${details}`; } } @@ -112,10 +112,10 @@ export class StorageEncodingError extends TaquitoError { public readonly semantics?: any ) { super(); - this.message = `Unable to encode ${obj}. The schema is: ${JSON.stringify( + this.message = `Unable to encode ${obj}. The schema is: ${stringify( schema - )}, the value is: ${JSON.stringify(value)}.${ - semantics ? `And the semantic is: ${JSON.stringify(semantics)}` : '' + )}, the value is: ${stringify(value)}.${ + semantics ? `And the semantic is: ${stringify(semantics)}` : '' }. Error details: ${details}`; } } diff --git a/packages/taquito-michelson-encoder/src/schema/storage.ts b/packages/taquito-michelson-encoder/src/schema/storage.ts index 676c76870c..e58cc4cbe4 100644 --- a/packages/taquito-michelson-encoder/src/schema/storage.ts +++ b/packages/taquito-michelson-encoder/src/schema/storage.ts @@ -28,6 +28,7 @@ import { } from './errors'; import { RpcTransaction } from './model'; import { TokenSchema } from './types'; +import { stringify } from '@taquito/core'; const schemaTypeSymbol = Symbol.for('taquito-schema-type-symbol'); @@ -192,7 +193,7 @@ export class Schema { if (!Array.isArray(diff)) { throw new InvalidBigMapDiffError( - `Big map diff must be an array, got: ${JSON.stringify(diff)}`, + `Big map diff must be an array, got: ${stringify(diff)}`, diff ); } diff --git a/packages/taquito-michelson-encoder/src/tokens/bigmap.ts b/packages/taquito-michelson-encoder/src/tokens/bigmap.ts index e2ff96e922..98f8e5bb39 100644 --- a/packages/taquito-michelson-encoder/src/tokens/bigmap.ts +++ b/packages/taquito-michelson-encoder/src/tokens/bigmap.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { MichelsonMap } from '../michelson-map'; import { BigMapTokenSchema } from '../schema/types'; import { @@ -69,7 +70,7 @@ export class BigMapToken extends Token { throw new BigMapValidationError( value, this, - `Value ${JSON.stringify(value)} is not a MichelsonMap` + `Value ${stringify(value)} is not a MichelsonMap` ); } } @@ -150,7 +151,7 @@ export class BigMapToken extends Token { throw new BigMapValidationError( val, this, - `Big map is expecting either an array (Athens) or an object with an int property (Babylon). Got ${JSON.stringify( + `Big map is expecting either an array (Athens) or an object with an int property (Babylon). Got ${stringify( val )}` ); diff --git a/packages/taquito-michelson-encoder/src/tokens/bls12-381-fr.ts b/packages/taquito-michelson-encoder/src/tokens/bls12-381-fr.ts index 5c889c9cfc..bd569ed69f 100644 --- a/packages/taquito-michelson-encoder/src/tokens/bls12-381-fr.ts +++ b/packages/taquito-michelson-encoder/src/tokens/bls12-381-fr.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { BaseTokenSchema } from '../schema/types'; import { SemanticEncoding, Token, TokenFactory, TokenValidationError } from './token'; @@ -31,7 +32,7 @@ export class Bls12381frToken extends Token { if (/^[0-9a-fA-F]*$/.test(val) && val.length % 2 === 0) { return; } - throw new Bls12381frValidationError(val, this, `Invalid bytes: ${JSON.stringify(val)}`); + throw new Bls12381frValidationError(val, this, `Invalid bytes: ${stringify(val)}`); } private convertUint8ArrayToHexString(val: any) { diff --git a/packages/taquito-michelson-encoder/src/tokens/bls12-381-g1.ts b/packages/taquito-michelson-encoder/src/tokens/bls12-381-g1.ts index 2d48ae6752..7b2a537941 100644 --- a/packages/taquito-michelson-encoder/src/tokens/bls12-381-g1.ts +++ b/packages/taquito-michelson-encoder/src/tokens/bls12-381-g1.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { BaseTokenSchema } from '../schema/types'; import { SemanticEncoding, Token, TokenFactory, TokenValidationError } from './token'; @@ -31,7 +32,7 @@ export class Bls12381g1Token extends Token { if (/^[0-9a-fA-F]*$/.test(val) && val.length % 2 === 0) { return; } - throw new Bls12381g1ValidationError(val, this, `Invalid bytes: ${JSON.stringify(val)}`); + throw new Bls12381g1ValidationError(val, this, `Invalid bytes: ${stringify(val)}`); } private convertUint8ArrayToHexString(val: any) { diff --git a/packages/taquito-michelson-encoder/src/tokens/bls12-381-g2.ts b/packages/taquito-michelson-encoder/src/tokens/bls12-381-g2.ts index ac63f0833f..18b1bc0c5b 100644 --- a/packages/taquito-michelson-encoder/src/tokens/bls12-381-g2.ts +++ b/packages/taquito-michelson-encoder/src/tokens/bls12-381-g2.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { BaseTokenSchema } from '../schema/types'; import { SemanticEncoding, Token, TokenFactory, TokenValidationError } from './token'; @@ -31,7 +32,7 @@ export class Bls12381g2Token extends Token { if (/^[0-9a-fA-F]*$/.test(val) && val.length % 2 === 0) { return; } - throw new Bls12381g2ValidationError(val, this, `Invalid bytes: ${JSON.stringify(val)}`); + throw new Bls12381g2ValidationError(val, this, `Invalid bytes: ${stringify(val)}`); } private convertUint8ArrayToHexString(val: any) { diff --git a/packages/taquito-michelson-encoder/src/tokens/chain-id.ts b/packages/taquito-michelson-encoder/src/tokens/chain-id.ts index c8ee0e47ed..54364e55ef 100644 --- a/packages/taquito-michelson-encoder/src/tokens/chain-id.ts +++ b/packages/taquito-michelson-encoder/src/tokens/chain-id.ts @@ -7,6 +7,7 @@ import { } from './token'; import { validateChain, ValidationResult } from '@taquito/utils'; import { BaseTokenSchema } from '../schema/types'; +import { stringify } from '@taquito/core'; /** * @category Error @@ -38,7 +39,7 @@ export class ChainIDToken extends ComparableToken { throw new ChainIDValidationError( value, this, - `Value ${JSON.stringify(value)} is not a valid ChainID` + `Value ${stringify(value)} is not a valid ChainID` ); } } diff --git a/packages/taquito-michelson-encoder/src/tokens/chest-key.ts b/packages/taquito-michelson-encoder/src/tokens/chest-key.ts index 52804ad304..2884bea2c6 100644 --- a/packages/taquito-michelson-encoder/src/tokens/chest-key.ts +++ b/packages/taquito-michelson-encoder/src/tokens/chest-key.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { BaseTokenSchema } from '../schema/types'; import { SemanticEncoding, Token, TokenFactory, TokenValidationError } from './token'; @@ -29,7 +30,7 @@ export class ChestKeyToken extends Token { if (/^[0-9a-fA-F]*$/.test(val) && val.length % 2 === 0) { return; } - throw new ChestKeyValidationError(val, this, `Invalid bytes: ${JSON.stringify(val)}`); + throw new ChestKeyValidationError(val, this, `Invalid bytes: ${stringify(val)}`); } private convertUint8ArrayToHexString(val: any) { diff --git a/packages/taquito-michelson-encoder/src/tokens/chest.ts b/packages/taquito-michelson-encoder/src/tokens/chest.ts index 9b84774286..05ab450a93 100644 --- a/packages/taquito-michelson-encoder/src/tokens/chest.ts +++ b/packages/taquito-michelson-encoder/src/tokens/chest.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { BaseTokenSchema } from '../schema/types'; import { SemanticEncoding, Token, TokenFactory, TokenValidationError } from './token'; @@ -29,7 +30,7 @@ export class ChestToken extends Token { if (/^[0-9a-fA-F]*$/.test(val) && val.length % 2 == 0) { return; } - throw new ChestValidationError(val, this, `Invalid bytes: ${JSON.stringify(val)}`); + throw new ChestValidationError(val, this, `Invalid bytes: ${stringify(val)}`); } private convertUint8ArrayToHexString(val: any) { diff --git a/packages/taquito-michelson-encoder/src/tokens/comparable/address.ts b/packages/taquito-michelson-encoder/src/tokens/comparable/address.ts index bebe9d42c2..575c7609b0 100644 --- a/packages/taquito-michelson-encoder/src/tokens/comparable/address.ts +++ b/packages/taquito-michelson-encoder/src/tokens/comparable/address.ts @@ -7,6 +7,7 @@ import { } from '../token'; import { b58decode, encodePubKey, validateAddress, ValidationResult } from '@taquito/utils'; import { BaseTokenSchema } from '../../schema/types'; +import { stringify } from '@taquito/core'; /** * @category Error @@ -43,11 +44,7 @@ export class AddressToken extends ComparableToken { */ private validate(value: any) { if (validateAddress(value) !== ValidationResult.VALID) { - throw new AddressValidationError( - value, - this, - `Address is not valid: ${JSON.stringify(value)}` - ); + throw new AddressValidationError(value, this, `Address is not valid: ${stringify(value)}`); } } @@ -86,7 +83,7 @@ export class AddressToken extends ComparableToken { throw new AddressValidationError( val, this, - `cannot be missing both string and bytes: ${JSON.stringify(val)}` + `cannot be missing both string and bytes: ${stringify(val)}` ); } @@ -119,7 +116,7 @@ export class AddressToken extends ComparableToken { throw new AddressValidationError( { bytes, string }, this, - `cannot be missing both string and bytes ${JSON.stringify({ string, bytes })}` + `cannot be missing both string and bytes ${stringify({ string, bytes })}` ); } diff --git a/packages/taquito-michelson-encoder/src/tokens/comparable/int.ts b/packages/taquito-michelson-encoder/src/tokens/comparable/int.ts index 7d8d06065a..9173fef346 100644 --- a/packages/taquito-michelson-encoder/src/tokens/comparable/int.ts +++ b/packages/taquito-michelson-encoder/src/tokens/comparable/int.ts @@ -7,6 +7,7 @@ import { } from '../token'; import BigNumber from 'bignumber.js'; import { BaseTokenSchema } from '../../schema/types'; +import { stringify } from '@taquito/core'; /** * @category Error @@ -55,7 +56,7 @@ export class IntToken extends ComparableToken { private validate(val: any) { const bigNumber = new BigNumber(val); if (bigNumber.isNaN()) { - throw new IntValidationError(val, this, `Value is not a number: ${JSON.stringify(val)}`); + throw new IntValidationError(val, this, `Value is not a number: ${stringify(val)}`); } } diff --git a/packages/taquito-michelson-encoder/src/tokens/comparable/key_hash.ts b/packages/taquito-michelson-encoder/src/tokens/comparable/key_hash.ts index 6af88aeaeb..90b4489a26 100644 --- a/packages/taquito-michelson-encoder/src/tokens/comparable/key_hash.ts +++ b/packages/taquito-michelson-encoder/src/tokens/comparable/key_hash.ts @@ -7,6 +7,7 @@ import { } from '../token'; import { encodeKeyHash, validateKeyHash, ValidationResult } from '@taquito/utils'; import { BaseTokenSchema } from '../../schema/types'; +import { stringify } from '@taquito/core'; /** * @category Error @@ -43,11 +44,7 @@ export class KeyHashToken extends ComparableToken { */ private validate(value: any) { if (validateKeyHash(value) !== ValidationResult.VALID) { - throw new KeyHashValidationError( - value, - this, - `KeyHash is not valid: ${JSON.stringify(value)}` - ); + throw new KeyHashValidationError(value, this, `KeyHash is not valid: ${stringify(value)}`); } } diff --git a/packages/taquito-michelson-encoder/src/tokens/comparable/nat.ts b/packages/taquito-michelson-encoder/src/tokens/comparable/nat.ts index dd4460584c..df11cb5878 100644 --- a/packages/taquito-michelson-encoder/src/tokens/comparable/nat.ts +++ b/packages/taquito-michelson-encoder/src/tokens/comparable/nat.ts @@ -7,6 +7,7 @@ import { } from '../token'; import BigNumber from 'bignumber.js'; import { BaseTokenSchema } from '../../schema/types'; +import { stringify } from '@taquito/core'; /** * @category Error @@ -51,10 +52,10 @@ export class NatToken extends ComparableToken { private validate(val: any) { const bigNumber = new BigNumber(val); if (bigNumber.isNaN()) { - throw new NatValidationError(val, this, `Value is not a number: ${JSON.stringify(val)}`); + throw new NatValidationError(val, this, `Value is not a number: ${stringify(val)}`); } if (bigNumber.isNegative()) { - throw new NatValidationError(val, this, `Value cannot be negative: ${JSON.stringify(val)}`); + throw new NatValidationError(val, this, `Value cannot be negative: ${stringify(val)}`); } } diff --git a/packages/taquito-michelson-encoder/src/tokens/comparable/tx_rollup_l2_address.ts b/packages/taquito-michelson-encoder/src/tokens/comparable/tx_rollup_l2_address.ts index 281130e147..633e6f46dc 100644 --- a/packages/taquito-michelson-encoder/src/tokens/comparable/tx_rollup_l2_address.ts +++ b/packages/taquito-michelson-encoder/src/tokens/comparable/tx_rollup_l2_address.ts @@ -12,6 +12,7 @@ import { TokenFactory, TokenValidationError, } from '../token'; +import { stringify } from '@taquito/core'; /** * @category Error @@ -51,7 +52,7 @@ export class TxRollupL2AddressToken extends ComparableToken { throw new TxRollupL2AddressValidationError( value, this, - `tx_rollup_l2_address is not valid: ${JSON.stringify(value)}` + `tx_rollup_l2_address is not valid: ${stringify(value)}` ); } } @@ -65,7 +66,7 @@ export class TxRollupL2AddressToken extends ComparableToken { throw new TxRollupL2AddressValidationError( val, this, - `arg missing to encode: this -> "${JSON.stringify(val)}"` + `arg missing to encode: this -> "${stringify(val)}"` ); } this.validate(val); @@ -96,7 +97,7 @@ export class TxRollupL2AddressToken extends ComparableToken { throw new TxRollupL2AddressValidationError( val, this, - `value cannot be missing string and byte value. must have one ${JSON.stringify(val)}` + `value cannot be missing string and byte value. must have one ${stringify(val)}` ); } return encodeL2Address(val.bytes); @@ -123,9 +124,7 @@ export class TxRollupL2AddressToken extends ComparableToken { throw new TxRollupL2AddressValidationError( bytes, this, - `value cannot be missing string and byte value. must have one: bytes = ${JSON.stringify( - bytes - )}` + `value cannot be missing string and byte value. must have one: bytes = ${stringify(bytes)}` ); } return encodeL2Address(bytes); diff --git a/packages/taquito-michelson-encoder/src/tokens/contract.ts b/packages/taquito-michelson-encoder/src/tokens/contract.ts index acda8c7ff7..f37904f743 100644 --- a/packages/taquito-michelson-encoder/src/tokens/contract.ts +++ b/packages/taquito-michelson-encoder/src/tokens/contract.ts @@ -2,6 +2,7 @@ import { TokenSchema } from './../schema/types'; import { encodePubKey, validateAddress, ValidationResult } from '@taquito/utils'; import { ContractTokenSchema } from '../schema/types'; import { SemanticEncoding, Token, TokenFactory, TokenValidationError } from './token'; +import { stringify } from '@taquito/core'; /** * @category Error @@ -34,7 +35,7 @@ export class ContractToken extends Token { throw new ContractValidationError( value, this, - `Value ${JSON.stringify(value)} is not a valid contract address.` + `Value ${stringify(value)} is not a valid contract address.` ); } @@ -52,9 +53,7 @@ export class ContractToken extends Token { throw new ContractValidationError( val, this, - `Value ${JSON.stringify( - val - )} is not a valid contract address. must contain bytes or string.` + `Value ${stringify(val)} is not a valid contract address. must contain bytes or string.` ); } diff --git a/packages/taquito-michelson-encoder/src/tokens/createToken.ts b/packages/taquito-michelson-encoder/src/tokens/createToken.ts index 1f269d2e6a..1266df1acf 100644 --- a/packages/taquito-michelson-encoder/src/tokens/createToken.ts +++ b/packages/taquito-michelson-encoder/src/tokens/createToken.ts @@ -1,7 +1,7 @@ import { tokens } from './tokens'; import { Token } from './token'; import { PairToken } from './pair'; -import { TaquitoError } from '@taquito/core'; +import { TaquitoError, stringify } from '@taquito/core'; /** * @category Error @@ -27,7 +27,7 @@ export function createToken(val: any, idx: number): Token { const t = tokens.find((x) => x.prim === val.prim); if (!t) { throw new InvalidTokenError( - `Malformed data: ${JSON.stringify(val)}. Expected a value with a valid prim property`, + `Malformed data: ${stringify(val)}. Expected a value with a valid prim property`, val ); } diff --git a/packages/taquito-michelson-encoder/src/tokens/list.ts b/packages/taquito-michelson-encoder/src/tokens/list.ts index e6a7fbcccd..995354a311 100644 --- a/packages/taquito-michelson-encoder/src/tokens/list.ts +++ b/packages/taquito-michelson-encoder/src/tokens/list.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { ListTokenSchema } from '../schema/types'; import { Token, TokenFactory, Semantic, TokenValidationError, SemanticEncoding } from './token'; @@ -32,11 +33,7 @@ export class ListToken extends Token { */ private validate(value: any) { if (!Array.isArray(value)) { - throw new ListValidationError( - value, - this, - `Value ${JSON.stringify(value)} is not a valid array` - ); + throw new ListValidationError(value, this, `Value ${stringify(value)} is not a valid array`); } } diff --git a/packages/taquito-michelson-encoder/src/tokens/map.ts b/packages/taquito-michelson-encoder/src/tokens/map.ts index 734baf02f8..0b2f4f45d3 100644 --- a/packages/taquito-michelson-encoder/src/tokens/map.ts +++ b/packages/taquito-michelson-encoder/src/tokens/map.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { MichelsonMap } from '../michelson-map'; import { MapTokenSchema } from '../schema/types'; import { @@ -47,7 +48,7 @@ export class MapToken extends Token { throw new MapValidationError( value, this, - `Value ${JSON.stringify(value)} is not a valid MichelsonMap` + `Value ${stringify(value)} is not a valid MichelsonMap` ); } } diff --git a/packages/taquito-michelson-encoder/src/tokens/never.ts b/packages/taquito-michelson-encoder/src/tokens/never.ts index c1188ad151..a0a69ee5a4 100644 --- a/packages/taquito-michelson-encoder/src/tokens/never.ts +++ b/packages/taquito-michelson-encoder/src/tokens/never.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { BaseTokenSchema } from '../schema/types'; import { SemanticEncoding, Token, TokenFactory, TokenValidationError } from './token'; @@ -30,7 +31,7 @@ export class NeverToken extends Token { throw new NeverTokenError( val, this, - `Assigning a value to the type never is forbidden. Trying to assign ${JSON.stringify(val)}.` + `Assigning a value to the type never is forbidden. Trying to assign ${stringify(val)}.` ); } @@ -44,7 +45,7 @@ export class NeverToken extends Token { throw new NeverTokenError( val, this, - `Assigning a value to the type never is forbidden. Trying to assign ${JSON.stringify(val)}.` + `Assigning a value to the type never is forbidden. Trying to assign ${stringify(val)}.` ); } @@ -55,7 +56,7 @@ export class NeverToken extends Token { throw new NeverTokenError( val, this, - `There is no literal value for the type never. Trying to execute ${JSON.stringify(val)}.` + `There is no literal value for the type never. Trying to execute ${stringify(val)}.` ); } diff --git a/packages/taquito-michelson-encoder/src/tokens/or.ts b/packages/taquito-michelson-encoder/src/tokens/or.ts index 1d3b25ac86..ad359b94c7 100644 --- a/packages/taquito-michelson-encoder/src/tokens/or.ts +++ b/packages/taquito-michelson-encoder/src/tokens/or.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { OrTokenSchema } from '../schema/types'; import { Token, @@ -145,7 +146,7 @@ export class OrToken extends ComparableToken { throw new OrValidationError( args, this, - `EncodeObject expects an object with a single key but got: ${JSON.stringify(args)}` + `EncodeObject expects an object with a single key but got: ${stringify(args)}` ); } } @@ -180,7 +181,7 @@ export class OrToken extends ComparableToken { throw new OrValidationError( val, this, - `Was expecting Left or Right prim but got: ${JSON.stringify(val.prim)}` + `Was expecting Left or Right prim but got: ${stringify(val.prim)}` ); } } @@ -303,8 +304,8 @@ export class OrToken extends ComparableToken { return token.compare(val1[labelVal1], val2[labelVal1]); } } else { - const encoded1 = JSON.stringify(this.EncodeObject(val1)); - const encoded2 = JSON.stringify(this.EncodeObject(val2)); + const encoded1 = stringify(this.EncodeObject(val1)); + const encoded2 = stringify(this.EncodeObject(val2)); return encoded1 < encoded2 ? -1 : 1; } } diff --git a/packages/taquito-michelson-encoder/src/tokens/pair.ts b/packages/taquito-michelson-encoder/src/tokens/pair.ts index 1bf8c02656..5f38cdd1da 100644 --- a/packages/taquito-michelson-encoder/src/tokens/pair.ts +++ b/packages/taquito-michelson-encoder/src/tokens/pair.ts @@ -2,7 +2,7 @@ import { Token, TokenFactory, Semantic, ComparableToken, SemanticEncoding } from import { OrToken } from './or'; import { PairTokenSchema } from '../schema/types'; import { MichelsonV1Expression, MichelsonV1ExpressionExtended } from '@taquito/rpc'; -import { TaquitoError } from '@taquito/core'; +import { TaquitoError, stringify } from '@taquito/core'; /** * @category Error @@ -23,7 +23,7 @@ export class TokenComparisonError extends TaquitoError { public name = 'TokenComparisonError'; constructor(public val1: string, public val2: string) { super(); - this.message = `Tokens ${JSON.stringify(val1)} and ${JSON.stringify(val2)} are not comparable`; + this.message = `Tokens ${stringify(val1)} and ${stringify(val2)} are not comparable`; } } @@ -43,7 +43,7 @@ function collapse(val: Token['val'] | any[], prim: string = PairToken.prim): [an } if (val.args === undefined) { throw new TokenArgumentValidationError( - `The value ${JSON.stringify( + `The value ${stringify( val )} is an invalid PairToken with no arguments, a pair must have two or more arguments.` ); diff --git a/packages/taquito-michelson-encoder/src/tokens/sapling-state.ts b/packages/taquito-michelson-encoder/src/tokens/sapling-state.ts index 86df68a3b5..be60f7e2d2 100644 --- a/packages/taquito-michelson-encoder/src/tokens/sapling-state.ts +++ b/packages/taquito-michelson-encoder/src/tokens/sapling-state.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { SaplingStateTokenSchema } from '../schema/types'; import { Semantic, SemanticEncoding, Token, TokenFactory, TokenValidationError } from './token'; @@ -40,7 +41,7 @@ export class SaplingStateToken extends Token { throw new SaplingStateValidationError( val, this, - `Sapling state is expecting an object with an int property. Got ${JSON.stringify(val)}` + `Sapling state is expecting an object with an int property. Got ${stringify(val)}` ); } } @@ -56,7 +57,7 @@ export class SaplingStateToken extends Token { throw new SaplingStateValidationError( val, this, - `Invalid sapling_state. Received: ${JSON.stringify(val)} while expecting: {}` + `Invalid sapling_state. Received: ${stringify(val)} while expecting: {}` ); } } @@ -74,7 +75,7 @@ export class SaplingStateToken extends Token { throw new SaplingStateValidationError( val, this, - `Invalid sapling_state. Received: ${JSON.stringify(val)} while expecting: {}` + `Invalid sapling_state. Received: ${stringify(val)} while expecting: {}` ); } } diff --git a/packages/taquito-michelson-encoder/src/tokens/sapling-transaction-deprecated.ts b/packages/taquito-michelson-encoder/src/tokens/sapling-transaction-deprecated.ts index 0b0348fc06..e38c757359 100644 --- a/packages/taquito-michelson-encoder/src/tokens/sapling-transaction-deprecated.ts +++ b/packages/taquito-michelson-encoder/src/tokens/sapling-transaction-deprecated.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { SaplingTransactionDeprecatedTokenSchema } from '../schema/types'; import { SemanticEncoding, Token, TokenFactory, TokenValidationError } from './token'; @@ -30,7 +31,7 @@ export class SaplingTransactionDeprecatedToken extends Token { throw new SaplingTransactionDeprecatedValidationError( _val, this, - `There is no literal value for the sapling_transaction_deprecated type. Got: ${JSON.stringify( + `There is no literal value for the sapling_transaction_deprecated type. Got: ${stringify( _val )}.` ); @@ -47,7 +48,7 @@ export class SaplingTransactionDeprecatedToken extends Token { throw new SaplingTransactionDeprecatedValidationError( val, this, - `Invalid bytes: ${JSON.stringify(val)}` + `Invalid bytes: ${stringify(val)}` ); } } diff --git a/packages/taquito-michelson-encoder/src/tokens/sapling-transaction.ts b/packages/taquito-michelson-encoder/src/tokens/sapling-transaction.ts index 31b92e8cdb..7fa55ee3ed 100644 --- a/packages/taquito-michelson-encoder/src/tokens/sapling-transaction.ts +++ b/packages/taquito-michelson-encoder/src/tokens/sapling-transaction.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { SaplingTransactionTokenSchema } from '../schema/types'; import { SemanticEncoding, Token, TokenFactory, TokenValidationError } from './token'; @@ -30,7 +31,7 @@ export class SaplingTransactionToken extends Token { throw new SaplingTransactionValidationError( _val, this, - `There is no literal value for the sapling_transaction type. Got: ${JSON.stringify(_val)}.` + `There is no literal value for the sapling_transaction type. Got: ${stringify(_val)}.` ); } @@ -42,11 +43,7 @@ export class SaplingTransactionToken extends Token { if (bytes && bytes[2].length % 2 === 0) { return bytes[2]; } else { - throw new SaplingTransactionValidationError( - val, - this, - `Invalid bytes: ${JSON.stringify(val)}` - ); + throw new SaplingTransactionValidationError(val, this, `Invalid bytes: ${stringify(val)}`); } } diff --git a/packages/taquito-michelson-encoder/src/tokens/set.ts b/packages/taquito-michelson-encoder/src/tokens/set.ts index 2c08975505..54be669e02 100644 --- a/packages/taquito-michelson-encoder/src/tokens/set.ts +++ b/packages/taquito-michelson-encoder/src/tokens/set.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { SetTokenSchema } from '../schema/types'; import { Token, @@ -39,7 +40,7 @@ export class SetToken extends Token { */ private validate(value: any) { if (!Array.isArray(value)) { - throw new SetValidationError(value, this, `Value ${JSON.stringify(value)} is not an array`); + throw new SetValidationError(value, this, `Value ${stringify(value)} is not an array`); } } diff --git a/packages/taquito-rpc/src/rpc-client-modules/rpc-cache.ts b/packages/taquito-rpc/src/rpc-client-modules/rpc-cache.ts index f39ff7e2fe..9788f442a0 100644 --- a/packages/taquito-rpc/src/rpc-client-modules/rpc-cache.ts +++ b/packages/taquito-rpc/src/rpc-client-modules/rpc-cache.ts @@ -53,7 +53,7 @@ import { OriginationProofParams, RPCSimulateOperationParam, } from '../types'; -import { InvalidAddressError, InvalidContractAddressError } from '@taquito/core'; +import { InvalidAddressError, InvalidContractAddressError, stringify } from '@taquito/core'; import { validateContractAddress, validateAddress, @@ -116,11 +116,11 @@ export class RpcClientCache implements RpcClientInterface { rpcMethodParams.forEach((param) => { paramsToString = typeof param === 'object' - ? paramsToString + JSON.stringify(param) + '/' + ? paramsToString + stringify(param) + '/' : paramsToString + param + '/'; }); return rpcMethodData - ? `${rpcUrl}/${rpcMethodName}/${paramsToString}${JSON.stringify(rpcMethodData)}/` + ? `${rpcUrl}/${rpcMethodName}/${paramsToString}${stringify(rpcMethodData)}/` : `${rpcUrl}/${rpcMethodName}/${paramsToString}`; } diff --git a/packages/taquito-rpc/test/rpc-cache.spec.ts b/packages/taquito-rpc/test/rpc-cache.spec.ts index 17c41c21d1..db9d31e089 100644 --- a/packages/taquito-rpc/test/rpc-cache.spec.ts +++ b/packages/taquito-rpc/test/rpc-cache.spec.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { RpcClientCache } from '../src/rpc-client-modules/rpc-cache'; import { rpcUrl, @@ -277,7 +278,7 @@ describe('RpcClientCache test', () => { ).toEqual(txRollupState); expect( rpcCache.getAllCachedData()[ - `rpcTest/getTicketBalance/head/${contractAddress}/${JSON.stringify(ticketToken)}/` + `rpcTest/getTicketBalance/head/${contractAddress}/${stringify(ticketToken)}/` ].response ).toEqual('3'); expect( @@ -454,7 +455,7 @@ describe('RpcClientCache test', () => { ).toEqual(txRollupState); expect( rpcCache.getAllCachedData()[ - `rpcTest/getTicketBalance/${block.block}/${contractAddress}/${JSON.stringify(ticketToken)}/` + `rpcTest/getTicketBalance/${block.block}/${contractAddress}/${stringify(ticketToken)}/` ].response ).toEqual('3'); expect( diff --git a/packages/taquito-sapling/src/errors.ts b/packages/taquito-sapling/src/errors.ts index 36101589cc..7e118c256d 100644 --- a/packages/taquito-sapling/src/errors.ts +++ b/packages/taquito-sapling/src/errors.ts @@ -1,4 +1,4 @@ -import { ParameterValidationError, TaquitoError } from '@taquito/core'; +import { ParameterValidationError, TaquitoError, stringify } from '@taquito/core'; /** * @category Error @@ -20,7 +20,7 @@ export class InvalidMerkleTreeError extends ParameterValidationError { constructor(public readonly root: string) { super(); this.name = 'InvalidMerkleTreeError'; - this.message = `Invalid merkle tree has root "${JSON.stringify( + this.message = `Invalid merkle tree has root "${stringify( root )}" different from expected root.`; } diff --git a/packages/taquito-sapling/test/sapling-state/sapling-state.spec.ts b/packages/taquito-sapling/test/sapling-state/sapling-state.spec.ts index dfcec2bd18..e5b571104e 100644 --- a/packages/taquito-sapling/test/sapling-state/sapling-state.spec.ts +++ b/packages/taquito-sapling/test/sapling-state/sapling-state.spec.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { SaplingState } from '../../src/sapling-state/sapling-state'; import { sapling_state_diff, witnessString, stateTree } from '../data/sapling_test_data'; import { BigNumber } from 'bignumber.js'; @@ -20,7 +21,7 @@ describe('Sapling State Tree tests', () => { const result = await state.getStateTree(sapling_state_diff); expect(result).toBeDefined(); - expect(JSON.stringify(result)).toEqual(stateTree); + expect(stringify(result)).toEqual(stateTree); }); it('Should be able to get witness from Sapling state diff', async () => { diff --git a/packages/taquito-signer/test/ecdsa.spec.ts b/packages/taquito-signer/test/ecdsa.spec.ts index f11931ad49..4bf656f2ff 100644 --- a/packages/taquito-signer/test/ecdsa.spec.ts +++ b/packages/taquito-signer/test/ecdsa.spec.ts @@ -1,285 +1,286 @@ -import { ECDSA, Hard } from "../src/derivation-tools"; -import * as Bip39 from 'bip39' +import { stringify } from '@taquito/core'; +import { ECDSA, Hard } from '../src/derivation-tools'; +import * as Bip39 from 'bip39'; interface TestKeyData { - path: number[]; - chain?: string; - priv?: string; + path: number[]; + chain?: string; + priv?: string; } interface TestChain { - mnemonic?: string; - seed?: string; - keys: TestKeyData[]; + mnemonic?: string; + seed?: string; + keys: TestKeyData[]; } interface CurveTestData { - curve: ECDSA.CurveName; - chain: TestChain[]; + curve: ECDSA.CurveName; + chain: TestChain[]; } const testData: CurveTestData[] = [ - { - curve: "secp256k1", - chain: [ - { - seed: "000102030405060708090a0b0c0d0e0f", - keys: [ - { - path: [], - chain: "873dff81c02f525623fd1fe5167eac3a55a049de3d314bb42ee227ffed37d508", - priv: "e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35", - }, - { - path: [0 | Hard], - chain: "47fdacbd0f1097043b78c63c20c34ef4ed9a111d980047ad16282c7ae6236141", - priv: "edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea", - }, - { - path: [0 | Hard, 1], - chain: "2a7857631386ba23dacac34180dd1983734e444fdbf774041578e9b6adb37c19", - priv: "3c6cb8d0f6a264c91ea8b5030fadaa8e538b020f0a387421a12de9319dc93368", - }, - { - path: [0 | Hard, 1, 2 | Hard], - chain: "04466b9cc8e161e966409ca52986c584f07e9dc81f735db683c3ff6ec7b1503f", - priv: "cbce0d719ecf7431d88e6a89fa1483e02e35092af60c042b1df2ff59fa424dca", - }, - { - path: [0 | Hard, 1, 2 | Hard, 2], - chain: "cfb71883f01676f587d023cc53a35bc7f88f724b1f8c2892ac1275ac822a3edd", - priv: "0f479245fb19a38a1954c5c7c0ebab2f9bdfd96a17563ef28a6a4b1a2a764ef4", - }, - { - path: [0 | Hard, 1, 2 | Hard, 2, 1000000000], - chain: "c783e67b921d2beb8f6b389cc646d7263b4145701dadd2161548a8b078e65e9e", - priv: "471b76e389e528d6de6d816857e012c5455051cad6660850e58372a6c3e6e7c8", - }, - ], - }, - { - seed: "fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542", - keys: [ - { - path: [], - chain: "60499f801b896d83179a4374aeb7822aaeaceaa0db1f85ee3e904c4defbd9689", - priv: "4b03d6fc340455b363f51020ad3ecca4f0850280cf436c70c727923f6db46c3e", - }, - { - path: [0], - chain: "f0909affaa7ee7abe5dd4e100598d4dc53cd709d5a5c2cac40e7412f232f7c9c", - priv: "abe74a98f6c7eabee0428f53798f0ab8aa1bd37873999041703c742f15ac7e1e", - }, - { - path: [0, 2147483647 | Hard], - chain: "be17a268474a6bb9c61e1d720cf6215e2a88c5406c4aee7b38547f585c9a37d9", - priv: "877c779ad9687164e9c2f4f0f4ff0340814392330693ce95a58fe18fd52e6e93", - }, - { - path: [0, 2147483647 | Hard, 1], - chain: "f366f48f1ea9f2d1d3fe958c95ca84ea18e4c4ddb9366c336c927eb246fb38cb", - priv: "704addf544a06e5ee4bea37098463c23613da32020d604506da8c0518e1da4b7", - }, - { - path: [0, 2147483647 | Hard, 1, 2147483646 | Hard], - chain: "637807030d55d01f9a0cb3a7839515d796bd07706386a6eddf06cc29a65a0e29", - priv: "f1c7c871a54a804afe328b4c83a1c33b8e5ff48f5087273f04efa83b247d6a2d", - }, - { - path: [0, 2147483647 | Hard, 1, 2147483646 | Hard, 2], - chain: "9452b549be8cea3ecb7a84bec10dcfd94afe4d129ebfd3b3cb58eedf394ed271", - priv: "bb7d39bdb83ecf58f2fd82b6d918341cbef428661ef01ab97c28a4842125ac23", - }, - ], - }, - // from Ledger - { - mnemonic: - "miracle blush border auto country easily icon below finish fruit base shift lift old farm wild room symbol ocean attitude ill tank soon know", - keys: [ - { - path: [44 | Hard, 1729 | Hard], - }, - ], - }, - // BOLOS test suite - { - seed: "5eb00bbddcf069084889a8ab9155568165f5c453ccb85e70811aaed6f6da5fc19a5ac40b389cd370d086206dec8aa6c43daea6690f20ad3d8d48b2d2ce9e38e4", - keys: [ - { - path: [738197632, 335544448 | Hard, 0, 0], - chain: "0524d4d89a04e06f0410003751306bbe7a1c4e80608433d12469fe6a92eecb43", - priv: "f7dd8c0fb5023c6fce668c035560a40914abea017d83b792b15563d6feb1251b", - }, - { - path: [738197504, 335544320 | Hard, 16777216, 33554432], - chain: "336717d2389fd2886088c3dff5ceb66ef6064ad90e0a0d07a867064d1c074864", - priv: "32cc0b6f100f76d724738926fd406f9b476770ba970c369318943562e70011e6", - }, - { - path: [44 | Hard, 148 | Hard, 0, 0], - chain: "8fff97b457b717b0cad899d2818b5d43165f350f31c5d5598cc71bbde707d604", - priv: "002e694a441a412fc0ca8c3a6dcc27a5da20f69341490bb27cddcd63db5b90ce", - }, - ], - }, + { + curve: 'secp256k1', + chain: [ + { + seed: '000102030405060708090a0b0c0d0e0f', + keys: [ + { + path: [], + chain: '873dff81c02f525623fd1fe5167eac3a55a049de3d314bb42ee227ffed37d508', + priv: 'e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35', + }, + { + path: [0 | Hard], + chain: '47fdacbd0f1097043b78c63c20c34ef4ed9a111d980047ad16282c7ae6236141', + priv: 'edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea', + }, + { + path: [0 | Hard, 1], + chain: '2a7857631386ba23dacac34180dd1983734e444fdbf774041578e9b6adb37c19', + priv: '3c6cb8d0f6a264c91ea8b5030fadaa8e538b020f0a387421a12de9319dc93368', + }, + { + path: [0 | Hard, 1, 2 | Hard], + chain: '04466b9cc8e161e966409ca52986c584f07e9dc81f735db683c3ff6ec7b1503f', + priv: 'cbce0d719ecf7431d88e6a89fa1483e02e35092af60c042b1df2ff59fa424dca', + }, + { + path: [0 | Hard, 1, 2 | Hard, 2], + chain: 'cfb71883f01676f587d023cc53a35bc7f88f724b1f8c2892ac1275ac822a3edd', + priv: '0f479245fb19a38a1954c5c7c0ebab2f9bdfd96a17563ef28a6a4b1a2a764ef4', + }, + { + path: [0 | Hard, 1, 2 | Hard, 2, 1000000000], + chain: 'c783e67b921d2beb8f6b389cc646d7263b4145701dadd2161548a8b078e65e9e', + priv: '471b76e389e528d6de6d816857e012c5455051cad6660850e58372a6c3e6e7c8', + }, ], - }, - { - curve: "p256", - chain: [ - { - seed: "000102030405060708090a0b0c0d0e0f", - keys: [ - { - path: [], - chain: "beeb672fe4621673f722f38529c07392fecaa61015c80c34f29ce8b41b3cb6ea", - priv: "612091aaa12e22dd2abef664f8a01a82cae99ad7441b7ef8110424915c268bc2", - }, - { - path: [0 | Hard], - chain: "3460cea53e6a6bb5fb391eeef3237ffd8724bf0a40e94943c98b83825342ee11", - priv: "6939694369114c67917a182c59ddb8cafc3004e63ca5d3b84403ba8613debc0c", - }, - { - path: [0 | Hard, 1], - chain: "4187afff1aafa8445010097fb99d23aee9f599450c7bd140b6826ac22ba21d0c", - priv: "284e9d38d07d21e4e281b645089a94f4cf5a5a81369acf151a1c3a57f18b2129", - }, - { - path: [0 | Hard, 1, 2 | Hard], - chain: "98c7514f562e64e74170cc3cf304ee1ce54d6b6da4f880f313e8204c2a185318", - priv: "694596e8a54f252c960eb771a3c41e7e32496d03b954aeb90f61635b8e092aa7", - }, - { - path: [0 | Hard, 1, 2 | Hard, 2], - chain: "ba96f776a5c3907d7fd48bde5620ee374d4acfd540378476019eab70790c63a0", - priv: "5996c37fd3dd2679039b23ed6f70b506c6b56b3cb5e424681fb0fa64caf82aaa", - }, - { - path: [0 | Hard, 1, 2 | Hard, 2, 1000000000], - chain: "b9b7b82d326bb9cb5b5b121066feea4eb93d5241103c9e7a18aad40f1dde8059", - priv: "21c4f269ef0a5fd1badf47eeacebeeaa3de22eb8e5b0adcd0f27dd99d34d0119", - }, - // derivation retry - { - path: [], - chain: "beeb672fe4621673f722f38529c07392fecaa61015c80c34f29ce8b41b3cb6ea", - priv: "612091aaa12e22dd2abef664f8a01a82cae99ad7441b7ef8110424915c268bc2", - }, - { - path: [28578 | Hard], - chain: "e94c8ebe30c2250a14713212f6449b20f3329105ea15b652ca5bdfc68f6c65c2", - priv: "06f0db126f023755d0b8d86d4591718a5210dd8d024e3e14b6159d63f53aa669", - }, - { - path: [28578 | Hard, 33941], - chain: "9e87fe95031f14736774cd82f25fd885065cb7c358c1edf813c72af535e83071", - priv: "092154eed4af83e078ff9b84322015aefe5769e31270f62c3f66c33888335f3a", - }, - ], - }, - { - seed: "fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542", - keys: [ - { - path: [], - chain: "96cd4465a9644e31528eda3592aa35eb39a9527769ce1855beafc1b81055e75d", - priv: "eaa31c2e46ca2962227cf21d73a7ef0ce8b31c756897521eb6c7b39796633357", - }, - { - path: [0], - chain: "84e9c258bb8557a40e0d041115b376dd55eda99c0042ce29e81ebe4efed9b86a", - priv: "d7d065f63a62624888500cdb4f88b6d59c2927fee9e6d0cdff9cad555884df6e", - }, - { - path: [0, 2147483647 | Hard], - chain: "f235b2bc5c04606ca9c30027a84f353acf4e4683edbd11f635d0dcc1cd106ea6", - priv: "96d2ec9316746a75e7793684ed01e3d51194d81a42a3276858a5b7376d4b94b9", - }, - { - path: [0, 2147483647 | Hard, 1], - chain: "7c0b833106235e452eba79d2bdd58d4086e663bc8cc55e9773d2b5eeda313f3b", - priv: "974f9096ea6873a915910e82b29d7c338542ccde39d2064d1cc228f371542bbc", - }, - { - path: [0, 2147483647 | Hard, 1, 2147483646 | Hard], - chain: "5794e616eadaf33413aa309318a26ee0fd5163b70466de7a4512fd4b1a5c9e6a", - priv: "da29649bbfaff095cd43819eda9a7be74236539a29094cd8336b07ed8d4eff63", - }, - { - path: [0, 2147483647 | Hard, 1, 2147483646 | Hard, 2], - chain: "3bfb29ee8ac4484f09db09c2079b520ea5616df7820f071a20320366fbe226a7", - priv: "bb0a77ba01cc31d77205d51d08bd313b979a71ef4de9b062f8958297e746bd67", - }, - ], - }, - // seed retry - { - seed: "a7305bc8df8d0951f0cb224c0e95d7707cbdf2c6ce7e8d481fec69c7ff5e9446", - keys: [ - { - path: [], - chain: "7762f9729fed06121fd13f326884c82f59aa95c57ac492ce8c9654e60efd130c", - priv: "3b8c18469a4634517d6d0b65448f8e6c62091b45540a1743c5846be55d47d88f", - }, - ], - }, - // from Ledger - { - mnemonic: - "miracle blush border auto country easily icon below finish fruit base shift lift old farm wild room symbol ocean attitude ill tank soon know", - keys: [ - { - path: [44 | Hard, 1729 | Hard], - }, - ], - }, - // BOLOS test suite - { - seed: "5eb00bbddcf069084889a8ab9155568165f5c453ccb85e70811aaed6f6da5fc19a5ac40b389cd370d086206dec8aa6c43daea6690f20ad3d8d48b2d2ce9e38e4", - keys: [ - { - path: [738197632, 335544448 | Hard, 0, 0], - chain: "cdc590746b238933166da99295ef0de9e048c9ef0717c269616613ac14e52934", - priv: "64461c084badf0064b2cd6c9aacf010ec073e850170bae02643d1b7f9574baf7", - }, - { - path: [738197504, 335544320 | Hard, 16777216, 33554432], - chain: "eb9bc0b0773fcbb10c4a3078c0a3bc2309ec0b4f28065d6224c5777b6b9e83cd", - priv: "3cbf2b3d850e1a8f47b35271d0156ca482debef29bdfa5285386d47eefb87204", - }, - { - path: [44 | Hard, 148 | Hard, 0, 0], - chain: "bba08de0a440987023821d4d82a39c46068e8c8ebe23be0e0329a7dc6467a30d", - priv: "7b95d7cb3fc819eb4ac356644eb3467d465d5eb5f4703f39670a03139b6cdf56", - }, - ], - }, + }, + { + seed: 'fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542', + keys: [ + { + path: [], + chain: '60499f801b896d83179a4374aeb7822aaeaceaa0db1f85ee3e904c4defbd9689', + priv: '4b03d6fc340455b363f51020ad3ecca4f0850280cf436c70c727923f6db46c3e', + }, + { + path: [0], + chain: 'f0909affaa7ee7abe5dd4e100598d4dc53cd709d5a5c2cac40e7412f232f7c9c', + priv: 'abe74a98f6c7eabee0428f53798f0ab8aa1bd37873999041703c742f15ac7e1e', + }, + { + path: [0, 2147483647 | Hard], + chain: 'be17a268474a6bb9c61e1d720cf6215e2a88c5406c4aee7b38547f585c9a37d9', + priv: '877c779ad9687164e9c2f4f0f4ff0340814392330693ce95a58fe18fd52e6e93', + }, + { + path: [0, 2147483647 | Hard, 1], + chain: 'f366f48f1ea9f2d1d3fe958c95ca84ea18e4c4ddb9366c336c927eb246fb38cb', + priv: '704addf544a06e5ee4bea37098463c23613da32020d604506da8c0518e1da4b7', + }, + { + path: [0, 2147483647 | Hard, 1, 2147483646 | Hard], + chain: '637807030d55d01f9a0cb3a7839515d796bd07706386a6eddf06cc29a65a0e29', + priv: 'f1c7c871a54a804afe328b4c83a1c33b8e5ff48f5087273f04efa83b247d6a2d', + }, + { + path: [0, 2147483647 | Hard, 1, 2147483646 | Hard, 2], + chain: '9452b549be8cea3ecb7a84bec10dcfd94afe4d129ebfd3b3cb58eedf394ed271', + priv: 'bb7d39bdb83ecf58f2fd82b6d918341cbef428661ef01ab97c28a4842125ac23', + }, ], - }, + }, + // from Ledger + { + mnemonic: + 'miracle blush border auto country easily icon below finish fruit base shift lift old farm wild room symbol ocean attitude ill tank soon know', + keys: [ + { + path: [44 | Hard, 1729 | Hard], + }, + ], + }, + // BOLOS test suite + { + seed: '5eb00bbddcf069084889a8ab9155568165f5c453ccb85e70811aaed6f6da5fc19a5ac40b389cd370d086206dec8aa6c43daea6690f20ad3d8d48b2d2ce9e38e4', + keys: [ + { + path: [738197632, 335544448 | Hard, 0, 0], + chain: '0524d4d89a04e06f0410003751306bbe7a1c4e80608433d12469fe6a92eecb43', + priv: 'f7dd8c0fb5023c6fce668c035560a40914abea017d83b792b15563d6feb1251b', + }, + { + path: [738197504, 335544320 | Hard, 16777216, 33554432], + chain: '336717d2389fd2886088c3dff5ceb66ef6064ad90e0a0d07a867064d1c074864', + priv: '32cc0b6f100f76d724738926fd406f9b476770ba970c369318943562e70011e6', + }, + { + path: [44 | Hard, 148 | Hard, 0, 0], + chain: '8fff97b457b717b0cad899d2818b5d43165f350f31c5d5598cc71bbde707d604', + priv: '002e694a441a412fc0ca8c3a6dcc27a5da20f69341490bb27cddcd63db5b90ce', + }, + ], + }, + ], + }, + { + curve: 'p256', + chain: [ + { + seed: '000102030405060708090a0b0c0d0e0f', + keys: [ + { + path: [], + chain: 'beeb672fe4621673f722f38529c07392fecaa61015c80c34f29ce8b41b3cb6ea', + priv: '612091aaa12e22dd2abef664f8a01a82cae99ad7441b7ef8110424915c268bc2', + }, + { + path: [0 | Hard], + chain: '3460cea53e6a6bb5fb391eeef3237ffd8724bf0a40e94943c98b83825342ee11', + priv: '6939694369114c67917a182c59ddb8cafc3004e63ca5d3b84403ba8613debc0c', + }, + { + path: [0 | Hard, 1], + chain: '4187afff1aafa8445010097fb99d23aee9f599450c7bd140b6826ac22ba21d0c', + priv: '284e9d38d07d21e4e281b645089a94f4cf5a5a81369acf151a1c3a57f18b2129', + }, + { + path: [0 | Hard, 1, 2 | Hard], + chain: '98c7514f562e64e74170cc3cf304ee1ce54d6b6da4f880f313e8204c2a185318', + priv: '694596e8a54f252c960eb771a3c41e7e32496d03b954aeb90f61635b8e092aa7', + }, + { + path: [0 | Hard, 1, 2 | Hard, 2], + chain: 'ba96f776a5c3907d7fd48bde5620ee374d4acfd540378476019eab70790c63a0', + priv: '5996c37fd3dd2679039b23ed6f70b506c6b56b3cb5e424681fb0fa64caf82aaa', + }, + { + path: [0 | Hard, 1, 2 | Hard, 2, 1000000000], + chain: 'b9b7b82d326bb9cb5b5b121066feea4eb93d5241103c9e7a18aad40f1dde8059', + priv: '21c4f269ef0a5fd1badf47eeacebeeaa3de22eb8e5b0adcd0f27dd99d34d0119', + }, + // derivation retry + { + path: [], + chain: 'beeb672fe4621673f722f38529c07392fecaa61015c80c34f29ce8b41b3cb6ea', + priv: '612091aaa12e22dd2abef664f8a01a82cae99ad7441b7ef8110424915c268bc2', + }, + { + path: [28578 | Hard], + chain: 'e94c8ebe30c2250a14713212f6449b20f3329105ea15b652ca5bdfc68f6c65c2', + priv: '06f0db126f023755d0b8d86d4591718a5210dd8d024e3e14b6159d63f53aa669', + }, + { + path: [28578 | Hard, 33941], + chain: '9e87fe95031f14736774cd82f25fd885065cb7c358c1edf813c72af535e83071', + priv: '092154eed4af83e078ff9b84322015aefe5769e31270f62c3f66c33888335f3a', + }, + ], + }, + { + seed: 'fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542', + keys: [ + { + path: [], + chain: '96cd4465a9644e31528eda3592aa35eb39a9527769ce1855beafc1b81055e75d', + priv: 'eaa31c2e46ca2962227cf21d73a7ef0ce8b31c756897521eb6c7b39796633357', + }, + { + path: [0], + chain: '84e9c258bb8557a40e0d041115b376dd55eda99c0042ce29e81ebe4efed9b86a', + priv: 'd7d065f63a62624888500cdb4f88b6d59c2927fee9e6d0cdff9cad555884df6e', + }, + { + path: [0, 2147483647 | Hard], + chain: 'f235b2bc5c04606ca9c30027a84f353acf4e4683edbd11f635d0dcc1cd106ea6', + priv: '96d2ec9316746a75e7793684ed01e3d51194d81a42a3276858a5b7376d4b94b9', + }, + { + path: [0, 2147483647 | Hard, 1], + chain: '7c0b833106235e452eba79d2bdd58d4086e663bc8cc55e9773d2b5eeda313f3b', + priv: '974f9096ea6873a915910e82b29d7c338542ccde39d2064d1cc228f371542bbc', + }, + { + path: [0, 2147483647 | Hard, 1, 2147483646 | Hard], + chain: '5794e616eadaf33413aa309318a26ee0fd5163b70466de7a4512fd4b1a5c9e6a', + priv: 'da29649bbfaff095cd43819eda9a7be74236539a29094cd8336b07ed8d4eff63', + }, + { + path: [0, 2147483647 | Hard, 1, 2147483646 | Hard, 2], + chain: '3bfb29ee8ac4484f09db09c2079b520ea5616df7820f071a20320366fbe226a7', + priv: 'bb0a77ba01cc31d77205d51d08bd313b979a71ef4de9b062f8958297e746bd67', + }, + ], + }, + // seed retry + { + seed: 'a7305bc8df8d0951f0cb224c0e95d7707cbdf2c6ce7e8d481fec69c7ff5e9446', + keys: [ + { + path: [], + chain: '7762f9729fed06121fd13f326884c82f59aa95c57ac492ce8c9654e60efd130c', + priv: '3b8c18469a4634517d6d0b65448f8e6c62091b45540a1743c5846be55d47d88f', + }, + ], + }, + // from Ledger + { + mnemonic: + 'miracle blush border auto country easily icon below finish fruit base shift lift old farm wild room symbol ocean attitude ill tank soon know', + keys: [ + { + path: [44 | Hard, 1729 | Hard], + }, + ], + }, + // BOLOS test suite + { + seed: '5eb00bbddcf069084889a8ab9155568165f5c453ccb85e70811aaed6f6da5fc19a5ac40b389cd370d086206dec8aa6c43daea6690f20ad3d8d48b2d2ce9e38e4', + keys: [ + { + path: [738197632, 335544448 | Hard, 0, 0], + chain: 'cdc590746b238933166da99295ef0de9e048c9ef0717c269616613ac14e52934', + priv: '64461c084badf0064b2cd6c9aacf010ec073e850170bae02643d1b7f9574baf7', + }, + { + path: [738197504, 335544320 | Hard, 16777216, 33554432], + chain: 'eb9bc0b0773fcbb10c4a3078c0a3bc2309ec0b4f28065d6224c5777b6b9e83cd', + priv: '3cbf2b3d850e1a8f47b35271d0156ca482debef29bdfa5285386d47eefb87204', + }, + { + path: [44 | Hard, 148 | Hard, 0, 0], + chain: 'bba08de0a440987023821d4d82a39c46068e8c8ebe23be0e0329a7dc6467a30d', + priv: '7b95d7cb3fc819eb4ac356644eb3467d465d5eb5f4703f39670a03139b6cdf56', + }, + ], + }, + ], + }, ]; -describe("ECDSA", () => { - for (const curve of testData) { - describe(curve.curve, () => { - for (const chain of curve.chain) { - describe(chain.seed || "mnemonic", () => { - const seed = chain.seed || Bip39.mnemonicToSeedSync(chain.mnemonic || "", ""); - const root = ECDSA.PrivateKey.fromSeed(seed, curve.curve); - for (const keyData of chain.keys) { - it(JSON.stringify(keyData.path.map((x) => x >>> 0)), () => { - const key = root.derivePath(keyData.path); - if (keyData.chain) { - expect(Buffer.from(key.chainCode).toString("hex")).toBe(keyData.chain); - } - if (keyData.priv) { - expect(Buffer.from(key.bytes()).toString("hex")).toBe(keyData.priv); - } - }); - } - }); - } +describe('ECDSA', () => { + for (const curve of testData) { + describe(curve.curve, () => { + for (const chain of curve.chain) { + describe(chain.seed || 'mnemonic', () => { + const seed = chain.seed || Bip39.mnemonicToSeedSync(chain.mnemonic || '', ''); + const root = ECDSA.PrivateKey.fromSeed(seed, curve.curve); + for (const keyData of chain.keys) { + it(stringify(keyData.path.map((x) => x >>> 0)), () => { + const key = root.derivePath(keyData.path); + if (keyData.chain) { + expect(Buffer.from(key.chainCode).toString('hex')).toBe(keyData.chain); + } + if (keyData.priv) { + expect(Buffer.from(key.bytes()).toString('hex')).toBe(keyData.priv); + } + }); + } }); - } + } + }); + } }); diff --git a/packages/taquito-signer/test/ed25519.spec.ts b/packages/taquito-signer/test/ed25519.spec.ts index e9f83834d7..c21b8e346c 100644 --- a/packages/taquito-signer/test/ed25519.spec.ts +++ b/packages/taquito-signer/test/ed25519.spec.ts @@ -1,148 +1,150 @@ -import { Ed25519, Hard } from "../src/derivation-tools"; -import * as Bip39 from 'bip39' -import { InvalidSeedLengthError } from "../src/errors"; +import { Ed25519, Hard } from '../src/derivation-tools'; +import * as Bip39 from 'bip39'; +import { InvalidSeedLengthError } from '../src/errors'; +import { stringify } from '@taquito/core'; interface TestKeyData { - path: number[]; - chain?: string; - priv?: string; + path: number[]; + chain?: string; + priv?: string; } interface TestChain { - mnemonic?: string; - seed?: string; - keys: TestKeyData[]; + mnemonic?: string; + seed?: string; + keys: TestKeyData[]; } const testData: TestChain[] = [ - { - seed: "000102030405060708090a0b0c0d0e0f", - keys: [ - { - path: [], - chain: "90046a93de5380a72b5e45010748567d5ea02bbf6522f979e05c0d8d8ca9fffb", - priv: "2b4be7f19ee27bbf30c667b642d5f4aa69fd169872f8fc3059c08ebae2eb19e7", - }, - { - path: [0 | Hard], - chain: "8b59aa11380b624e81507a27fedda59fea6d0b779a778918a2fd3590e16e9c69", - priv: "68e0fe46dfb67e368c75379acec591dad19df3cde26e63b93a8e704f1dade7a3", - }, - { - path: [0 | Hard, 1 | Hard], - chain: "a320425f77d1b5c2505a6b1b27382b37368ee640e3557c315416801243552f14", - priv: "b1d0bad404bf35da785a64ca1ac54b2617211d2777696fbffaf208f746ae84f2", - }, - { - path: [0 | Hard, 1 | Hard, 2 | Hard], - chain: "2e69929e00b5ab250f49c3fb1c12f252de4fed2c1db88387094a0f8c4c9ccd6c", - priv: "92a5b23c0b8a99e37d07df3fb9966917f5d06e02ddbd909c7e184371463e9fc9", - }, - { - path: [0 | Hard, 1 | Hard, 2 | Hard, 2 | Hard], - chain: "8f6d87f93d750e0efccda017d662a1b31a266e4a6f5993b15f5c1f07f74dd5cc", - priv: "30d1dc7e5fc04c31219ab25a27ae00b50f6fd66622f6e9c913253d6511d1e662", - }, - { - path: [0 | Hard, 1 | Hard, 2 | Hard, 2 | Hard, 1000000000 | Hard], - chain: "68789923a0cac2cd5a29172a475fe9e0fb14cd6adb5ad98a3fa70333e7afa230", - priv: "8f94d394a8e8fd6b1bc2f3f49f5c47e385281d5c17e65324b0f62483e37e8793", - }, - ], - }, - { - seed: "fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542", - keys: [ - { - path: [], - chain: "ef70a74db9c3a5af931b5fe73ed8e1a53464133654fd55e7a66f8570b8e33c3b", - priv: "171cb88b1b3c1db25add599712e36245d75bc65a1a5c9e18d76f9f2b1eab4012", - }, - { - path: [0 | Hard], - chain: "0b78a3226f915c082bf118f83618a618ab6dec793752624cbeb622acb562862d", - priv: "1559eb2bbec5790b0c65d8693e4d0875b1747f4970ae8b650486ed7470845635", - }, - { - path: [0 | Hard, 2147483647 | Hard], - chain: "138f0b2551bcafeca6ff2aa88ba8ed0ed8de070841f0c4ef0165df8181eaad7f", - priv: "ea4f5bfe8694d8bb74b7b59404632fd5968b774ed545e810de9c32a4fb4192f4", - }, - { - path: [0 | Hard, 2147483647 | Hard, 1 | Hard], - chain: "73bd9fff1cfbde33a1b846c27085f711c0fe2d66fd32e139d3ebc28e5a4a6b90", - priv: "3757c7577170179c7868353ada796c839135b3d30554bbb74a4b1e4a5a58505c", - }, - { - path: [0 | Hard, 2147483647 | Hard, 1 | Hard, 2147483646 | Hard], - chain: "0902fe8a29f9140480a00ef244bd183e8a13288e4412d8389d140aac1794825a", - priv: "5837736c89570de861ebc173b1086da4f505d4adb387c6a1b1342d5e4ac9ec72", - }, - { - path: [0 | Hard, 2147483647 | Hard, 1 | Hard, 2147483646 | Hard, 2 | Hard], - chain: "5d70af781f3a37b829f0d060924d5e960bdc02e85423494afc0b1a41bbe196d4", - priv: "551d333177df541ad876a60ea71f00447931c0a9da16f227c11ea080d7391b8d", - }, - ], - }, - // from Ledger - { - mnemonic: - "miracle blush border auto country easily icon below finish fruit base shift lift old farm wild room symbol ocean attitude ill tank soon know", - keys: [ - { - path: [44 | Hard, 1729 | Hard], - }, - ], - }, - // BOLOS - { - seed: "5eb00bbddcf069084889a8ab9155568165f5c453ccb85e70811aaed6f6da5fc19a5ac40b389cd370d086206dec8aa6c43daea6690f20ad3d8d48b2d2ce9e38e4", - keys: [ - { - path: [738197632 | Hard, 335544448 | Hard, 0 | Hard, 0 | Hard], - chain: "b609a7af6a8ae5568bff26a3747aa0c4d8b383144db5c3da28650a37015f2503", - priv: "9761691a62523b637c55aa267b3c4835b7cdd4bb704b399a0f7290ca570262cb", - }, - { - path: [738197504 | Hard, 335544320 | Hard, 16777216 | Hard, 33554432 | Hard], - chain: "1a8e8df02b17fd4632529dab6443887359ecf94d547291535952b412cba88420", - priv: "e36a66d67ea0d2dcf9af54bc4617c0fa0724b42acff17501ac9dd27588bbd7dd", - }, - { - path: [44 | Hard, 148 | Hard, 0 | Hard, 0 | Hard], - chain: "ad38cb3640dd5a1e7540030761ec7ade17a8b38a203c37072647ec22eea7a3ba", - priv: "a044cf4dcc4c6206d64ea3a7dae79337afcd61808dc6239a22c1ba1f4618c055", - }, - { - path: [44 | Hard, 148 | Hard, 1 | Hard, 2 | Hard], - chain: "fbc472b0a324f71f264c6b002524a93a690a3d9fd130c9ca949d0ccc1e37b07e", - priv: "889fc3bc31029c0f09eb6a24f1617af15b919dc9a6b3caac3c57383da094a157", - }, - ], - }, + { + seed: '000102030405060708090a0b0c0d0e0f', + keys: [ + { + path: [], + chain: '90046a93de5380a72b5e45010748567d5ea02bbf6522f979e05c0d8d8ca9fffb', + priv: '2b4be7f19ee27bbf30c667b642d5f4aa69fd169872f8fc3059c08ebae2eb19e7', + }, + { + path: [0 | Hard], + chain: '8b59aa11380b624e81507a27fedda59fea6d0b779a778918a2fd3590e16e9c69', + priv: '68e0fe46dfb67e368c75379acec591dad19df3cde26e63b93a8e704f1dade7a3', + }, + { + path: [0 | Hard, 1 | Hard], + chain: 'a320425f77d1b5c2505a6b1b27382b37368ee640e3557c315416801243552f14', + priv: 'b1d0bad404bf35da785a64ca1ac54b2617211d2777696fbffaf208f746ae84f2', + }, + { + path: [0 | Hard, 1 | Hard, 2 | Hard], + chain: '2e69929e00b5ab250f49c3fb1c12f252de4fed2c1db88387094a0f8c4c9ccd6c', + priv: '92a5b23c0b8a99e37d07df3fb9966917f5d06e02ddbd909c7e184371463e9fc9', + }, + { + path: [0 | Hard, 1 | Hard, 2 | Hard, 2 | Hard], + chain: '8f6d87f93d750e0efccda017d662a1b31a266e4a6f5993b15f5c1f07f74dd5cc', + priv: '30d1dc7e5fc04c31219ab25a27ae00b50f6fd66622f6e9c913253d6511d1e662', + }, + { + path: [0 | Hard, 1 | Hard, 2 | Hard, 2 | Hard, 1000000000 | Hard], + chain: '68789923a0cac2cd5a29172a475fe9e0fb14cd6adb5ad98a3fa70333e7afa230', + priv: '8f94d394a8e8fd6b1bc2f3f49f5c47e385281d5c17e65324b0f62483e37e8793', + }, + ], + }, + { + seed: 'fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542', + keys: [ + { + path: [], + chain: 'ef70a74db9c3a5af931b5fe73ed8e1a53464133654fd55e7a66f8570b8e33c3b', + priv: '171cb88b1b3c1db25add599712e36245d75bc65a1a5c9e18d76f9f2b1eab4012', + }, + { + path: [0 | Hard], + chain: '0b78a3226f915c082bf118f83618a618ab6dec793752624cbeb622acb562862d', + priv: '1559eb2bbec5790b0c65d8693e4d0875b1747f4970ae8b650486ed7470845635', + }, + { + path: [0 | Hard, 2147483647 | Hard], + chain: '138f0b2551bcafeca6ff2aa88ba8ed0ed8de070841f0c4ef0165df8181eaad7f', + priv: 'ea4f5bfe8694d8bb74b7b59404632fd5968b774ed545e810de9c32a4fb4192f4', + }, + { + path: [0 | Hard, 2147483647 | Hard, 1 | Hard], + chain: '73bd9fff1cfbde33a1b846c27085f711c0fe2d66fd32e139d3ebc28e5a4a6b90', + priv: '3757c7577170179c7868353ada796c839135b3d30554bbb74a4b1e4a5a58505c', + }, + { + path: [0 | Hard, 2147483647 | Hard, 1 | Hard, 2147483646 | Hard], + chain: '0902fe8a29f9140480a00ef244bd183e8a13288e4412d8389d140aac1794825a', + priv: '5837736c89570de861ebc173b1086da4f505d4adb387c6a1b1342d5e4ac9ec72', + }, + { + path: [0 | Hard, 2147483647 | Hard, 1 | Hard, 2147483646 | Hard, 2 | Hard], + chain: '5d70af781f3a37b829f0d060924d5e960bdc02e85423494afc0b1a41bbe196d4', + priv: '551d333177df541ad876a60ea71f00447931c0a9da16f227c11ea080d7391b8d', + }, + ], + }, + // from Ledger + { + mnemonic: + 'miracle blush border auto country easily icon below finish fruit base shift lift old farm wild room symbol ocean attitude ill tank soon know', + keys: [ + { + path: [44 | Hard, 1729 | Hard], + }, + ], + }, + // BOLOS + { + seed: '5eb00bbddcf069084889a8ab9155568165f5c453ccb85e70811aaed6f6da5fc19a5ac40b389cd370d086206dec8aa6c43daea6690f20ad3d8d48b2d2ce9e38e4', + keys: [ + { + path: [738197632 | Hard, 335544448 | Hard, 0 | Hard, 0 | Hard], + chain: 'b609a7af6a8ae5568bff26a3747aa0c4d8b383144db5c3da28650a37015f2503', + priv: '9761691a62523b637c55aa267b3c4835b7cdd4bb704b399a0f7290ca570262cb', + }, + { + path: [738197504 | Hard, 335544320 | Hard, 16777216 | Hard, 33554432 | Hard], + chain: '1a8e8df02b17fd4632529dab6443887359ecf94d547291535952b412cba88420', + priv: 'e36a66d67ea0d2dcf9af54bc4617c0fa0724b42acff17501ac9dd27588bbd7dd', + }, + { + path: [44 | Hard, 148 | Hard, 0 | Hard, 0 | Hard], + chain: 'ad38cb3640dd5a1e7540030761ec7ade17a8b38a203c37072647ec22eea7a3ba', + priv: 'a044cf4dcc4c6206d64ea3a7dae79337afcd61808dc6239a22c1ba1f4618c055', + }, + { + path: [44 | Hard, 148 | Hard, 1 | Hard, 2 | Hard], + chain: 'fbc472b0a324f71f264c6b002524a93a690a3d9fd130c9ca949d0ccc1e37b07e', + priv: '889fc3bc31029c0f09eb6a24f1617af15b919dc9a6b3caac3c57383da094a157', + }, + ], + }, ]; -const badSeed = "fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542ababababababababababababababababababababab" +const badSeed = + 'fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542ababababababababababababababababababababab'; -describe("Ed25519", () => { - for (const d of testData) { - describe(d.seed || "mnemonic", () => { - const seed = d.seed || Bip39.mnemonicToSeedSync(d.mnemonic || ""); - const root = Ed25519.PrivateKey.fromSeed(seed); - for (const keyData of d.keys) { - it(JSON.stringify(keyData.path.map((x) => x >>> 0)), () => { - const key = root.derivePath(keyData.path); - if (keyData.chain) { - expect(Buffer.from(key.chainCode).toString("hex")).toBe(keyData.chain); - } - if (keyData.priv) { - expect(Buffer.from(key.seed()).toString("hex")).toBe(keyData.priv); - } - }); - } +describe('Ed25519', () => { + for (const d of testData) { + describe(d.seed || 'mnemonic', () => { + const seed = d.seed || Bip39.mnemonicToSeedSync(d.mnemonic || ''); + const root = Ed25519.PrivateKey.fromSeed(seed); + for (const keyData of d.keys) { + it(stringify(keyData.path.map((x) => x >>> 0)), () => { + const key = root.derivePath(keyData.path); + if (keyData.chain) { + expect(Buffer.from(key.chainCode).toString('hex')).toBe(keyData.chain); + } + if (keyData.priv) { + expect(Buffer.from(key.seed()).toString('hex')).toBe(keyData.priv); + } }); - } - it('Should reject with bad seed', () => { - expect(() => Ed25519.PrivateKey.fromSeed(badSeed)).toThrowError(InvalidSeedLengthError) - }) + } + }); + } + it('Should reject with bad seed', () => { + expect(() => Ed25519.PrivateKey.fromSeed(badSeed)).toThrowError(InvalidSeedLengthError); + }); }); diff --git a/packages/taquito-tzip16/src/viewKind/michelson-storage-view.ts b/packages/taquito-tzip16/src/viewKind/michelson-storage-view.ts index b01373da94..6859caa200 100644 --- a/packages/taquito-tzip16/src/viewKind/michelson-storage-view.ts +++ b/packages/taquito-tzip16/src/viewKind/michelson-storage-view.ts @@ -13,7 +13,7 @@ import { import { ForbiddenInstructionInViewCodeError, NoParameterExpectedError } from '../errors'; import { validateAndExtractFailwith, TzReadProvider } from '@taquito/taquito'; import { View } from './interface'; -import { InvalidViewParameterError } from '@taquito/core'; +import { InvalidViewParameterError, stringify } from '@taquito/core'; export class MichelsonStorageView implements View { constructor( @@ -191,7 +191,7 @@ export class MichelsonStorageView implements View { const failWith = validateAndExtractFailwith(error); throw failWith ? new ViewSimulationError( - `The simulation of the Michelson view failed with: ${JSON.stringify(failWith)}`, + `The simulation of the Michelson view failed with: ${stringify(failWith)}`, this.viewName, failWith, error diff --git a/packages/taquito/src/batch/rpc-batch-provider.ts b/packages/taquito/src/batch/rpc-batch-provider.ts index 593c298da1..7101976ea5 100644 --- a/packages/taquito/src/batch/rpc-batch-provider.ts +++ b/packages/taquito/src/batch/rpc-batch-provider.ts @@ -35,6 +35,7 @@ import { InvalidKeyHashError, InvalidOperationKindError, InvalidAmountError, + stringify, } from '@taquito/core'; import { Provider } from '../provider'; import { PrepareProvider } from '../prepare'; @@ -236,7 +237,7 @@ export class OperationBatch extends Provider { ...param, }); default: - throw new InvalidOperationKindError(JSON.stringify((param as any).kind)); + throw new InvalidOperationKindError(stringify((param as any).kind)); } } @@ -278,7 +279,7 @@ export class OperationBatch extends Provider { this.withSmartRollupOriginate(param); break; default: - throw new InvalidOperationKindError(JSON.stringify((param as any).kind)); + throw new InvalidOperationKindError(stringify((param as any).kind)); } } diff --git a/packages/taquito/src/contract/contract-methods/contract-on-chain-view.ts b/packages/taquito/src/contract/contract-methods/contract-on-chain-view.ts index 4bc717dd6f..eea47ed2c7 100644 --- a/packages/taquito/src/contract/contract-methods/contract-on-chain-view.ts +++ b/packages/taquito/src/contract/contract-methods/contract-on-chain-view.ts @@ -13,7 +13,7 @@ import { ViewSimulationError, validateAndExtractFailwith, } from '../errors'; -import { InvalidViewParameterError } from '@taquito/core'; +import { InvalidViewParameterError, stringify } from '@taquito/core'; export interface ExecutionContextParams { source?: string; @@ -141,7 +141,7 @@ export class OnChainView { ? new ViewSimulationError( `The simulation of the on-chain view named ${ this._smartContractViewSchema.viewName - } failed with: ${JSON.stringify(failWith)}`, + } failed with: ${stringify(failWith)}`, this._smartContractViewSchema.viewName, failWith, error diff --git a/packages/taquito/src/contract/errors.ts b/packages/taquito/src/contract/errors.ts index c75c1d06cb..83e35dbff3 100644 --- a/packages/taquito/src/contract/errors.ts +++ b/packages/taquito/src/contract/errors.ts @@ -1,4 +1,4 @@ -import { ParameterValidationError, RpcError } from '@taquito/core'; +import { ParameterValidationError, RpcError, stringify } from '@taquito/core'; import { HttpResponseError } from '@taquito/http-utils'; import { MichelsonV1Expression } from '@taquito/rpc'; @@ -16,7 +16,7 @@ export class InvalidParameterError extends ParameterValidationError { this.name = 'InvalidParameterError'; this.message = `${smartContractMethodName} Received ${ invalidParams.length - } arguments while expecting one of the following signatures (${JSON.stringify(sigs)})`; + } arguments while expecting one of the following signatures (${stringify(sigs)})`; } } diff --git a/packages/taquito/src/injector/helper.ts b/packages/taquito/src/injector/helper.ts index 03dd64f3f4..18d483df2c 100644 --- a/packages/taquito/src/injector/helper.ts +++ b/packages/taquito/src/injector/helper.ts @@ -1,9 +1,10 @@ +import { stringify } from '@taquito/core'; import { HttpResponseError } from '@taquito/http-utils'; export function formatErrorMessage(error: HttpResponseError, stringToReplace: string) { const body = JSON.parse(error.body); if (body[0] && body[0].kind && body[0].msg) { - const newBody = JSON.stringify({ + const newBody = stringify({ kind: body[0].kind, id: body[0].id, msg: body[0].msg.replace(stringToReplace, ''), diff --git a/packages/taquito/src/operations/errors.ts b/packages/taquito/src/operations/errors.ts index cc987b0b78..2befd5d309 100644 --- a/packages/taquito/src/operations/errors.ts +++ b/packages/taquito/src/operations/errors.ts @@ -1,4 +1,4 @@ -import { ParameterValidationError, RpcError, TaquitoError } from '@taquito/core'; +import { ParameterValidationError, RpcError, TaquitoError, stringify } from '@taquito/core'; import { MichelsonV1ExpressionBase, OperationResult, @@ -55,7 +55,7 @@ export class TezosOperationError extends RpcError { } else if (lastError.with.int) { this.message = lastError.with.int; } else { - this.message = JSON.stringify(lastError.with); + this.message = stringify(lastError.with); } } } diff --git a/packages/taquito/src/wallet/wallet.ts b/packages/taquito/src/wallet/wallet.ts index d6bd43bdc4..23a5368fec 100644 --- a/packages/taquito/src/wallet/wallet.ts +++ b/packages/taquito/src/wallet/wallet.ts @@ -21,6 +21,7 @@ import { InvalidAddressError, InvalidContractAddressError, InvalidOperationKindError, + stringify, } from '@taquito/core'; import { validateAddress, @@ -132,7 +133,7 @@ export class WalletOperationBatch { case OpKind.INCREASE_PAID_STORAGE: return this.walletProvider.mapIncreasePaidStorageWalletParams(async () => param); default: - throw new InvalidOperationKindError(JSON.stringify((param as any).kind)); + throw new InvalidOperationKindError(stringify((param as any).kind)); } } @@ -159,7 +160,7 @@ export class WalletOperationBatch { this.withIncreasePaidStorage(param); break; default: - throw new InvalidOperationKindError(JSON.stringify((param as any).kind)); + throw new InvalidOperationKindError(stringify((param as any).kind)); } } diff --git a/packages/taquito/test/contract/rpc-contract-provider.spec.ts b/packages/taquito/test/contract/rpc-contract-provider.spec.ts index 8433d0d2eb..e89674d79c 100644 --- a/packages/taquito/test/contract/rpc-contract-provider.spec.ts +++ b/packages/taquito/test/contract/rpc-contract-provider.spec.ts @@ -25,6 +25,7 @@ import { OpKind, ParamsWithKind, TransferTicketParams } from '../../src/operatio import { NoopParser } from '../../src/taquito'; import { OperationBatch } from '../../src/batch/rpc-batch-provider'; import { PvmKind } from '@taquito/rpc'; +import { stringify } from '@taquito/core'; /** * RPCContractProvider test @@ -240,7 +241,7 @@ describe('RpcContractProvider test', () => { storageLimit: 257, }); - const res = JSON.parse(JSON.stringify(result.raw)); // Strip symbols + const res = JSON.parse(stringify(result.raw)); // Strip symbols expect(res).toEqual(originateResults); done(); @@ -257,7 +258,7 @@ describe('RpcContractProvider test', () => { storageLimit: 257, mutez: true, }); - const res = JSON.parse(JSON.stringify(result.raw)); // Strip symbols + const res = JSON.parse(stringify(result.raw)); // Strip symbols expect(res).toEqual(originateResultsMutezTrue); done(); @@ -274,7 +275,7 @@ describe('RpcContractProvider test', () => { init: miInit, }); - const res = JSON.parse(JSON.stringify(result.raw)); // Strip symbols + const res = JSON.parse(stringify(result.raw)); // Strip symbols expect(res).toEqual(originateResultsEstimate); done(); diff --git a/packages/taquito/test/parser/michel-codec-parser.spec.ts b/packages/taquito/test/parser/michel-codec-parser.spec.ts index 0e6f66eeae..08063f3ec5 100644 --- a/packages/taquito/test/parser/michel-codec-parser.spec.ts +++ b/packages/taquito/test/parser/michel-codec-parser.spec.ts @@ -1,3 +1,4 @@ +import { stringify } from '@taquito/core'; import { OriginateParams } from '../../src/operations/types'; import { Context, MichelCodecParser, Protocols, InvalidCodeParameter } from '../../src/taquito'; @@ -34,8 +35,8 @@ describe('MichelCodec parser', () => { const parser = new MichelCodecParser(new Context(mockRpcClient as any)); const result = await parser.prepareCodeOrigination(originateParams); - expect(JSON.stringify(result)).toEqual( - JSON.stringify({ + expect(stringify(result)).toEqual( + stringify({ code: [ { prim: 'parameter', args: [{ prim: 'int' }] }, { @@ -74,8 +75,8 @@ describe('MichelCodec parser', () => { const parser = new MichelCodecParser(new Context(mockRpcClient as any)); const result = await parser.prepareCodeOrigination(originateParams); - expect(JSON.stringify(result)).toEqual( - JSON.stringify({ + expect(stringify(result)).toEqual( + stringify({ code: [ { prim: 'parameter', args: [{ prim: 'int' }] }, { @@ -114,8 +115,8 @@ describe('MichelCodec parser', () => { const parser = new MichelCodecParser(new Context(mockRpcClient as any)); const result = await parser.prepareCodeOrigination(originateParams); - expect(JSON.stringify(result)).toEqual( - JSON.stringify({ + expect(stringify(result)).toEqual( + stringify({ code: [ { prim: 'parameter', args: [{ prim: 'int' }] }, { diff --git a/packages/taquito/test/prepare/prepare-provider.spec.ts b/packages/taquito/test/prepare/prepare-provider.spec.ts index 0568530098..797573caac 100644 --- a/packages/taquito/test/prepare/prepare-provider.spec.ts +++ b/packages/taquito/test/prepare/prepare-provider.spec.ts @@ -8,6 +8,7 @@ import { TransferTicketParams, OpKind } from '../../src/operations/types'; import { PvmKind } from '@taquito/rpc'; import { preparedTransactionMock } from '../helpers'; import { PreparedOperation } from '../../src/prepare'; +import { stringify } from '@taquito/core'; describe('PrepareProvider test', () => { let prepareProvider: PrepareProvider; @@ -171,7 +172,7 @@ describe('PrepareProvider test', () => { init: `"test"`, }); - const res = JSON.parse(JSON.stringify(prepared)); + const res = JSON.parse(stringify(prepared)); expect(res).toEqual(preparedOriginationOpWithReveal); }); @@ -190,7 +191,7 @@ describe('PrepareProvider test', () => { init: `"test"`, }); - const res = JSON.parse(JSON.stringify(prepared)); + const res = JSON.parse(stringify(prepared)); expect(res).toEqual(preparedOriginationOpNoReveal); }); diff --git a/packages/taquito/test/wallet/operation.spec.ts b/packages/taquito/test/wallet/operation.spec.ts index 698b50dcde..f729a550b3 100644 --- a/packages/taquito/test/wallet/operation.spec.ts +++ b/packages/taquito/test/wallet/operation.spec.ts @@ -3,11 +3,12 @@ import { BlockResponse } from '@taquito/rpc'; import { Context } from '../../src/context'; import { WalletOperation } from '../../src/wallet'; import { blockResponse } from './data'; +import { stringify } from '@taquito/core'; describe('WalletOperation', () => { let testScheduler: TestScheduler; - const toJSON = (x: any) => JSON.parse(JSON.stringify(x)); + const toJSON = (x: any) => JSON.parse(stringify(x)); const createFakeBlock = (level: number, opHash?: string) => { const op = { hash: `block_hash_${level}`,