Skip to content

Commit

Permalink
feat: start support bytes conversion 2268
Browse files Browse the repository at this point in the history
close #2268
  • Loading branch information
Zainen Suzuki authored and Zainen Suzuki committed Jan 25, 2023
1 parent 4e5e9e9 commit 6313104
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/taquito-michel-codec/src/michelson-typecheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1296,9 +1296,17 @@ function functionTypeInternal(
return [annotateVar({ prim: 'option', args: [{ prim: 'nat' }] }), ...stack.slice(1)];

case 'INT':
args(0, ['nat', 'bls12_381_fr']);
args(0, ['nat', 'bls12_381_fr', 'bytes']);
return [annotateVar({ prim: 'int' }), ...stack.slice(1)];

case 'BYTES':
args(0, ['nat', 'int']);
return [annotateVar({ prim: 'bytes' }), ...stack.slice(1)];

case 'NAT':
args(0, ['bytes']);
return [annotateVar({ prim: 'nat' }), ...stack.slice(1)];

case 'NEG': {
const s = args(0, ['nat', 'int', 'bls12_381_g1', 'bls12_381_g2', 'bls12_381_fr'])[0];
if (s.prim === 'nat' || s.prim === 'int') {
Expand Down
4 changes: 3 additions & 1 deletion packages/taquito-michel-codec/src/michelson-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ type MichelsonNoArgInstructionID =
| 'XOR'
| 'RENAME'
| 'OPEN_CHEST'
| 'MIN_BLOCK_TIME';
| 'MIN_BLOCK_TIME'
| 'BYTES'
| 'NAT';

type MichelsonRegularInstructionID =
| 'CONTRACT'
Expand Down
2 changes: 2 additions & 0 deletions packages/taquito-michel-codec/src/michelson-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ const noArgInstructionIDs: Record<MichelsonNoArgInstruction['prim'], true> = {
OPEN_CHEST: true,
SUB_MUTEZ: true,
MIN_BLOCK_TIME: true,
BYTES: true,
NAT: true,
};

export const instructionIDs: Record<MichelsonInstruction['prim'], true> = Object.assign(
Expand Down
2 changes: 2 additions & 0 deletions packages/taquito-michel-codec/test/contracts_016.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const contracts: {
'not_bytes.tz',
'or_bytes.tz',
'xor_bytes.tz',
'bytes_of_int.tz',
'bytes_of_nat.tz',
],
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
parameter unit;
storage unit;
code { DROP;

PUSH int 0; BYTES; PUSH bytes 0x; ASSERT_CMPEQ;
PUSH int 1; BYTES; PUSH bytes 0x01; ASSERT_CMPEQ;
PUSH int 1193046; BYTES; PUSH bytes 0x123456; ASSERT_CMPEQ;

PUSH bytes 0x123456; INT; PUSH int 1193046; ASSERT_CMPEQ;
PUSH bytes 0x0000123456; INT; PUSH int 1193046; ASSERT_CMPEQ;
PUSH bytes 0x; INT; PUSH int 0; ASSERT_CMPEQ;
PUSH bytes 0x0000; INT; PUSH int 0; ASSERT_CMPEQ;

PUSH int -128; BYTES; PUSH bytes 0x80; ASSERT_CMPEQ;
PUSH int -129; BYTES; PUSH bytes 0xff7f; ASSERT_CMPEQ;
PUSH int -33024; BYTES; PUSH bytes 0xff7f00; ASSERT_CMPEQ;
PUSH int -4294967296; BYTES; PUSH bytes 0xff00000000; ASSERT_CMPEQ;

PUSH bytes 0x80; INT; PUSH int -128; ASSERT_CMPEQ;
PUSH bytes 0xff7f; INT; PUSH int -129; ASSERT_CMPEQ;
PUSH bytes 0xff7f00; INT; PUSH int -33024; ASSERT_CMPEQ;
PUSH bytes 0xffffff7f00; INT; PUSH int -33024; ASSERT_CMPEQ;
PUSH bytes 0xff00000000; INT; PUSH int -4294967296; ASSERT_CMPEQ;

UNIT; NIL operation; PAIR; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
parameter unit;
storage unit;
code { DROP;

PUSH nat 0; BYTES; PUSH bytes 0x; ASSERT_CMPEQ;
PUSH nat 1; BYTES; PUSH bytes 0x01; ASSERT_CMPEQ;
PUSH nat 1193046; BYTES; PUSH bytes 0x123456; ASSERT_CMPEQ;

PUSH bytes 0x123456; NAT; PUSH nat 1193046; ASSERT_CMPEQ;
PUSH bytes 0x0000123456; NAT; PUSH nat 1193046; ASSERT_CMPEQ;
PUSH bytes 0x; NAT; PUSH nat 0; ASSERT_CMPEQ;
PUSH bytes 0x0000; NAT; PUSH nat 0; ASSERT_CMPEQ;

UNIT; NIL operation; PAIR; }

0 comments on commit 6313104

Please sign in to comment.