From 66cdd13db48fa17b165a8203c11fab960944f62b Mon Sep 17 00:00:00 2001 From: lykimq Date: Mon, 20 Feb 2023 17:43:56 +0100 Subject: [PATCH 1/2] Alcotezt: port [src/proto_/lib_protocol/test/integration/michelson] to alcotezt] --- .gitlab/ci/jobs/coverage/coverage.yml | 3 - .gitlab/ci/jobs/test/unit.yml | 59 --------------- manifest/main.ml | 40 +++++++++-- manifest/manifest.ml | 8 ++- manifest/manifest.mli | 1 + opam/tezos-protocol-015-PtLimaPt-tests.opam | 11 ++- opam/tezos-protocol-016-PtMumbai-tests.opam | 11 ++- opam/tezos-protocol-alpha-tests.opam | 11 ++- .../test/integration/michelson/dune | 57 ++++++++++++--- .../michelson/test_contract_event.ml | 5 +- .../michelson/test_interpretation.ml | 16 +++-- .../michelson/{main.ml => test_main.ml} | 46 ++++++------ .../michelson/test_patched_contracts.ml | 6 +- .../integration/michelson/test_sapling.ml | 71 ++++++------------- .../michelson/test_script_cache.ml | 17 +++-- .../michelson/test_temp_big_maps.ml | 10 ++- .../integration/michelson/test_timelock.ml | 2 +- .../michelson/test_typechecking.ml | 14 ++-- .../test/integration/michelson/dune | 58 ++++++++++++--- .../michelson/test_contract_event.ml | 4 +- .../michelson/test_interpretation.ml | 16 +++-- .../michelson/{main.ml => test_main.ml} | 48 +++++++------ .../michelson/test_patched_contracts.ml | 6 +- .../integration/michelson/test_sapling.ml | 71 ++++++------------- .../michelson/test_script_cache.ml | 17 +++-- .../michelson/test_temp_big_maps.ml | 10 ++- .../integration/michelson/test_timelock.ml | 2 +- .../michelson/test_typechecking.ml | 12 ++-- .../test/integration/michelson/dune | 57 ++++++++++++--- .../michelson/test_contract_event.ml | 4 +- .../michelson/test_interpretation.ml | 16 +++-- .../michelson/{main.ml => test_main.ml} | 48 +++++++------ .../michelson/test_patched_contracts.ml | 6 +- .../integration/michelson/test_sapling.ml | 25 ++++--- .../michelson/test_script_cache.ml | 30 ++++++-- .../michelson/test_temp_big_maps.ml | 4 +- .../integration/michelson/test_timelock.ml | 2 +- .../michelson/test_typechecking.ml | 12 ++-- tezt/tests/dune | 3 + 39 files changed, 479 insertions(+), 360 deletions(-) rename src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/{main.ml => test_main.ml} (58%) rename src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/{main.ml => test_main.ml} (57%) rename src/proto_alpha/lib_protocol/test/integration/michelson/{main.ml => test_main.ml} (57%) diff --git a/.gitlab/ci/jobs/coverage/coverage.yml b/.gitlab/ci/jobs/coverage/coverage.yml index 0ae3295e0ba0..b5b5d8c175d8 100644 --- a/.gitlab/ci/jobs/coverage/coverage.yml +++ b/.gitlab/ci/jobs/coverage/coverage.yml @@ -55,10 +55,7 @@ unified_coverage: - "tezt 38/40" - "tezt 39/40" - "tezt 40/40" - - "unit:alpha: [proto_alpha]" - - "unit:alpha: [proto_alpha__lib_protocol__2]" - "unit:non-proto-x86_64" - script: # On the development branches, we compute coverage - ./scripts/ci/report_coverage.sh diff --git a/.gitlab/ci/jobs/test/unit.yml b/.gitlab/ci/jobs/test/unit.yml index 8f5eaa8a3cec..99fb86f5a2de 100644 --- a/.gitlab/ci/jobs/test/unit.yml +++ b/.gitlab/ci/jobs/test/unit.yml @@ -41,65 +41,6 @@ tags: - arm64 -unit:015_PtLimaPt: - extends: - - .unit_test_template_x86_64_coverage - # We use an extra level of indirection for TEST_TARGETS, to avoid - # overly long job names causing GitLab CI to silently fail. - variables: - # Note the use of @ resp. @@ to select tests recursively resp. non-recursively - proto_015_PtLimaPt__lib_protocol__2: > - @src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/runtest - @src/proto_015_PtLimaPt/lib_protocol/test/integration/validate/runtest - parallel: - matrix: - - TEST_TARGETS: - - proto_015_PtLimaPt__lib_protocol__2 - script: - - scripts/test_wrapper.sh $TEST_TARGETS ${!TEST_TARGETS} - - ./scripts/ci/merge_coverage.sh - -unit:016_PtMumbai: - extends: - - .unit_test_template_x86_64_coverage - # We use an extra level of indirection for TEST_TARGETS, to avoid - # overly long job names causing GitLab CI to silently fail. - variables: - # Note the use of @ resp. @@ to select tests recursively resp. non-recursively - proto_016_PtMumbai__lib_protocol__2: > - @src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/runtest - @src/proto_016_PtMumbai/lib_protocol/test/integration/validate/runtest - proto_016_PtMumbai: > - @src/proto_016_PtMumbai/lib_dal/runtest - parallel: - matrix: - - TEST_TARGETS: - - proto_016_PtMumbai__lib_protocol__2 - - proto_016_PtMumbai - script: - - scripts/test_wrapper.sh $TEST_TARGETS ${!TEST_TARGETS} - - ./scripts/ci/merge_coverage.sh - -unit:alpha: - extends: - - .unit_test_template_x86_64_coverage - # We use an extra level of indirection for TEST_TARGETS, to avoid - # overly long job names causing GitLab CI to silently fail. - variables: - # Note the use of @ resp. @@ to select tests recursively resp. non-recursively - proto_alpha__lib_protocol__2: > - @src/proto_alpha/lib_protocol/test/integration/michelson/runtest - @src/proto_alpha/lib_protocol/test/integration/validate/runtest - proto_alpha: > - @src/proto_alpha/lib_dal/runtest - parallel: - matrix: - - TEST_TARGETS: - - proto_alpha__lib_protocol__2 - - proto_alpha - script: - - scripts/test_wrapper.sh $TEST_TARGETS ${!TEST_TARGETS} - - ./scripts/ci/merge_coverage.sh unit:non-proto-x86_64: extends: - .unit_test_template_x86_64_coverage diff --git a/manifest/main.ml b/manifest/main.ml index 8b681083324a..31ce16af4ffe 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -385,8 +385,9 @@ let tezt_core_lib = let tezt_js_lib = external_sublib tezt_lib ~js_compatible:true "tezt.js" -let tezt ~opam ~path ?js_compatible ?modes ?(deps = []) ?dep_globs ?dep_files - ?opam_with_test ?synopsis ?(with_macos_security_framework = false) l = +let tezt ~opam ~path ?js_compatible ?modes ?(deps = []) ?dep_globs + ?dep_globs_rec ?dep_files ?opam_with_test ?synopsis + ?(with_macos_security_framework = false) l = tezt_without_tezt_lib_dependency ~with_macos_security_framework ~opam @@ -398,6 +399,7 @@ let tezt ~opam ~path ?js_compatible ?modes ?(deps = []) ?dep_globs ?dep_files ~exe_deps:[tezt_lib] ~js_deps:[tezt_js_lib] ?dep_globs + ?dep_globs_rec ?dep_files ?opam_with_test l @@ -3933,8 +3935,36 @@ end = struct ] in let _integration_michelson = - test - "main" + let modules = + [ + ("test_main", true); + ("test_annotations", true); + ("test_block_time_instructions", true); + ("test_contract_event", true); + ("test_global_constants_storage", true); + ("test_interpretation", true); + ("test_lazy_storage_diff", true); + ("test_patched_contracts", true); + ("test_sapling", true); + ("test_script_cache", true); + ("test_script_typed_ir_size", true); + ("test_temp_big_maps", true); + ("test_ticket_accounting", true); + ("test_ticket_balance_key", true); + ("test_ticket_balance", true); + ("test_ticket_lazy_storage_diff", true); + ("test_ticket_manager", true); + ("test_ticket_operations_diff", true); + ("test_ticket_scanner", true); + ("test_ticket_storage", true); + ("test_timelock", true); + ("test_typechecking", true); + ("test_lambda_normalization", N.(number >= 016)); + ] + |> List.filter_map (fun (n, b) -> if b then Some n else None) + in + tezt + modules ~path:(path // "lib_protocol/test/integration/michelson") ~opam:(sf "tezos-protocol-%s-tests" name_dash) ~with_macos_security_framework:true @@ -3952,7 +3982,7 @@ end = struct ]) ~deps: [ - alcotest_lwt; + alcotezt; octez_base |> open_ ~m:"TzPervasives" |> open_ ~m:"TzPervasives.Error_monad.Legacy_monad_globals"; main |> open_; diff --git a/manifest/manifest.ml b/manifest/manifest.ml index 70979abc52e0..423185761f4a 100644 --- a/manifest/manifest.ml +++ b/manifest/manifest.ml @@ -1786,6 +1786,7 @@ type tezt_target = { exe_deps : target list; js_deps : target list; dep_globs : string list; + dep_globs_rec : string list; dep_files : string list; modules : string list; js_compatible : bool option; @@ -1798,8 +1799,8 @@ type tezt_target = { let tezt_targets_by_path : tezt_target String_map.t ref = ref String_map.empty let tezt ~opam ~path ?js_compatible ?modes ?(lib_deps = []) ?(exe_deps = []) - ?(js_deps = []) ?(dep_globs = []) ?(dep_files = []) ?synopsis - ?opam_with_test ?(with_macos_security_framework = false) modules = + ?(js_deps = []) ?(dep_globs = []) ?(dep_globs_rec = []) ?(dep_files = []) + ?synopsis ?opam_with_test ?(with_macos_security_framework = false) modules = if String_map.mem path !tezt_targets_by_path then invalid_arg ("cannot call Manifest.tezt twice for the same directory: " ^ path) ; @@ -1811,6 +1812,7 @@ let tezt ~opam ~path ?js_compatible ?modes ?(lib_deps = []) ?(exe_deps = []) js_deps; dep_globs; dep_files; + dep_globs_rec; modules; js_compatible; modes; @@ -1830,6 +1832,7 @@ let register_tezt_targets ~make_tezt_exe = exe_deps; js_deps; dep_globs; + dep_globs_rec; dep_files; modules; js_compatible; @@ -1867,6 +1870,7 @@ let register_tezt_targets ~make_tezt_exe = ?modes ~deps:(lib :: deps) ~dep_globs + ~dep_globs_rec ~dep_files ~modules:[exe_name] ?opam_with_test diff --git a/manifest/manifest.mli b/manifest/manifest.mli index 19f10e349dee..74a395da8a38 100644 --- a/manifest/manifest.mli +++ b/manifest/manifest.mli @@ -929,6 +929,7 @@ val tezt : ?exe_deps:target list -> ?js_deps:target list -> ?dep_globs:string list -> + ?dep_globs_rec:string list -> ?dep_files:string list -> ?synopsis:string -> ?opam_with_test:with_test -> diff --git a/opam/tezos-protocol-015-PtLimaPt-tests.opam b/opam/tezos-protocol-015-PtLimaPt-tests.opam index 09cc99d77331..532accfa4ad1 100644 --- a/opam/tezos-protocol-015-PtLimaPt-tests.opam +++ b/opam/tezos-protocol-015-PtLimaPt-tests.opam @@ -10,20 +10,19 @@ license: "MIT" depends: [ "dune" { >= "3.0" } "ocaml" { >= "4.14" } - "alcotest-lwt" { with-test & >= "1.5.0" } + "tezt" { with-test & >= "3.0.0" } + "tezos-context" {with-test} + "octez-alcotezt" {with-test} "tezos-base" {with-test} + "tezos-client-015-PtLimaPt" {with-test} "tezos-protocol-015-PtLimaPt" {with-test} "tezos-015-PtLimaPt-test-helpers" {with-test} "tezos-base-test-helpers" {with-test} - "tezos-client-015-PtLimaPt" {with-test} + "tezos-protocol-plugin-015-PtLimaPt" {with-test} "tezos-benchmark" {with-test} "tezos-micheline" {with-test} "tezos-benchmark-015-PtLimaPt" {with-test} "tezos-benchmark-type-inference-015-PtLimaPt" {with-test} - "tezos-protocol-plugin-015-PtLimaPt" {with-test} - "tezt" { with-test & >= "3.0.0" } - "tezos-context" {with-test} - "octez-alcotezt" {with-test} "qcheck-alcotest" { with-test & >= "0.20" } "tezos-test-helpers" {with-test} "tezt-tezos" {with-test} diff --git a/opam/tezos-protocol-016-PtMumbai-tests.opam b/opam/tezos-protocol-016-PtMumbai-tests.opam index 0cea964987b6..0e0e4e8ab89c 100644 --- a/opam/tezos-protocol-016-PtMumbai-tests.opam +++ b/opam/tezos-protocol-016-PtMumbai-tests.opam @@ -10,20 +10,19 @@ license: "MIT" depends: [ "dune" { >= "3.0" } "ocaml" { >= "4.14" } - "alcotest-lwt" { with-test & >= "1.5.0" } + "tezt" { with-test & >= "3.0.0" } + "tezos-context" {with-test} + "octez-alcotezt" {with-test} "tezos-base" {with-test} + "tezos-client-016-PtMumbai" {with-test} "tezos-protocol-016-PtMumbai" {with-test} "tezos-016-PtMumbai-test-helpers" {with-test} "tezos-base-test-helpers" {with-test} - "tezos-client-016-PtMumbai" {with-test} + "tezos-protocol-plugin-016-PtMumbai" {with-test} "tezos-benchmark" {with-test} "tezos-micheline" {with-test} "tezos-benchmark-016-PtMumbai" {with-test} "tezos-benchmark-type-inference-016-PtMumbai" {with-test} - "tezos-protocol-plugin-016-PtMumbai" {with-test} - "tezt" { with-test & >= "3.0.0" } - "tezos-context" {with-test} - "octez-alcotezt" {with-test} "qcheck-alcotest" { with-test & >= "0.20" } "tezos-test-helpers" {with-test} "tezos-smart-rollup-016-PtMumbai" {with-test} diff --git a/opam/tezos-protocol-alpha-tests.opam b/opam/tezos-protocol-alpha-tests.opam index bad995203e34..69568ef93f48 100644 --- a/opam/tezos-protocol-alpha-tests.opam +++ b/opam/tezos-protocol-alpha-tests.opam @@ -10,20 +10,19 @@ license: "MIT" depends: [ "dune" { >= "3.0" } "ocaml" { >= "4.14" } - "alcotest-lwt" { with-test & >= "1.5.0" } + "tezt" { with-test & >= "3.0.0" } + "tezos-context" {with-test} + "octez-alcotezt" {with-test} "tezos-base" {with-test} + "tezos-client-alpha" {with-test} "tezos-protocol-alpha" {with-test} "tezos-alpha-test-helpers" {with-test} "tezos-base-test-helpers" {with-test} - "tezos-client-alpha" {with-test} + "tezos-protocol-plugin-alpha" {with-test} "tezos-benchmark" {with-test} "tezos-micheline" {with-test} "tezos-benchmark-alpha" {with-test} "tezos-benchmark-type-inference-alpha" {with-test} - "tezos-protocol-plugin-alpha" {with-test} - "tezt" { with-test & >= "3.0.0" } - "tezos-context" {with-test} - "octez-alcotezt" {with-test} "qcheck-alcotest" { with-test & >= "0.20" } "tezos-test-helpers" {with-test} "tezos-smart-rollup-alpha" {with-test} diff --git a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/dune b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/dune index 07bfd99420e7..1146d236e460 100644 --- a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/dune +++ b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/dune @@ -1,10 +1,13 @@ ; This file was automatically generated, do not edit. ; Edit file manifest/main.ml instead. -(executable - (name main) +(library + (name + src_proto_015_PtLimaPt_lib_protocol_test_integration_michelson_tezt_lib) + (instrumentation (backend bisect_ppx)) (libraries - alcotest-lwt + tezt.core + octez-alcotezt tezos-base tezos-protocol-015-PtLimaPt tezos-015-PtLimaPt-test-helpers @@ -16,11 +19,12 @@ tezos-benchmark-type-inference-015-PtLimaPt tezos-protocol-plugin-015-PtLimaPt tezos-protocol-015-PtLimaPt.parameters) - (link_flags - (:standard) - (:include %{workspace_root}/macos-link-flags.sexp)) + (library_flags (:standard -linkall)) (flags (:standard) + -open Tezt_core + -open Tezt_core.Base + -open Octez_alcotezt -open Tezos_base.TzPervasives -open Tezos_base.TzPervasives.Error_monad.Legacy_monad_globals -open Tezos_protocol_015_PtLimaPt @@ -30,13 +34,50 @@ -open Tezos_micheline -open Tezos_benchmark_015_PtLimaPt -open Tezos_benchmark_type_inference_015_PtLimaPt - -open Tezos_protocol_plugin_015_PtLimaPt)) + -open Tezos_protocol_plugin_015_PtLimaPt) + (modules + test_main + test_annotations + test_block_time_instructions + test_contract_event + test_global_constants_storage + test_interpretation + test_lazy_storage_diff + test_patched_contracts + test_sapling + test_script_cache + test_script_typed_ir_size + test_temp_big_maps + test_ticket_accounting + test_ticket_balance_key + test_ticket_balance + test_ticket_lazy_storage_diff + test_ticket_manager + test_ticket_operations_diff + test_ticket_scanner + test_ticket_storage + test_timelock + test_typechecking)) + +(executable + (name main) + (libraries + src_proto_015_PtLimaPt_lib_protocol_test_integration_michelson_tezt_lib + tezt) + (link_flags + (:standard) + (:include %{workspace_root}/macos-link-flags.sexp)) + (modules main)) (rule - (alias runtest) + (alias runtezt) (package tezos-protocol-015-PtLimaPt-tests) (deps (glob_files contracts/*) (glob_files patched_contracts/*) (glob_files_rec ../../../../../../michelson_test_scripts/*)) (action (run %{dep:./main.exe}))) + +(rule + (targets main.ml) + (action (with-stdout-to %{targets} (echo "let () = Tezt.Test.run ()")))) diff --git a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_contract_event.ml b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_contract_event.ml index 9625e49f354e..16913a0155f4 100644 --- a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_contract_event.ml +++ b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_contract_event.ml @@ -60,10 +60,13 @@ let originate_contract file storage src b = let+ b = Incremental.finalize_block incr in (dst, b) +let path = project_root // Filename.dirname __FILE__ + (** Run emit.tz and assert that both the order of events and data content are correct *) let contract_test () = let* b, src = Context.init1 ~consensus_threshold:0 () in - let* dst, b = originate_contract "contracts/emit.tz" "Unit" src b in + let script = path // "contracts/emit.tz" in + let* dst, b = originate_contract script "Unit" src b in let fee = Test_tez.of_int 10 in let parameters = Script.unit_parameter in let* operation = diff --git a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_interpretation.ml b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_interpretation.ml index c71e5845e8a0..ba0b164024a7 100644 --- a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_interpretation.ml +++ b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_interpretation.ml @@ -367,6 +367,8 @@ let test_store_and_reload path ~init_storage ~entrypoint_str_1 ~param_1 (Expr.to_string real.storage)) ~ko:fail_with_trace +let path = project_root // Filename.dirname __FILE__ + let tests = [ Tztest.tztest "test bad contract error" `Quick test_bad_contract_parameter; @@ -388,20 +390,24 @@ let tests = Tztest.tztest "test lambda_rec instruction" `Quick - (test_contract_success "./contracts/rec_fact.tz" "0" "5" "120"); + (test_contract_success (path // "contracts/rec_fact.tz") "0" "5" "120"); Tztest.tztest "test lambda_rec instruction with apply" `Quick - (test_contract_success "./contracts/rec_fact_apply.tz" "0" "5" "120"); + (test_contract_success + (path // "contracts/rec_fact_apply.tz") + "0" + "5" + "120"); Tztest.tztest "test lambda_rec instruction with an infinite recursion" `Quick - (test_contract_fail "./contracts/omega.tz" "Unit" "Unit"); + (test_contract_fail (path // "contracts/omega.tz") "Unit" "Unit"); Tztest.tztest "test lambda_rec instruction storage" `Quick (test_store_and_reload - "./contracts/rec_fact_store.tz" + (path // "contracts/rec_fact_store.tz") ~init_storage:"Left 0" ~entrypoint_str_1:"gen" ~param_1:"Unit" @@ -420,7 +426,7 @@ let tests = "test lambda_rec instruction storage" `Quick (test_store_and_reload - "./contracts/rec_fact_apply_store.tz" + (path // "contracts/rec_fact_apply_store.tz") ~init_storage:"Left 0" ~entrypoint_str_1:"gen" ~param_1:"Unit" diff --git a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/main.ml b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_main.ml similarity index 58% rename from src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/main.ml rename to src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_main.ml index dd1a9f76fe0f..9aafa0dee0ca 100644 --- a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/main.ml +++ b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_main.ml @@ -34,26 +34,30 @@ let () = Alcotest_lwt.run "protocol > integration > michelson" [ - ("global table of constants", Test_global_constants_storage.tests); - ("interpretation", Test_interpretation.tests); - ("lazy storage diff", Test_lazy_storage_diff.tests); - ("sapling", Test_sapling.tests); - ("script typed ir size", Test_script_typed_ir_size.tests); - ("temp big maps", Test_temp_big_maps.tests); - ("ticket balance key", Test_ticket_balance_key.tests); - ("ticket scanner", Test_ticket_scanner.tests); - ("ticket storage", Test_ticket_storage.tests); - ("ticket lazy storage diff", Test_ticket_lazy_storage_diff.tests); - ("ticket operations diff", Test_ticket_operations_diff.tests); - ("ticket accounting", Test_ticket_accounting.tests); - ("ticket balance", Test_ticket_balance.tests); - ("ticket manager", Test_ticket_manager.tests); - ("timelock", Test_timelock.tests); - ("typechecking", Test_typechecking.tests); - ("script cache", Test_script_cache.tests); - ("block time instructions", Test_block_time_instructions.tests); - ("annotations", Test_annotations.tests); - ("event logging", Test_contract_event.tests); - ("patched contracts", Test_patched_contracts.tests); + ( Protocol.name ^ ": global table of constants", + Test_global_constants_storage.tests ); + (Protocol.name ^ ": interpretation", Test_interpretation.tests); + (Protocol.name ^ ": lazy storage diff", Test_lazy_storage_diff.tests); + (Protocol.name ^ ": sapling", Test_sapling.tests); + (Protocol.name ^ ": script typed ir size", Test_script_typed_ir_size.tests); + (Protocol.name ^ ": temp big maps", Test_temp_big_maps.tests); + (Protocol.name ^ ": ticket balance key", Test_ticket_balance_key.tests); + (Protocol.name ^ ": ticket scanner", Test_ticket_scanner.tests); + (Protocol.name ^ ": ticket storage", Test_ticket_storage.tests); + ( Protocol.name ^ ": ticket lazy storage diff", + Test_ticket_lazy_storage_diff.tests ); + ( Protocol.name ^ ": ticket operations diff", + Test_ticket_operations_diff.tests ); + (Protocol.name ^ ": ticket accounting", Test_ticket_accounting.tests); + (Protocol.name ^ ": ticket balance", Test_ticket_balance.tests); + (Protocol.name ^ ": ticket manager", Test_ticket_manager.tests); + (Protocol.name ^ ": timelock", Test_timelock.tests); + (Protocol.name ^ ": typechecking", Test_typechecking.tests); + (Protocol.name ^ ": script cache", Test_script_cache.tests); + ( Protocol.name ^ ": block time instructions", + Test_block_time_instructions.tests ); + (Protocol.name ^ ": annotations", Test_annotations.tests); + (Protocol.name ^ ": event logging", Test_contract_event.tests); + (Protocol.name ^ ": patched contracts", Test_patched_contracts.tests); ] |> Lwt_main.run diff --git a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_patched_contracts.ml b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_patched_contracts.ml index 8d6916166c85..e11b1a4e927e 100644 --- a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_patched_contracts.ml +++ b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_patched_contracts.ml @@ -80,12 +80,14 @@ module Legacy_patch_test (Patches : LEGACY_SCRIPT_PATCHES) : let open Micheline in map_node (fun _ -> ()) Michelson_v1_primitives.string_of_prim (root m) + let path = project_root // Filename.dirname __FILE__ + let contract_path ?(ext = "patched.tz") hash = Filename.concat "patched_contracts" @@ Format.asprintf "%a.%s" Script_expr_hash.pp hash ext let read_file ?ext hash = - let filename = contract_path ?ext hash in + let filename = path // contract_path ?ext hash in Lwt_io.(with_file ~mode:Input filename read) (* Test that the hashes of the scripts in ./patched_contract/.original.tz @@ -154,7 +156,7 @@ module Legacy_patch_test (Patches : LEGACY_SCRIPT_PATCHES) : current_code; |] ) in - let*! actual_diff = Lwt_process.pread diff_cmd in + let*! actual_diff = Lwt_process.pread ~cwd:path diff_cmd in Alcotest.(check string) "same diff" expected_diff actual_diff ; return () diff --git a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_sapling.ml b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_sapling.ml index be87ed1b2533..467f0b086a6d 100644 --- a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_sapling.ml +++ b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_sapling.ml @@ -593,6 +593,8 @@ module Interpreter_tests = struct let string = "{ " ^ String.concat " ; " transactions ^ " }" in Alpha_context.Script.(lazy_expr (Expr.from_string string)) + let path = project_root // Filename.dirname __FILE__ + (* In this test we use a contract which takes a list of transactions, applies all of them, and assert all of them are correct. It also enforces a 1-to-1 conversion with mutez by asking an amount to shield and asking for a pkh to @@ -604,12 +606,8 @@ module Interpreter_tests = struct let test_shielded_tez () = init () >>=? fun (genesis, baker, src0, src1) -> let memo_size = 8 in - originate_contract_hash - "contracts/sapling_contract.tz" - "{ }" - src0 - genesis - baker + let script = path // "contracts/sapling_contract.tz" in + originate_contract_hash script "{ }" src0 genesis baker >>=? fun (dst, b1, anti_replay) -> let wa = wallet_gen () in let list_transac, total = @@ -774,21 +772,11 @@ module Interpreter_tests = struct (* Originating a contract to get a sapling_state with ID 0, used in the next contract *) >>=? fun (block, baker, src, _) -> - originate_contract_hash - "contracts/sapling_contract.tz" - "{ }" - src - block - baker - >>=? fun _ -> + let script = path // "contracts/sapling_contract.tz" in + originate_contract_hash script "{ }" src block baker >>=? fun _ -> + let script = path // "contracts/sapling_push_sapling_state.tz" in (* Originating the next contract should fail *) - originate_contract_hash - "contracts/sapling_push_sapling_state.tz" - "{ }" - src - block - baker - >>= function + originate_contract_hash script "{ }" src block baker >>= function | Error [ Environment.Ecoproto_error (Script_tc_errors.Ill_typed_contract _); @@ -804,15 +792,11 @@ module Interpreter_tests = struct *) init () (* Originating the contracts *) >>=? fun (block, baker, src, _) -> let memo_size = 8 in + let script = path // "contracts/sapling_use_existing_state.tz" in (* originate_contract "contracts/sapling_contract.tz" "{ }" src block baker >>=? fun (_shielded_pool_contract_address, block, _anti_replay_shielded_pool) -> *) - originate_contract_hash - "contracts/sapling_use_existing_state.tz" - "{ }" - src - block - baker + originate_contract_hash script "{ }" src block baker >>=? fun (existing_state_contract_address, block, anti_replay_2) -> (* we create one shielding transaction and transform it in Micheline to use it as a parameter @@ -861,7 +845,8 @@ module Interpreter_tests = struct let test_transac_and_block () = init () >>=? fun (b, baker, src, _) -> let memo_size = 8 in - originate_contract_hash "contracts/sapling_contract.tz" "{ }" src b baker + let script = path // "contracts/sapling_contract.tz" in + originate_contract_hash script "{ }" src b baker >>=? fun (dst, block_start, anti_replay) -> let {sk; vk} = wallet_gen () in let hex_transac_1 = hex_shield ~memo_size {sk; vk} anti_replay in @@ -999,12 +984,8 @@ module Interpreter_tests = struct is drop). *) let test_drop () = init () >>=? fun (b, baker, src, _) -> - originate_contract_hash - "contracts/sapling_contract_drop.tz" - "Unit" - src - b - baker + let script = path // "contracts/sapling_contract_drop.tz" in + originate_contract_hash script "Unit" src b baker >>=? fun (dst, b, anti_replay) -> let {sk; vk} = wallet_gen () in let list_transac, _total = @@ -1032,12 +1013,8 @@ module Interpreter_tests = struct let test_double () = init () >>=? fun (b, baker, src, _) -> let memo_size = 8 in - originate_contract_hash - "contracts/sapling_contract_double.tz" - "(Pair { } { })" - src - b - baker + let script = path // "contracts/sapling_contract_double.tz" in + originate_contract_hash script "(Pair { } { })" src b baker >>=? fun (dst, b, anti_replay) -> let wa = wallet_gen () in let hex_transac_1 = hex_shield ~memo_size wa anti_replay in @@ -1123,19 +1100,11 @@ module Interpreter_tests = struct let test_state_as_arg () = init () >>=? fun (b, baker, src, _) -> - originate_contract_hash - "contracts/sapling_contract_state_as_arg.tz" - "None" - src - b - baker + let script = path // "contracts/sapling_contract_state_as_arg.tz" in + originate_contract_hash script "None" src b baker >>=? fun (dst, b, anti_replay) -> - originate_contract_hash - "contracts/sapling_contract_send.tz" - "Unit" - src - b - baker + let script = path // "contracts/sapling_contract_send.tz" in + originate_contract_hash script "Unit" src b baker >>=? fun (dst_2, b, anti_replay_2) -> let w = wallet_gen () in let hex_transac_1 = hex_shield ~memo_size:8 w anti_replay in diff --git a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_script_cache.ml b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_script_cache.ml index 70b39739dea4..e7ca8d0aeab9 100644 --- a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_script_cache.ml +++ b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_script_cache.ml @@ -87,6 +87,8 @@ let value_as_int : type a ac. (a, ac) Script_typed_ir.ty -> a -> Script_int.z Script_int.num = fun ty v -> match ty with Int_t -> v | _ -> Stdlib.failwith "value_as_int" +let path = project_root // Filename.dirname __FILE__ + let add_some_contracts k src block baker = ( make_block block @@ fun ctxt -> find ctxt liquidity_baking_contract >>=? fun (ctxt, id, _, _) -> @@ -94,7 +96,8 @@ let add_some_contracts k src block baker = >>=? fun (liquidity_baking_contract_id, block) -> List.fold_left_es (fun (rev_contracts, block) _ -> - originate_contract_hash "contracts/int-store.tz" "31" src block baker + let script = path // "contracts/int-store.tz" in + originate_contract_hash script "31" src block baker >>=? fun (addr, block) -> Block.bake block >>=? fun block -> make_block block @@ fun ctxt -> @@ -141,8 +144,8 @@ let test_size_of_liquidity_baking_contract () = let test_size_of_int_store_contract () = init () >>=? fun (block, baker, src, _) -> - originate_contract_hash "contracts/int-store.tz" "31" src block baker - >>=? fun (addr, block) -> + let script = path // "contracts/int-store.tz" in + originate_contract_hash script "31" src block baker >>=? fun (addr, block) -> ( make_block block @! fun ctxt -> Script_cache.find ctxt addr >|= Environment.wrap_tzresult >>=? fun (ctxt, _, _) -> @@ -158,8 +161,8 @@ let test_size_of_int_store_contract () = *) let test_find_correctly_looks_up () = init () >>=? fun (block, baker, src, _) -> - originate_contract_hash "contracts/sapling_contract.tz" "{ }" src block baker - >>=? fun (addr, block) -> + let script = path // "contracts/sapling_contract.tz" in + originate_contract_hash script "{ }" src block baker >>=? fun (addr, block) -> ( make_block block @! fun ctxt -> (* Contract is present. @@ -197,8 +200,8 @@ let test_find_correctly_looks_up () = *) let test_update_modifies_cached_contract () = init () >>=? fun (block, baker, src, _) -> - originate_contract_hash "contracts/int-store.tz" "36" src block baker - >>=? fun (addr, block) -> + let script = path // "contracts/int-store.tz" in + originate_contract_hash script "36" src block baker >>=? fun (addr, block) -> ( make_block block @! fun ctxt -> find ctxt addr >>=? fun (ctxt, identifier, script, Ex_script (Script ir)) -> match ir.storage_type with diff --git a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_temp_big_maps.ml b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_temp_big_maps.ml index 0df912fd077a..1f47c3605895 100644 --- a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_temp_big_maps.ml +++ b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_temp_big_maps.ml @@ -64,6 +64,8 @@ let call_the_contract b ~baker ~src contract param_left param_right = Incremental.add_operation incr operation >>=? fun incr -> Incremental.finalize_block incr +let path = project_root // Filename.dirname __FILE__ + (** Originates the contract at contracts/temp_big_maps.tz and calls it with the pair [(param_left, param_right)]. An action (originating, storing, passing, passing twice) is done on a big @@ -72,12 +74,8 @@ let call_the_contract b ~baker ~src contract param_left param_right = *) let test_temp_big_maps_contract param_left param_right () = Contract_helpers.init () >>=? fun (b, baker, src, _src2) -> - Contract_helpers.originate_contract - "contracts/temp_big_maps.tz" - "{}" - src - b - baker + let script = path // "contracts/temp_big_maps.tz" in + Contract_helpers.originate_contract script "{}" src b baker >>=? fun (contract, b) -> check_no_dangling_temp_big_map b >>=? fun () -> call_the_contract b ~baker ~src contract param_left param_right >>=? fun b -> diff --git a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_timelock.ml b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_timelock.ml index 76f394e0c16a..84f24245a3d9 100644 --- a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_timelock.ml +++ b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_timelock.ml @@ -65,7 +65,7 @@ let simple_test () = return_unit let timelock_path = - "../../../../../../michelson_test_scripts/ill_typed/timelock.tz" + project_root // "michelson_test_scripts/ill_typed/timelock.tz" let deprecated_chest_open () = (* Verify contract fails origination as OPEN_CHEST is marked as legacy (deprecated )*) diff --git a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_typechecking.ml b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_typechecking.ml index 723b75343c83..a18e580ca491 100644 --- a/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_typechecking.ml +++ b/src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson/test_typechecking.ml @@ -132,6 +132,10 @@ let test_context_with_nat_nat_big_map ?(sc_rollup_enable = false) () = @@ Contract.update_script_storage ctxt originated nat_ty_expr (Some diffs) >>=? fun ctxt -> return (ctxt, id) +let path = + project_root + // "src/proto_015_PtLimaPt/lib_protocol/test/integration/michelson" + let read_file filename = let ch = open_in filename in let s = really_input_string ch (in_channel_length ch) in @@ -144,7 +148,7 @@ let test_typecheck_stack_overflow () = test_context () >>=? fun ctxt -> let storage = "Unit" in let parameter = "Unit" in - let script = read_file "./contracts/big_interpreter_stack.tz" in + let script = read_file (path // "contracts/big_interpreter_stack.tz") in Contract_helpers.run_script ctxt script ~storage ~parameter () >>= function | Ok _ -> Alcotest.fail "expected an error" | Error lst @@ -770,7 +774,7 @@ let test_contract_not_packable () = (* This test function is used to checks forbidden operations in views. *) let test_forbidden_op_in_view op () = - let prefix = "./contracts/forbidden_op_in_view_" in + let prefix = path // "contracts/forbidden_op_in_view_" in let script = read_file (prefix ^ op ^ ".tz") in let contract_expr = Expr.from_string script in test_context () >>=? fun ctxt -> @@ -981,13 +985,13 @@ let tests = Tztest.tztest "test lambda_rec instruction" `Quick - (test_contract_success "./contracts/rec_fact.tz"); + (test_contract_success (path // "contracts/rec_fact.tz")); Tztest.tztest "test lambda_rec instruction with apply" `Quick - (test_contract_success "./contracts/rec_fact_apply.tz"); + (test_contract_success (path // "contracts/rec_fact_apply.tz")); Tztest.tztest "test lambda_rec with type error" `Quick - (test_contract_failure "./contracts/fail_rec.tz"); + (test_contract_failure (path // "contracts/fail_rec.tz")); ] diff --git a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/dune b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/dune index b8d464a6c70b..602e39e96ce2 100644 --- a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/dune +++ b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/dune @@ -1,10 +1,13 @@ ; This file was automatically generated, do not edit. ; Edit file manifest/main.ml instead. -(executable - (name main) +(library + (name + src_proto_016_PtMumbai_lib_protocol_test_integration_michelson_tezt_lib) + (instrumentation (backend bisect_ppx)) (libraries - alcotest-lwt + tezt.core + octez-alcotezt tezos-base tezos-protocol-016-PtMumbai tezos-016-PtMumbai-test-helpers @@ -16,11 +19,12 @@ tezos-benchmark-type-inference-016-PtMumbai tezos-protocol-plugin-016-PtMumbai tezos-protocol-016-PtMumbai.parameters) - (link_flags - (:standard) - (:include %{workspace_root}/macos-link-flags.sexp)) + (library_flags (:standard -linkall)) (flags (:standard) + -open Tezt_core + -open Tezt_core.Base + -open Octez_alcotezt -open Tezos_base.TzPervasives -open Tezos_base.TzPervasives.Error_monad.Legacy_monad_globals -open Tezos_protocol_016_PtMumbai @@ -30,13 +34,51 @@ -open Tezos_micheline -open Tezos_benchmark_016_PtMumbai -open Tezos_benchmark_type_inference_016_PtMumbai - -open Tezos_protocol_plugin_016_PtMumbai)) + -open Tezos_protocol_plugin_016_PtMumbai) + (modules + test_main + test_annotations + test_block_time_instructions + test_contract_event + test_global_constants_storage + test_interpretation + test_lazy_storage_diff + test_patched_contracts + test_sapling + test_script_cache + test_script_typed_ir_size + test_temp_big_maps + test_ticket_accounting + test_ticket_balance_key + test_ticket_balance + test_ticket_lazy_storage_diff + test_ticket_manager + test_ticket_operations_diff + test_ticket_scanner + test_ticket_storage + test_timelock + test_typechecking + test_lambda_normalization)) + +(executable + (name main) + (libraries + src_proto_016_PtMumbai_lib_protocol_test_integration_michelson_tezt_lib + tezt) + (link_flags + (:standard) + (:include %{workspace_root}/macos-link-flags.sexp)) + (modules main)) (rule - (alias runtest) + (alias runtezt) (package tezos-protocol-016-PtMumbai-tests) (deps (glob_files contracts/*) (glob_files patched_contracts/*) (glob_files_rec ../../../../../../michelson_test_scripts/*)) (action (run %{dep:./main.exe}))) + +(rule + (targets main.ml) + (action (with-stdout-to %{targets} (echo "let () = Tezt.Test.run ()")))) diff --git a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_contract_event.ml b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_contract_event.ml index 9625e49f354e..305d11d16360 100644 --- a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_contract_event.ml +++ b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_contract_event.ml @@ -60,10 +60,12 @@ let originate_contract file storage src b = let+ b = Incremental.finalize_block incr in (dst, b) +let path = project_root // Filename.dirname __FILE__ + (** Run emit.tz and assert that both the order of events and data content are correct *) let contract_test () = let* b, src = Context.init1 ~consensus_threshold:0 () in - let* dst, b = originate_contract "contracts/emit.tz" "Unit" src b in + let* dst, b = originate_contract (path // "contracts/emit.tz") "Unit" src b in let fee = Test_tez.of_int 10 in let parameters = Script.unit_parameter in let* operation = diff --git a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_interpretation.ml b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_interpretation.ml index ebb8358c3f49..09fba97fdcb2 100644 --- a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_interpretation.ml +++ b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_interpretation.ml @@ -371,6 +371,8 @@ let test_store_and_reload path ~init_storage ~entrypoint_str_1 ~param_1 (Expr.to_string real.storage)) ~ko:fail_with_trace +let path = project_root // Filename.dirname __FILE__ + let tests = [ Tztest.tztest "test bad contract error" `Quick test_bad_contract_parameter; @@ -392,20 +394,24 @@ let tests = Tztest.tztest "test lambda_rec instruction" `Quick - (test_contract_success "./contracts/rec_fact.tz" "0" "5" "120"); + (test_contract_success (path // "contracts/rec_fact.tz") "0" "5" "120"); Tztest.tztest "test lambda_rec instruction with apply" `Quick - (test_contract_success "./contracts/rec_fact_apply.tz" "0" "5" "120"); + (test_contract_success + (path // "contracts/rec_fact_apply.tz") + "0" + "5" + "120"); Tztest.tztest "test lambda_rec instruction with an infinite recursion" `Quick - (test_contract_fail "./contracts/omega.tz" "Unit" "Unit"); + (test_contract_fail (path // "contracts/omega.tz") "Unit" "Unit"); Tztest.tztest "test lambda_rec instruction storage" `Quick (test_store_and_reload - "./contracts/rec_fact_store.tz" + (path // "contracts/rec_fact_store.tz") ~init_storage:"Left 0" ~entrypoint_str_1:"gen" ~param_1:"Unit" @@ -424,7 +430,7 @@ let tests = "test lambda_rec instruction storage" `Quick (test_store_and_reload - "./contracts/rec_fact_apply_store.tz" + (path // "contracts/rec_fact_apply_store.tz") ~init_storage:"Left 0" ~entrypoint_str_1:"gen" ~param_1:"Unit" diff --git a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/main.ml b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_main.ml similarity index 57% rename from src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/main.ml rename to src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_main.ml index f93799c4d484..4a99ecee3560 100644 --- a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/main.ml +++ b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_main.ml @@ -34,27 +34,31 @@ let () = Alcotest_lwt.run "protocol > integration > michelson" [ - ("global table of constants", Test_global_constants_storage.tests); - ("interpretation", Test_interpretation.tests); - ("lazy storage diff", Test_lazy_storage_diff.tests); - ("sapling", Test_sapling.tests); - ("script typed ir size", Test_script_typed_ir_size.tests); - ("temp big maps", Test_temp_big_maps.tests); - ("ticket balance key", Test_ticket_balance_key.tests); - ("ticket scanner", Test_ticket_scanner.tests); - ("ticket storage", Test_ticket_storage.tests); - ("ticket lazy storage diff", Test_ticket_lazy_storage_diff.tests); - ("ticket operations diff", Test_ticket_operations_diff.tests); - ("ticket accounting", Test_ticket_accounting.tests); - ("ticket balance", Test_ticket_balance.tests); - ("ticket manager", Test_ticket_manager.tests); - ("timelock", Test_timelock.tests); - ("typechecking", Test_typechecking.tests); - ("script cache", Test_script_cache.tests); - ("block time instructions", Test_block_time_instructions.tests); - ("annotations", Test_annotations.tests); - ("event logging", Test_contract_event.tests); - ("patched contracts", Test_patched_contracts.tests); - ("lambda normalization", Test_lambda_normalization.tests); + ( Protocol.name ^ ": global table of constants", + Test_global_constants_storage.tests ); + (Protocol.name ^ ": interpretation", Test_interpretation.tests); + (Protocol.name ^ ": lazy storage diff", Test_lazy_storage_diff.tests); + (Protocol.name ^ ": sapling", Test_sapling.tests); + (Protocol.name ^ ": script typed ir size", Test_script_typed_ir_size.tests); + (Protocol.name ^ ": temp big maps", Test_temp_big_maps.tests); + (Protocol.name ^ ": ticket balance key", Test_ticket_balance_key.tests); + (Protocol.name ^ ": ticket scanner", Test_ticket_scanner.tests); + (Protocol.name ^ ": ticket storage", Test_ticket_storage.tests); + ( Protocol.name ^ ": ticket lazy storage diff", + Test_ticket_lazy_storage_diff.tests ); + ( Protocol.name ^ ": ticket operations diff", + Test_ticket_operations_diff.tests ); + (Protocol.name ^ ": ticket accounting", Test_ticket_accounting.tests); + (Protocol.name ^ ": ticket balance", Test_ticket_balance.tests); + (Protocol.name ^ ": ticket manager", Test_ticket_manager.tests); + (Protocol.name ^ ": timelock", Test_timelock.tests); + (Protocol.name ^ ": typechecking", Test_typechecking.tests); + (Protocol.name ^ ": script cache", Test_script_cache.tests); + ( Protocol.name ^ ": block time instructions", + Test_block_time_instructions.tests ); + (Protocol.name ^ ": annotations", Test_annotations.tests); + (Protocol.name ^ ": event logging", Test_contract_event.tests); + (Protocol.name ^ ": patched contracts", Test_patched_contracts.tests); + (Protocol.name ^ ": lambda normalization", Test_lambda_normalization.tests); ] |> Lwt_main.run diff --git a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_patched_contracts.ml b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_patched_contracts.ml index d5f13a418b5c..dae507c20618 100644 --- a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_patched_contracts.ml +++ b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_patched_contracts.ml @@ -80,12 +80,14 @@ module Legacy_patch_test (Patches : LEGACY_SCRIPT_PATCHES) : let open Micheline in map_node (fun _ -> ()) Michelson_v1_primitives.string_of_prim (root m) + let path = project_root // Filename.dirname __FILE__ + let contract_path ?(ext = "patched.tz") hash = Filename.concat "patched_contracts" @@ Format.asprintf "%a.%s" Script_expr_hash.pp hash ext let read_file ?ext hash = - let filename = contract_path ?ext hash in + let filename = path // contract_path ?ext hash in Lwt_io.(with_file ~mode:Input filename read) (* Test that the hashes of the scripts in ./patched_contract/.original.tz @@ -154,7 +156,7 @@ module Legacy_patch_test (Patches : LEGACY_SCRIPT_PATCHES) : current_code; |] ) in - let*! actual_diff = Lwt_process.pread diff_cmd in + let*! actual_diff = Lwt_process.pread ~cwd:path diff_cmd in Alcotest.(check string) "same diff" expected_diff actual_diff ; return () diff --git a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_sapling.ml b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_sapling.ml index d17de0ab45cf..08f4dfe877e8 100644 --- a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_sapling.ml +++ b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_sapling.ml @@ -593,6 +593,8 @@ module Interpreter_tests = struct let string = "{ " ^ String.concat " ; " transactions ^ " }" in Alpha_context.Script.(lazy_expr (Expr.from_string string)) + let path = project_root // Filename.dirname __FILE__ + (* In this test we use a contract which takes a list of transactions, applies all of them, and assert all of them are correct. It also enforces a 1-to-1 conversion with mutez by asking an amount to shield and asking for a pkh to @@ -604,12 +606,8 @@ module Interpreter_tests = struct let test_shielded_tez () = init () >>=? fun (genesis, baker, src0, src1) -> let memo_size = 8 in - originate_contract_hash - "contracts/sapling_contract.tz" - "{ }" - src0 - genesis - baker + let script = path // "contracts/sapling_contract.tz" in + originate_contract_hash script "{ }" src0 genesis baker >>=? fun (dst, b1, anti_replay) -> let wa = wallet_gen () in let list_transac, total = @@ -774,21 +772,11 @@ module Interpreter_tests = struct (* Originating a contract to get a sapling_state with ID 0, used in the next contract *) >>=? fun (block, baker, src, _) -> - originate_contract_hash - "contracts/sapling_contract.tz" - "{ }" - src - block - baker - >>=? fun (_, _, _) -> + let script = path // "contracts/sapling_contract.tz" in + originate_contract_hash script "{ }" src block baker >>=? fun (_, _, _) -> + let script = path // "contracts/sapling_push_sapling_state.tz" in (* Originating the next contract should fail *) - originate_contract_hash - "contracts/sapling_push_sapling_state.tz" - "{ }" - src - block - baker - >>= function + originate_contract_hash script "{ }" src block baker >>= function | Error [ Environment.Ecoproto_error (Script_tc_errors.Ill_typed_contract _); @@ -804,15 +792,11 @@ module Interpreter_tests = struct *) init () (* Originating the contracts *) >>=? fun (block, baker, src, _) -> let memo_size = 8 in + let script = path // "contracts/sapling_use_existing_state.tz" in (* originate_contract "contracts/sapling_contract.tz" "{ }" src block baker >>=? fun (_shielded_pool_contract_address, block, _anti_replay_shielded_pool) -> *) - originate_contract_hash - "contracts/sapling_use_existing_state.tz" - "{ }" - src - block - baker + originate_contract_hash script "{ }" src block baker >>=? fun (existing_state_contract_address, block, anti_replay_2) -> (* we create one shielding transaction and transform it in Micheline to use it as a parameter @@ -861,7 +845,8 @@ module Interpreter_tests = struct let test_transac_and_block () = init () >>=? fun (b, baker, src, _) -> let memo_size = 8 in - originate_contract_hash "contracts/sapling_contract.tz" "{ }" src b baker + let script = path // "contracts/sapling_contract.tz" in + originate_contract_hash script "{ }" src b baker >>=? fun (dst, block_start, anti_replay) -> let {sk; vk} = wallet_gen () in let hex_transac_1 = hex_shield ~memo_size {sk; vk} anti_replay in @@ -999,12 +984,8 @@ module Interpreter_tests = struct is drop). *) let test_drop () = init () >>=? fun (b, baker, src, _) -> - originate_contract_hash - "contracts/sapling_contract_drop.tz" - "Unit" - src - b - baker + let script = path // "contracts/sapling_contract_drop.tz" in + originate_contract_hash script "Unit" src b baker >>=? fun (dst, b, anti_replay) -> let {sk; vk} = wallet_gen () in let list_transac, _total = @@ -1032,12 +1013,8 @@ module Interpreter_tests = struct let test_double () = init () >>=? fun (b, baker, src, _) -> let memo_size = 8 in - originate_contract_hash - "contracts/sapling_contract_double.tz" - "(Pair { } { })" - src - b - baker + let script = path // "contracts/sapling_contract_double.tz" in + originate_contract_hash script "(Pair { } { })" src b baker >>=? fun (dst, b, anti_replay) -> let wa = wallet_gen () in let hex_transac_1 = hex_shield ~memo_size wa anti_replay in @@ -1123,19 +1100,11 @@ module Interpreter_tests = struct let test_state_as_arg () = init () >>=? fun (b, baker, src, _) -> - originate_contract_hash - "contracts/sapling_contract_state_as_arg.tz" - "None" - src - b - baker + let script = path // "contracts/sapling_contract_state_as_arg.tz" in + originate_contract_hash script "None" src b baker >>=? fun (dst, b, anti_replay) -> - originate_contract_hash - "contracts/sapling_contract_send.tz" - "Unit" - src - b - baker + let script = path // "contracts/sapling_contract_send.tz" in + originate_contract_hash script "Unit" src b baker >>=? fun (dst_2, b, anti_replay_2) -> let w = wallet_gen () in let hex_transac_1 = hex_shield ~memo_size:8 w anti_replay in diff --git a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_script_cache.ml b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_script_cache.ml index d6797f5bf7fc..9351c3a8274f 100644 --- a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_script_cache.ml +++ b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_script_cache.ml @@ -87,6 +87,8 @@ let value_as_int : type a ac. (a, ac) Script_typed_ir.ty -> a -> Script_int.z Script_int.num = fun ty v -> match ty with Int_t -> v | _ -> Stdlib.failwith "value_as_int" +let path = project_root // Filename.dirname __FILE__ + let add_some_contracts k src block baker = ( make_block block @@ fun ctxt -> find ctxt liquidity_baking_contract >>=? fun (ctxt, id, _, _) -> @@ -94,7 +96,8 @@ let add_some_contracts k src block baker = >>=? fun (liquidity_baking_contract_id, block) -> List.fold_left_es (fun (rev_contracts, block) _ -> - originate_contract_hash "contracts/int-store.tz" "31" src block baker + let script = path // "contracts/int-store.tz" in + originate_contract_hash script "31" src block baker >>=? fun (addr, block) -> Block.bake block >>=? fun block -> make_block block @@ fun ctxt -> @@ -141,8 +144,8 @@ let test_size_of_liquidity_baking_contract () = let test_size_of_int_store_contract () = init () >>=? fun (block, baker, src, _) -> - originate_contract_hash "contracts/int-store.tz" "31" src block baker - >>=? fun (addr, block) -> + let script = path // "contracts/int-store.tz" in + originate_contract_hash script "31" src block baker >>=? fun (addr, block) -> ( make_block block @! fun ctxt -> Script_cache.find ctxt addr >|= Environment.wrap_tzresult >>=? fun (ctxt, _, _) -> @@ -158,8 +161,8 @@ let test_size_of_int_store_contract () = *) let test_find_correctly_looks_up () = init () >>=? fun (block, baker, src, _) -> - originate_contract_hash "contracts/sapling_contract.tz" "{ }" src block baker - >>=? fun (addr, block) -> + let script = path // "contracts/sapling_contract.tz" in + originate_contract_hash script "{ }" src block baker >>=? fun (addr, block) -> ( make_block block @! fun ctxt -> (* Contract is present. @@ -197,8 +200,8 @@ let test_find_correctly_looks_up () = *) let test_update_modifies_cached_contract () = init () >>=? fun (block, baker, src, _) -> - originate_contract_hash "contracts/int-store.tz" "36" src block baker - >>=? fun (addr, block) -> + let script = path // "contracts/int-store.tz" in + originate_contract_hash script "36" src block baker >>=? fun (addr, block) -> ( make_block block @! fun ctxt -> find ctxt addr >>=? fun (ctxt, identifier, script, Ex_script (Script ir)) -> match ir.storage_type with diff --git a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_temp_big_maps.ml b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_temp_big_maps.ml index 0df912fd077a..1f47c3605895 100644 --- a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_temp_big_maps.ml +++ b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_temp_big_maps.ml @@ -64,6 +64,8 @@ let call_the_contract b ~baker ~src contract param_left param_right = Incremental.add_operation incr operation >>=? fun incr -> Incremental.finalize_block incr +let path = project_root // Filename.dirname __FILE__ + (** Originates the contract at contracts/temp_big_maps.tz and calls it with the pair [(param_left, param_right)]. An action (originating, storing, passing, passing twice) is done on a big @@ -72,12 +74,8 @@ let call_the_contract b ~baker ~src contract param_left param_right = *) let test_temp_big_maps_contract param_left param_right () = Contract_helpers.init () >>=? fun (b, baker, src, _src2) -> - Contract_helpers.originate_contract - "contracts/temp_big_maps.tz" - "{}" - src - b - baker + let script = path // "contracts/temp_big_maps.tz" in + Contract_helpers.originate_contract script "{}" src b baker >>=? fun (contract, b) -> check_no_dangling_temp_big_map b >>=? fun () -> call_the_contract b ~baker ~src contract param_left param_right >>=? fun b -> diff --git a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_timelock.ml b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_timelock.ml index 4d61fcdbd941..ef1d36206746 100644 --- a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_timelock.ml +++ b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_timelock.ml @@ -65,7 +65,7 @@ let simple_test () = return_unit let timelock_path = - "../../../../../../michelson_test_scripts/ill_typed/timelock.tz" + project_root // "michelson_test_scripts/ill_typed/timelock.tz" let deprecated_chest_open () = (* Verify contract fails origination as OPEN_CHEST is marked as legacy (deprecated )*) diff --git a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_typechecking.ml b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_typechecking.ml index 1ed6240ac354..526b56ca4156 100644 --- a/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_typechecking.ml +++ b/src/proto_016_PtMumbai/lib_protocol/test/integration/michelson/test_typechecking.ml @@ -143,13 +143,15 @@ let read_file filename = close_in ch ; s +let path = project_root // Filename.dirname __FILE__ + (** Check that the custom stack overflow exception is triggered when it should be. *) let test_typecheck_stack_overflow () = test_context () >>=? fun ctxt -> let storage = "Unit" in let parameter = "Unit" in - let script = read_file "./contracts/big_interpreter_stack.tz" in + let script = read_file (path // "contracts/big_interpreter_stack.tz") in Contract_helpers.run_script ctxt script ~storage ~parameter () >>= function | Ok _ -> Alcotest.fail "expected an error" | Error lst @@ -775,7 +777,7 @@ let test_contract_not_packable () = (* This test function is used to checks forbidden operations in views. *) let test_forbidden_op_in_view op () = - let prefix = "./contracts/forbidden_op_in_view_" in + let prefix = path // "contracts/forbidden_op_in_view_" in let script = read_file (prefix ^ op ^ ".tz") in let contract_expr = Expr.from_string script in test_context () >>=? fun ctxt -> @@ -923,13 +925,13 @@ let tests = Tztest.tztest "test lambda_rec instruction" `Quick - (test_contract_success "./contracts/rec_fact.tz"); + (test_contract_success (path // "contracts/rec_fact.tz")); Tztest.tztest "test lambda_rec instruction with apply" `Quick - (test_contract_success "./contracts/rec_fact_apply.tz"); + (test_contract_success (path // "contracts/rec_fact_apply.tz")); Tztest.tztest "test lambda_rec with type error" `Quick - (test_contract_failure "./contracts/fail_rec.tz"); + (test_contract_failure (path // "contracts/fail_rec.tz")); ] diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/dune b/src/proto_alpha/lib_protocol/test/integration/michelson/dune index a724d96f524e..d457b1058169 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/dune +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/dune @@ -1,10 +1,12 @@ ; This file was automatically generated, do not edit. ; Edit file manifest/main.ml instead. -(executable - (name main) +(library + (name src_proto_alpha_lib_protocol_test_integration_michelson_tezt_lib) + (instrumentation (backend bisect_ppx)) (libraries - alcotest-lwt + tezt.core + octez-alcotezt tezos-base tezos-protocol-alpha tezos-alpha-test-helpers @@ -16,11 +18,12 @@ tezos-benchmark-type-inference-alpha tezos-protocol-plugin-alpha tezos-protocol-alpha.parameters) - (link_flags - (:standard) - (:include %{workspace_root}/macos-link-flags.sexp)) + (library_flags (:standard -linkall)) (flags (:standard) + -open Tezt_core + -open Tezt_core.Base + -open Octez_alcotezt -open Tezos_base.TzPervasives -open Tezos_base.TzPervasives.Error_monad.Legacy_monad_globals -open Tezos_protocol_alpha @@ -30,13 +33,51 @@ -open Tezos_micheline -open Tezos_benchmark_alpha -open Tezos_benchmark_type_inference_alpha - -open Tezos_protocol_plugin_alpha)) + -open Tezos_protocol_plugin_alpha) + (modules + test_main + test_annotations + test_block_time_instructions + test_contract_event + test_global_constants_storage + test_interpretation + test_lazy_storage_diff + test_patched_contracts + test_sapling + test_script_cache + test_script_typed_ir_size + test_temp_big_maps + test_ticket_accounting + test_ticket_balance_key + test_ticket_balance + test_ticket_lazy_storage_diff + test_ticket_manager + test_ticket_operations_diff + test_ticket_scanner + test_ticket_storage + test_timelock + test_typechecking + test_lambda_normalization)) + +(executable + (name main) + (libraries + src_proto_alpha_lib_protocol_test_integration_michelson_tezt_lib + tezt) + (link_flags + (:standard) + (:include %{workspace_root}/macos-link-flags.sexp)) + (modules main)) (rule - (alias runtest) + (alias runtezt) (package tezos-protocol-alpha-tests) (deps (glob_files contracts/*) (glob_files patched_contracts/*) (glob_files_rec ../../../../../../michelson_test_scripts/*)) (action (run %{dep:./main.exe}))) + +(rule + (targets main.ml) + (action (with-stdout-to %{targets} (echo "let () = Tezt.Test.run ()")))) diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_contract_event.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_contract_event.ml index bd1fa4cb7d12..39ac884df84a 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_contract_event.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_contract_event.ml @@ -58,11 +58,13 @@ let originate_contract file storage src b = let+ b = Incremental.finalize_block incr in (dst, b) +let path = project_root // Filename.dirname __FILE__ + (** Run emit.tz and assert that both the order of events and data content are correct *) let contract_test () = let open Lwt_result_syntax in let* b, src = Context.init1 ~consensus_threshold:0 () in - let* dst, b = originate_contract "contracts/emit.tz" "Unit" src b in + let* dst, b = originate_contract (path // "contracts/emit.tz") "Unit" src b in let fee = Test_tez.of_int 10 in let parameters = Script.unit_parameter in let* operation = diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_interpretation.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_interpretation.ml index 7db1844941ec..4f1083365733 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_interpretation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_interpretation.ml @@ -368,6 +368,8 @@ let test_store_and_reload path ~init_storage ~entrypoint_str_1 ~param_1 (Expr.to_string real.storage)) ~ko:fail_with_trace +let path = project_root // Filename.dirname __FILE__ + let tests = [ Tztest.tztest "test bad contract error" `Quick test_bad_contract_parameter; @@ -389,20 +391,24 @@ let tests = Tztest.tztest "test lambda_rec instruction" `Quick - (test_contract_success "./contracts/rec_fact.tz" "0" "5" "120"); + (test_contract_success (path // "contracts/rec_fact.tz") "0" "5" "120"); Tztest.tztest "test lambda_rec instruction with apply" `Quick - (test_contract_success "./contracts/rec_fact_apply.tz" "0" "5" "120"); + (test_contract_success + (path // "contracts/rec_fact_apply.tz") + "0" + "5" + "120"); Tztest.tztest "test lambda_rec instruction with an infinite recursion" `Quick - (test_contract_fail "./contracts/omega.tz" "Unit" "Unit"); + (test_contract_fail (path // "contracts/omega.tz") "Unit" "Unit"); Tztest.tztest "test lambda_rec instruction storage" `Quick (test_store_and_reload - "./contracts/rec_fact_store.tz" + (path // "contracts/rec_fact_store.tz") ~init_storage:"Left 0" ~entrypoint_str_1:"gen" ~param_1:"Unit" @@ -421,7 +427,7 @@ let tests = "test lambda_rec instruction storage" `Quick (test_store_and_reload - "./contracts/rec_fact_apply_store.tz" + (path // "contracts/rec_fact_apply_store.tz") ~init_storage:"Left 0" ~entrypoint_str_1:"gen" ~param_1:"Unit" diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/main.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_main.ml similarity index 57% rename from src/proto_alpha/lib_protocol/test/integration/michelson/main.ml rename to src/proto_alpha/lib_protocol/test/integration/michelson/test_main.ml index f93799c4d484..4a99ecee3560 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/main.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_main.ml @@ -34,27 +34,31 @@ let () = Alcotest_lwt.run "protocol > integration > michelson" [ - ("global table of constants", Test_global_constants_storage.tests); - ("interpretation", Test_interpretation.tests); - ("lazy storage diff", Test_lazy_storage_diff.tests); - ("sapling", Test_sapling.tests); - ("script typed ir size", Test_script_typed_ir_size.tests); - ("temp big maps", Test_temp_big_maps.tests); - ("ticket balance key", Test_ticket_balance_key.tests); - ("ticket scanner", Test_ticket_scanner.tests); - ("ticket storage", Test_ticket_storage.tests); - ("ticket lazy storage diff", Test_ticket_lazy_storage_diff.tests); - ("ticket operations diff", Test_ticket_operations_diff.tests); - ("ticket accounting", Test_ticket_accounting.tests); - ("ticket balance", Test_ticket_balance.tests); - ("ticket manager", Test_ticket_manager.tests); - ("timelock", Test_timelock.tests); - ("typechecking", Test_typechecking.tests); - ("script cache", Test_script_cache.tests); - ("block time instructions", Test_block_time_instructions.tests); - ("annotations", Test_annotations.tests); - ("event logging", Test_contract_event.tests); - ("patched contracts", Test_patched_contracts.tests); - ("lambda normalization", Test_lambda_normalization.tests); + ( Protocol.name ^ ": global table of constants", + Test_global_constants_storage.tests ); + (Protocol.name ^ ": interpretation", Test_interpretation.tests); + (Protocol.name ^ ": lazy storage diff", Test_lazy_storage_diff.tests); + (Protocol.name ^ ": sapling", Test_sapling.tests); + (Protocol.name ^ ": script typed ir size", Test_script_typed_ir_size.tests); + (Protocol.name ^ ": temp big maps", Test_temp_big_maps.tests); + (Protocol.name ^ ": ticket balance key", Test_ticket_balance_key.tests); + (Protocol.name ^ ": ticket scanner", Test_ticket_scanner.tests); + (Protocol.name ^ ": ticket storage", Test_ticket_storage.tests); + ( Protocol.name ^ ": ticket lazy storage diff", + Test_ticket_lazy_storage_diff.tests ); + ( Protocol.name ^ ": ticket operations diff", + Test_ticket_operations_diff.tests ); + (Protocol.name ^ ": ticket accounting", Test_ticket_accounting.tests); + (Protocol.name ^ ": ticket balance", Test_ticket_balance.tests); + (Protocol.name ^ ": ticket manager", Test_ticket_manager.tests); + (Protocol.name ^ ": timelock", Test_timelock.tests); + (Protocol.name ^ ": typechecking", Test_typechecking.tests); + (Protocol.name ^ ": script cache", Test_script_cache.tests); + ( Protocol.name ^ ": block time instructions", + Test_block_time_instructions.tests ); + (Protocol.name ^ ": annotations", Test_annotations.tests); + (Protocol.name ^ ": event logging", Test_contract_event.tests); + (Protocol.name ^ ": patched contracts", Test_patched_contracts.tests); + (Protocol.name ^ ": lambda normalization", Test_lambda_normalization.tests); ] |> Lwt_main.run diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_patched_contracts.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_patched_contracts.ml index 8bdaf8876ad3..eb6873547f4f 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_patched_contracts.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_patched_contracts.ml @@ -78,12 +78,14 @@ module Legacy_patch_test (Patches : LEGACY_SCRIPT_PATCHES) : let open Micheline in map_node (fun _ -> ()) Michelson_v1_primitives.string_of_prim (root m) + let path = project_root // Filename.dirname __FILE__ + let contract_path ?(ext = "patched.tz") hash = Filename.concat "patched_contracts" @@ Format.asprintf "%a.%s" Script_expr_hash.pp hash ext let read_file ?ext hash = - let filename = contract_path ?ext hash in + let filename = path // contract_path ?ext hash in Lwt_io.(with_file ~mode:Input filename read) (* Test that the hashes of the scripts in ./patched_contract/.original.tz @@ -155,7 +157,7 @@ module Legacy_patch_test (Patches : LEGACY_SCRIPT_PATCHES) : current_code; |] ) in - let*! actual_diff = Lwt_process.pread diff_cmd in + let*! actual_diff = Lwt_process.pread ~cwd:path diff_cmd in Alcotest.(check string) "same diff" expected_diff actual_diff ; return () diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_sapling.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_sapling.ml index a07a2e425536..c7a3199df51d 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_sapling.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_sapling.ml @@ -593,6 +593,8 @@ module Interpreter_tests = struct let string = "{ " ^ String.concat " ; " transactions ^ " }" in Alpha_context.Script.(lazy_expr (Expr.from_string string)) + let path = project_root // Filename.dirname __FILE__ + (* In this test we use a contract which takes a list of transactions, applies all of them, and assert all of them are correct. It also enforces a 1-to-1 conversion with mutez by asking an amount to shield and asking for a pkh to @@ -605,7 +607,7 @@ module Interpreter_tests = struct init () >>=? fun (genesis, baker, src0, src1) -> let memo_size = 8 in originate_contract_hash - "contracts/sapling_contract.tz" + (path // "contracts/sapling_contract.tz") "{ }" src0 genesis @@ -775,7 +777,7 @@ module Interpreter_tests = struct >>=? fun (block, baker, src, _) -> originate_contract_hash - "contracts/sapling_contract.tz" + (path // "contracts/sapling_contract.tz") "{ }" src block @@ -783,7 +785,7 @@ module Interpreter_tests = struct >>=? fun (_, _, _) -> (* Originating the next contract should fail *) originate_contract_hash - "contracts/sapling_push_sapling_state.tz" + (path // "contracts/sapling_push_sapling_state.tz") "{ }" src block @@ -808,7 +810,7 @@ module Interpreter_tests = struct >>=? fun (_shielded_pool_contract_address, block, _anti_replay_shielded_pool) -> *) originate_contract_hash - "contracts/sapling_use_existing_state.tz" + (path // "contracts/sapling_use_existing_state.tz") "{ }" src block @@ -861,7 +863,12 @@ module Interpreter_tests = struct let test_transac_and_block () = init () >>=? fun (b, baker, src, _) -> let memo_size = 8 in - originate_contract_hash "contracts/sapling_contract.tz" "{ }" src b baker + originate_contract_hash + (path // "contracts/sapling_contract.tz") + "{ }" + src + b + baker >>=? fun (dst, block_start, anti_replay) -> let {sk; vk} = wallet_gen () in let hex_transac_1 = hex_shield ~memo_size {sk; vk} anti_replay in @@ -1000,7 +1007,7 @@ module Interpreter_tests = struct let test_drop () = init () >>=? fun (b, baker, src, _) -> originate_contract_hash - "contracts/sapling_contract_drop.tz" + (path // "contracts/sapling_contract_drop.tz") "Unit" src b @@ -1033,7 +1040,7 @@ module Interpreter_tests = struct init () >>=? fun (b, baker, src, _) -> let memo_size = 8 in originate_contract_hash - "contracts/sapling_contract_double.tz" + (path // "contracts/sapling_contract_double.tz") "(Pair { } { })" src b @@ -1124,14 +1131,14 @@ module Interpreter_tests = struct let test_state_as_arg () = init () >>=? fun (b, baker, src, _) -> originate_contract_hash - "contracts/sapling_contract_state_as_arg.tz" + (path // "contracts/sapling_contract_state_as_arg.tz") "None" src b baker >>=? fun (dst, b, anti_replay) -> originate_contract_hash - "contracts/sapling_contract_send.tz" + (path // "contracts/sapling_contract_send.tz") "Unit" src b diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml index 72e866595f0b..f0c97f413bff 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml @@ -87,6 +87,8 @@ let value_as_int : type a ac. (a, ac) Script_typed_ir.ty -> a -> Script_int.z Script_int.num = fun ty v -> match ty with Int_t -> v | _ -> Stdlib.failwith "value_as_int" +let path = project_root // Filename.dirname __FILE__ + let add_some_contracts k src block baker = ( make_block block @@ fun ctxt -> find ctxt liquidity_baking_contract >>=? fun (ctxt, id, _, _) -> @@ -94,7 +96,12 @@ let add_some_contracts k src block baker = >>=? fun (liquidity_baking_contract_id, block) -> List.fold_left_es (fun (rev_contracts, block) _ -> - originate_contract_hash "contracts/int-store.tz" "31" src block baker + originate_contract_hash + (path // "contracts/int-store.tz") + "31" + src + block + baker >>=? fun (addr, block) -> Block.bake block >>=? fun block -> make_block block @@ fun ctxt -> @@ -141,7 +148,12 @@ let test_size_of_liquidity_baking_contract () = let test_size_of_int_store_contract () = init () >>=? fun (block, baker, src, _) -> - originate_contract_hash "contracts/int-store.tz" "31" src block baker + originate_contract_hash + (path // "contracts/int-store.tz") + "31" + src + block + baker >>=? fun (addr, block) -> ( make_block block @! fun ctxt -> Script_cache.find ctxt addr >|= Environment.wrap_tzresult @@ -158,7 +170,12 @@ let test_size_of_int_store_contract () = *) let test_find_correctly_looks_up () = init () >>=? fun (block, baker, src, _) -> - originate_contract_hash "contracts/sapling_contract.tz" "{ }" src block baker + originate_contract_hash + (path // "contracts/sapling_contract.tz") + "{ }" + src + block + baker >>=? fun (addr, block) -> ( make_block block @! fun ctxt -> (* @@ -197,7 +214,12 @@ let test_find_correctly_looks_up () = *) let test_update_modifies_cached_contract () = init () >>=? fun (block, baker, src, _) -> - originate_contract_hash "contracts/int-store.tz" "36" src block baker + originate_contract_hash + (path // "contracts/int-store.tz") + "36" + src + block + baker >>=? fun (addr, block) -> ( make_block block @! fun ctxt -> find ctxt addr >>=? fun (ctxt, identifier, script, Ex_script (Script ir)) -> diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_temp_big_maps.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_temp_big_maps.ml index 0df912fd077a..8a073ce9bc63 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_temp_big_maps.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_temp_big_maps.ml @@ -64,6 +64,8 @@ let call_the_contract b ~baker ~src contract param_left param_right = Incremental.add_operation incr operation >>=? fun incr -> Incremental.finalize_block incr +let path = project_root // Filename.dirname __FILE__ + (** Originates the contract at contracts/temp_big_maps.tz and calls it with the pair [(param_left, param_right)]. An action (originating, storing, passing, passing twice) is done on a big @@ -73,7 +75,7 @@ let call_the_contract b ~baker ~src contract param_left param_right = let test_temp_big_maps_contract param_left param_right () = Contract_helpers.init () >>=? fun (b, baker, src, _src2) -> Contract_helpers.originate_contract - "contracts/temp_big_maps.tz" + (path // "contracts/temp_big_maps.tz") "{}" src b diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_timelock.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_timelock.ml index 7ec36aee6d3a..b55cb5d6c2b6 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_timelock.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_timelock.ml @@ -64,7 +64,7 @@ let simple_test () = return_unit let timelock_path = - "../../../../../../michelson_test_scripts/ill_typed/timelock.tz" + project_root // "michelson_test_scripts/ill_typed/timelock.tz" let deprecated_chest_open () = let open Lwt_result_syntax in diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_typechecking.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_typechecking.ml index aa18c26cdd24..0373dca0b3e0 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_typechecking.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_typechecking.ml @@ -137,13 +137,15 @@ let read_file filename = close_in ch ; s +let path = project_root // Filename.dirname __FILE__ + (** Check that the custom stack overflow exception is triggered when it should be. *) let test_typecheck_stack_overflow () = test_context () >>=? fun ctxt -> let storage = "Unit" in let parameter = "Unit" in - let script = read_file "./contracts/big_interpreter_stack.tz" in + let script = read_file (path // "contracts/big_interpreter_stack.tz") in Contract_helpers.run_script ctxt script ~storage ~parameter () >>= function | Ok _ -> Alcotest.fail "expected an error" | Error lst @@ -769,7 +771,7 @@ let test_contract_not_packable () = (* This test function is used to checks forbidden operations in views. *) let test_forbidden_op_in_view op () = - let prefix = "./contracts/forbidden_op_in_view_" in + let prefix = path // "contracts/forbidden_op_in_view_" in let script = read_file (prefix ^ op ^ ".tz") in let contract_expr = Expr.from_string script in test_context () >>=? fun ctxt -> @@ -917,13 +919,13 @@ let tests = Tztest.tztest "test lambda_rec instruction" `Quick - (test_contract_success "./contracts/rec_fact.tz"); + (test_contract_success (path // "contracts/rec_fact.tz")); Tztest.tztest "test lambda_rec instruction with apply" `Quick - (test_contract_success "./contracts/rec_fact_apply.tz"); + (test_contract_success (path // "contracts/rec_fact_apply.tz")); Tztest.tztest "test lambda_rec with type error" `Quick - (test_contract_failure "./contracts/fail_rec.tz"); + (test_contract_failure (path // "contracts/fail_rec.tz")); ] diff --git a/tezt/tests/dune b/tezt/tests/dune index ec633ac3f76e..d383e36cc91f 100644 --- a/tezt/tests/dune +++ b/tezt/tests/dune @@ -18,6 +18,7 @@ src_proto_alpha_lib_protocol_test_pbt_tezt_lib src_proto_alpha_lib_protocol_test_integration_validate_tezt_lib src_proto_alpha_lib_protocol_test_integration_operations_tezt_lib + src_proto_alpha_lib_protocol_test_integration_michelson_tezt_lib src_proto_alpha_lib_protocol_test_integration_gas_tezt_lib src_proto_alpha_lib_protocol_test_integration_consensus_tezt_lib src_proto_alpha_lib_protocol_test_integration_tezt_lib @@ -31,6 +32,7 @@ src_proto_016_PtMumbai_lib_protocol_test_pbt_tezt_lib src_proto_016_PtMumbai_lib_protocol_test_integration_validate_tezt_lib src_proto_016_PtMumbai_lib_protocol_test_integration_operations_tezt_lib + src_proto_016_PtMumbai_lib_protocol_test_integration_michelson_tezt_lib src_proto_016_PtMumbai_lib_protocol_test_integration_gas_tezt_lib src_proto_016_PtMumbai_lib_protocol_test_integration_consensus_tezt_lib src_proto_016_PtMumbai_lib_protocol_test_integration_tezt_lib @@ -43,6 +45,7 @@ src_proto_015_PtLimaPt_lib_protocol_test_pbt_tezt_lib src_proto_015_PtLimaPt_lib_protocol_test_integration_validate_tezt_lib src_proto_015_PtLimaPt_lib_protocol_test_integration_operations_tezt_lib + src_proto_015_PtLimaPt_lib_protocol_test_integration_michelson_tezt_lib src_proto_015_PtLimaPt_lib_protocol_test_integration_gas_tezt_lib src_proto_015_PtLimaPt_lib_protocol_test_integration_consensus_tezt_lib src_proto_015_PtLimaPt_lib_protocol_test_integration_tezt_lib -- GitLab From b2eb72e9961b9ff8b3ba5bce1a254e565b003eb9 Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Wed, 15 Mar 2023 15:21:34 +0100 Subject: [PATCH 2/2] Scripts: remove [declare-new-protocol-unit-test] All protocol unit tests now run through the tezt main entry point, and there is no longer any need to define separate jobs for these tests. --- scripts/.ocamlformat-ignore | 1 - scripts/declare-new-protocol-unit-test/dune | 3 - .../declare-new-protocol-unit-test/main.ml | 85 ------------------- scripts/snapshot_alpha.sh | 6 -- scripts/snapshot_alpha_and_link.sh | 3 - 5 files changed, 98 deletions(-) delete mode 100644 scripts/declare-new-protocol-unit-test/dune delete mode 100755 scripts/declare-new-protocol-unit-test/main.ml diff --git a/scripts/.ocamlformat-ignore b/scripts/.ocamlformat-ignore index 4b9d838684c0..14e7d3ccf985 100644 --- a/scripts/.ocamlformat-ignore +++ b/scripts/.ocamlformat-ignore @@ -1,3 +1,2 @@ -declare-new-protocol-unit-test/main.ml gen-genesis/gen_genesis.ml print_version.ml diff --git a/scripts/declare-new-protocol-unit-test/dune b/scripts/declare-new-protocol-unit-test/dune deleted file mode 100644 index 0281b148b0fc..000000000000 --- a/scripts/declare-new-protocol-unit-test/dune +++ /dev/null @@ -1,3 +0,0 @@ -(executable - (name main) - (libraries re)) \ No newline at end of file diff --git a/scripts/declare-new-protocol-unit-test/main.ml b/scripts/declare-new-protocol-unit-test/main.ml deleted file mode 100755 index bc904c837c38..000000000000 --- a/scripts/declare-new-protocol-unit-test/main.ml +++ /dev/null @@ -1,85 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2021 Nomadic Labs, *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -let error message = - prerr_endline message; - exit 1 - -let () = - if Array.length Sys.argv <> 3 then - error - "Usage: dune exec \ - scripts/declare-new-protocol-unit-test/main.exe -- XXX YYYYYYYY"; - let proto_version = Sys.argv.(1) in - let proto_short_hash = Sys.argv.(2) in - let new_proto_name = proto_version ^ "_" ^ proto_short_hash in - let in_ch = open_in ".gitlab/ci/jobs/test/unit.yml" in - Fun.protect ~finally: (fun () -> close_in in_ch) @@ fun () -> - let out_ch = open_out ".gitlab/ci/jobs/test/unit2.yml" in - Fun.protect ~finally: (fun () -> close_out out_ch) @@ fun () -> - let output_line line = - output_string out_ch line; - output_char out_ch '\n' - in - let replace line = - Re.replace_string (Re.compile (Re.str "alpha")) ~by: new_proto_name line - in - let rec read_and_write_the_rest () = - match input_line in_ch with - | exception End_of_file -> - () - | line -> - output_line line; - read_and_write_the_rest () - in - let rec continue_reading_unit_alpha unit_alpha_lines = - match input_line in_ch with - | exception End_of_file | "" -> - (* Found the end of what we were looking for. *) - (* Write unit:alpha: job, and the rest of the file. *) - output_line ""; - List.iter output_line (List.rev unit_alpha_lines); - read_and_write_the_rest () - | line -> - (* Still parsing the unit:alpha: job, replace it as we go. *) - output_line (replace line); - continue_reading_unit_alpha (line :: unit_alpha_lines) - in - let rec find_unit_alpha () = - match input_line in_ch with - | exception End_of_file -> - error - "End of file reached before seeing unit:alpha: - check \ - .gitlab/ci/jobs/test/unit.yml" - | "unit:alpha:" as line -> - (* Found the job we were looking for, start replacing it. *) - output_line (replace line); - continue_reading_unit_alpha [ line ] - | line -> - output_line line; - find_unit_alpha () - in - find_unit_alpha (); - Sys.rename ".gitlab/ci/jobs/test/unit2.yml" ".gitlab/ci/jobs/test/unit.yml" diff --git a/scripts/snapshot_alpha.sh b/scripts/snapshot_alpha.sh index e68f7bcdebc9..c1753fef8723 100755 --- a/scripts/snapshot_alpha.sh +++ b/scripts/snapshot_alpha.sh @@ -174,9 +174,3 @@ cd ../../.. # remove files generated by sed find . -name '*.old' -exec rm {} \; - -if [ -z "$SILENCE_REMINDER" ]; then - echo "Generated src/proto_${version}_${short_hash}. Don't forget to:" - echo "" - echo " dune exec scripts/declare-new-protocol-unit-test/main.exe -- ${version} ${short_hash}" -fi diff --git a/scripts/snapshot_alpha_and_link.sh b/scripts/snapshot_alpha_and_link.sh index 6cfa0af8e417..93f3e2a98e5f 100755 --- a/scripts/snapshot_alpha_and_link.sh +++ b/scripts/snapshot_alpha_and_link.sh @@ -41,8 +41,5 @@ fi echo "link_protocol.sh src/proto_${version_number}_${short_hash}" $script_dir/link_protocol.sh src/proto_${version_number}_${short_hash} -echo "dune exec scripts/declare-new-protocol-unit-test/main.exe -- ${version_number} ${short_hash}" -dune exec scripts/declare-new-protocol-unit-test/main.exe -- ${version_number} ${short_hash} - echo "Done. You can now commit everything." echo "Don't forget to: git add src/proto_${version_number}_${short_hash} docs/${version_number}" -- GitLab