From afca9974a40df8d2a3dac6111bb639158236f27a Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Wed, 1 Mar 2023 11:23:25 +0100 Subject: [PATCH] lib_sapling: port tests to alcotezt --- .gitlab/ci/jobs/packaging/opam_package.yml | 4 +- manifest/main.ml | 15 +++- opam/tezos-sapling.opam | 5 +- src/lib_sapling/test/dune | 94 +++++++++++----------- src/lib_sapling/test/keys.ml | 6 +- tezt/tests/dune | 1 + 6 files changed, 68 insertions(+), 57 deletions(-) diff --git a/.gitlab/ci/jobs/packaging/opam_package.yml b/.gitlab/ci/jobs/packaging/opam_package.yml index 4648dcf53981..60726a8f6ca6 100644 --- a/.gitlab/ci/jobs/packaging/opam_package.yml +++ b/.gitlab/ci/jobs/packaging/opam_package.yml @@ -1343,7 +1343,7 @@ opam:tezos-rpc-http-server: opam:tezos-sapling: extends: - .opam_template - - .rules_template__trigger_opam_batch_6 + - .rules_template__trigger_opam_batch_7 variables: package: tezos-sapling @@ -1540,7 +1540,7 @@ opam:tezos-webassembly-interpreter-extra: opam:tezos-workers: extends: - .opam_template - - .rules_template__trigger_opam_batch_7 + - .rules_template__trigger_opam_batch_6 variables: package: tezos-workers diff --git a/manifest/main.ml b/manifest/main.ml index 04af7760ab07..510f5d27cf8a 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -2081,8 +2081,16 @@ let octez_sapling = ] let _octez_sapling_tests = - tests - ["test_rustzcash"; "test_keys"; "test_merkle"; "test_roots"; "test_sapling"] + tezt + [ + "test_rustzcash"; + "test_keys"; + "test_merkle"; + "test_roots"; + "test_sapling"; + "keys"; + "example"; + ] ~path:"src/lib_sapling/test" ~with_macos_security_framework:true ~opam:"tezos-sapling" @@ -2098,9 +2106,8 @@ let _octez_sapling_tests = octez_stdlib_unix; data_encoding |> open_; octez_base_test_helpers |> open_; - alcotest_lwt; + alcotezt; ] - ~all_modules_except:["test_js"] ~opam_with_test:Never let _octez_sapling_js_tests = diff --git a/opam/tezos-sapling.opam b/opam/tezos-sapling.opam index 71b1e987b942..4fc76db48457 100644 --- a/opam/tezos-sapling.opam +++ b/opam/tezos-sapling.opam @@ -21,11 +21,12 @@ depends: [ "tezos-error-monad" "tezos-rust-libs" { = "1.5" } "tezos-lwt-result-stdlib" + "tezos-hacl" {with-test} + "tezt" { with-test & >= "3.0.0" } "tezos-base" {with-test} "tezos-stdlib-unix" {with-test} "tezos-base-test-helpers" {with-test} - "alcotest-lwt" { with-test & >= "1.5.0" } - "tezos-hacl" {with-test} + "octez-alcotezt" {with-test} ] x-opam-monorepo-opam-provided: [ "tezos-rust-libs" diff --git a/src/lib_sapling/test/dune b/src/lib_sapling/test/dune index 660c75094155..7f285d96f8f7 100644 --- a/src/lib_sapling/test/dune +++ b/src/lib_sapling/test/dune @@ -3,9 +3,28 @@ (env (_ (env-vars (NODE_PRELOAD hacl-wasm,ocaml-bls12-381,secp256k1-wasm)))) -(executables - (names test_rustzcash test_keys test_merkle test_roots test_sapling) +(executable + (name test_js) + (modes js) (libraries + tezos-sapling + tezos-hacl) + (js_of_ocaml) + (link_flags + (:standard) + (-linkall)) + (modules test_js)) + +(rule + (alias runtest_js) + (package tezos-sapling) + (action (run node %{dep:./test_js.bc.js}))) + +(library + (name src_lib_sapling_test_tezt_lib) + (instrumentation (backend bisect_ppx)) + (libraries + tezt.core tezos-sapling tezos-crypto str @@ -15,61 +34,42 @@ tezos-stdlib-unix data-encoding tezos-base-test-helpers - alcotest-lwt) - (link_flags - (:standard) - (:include %{workspace_root}/macos-link-flags.sexp)) + octez-alcotezt) + (library_flags (:standard -linkall)) (flags (:standard) + -open Tezt_core + -open Tezt_core.Base -open Tezos_sapling -open Tezos_stdlib -open Data_encoding - -open Tezos_base_test_helpers) - (modules (:standard \ test_js))) - -(rule - (alias runtest) - (package tezos-sapling) - (deps vectors.csv vectors-zip32.csv) - (action (run %{dep:./test_rustzcash.exe}))) - -(rule - (alias runtest) - (package tezos-sapling) - (deps vectors.csv vectors-zip32.csv) - (action (run %{dep:./test_keys.exe}))) - -(rule - (alias runtest) - (package tezos-sapling) - (deps vectors.csv vectors-zip32.csv) - (action (run %{dep:./test_merkle.exe}))) - -(rule - (alias runtest) - (package tezos-sapling) - (deps vectors.csv vectors-zip32.csv) - (action (run %{dep:./test_roots.exe}))) - -(rule - (alias runtest) - (package tezos-sapling) - (deps vectors.csv vectors-zip32.csv) - (action (run %{dep:./test_sapling.exe}))) + -open Tezos_base_test_helpers + -open Octez_alcotezt) + (modules + test_rustzcash + test_keys + test_merkle + test_roots + test_sapling + keys + example)) (executable - (name test_js) - (modes js) + (name main) (libraries - tezos-sapling - tezos-hacl) - (js_of_ocaml) + src_lib_sapling_test_tezt_lib + tezt) (link_flags (:standard) - (-linkall)) - (modules test_js)) + (:include %{workspace_root}/macos-link-flags.sexp)) + (modules main)) (rule - (alias runtest_js) + (alias runtezt) (package tezos-sapling) - (action (run node %{dep:./test_js.bc.js}))) + (deps vectors.csv vectors-zip32.csv) + (action (run %{dep:./main.exe}))) + +(rule + (targets main.ml) + (action (with-stdout-to %{targets} (echo "let () = Tezt.Test.run ()")))) diff --git a/src/lib_sapling/test/keys.ml b/src/lib_sapling/test/keys.ml index 6dfbf7d5742d..533b538b7e0b 100644 --- a/src/lib_sapling/test/keys.ml +++ b/src/lib_sapling/test/keys.ml @@ -6,6 +6,8 @@ module Vk = Core.Raw.Viewing_key let ba_of_hex h = Hex.to_bytes_exn (`Hex h) +let path filename = project_root // Filename.dirname __FILE__ // filename + module Vector = struct type test_vector = { sk : Bytes.t; @@ -55,7 +57,7 @@ module Vector = struct } in (* read file in memory skipping lines with # *) - let file = "vectors.csv" in + let file = path "vectors.csv" in let ic = open_in file in let rec read_lines ls = try @@ -118,7 +120,7 @@ let vectors_zip32 = } in (* read file in memory skipping lines with # *) - let file = "vectors-zip32.csv" in + let file = path "vectors-zip32.csv" in let ic = open_in file in let rec read_lines ls = try diff --git a/tezt/tests/dune b/tezt/tests/dune index 27b6ca20d56b..9a75882cbfe3 100644 --- a/tezt/tests/dune +++ b/tezt/tests/dune @@ -42,6 +42,7 @@ src_lib_signer_backends_unix_test_tezt_lib src_lib_signer_backends_test_tezt_lib src_lib_shell_test_tezt_lib + src_lib_sapling_test_tezt_lib src_lib_p2p_tezt_tezt_lib src_lib_mockup_test_tezt_lib src_lib_lwt_result_stdlib_test_tezt_lib -- GitLab