Skip to content

Commit

Permalink
fix: address comment with TicketDeprecatedEncodeError and fix unit tests
Browse files Browse the repository at this point in the history
fix #2073
  • Loading branch information
hui-an-yang committed Nov 4, 2022
1 parent 0d6dd3e commit 4158036
Show file tree
Hide file tree
Showing 3 changed files with 583 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/taquito-michelson-encoder/src/schema/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { createToken } from '../tokens/createToken';
import { OrToken } from '../tokens/or';
import { PairToken } from '../tokens/pair';
import { TicketToken } from '../tokens/ticket';
import { TicketDeprecatedToken } from '../tokens/ticket-deprecated';
import {
BigMapKeyType,
Semantic,
Expand Down Expand Up @@ -161,6 +162,9 @@ export class Schema {
if (this.root instanceof TicketToken && val.ticketer && val.value && val.amount) {
return true;
}
if (this.root instanceof TicketDeprecatedToken && val.ticketer && val.value && val.amount) {
return true;
}
try {
this.root.EncodeObject(val);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { Token, TokenFactory, Semantic, SemanticEncoding } from './token';
* @category Error
* @description Error that indicates a failure when encoding and sending a ticket to the blockchain
*/
export class EncodeTicketError extends Error {
name = 'TicketEncodeError';
export class EncodeTicketDeprecatedError extends Error {
name = 'TicketDeprecatedEncodeError';

constructor() {
super('Tickets cannot be sent to the blockchain; they are created on-chain');
super('Ticket_deprecated cannot be sent to the blockchain; they are created on-chain');
}
}

Expand All @@ -34,14 +34,14 @@ export class TicketDeprecatedToken extends Token {
}

public Encode(_args: any[]): any {
throw new EncodeTicketError();
throw new EncodeTicketDeprecatedError();
}

public EncodeObject(args: any, semantic?: SemanticEncoding): any {
if (semantic && semantic[TicketDeprecatedToken.prim]) {
return semantic[TicketDeprecatedToken.prim](args, this.val);
}
throw new EncodeTicketError();
throw new EncodeTicketDeprecatedError();
}

public Execute(val: any, semantics?: Semantic) {
Expand Down
Loading

0 comments on commit 4158036

Please sign in to comment.