From 82cb0ace7365753e7a57221baa40f64fb9b56b39 Mon Sep 17 00:00:00 2001 From: huianyang Date: Mon, 10 Jul 2023 15:05:52 -0700 Subject: [PATCH] perf: addressed pr comments --- .../tzip16-non-compliant-contract.spec.ts | 70 +++++++++---------- .../tzip16-non-compliant-wallet.spec.ts | 70 +++++++++---------- .../src/tzip12-contract-abstraction.ts | 2 +- .../test/tzip12-contract-abstraction.spec.ts | 6 +- packages/taquito-tzip16/src/errors.ts | 38 +++++----- .../src/handlers/tezos-storage-handler.ts | 16 ++--- .../taquito-tzip16/src/metadata-provider.ts | 8 +-- .../src/tzip16-contract-abstraction.ts | 12 ++-- .../src/viewKind/michelson-storage-view.ts | 12 ++-- .../handlers/tezos-storage-handler.spec.ts | 24 +++---- .../test/metadata-provider.spec.ts | 10 +-- .../test/tzip16-contract-abstraction.spec.ts | 10 +-- .../viewKind/michelson-storage-view.spec.ts | 36 +++++----- packages/taquito/src/contract/prepare.ts | 2 +- 14 files changed, 160 insertions(+), 156 deletions(-) diff --git a/integration-tests/tzip16-non-compliant-contract.spec.ts b/integration-tests/tzip16-non-compliant-contract.spec.ts index 570df960ea..93aa5ad200 100644 --- a/integration-tests/tzip16-non-compliant-contract.spec.ts +++ b/integration-tests/tzip16-non-compliant-contract.spec.ts @@ -1,45 +1,45 @@ import { CONFIGS } from "./config"; -import { tzip16, Tzip16Module, BigMapMetadataNotFound } from '@taquito/tzip16'; +import { tzip16, Tzip16Module, BigMapContractMetadataNotFoundError } from '@taquito/tzip16'; CONFIGS().forEach(({ lib, rpc, setup }) => { - const Tezos = lib; - Tezos.addExtension(new Tzip16Module()); + const Tezos = lib; + Tezos.addExtension(new Tzip16Module()); - describe(`Test contract origination of a Tzip16 non-complaint contract through contract api using: ${rpc}`, () => { + describe(`Test contract origination of a Tzip16 non-complaint contract through contract api using: ${rpc}`, () => { - beforeEach(async (done) => { - await setup() - done() - }) - it('Verify contract.originate for a simple contract having no metadata and then try to fetch metadata', async (done) => { + beforeEach(async (done) => { + await setup() + done() + }) + it('Verify contract.originate for a simple contract having no metadata and then try to fetch metadata', async (done) => { - const value = '1234'; - const code = - [{ "prim": "parameter", "args": [{ "prim": "bytes" }] }, - { "prim": "storage", "args": [{ "prim": "bytes" }] }, - { - "prim": "code", - "args": - [[{ "prim": "DUP" }, { "prim": "CAR" }, { "prim": "SWAP" }, - { "prim": "CDR" }, { "prim": "CONCAT" }, - { "prim": "NIL", "args": [{ "prim": "operation" }] }, - { "prim": "PAIR" }]] - }]; + const value = '1234'; + const code = + [{ "prim": "parameter", "args": [{ "prim": "bytes" }] }, + { "prim": "storage", "args": [{ "prim": "bytes" }] }, + { + "prim": "code", + "args": + [[{ "prim": "DUP" }, { "prim": "CAR" }, { "prim": "SWAP" }, + { "prim": "CDR" }, { "prim": "CONCAT" }, + { "prim": "NIL", "args": [{ "prim": "operation" }] }, + { "prim": "PAIR" }]] + }]; - const op = await Tezos.contract.originate({ - code: code, - storage: value - }); - await op.confirmation(); - const contractAddress = (await op.contract()).address; + const op = await Tezos.contract.originate({ + code: code, + storage: value + }); + await op.confirmation(); + const contractAddress = (await op.contract()).address; - const contract = await Tezos.contract.at(contractAddress, tzip16); - try { - await contract.tzip16().getMetadata(); - } catch (ex) { - expect(ex).toBeInstanceOf(BigMapMetadataNotFound); - } - done(); - }); + const contract = await Tezos.contract.at(contractAddress, tzip16); + try { + await contract.tzip16().getMetadata(); + } catch (ex) { + expect(ex).toBeInstanceOf(BigMapContractMetadataNotFoundError); + } + done(); }); + }); }) diff --git a/integration-tests/tzip16-non-compliant-wallet.spec.ts b/integration-tests/tzip16-non-compliant-wallet.spec.ts index db4145c96e..081de9f662 100644 --- a/integration-tests/tzip16-non-compliant-wallet.spec.ts +++ b/integration-tests/tzip16-non-compliant-wallet.spec.ts @@ -1,45 +1,45 @@ import { CONFIGS } from "./config"; -import { tzip16, Tzip16Module, BigMapMetadataNotFound } from '@taquito/tzip16'; +import { tzip16, Tzip16Module, BigMapContractMetadataNotFoundError } from '@taquito/tzip16'; CONFIGS().forEach(({ lib, rpc, setup }) => { - const Tezos = lib; - Tezos.addExtension(new Tzip16Module()); + const Tezos = lib; + Tezos.addExtension(new Tzip16Module()); - describe(`Test contract origination of a Tzip16 non-complaint contract through wallet api using: ${rpc}`, () => { + describe(`Test contract origination of a Tzip16 non-complaint contract through wallet api using: ${rpc}`, () => { - beforeEach(async (done) => { - await setup() - done() - }) - it('Verify contract.originate for a simple contract having no metadata and then try to fetch metadata', async (done) => { + beforeEach(async (done) => { + await setup() + done() + }) + it('Verify contract.originate for a simple contract having no metadata and then try to fetch metadata', async (done) => { - const value = '1234'; - const code = - [{ "prim": "parameter", "args": [{ "prim": "bytes" }] }, - { "prim": "storage", "args": [{ "prim": "bytes" }] }, - { - "prim": "code", - "args": - [[{ "prim": "DUP" }, { "prim": "CAR" }, { "prim": "SWAP" }, - { "prim": "CDR" }, { "prim": "CONCAT" }, - { "prim": "NIL", "args": [{ "prim": "operation" }] }, - { "prim": "PAIR" }]] - }]; + const value = '1234'; + const code = + [{ "prim": "parameter", "args": [{ "prim": "bytes" }] }, + { "prim": "storage", "args": [{ "prim": "bytes" }] }, + { + "prim": "code", + "args": + [[{ "prim": "DUP" }, { "prim": "CAR" }, { "prim": "SWAP" }, + { "prim": "CDR" }, { "prim": "CONCAT" }, + { "prim": "NIL", "args": [{ "prim": "operation" }] }, + { "prim": "PAIR" }]] + }]; - const op = await Tezos.wallet.originate({ - code, - storage: value - }).send(); - await op.confirmation(); - const contractAddress = (await op.contract()).address; + const op = await Tezos.wallet.originate({ + code, + storage: value + }).send(); + await op.confirmation(); + const contractAddress = (await op.contract()).address; - const contract = await Tezos.wallet.at(contractAddress, tzip16); - try { - await contract.tzip16().getMetadata(); - } catch (ex) { - expect(ex).toBeInstanceOf(BigMapMetadataNotFound); - } - done(); - }); + const contract = await Tezos.wallet.at(contractAddress, tzip16); + try { + await contract.tzip16().getMetadata(); + } catch (ex) { + expect(ex).toBeInstanceOf(BigMapContractMetadataNotFoundError); + } + done(); }); + }); }) diff --git a/packages/taquito-tzip12/src/tzip12-contract-abstraction.ts b/packages/taquito-tzip12/src/tzip12-contract-abstraction.ts index e4af21d56a..7238d04b73 100644 --- a/packages/taquito-tzip12/src/tzip12-contract-abstraction.ts +++ b/packages/taquito-tzip12/src/tzip12-contract-abstraction.ts @@ -135,7 +135,7 @@ export class Tzip12ContractAbstraction { ); return metadataFromUri.metadata; } catch (e: any) { - if (e.name === 'InvalidUri') { + if (e.name === 'InvalidUriError') { console.warn( `The URI ${bytes2Char(uri)} is present in the token metadata, but is invalid.` ); diff --git a/packages/taquito-tzip12/test/tzip12-contract-abstraction.spec.ts b/packages/taquito-tzip12/test/tzip12-contract-abstraction.spec.ts index 0f707ebcb0..2639e080eb 100644 --- a/packages/taquito-tzip12/test/tzip12-contract-abstraction.spec.ts +++ b/packages/taquito-tzip12/test/tzip12-contract-abstraction.spec.ts @@ -1,5 +1,5 @@ import { MichelsonMap, ViewSimulationError } from '@taquito/taquito'; -import { char2Bytes, InvalidUri } from '@taquito/tzip16'; +import { char2Bytes, InvalidUriError } from '@taquito/tzip16'; import { Tzip12ContractAbstraction } from '../src/tzip12-contract-abstraction'; import { InvalidTokenMetadata, TokenIdNotFound, TokenMetadataNotFound } from '../src/errors'; @@ -223,11 +223,11 @@ describe('Tzip12 contract abstraction test', () => { it('Test 1 for fetchTokenMetadataFromUri(): Should warn that the URI is invalid and return undefined', async (done) => { const tokenMap = new MichelsonMap(); tokenMap.set('test', char2Bytes('test')); - tokenMap.set('', char2Bytes('invalidURI')); + tokenMap.set('', char2Bytes('InvalidUriError')); tokenMap.set('testtest', char2Bytes('testtest')); mockMetadataProvider.provideMetadata.mockImplementation(() => { - throw new InvalidUri(char2Bytes('invalidURI')); + throw new InvalidUriError(char2Bytes('InvalidUriError')); }); const tokenMetadata = await tzip12Abs['fetchTokenMetadataFromUri']( diff --git a/packages/taquito-tzip16/src/errors.ts b/packages/taquito-tzip16/src/errors.ts index 3355fc053a..c2c1e64426 100644 --- a/packages/taquito-tzip16/src/errors.ts +++ b/packages/taquito-tzip16/src/errors.ts @@ -6,10 +6,10 @@ export { InvalidViewParameterError } from '@taquito/core'; * @category Error * @description Error indicates missing big map metadata (non compliance to the TZIP-16 standard) */ -export class BigMapMetadataNotFound extends TaquitoError { - constructor() { +export class BigMapContractMetadataNotFoundError extends TaquitoError { + constructor(public readonly invalidBigMapId: any) { super(); - this.name = 'BigMapMetadataNotFound'; + this.name = 'BigMapContractMetadataNotFoundError'; this.message = 'Non-compliance with the TZIP-016 standard. No big map named metadata was found in the contract storage.'; } @@ -19,10 +19,10 @@ export class BigMapMetadataNotFound extends TaquitoError { * @category Error * @description Error indicates missing metadata in storage */ -export class ContractMetadataNotFound extends TaquitoError { +export class ContractMetadataNotFoundError extends TaquitoError { constructor(public readonly info: string) { super(); - this.name = 'ContractMetadataNotFound'; + this.name = 'ContractMetadataNotFoundError'; this.message = `No metadata was found in the contract storage. ${info}`; } } @@ -31,10 +31,10 @@ export class ContractMetadataNotFound extends TaquitoError { * @category Error * @description Error indicates missing URI (non compliance to the TZIP-16 standard) */ -export class UriNotFound extends TaquitoError { +export class UriNotFoundError extends TaquitoError { constructor() { super(); - this.name = 'UriNotFound'; + this.name = 'UriNotFoundError'; this.message = 'Non-compliance with the TZIP-016 standard. No URI found in the contract storage.'; } @@ -44,10 +44,10 @@ export class UriNotFound extends TaquitoError { * @category Error * @description Error indicates an invalid URI (non compliance to the TZIP-16 standard) */ -export class InvalidUri extends TaquitoError { +export class InvalidUriError extends TaquitoError { constructor(public readonly uri: string) { super(); - this.name = 'InvalidUri'; + this.name = 'InvalidUriError'; this.message = `Non-compliance with the TZIP-016 standard. The URI is invalid: ${uri}.`; } } @@ -56,10 +56,10 @@ export class InvalidUri extends TaquitoError { * @category Error * @description Error indicates invalid metadata (non compliance to the TZIP-16 standard) */ -export class InvalidContractMetadata extends TaquitoError { +export class InvalidContractMetadataError extends TaquitoError { constructor(public readonly invalidMetadata: string) { super(); - this.name = 'InvalidContractMetadata'; + this.name = 'InvalidContractMetadataError'; this.message = `The metadata found at the pointed ressource are not compliant with tzip16 standard: ${invalidMetadata}.`; } } @@ -68,10 +68,10 @@ export class InvalidContractMetadata extends TaquitoError { * @category Error * @description Error indicates the uri protocol being passed or used is not supported */ -export class ProtocolNotSupported extends ParameterValidationError { +export class ProtocolNotSupportedError extends ParameterValidationError { constructor(public readonly protocol: string) { super(); - this.name = 'ProtocolNotSupported'; + this.name = 'ProtocolNotSupportedError'; this.message = `The protocol found in the URI is not supported: ${protocol}.`; } } @@ -80,10 +80,10 @@ export class ProtocolNotSupported extends ParameterValidationError { * @category Error * @description Error indicates the metadata type is invalid (non compliance to the TZIP-16 standard) */ -export class InvalidContractMetadataType extends TaquitoError { +export class InvalidContractMetadataTypeError extends TaquitoError { constructor() { super(); - this.name = 'InvalidContractMetadataType'; + this.name = 'InvalidContractMetadataTypeError'; this.message = 'Non-compliance with the TZIP-016 standard. The type of metadata should be bytes.'; } @@ -93,10 +93,10 @@ export class InvalidContractMetadataType extends TaquitoError { * @category Error * @description Error indicates metadata provider being unconfigured in the TezosToolkit instance */ -export class UnconfiguredMetadataProviderError extends TezosToolkitConfigError { +export class UnconfiguredContractMetadataProviderError extends TezosToolkitConfigError { constructor() { super(); - this.name = 'UnconfiguredMetadataProviderError'; + this.name = 'UnconfiguredContractMetadataProviderError'; this.message = 'No metadata provider has been configured. The default one can be configured by calling addExtension(new Tzip16Module()) on your TezosToolkit instance.'; } @@ -106,10 +106,10 @@ export class UnconfiguredMetadataProviderError extends TezosToolkitConfigError { * @category Error * @description Error indicates a forbidden instruction being found inside the View code */ -export class ForbiddenInstructionInViewCode extends TaquitoError { +export class ForbiddenInstructionInViewCodeError extends TaquitoError { constructor(public readonly instruction: string) { super(); - this.name = 'ForbiddenInstructionInViewCode'; + this.name = 'ForbiddenInstructionInViewCodeError'; this.message = `Error found in the code of the view. It contains a forbidden instruction: ${instruction}.`; } } diff --git a/packages/taquito-tzip16/src/handlers/tezos-storage-handler.ts b/packages/taquito-tzip16/src/handlers/tezos-storage-handler.ts index 5bed7af8b6..fcdab8b23d 100644 --- a/packages/taquito-tzip16/src/handlers/tezos-storage-handler.ts +++ b/packages/taquito-tzip16/src/handlers/tezos-storage-handler.ts @@ -3,10 +3,10 @@ import { Context, ContractAbstraction, ContractProvider, Wallet } from '@taquito import { Handler, Tzip16Uri } from '../metadata-provider'; import { bytes2Char } from '@taquito/utils'; import { - InvalidContractMetadataType, - BigMapMetadataNotFound, - InvalidUri, - ContractMetadataNotFound, + InvalidContractMetadataTypeError, + BigMapContractMetadataNotFoundError, + InvalidUriError, + ContractMetadataNotFoundError, } from '../errors'; const typeOfValueToFind = { @@ -27,7 +27,7 @@ export class TezosStorageHandler implements Handler { ) { const parsedTezosStorageUri = this.parseTezosStorageUri(location); if (!parsedTezosStorageUri) { - throw new InvalidUri(`tezos-storage:${location}`); + throw new InvalidUriError(`tezos-storage:${location}`); } const script = await context.readProvider.getScript( parsedTezosStorageUri.contractAddress || contractAbstraction.address, @@ -39,7 +39,7 @@ export class TezosStorageHandler implements Handler { ); if (!bigMapId || !bigMapId.int) { - throw new BigMapMetadataNotFound(); + throw new BigMapContractMetadataNotFoundError(bigMapId); } const bytes = await context.contract.getBigMapKeyByID( bigMapId.int.toString(), @@ -48,7 +48,7 @@ export class TezosStorageHandler implements Handler { ); if (!bytes) { - throw new ContractMetadataNotFound( + throw new ContractMetadataNotFoundError( `No '${parsedTezosStorageUri.path}' key found in the big map %metadata of the contract ${ parsedTezosStorageUri.contractAddress || contractAbstraction.address }` @@ -56,7 +56,7 @@ export class TezosStorageHandler implements Handler { } if (!/^[0-9a-fA-F]*$/.test(bytes)) { - throw new InvalidContractMetadataType(); + throw new InvalidContractMetadataTypeError(); } return bytes2Char(bytes); } diff --git a/packages/taquito-tzip16/src/metadata-provider.ts b/packages/taquito-tzip16/src/metadata-provider.ts index ff1d914a8b..5381805b1a 100644 --- a/packages/taquito-tzip16/src/metadata-provider.ts +++ b/packages/taquito-tzip16/src/metadata-provider.ts @@ -1,7 +1,7 @@ import { ContractAbstraction, ContractProvider, Wallet, Context } from '@taquito/taquito'; import { MetadataInterface } from './metadata-interface'; import { MetadataContext } from './tzip16-contract-abstraction'; -import { InvalidContractMetadata, InvalidUri, ProtocolNotSupported } from './errors'; +import { InvalidContractMetadataError, InvalidUriError, ProtocolNotSupportedError } from './errors'; import { calculateSHA256Hash } from './tzip16-utils'; export interface MetadataProviderInterface { @@ -54,12 +54,12 @@ export class MetadataProvider implements MetadataProviderInterface { ): Promise { const uriInfo = this.extractProtocolInfo(uri); if (!uriInfo || !uriInfo.location) { - throw new InvalidUri(uri); + throw new InvalidUriError(uri); } const handler = this.handlers.get(uriInfo.protocol); if (!handler) { - throw new ProtocolNotSupported(uriInfo.protocol); + throw new ProtocolNotSupportedError(uriInfo.protocol); } const metadata = await handler.getMetadata(contractAbstraction, uriInfo, context); @@ -68,7 +68,7 @@ export class MetadataProvider implements MetadataProviderInterface { try { metadataJSON = JSON.parse(metadata); } catch (ex) { - throw new InvalidContractMetadata(metadata); + throw new InvalidContractMetadataError(metadata); } return { diff --git a/packages/taquito-tzip16/src/tzip16-contract-abstraction.ts b/packages/taquito-tzip16/src/tzip16-contract-abstraction.ts index 4e2fe05a6f..1400b2dc04 100644 --- a/packages/taquito-tzip16/src/tzip16-contract-abstraction.ts +++ b/packages/taquito-tzip16/src/tzip16-contract-abstraction.ts @@ -8,7 +8,11 @@ import { } from '@taquito/taquito'; import { bytes2Char } from '@taquito/utils'; import { MetadataEnvelope, MetadataProviderInterface } from './metadata-provider'; -import { BigMapMetadataNotFound, UnconfiguredMetadataProviderError, UriNotFound } from './errors'; +import { + BigMapContractMetadataNotFoundError, + UnconfiguredContractMetadataProviderError, + UriNotFoundError, +} from './errors'; import BigNumber from 'bignumber.js'; import { Schema } from '@taquito/michelson-encoder'; import { ViewFactory } from './viewKind/viewFactory'; @@ -44,7 +48,7 @@ export class Tzip16ContractAbstraction { ); if (!metadataBigMapId || !metadataBigMapId.int) { - throw new BigMapMetadataNotFound(); + throw new BigMapContractMetadataNotFoundError(metadataBigMapId); } return new BigMapAbstraction( @@ -58,7 +62,7 @@ export class Tzip16ContractAbstraction { const metadataBigMap = await this.findMetadataBigMap(); const uri = await metadataBigMap.get(''); if (!uri) { - throw new UriNotFound(); + throw new UriNotFoundError(); } return uri; } @@ -68,7 +72,7 @@ export class Tzip16ContractAbstraction { */ async getMetadata() { if (!this._metadataProvider) { - throw new UnconfiguredMetadataProviderError(); + throw new UnconfiguredContractMetadataProviderError(); } if (!this._metadataEnvelope) { const uri = await this.getUriOrFail(); diff --git a/packages/taquito-tzip16/src/viewKind/michelson-storage-view.ts b/packages/taquito-tzip16/src/viewKind/michelson-storage-view.ts index 778bcc7cdc..b01373da94 100644 --- a/packages/taquito-tzip16/src/viewKind/michelson-storage-view.ts +++ b/packages/taquito-tzip16/src/viewKind/michelson-storage-view.ts @@ -10,7 +10,7 @@ import { Wallet, ViewSimulationError, } from '@taquito/taquito'; -import { ForbiddenInstructionInViewCode, NoParameterExpectedError } from '../errors'; +import { ForbiddenInstructionInViewCodeError, NoParameterExpectedError } from '../errors'; import { validateAndExtractFailwith, TzReadProvider } from '@taquito/taquito'; import { View } from './interface'; import { InvalidViewParameterError } from '@taquito/core'; @@ -31,7 +31,7 @@ export class MichelsonStorageView implements View { * 'AMOUNT', 'CREATE_CONTRACT', 'SENDER', 'SET_DELEGATE', 'SOURCE', and 'TRANSFER_TOKENS' * The method throw an error if an illegal instruction is found */ - private findForbiddenInstructionInViewCode(code: MichelsonV1ExpressionExtended[]) { + private findForbiddenInstructionInViewCodeError(code: MichelsonV1ExpressionExtended[]) { const illegalInstructions = [ 'AMOUNT', 'CREATE_CONTRACT', @@ -44,10 +44,10 @@ export class MichelsonStorageView implements View { for (const forbiddenInstruction of illegalInstructions) { for (const instruction of code) { if (instruction.prim === forbiddenInstruction) { - throw new ForbiddenInstructionInViewCode(forbiddenInstruction); + throw new ForbiddenInstructionInViewCodeError(forbiddenInstruction); } if (instruction.args && instruction.args.length !== 0) { - this.findForbiddenInstructionInViewCode(instruction.args as any); + this.findForbiddenInstructionInViewCodeError(instruction.args as any); } } } @@ -63,7 +63,7 @@ export class MichelsonStorageView implements View { const index = code.indexOf(instruction); const nextInstruction = code[index + 1] ? code[index + 1].prim : undefined; if (nextInstruction !== 'ADDRESS') { - throw new ForbiddenInstructionInViewCode( + throw new ForbiddenInstructionInViewCodeError( 'the instruction SELF should only be used before ADDRESS' ); } @@ -138,7 +138,7 @@ export class MichelsonStorageView implements View { async executeView(...args: any[]) { // validate view code against tzip-16 specifications - this.findForbiddenInstructionInViewCode(this.code); + this.findForbiddenInstructionInViewCodeError(this.code); this.illegalUseOfSelfInstruction(this.code); const { arg, viewParameterType } = this.formatArgsAndParameter(args); diff --git a/packages/taquito-tzip16/test/handlers/tezos-storage-handler.spec.ts b/packages/taquito-tzip16/test/handlers/tezos-storage-handler.spec.ts index b32566e8dc..d053cca966 100644 --- a/packages/taquito-tzip16/test/handlers/tezos-storage-handler.spec.ts +++ b/packages/taquito-tzip16/test/handlers/tezos-storage-handler.spec.ts @@ -1,9 +1,9 @@ import { TezosStorageHandler } from '../../src/handlers/tezos-storage-handler'; import { - InvalidContractMetadataType, - InvalidUri, - BigMapMetadataNotFound, - ContractMetadataNotFound, + InvalidContractMetadataTypeError, + InvalidUriError, + BigMapContractMetadataNotFoundError, + ContractMetadataNotFoundError, } from '../../src/errors'; describe('Parse Tezos storage URI test', () => { @@ -124,7 +124,7 @@ describe('Tzip16 tezos storage handler test', () => { done(); }); - it('Should fail with InvalidUri when the URI is invalid', async (done) => { + it('Should fail with InvalidUriError when the URI is invalid', async (done) => { const tzip16Uri = { sha256hash: undefined, protocol: 'tezos-storage', @@ -137,12 +137,12 @@ describe('Tzip16 tezos storage handler test', () => { mockContext as any ); } catch (ex) { - expect(ex).toBeInstanceOf(InvalidUri); + expect(ex).toBeInstanceOf(InvalidUriError); } done(); }); - it('Should fail with BigMapMetadataNotFound when there is no big map %metadata in the storage', async (done) => { + it('Should fail with BigMapContractMetadataNotFoundError when there is no big map %metadata in the storage', async (done) => { mockReadProvider.getScript.mockResolvedValue({ code: [{ prim: 'storage', args: [{ prim: 'pair', args: [{}, {}] }] }], storage: { prim: 'Pair', args: [] }, @@ -156,12 +156,12 @@ describe('Tzip16 tezos storage handler test', () => { try { await tezosStorageHandler.getMetadata(mockContractAbstraction, tzip16Uri, mockContext as any); } catch (ex) { - expect(ex).toBeInstanceOf(BigMapMetadataNotFound); + expect(ex).toBeInstanceOf(BigMapContractMetadataNotFoundError); } done(); }); - it('Should fail with ContractMetadataNotFound when the path extracted from the URI is not a key of the big map %metadata', async (done) => { + it('Should fail with ContractMetadataNotFoundError when the path extracted from the URI is not a key of the big map %metadata', async (done) => { mockContractProvider.getBigMapKeyByID.mockResolvedValue(undefined); const tzip16Uri = { @@ -176,12 +176,12 @@ describe('Tzip16 tezos storage handler test', () => { mockContext as any ); } catch (ex) { - expect(ex).toBeInstanceOf(ContractMetadataNotFound); + expect(ex).toBeInstanceOf(ContractMetadataNotFoundError); } done(); }); - it('Should fail with InvalidContractMetadataType when metadata type is not bytes', async (done) => { + it('Should fail with InvalidContractMetadataTypeError when metadata type is not bytes', async (done) => { mockContractProvider.getBigMapKeyByID.mockResolvedValue('NOT-BYTES'); const tzip16Uri = { @@ -196,7 +196,7 @@ describe('Tzip16 tezos storage handler test', () => { mockContext as any ); } catch (ex) { - expect(ex).toBeInstanceOf(InvalidContractMetadataType); + expect(ex).toBeInstanceOf(InvalidContractMetadataTypeError); } done(); }); diff --git a/packages/taquito-tzip16/test/metadata-provider.spec.ts b/packages/taquito-tzip16/test/metadata-provider.spec.ts index 8295feeb36..252d4fd3d5 100644 --- a/packages/taquito-tzip16/test/metadata-provider.spec.ts +++ b/packages/taquito-tzip16/test/metadata-provider.spec.ts @@ -1,5 +1,5 @@ import { Handler, MetadataProvider } from '../src/metadata-provider'; -import { InvalidContractMetadata, InvalidUri } from '../src/errors'; +import { InvalidContractMetadataError, InvalidUriError } from '../src/errors'; describe('Metadata provider test', () => { let metadataProvider: MetadataProvider; @@ -134,7 +134,7 @@ describe('Metadata provider test', () => { done(); }); - it('Should fail with InvalidUri', async (done) => { + it('Should fail with InvalidUriError', async (done) => { try { await metadataProvider.provideMetadata( mockContractAbstraction, @@ -142,19 +142,19 @@ describe('Metadata provider test', () => { mockContext ); } catch (ex) { - expect(ex).toBeInstanceOf(InvalidUri); + expect(ex).toBeInstanceOf(InvalidUriError); } done(); }); - it('Should fail with InvalidContractMetadata when metadata is not a JSON object', async (done) => { + it('Should fail with InvalidContractMetadataError when metadata is not a JSON object', async (done) => { mockHttpHandler.getMetadata.mockResolvedValue( `"description": "Invalid metadata, not in JSON format"` ); try { await metadataProvider.provideMetadata(mockContractAbstraction, 'https://test', mockContext); } catch (ex) { - expect(ex).toBeInstanceOf(InvalidContractMetadata); + expect(ex).toBeInstanceOf(InvalidContractMetadataError); } done(); }); diff --git a/packages/taquito-tzip16/test/tzip16-contract-abstraction.spec.ts b/packages/taquito-tzip16/test/tzip16-contract-abstraction.spec.ts index acb93b88d5..848f3b2211 100644 --- a/packages/taquito-tzip16/test/tzip16-contract-abstraction.spec.ts +++ b/packages/taquito-tzip16/test/tzip16-contract-abstraction.spec.ts @@ -1,5 +1,5 @@ import { Tzip16ContractAbstraction } from '../src/tzip16-contract-abstraction'; -import { BigMapMetadataNotFound, UriNotFound } from '../src/errors'; +import { BigMapContractMetadataNotFoundError, UriNotFoundError } from '../src/errors'; describe('Tzip16 contract abstraction test', () => { let mockMetadataProvider: { @@ -102,7 +102,7 @@ describe('Tzip16 contract abstraction test', () => { done(); }); - it('Should fail with BigMapMetadataNotFound', async (done) => { + it('Should fail with BigMapContractMetadataNotFoundError', async (done) => { mockSchema.FindFirstInTopLevelPair.mockReturnValue(undefined); const tzip16Abs = new Tzip16ContractAbstraction(mockContractAbstraction as any, mockContext); @@ -110,12 +110,12 @@ describe('Tzip16 contract abstraction test', () => { try { await tzip16Abs.getMetadata(); } catch (e) { - expect(e).toBeInstanceOf(BigMapMetadataNotFound); + expect(e).toBeInstanceOf(BigMapContractMetadataNotFoundError); } done(); }); - it('Should fail with UriNotFound', async (done) => { + it('Should fail with UriNotFoundError', async (done) => { mockSchema.FindFirstInTopLevelPair.mockReturnValue({ int: '20350' }); mockRpcContractProvider.getBigMapKeyByID.mockResolvedValue(undefined); @@ -124,7 +124,7 @@ describe('Tzip16 contract abstraction test', () => { try { await tzip16Abs.getMetadata(); } catch (e) { - expect(e).toBeInstanceOf(UriNotFound); + expect(e).toBeInstanceOf(UriNotFoundError); } done(); }); diff --git a/packages/taquito-tzip16/test/viewKind/michelson-storage-view.spec.ts b/packages/taquito-tzip16/test/viewKind/michelson-storage-view.spec.ts index 43cb647c46..6d65adf6f1 100644 --- a/packages/taquito-tzip16/test/viewKind/michelson-storage-view.spec.ts +++ b/packages/taquito-tzip16/test/viewKind/michelson-storage-view.spec.ts @@ -1,5 +1,5 @@ import { RpcReadAdapter } from '@taquito/taquito'; -import { ForbiddenInstructionInViewCode, NoParameterExpectedError } from '../../src/errors'; +import { ForbiddenInstructionInViewCodeError, NoParameterExpectedError } from '../../src/errors'; import { MichelsonStorageView } from '../../src/viewKind/michelson-storage-view'; describe('MichelsonStorageView test', () => { @@ -97,7 +97,7 @@ describe('MichelsonStorageView test', () => { try { await michelsonStorageView.executeView(); } catch (e) { - expect(e).toBeInstanceOf(ForbiddenInstructionInViewCode); + expect(e).toBeInstanceOf(ForbiddenInstructionInViewCodeError); expect(e.message).toEqual( 'Error found in the code of the view. It contains a forbidden instruction: AMOUNT.' ); @@ -105,7 +105,7 @@ describe('MichelsonStorageView test', () => { done(); }); - it('Should throw ForbiddenInstructionInViewCode when code of the view contains the instruction CREATE_CONTRACT', async (done) => { + it('Should throw ForbiddenInstructionInViewCodeError when code of the view contains the instruction CREATE_CONTRACT', async (done) => { const viewCode = [ { prim: 'CAR', args: [], annots: [] }, { prim: 'CREATE_CONTRACT', args: [], annots: [] }, @@ -124,7 +124,7 @@ describe('MichelsonStorageView test', () => { try { await michelsonStorageView.executeView(); } catch (e) { - expect(e).toBeInstanceOf(ForbiddenInstructionInViewCode); + expect(e).toBeInstanceOf(ForbiddenInstructionInViewCodeError); expect(e.message).toEqual( 'Error found in the code of the view. It contains a forbidden instruction: CREATE_CONTRACT.' ); @@ -132,7 +132,7 @@ describe('MichelsonStorageView test', () => { done(); }); - it('Should throw ForbiddenInstructionInViewCode when code of the view contains the instruction SENDER', async (done) => { + it('Should throw ForbiddenInstructionInViewCodeError when code of the view contains the instruction SENDER', async (done) => { const viewCode = [ { prim: 'CAR', args: [], annots: [] }, { prim: 'SENDER', args: [], annots: [] }, @@ -150,7 +150,7 @@ describe('MichelsonStorageView test', () => { try { await michelsonStorageView.executeView(); } catch (e) { - expect(e).toBeInstanceOf(ForbiddenInstructionInViewCode); + expect(e).toBeInstanceOf(ForbiddenInstructionInViewCodeError); expect(e.message).toEqual( 'Error found in the code of the view. It contains a forbidden instruction: SENDER.' ); @@ -158,7 +158,7 @@ describe('MichelsonStorageView test', () => { done(); }); - it('Should throw ForbiddenInstructionInViewCode when code of the view contains the instruction SET_DELEGATE', async (done) => { + it('Should throw ForbiddenInstructionInViewCodeError when code of the view contains the instruction SET_DELEGATE', async (done) => { const viewCode = [{ prim: 'SET_DELEGATE', args: [], annots: [] }]; // code const michelsonStorageView = new MichelsonStorageView( 'test', @@ -172,7 +172,7 @@ describe('MichelsonStorageView test', () => { try { await michelsonStorageView.executeView(); } catch (e) { - expect(e).toBeInstanceOf(ForbiddenInstructionInViewCode); + expect(e).toBeInstanceOf(ForbiddenInstructionInViewCodeError); expect(e.message).toEqual( 'Error found in the code of the view. It contains a forbidden instruction: SET_DELEGATE.' ); @@ -180,7 +180,7 @@ describe('MichelsonStorageView test', () => { done(); }); - it('Should throw ForbiddenInstructionInViewCode when code of the view contains the instruction SOURCE', async (done) => { + it('Should throw ForbiddenInstructionInViewCodeError when code of the view contains the instruction SOURCE', async (done) => { const viewCode = [{ prim: 'SOURCE', args: [], annots: [] }]; // code const michelsonStorageView = new MichelsonStorageView( 'test', @@ -194,7 +194,7 @@ describe('MichelsonStorageView test', () => { try { await michelsonStorageView.executeView(); } catch (e) { - expect(e).toBeInstanceOf(ForbiddenInstructionInViewCode); + expect(e).toBeInstanceOf(ForbiddenInstructionInViewCodeError); expect(e.message).toEqual( 'Error found in the code of the view. It contains a forbidden instruction: SOURCE.' ); @@ -202,7 +202,7 @@ describe('MichelsonStorageView test', () => { done(); }); - it('Should throw ForbiddenInstructionInViewCode when code of the view contains the instruction TRANSFER_TOKENS', async (done) => { + it('Should throw ForbiddenInstructionInViewCodeError when code of the view contains the instruction TRANSFER_TOKENS', async (done) => { const viewCode = [{ prim: 'TRANSFER_TOKENS', args: [], annots: [] }]; // code const michelsonStorageView = new MichelsonStorageView( 'test', @@ -216,7 +216,7 @@ describe('MichelsonStorageView test', () => { try { await michelsonStorageView.executeView(); } catch (e) { - expect(e).toBeInstanceOf(ForbiddenInstructionInViewCode); + expect(e).toBeInstanceOf(ForbiddenInstructionInViewCodeError); expect(e.message).toEqual( 'Error found in the code of the view. It contains a forbidden instruction: TRANSFER_TOKENS.' ); @@ -224,7 +224,7 @@ describe('MichelsonStorageView test', () => { done(); }); - it('Should throw ForbiddenInstructionInViewCode when code of the view contains a nested forbidden instruction', async (done) => { + it('Should throw ForbiddenInstructionInViewCodeError when code of the view contains a nested forbidden instruction', async (done) => { const viewCode = [ { prim: 'test', args: [{ prim: 'test2', args: [{ prim: 'TRANSFER_TOKENS' }] }], annots: [] }, ]; // code @@ -240,7 +240,7 @@ describe('MichelsonStorageView test', () => { try { await michelsonStorageView.executeView(); } catch (e) { - expect(e).toBeInstanceOf(ForbiddenInstructionInViewCode); + expect(e).toBeInstanceOf(ForbiddenInstructionInViewCodeError); expect(e.message).toEqual( 'Error found in the code of the view. It contains a forbidden instruction: TRANSFER_TOKENS.' ); @@ -248,7 +248,7 @@ describe('MichelsonStorageView test', () => { done(); }); - it('Should throw ForbiddenInstructionInViewCode when code of the view contains the instruction SELF which is not followed by an instruction ADDRESS', async (done) => { + it('Should throw ForbiddenInstructionInViewCodeError when code of the view contains the instruction SELF which is not followed by an instruction ADDRESS', async (done) => { const viewCode = [ { prim: 'SELF', args: [], annots: [] }, { prim: 'CONTRACT', args: [], annots: [] }, @@ -266,7 +266,7 @@ describe('MichelsonStorageView test', () => { try { await michelsonStorageView.executeView(); } catch (e) { - expect(e).toBeInstanceOf(ForbiddenInstructionInViewCode); + expect(e).toBeInstanceOf(ForbiddenInstructionInViewCodeError); expect(e.message).toEqual( 'Error found in the code of the view. It contains a forbidden instruction: the instruction SELF should only be used before ADDRESS.' ); @@ -274,7 +274,7 @@ describe('MichelsonStorageView test', () => { done(); }); - it('Should throw ForbiddenInstructionInViewCode when code of the view contains the instruction SELF which is not followed by an instruction ADDRESS', async (done) => { + it('Should throw ForbiddenInstructionInViewCodeError when code of the view contains the instruction SELF which is not followed by an instruction ADDRESS', async (done) => { const viewCode = [{ prim: 'test', args: [{ prim: 'SELF' }, { prim: 'test2' }], annots: [] }]; // code const michelsonStorageView = new MichelsonStorageView( @@ -289,7 +289,7 @@ describe('MichelsonStorageView test', () => { try { await michelsonStorageView.executeView(); } catch (e) { - expect(e).toBeInstanceOf(ForbiddenInstructionInViewCode); + expect(e).toBeInstanceOf(ForbiddenInstructionInViewCodeError); expect(e.message).toEqual( 'Error found in the code of the view. It contains a forbidden instruction: the instruction SELF should only be used before ADDRESS.' ); diff --git a/packages/taquito/src/contract/prepare.ts b/packages/taquito/src/contract/prepare.ts index 43303eb61b..96955e3bb7 100644 --- a/packages/taquito/src/contract/prepare.ts +++ b/packages/taquito/src/contract/prepare.ts @@ -97,7 +97,7 @@ export const createOriginationOperation = async ({ }; if (isNaN(Number(balance))) { - throw new InvalidBalanceError(`Invalid Balance "${balance}", can't convert to a number`); + throw new InvalidBalanceError(`Invalid Balance "${balance}", cannot be converted to a number`); } const operation: RPCOriginationOperation = {