From 382f7868c6dfdfbb187f8c1e4753180e04319a54 Mon Sep 17 00:00:00 2001 From: Jordan Last Date: Wed, 13 Sep 2023 12:58:27 -0500 Subject: [PATCH] update the persistent_storage example --- .../persistent-storage/Cargo.lock | 954 ------------------ .../persistent-storage/Cargo.toml | 9 - .../persistent-storage/benchmark/benchmark.ts | 25 - .../persistent-storage/benchmarks.csv | 3 - .../persistent-storage/benchmarks.md | 87 -- .../canisters/azle/index.did | 7 - .../canisters/azle/index.ts | 88 -- .../canisters/motoko/main.mo | 47 - .../canisters/rust/Cargo.toml | 12 - .../canisters/rust/src/lib.did | 11 - .../canisters/rust/src/lib.rs | 69 -- .../persistent-storage/dfx.json | 31 +- .../persistent-storage/package-lock.json | 238 +++-- .../persistent-storage/package.json | 9 +- .../persistent-storage/src/index.did | 5 + .../persistent-storage/src/index.ts | 56 + .../persistent-storage/test/pretest.ts | 6 +- .../persistent-storage/test/test.ts | 13 +- .../persistent-storage/test/tests.ts | 20 +- 19 files changed, 267 insertions(+), 1423 deletions(-) delete mode 100644 examples/motoko_examples/persistent-storage/Cargo.lock delete mode 100644 examples/motoko_examples/persistent-storage/Cargo.toml delete mode 100644 examples/motoko_examples/persistent-storage/benchmark/benchmark.ts delete mode 100644 examples/motoko_examples/persistent-storage/benchmarks.csv delete mode 100644 examples/motoko_examples/persistent-storage/benchmarks.md delete mode 100644 examples/motoko_examples/persistent-storage/canisters/azle/index.did delete mode 100644 examples/motoko_examples/persistent-storage/canisters/azle/index.ts delete mode 100644 examples/motoko_examples/persistent-storage/canisters/motoko/main.mo delete mode 100644 examples/motoko_examples/persistent-storage/canisters/rust/Cargo.toml delete mode 100644 examples/motoko_examples/persistent-storage/canisters/rust/src/lib.did delete mode 100644 examples/motoko_examples/persistent-storage/canisters/rust/src/lib.rs create mode 100644 examples/motoko_examples/persistent-storage/src/index.did create mode 100644 examples/motoko_examples/persistent-storage/src/index.ts diff --git a/examples/motoko_examples/persistent-storage/Cargo.lock b/examples/motoko_examples/persistent-storage/Cargo.lock deleted file mode 100644 index 36b3c8cab2..0000000000 --- a/examples/motoko_examples/persistent-storage/Cargo.lock +++ /dev/null @@ -1,954 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "aho-corasick" -version = "0.7.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" -dependencies = [ - "memchr", -] - -[[package]] -name = "anyhow" -version = "1.0.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" - -[[package]] -name = "arrayvec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" - -[[package]] -name = "ascii-canvas" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6" -dependencies = [ - "term", -] - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "beef" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" - -[[package]] -name = "binread" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16598dfc8e6578e9b597d9910ba2e73618385dc9f4b1d43dd92c349d6be6418f" -dependencies = [ - "binread_derive", - "lazy_static", - "rustversion", -] - -[[package]] -name = "binread_derive" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d9672209df1714ee804b1f4d4f68c8eb2a90b1f7a07acf472f88ce198ef1fed" -dependencies = [ - "either", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "bit-set" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" -dependencies = [ - "bit-vec", -] - -[[package]] -name = "bit-vec" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "block-buffer" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" -dependencies = [ - "generic-array", -] - -[[package]] -name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" - -[[package]] -name = "candid" -version = "0.7.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4f5cdd24185c6d6edba09bcfe06cf9c1e7fd579cbe5e4ae2dffba9c474a5a7f" -dependencies = [ - "anyhow", - "binread", - "byteorder", - "candid_derive", - "codespan-reporting", - "hex", - "ic-types", - "lalrpop", - "lalrpop-util", - "leb128", - "logos", - "num-bigint", - "num-traits", - "num_enum", - "paste", - "pretty", - "serde", - "serde_bytes", - "thiserror", -] - -[[package]] -name = "candid_derive" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e02c03c4d547674a3f3f3109538fb49871fbe636216daa019f06a62faca9061" -dependencies = [ - "lazy_static", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "codespan-reporting" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" -dependencies = [ - "termcolor", - "unicode-width", -] - -[[package]] -name = "cpufeatures" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" -dependencies = [ - "libc", -] - -[[package]] -name = "crc32fast" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "data-encoding" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" - -[[package]] -name = "diff" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" - -[[package]] -name = "digest" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" -dependencies = [ - "block-buffer", - "crypto-common", -] - -[[package]] -name = "dirs-next" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" -dependencies = [ - "cfg-if", - "dirs-sys-next", -] - -[[package]] -name = "dirs-sys-next" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - -[[package]] -name = "either" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" - -[[package]] -name = "ena" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7402b94a93c24e742487327a7cd839dc9d36fec9de9fb25b09f2dae459f36c3" -dependencies = [ - "log", -] - -[[package]] -name = "fixedbitset" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "generic-array" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getrandom" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "ic-cdk" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "141341c2cb26c4e5f196d5b64305c677b1abebe093eefbe2c622b4a2e6de8a9f" -dependencies = [ - "candid", - "cfg-if", - "serde", -] - -[[package]] -name = "ic-cdk-macros" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5196f57df320b206129d4aae96a0cea72ea2759a5c82651bbb60d721f834998" -dependencies = [ - "candid", - "ic-cdk", - "proc-macro2", - "quote", - "serde", - "serde_tokenstream", - "syn", -] - -[[package]] -name = "ic-types" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e9cac29df1f2906137c327ed24dfc398460eda054abaa6107273c11afe6384" -dependencies = [ - "crc32fast", - "data-encoding", - "hex", - "serde", - "serde_bytes", - "sha2", - "thiserror", -] - -[[package]] -name = "indexmap" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" -dependencies = [ - "autocfg", - "hashbrown", -] - -[[package]] -name = "itertools" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" -dependencies = [ - "either", -] - -[[package]] -name = "lalrpop" -version = "0.19.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b30455341b0e18f276fa64540aff54deafb54c589de6aca68659c63dd2d5d823" -dependencies = [ - "ascii-canvas", - "atty", - "bit-set", - "diff", - "ena", - "itertools", - "lalrpop-util", - "petgraph", - "pico-args", - "regex", - "regex-syntax", - "string_cache", - "term", - "tiny-keccak", - "unicode-xid", -] - -[[package]] -name = "lalrpop-util" -version = "0.19.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf796c978e9b4d983414f4caedc9273aa33ee214c5b887bd55fde84c85d2dc4" -dependencies = [ - "regex", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "libc" -version = "0.2.126" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" - -[[package]] -name = "lock_api" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "logos" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf8b031682c67a8e3d5446840f9573eb7fe26efe7ec8d195c9ac4c0647c502f1" -dependencies = [ - "logos-derive", -] - -[[package]] -name = "logos-derive" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d849148dbaf9661a6151d1ca82b13bb4c4c128146a88d05253b38d4e2f496c" -dependencies = [ - "beef", - "fnv", - "proc-macro2", - "quote", - "regex-syntax", - "syn", -] - -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "new_debug_unreachable" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" - -[[package]] -name = "num-bigint" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" -dependencies = [ - "autocfg", -] - -[[package]] -name = "num_enum" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf5395665662ef45796a4ff5486c5d41d29e0c09640af4c5f17fd94ee2c119c9" -dependencies = [ - "num_enum_derive", -] - -[[package]] -name = "num_enum_derive" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b0498641e53dd6ac1a4f22547548caa6864cc4933784319cd1775271c5a46ce" -dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "once_cell" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" - -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-sys", -] - -[[package]] -name = "paste" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc" - -[[package]] -name = "petgraph" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5014253a1331579ce62aa67443b4a658c5e7dd03d4bc6d302b94474888143" -dependencies = [ - "fixedbitset", - "indexmap", -] - -[[package]] -name = "phf_shared" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" -dependencies = [ - "siphasher", -] - -[[package]] -name = "pico-args" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468" - -[[package]] -name = "precomputed-hash" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" - -[[package]] -name = "pretty" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad9940b913ee56ddd94aec2d3cd179dd47068236f42a1a6415ccf9d880ce2a61" -dependencies = [ - "arrayvec", - "typed-arena", -] - -[[package]] -name = "proc-macro-crate" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a" -dependencies = [ - "thiserror", - "toml", -] - -[[package]] -name = "proc-macro2" -version = "1.0.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c278e965f1d8cf32d6e0e96de3d3e79712178ae67986d9cf9151f51e95aac89b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags", -] - -[[package]] -name = "redox_users" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" -dependencies = [ - "getrandom", - "redox_syscall", - "thiserror", -] - -[[package]] -name = "regex" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.6.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" - -[[package]] -name = "rust" -version = "0.0.0" -dependencies = [ - "candid", - "ic-cdk", - "ic-cdk-macros", -] - -[[package]] -name = "rustversion" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24c8ad4f0c00e1eb5bc7614d236a7f1300e3dbd76b68cac8e06fb00b015ad8d8" - -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "serde" -version = "1.0.140" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc855a42c7967b7c369eb5860f7164ef1f6f81c20c7cc1141f2a604e18723b03" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_bytes" -version = "0.11.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212e73464ebcde48d723aa02eb270ba62eff38a9b732df31f33f1b4e145f3a54" -dependencies = [ - "serde", -] - -[[package]] -name = "serde_derive" -version = "1.0.140" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2122636b9fe3b81f1cb25099fcf2d3f542cdb1d45940d56c713158884a05da" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_tokenstream" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6deb15c3a535e81438110111d90168d91721652f502abb147f31cde129f683d" -dependencies = [ - "proc-macro2", - "serde", - "syn", -] - -[[package]] -name = "sha2" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "siphasher" -version = "0.3.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" - -[[package]] -name = "smallvec" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" - -[[package]] -name = "string_cache" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213494b7a2b503146286049378ce02b482200519accc31872ee8be91fa820a08" -dependencies = [ - "new_debug_unreachable", - "once_cell", - "parking_lot", - "phf_shared", - "precomputed-hash", -] - -[[package]] -name = "syn" -version = "1.0.98" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "term" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" -dependencies = [ - "dirs-next", - "rustversion", - "winapi", -] - -[[package]] -name = "termcolor" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "thiserror" -version = "1.0.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tiny-keccak" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" -dependencies = [ - "crunchy", -] - -[[package]] -name = "toml" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" -dependencies = [ - "serde", -] - -[[package]] -name = "typed-arena" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0685c84d5d54d1c26f7d3eb96cd41550adb97baed141a761cf335d3d33bcd0ae" - -[[package]] -name = "typenum" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" - -[[package]] -name = "unicode-ident" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" - -[[package]] -name = "unicode-width" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" - -[[package]] -name = "unicode-xid" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" -dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" - -[[package]] -name = "windows_i686_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" - -[[package]] -name = "windows_i686_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" diff --git a/examples/motoko_examples/persistent-storage/Cargo.toml b/examples/motoko_examples/persistent-storage/Cargo.toml deleted file mode 100644 index 4513438de5..0000000000 --- a/examples/motoko_examples/persistent-storage/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[workspace] -members = [ - "canisters/rust", -] - -[profile.release] -lto = true -opt-level = 'z' -codegen-units = 1 diff --git a/examples/motoko_examples/persistent-storage/benchmark/benchmark.ts b/examples/motoko_examples/persistent-storage/benchmark/benchmark.ts deleted file mode 100644 index 2306004ff0..0000000000 --- a/examples/motoko_examples/persistent-storage/benchmark/benchmark.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Benchmark, run_benchmarks } from 'azle/benchmark'; -import { createActor as createActorAzle } from '../dfx_generated/azle'; -import { createActor as createActorMotoko } from '../dfx_generated/motoko'; -import { createActor as createActorRust } from '../dfx_generated/rust'; - -const benchmarks: Benchmark[] = [ - { - canister_method: 'increment', - args: [] - }, - { - canister_method: 'reset', - args: [] - } -]; - -run_benchmarks( - 'GLOBAL_VALUE', - benchmarks, - createActorAzle, - createActorMotoko, - createActorRust, - 10, - `benchmarks` -); diff --git a/examples/motoko_examples/persistent-storage/benchmarks.csv b/examples/motoko_examples/persistent-storage/benchmarks.csv deleted file mode 100644 index 9068a2740d..0000000000 --- a/examples/motoko_examples/persistent-storage/benchmarks.csv +++ /dev/null @@ -1,3 +0,0 @@ -Description,Azle Wasm Instructions (function body only),Azle Wasm Instructions (function prelude and body),Motoko Wasm Instructions (function body only),Motoko Wasm Instructions (function prelude and body),Rust Wasm Instructions (function body only),Rust Wasm Instructions (function prelude and body),Azle/Motoko Change Multiplier (function body only),Azle/Motoko Change Multiplier (function prelude and body),Azle/Rust Change Multiplier (function body only),Azle/Rust Change Multiplier (function prelude and body),Motoko/Azle Change Multiplier (function body only),Motoko/Azle Change Multiplier (function prelude and body),Motoko/Rust Change Multiplier (function body only),Motoko/Rust Change Multiplier (function prelude and body),Rust/Azle Change Multiplier (function body only),Rust/Azle Change Multiplier (function prelude and body),Rust/Motoko Change Multiplier (function body only),Rust/Motoko Change Multiplier (function prelude and body) -increment,179984,711986,226,1359,120562,139261,796,524,1,5,-796,-524,-533,-102,-1,-5,533,102 -reset,144461,892879,200,1330,17896,36523,722,671,8,24,-722,-671,-89,-27,-8,-24,89,27 diff --git a/examples/motoko_examples/persistent-storage/benchmarks.md b/examples/motoko_examples/persistent-storage/benchmarks.md deleted file mode 100644 index a6381e58b7..0000000000 --- a/examples/motoko_examples/persistent-storage/benchmarks.md +++ /dev/null @@ -1,87 +0,0 @@ -# Azle/Motoko/Rust Benchmarks - -- These benchmarks should be considered preliminary (especially the Motoko benchmarks, something seems off with the function prelude) -- These benchmarks were implemented using the performance counter API - - Performance counter information in [The Internet Computer Interface Spec](https://internetcomputer.org/docs/current/references/ic-interface-spec/#system-api-imports) - - Performance counter information in [the forum](https://forum.dfinity.org/t/introducing-performance-counter-on-the-internet-computer/14027) -- Each benchmark is the average of 10 runs -- The following may be inaccurate or missing from the benchmarks as described [here](https://forum.dfinity.org/t/introducing-performance-counter-on-the-internet-computer/14027): - - Candid serialization/deserialization of function parameters and return types - - Canister method prologue/epilogue - - Some Motoko runtime behavior (such as garbage collection) -- You can find a raw CSV file with this data [here](./benchmarks.csv) -- A rough USD cost model for various app scenarios can be found [here](https://docs.google.com/spreadsheets/d/1PQ53R9hYE1fuMB_z-Bl6dyymm7end7rVJ85TvGEh0BQ) - -The format for benchmark numbers is (x / y) where: - -- x = Wasm instructions counted only in the function body -- y = Wasm instructions counted in the function body and the function prelude - -## USD Cost Estimates Per Year - -These estimates use the average Wasm instructions per update function call including the function prelude from the benchmarks below. - -The Wasm instruction counts used are: - -- Azle: 802_433 -- Motoko: 1_345 -- Rust: 87_892 - -### Application Scenarios - -| Usage | Query/Update Heaviness | Ingress Bytes Per Query Message | Ingress Bytes Per Update Message | GB Storage | Query Messages Per Second | Update Messages Per Second | Xnet Calls Per Second | Xnet Call Bytes | -| -------- | ---------------------- | ------------------------------- | -------------------------------- | ---------- | ------------------------- | -------------------------- | --------------------- | --------------- | -| Light | Even | 100 | 100 | 0.5 | 0.01 | 0.01 | 0.001 | 20 | -| Light | Query Heavy | 100 | 100 | 0.5 | 0.01 | 0.0001 | 0.001 | 20 | -| Light | Update Heavy | 100 | 100 | 0.5 | 0.0001 | 0.01 | 0.001 | 20 | -| Moderate | Even | 1_000 | 1_000 | 1 | 1 | 1 | 0.1 | 200 | -| Moderate | Query Heavy | 1_000 | 1_000 | 1 | 1 | 0.01 | 0.1 | 200 | -| Moderate | Update Heavy | 1_000 | 1_000 | 1 | 0.01 | 1 | 0.1 | 200 | -| Heavy | Even | 10_000 | 10_000 | 2 | 100 | 100 | 10 | 2_000 | -| Heavy | Query Heavy | 10_000 | 10_000 | 2 | 100 | 1 | 10 | 2_000 | -| Heavy | Update Heavy | 10_000 | 10_000 | 2 | 1 | 100 | 10 | 2_000 | - -### Application USD Cost Estimates Per Year - -| Usage | Query/Update Heaviness | CDK | Ingress Messages | Ingress Bytes Query Messages | Ingress Bytes Update Messages | Update Messages | Update Instructions | Xnet Calls | Xnet Byte Transmission | GB Storage | Total Cost | -| -------- | ---------------------- | ------ | ---------------- | ---------------------------- | ----------------------------- | --------------- | ------------------- | ---------- | ---------------------- | ---------- | ----------- | -| Light | Even | Azle | $1.00 | $0.08 | $0.08 | $0.25 | $0.13 | $0.01 | $0.00 | $2.64 | $4.20 | -| Light | Even | Motoko | $1.00 | $0.08 | $0.08 | $0.25 | $0.00 | $0.01 | $0.00 | $2.64 | $4.07 | -| Light | Even | Rust | $1.00 | $0.08 | $0.08 | $0.25 | $0.01 | $0.01 | $0.00 | $2.64 | $4.08 | -| Light | Query Heavy | Azle | $0.50 | $0.08 | $0.00 | $0.00 | $0.00 | $0.01 | $0.00 | $2.64 | $3.25 | -| Light | Query Heavy | Motoko | $0.50 | $0.08 | $0.00 | $0.00 | $0.00 | $0.01 | $0.00 | $2.64 | $3.25 | -| Light | Query Heavy | Rust | $0.50 | $0.08 | $0.00 | $0.00 | $0.00 | $0.01 | $0.00 | $2.64 | $3.25 | -| Light | Update Heavy | Azle | $0.50 | $0.00 | $0.08 | $0.25 | $0.13 | $0.01 | $0.00 | $2.64 | $3.62 | -| Light | Update Heavy | Motoko | $0.50 | $0.00 | $0.08 | $0.25 | $0.00 | $0.01 | $0.00 | $2.64 | $3.49 | -| Light | Update Heavy | Rust | $0.50 | $0.00 | $0.08 | $0.25 | $0.01 | $0.01 | $0.00 | $2.64 | $3.50 | -| Moderate | Even | Azle | $99.91 | $83.26 | $83.26 | $24.56 | $13.36 | $1.08 | $0.83 | $5.29 | $311.54 | -| Moderate | Even | Motoko | $99.91 | $83.26 | $83.26 | $24.56 | $0.02 | $1.08 | $0.83 | $5.29 | $298.20 | -| Moderate | Even | Rust | $99.91 | $83.26 | $83.26 | $24.56 | $1.46 | $1.08 | $0.83 | $5.29 | $299.64 | -| Moderate | Query Heavy | Azle | $50.45 | $83.26 | $0.83 | $0.25 | $0.13 | $1.08 | $0.83 | $5.29 | $142.12 | -| Moderate | Query Heavy | Motoko | $50.45 | $83.26 | $0.83 | $0.25 | $0.00 | $1.08 | $0.83 | $5.29 | $141.99 | -| Moderate | Query Heavy | Rust | $50.45 | $83.26 | $0.83 | $0.25 | $0.01 | $1.08 | $0.83 | $5.29 | $142.00 | -| Moderate | Update Heavy | Azle | $50.45 | $0.83 | $83.26 | $24.56 | $13.36 | $1.08 | $0.83 | $5.29 | $179.66 | -| Moderate | Update Heavy | Motoko | $50.45 | $0.83 | $83.26 | $24.56 | $0.02 | $1.08 | $0.83 | $5.29 | $166.32 | -| Moderate | Update Heavy | Rust | $50.45 | $0.83 | $83.26 | $24.56 | $1.46 | $1.08 | $0.83 | $5.29 | $167.77 | -| Heavy | Even | Azle | $9,990.60 | $83,255.04 | $83,255.04 | $2,456.02 | $1,336.13 | $108.23 | $832.55 | $10.57 | $181,244.19 | -| Heavy | Even | Motoko | $9,990.60 | $83,255.04 | $83,255.04 | $2,456.02 | $2.24 | $108.23 | $832.55 | $10.57 | $179,910.30 | -| Heavy | Even | Rust | $9,990.60 | $83,255.04 | $83,255.04 | $2,456.02 | $146.35 | $108.23 | $832.55 | $10.57 | $180,054.41 | -| Heavy | Query Heavy | Azle | $5,045.26 | $83,255.04 | $832.55 | $24.56 | $13.36 | $108.23 | $832.55 | $10.57 | $90,122.12 | -| Heavy | Query Heavy | Motoko | $5,045.26 | $83,255.04 | $832.55 | $24.56 | $0.02 | $108.23 | $832.55 | $10.57 | $90,108.78 | -| Heavy | Query Heavy | Rust | $5,045.26 | $83,255.04 | $832.55 | $24.56 | $1.46 | $108.23 | $832.55 | $10.57 | $90,110.22 | -| Heavy | Update Heavy | Azle | $5,045.26 | $832.55 | $83,255.04 | $2,456.02 | $1,336.13 | $108.23 | $832.55 | $10.57 | $93,876.36 | -| Heavy | Update Heavy | Motoko | $5,045.26 | $832.55 | $83,255.04 | $2,456.02 | $2.24 | $108.23 | $832.55 | $10.57 | $92,542.46 | -| Heavy | Update Heavy | Rust | $5,045.26 | $832.55 | $83,255.04 | $2,456.02 | $146.35 | $108.23 | $832.55 | $10.57 | $92,686.57 | - -## Averages - -| Azle Wasm Instructions | Motoko Wasm Instructions | Rust Wasm Instructions | Azle/Motoko Change Multiplier | Azle/Rust Change Multiplier | Motoko/Azle Change Multiplier | Motoko/Rust Change Multiplier | Rust/Azle Change Multiplier | Rust/Motoko Change Multiplier | -| ---------------------- | ------------------------ | ---------------------- | ----------------------------- | --------------------------- | ----------------------------- | ----------------------------- | --------------------------- | ----------------------------- | -| (162_222 / 802_433) | (213 / 1_345) | (69_229 / 87_892) | (759x / 598x) | (5x / 15x) | (-759x / -598x) | (-311x / -65x) | (-5x / -15x) | (311x / 65x) | - -## Benchmarks - -| Description | Azle Wasm Instructions | Motoko Wasm Instructions | Rust Wasm Instructions | Azle/Motoko Change Multiplier | Azle/Rust Change Multiplier | Motoko/Azle Change Multiplier | Motoko/Rust Change Multiplier | Rust/Azle Change Multiplier | Rust/Motoko Change Multiplier | -| ----------- | ---------------------- | ------------------------ | ---------------------- | ----------------------------- | --------------------------- | ----------------------------- | ----------------------------- | --------------------------- | ----------------------------- | -| increment | (179_984 / 711_986) | (226 / 1_359) | (120_562 / 139_261) | (796x / 524x) | (1x / 5x) | (-796x / -524x) | (-533x / -102x) | (-1x / -5x) | (533x / 102x) | -| reset | (144_461 / 892_879) | (200 / 1_330) | (17_896 / 36_523) | (722x / 671x) | (8x / 24x) | (-722x / -671x) | (-89x / -27x) | (-8x / -24x) | (89x / 27x) | diff --git a/examples/motoko_examples/persistent-storage/canisters/azle/index.did b/examples/motoko_examples/persistent-storage/canisters/azle/index.did deleted file mode 100644 index 1ddd48c411..0000000000 --- a/examples/motoko_examples/persistent-storage/canisters/azle/index.did +++ /dev/null @@ -1,7 +0,0 @@ -type PerfResult = record { wasmBodyOnly : nat64; wasmIncludingPrelude : nat64 }; -service : () -> { - get : () -> (nat) query; - getPerfResult : () -> (opt PerfResult) query; - increment : () -> (nat); - reset : () -> (nat); -} \ No newline at end of file diff --git a/examples/motoko_examples/persistent-storage/canisters/azle/index.ts b/examples/motoko_examples/persistent-storage/canisters/azle/index.ts deleted file mode 100644 index 256b12db5a..0000000000 --- a/examples/motoko_examples/persistent-storage/canisters/azle/index.ts +++ /dev/null @@ -1,88 +0,0 @@ -import { - ic, - $init, - match, - nat, - nat64, - Opt, - $query, - Record, - StableBTreeMap, - $update -} from 'azle'; - -//#region Performance -type PerfResult = Record<{ - wasmBodyOnly: nat64; - wasmIncludingPrelude: nat64; -}>; - -let perfResult: Opt = Opt.None; - -$query; -export function getPerfResult(): Opt { - return perfResult; -} - -function recordPerformance(start: nat64, end: nat64): void { - perfResult = Opt.Some({ - wasmBodyOnly: end - start, - wasmIncludingPrelude: ic.performanceCounter(0) - }); -} -//#endregion - -let stableStorage = new StableBTreeMap(0, 25, 1_000); - -$init; -export function init(): void { - stableStorage.insert('counter', 0n); -} - -$update; -export function increment(): nat { - const perfStart = ic.performanceCounter(0); - - stableStorage.insert( - 'counter', - match(stableStorage.get('counter'), { - Some: (x) => x, - None: () => 0n - }) + 1n - ); - const result = match(stableStorage.get('counter'), { - Some: (x) => x, - None: () => 0n - }); - - const perfEnd = ic.performanceCounter(0); - - recordPerformance(perfStart, perfEnd); - - return result; -} - -$query; -export function get(): nat { - return match(stableStorage.get('counter'), { - Some: (x) => x, - None: () => 0n - }); -} - -$update; -export function reset(): nat { - const perfStart = ic.performanceCounter(0); - - stableStorage.insert('counter', 0n); - const result = match(stableStorage.get('counter'), { - Some: (x) => x, - None: () => 0n - }); - - const perfEnd = ic.performanceCounter(0); - - recordPerformance(perfStart, perfEnd); - - return result; -} diff --git a/examples/motoko_examples/persistent-storage/canisters/motoko/main.mo b/examples/motoko_examples/persistent-storage/canisters/motoko/main.mo deleted file mode 100644 index db4727f142..0000000000 --- a/examples/motoko_examples/persistent-storage/canisters/motoko/main.mo +++ /dev/null @@ -1,47 +0,0 @@ -import Prim "mo:⛔"; - -actor { - //#region Performance - type PerfResult = { - wasm_body_only: Nat64; - wasm_including_prelude: Nat64; - }; - - var perf_result: ?PerfResult = null; - - public query func get_perf_result(): async ?PerfResult { - return perf_result; - }; - - func record_performance(start: Nat64, end: Nat64) { - perf_result := ?{ - wasm_body_only = end - start; - wasm_including_prelude = Prim.performanceCounter(0); - }; - }; - //#endregion - - stable var counter : Nat = 0; - - public func increment() : async Nat { - let perf_start = Prim.performanceCounter(0); - counter += 1; - let perf_end = Prim.performanceCounter(0); - - record_performance(perf_start, perf_end); - return counter; - }; - - public query func get() : async Nat { - return counter; - }; - - public func reset() : async Nat { - let perf_start = Prim.performanceCounter(0); - counter := 0; - let perf_end = Prim.performanceCounter(0); - - record_performance(perf_start, perf_end); - return counter; - }; -}; diff --git a/examples/motoko_examples/persistent-storage/canisters/rust/Cargo.toml b/examples/motoko_examples/persistent-storage/canisters/rust/Cargo.toml deleted file mode 100644 index f6d792e880..0000000000 --- a/examples/motoko_examples/persistent-storage/canisters/rust/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "rust" -version = "0.0.0" -edition = "2018" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -ic-cdk = "0.5.2" -ic-cdk-macros = "0.5.2" -candid = "0.7.14" diff --git a/examples/motoko_examples/persistent-storage/canisters/rust/src/lib.did b/examples/motoko_examples/persistent-storage/canisters/rust/src/lib.did deleted file mode 100644 index 0068821740..0000000000 --- a/examples/motoko_examples/persistent-storage/canisters/rust/src/lib.did +++ /dev/null @@ -1,11 +0,0 @@ -type PerfResult = record { - "wasm_body_only": nat64; - "wasm_including_prelude": nat64; -}; - -service: () -> { - "get_perf_result": () -> (opt PerfResult) query; - "get": () -> (nat) query; - "increment": () -> (nat); - "reset": () -> (nat); -} diff --git a/examples/motoko_examples/persistent-storage/canisters/rust/src/lib.rs b/examples/motoko_examples/persistent-storage/canisters/rust/src/lib.rs deleted file mode 100644 index f6a30a62bc..0000000000 --- a/examples/motoko_examples/persistent-storage/canisters/rust/src/lib.rs +++ /dev/null @@ -1,69 +0,0 @@ -use std::cell::RefCell; -use candid::Nat; - -//#region Performance -#[derive(candid::CandidType, Clone)] -pub struct PerfResult { - wasm_body_only: u64, - wasm_including_prelude: u64 -} - -thread_local! { - static PERF_RESULT_REF_CELL: RefCell> = RefCell::default(); -} - -#[ic_cdk_macros::query] -pub fn get_perf_result() -> Option { - PERF_RESULT_REF_CELL.with(|perf_result_ref_cell| perf_result_ref_cell.borrow().as_ref().cloned()) -} - -fn record_performance(start: u64, end: u64) { - PERF_RESULT_REF_CELL.with(|perf_result_ref_cell| { - let mut perf_result = perf_result_ref_cell.borrow_mut(); - - *perf_result = Some(PerfResult { - wasm_body_only: end - start, - wasm_including_prelude: ic_cdk::api::call::performance_counter(0) - }) - }); -} -//#endregion - -#[ic_cdk_macros::init] -pub fn init() { - ic_cdk::storage::stable_save((Nat::from(0),)).unwrap(); -} - -#[ic_cdk_macros::update] -pub fn increment() -> Nat { - let perf_start = ic_cdk::api::call::performance_counter(0); - - let stable_storage: (Nat,) = ic_cdk::storage::stable_restore().unwrap(); - let counter = stable_storage.0 + Nat::from(1); - ic_cdk::storage::stable_save((counter.clone(),)).unwrap(); - - let perf_end = ic_cdk::api::call::performance_counter(0); - - record_performance(perf_start, perf_end); - counter -} - -#[ic_cdk_macros::query] -pub fn get() -> Nat { - let stable_storage: (Nat,) = ic_cdk::storage::stable_restore().unwrap(); - stable_storage.0 -} - -#[ic_cdk_macros::update] -pub fn reset() -> Nat { - let perf_start = ic_cdk::api::call::performance_counter(0); - - let counter: Nat = Nat::from(0); - ic_cdk::storage::stable_save((counter.clone(),)).unwrap(); - - let perf_end = ic_cdk::api::call::performance_counter(0); - - record_performance(perf_start, perf_end); - - counter -} diff --git a/examples/motoko_examples/persistent-storage/dfx.json b/examples/motoko_examples/persistent-storage/dfx.json index f83e6b87b2..644cad79d9 100644 --- a/examples/motoko_examples/persistent-storage/dfx.json +++ b/examples/motoko_examples/persistent-storage/dfx.json @@ -1,31 +1,14 @@ { "canisters": { - "azle": { + "persistent_storage": { "type": "custom", - "build": "npx azle azle", - "root": "canisters/azle", - "ts": "canisters/azle/index.ts", - "candid": "canisters/azle/index.did", - "wasm": ".azle/azle/azle.wasm.gz", + "build": "npx azle persistent_storage", + "root": "src", + "ts": "src/index.ts", + "candid": "src/index.did", + "wasm": ".azle/persistent_storage/persistent_storage.wasm.gz", "declarations": { - "output": "dfx_generated/azle", - "node_compatibility": true - } - }, - "motoko": { - "type": "motoko", - "main": "canisters/motoko/main.mo", - "declarations": { - "output": "dfx_generated/motoko", - "node_compatibility": true - } - }, - "rust": { - "type": "rust", - "package": "rust", - "candid": "canisters/rust/src/lib.did", - "declarations": { - "output": "dfx_generated/rust", + "output": "test/dfx_generated/persistent_storage", "node_compatibility": true } } diff --git a/examples/motoko_examples/persistent-storage/package-lock.json b/examples/motoko_examples/persistent-storage/package-lock.json index fa2b41d5ea..a7e060b9d4 100644 --- a/examples/motoko_examples/persistent-storage/package-lock.json +++ b/examples/motoko_examples/persistent-storage/package-lock.json @@ -8,9 +8,9 @@ "azle": "0.17.1" }, "devDependencies": { - "@dfinity/agent": "0.11.1", - "ts-node": "10.7.0", - "typescript": "4.6.3" + "@dfinity/agent": "^0.19.2", + "ts-node": "^10.9.1", + "typescript": "^5.2.2" } }, "node_modules/@cspotcode/source-map-consumer": { @@ -33,33 +33,77 @@ } }, "node_modules/@dfinity/agent": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/@dfinity/agent/-/agent-0.11.1.tgz", - "integrity": "sha512-Z1zw8l3d+AG3uu7d8G/Rd9Q5MWT9gB+Cori/Rqb6IjSEribRhL36ulCSkDYZJU/dhqSUp1VlvX5u51+wgv+MLg==", + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/@dfinity/agent/-/agent-0.19.2.tgz", + "integrity": "sha512-KLRWEjeU9SyyaS7IBVJ9ZUcufxufr55e/kRIyClK157+0pkTG9a8xKjUIMx3QzKvLsqqzXL238nWwdoP6jAD8g==", "dev": true, "dependencies": { + "@noble/hashes": "^1.3.1", "base64-arraybuffer": "^0.2.0", - "bignumber.js": "^9.0.0", "borc": "^2.1.1", - "js-sha256": "0.9.0", "simple-cbor": "^0.4.1" }, "peerDependencies": { - "@dfinity/candid": "^0.11.1", - "@dfinity/principal": "^0.11.1" + "@dfinity/candid": "^0.19.2", + "@dfinity/principal": "^0.19.2" } }, "node_modules/@dfinity/candid": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/@dfinity/candid/-/candid-0.11.1.tgz", - "integrity": "sha512-EYZZg+x7OgZxa56D9SWMeTlaMb09HJ7wIfL42+l/e0lgrx+sTXYxKe8bM9FrUW9AWo9/gKkOGV/IxJL/Acncng==", + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/@dfinity/candid/-/candid-0.19.2.tgz", + "integrity": "sha512-X2hCqNMhnnmwtnOc0WnymOZYx3qphjEMuSYbBr7tMIkV7Hwt9BmXXlLnQTxUytTPxf+3he0GcS3KzsSQ9CK8ew==", "dev": true, - "peer": true + "peer": true, + "peerDependencies": { + "@dfinity/principal": "^0.19.2" + } }, "node_modules/@dfinity/principal": { - "version": "0.11.2", - "resolved": "https://registry.npmjs.org/@dfinity/principal/-/principal-0.11.2.tgz", - "integrity": "sha512-vReWruqIl16yQeKOrCLDLDf2aTEJsXcKeW9qbwVfmV0kwLNE3B2Z6tbRjYbY7s+KwpysD5B1b48ZbIwI00BeyQ==" + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/@dfinity/principal/-/principal-0.19.2.tgz", + "integrity": "sha512-vsKN6BKya70bQUsjgKRDlR2lOpv/XpUkCMIiji6rjMtKHIuWEB5Eu3JqZsOuBmWo3A3TT/K/osT9VPm0k4qdYQ==", + "dev": true, + "peer": true, + "dependencies": { + "@noble/hashes": "^1.3.1" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz", + "integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==", + "dev": true, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.4.15", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", + "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==", + "dev": true + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, + "node_modules/@noble/hashes": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz", + "integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==", + "dev": true, + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } }, "node_modules/@swc/core": { "version": "1.2.151", @@ -194,6 +238,11 @@ "resolved": "https://registry.npmjs.org/azle-syn/-/azle-syn-0.0.0.tgz", "integrity": "sha512-fWExJb5/hOEJOuBQ8hMMHRs9WryYeLLa9/ydqPWxbwjMEpE8RKdU1dTK6mdZtzNMhbeHdyne2pU1iVKiKmImGw==" }, + "node_modules/azle/node_modules/@dfinity/principal": { + "version": "0.11.2", + "resolved": "https://registry.npmjs.org/@dfinity/principal/-/principal-0.11.2.tgz", + "integrity": "sha512-vReWruqIl16yQeKOrCLDLDf2aTEJsXcKeW9qbwVfmV0kwLNE3B2Z6tbRjYbY7s+KwpysD5B1b48ZbIwI00BeyQ==" + }, "node_modules/azle/node_modules/ts-node": { "version": "10.3.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.3.1.tgz", @@ -276,9 +325,9 @@ ] }, "node_modules/bignumber.js": { - "version": "9.0.2", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.2.tgz", - "integrity": "sha512-GAcQvbpsM0pUb0zw1EI0KhQEZ+lRwR5fYaAp3vPOYuP7aDvGy6cVN6XHLauvF8SOga2y0dcLcjt3iQDTSEliyw==", + "version": "9.1.2", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz", + "integrity": "sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==", "dev": true, "engines": { "node": "*" @@ -340,7 +389,7 @@ "node_modules/delimit-stream": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/delimit-stream/-/delimit-stream-0.1.0.tgz", - "integrity": "sha1-m4MZR3wOX4rrPONXrjBfwl6hzSs=", + "integrity": "sha512-a02fiQ7poS5CnjiJBAsjGLPp5EwVoGHNeu9sziBd9huppRfsAFIpv5zNLv0V1gbop53ilngAf5Kf331AwcoRBQ==", "dev": true }, "node_modules/diff": { @@ -746,7 +795,7 @@ "node_modules/json-text-sequence": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/json-text-sequence/-/json-text-sequence-0.1.1.tgz", - "integrity": "sha1-py8hfcSvxGKf/1/rME3BvVGi89I=", + "integrity": "sha512-L3mEegEWHRekSHjc7+sc8eJhba9Clq1PZ8kMkzf8OxElhXc8O4TS5MwcVlj9aEbm5dr81N90WHC5nAz3UO971w==", "dev": true, "dependencies": { "delimit-stream": "0.1.0" @@ -769,9 +818,9 @@ "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==" }, "node_modules/readable-stream": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", "dev": true, "dependencies": { "inherits": "^2.0.3", @@ -818,12 +867,12 @@ } }, "node_modules/ts-node": { - "version": "10.7.0", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.7.0.tgz", - "integrity": "sha512-TbIGS4xgJoX2i3do417KSaep1uRAW/Lu+WAL2doDHC0D6ummjirVOXU5/7aiZotbQ5p1Zp9tP7U6cYhA0O7M8A==", + "version": "10.9.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", + "integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==", "dev": true, "dependencies": { - "@cspotcode/source-map-support": "0.7.0", + "@cspotcode/source-map-support": "^0.8.0", "@tsconfig/node10": "^1.0.7", "@tsconfig/node12": "^1.0.7", "@tsconfig/node14": "^1.0.0", @@ -834,7 +883,7 @@ "create-require": "^1.1.0", "diff": "^4.0.1", "make-error": "^1.1.1", - "v8-compile-cache-lib": "^3.0.0", + "v8-compile-cache-lib": "^3.0.1", "yn": "3.1.1" }, "bin": { @@ -860,17 +909,29 @@ } } }, + "node_modules/ts-node/node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/typescript": { - "version": "4.6.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz", - "integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==", + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", + "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=4.2.0" + "node": ">=14.17" } }, "node_modules/universalify": { @@ -884,7 +945,7 @@ "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "dev": true }, "node_modules/v8-compile-cache-lib": { @@ -917,29 +978,62 @@ } }, "@dfinity/agent": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/@dfinity/agent/-/agent-0.11.1.tgz", - "integrity": "sha512-Z1zw8l3d+AG3uu7d8G/Rd9Q5MWT9gB+Cori/Rqb6IjSEribRhL36ulCSkDYZJU/dhqSUp1VlvX5u51+wgv+MLg==", + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/@dfinity/agent/-/agent-0.19.2.tgz", + "integrity": "sha512-KLRWEjeU9SyyaS7IBVJ9ZUcufxufr55e/kRIyClK157+0pkTG9a8xKjUIMx3QzKvLsqqzXL238nWwdoP6jAD8g==", "dev": true, "requires": { + "@noble/hashes": "^1.3.1", "base64-arraybuffer": "^0.2.0", - "bignumber.js": "^9.0.0", "borc": "^2.1.1", - "js-sha256": "0.9.0", "simple-cbor": "^0.4.1" } }, "@dfinity/candid": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/@dfinity/candid/-/candid-0.11.1.tgz", - "integrity": "sha512-EYZZg+x7OgZxa56D9SWMeTlaMb09HJ7wIfL42+l/e0lgrx+sTXYxKe8bM9FrUW9AWo9/gKkOGV/IxJL/Acncng==", + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/@dfinity/candid/-/candid-0.19.2.tgz", + "integrity": "sha512-X2hCqNMhnnmwtnOc0WnymOZYx3qphjEMuSYbBr7tMIkV7Hwt9BmXXlLnQTxUytTPxf+3he0GcS3KzsSQ9CK8ew==", "dev": true, - "peer": true + "peer": true, + "requires": {} }, "@dfinity/principal": { - "version": "0.11.2", - "resolved": "https://registry.npmjs.org/@dfinity/principal/-/principal-0.11.2.tgz", - "integrity": "sha512-vReWruqIl16yQeKOrCLDLDf2aTEJsXcKeW9qbwVfmV0kwLNE3B2Z6tbRjYbY7s+KwpysD5B1b48ZbIwI00BeyQ==" + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/@dfinity/principal/-/principal-0.19.2.tgz", + "integrity": "sha512-vsKN6BKya70bQUsjgKRDlR2lOpv/XpUkCMIiji6rjMtKHIuWEB5Eu3JqZsOuBmWo3A3TT/K/osT9VPm0k4qdYQ==", + "dev": true, + "peer": true, + "requires": { + "@noble/hashes": "^1.3.1" + } + }, + "@jridgewell/resolve-uri": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz", + "integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==", + "dev": true + }, + "@jridgewell/sourcemap-codec": { + "version": "1.4.15", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", + "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==", + "dev": true + }, + "@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "requires": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, + "@noble/hashes": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz", + "integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==", + "dev": true }, "@swc/core": { "version": "1.2.151", @@ -1029,6 +1123,11 @@ "typescript": "4.4.4" }, "dependencies": { + "@dfinity/principal": { + "version": "0.11.2", + "resolved": "https://registry.npmjs.org/@dfinity/principal/-/principal-0.11.2.tgz", + "integrity": "sha512-vReWruqIl16yQeKOrCLDLDf2aTEJsXcKeW9qbwVfmV0kwLNE3B2Z6tbRjYbY7s+KwpysD5B1b48ZbIwI00BeyQ==" + }, "ts-node": { "version": "10.3.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.3.1.tgz", @@ -1073,9 +1172,9 @@ "dev": true }, "bignumber.js": { - "version": "9.0.2", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.2.tgz", - "integrity": "sha512-GAcQvbpsM0pUb0zw1EI0KhQEZ+lRwR5fYaAp3vPOYuP7aDvGy6cVN6XHLauvF8SOga2y0dcLcjt3iQDTSEliyw==", + "version": "9.1.2", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz", + "integrity": "sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==", "dev": true }, "borc": { @@ -1117,7 +1216,7 @@ "delimit-stream": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/delimit-stream/-/delimit-stream-0.1.0.tgz", - "integrity": "sha1-m4MZR3wOX4rrPONXrjBfwl6hzSs=", + "integrity": "sha512-a02fiQ7poS5CnjiJBAsjGLPp5EwVoGHNeu9sziBd9huppRfsAFIpv5zNLv0V1gbop53ilngAf5Kf331AwcoRBQ==", "dev": true }, "diff": { @@ -1313,7 +1412,7 @@ "json-text-sequence": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/json-text-sequence/-/json-text-sequence-0.1.1.tgz", - "integrity": "sha1-py8hfcSvxGKf/1/rME3BvVGi89I=", + "integrity": "sha512-L3mEegEWHRekSHjc7+sc8eJhba9Clq1PZ8kMkzf8OxElhXc8O4TS5MwcVlj9aEbm5dr81N90WHC5nAz3UO971w==", "dev": true, "requires": { "delimit-stream": "0.1.0" @@ -1334,9 +1433,9 @@ "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==" }, "readable-stream": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", "dev": true, "requires": { "inherits": "^2.0.3", @@ -1366,12 +1465,12 @@ } }, "ts-node": { - "version": "10.7.0", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.7.0.tgz", - "integrity": "sha512-TbIGS4xgJoX2i3do417KSaep1uRAW/Lu+WAL2doDHC0D6ummjirVOXU5/7aiZotbQ5p1Zp9tP7U6cYhA0O7M8A==", + "version": "10.9.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", + "integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==", "dev": true, "requires": { - "@cspotcode/source-map-support": "0.7.0", + "@cspotcode/source-map-support": "^0.8.0", "@tsconfig/node10": "^1.0.7", "@tsconfig/node12": "^1.0.7", "@tsconfig/node14": "^1.0.0", @@ -1382,14 +1481,25 @@ "create-require": "^1.1.0", "diff": "^4.0.1", "make-error": "^1.1.1", - "v8-compile-cache-lib": "^3.0.0", + "v8-compile-cache-lib": "^3.0.1", "yn": "3.1.1" + }, + "dependencies": { + "@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "requires": { + "@jridgewell/trace-mapping": "0.3.9" + } + } } }, "typescript": { - "version": "4.6.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz", - "integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==", + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", + "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", "dev": true }, "universalify": { @@ -1400,7 +1510,7 @@ "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "dev": true }, "v8-compile-cache-lib": { diff --git a/examples/motoko_examples/persistent-storage/package.json b/examples/motoko_examples/persistent-storage/package.json index 52589268e5..6bc660e4c9 100644 --- a/examples/motoko_examples/persistent-storage/package.json +++ b/examples/motoko_examples/persistent-storage/package.json @@ -1,15 +1,14 @@ { "scripts": { "pretest": "AZLE_REBUILD=true ts-node --transpile-only --ignore=false test/pretest.ts", - "test": "AZLE_REBUILD=true ts-node --transpile-only --ignore=false test/test.ts", - "benchmark": "ts-node --transpile-only --ignore=false benchmark/benchmark.ts" + "test": "AZLE_REBUILD=true ts-node --transpile-only --ignore=false test/test.ts" }, "dependencies": { "azle": "0.17.1" }, "devDependencies": { - "@dfinity/agent": "0.11.1", - "ts-node": "10.7.0", - "typescript": "4.6.3" + "@dfinity/agent": "^0.19.2", + "ts-node": "^10.9.1", + "typescript": "^5.2.2" } } diff --git a/examples/motoko_examples/persistent-storage/src/index.did b/examples/motoko_examples/persistent-storage/src/index.did new file mode 100644 index 0000000000..0233802ba2 --- /dev/null +++ b/examples/motoko_examples/persistent-storage/src/index.did @@ -0,0 +1,5 @@ +service: () -> { + increment: () -> (nat); + get: () -> (nat) query; + reset: () -> (nat); +} diff --git a/examples/motoko_examples/persistent-storage/src/index.ts b/examples/motoko_examples/persistent-storage/src/index.ts new file mode 100644 index 0000000000..fed9aa66d7 --- /dev/null +++ b/examples/motoko_examples/persistent-storage/src/index.ts @@ -0,0 +1,56 @@ +import { + ic, + init, + nat, + query, + Service, + StableBTreeMap, + text, + update +} from 'azle'; + +export default class extends Service { + stableStorage = new StableBTreeMap(text, nat, 0); + + @init([]) + init() { + this.stableStorage.insert('counter', 0n); + } + + @update([], nat) + increment(): nat { + const counterOpt = this.stableStorage.get('counter'); + const counter = + counterOpt.length === 0 + ? ic.trap('counter not defined') + : counterOpt[0] + 1n; + + this.stableStorage.insert('counter', counter); + + return counter; + } + + @query([], nat) + get(): nat { + const counterOpt = this.stableStorage.get('counter'); + const counter = + counterOpt.length === 0 + ? ic.trap('counter not defined') + : counterOpt[0]; + + return counter; + } + + @update([], nat) + reset(): nat { + this.stableStorage.insert('counter', 0n); + + const counterOpt = this.stableStorage.get('counter'); + const counter = + counterOpt.length === 0 + ? ic.trap('counter not defined') + : counterOpt[0]; + + return counter; + } +} diff --git a/examples/motoko_examples/persistent-storage/test/pretest.ts b/examples/motoko_examples/persistent-storage/test/pretest.ts index a807f0783b..1c7ee65983 100644 --- a/examples/motoko_examples/persistent-storage/test/pretest.ts +++ b/examples/motoko_examples/persistent-storage/test/pretest.ts @@ -3,15 +3,15 @@ import { execSync } from 'child_process'; async function pretest() { await new Promise((resolve) => setTimeout(resolve, 5000)); - execSync(`dfx canister uninstall-code azle || true`, { + execSync(`dfx canister uninstall-code persistent_storage || true`, { stdio: 'inherit' }); - execSync(`dfx deploy azle`, { + execSync(`dfx deploy persistent_storage`, { stdio: 'inherit' }); - execSync(`dfx generate azle`, { + execSync(`dfx generate persistent_storage`, { stdio: 'inherit' }); } diff --git a/examples/motoko_examples/persistent-storage/test/test.ts b/examples/motoko_examples/persistent-storage/test/test.ts index 8cbca2f19e..a10e92a789 100644 --- a/examples/motoko_examples/persistent-storage/test/test.ts +++ b/examples/motoko_examples/persistent-storage/test/test.ts @@ -1,11 +1,14 @@ import { getCanisterId, runTests } from 'azle/test'; -import { createActor } from '../dfx_generated/azle'; +import { createActor } from './dfx_generated/persistent_storage'; import { getTests } from './tests'; -const persistentStorageCanister = createActor(getCanisterId('azle'), { - agentOptions: { - host: 'http://127.0.0.1:8000' +const persistentStorageCanister = createActor( + getCanisterId('persistent_storage'), + { + agentOptions: { + host: 'http://127.0.0.1:8000' + } } -}); +); runTests(getTests(persistentStorageCanister)); diff --git a/examples/motoko_examples/persistent-storage/test/tests.ts b/examples/motoko_examples/persistent-storage/test/tests.ts index 4fe06fc275..7c31ec7ba7 100644 --- a/examples/motoko_examples/persistent-storage/test/tests.ts +++ b/examples/motoko_examples/persistent-storage/test/tests.ts @@ -1,5 +1,6 @@ import { Test } from 'azle/test'; -import { _SERVICE } from '../dfx_generated/azle/azle.did'; +import { execSync } from 'child_process'; +import { _SERVICE } from './dfx_generated/persistent_storage/persistent_storage.did'; import { ActorSubclass } from '@dfinity/agent'; export function getTests( @@ -33,15 +34,14 @@ export function getTests( }; } }, - // TODO: upgrade to DFX v0.10.x - // { - // name: 'deploy (upgrade)', - // prep: async () => { - // execSync(`dfx deploy --upgrade-unchanged`, { - // stdio: 'inherit' - // }); - // } - // }, + { + name: 'deploy', + prep: async () => { + execSync(`dfx deploy`, { + stdio: 'inherit' + }); + } + }, { name: 'get', test: async () => {