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

fix: fixed idx calculation in pairs with mix of annotated and unanntated children #2609

Merged
merged 1 commit into from
Aug 25, 2023
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
6 changes: 3 additions & 3 deletions packages/taquito-michelson-encoder/src/tokens/pair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ export class PairToken extends ComparableToken {
const leftToken = this.createToken(args[0], this.idx);
let keyCount = 1;
let leftValue;
if (leftToken instanceof PairToken) {
keyCount = Object.keys(leftToken.ExtractSchema()).length;
}
if (leftToken instanceof PairToken && !leftToken.hasAnnotations()) {
leftValue = getLeftValue(leftToken);
if (leftToken instanceof PairToken) {
ac10n marked this conversation as resolved.
Show resolved Hide resolved
keyCount = Object.keys(leftToken.ExtractSchema()).length;
}
} else {
leftValue = { [leftToken.annot()]: getLeftValue(leftToken) };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('Global constant token', () => {
} catch (e: any) {
expect(e).toBeInstanceOf(GlobalConstantDecodingError);
expect(e.message).toEqual(
`[2] Unable to decode a value represented by a global constants. Please provide an expanded script to the Michelson-Encoder or semantics for the decoding. The following global constant hash was encountered: expru5X5fvCer8tbRkSAtwyVCs9FUCq46JQG7QCAkhZSumjbZBUGzb.`
`[1] Unable to decode a value represented by a global constants. Please provide an expanded script to the Michelson-Encoder or semantics for the decoding. The following global constant hash was encountered: expru5X5fvCer8tbRkSAtwyVCs9FUCq46JQG7QCAkhZSumjbZBUGzb.`
);
}
});
Expand Down
48 changes: 46 additions & 2 deletions packages/taquito-michelson-encoder/test/tokens/pair.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Schema } from '../../src/taquito-michelson-encoder';
import { createToken } from '../../src/tokens/createToken';
import { PairToken } from '../../src/tokens/pair';
import BigNumber from 'bignumber.js';

describe('Pair token', () => {
const token = createToken(
Expand Down Expand Up @@ -162,7 +164,7 @@ describe('Complexe pair token', () => {
optional: {
__michelsonType: 'pair',
schema: {
'3': {
'2': {
__michelsonType: 'or',
schema: {
int: {
Expand All @@ -175,7 +177,7 @@ describe('Complexe pair token', () => {
},
},
},
'4': {
'3': {
__michelsonType: 'or',
schema: {
int: {
Expand Down Expand Up @@ -312,3 +314,45 @@ describe('Complexe pair token', () => {
});
});
});

describe('PairToken mixed with and without annotations', () => {
const schema = {
prim: 'pair',
args: [
{
prim: 'pair',
args: [
{
prim: 'pair',
args: [{ prim: 'int' }, { prim: 'int' }],
annots: ['%A3'],
},
{ prim: 'int' },
],
},
{ prim: 'bool' },
],
};

const michelineJson = {
prim: 'Pair',
args: [
{
prim: 'Pair',
args: [{ prim: 'Pair', args: [{ int: '11' }, { int: '22' }] }, { int: '33' }],
},
{ prim: 'True' },
],
};

const javaScriptObject = new Schema(schema).Execute(michelineJson);

expect(javaScriptObject).toEqual({
1: new BigNumber(33),
2: true,
A3: {
0: new BigNumber(11),
1: new BigNumber(22),
},
});
});