Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1994 taquito local forging error improvement #2486

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions packages/taquito-local-forging/src/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {
DecodeBallotValueError,
UnsupportedPvmKindError,
DecodePvmKindError,
InvalidSmartRollupContractAddressError,
InvalidSmartRollupCommitmentHashError,
InvalidSmartRollupAddressError,
} from './error';
} from './errors';
import BigNumber from 'bignumber.js';
import { entrypointMapping, entrypointMappingReverse, ENTRYPOINT_MAX_LENGTH } from './constants';
import {
Expand Down Expand Up @@ -252,7 +252,10 @@ export const addressEncoder = (val: string): string => {

export const smartRollupAddressEncoder = (val: string): string => {
if (val.substring(0, 3) !== Prefix.SR1) {
throw new InvalidSmartRollupAddressError(val);
throw new InvalidSmartRollupAddressError(
val,
invalidErrorDetail(ValidationResult.NO_PREFIX_MATCHED) + ` expecting prefix '${Prefix.SR1}'.`
);
}
return prefixEncoder(Prefix.SR1)(val);
};
Expand Down Expand Up @@ -286,12 +289,15 @@ export const publicKeyDecoder = (val: Uint8ArrayConsumer) => {
}
};

export const smartRollupContractAddressEncoder = (val: string): string => {
export const smartRollupCommitmentHashEncoder = (val: string): string => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, thanks for fixing this

const prefix = val.substring(0, 4);
if (prefix === Prefix.SRC1) {
return prefixEncoder(Prefix.SRC1)(val);
}
throw new InvalidSmartRollupContractAddressError(val);
throw new InvalidSmartRollupCommitmentHashError(
val,
invalidErrorDetail(ValidationResult.NO_PREFIX_MATCHED) + ` expecting prefix '${Prefix.SRC1}'`
);
};

export const addressDecoder = (val: Uint8ArrayConsumer) => {
Expand All @@ -312,7 +318,7 @@ export const addressDecoder = (val: Uint8ArrayConsumer) => {
export const smartRollupAddressDecoder = (val: Uint8ArrayConsumer): string => {
const address = prefixDecoder(Prefix.SR1)(val);
if (address.substring(0, 3) !== Prefix.SR1) {
throw new InvalidAddressError(
throw new InvalidSmartRollupAddressError(
address,
invalidErrorDetail(ValidationResult.NO_PREFIX_MATCHED) + ` expecting prefix '${Prefix.SR1}'.`
);
Expand All @@ -336,7 +342,10 @@ export const smartContractAddressDecoder = (val: Uint8ArrayConsumer) => {
export const smartRollupCommitmentHashDecoder = (val: Uint8ArrayConsumer) => {
const address = prefixDecoder(Prefix.SRC1)(val);
if (address.substring(0, 4) !== Prefix.SRC1) {
throw new InvalidSmartRollupContractAddressError(address);
throw new InvalidSmartRollupCommitmentHashError(
address,
invalidErrorDetail(ValidationResult.NO_PREFIX_MATCHED) + ` expecting prefix '${Prefix.SRC1}'`
);
}
return address;
};
Expand Down
7 changes: 4 additions & 3 deletions packages/taquito-local-forging/src/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
pvmKindEncoder,
smartContractAddressEncoder,
smartRollupAddressEncoder,
smartRollupContractAddressEncoder,
smartRollupCommitmentHashEncoder,
txRollupBatchContentEncoder,
txRollupIdEncoder,
txRollupOriginationParamEncoder,
Expand Down Expand Up @@ -75,7 +75,7 @@ export const encoders: { [key: string]: Encoder<any> } = {
[CODEC.ADDRESS]: addressEncoder,
[CODEC.SMART_ROLLUP_ADDRESS]: smartRollupAddressEncoder,
[CODEC.SMART_CONTRACT_ADDRESS]: smartContractAddressEncoder,
[CODEC.SMART_ROLLUP_COMMITMENT_HASH]: smartRollupContractAddressEncoder,
[CODEC.SMART_ROLLUP_COMMITMENT_HASH]: smartRollupCommitmentHashEncoder,
[CODEC.VALUE]: valueParameterEncoder,
[CODEC.INT16]: int16Encoder,
[CODEC.BLOCK_PAYLOAD_HASH]: blockPayloadHashEncoder,
Expand Down Expand Up @@ -121,4 +121,5 @@ encoders[CODEC.OP_SMART_ROLLUP_ADD_MESSAGES] = (val: any) =>
encoders[CODEC.OP_SMART_ROLLUP_EXECUTE_OUTBOX_MESSAGE] = (val: any) =>
schemaEncoder(encoders)(SmartRollupExecuteOutboxMessageSchema)(val);
encoders[CODEC.MANAGER] = schemaEncoder(encoders)(ManagerOperationSchema);
encoders[CODEC.OP_SET_DEPOSITS_LIMIT] = (val) => schemaEncoder(encoders)(SetDepositsLimitSchema)(val);
encoders[CODEC.OP_SET_DEPOSITS_LIMIT] = (val) =>
schemaEncoder(encoders)(SetDepositsLimitSchema)(val);
134 changes: 0 additions & 134 deletions packages/taquito-local-forging/src/error.ts

This file was deleted.

147 changes: 147 additions & 0 deletions packages/taquito-local-forging/src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import { ParameterValidationError } from '@taquito/core';
import { OperationContents } from '@taquito/rpc';
import { ENTRYPOINT_MAX_LENGTH } from './constants';

/**
* @category Error
* @description Error indicates an invalid operation content being passed or used
*/ export class InvalidOperationSchemaError extends ParameterValidationError {
constructor(public operation: OperationContents, errorDetail?: string) {
super();
this.name = 'InvalidOperationSchemaError';
this.message = `Invalid operation content recevied`;
errorDetail ? (this.message += ` ${errorDetail}.`) : '';
}
}

/**
* @category Error
* @description Error indicates an entrypoint name exceeding maximum length
*/
export class OversizedEntryPointError extends ParameterValidationError {
constructor(public entrypoint: string) {
super();
this.name = 'OversizedEntryPointError';
this.message = `Invalid entrypoint length "${entrypoint.length}", maximum length is "${ENTRYPOINT_MAX_LENGTH}".`;
}
}

/**
* @category Error
* @description Error indicates an invalid ballot value being used
*/
export class InvalidBallotValueError extends ParameterValidationError {
constructor(public ballotValue: string) {
super();
this.name = 'InvalidBallotValueError';
this.message = `Invalid ballot value "${ballotValue}" expecting one of the following: "yay", "nay", "pass".`;
}
}

/**
* @category Error
* @description Error indicates a failure when trying to decode ballot value
*/
export class DecodeBallotValueError extends ParameterValidationError {
constructor(public ballotValue: string) {
super();
this.name = 'DecodeBallotValueError';
this.message = `Invalid ballot value "${ballotValue}", cannot be decoded.`;
}
}

/**
* @category Error
* @description Error indicates unexpected Michelson Value being passed or used
*/
export class UnexpectedMichelsonValueError extends ParameterValidationError {
constructor(public value: string) {
super();
this.name = 'UnexpectedMichelsonValueError';
this.message = `Invalid Michelson value "${value}", unalbe to encode.`;
}
}

/**
* @category Error
* @description Error indicates a failure when trying to decode an operation
*/
export class OperationDecodingError extends ParameterValidationError {
constructor(public message: string) {
super();
this.name = 'OperationDecodingError';
}
}

/**
* @category Error
* @description Error indicates a failure when trying to encode an operation
*/
export class OperationEncodingError extends ParameterValidationError {
constructor(public message: string) {
super();
this.name = 'OperationEncodingError';
}
}

/**
* @category Error
* @description Error indicates an unsupported operation being passed or used
*/
export class UnsupportedOperationError extends ParameterValidationError {
constructor(public op: string) {
super();
this.name = 'UnsupportedOperationError';
this.message = `Unsupported operation "${op}", can submit an issue on our github for feature request.`;
}
}

/**
* @cateogry Error
* @description Error indicates an unsupported pvm being passed or used
*/
export class UnsupportedPvmKindError extends ParameterValidationError {
constructor(public pvm: string) {
super();
this.name = 'UnsupportedPvmKindError';
this.message = `Invalid Pvm kind "${pvm}" expecting either "arith" or "wasm_2_0_0".`;
}
}

/**
* @category Error
* @description Error indicates an unsupported pvm to decode
*/
export class DecodePvmKindError extends ParameterValidationError {
constructor(public pvm: string) {
super();
this.name = 'DecodePvmKindError';
this.message = `Invalid Pvm kind "${pvm}", cannot be decoded.`;
}
}

/**
* @category Error
* @description Error indicates an invalid Smart Rollup Address (sr1)
*/
export class InvalidSmartRollupAddressError extends ParameterValidationError {
constructor(public address: string, errorDetail?: string) {
super();
this.name = 'InvalidSmartRollupAddress';
this.message = `Invalid smart rollup address "${address}"`;
errorDetail ? (this.message += ` ${errorDetail}.`) : '';
}
}

/**
* @category Error
* @description Error indicates an invalid Smart Rollup commitment hash (src1)
*/
export class InvalidSmartRollupCommitmentHashError extends ParameterValidationError {
constructor(public hash: string, errorDetail?: string) {
super();
this.name = 'InvalidSmartRollupCommitmentHashError'
this.message = `Invalid smart rollup commitment hash "${hash}"`
errorDetail ? (this.message += ` ${errorDetail}.`) : '';
}
}
2 changes: 1 addition & 1 deletion packages/taquito-local-forging/src/michelson/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Uint8ArrayConsumer } from '../uint8array-consumer';
import { Encoder } from '../taquito-local-forging';
import { opMappingReverse, opMapping } from '../constants';
import { pad } from '../utils';
import { UnexpectedMichelsonValueError } from '../error';
import { UnexpectedMichelsonValueError } from '../errors';
import { InvalidHexStringError } from '@taquito/core';

export type PrimValue = { prim: string; args?: MichelsonValue[]; annots?: string[] };
Expand Down
Loading