diff --git a/cspell.json b/cspell.json index 55703c4a06..8ba11d35e3 100644 --- a/cspell.json +++ b/cspell.json @@ -75,6 +75,7 @@ "tezbridge", "tezos", "ticketer", + "timelock", "toolbelt", "TORU", "typecheck", diff --git a/integration-tests/data/allTestsCases.ts b/integration-tests/data/allTestsCases.ts index 0979aa95f2..87857f764e 100644 --- a/integration-tests/data/allTestsCases.ts +++ b/integration-tests/data/allTestsCases.ts @@ -22,6 +22,7 @@ import { codeViewsTopLevel, storageViewsTopLevel } from './contract_views_top_le import { MichelsonV1Expression, OpKind, PvmKind } from '@taquito/rpc'; import { emitCode } from './code_with_emit'; import { lambdaRecCode } from './code_with_lambda_rec'; +import { timelockCode, timelockStorage, timelockExpected } from './timelock-flip-contract'; function extractOp( startIndex: number, @@ -1171,21 +1172,6 @@ export const commonCases: TestCase[] = [ ], }, }, - { - name: 'Attestation', - operation: { - branch: 'BLzyjjHKEKMULtvkpSHxuZxx6ei6fpntH2BTkYZiLgs8zLVstvX', - contents: [ - { - kind: OpKind.ATTESTATION, - slot: 0, - level: 66299, - round: 5, - block_payload_hash: 'vh3FEkypvxUYLwjGYd2Sme7aWyfX8npDsqxcL6imVpBWnAZeNn2n', - }, - ], - }, - }, { name: `Origination of a contract that contains the instructions SUB_MUTEZ`, operation: { @@ -1348,28 +1334,6 @@ export const commonCases: TestCase[] = [ ], }, }, - { - name: `Origination of a smart_rollup_originate operation`, - operation: { - branch: 'BLxGBu48ybnWvZoaVLyXV4XVnhdeDc9V2NcB9wsegQniza6mxvX', - contents: [ - { - kind: OpKind.SMART_ROLLUP_ORIGINATE, - source: 'tz1h5DrMhmdrGMpb3qkykU1RmCWoTYAkFJPu', - fee: '1496', - counter: '3969', - gas_limit: '2849', - storage_limit: '6572', - pvm_kind: PvmKind.WASM2, - kernel: - '23212f7573722f62696e2f656e762073680a6578706f7274204b45524e454c3d22303036313733366430313030303030303031323830373630303337663766376630313766363030323766376630313766363030353766376637663766376630313766363030313766303036303031376630313766363030323766376630303630303030303032363130333131373336643631373237343566373236663663366337353730356636333666373236353061373236353631363435663639366537303735373430303030313137333664363137323734356637323666366336633735373035663633366637323635306337373732363937343635356636663735373437303735373430303031313137333664363137323734356637323666366336633735373035663633366637323635306237333734366637323635356637373732363937343635303030323033303530343033303430353036303530333031303030313037313430323033366436353664303230303061366236353732366536353663356637323735366530303036306161343031303432613031303237663431666130303266303130303231303132303030326630313030323130323230303132303032343730343430343165343030343131323431303034316534303034313030313030323161306230623038303032303030343163343030366230623530303130353766343166653030326430303030323130333431666330303266303130303231303232303030326430303030323130343230303032663031303032313035323030313130303432313036323030343230303334363034343032303030343130313661323030313431303136623130303131613035323030353230303234363034343032303030343130373661323030363130303131613062306230623164303130313766343164633031343138343032343139303163313030303231303034313834303232303030313030353431383430323130303330623062333830353030343165343030306231323266366236353732366536353663326636353665373632663732363536323666366637343030343166383030306230323030303130303431666130303062303230303032303034316663303030623032303030303030343166653030306230313031220a', - parameters_ty: { - prim: 'bytes', - }, - }, - ], - } - }, { name: `Origination of a smart_rollup_add_messages operation`, operation: { @@ -1423,3 +1387,82 @@ export const commonCases: TestCase[] = [ } } ]; + +export const oxfordCases: TestCase[] = [ + { + name: 'Attestation', + operation: { + branch: 'BLzyjjHKEKMULtvkpSHxuZxx6ei6fpntH2BTkYZiLgs8zLVstvX', + contents: [ + { + kind: OpKind.ATTESTATION, + slot: 0, + level: 66299, + round: 5, + block_payload_hash: 'vh3FEkypvxUYLwjGYd2Sme7aWyfX8npDsqxcL6imVpBWnAZeNn2n', + }, + ], + }, + }, + { + name: `Origination of a smart_rollup_originate operation`, + operation: { + branch: 'BLxGBu48ybnWvZoaVLyXV4XVnhdeDc9V2NcB9wsegQniza6mxvX', + contents: [ + { + kind: OpKind.SMART_ROLLUP_ORIGINATE, + source: 'tz1h5DrMhmdrGMpb3qkykU1RmCWoTYAkFJPu', + fee: '1496', + counter: '3969', + gas_limit: '2849', + storage_limit: '6572', + pvm_kind: PvmKind.WASM2, + kernel: + '23212f7573722f62696e2f656e762073680a6578706f7274204b45524e454c3d22303036313733366430313030303030303031323830373630303337663766376630313766363030323766376630313766363030353766376637663766376630313766363030313766303036303031376630313766363030323766376630303630303030303032363130333131373336643631373237343566373236663663366337353730356636333666373236353061373236353631363435663639366537303735373430303030313137333664363137323734356637323666366336633735373035663633366637323635306337373732363937343635356636663735373437303735373430303031313137333664363137323734356637323666366336633735373035663633366637323635306237333734366637323635356637373732363937343635303030323033303530343033303430353036303530333031303030313037313430323033366436353664303230303061366236353732366536353663356637323735366530303036306161343031303432613031303237663431666130303266303130303231303132303030326630313030323130323230303132303032343730343430343165343030343131323431303034316534303034313030313030323161306230623038303032303030343163343030366230623530303130353766343166653030326430303030323130333431666330303266303130303231303232303030326430303030323130343230303032663031303032313035323030313130303432313036323030343230303334363034343032303030343130313661323030313431303136623130303131613035323030353230303234363034343032303030343130373661323030363130303131613062306230623164303130313766343164633031343138343032343139303163313030303231303034313834303232303030313030353431383430323130303330623062333830353030343165343030306231323266366236353732366536353663326636353665373632663732363536323666366637343030343166383030306230323030303130303431666130303062303230303032303034316663303030623032303030303030343166653030306230313031220a', + parameters_ty: { + prim: 'bytes', + }, + }, + ], + } + }, + { + name: 'Origination of a contract that contains the types chest, chest_key and the instruction OPEN_CHEST', + operation: { + branch: 'BMV9bffK5yjWCJgUJBsoTRifb4SsAYbkCVwVkKbJHffJYn7ePBL', + contents: [ + { + kind: OpKind.ORIGINATION, + counter: '1', + source: 'tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn', + fee: '10000', + gas_limit: '10', + storage_limit: '10', + balance: '0', + script: { + code: timelockCode, + storage: timelockStorage, + }, + }, + ], + }, + expected: { + branch: 'BMV9bffK5yjWCJgUJBsoTRifb4SsAYbkCVwVkKbJHffJYn7ePBL', + contents: [ + { + kind: OpKind.ORIGINATION, + counter: '1', + source: 'tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn', + fee: '10000', + gas_limit: '10', + storage_limit: '10', + balance: '0', + script: { + code: timelockExpected, + storage: timelockStorage, + }, + }, + ], + }, + } +] diff --git a/integration-tests/data/timelock-flip-contract.ts b/integration-tests/data/timelock-flip-contract.ts new file mode 100644 index 0000000000..a1157f0ffd --- /dev/null +++ b/integration-tests/data/timelock-flip-contract.ts @@ -0,0 +1,854 @@ +// https://gitlab.com/tezos/tezos/-/blob/master/src/proto_alpha/lib_protocol/contracts/timelock_flip.tz?ref_type=heads + +export const timelockStorage = { + "prim": "Pair", + "args": [ + { + "int": "0" + }, + { + "prim": "Pair", + "args": [ + { + "bytes": "e0d984a0e19fd7e7a4ac90dc9bf7e59288e8d8b0a0ca8bf988cae8fa90dbc584c2ee91a1f5d1a1d8d695f58bd1c7b1e4c0b9f384918a89dfd4eff5c3fbaff7e5d68de19088c5fdc08286f18bc7d1c4f99590f3bfd881c68d97bf91d2d4d2ded688d993e59b8aac84b798eed496a1e2dff9cfc1e3c793a8eea1fbf3a8c6c895bb8d8dedded3ed80b4848cb9ddb0c2f1ea98b8a6c3b6c691f2e787afc9bc8dd386a4b08392bbb7c1b6cdbaa6ec98a1fc96ecb287d5f6e39892aea199f4bf91e89bb8e7b58dc4f5d5bfec88ba99d1efc7c98aabe6bebbeeb4b589a383a6f581e69edbe2a4e7db8cb7e4ab8390b6f7c4c6ba9ee7c1f8d7e0f2aba5bf97cdbb85ca8dd0f7dff8fd95a1a9a68dd3b283a5f9fc93a2e7acafc4cbbeb3b2f8fe8faf97c5d2fae681081fe2a28ce94b55c47fe6a2927dc36c403067a86e36a163000000001a7c31a45bcb9934e3089cbc023a0bebe815ee2f646a0d344469f7" + }, + { + "prim": "Pair", + "args": [ + { + "bytes": "01" + }, + { + "bytes": "01" + } + ] + } + ] + } + ] +} + +export const timelockCode = [ + { + "prim": "storage", + "args": [ + { + "prim": "pair", + "args": [ + { + "prim": "nat", + "annots": [ + "%level" + ] + }, + { + "prim": "chest" + }, + { + "prim": "bytes", + "annots": [ + "%guess" + ] + }, + { + "prim": "bytes", + "annots": [ + "%result" + ] + } + ] + } + ] + }, + { + "prim": "parameter", + "args": [ + { + "prim": "or", + "args": [ + { + "prim": "chest", + "annots": [ + "%initialize_game" + ] + }, + { + "prim": "or", + "args": [ + { + "prim": "bytes", + "annots": [ + "%guess" + ] + }, + { + "prim": "chest_key", + "annots": [ + "%finish_game" + ] + } + ] + } + ] + } + ] + }, + { + "prim": "code", + "args": [ + [ + { + "prim": "UNPAIR", + "args": [ + { + "int": "5" + } + ] + }, + { + "prim": "IF_LEFT", + "args": [ + [ + { + "prim": "DIP", + "args": [ + [ + { + "prim": "DROP", + "args": [ + { + "int": "4" + } + ] + } + ] + ] + }, + { + "prim": "PUSH", + "args": [ + { + "prim": "bytes" + }, + { + "bytes": "A0" + } + ] + }, + { + "prim": "DUP" + }, + { + "prim": "PAIR" + }, + { + "prim": "SWAP" + }, + { + "prim": "LEVEL" + }, + { + "prim": "PAIR", + "args": [ + { + "int": "3" + } + ] + } + ], + [ + { + "prim": "IF_LEFT", + "args": [ + [ + { + "prim": "SWAP" + }, + { + "prim": "DUP" + }, + { + "prim": "PUSH", + "args": [ + { + "prim": "nat" + }, + { + "int": "10" + } + ] + }, + { + "prim": "ADD" + }, + { + "prim": "LEVEL" + }, + { + "prim": "COMPARE" + }, + { + "prim": "LE" + }, + { + "prim": "IF", + "args": [ + [ + { + "prim": "DIP", + "args": [ + { + "int": "2" + }, + [ + { + "prim": "PUSH", + "args": [ + { + "prim": "bytes" + }, + { + "bytes": "B0" + } + ] + } + ] + ] + }, + { + "prim": "DIP", + "args": [ + [ + { + "prim": "PAIR" + }, + { + "prim": "SWAP" + }, + { + "prim": "PAIR" + } + ] + ] + }, + { + "prim": "PAIR" + }, + { + "prim": "DIP", + "args": [ + [ + { + "prim": "DROP", + "args": [ + { + "int": "2" + } + ] + } + ] + ] + } + ], + [ + { + "prim": "SWAP" + }, + { + "prim": "DROP" + }, + { + "prim": "PAIR", + "args": [ + { + "int": "4" + } + ] + } + ] + ] + } + ], + [ + { + "prim": "DIP", + "args": [ + { + "int": "4" + }, + [ + { + "prim": "DROP" + } + ] + ] + }, + { + "prim": "DUP", + "args": [ + { + "int": "3" + } + ] + }, + { + "prim": "SWAP" + }, + { + "prim": "DIP", + "args": [ + { + "int": "2" + }, + [ + { + "prim": "PUSH", + "args": [ + { + "prim": "nat" + }, + { + "int": "1024" + } + ] + } + ] + ] + }, + { + "prim": "OPEN_CHEST" + }, + [ + { + "prim": "IF_NONE", + "args": [ + [ + { + "prim": "PUSH", + "args": [ + { + "prim": "bytes" + }, + { + "bytes": "10" + } + ] + } + ], + [ + { + "prim": "DUP", + "args": [ + { + "int": "4" + } + ] + }, + { + "prim": "COMPARE" + }, + { + "prim": "EQ" + }, + { + "prim": "IF", + "args": [ + [ + { + "prim": "PUSH", + "args": [ + { + "prim": "bytes" + }, + { + "bytes": "00" + } + ] + } + ], + [ + { + "prim": "PUSH", + "args": [ + { + "prim": "bytes" + }, + { + "bytes": "01" + } + ] + } + ] + ] + } + ] + ] + } + ], + { + "prim": "DIG", + "args": [ + { + "int": "3" + } + ] + }, + { + "prim": "PAIR" + }, + { + "prim": "DIG", + "args": [ + { + "int": "2" + } + ] + }, + { + "prim": "PAIR" + }, + { + "prim": "DIG", + "args": [ + { + "int": "1" + } + ] + }, + { + "prim": "PAIR" + } + ] + ] + } + ] + ] + }, + { + "prim": "NIL", + "args": [ + { + "prim": "operation" + } + ] + }, + { + "prim": "PAIR" + } + ] + ] + } +] + +// parse bytes will be lowercased ref https://github.com/ecadlabs/taquito/pull/1623 +export const timelockExpected = [ + { + "prim": "storage", + "args": [ + { + "prim": "pair", + "args": [ + { + "prim": "nat", + "annots": [ + "%level" + ] + }, + { + "prim": "chest" + }, + { + "prim": "bytes", + "annots": [ + "%guess" + ] + }, + { + "prim": "bytes", + "annots": [ + "%result" + ] + } + ] + } + ] + }, + { + "prim": "parameter", + "args": [ + { + "prim": "or", + "args": [ + { + "prim": "chest", + "annots": [ + "%initialize_game" + ] + }, + { + "prim": "or", + "args": [ + { + "prim": "bytes", + "annots": [ + "%guess" + ] + }, + { + "prim": "chest_key", + "annots": [ + "%finish_game" + ] + } + ] + } + ] + } + ] + }, + { + "prim": "code", + "args": [ + [ + { + "prim": "UNPAIR", + "args": [ + { + "int": "5" + } + ] + }, + { + "prim": "IF_LEFT", + "args": [ + [ + { + "prim": "DIP", + "args": [ + [ + { + "prim": "DROP", + "args": [ + { + "int": "4" + } + ] + } + ] + ] + }, + { + "prim": "PUSH", + "args": [ + { + "prim": "bytes" + }, + { + "bytes": "a0" + } + ] + }, + { + "prim": "DUP" + }, + { + "prim": "PAIR" + }, + { + "prim": "SWAP" + }, + { + "prim": "LEVEL" + }, + { + "prim": "PAIR", + "args": [ + { + "int": "3" + } + ] + } + ], + [ + { + "prim": "IF_LEFT", + "args": [ + [ + { + "prim": "SWAP" + }, + { + "prim": "DUP" + }, + { + "prim": "PUSH", + "args": [ + { + "prim": "nat" + }, + { + "int": "10" + } + ] + }, + { + "prim": "ADD" + }, + { + "prim": "LEVEL" + }, + { + "prim": "COMPARE" + }, + { + "prim": "LE" + }, + { + "prim": "IF", + "args": [ + [ + { + "prim": "DIP", + "args": [ + { + "int": "2" + }, + [ + { + "prim": "PUSH", + "args": [ + { + "prim": "bytes" + }, + { + "bytes": "b0" + } + ] + } + ] + ] + }, + { + "prim": "DIP", + "args": [ + [ + { + "prim": "PAIR" + }, + { + "prim": "SWAP" + }, + { + "prim": "PAIR" + } + ] + ] + }, + { + "prim": "PAIR" + }, + { + "prim": "DIP", + "args": [ + [ + { + "prim": "DROP", + "args": [ + { + "int": "2" + } + ] + } + ] + ] + } + ], + [ + { + "prim": "SWAP" + }, + { + "prim": "DROP" + }, + { + "prim": "PAIR", + "args": [ + { + "int": "4" + } + ] + } + ] + ] + } + ], + [ + { + "prim": "DIP", + "args": [ + { + "int": "4" + }, + [ + { + "prim": "DROP" + } + ] + ] + }, + { + "prim": "DUP", + "args": [ + { + "int": "3" + } + ] + }, + { + "prim": "SWAP" + }, + { + "prim": "DIP", + "args": [ + { + "int": "2" + }, + [ + { + "prim": "PUSH", + "args": [ + { + "prim": "nat" + }, + { + "int": "1024" + } + ] + } + ] + ] + }, + { + "prim": "OPEN_CHEST" + }, + [ + { + "prim": "IF_NONE", + "args": [ + [ + { + "prim": "PUSH", + "args": [ + { + "prim": "bytes" + }, + { + "bytes": "10" + } + ] + } + ], + [ + { + "prim": "DUP", + "args": [ + { + "int": "4" + } + ] + }, + { + "prim": "COMPARE" + }, + { + "prim": "EQ" + }, + { + "prim": "IF", + "args": [ + [ + { + "prim": "PUSH", + "args": [ + { + "prim": "bytes" + }, + { + "bytes": "00" + } + ] + } + ], + [ + { + "prim": "PUSH", + "args": [ + { + "prim": "bytes" + }, + { + "bytes": "01" + } + ] + } + ] + ] + } + ] + ] + } + ], + { + "prim": "DIG", + "args": [ + { + "int": "3" + } + ] + }, + { + "prim": "PAIR" + }, + { + "prim": "DIG", + "args": [ + { + "int": "2" + } + ] + }, + { + "prim": "PAIR" + }, + { + "prim": "DIG", + "args": [ + { + "int": "1" + } + ] + }, + { + "prim": "PAIR" + } + ] + ] + } + ] + ] + }, + { + "prim": "NIL", + "args": [ + { + "prim": "operation" + } + ] + }, + { + "prim": "PAIR" + } + ] + ] + } +] \ No newline at end of file diff --git a/integration-tests/local-forging.spec.ts b/integration-tests/local-forging.spec.ts index aa487c73e3..facc34154e 100644 --- a/integration-tests/local-forging.spec.ts +++ b/integration-tests/local-forging.spec.ts @@ -1,11 +1,12 @@ import { CONFIGS } from "./config"; -import { commonCases, nairobiCases } from './data/allTestsCases'; +import { commonCases, nairobiCases, oxfordCases } from './data/allTestsCases'; import { LocalForger, ProtocolsHash } from '@taquito/local-forging' import { Protocols, TezosToolkit } from "@taquito/taquito"; CONFIGS().forEach(({ rpc, protocol }) => { const Tezos = new TezosToolkit(rpc); const nairobinet = protocol === Protocols.PtNairobi ? it : it.skip; + const oxfordnet = protocol === Protocols.ProxfordS ? it : it.skip; describe(`Test local forger: ${rpc}`, () => { nairobiCases.forEach(({ name, operation, expected }) => { @@ -19,6 +20,17 @@ CONFIGS().forEach(({ rpc, protocol }) => { done(); }); }); + oxfordCases.forEach(({ name, operation, expected }) => { + oxfordnet(`Verify that .forge for local forge will return same result as for network forge for rpc: ${name} (${rpc})`, async done => { + const localForger = new LocalForger(protocol as unknown as ProtocolsHash); + const result = await localForger.forge(operation); + const rpcResult = await Tezos.rpc.forgeOperations(operation); + expect(result).toEqual(rpcResult); + expect(await localForger.parse(result)).toEqual(expected || operation); + + done(); + }); + }); // all protocols commonCases.forEach(({ name, operation, expected }) => { it(`Verify that .forge for local forge will return same result as for network forge for rpc: ${name} (${rpc})`, async done => {