From b8312ab4a40ba1a151430fec1f6127ee1580d322 Mon Sep 17 00:00:00 2001 From: damirka Date: Wed, 21 Apr 2021 13:01:11 +0300 Subject: [PATCH] adds integration tests to Leo CLI - leo tests are now written as cli commands - leo libraries and binaries removed from package and cli - small code optimizations and removals --- Cargo.lock | 724 ++++++++++++++++++++- Cargo.toml | 6 + examples/silly-sudoku/inputs/test_input.in | 14 + leo/commands/build.rs | 200 +++--- leo/commands/init.rs | 4 +- leo/commands/new.rs | 2 +- leo/commands/setup.rs | 3 +- leo/commands/watch.rs | 9 +- leo/tests/cmd.rs | 122 ++++ leo/tests/mod.rs | 3 +- package/src/lib.rs | 9 +- package/src/package.rs | 112 ++-- package/src/source/library.rs | 76 --- package/src/source/mod.rs | 3 - package/tests/initialize/initialize.rs | 72 +- 15 files changed, 1020 insertions(+), 339 deletions(-) create mode 100644 examples/silly-sudoku/inputs/test_input.in create mode 100644 leo/tests/cmd.rs delete mode 100644 package/src/source/library.rs diff --git a/Cargo.lock b/Cargo.lock index a5661976ca..f32906f20a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,6 +87,140 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" +[[package]] +name = "assert_cmd" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2475b58cd94eb4f70159f4fd8844ba3b807532fe3131b3373fae060bbe30396" +dependencies = [ + "bstr", + "doc-comment", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + +[[package]] +name = "async-channel" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2114d64672151c0c5eaa5e131ec84a74f06e1e559830dabba01ca30605d66319" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + +[[package]] +name = "async-executor" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb877970c7b440ead138f6321a3b5395d6061183af779340b65e20c0fede9146" +dependencies = [ + "async-task 4.0.3", + "concurrent-queue", + "fastrand", + "futures-lite 1.11.3", + "once_cell", + "vec-arena", +] + +[[package]] +name = "async-fs" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b3ca4f8ff117c37c278a2f7415ce9be55560b846b5bc4412aaa5d29c1c3dae2" +dependencies = [ + "async-lock", + "blocking 1.0.2", + "futures-lite 1.11.3", +] + +[[package]] +name = "async-io" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5bfd63f6fc8fd2925473a147d3f4d252c712291efdde0d7057b25146563402c" +dependencies = [ + "concurrent-queue", + "fastrand", + "futures-lite 1.11.3", + "log", + "nb-connect", + "once_cell", + "parking 2.0.0", + "polling", + "vec-arena", + "waker-fn", +] + +[[package]] +name = "async-lock" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6a8ea61bf9947a1007c5cada31e647dbc77b103c679858150003ba697ea798b" +dependencies = [ + "event-listener", +] + +[[package]] +name = "async-net" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06de475c85affe184648202401d7622afb32f0f74e02192857d0201a16defbe5" +dependencies = [ + "async-io", + "blocking 1.0.2", + "fastrand", + "futures-lite 1.11.3", +] + +[[package]] +name = "async-process" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef37b86e2fa961bae5a4d212708ea0154f904ce31d1a4a7f47e1bbc33a0c040b" +dependencies = [ + "async-io", + "blocking 1.0.2", + "cfg-if 1.0.0", + "event-listener", + "futures-lite 1.11.3", + "once_cell", + "signal-hook", + "winapi 0.3.9", +] + +[[package]] +name = "async-task" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17772156ef2829aadc587461c7753af20b7e8db1529bc66855add962a3b35d3" + +[[package]] +name = "async-task" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0" + +[[package]] +name = "async-trait" +version = "0.1.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b98e84bbb4cbcdd97da190ba0c58a1bb0de2c1fdf67d159e192ed766aeca722" +dependencies = [ + "proc-macro2 1.0.24", + "quote 1.0.9", + "syn 1.0.64", +] + +[[package]] +name = "atomic-waker" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" + [[package]] name = "atty" version = "0.2.14" @@ -239,6 +373,34 @@ dependencies = [ "byte-tools", ] +[[package]] +name = "blocking" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2468ff7bf85066b4a3678fede6fe66db31846d753ff0adfbfab2c6a6e81612b" +dependencies = [ + "async-channel", + "atomic-waker", + "futures-lite 0.1.11", + "once_cell", + "parking 1.0.6", + "waker-fn", +] + +[[package]] +name = "blocking" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e170dbede1f740736619b776d7251cb1b9095c435c34d8ca9f57fcd2f335e9" +dependencies = [ + "async-channel", + "async-task 4.0.3", + "atomic-waker", + "fastrand", + "futures-lite 1.11.3", + "once_cell", +] + [[package]] name = "bstr" version = "0.2.15" @@ -296,6 +458,12 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "cache-padded" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" + [[package]] name = "cast" version = "0.2.3" @@ -395,6 +563,15 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "concurrent-queue" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" +dependencies = [ + "cache-padded", +] + [[package]] name = "console" version = "0.14.1" @@ -571,7 +748,7 @@ dependencies = [ "openssl-probe", "openssl-sys", "schannel", - "socket2", + "socket2 0.3.19", "winapi 0.3.9", ] @@ -590,6 +767,26 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "darwin-libproc" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb90051930c9a0f09e585762152048e23ac74d20c10590ef7cf01c0343c3046" +dependencies = [ + "darwin-libproc-sys", + "libc", + "memchr", +] + +[[package]] +name = "darwin-libproc-sys" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57cebb5bde66eecdd30ddc4b9cd208238b15db4982ccc72db59d699ea10867c1" +dependencies = [ + "libc", +] + [[package]] name = "derivative" version = "2.2.0" @@ -601,6 +798,12 @@ dependencies = [ "syn 1.0.64", ] +[[package]] +name = "difference" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" + [[package]] name = "digest" version = "0.8.1" @@ -639,6 +842,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + [[package]] name = "dtoa" version = "0.4.8" @@ -689,6 +898,12 @@ dependencies = [ "indexmap", ] +[[package]] +name = "event-listener" +version = "2.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" + [[package]] name = "failure" version = "0.1.8" @@ -717,6 +932,15 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" +[[package]] +name = "fastrand" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca5faf057445ce5c9d4329e382b2ce7ca38550ef3b73a5348362d5f24e0c7fe3" +dependencies = [ + "instant", +] + [[package]] name = "filetime" version = "0.2.14" @@ -839,6 +1063,20 @@ dependencies = [ "new_debug_unreachable", ] +[[package]] +name = "futures" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f55667319111d593ba876406af7c409c0ebb44dc4be6132a783ccf163ea14c1" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.13" @@ -846,6 +1084,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c2dd2df839b57db9ab69c2c9d8f3e8c81984781937fe2807dc6dcf3b2ad2939" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -860,6 +1099,36 @@ version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d71c2c65c57704c32f5241c1223167c2c3294fd34ac020c807ddbe6db287ba59" +[[package]] +name = "futures-lite" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97999970129b808f0ccba93211201d431fcc12d7e1ffae03a61b5cedd1a7ced2" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking 2.0.0", + "pin-project-lite 0.1.12", + "waker-fn", +] + +[[package]] +name = "futures-lite" +version = "1.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4481d0cd0de1d204a4fa55e7d45f07b1d958abcb06714b3446438e2eff695fb" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking 2.0.0", + "pin-project-lite 0.2.4", + "waker-fn", +] + [[package]] name = "futures-sink" version = "0.3.13" @@ -872,17 +1141,25 @@ version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa189ef211c15ee602667a6fcfe1c1fd9e07d42250d2156382820fba33c9df80" +[[package]] +name = "futures-timer" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" + [[package]] name = "futures-util" version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1812c7ab8aedf8d6f2701a43e1243acdbcc2b36ab26e2ad421eb99ac963d96d1" dependencies = [ + "futures-channel", "futures-core", "futures-io", + "futures-sink", "futures-task", "memchr", - "pin-project-lite", + "pin-project-lite 0.2.4", "pin-utils", "slab", ] @@ -999,6 +1276,125 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "heim" +version = "0.1.0-beta.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1014732324a9baf5a691525faabb33909bf6f40dcc2b03c8f2fb07bb01e7e3f" +dependencies = [ + "heim-common", + "heim-process", + "heim-runtime", +] + +[[package]] +name = "heim-common" +version = "0.1.0-rc.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767e6e47cf88abe7c9a5ebb4df82f180d30d9c0ba0269b6d166482461765834" +dependencies = [ + "cfg-if 1.0.0", + "core-foundation", + "futures-core", + "futures-util", + "lazy_static", + "libc", + "mach", + "nix 0.19.1", + "pin-utils", + "uom", + "winapi 0.3.9", +] + +[[package]] +name = "heim-cpu" +version = "0.1.0-beta.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73b1442359831aa671aa931f0a084aab210e77b1330ded78f1e60cc305abc4bb" +dependencies = [ + "cfg-if 0.1.10", + "futures", + "glob", + "heim-common", + "heim-runtime", + "lazy_static", + "libc", + "mach", + "ntapi", + "smol 0.1.18", + "winapi 0.3.9", +] + +[[package]] +name = "heim-host" +version = "0.1.0-beta.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79cce3ce658bd45e510ff0a2fb5c668cbe1a7368929fd1db123741c99fd6902e" +dependencies = [ + "cfg-if 0.1.10", + "heim-common", + "heim-runtime", + "lazy_static", + "libc", + "log", + "mach", + "ntapi", + "platforms", + "winapi 0.3.9", +] + +[[package]] +name = "heim-net" +version = "0.1.0-beta.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59da1108e732afcda77e1429b5d0ce648b9a31d1f8cf385108b83bea4cf91342" +dependencies = [ + "bitflags", + "cfg-if 0.1.10", + "heim-common", + "heim-runtime", + "libc", + "macaddr", + "nix 0.17.0", +] + +[[package]] +name = "heim-process" +version = "0.1.1-beta.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd969deb2a89a488b6a9bf18a65923ae4cdef6b128fa2dedb74ef5c694deb5ae" +dependencies = [ + "async-trait", + "cfg-if 0.1.10", + "darwin-libproc", + "futures", + "heim-common", + "heim-cpu", + "heim-host", + "heim-net", + "heim-runtime", + "lazy_static", + "libc", + "mach", + "memchr", + "ntapi", + "ordered-float", + "smol 0.1.18", + "winapi 0.3.9", +] + +[[package]] +name = "heim-runtime" +version = "0.1.0-beta.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "906dd26ed2eb6b9f5f0dc3dfc04caeb82785ccc05a3b3326e4c841613451acc7" +dependencies = [ + "futures", + "futures-timer", + "smol 0.1.18", + "version-sync", +] + [[package]] name = "hermit-abi" version = "0.1.18" @@ -1073,7 +1469,7 @@ dependencies = [ "httpdate", "itoa", "pin-project", - "socket2", + "socket2 0.3.19", "tokio", "tower-service", "tracing", @@ -1354,6 +1750,7 @@ version = "1.4.0" dependencies = [ "ansi_term 0.12.1", "anyhow", + "assert_cmd", "clap", "colored", "console", @@ -1381,6 +1778,7 @@ dependencies = [ "snarkvm-r1cs", "snarkvm-utilities", "structopt", + "testdir", "thiserror", "toml", "tracing", @@ -1535,6 +1933,21 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" +[[package]] +name = "macaddr" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baee0bbc17ce759db233beb01648088061bf678383130602a298e6998eedb2d8" + +[[package]] +name = "mach" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +dependencies = [ + "libc", +] + [[package]] name = "maplit" version = "1.0.2" @@ -1668,7 +2081,7 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" dependencies = [ - "socket2", + "socket2 0.3.19", "winapi 0.3.9", ] @@ -1690,6 +2103,16 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nb-connect" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a19900e7eee95eb2b3c2e26d12a874cc80aaf750e31be6fcbe743ead369fa45d" +dependencies = [ + "libc", + "socket2 0.4.0", +] + [[package]] name = "net2" version = "0.2.37" @@ -1713,6 +2136,31 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab250442c86f1850815b5d268639dff018c0627022bc1940eb2d642ca1ce12f0" +[[package]] +name = "nix" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50e4785f2c3b7589a0d0c1dd60285e1188adac4006e8abd6dd578e1567027363" +dependencies = [ + "bitflags", + "cc", + "cfg-if 0.1.10", + "libc", + "void", +] + +[[package]] +name = "nix" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ccba0cfe4fdf15982d1674c69b1fd80bad427d293849982668dfe454bd61f2" +dependencies = [ + "bitflags", + "cc", + "cfg-if 1.0.0", + "libc", +] + [[package]] name = "nom" version = "5.1.2" @@ -1784,6 +2232,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-rational" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.14" @@ -1872,6 +2331,27 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "ordered-float" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18869315e81473c951eb56ad5558bbc56978562d3ecfb87abb7a1e944cea4518" +dependencies = [ + "num-traits", +] + +[[package]] +name = "parking" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cb300f271742d4a2a66c01b6b2fa0c83dfebd2e0bf11addb879a3547b4ed87c" + +[[package]] +name = "parking" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" + [[package]] name = "parking_lot" version = "0.11.1" @@ -1985,6 +2465,12 @@ dependencies = [ "syn 1.0.64", ] +[[package]] +name = "pin-project-lite" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" + [[package]] name = "pin-project-lite" version = "0.2.4" @@ -2003,6 +2489,12 @@ version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" +[[package]] +name = "platforms" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "feb3b2b1033b8a60b4da6ee470325f887758c95d5320f52f9ce0df055a55940e" + [[package]] name = "plotters" version = "0.3.0" @@ -2031,12 +2523,51 @@ dependencies = [ "plotters-backend", ] +[[package]] +name = "polling" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0720e0b9ea9d52451cf29d3413ba8a9303f8815d9d9653ef70e03ff73e65566" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "log", + "wepoll-sys-stjepang", + "winapi 0.3.9", +] + [[package]] name = "ppv-lite86" version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +[[package]] +name = "predicates" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eeb433456c1a57cc93554dea3ce40b4c19c4057e41c55d4a0f3d84ea71c325aa" +dependencies = [ + "difference", + "predicates-core", +] + +[[package]] +name = "predicates-core" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451" + +[[package]] +name = "predicates-tree" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15f553275e5721409451eb85e15fd9a860a6e5ab4496eb215987502b5f5391f2" +dependencies = [ + "predicates-core", + "treeline", +] + [[package]] name = "proc-macro-crate" version = "0.1.5" @@ -2088,6 +2619,17 @@ dependencies = [ "unicode-xid 0.2.1", ] +[[package]] +name = "pulldown-cmark" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8" +dependencies = [ + "bitflags", + "memchr", + "unicase", +] + [[package]] name = "quick-error" version = "1.2.3" @@ -2286,7 +2828,7 @@ dependencies = [ "mime_guess", "native-tls", "percent-encoding", - "pin-project-lite", + "pin-project-lite 0.2.4", "serde", "serde_json", "serde_urlencoded", @@ -2388,6 +2930,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "scoped-tls" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" + [[package]] name = "scopeguard" version = "1.1.0" @@ -2459,6 +3007,12 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +[[package]] +name = "semver-parser" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b46e1121e8180c12ff69a742aabc4f310542b6ccb69f1691689ac17fdf8618aa" + [[package]] name = "semver-parser" version = "0.10.2" @@ -2573,6 +3127,25 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" +[[package]] +name = "signal-hook" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef33d6d0cd06e0840fba9985aab098c147e67e05cee14d412d3345ed14ff30ac" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-registry" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" +dependencies = [ + "libc", +] + [[package]] name = "single" version = "1.0.0" @@ -2594,6 +3167,45 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" +[[package]] +name = "smol" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "620cbb3c6e34da57d3a248cda0cd01cd5848164dc062e764e65d06fe3ea7aed5" +dependencies = [ + "async-task 3.0.0", + "blocking 0.4.7", + "concurrent-queue", + "fastrand", + "futures-io", + "futures-util", + "libc", + "once_cell", + "scoped-tls", + "slab", + "socket2 0.3.19", + "wepoll-sys-stjepang", + "winapi 0.3.9", +] + +[[package]] +name = "smol" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cf3b5351f3e783c1d79ab5fc604eeed8b8ae9abd36b166e8b87a089efd85e4" +dependencies = [ + "async-channel", + "async-executor", + "async-fs", + "async-io", + "async-lock", + "async-net", + "async-process", + "blocking 1.0.2", + "futures-lite 1.11.3", + "once_cell", +] + [[package]] name = "snarkvm-algorithms" version = "0.2.2" @@ -2803,6 +3415,16 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "socket2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" +dependencies = [ + "libc", + "winapi 0.3.9", +] + [[package]] name = "static_assertions" version = "1.1.0" @@ -2929,6 +3551,20 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "testdir" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c13a556e110c7d373db3c12464a80e4d24ed25942381242b17aad43aee98085" +dependencies = [ + "anyhow", + "backtrace", + "heim", + "once_cell", + "smol 1.2.5", + "whoami", +] + [[package]] name = "textwrap" version = "0.11.0" @@ -3014,7 +3650,7 @@ dependencies = [ "memchr", "mio 0.7.10", "num_cpus", - "pin-project-lite", + "pin-project-lite 0.2.4", ] [[package]] @@ -3037,7 +3673,7 @@ dependencies = [ "futures-core", "futures-sink", "log", - "pin-project-lite", + "pin-project-lite 0.2.4", "tokio", ] @@ -3063,7 +3699,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" dependencies = [ "cfg-if 1.0.0", - "pin-project-lite", + "pin-project-lite 0.2.4", "tracing-attributes", "tracing-core", ] @@ -3141,6 +3777,12 @@ dependencies = [ "tracing-serde", ] +[[package]] +name = "treeline" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" + [[package]] name = "try-lock" version = "0.2.3" @@ -3216,6 +3858,17 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +[[package]] +name = "uom" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e76503e636584f1e10b9b3b9498538279561adcef5412927ba00c2b32c4ce5ed" +dependencies = [ + "num-rational", + "num-traits", + "typenum", +] + [[package]] name = "url" version = "2.2.1" @@ -3240,12 +3893,33 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" +[[package]] +name = "vec-arena" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34b2f665b594b07095e3ac3f718e13c2197143416fae4c5706cffb7b1af8d7f1" + [[package]] name = "vec_map" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +[[package]] +name = "version-sync" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cb94ca10ca0cf44f5d926ac977f0cac2d13e9789aa4bbe9d9388de445e61028" +dependencies = [ + "proc-macro2 1.0.24", + "pulldown-cmark", + "regex", + "semver-parser 0.9.0", + "syn 1.0.64", + "toml", + "url", +] + [[package]] name = "version_check" version = "0.9.2" @@ -3258,6 +3932,21 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] +name = "waker-fn" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" + [[package]] name = "walkdir" version = "2.3.2" @@ -3369,6 +4058,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "wepoll-sys-stjepang" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fdfbb03f290ca0b27922e8d48a0997b4ceea12df33269b9f75e713311eb178d" +dependencies = [ + "cc", +] + [[package]] name = "which" version = "3.1.1" @@ -3378,6 +4076,16 @@ dependencies = [ "libc", ] +[[package]] +name = "whoami" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4abacf325c958dfeaf1046931d37f2a901b6dfe0968ee965a29e94c6766b2af6" +dependencies = [ + "wasm-bindgen", + "web-sys", +] + [[package]] name = "winapi" version = "0.2.8" diff --git a/Cargo.toml b/Cargo.toml index dc9bfb5f6f..2aca1ffe77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -156,6 +156,12 @@ version = "0.12.1" [dev-dependencies.rusty-hook] version = "0.11.2" +[dev-dependencies.assert_cmd] +version = "1.0.3" + +[dev-dependencies.testdir] +version = "0.4.0" + [features] default = [ ] ci_skip = [ "leo-compiler/ci_skip" ] diff --git a/examples/silly-sudoku/inputs/test_input.in b/examples/silly-sudoku/inputs/test_input.in new file mode 100644 index 0000000000..36f8362978 --- /dev/null +++ b/examples/silly-sudoku/inputs/test_input.in @@ -0,0 +1,14 @@ +// The program input for tmp-test/src/main.leo +[main] +puzzle: [u8; (3, 3)] = [[1, 0, 5], + [0, 2, 0], + [7, 0, 0]]; + +answer: [u8; (3, 3)] = [[1, 4, 5], + [3, 2, 6], + [7, 8, 9]]; + +expected: bool = true; + +[registers] +r: bool = false; diff --git a/leo/commands/build.rs b/leo/commands/build.rs index 392859e238..dba9414016 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -22,11 +22,11 @@ use leo_compiler::{ use leo_package::{ inputs::*, outputs::{ChecksumFile, CircuitFile, OutputsDirectory, OUTPUTS_DIRECTORY_NAME}, - source::{LibraryFile, MainFile, LIBRARY_FILENAME, MAIN_FILENAME, SOURCE_DIRECTORY_NAME}, + source::{MainFile, MAIN_FILENAME, SOURCE_DIRECTORY_NAME}, }; use leo_synthesizer::{CircuitSynthesizer, SerializedCircuit}; -use anyhow::Result; +use anyhow::{anyhow, Result}; use snarkvm_curves::{bls12_377::Bls12_377, edwards_bls12::Fq}; use snarkvm_r1cs::ConstraintSystem; use structopt::StructOpt; @@ -39,7 +39,7 @@ pub struct Build {} impl Command for Build { type Input = (); - type Output = Option<(Compiler<'static, Fq, EdwardsGroupType>, bool)>; + type Output = (Compiler<'static, Fq, EdwardsGroupType>, bool); fn log_span(&self) -> Span { tracing::span!(tracing::Level::INFO, "Build") @@ -65,115 +65,95 @@ impl Command for Build { tracing::info!("Starting..."); - // Compile the package starting with the lib.leo file - if LibraryFile::exists_at(&package_path) { - // Construct the path to the library file in the source directory - let mut lib_file_path = package_path.clone(); - lib_file_path.push(SOURCE_DIRECTORY_NAME); - lib_file_path.push(LIBRARY_FILENAME); - - // Log compilation of library file to console - tracing::info!("Compiling library... ({:?})", lib_file_path); - - // Compile the library file but do not output - let _program = Compiler::::parse_program_without_input( - package_name.clone(), - lib_file_path, - output_directory.clone(), - thread_leaked_context(), - )?; - tracing::info!("Complete"); - }; - // Compile the main.leo file along with constraints - if MainFile::exists_at(&package_path) { - // Create the output directory - OutputsDirectory::create(&package_path)?; - - // Construct the path to the main file in the source directory - let mut main_file_path = package_path.clone(); - main_file_path.push(SOURCE_DIRECTORY_NAME); - main_file_path.push(MAIN_FILENAME); - - // Load the input file at `package_name.in` - let (input_string, input_path) = InputFile::new(&package_name).read_from(&path)?; - - // Load the state file at `package_name.in` - let (state_string, state_path) = StateFile::new(&package_name).read_from(&path)?; - - // Log compilation of files to console - tracing::info!("Compiling main program... ({:?})", main_file_path); - - // Load the program at `main_file_path` - let program = Compiler::::parse_program_with_input( - package_name.clone(), - main_file_path, - output_directory, - &input_string, - &input_path, - &state_string, - &state_path, - thread_leaked_context(), - )?; - - // Compute the current program checksum - let program_checksum = program.checksum()?; - - // Generate the program on the constraint system and verify correctness - { - let mut cs = CircuitSynthesizer:: { - constraints: Default::default(), - public_variables: Default::default(), - private_variables: Default::default(), - namespaces: Default::default(), - }; - let temporary_program = program.clone(); - let output = temporary_program.compile_constraints(&mut cs)?; - - tracing::debug!("Compiled output - {:#?}", output); - tracing::info!("Number of constraints - {:#?}", cs.num_constraints()); - - // Serialize the circuit - let circuit_object = SerializedCircuit::from(cs); - let json = circuit_object.to_json_string().unwrap(); - // println!("json: {}", json); - - // Write serialized circuit to circuit `.json` file. - let circuit_file = CircuitFile::new(&package_name); - circuit_file.write_to(&path, json)?; - - // Check that we can read the serialized circuit file - // let serialized = circuit_file.read_from(&package_path)?; - - // Deserialize the circuit - // let deserialized = SerializedCircuit::from_json_string(&serialized).unwrap(); - // let _circuit_synthesizer = CircuitSynthesizer::::try_from(deserialized).unwrap(); - // println!("deserialized {:?}", circuit_synthesizer.num_constraints()); - } - - // If a checksum file exists, check if it differs from the new checksum - let checksum_file = ChecksumFile::new(&package_name); - let checksum_differs = if checksum_file.exists_at(&package_path) { - let previous_checksum = checksum_file.read_from(&package_path)?; - program_checksum != previous_checksum - } else { - // By default, the checksum differs if there is no checksum to compare against - true - }; - - // If checksum differs, compile the program - if checksum_differs { - // Write the new checksum to the output directory - checksum_file.write_to(&path, program_checksum)?; - - tracing::debug!("Checksum saved ({:?})", path); - } - - tracing::info!("Complete"); - - return Ok(Some((program, checksum_differs))); + if !MainFile::exists_at(&package_path) { + return Err(anyhow!("File main.leo not found in src/ directory")); } - Ok(None) + // Create the output directory + OutputsDirectory::create(&package_path)?; + + // Construct the path to the main file in the source directory + let mut main_file_path = package_path.clone(); + main_file_path.push(SOURCE_DIRECTORY_NAME); + main_file_path.push(MAIN_FILENAME); + + // Load the input file at `package_name.in` + let (input_string, input_path) = InputFile::new(&package_name).read_from(&path)?; + + // Load the state file at `package_name.in` + let (state_string, state_path) = StateFile::new(&package_name).read_from(&path)?; + + // Log compilation of files to console + tracing::info!("Compiling main program... ({:?})", main_file_path); + + // Load the program at `main_file_path` + let program = Compiler::::parse_program_with_input( + package_name.clone(), + main_file_path, + output_directory, + &input_string, + &input_path, + &state_string, + &state_path, + thread_leaked_context(), + )?; + + // Compute the current program checksum + let program_checksum = program.checksum()?; + + // Generate the program on the constraint system and verify correctness + { + let mut cs = CircuitSynthesizer:: { + constraints: Default::default(), + public_variables: Default::default(), + private_variables: Default::default(), + namespaces: Default::default(), + }; + let temporary_program = program.clone(); + let output = temporary_program.compile_constraints(&mut cs)?; + + tracing::debug!("Compiled output - {:#?}", output); + tracing::info!("Number of constraints - {:#?}", cs.num_constraints()); + + // Serialize the circuit + let circuit_object = SerializedCircuit::from(cs); + let json = circuit_object.to_json_string().unwrap(); + // println!("json: {}", json); + + // Write serialized circuit to circuit `.json` file. + let circuit_file = CircuitFile::new(&package_name); + circuit_file.write_to(&path, json)?; + + // Check that we can read the serialized circuit file + // let serialized = circuit_file.read_from(&package_path)?; + + // Deserialize the circuit + // let deserialized = SerializedCircuit::from_json_string(&serialized).unwrap(); + // let _circuit_synthesizer = CircuitSynthesizer::::try_from(deserialized).unwrap(); + // println!("deserialized {:?}", circuit_synthesizer.num_constraints()); + } + + // If a checksum file exists, check if it differs from the new checksum + let checksum_file = ChecksumFile::new(&package_name); + let checksum_differs = if checksum_file.exists_at(&package_path) { + let previous_checksum = checksum_file.read_from(&package_path)?; + program_checksum != previous_checksum + } else { + // By default, the checksum differs if there is no checksum to compare against + true + }; + + // If checksum differs, compile the program + if checksum_differs { + // Write the new checksum to the output directory + checksum_file.write_to(&path, program_checksum)?; + + tracing::debug!("Checksum saved ({:?})", path); + } + + tracing::info!("Complete"); + + Ok((program, checksum_differs)) } } diff --git a/leo/commands/init.rs b/leo/commands/init.rs index 98b63a755c..2896f84630 100644 --- a/leo/commands/init.rs +++ b/leo/commands/init.rs @@ -55,12 +55,12 @@ impl Command for Init { .to_string_lossy() .to_string(); if !LeoPackage::is_package_name_valid(&package_name) { - return Err(anyhow!("Invalid Leo project name")); + return Err(anyhow!("Invalid Leo project name: {}", package_name)); } let username = read_username().ok(); - LeoPackage::initialize(&package_name, false, &path, username)?; + LeoPackage::initialize(&package_name, &path, username)?; Ok(()) } diff --git a/leo/commands/new.rs b/leo/commands/new.rs index df9a92e376..fe4096d062 100644 --- a/leo/commands/new.rs +++ b/leo/commands/new.rs @@ -63,7 +63,7 @@ impl Command for New { // Create the package directory fs::create_dir_all(&path).map_err(|err| anyhow!("Could not create directory {}", err))?; - LeoPackage::initialize(&package_name, false, &path, username)?; + LeoPackage::initialize(&package_name, &path, username)?; Ok(()) } diff --git a/leo/commands/setup.rs b/leo/commands/setup.rs index 2553129f7d..5a474c9867 100644 --- a/leo/commands/setup.rs +++ b/leo/commands/setup.rs @@ -58,8 +58,7 @@ impl Command for Setup { let package_name = context.manifest()?.get_package_name(); // Check if leo build failed - let (program, checksum_differs) = - input.ok_or_else(|| anyhow!("Unable to build, check that main file exists"))?; + let (program, checksum_differs) = input; // Check if a proving key and verification key already exists let keys_exist = ProvingKeyFile::new(&package_name).exists_at(&path) diff --git a/leo/commands/watch.rs b/leo/commands/watch.rs index 77e9e5f304..5127433272 100644 --- a/leo/commands/watch.rs +++ b/leo/commands/watch.rs @@ -65,13 +65,8 @@ impl Command for Watch { // See changes on the write event Ok(DebouncedEvent::Write(_write)) => { match (Build {}).execute(context.clone()) { - Ok(_output) => { - tracing::info!("Built successfully"); - } - Err(e) => { - // Syntax error - tracing::error!("Error {:?}", e); - } + Ok(_output) => tracing::info!("Built successfully"), + Err(e) => tracing::error!("Error {:?}", e), }; } // Other events diff --git a/leo/tests/cmd.rs b/leo/tests/cmd.rs new file mode 100644 index 0000000000..d11aa8864f --- /dev/null +++ b/leo/tests/cmd.rs @@ -0,0 +1,122 @@ +// Copyright (C) 2019-2021 Aleo Systems Inc. +// This file is part of the Leo library. + +// The Leo library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Leo library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Leo library. If not, see . + +use assert_cmd::Command; +use std::path::PathBuf; +use testdir::testdir; + +/// Create Command from given arguments and CWD. +fn command(args: &str, cwd: Option) -> Command { + let args = args.split(" ").collect::>(); + let mut cmd = Command::cargo_bin("leo").unwrap(); + + if let Some(cwd) = cwd { + cmd.current_dir(cwd); + } + + cmd.args(args); + cmd +} + +fn expect_success(args: &str, cwd: Option) { + command(args, cwd).unwrap(); +} + +fn expect_fail(args: &str, cwd: Option) { + command(args, cwd).unwrap_err(); +} + +#[test] +fn test_global_options() { + expect_success("--path examples/pedersen-hash build", None); + expect_success("--path examples/pedersen-hash -q build", None); + expect_success("--path examples/pedersen-hash -d build", None); + + expect_fail("--path examples/no-directory-there build", None); + expect_fail("-v build", None); // no such option +} + +#[test] +fn init() { + let dir = Some(testdir!()); + + expect_success("init", dir.clone()); + expect_fail("init", dir); // can't do twice +} + +#[test] +fn init_fail() { + let dir = Some(testdir!()); // directory is named /init_fail - as test name + + expect_fail("init", Some("directory-doesnt-exist".into())); + expect_fail("init", dir); +} + +#[test] +fn new() { + let dir = Some(testdir!()); + + expect_success("new test", dir.clone()); + expect_fail("new test", dir.clone()); // duplicate + expect_fail("new wrong_name123123", dir.clone()); +} + +#[test] +fn unimplemented() { + expect_fail("lint", None); + expect_fail("deploy", None); +} + +#[test] +fn clean() { + expect_success("--path examples/pedersen-hash build", None); + expect_success("--path examples/pedersen-hash clean", None); +} + +#[test] +fn setup_prove_run_clean() { + let dir = testdir!(); + + expect_success("new setup", Some(dir.clone())); + + let dir = Some(dir.join("setup")); + + expect_success("setup", dir.clone()); + expect_success("setup", dir.clone()); + expect_success("setup --skip-key-check", dir.clone()); + expect_success("prove --skip-key-check", dir.clone()); + expect_success("run --skip-key-check", dir.clone()); + expect_success("clean", dir); +} + +#[test] +fn test_sudoku() { + let path = "examples/silly-sudoku"; + + expect_success("build", Some(path.into())); + expect_success("test", Some(path.into())); + expect_success("test -f src/lib.leo", Some(path.into())); + expect_success("test -f src/main.leo", Some(path.into())); +} + +#[test] +fn test_missing_file() { + let path = testdir!(); + + expect_success("new missing-file-test", Some(path.clone())); + std::fs::remove_file(&path.clone().join("missing-file-test/src/main.leo")).unwrap(); + expect_fail("test", Some(path.join("missing-file"))); +} diff --git a/leo/tests/mod.rs b/leo/tests/mod.rs index 7bc611f49d..fe4f9f3540 100644 --- a/leo/tests/mod.rs +++ b/leo/tests/mod.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::path::PathBuf; +mod cmd; use anyhow::Result; +use std::path::PathBuf; use crate::{ commands::{ diff --git a/package/src/lib.rs b/package/src/lib.rs index 8006282739..1ae814a303 100644 --- a/package/src/lib.rs +++ b/package/src/lib.rs @@ -33,13 +33,8 @@ pub struct LeoPackage; impl LeoPackage { /// Initializes a Leo package at the given path. - pub fn initialize( - package_name: &str, - is_lib: bool, - path: &Path, - author: Option, - ) -> Result<(), PackageError> { - package::Package::initialize(package_name, is_lib, path, author) + pub fn initialize(package_name: &str, path: &Path, author: Option) -> Result<(), PackageError> { + package::Package::initialize(package_name, path, author) } /// Returns `true` if the given Leo package name is valid. diff --git a/package/src/package.rs b/package/src/package.rs index cf09d3509c..8a7fb861e7 100644 --- a/package/src/package.rs +++ b/package/src/package.rs @@ -19,7 +19,7 @@ use crate::{ imports::ImportsDirectory, inputs::{InputFile, InputsDirectory, StateFile}, root::{Gitignore, Manifest, README}, - source::{LibraryFile, MainFile, SourceDirectory}, + source::{MainFile, SourceDirectory}, }; use serde::Deserialize; @@ -107,7 +107,7 @@ impl Package { } /// Returns `true` if a package is can be initialized at a given path. - pub fn can_initialize(package_name: &str, is_lib: bool, path: &Path) -> bool { + pub fn can_initialize(package_name: &str, path: &Path) -> bool { // Check that the package name is valid. if !Self::is_package_name_valid(package_name) { return false; @@ -122,32 +122,24 @@ impl Package { result = false; } - if is_lib { - // Check if the library file already exists. - if LibraryFile::exists_at(path) { - existing_files.push(LibraryFile::filename()); - result = false; - } - } else { - // Check if the input file already exists. - let input_file = InputFile::new(&package_name); - if input_file.exists_at(path) { - existing_files.push(input_file.filename()); - result = false; - } + // Check if the input file already exists. + let input_file = InputFile::new(&package_name); + if input_file.exists_at(path) { + existing_files.push(input_file.filename()); + result = false; + } - // Check if the state file already exists. - let state_file = StateFile::new(&package_name); - if state_file.exists_at(path) { - existing_files.push(state_file.filename()); - result = false; - } + // Check if the state file already exists. + let state_file = StateFile::new(&package_name); + if state_file.exists_at(path) { + existing_files.push(state_file.filename()); + result = false; + } - // Check if the main file already exists. - if MainFile::exists_at(path) { - existing_files.push(MainFile::filename()); - result = false; - } + // Check if the main file already exists. + if MainFile::exists_at(path) { + existing_files.push(MainFile::filename()); + result = false; } if !existing_files.is_empty() { @@ -158,7 +150,7 @@ impl Package { } /// Returns `true` if a package is initialized at the given path - pub fn is_initialized(package_name: &str, is_lib: bool, path: &Path) -> bool { + pub fn is_initialized(package_name: &str, path: &Path) -> bool { // Check that the package name is valid. if !Self::is_package_name_valid(package_name) { return false; @@ -169,43 +161,31 @@ impl Package { return false; } - if is_lib { - // Check if the library file exists. - if !LibraryFile::exists_at(&path) { - return false; - } - } else { - // Check if the input file exists. - let input_file = InputFile::new(&package_name); - if !input_file.exists_at(&path) { - return false; - } + // Check if the input file exists. + let input_file = InputFile::new(&package_name); + if !input_file.exists_at(&path) { + return false; + } - // Check if the state file exists. - let state_file = StateFile::new(&package_name); - if !state_file.exists_at(&path) { - return false; - } + // Check if the state file exists. + let state_file = StateFile::new(&package_name); + if !state_file.exists_at(&path) { + return false; + } - // Check if the main file exists. - if !MainFile::exists_at(&path) { - return false; - } + // Check if the main file exists. + if !MainFile::exists_at(&path) { + return false; } true } /// Creates a package at the given path - pub fn initialize( - package_name: &str, - is_lib: bool, - path: &Path, - author: Option, - ) -> Result<(), PackageError> { + pub fn initialize(package_name: &str, path: &Path, author: Option) -> Result<(), PackageError> { // First, verify that this directory is not already initialized as a Leo package. { - if !Self::can_initialize(package_name, is_lib, path) { + if !Self::can_initialize(package_name, path) { return Err(PackageError::FailedToInitialize( package_name.to_owned(), path.as_os_str().to_owned(), @@ -232,27 +212,21 @@ impl Package { // Create the source directory. SourceDirectory::create(&path)?; - // Create a new library or binary file. - if is_lib { - // Create the library file in the source directory. - LibraryFile::new(&package_name).write_to(&path)?; - } else { - // Create the input directory. - InputsDirectory::create(&path)?; + // Create the input directory. + InputsDirectory::create(&path)?; - // Create the input file in the inputs directory. - InputFile::new(&package_name).write_to(&path)?; + // Create the input file in the inputs directory. + InputFile::new(&package_name).write_to(&path)?; - // Create the state file in the inputs directory. - StateFile::new(&package_name).write_to(&path)?; + // Create the state file in the inputs directory. + StateFile::new(&package_name).write_to(&path)?; - // Create the main file in the source directory. - MainFile::new(&package_name).write_to(&path)?; - } + // Create the main file in the source directory. + MainFile::new(&package_name).write_to(&path)?; } // Next, verify that a valid Leo package has been initialized in this directory { - if !Self::is_initialized(package_name, is_lib, path) { + if !Self::is_initialized(package_name, path) { return Err(PackageError::FailedToInitialize( package_name.to_owned(), path.as_os_str().to_owned(), diff --git a/package/src/source/library.rs b/package/src/source/library.rs deleted file mode 100644 index 90a5193b85..0000000000 --- a/package/src/source/library.rs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -//! The `lib.leo` file. - -use crate::{errors::LibraryFileError, source::directory::SOURCE_DIRECTORY_NAME}; - -use serde::Deserialize; -use std::{borrow::Cow, fs::File, io::Write, path::Path}; - -pub static LIBRARY_FILENAME: &str = "lib.leo"; - -#[derive(Deserialize)] -pub struct LibraryFile { - pub package_name: String, -} - -impl LibraryFile { - pub fn new(package_name: &str) -> Self { - Self { - package_name: package_name.to_string(), - } - } - - pub fn filename() -> String { - format!("{}{}", SOURCE_DIRECTORY_NAME, LIBRARY_FILENAME) - } - - pub fn exists_at(path: &Path) -> bool { - let mut path = Cow::from(path); - if path.is_dir() { - if !path.ends_with(SOURCE_DIRECTORY_NAME) { - path.to_mut().push(SOURCE_DIRECTORY_NAME); - } - path.to_mut().push(LIBRARY_FILENAME); - } - path.exists() - } - - pub fn write_to(self, path: &Path) -> Result<(), LibraryFileError> { - let mut path = Cow::from(path); - if path.is_dir() { - if !path.ends_with(SOURCE_DIRECTORY_NAME) { - path.to_mut().push(SOURCE_DIRECTORY_NAME); - } - path.to_mut().push(LIBRARY_FILENAME); - } - - let mut file = File::create(&path)?; - Ok(file.write_all(self.template().as_bytes())?) - } - - fn template(&self) -> String { - format!( - r#"// The '{}' library circuit. -circuit Foo {{ - a: field -}} -"#, - self.package_name - ) - } -} diff --git a/package/src/source/mod.rs b/package/src/source/mod.rs index 3057d1a2b5..489cee59da 100644 --- a/package/src/source/mod.rs +++ b/package/src/source/mod.rs @@ -17,8 +17,5 @@ pub mod directory; pub use directory::*; -pub mod library; -pub use library::*; - pub mod main; pub use main::*; diff --git a/package/tests/initialize/initialize.rs b/package/tests/initialize/initialize.rs index 67bd922ef7..882e4ae707 100644 --- a/package/tests/initialize/initialize.rs +++ b/package/tests/initialize/initialize.rs @@ -19,7 +19,7 @@ use leo_package::{ inputs::{InputFile, InputsDirectory, StateFile}, package::Package, root::Manifest, - source::{LibraryFile, MainFile, SourceDirectory}, + source::{MainFile, SourceDirectory}, }; const TEST_PACKAGE_NAME: &str = "test-package"; @@ -29,13 +29,13 @@ fn initialize_valid_package() { let test_directory = test_dir(); // Ensure a package can be initialized at the `test_directory` - assert!(Package::can_initialize(TEST_PACKAGE_NAME, false, &test_directory)); + assert!(Package::can_initialize(TEST_PACKAGE_NAME, &test_directory)); // Initialize a package at the `test_directory` - assert!(Package::initialize(TEST_PACKAGE_NAME, false, &test_directory, None).is_ok()); + assert!(Package::initialize(TEST_PACKAGE_NAME, &test_directory, None).is_ok()); // Ensure a package is initialized at the `test_directory` - assert!(Package::is_initialized(TEST_PACKAGE_NAME, false, &test_directory)); + assert!(Package::is_initialized(TEST_PACKAGE_NAME, &test_directory)); } #[test] @@ -43,21 +43,13 @@ fn initialize_valid_package_with_author() { let test_directory = test_dir(); // Ensure a package can be initialized at the `test_directory` - assert!(Package::can_initialize(TEST_PACKAGE_NAME, false, &test_directory)); + assert!(Package::can_initialize(TEST_PACKAGE_NAME, &test_directory)); // Initialize a package at the `test_directory` - assert!( - Package::initialize( - TEST_PACKAGE_NAME, - false, - &test_directory, - Some(String::from("test_user")) - ) - .is_ok() - ); + assert!(Package::initialize(TEST_PACKAGE_NAME, &test_directory, Some(String::from("test_user"))).is_ok()); // Ensure a package is initialized at the `test_directory` - assert!(Package::is_initialized(TEST_PACKAGE_NAME, false, &test_directory)); + assert!(Package::is_initialized(TEST_PACKAGE_NAME, &test_directory)); } #[test] @@ -71,7 +63,7 @@ fn initialize_fails_with_existing_manifest() { let test_directory = test_dir(); // Ensure a package can be initialized at the `test_directory` - assert!(Package::can_initialize(TEST_PACKAGE_NAME, false, &test_directory)); + assert!(Package::can_initialize(TEST_PACKAGE_NAME, &test_directory)); // Manually add a manifest file to the `test_directory` Manifest::new(TEST_PACKAGE_NAME, None) @@ -80,28 +72,10 @@ fn initialize_fails_with_existing_manifest() { .unwrap(); // Attempt to initialize a package at the `test_directory` - assert!(Package::initialize(TEST_PACKAGE_NAME, false, &test_directory, None).is_err()); + assert!(Package::initialize(TEST_PACKAGE_NAME, &test_directory, None).is_err()); // Ensure package is not initialized at the `test_directory` - assert!(!Package::is_initialized(TEST_PACKAGE_NAME, false, &test_directory)); -} - -#[test] -fn initialize_fails_with_existing_library_file() { - let test_directory = test_dir(); - - // Ensure a package can be initialized at the `test_directory` - assert!(Package::can_initialize(TEST_PACKAGE_NAME, true, &test_directory)); - - // Manually add a source directory and a library file to the `test_directory` - SourceDirectory::create(&test_directory).unwrap(); - LibraryFile::new(TEST_PACKAGE_NAME).write_to(&test_directory).unwrap(); - - // Attempt to initialize a package at the `test_directory` - assert!(Package::initialize(TEST_PACKAGE_NAME, true, &test_directory, None).is_err()); - - // Ensure package is not initialized at the `test_directory` - assert!(!Package::is_initialized(TEST_PACKAGE_NAME, true, &test_directory)); + assert!(!Package::is_initialized(TEST_PACKAGE_NAME, &test_directory)); } #[test] @@ -109,25 +83,17 @@ fn initialize_fails_with_existing_input_file() { let test_directory = test_dir(); // Ensure a package can be initialized at the `test_directory` - assert!(Package::can_initialize(TEST_PACKAGE_NAME, false, &test_directory)); + assert!(Package::can_initialize(TEST_PACKAGE_NAME, &test_directory)); // Manually add an inputs directory and an input file to the `test_directory` InputsDirectory::create(&test_directory).unwrap(); InputFile::new(TEST_PACKAGE_NAME).write_to(&test_directory).unwrap(); // Attempt to initialize a package at the `test_directory` - assert!( - Package::initialize( - TEST_PACKAGE_NAME, - false, - &test_directory, - Some(String::from("test_user")) - ) - .is_err() - ); + assert!(Package::initialize(TEST_PACKAGE_NAME, &test_directory, Some(String::from("test_user"))).is_err()); // Ensure package is not initialized at the `test_directory` - assert!(!Package::is_initialized(TEST_PACKAGE_NAME, false, &test_directory)); + assert!(!Package::is_initialized(TEST_PACKAGE_NAME, &test_directory)); } #[test] @@ -135,17 +101,17 @@ fn initialize_fails_with_existing_state_file() { let test_directory = test_dir(); // Ensure a package can be initialized at the `test_directory` - assert!(Package::can_initialize(TEST_PACKAGE_NAME, false, &test_directory)); + assert!(Package::can_initialize(TEST_PACKAGE_NAME, &test_directory)); // Manually add an inputs directory and a state file to the `test_directory` InputsDirectory::create(&test_directory).unwrap(); StateFile::new(TEST_PACKAGE_NAME).write_to(&test_directory).unwrap(); // Attempt to initialize a package at the `test_directory` - assert!(Package::initialize(TEST_PACKAGE_NAME, false, &test_directory, None).is_err()); + assert!(Package::initialize(TEST_PACKAGE_NAME, &test_directory, None).is_err()); // Ensure package is not initialized at the `test_directory` - assert!(!Package::is_initialized(TEST_PACKAGE_NAME, false, &test_directory)); + assert!(!Package::is_initialized(TEST_PACKAGE_NAME, &test_directory)); } #[test] @@ -153,15 +119,15 @@ fn initialize_fails_with_existing_main_file() { let test_directory = test_dir(); // Ensure a package can be initialized at the `test_directory` - assert!(Package::can_initialize(TEST_PACKAGE_NAME, false, &test_directory)); + assert!(Package::can_initialize(TEST_PACKAGE_NAME, &test_directory)); // Manually add a source directory and a main file to the `test_directory` SourceDirectory::create(&test_directory).unwrap(); MainFile::new(TEST_PACKAGE_NAME).write_to(&test_directory).unwrap(); // Attempt to initialize a package at the `test_directory` - assert!(Package::initialize(TEST_PACKAGE_NAME, false, &test_directory, None).is_err()); + assert!(Package::initialize(TEST_PACKAGE_NAME, &test_directory, None).is_err()); // Ensure package is not initialized at the `test_directory` - assert!(!Package::is_initialized(TEST_PACKAGE_NAME, false, &test_directory)); + assert!(!Package::is_initialized(TEST_PACKAGE_NAME, &test_directory)); }