From 1476b658b5a0f38aeaa47bef6b796c47dcc43847 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Mon, 17 Jul 2023 19:29:59 +0200 Subject: [PATCH 1/7] feat: migrate files --- Cargo.lock | 1020 +++++++++++------ Cargo.toml | 57 +- cairo | 2 +- src/openzeppelin/introspection.cairo | 1 + .../introspection/dual_src5.cairo | 4 +- src/openzeppelin/introspection/src5.cairo | 66 +- src/openzeppelin/lib.cairo | 8 +- src/openzeppelin/tests.cairo | 12 +- .../access/test_dual_accesscontrol.cairo | 21 +- .../tests/access/test_dual_ownable.cairo | 14 +- .../tests/account/test_dual_account.cairo | 21 +- .../tests/introspection/test_dual_src5.cairo | 27 +- .../tests/introspection/test_src5.cairo | 27 +- src/openzeppelin/tests/mocks.cairo | 38 +- .../tests/mocks/non_implementing_mock.cairo | 9 +- src/openzeppelin/tests/mocks/src5_mocks.cairo | 42 +- .../tests/token/test_dual721.cairo | 14 +- .../tests/token/test_dual721_receiver.cairo | 21 +- src/openzeppelin/token/erc721/erc721.cairo | 9 +- src/openzeppelin/utils/serde.cairo | 16 - 20 files changed, 848 insertions(+), 581 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a5ca15c63..278c09912 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,17 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + [[package]] name = "ahash" version = "0.8.3" @@ -22,6 +33,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "aho-corasick" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" +dependencies = [ + "memchr", +] + +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + [[package]] name = "anyhow" version = "1.0.70" @@ -29,129 +55,139 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" [[package]] -name = "ark-ff" -version = "0.3.0" +name = "ark-ec" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b3235cc41ee7a12aaaf2c575a2ad7b46713a8a50bda2fc3b003a04845c05dd6" +checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba" dependencies = [ - "ark-ff-asm 0.3.0", - "ark-ff-macros 0.3.0", - "ark-serialize 0.3.0", - "ark-std 0.3.0", + "ark-ff", + "ark-poly", + "ark-serialize", + "ark-std", "derivative", - "num-bigint", + "hashbrown 0.13.2", + "itertools 0.10.5", "num-traits 0.2.15", - "paste", - "rustc_version 0.3.3", "zeroize", ] [[package]] name = "ark-ff" -version = "0.4.0-alpha.7" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cf4b42c978bd9b967f6a2ba54a4cc57f34780f9d0cf86916f8f7e922b4f80fe" +checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" dependencies = [ - "ark-ff-asm 0.4.0-alpha.7", - "ark-ff-macros 0.4.0-alpha.7", - "ark-serialize 0.4.0-alpha.7", - "ark-std 0.4.0-alpha", + "ark-ff-asm", + "ark-ff-macros", + "ark-serialize", + "ark-std", "derivative", - "digest 0.10.6", - "itertools", + "digest", + "itertools 0.10.5", "num-bigint", "num-traits 0.2.15", "paste", - "rustc_version 0.4.0", + "rustc_version", "zeroize", ] [[package]] name = "ark-ff-asm" -version = "0.3.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db02d390bf6643fb404d3d22d31aee1c4bc4459600aef9113833d17e786c6e44" +checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" dependencies = [ "quote", "syn 1.0.103", ] [[package]] -name = "ark-ff-asm" -version = "0.4.0-alpha.7" +name = "ark-ff-macros" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3ba0a3cf584a8ede533a1749b86040e9018cf752265fc39a71c69fe1fafaba5" +checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" dependencies = [ + "num-bigint", + "num-traits 0.2.15", + "proc-macro2", "quote", "syn 1.0.103", ] [[package]] -name = "ark-ff-macros" -version = "0.3.0" +name = "ark-poly" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db2fd794a08ccb318058009eefdf15bcaaaaf6f8161eb3345f907222bac38b20" +checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf" dependencies = [ - "num-bigint", - "num-traits 0.2.15", - "quote", - "syn 1.0.103", + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", ] [[package]] -name = "ark-ff-macros" -version = "0.4.0-alpha.7" +name = "ark-secp256k1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9989a01ec42d2f31232796831077ef730d4cd0d0931f5ef6962a43ebddd215fa" +checksum = "4c02e954eaeb4ddb29613fee20840c2bbc85ca4396d53e33837e11905363c5f2" dependencies = [ - "num-bigint", - "num-traits 0.2.15", - "proc-macro2", - "quote", - "syn 1.0.103", + "ark-ec", + "ark-ff", + "ark-std", ] [[package]] -name = "ark-serialize" -version = "0.3.0" +name = "ark-secp256r1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d6c2b318ee6e10f8c2853e73a83adc0ccb88995aa978d8a3408d492ab2ee671" +checksum = "3975a01b0a6e3eae0f72ec7ca8598a6620fc72fa5981f6f5cca33b7cd788f633" dependencies = [ - "ark-std 0.3.0", - "digest 0.9.0", + "ark-ec", + "ark-ff", + "ark-std", ] [[package]] name = "ark-serialize" -version = "0.4.0-alpha.7" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84aeb60f7c6792ae71e9e2225412ecd59d7c85cfec4183a8c497f2a3a4cdb36e" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" dependencies = [ - "ark-std 0.4.0-alpha", - "digest 0.10.6", + "ark-serialize-derive", + "ark-std", + "digest", "num-bigint", ] [[package]] -name = "ark-std" -version = "0.3.0" +name = "ark-serialize-derive" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df2c09229cbc5a028b1d70e00fdb2acee28b1055dfb5ca73eea49c5a25c4e7c" +checksum = "ae3281bc6d0fd7e549af32b52511e1302185bd688fd3359fa36423346ff682ea" dependencies = [ - "num-traits 0.2.15", - "rand", + "proc-macro2", + "quote", + "syn 1.0.103", ] [[package]] name = "ark-std" -version = "0.4.0-alpha" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc5b16d734e9b2e43886ff586755219df7fb9639cc04ab00c7e636708a5ba06a" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" dependencies = [ "num-traits 0.2.15", "rand", ] +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "ascii-canvas" version = "3.0.0" @@ -191,9 +227,9 @@ dependencies = [ [[package]] name = "auto_impl" -version = "0.5.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7862e21c893d65a1650125d157eaeec691439379a1cee17ee49031b79236ada4" +checksum = "fee3da8ef1276b0bee5dd1c7258010d8fffd31801447323115a25560e1327b89" dependencies = [ "proc-macro-error", "proc-macro2", @@ -215,9 +251,9 @@ checksum = "bc0455254eb5c6964c4545d8bac815e1a1be4f3afe0ae695ea539c12d728d44b" [[package]] name = "bincode" -version = "2.0.0-rc.2" +version = "2.0.0-rc.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bb50c5a2ef4b9b1e7ae73e3a73b52ea24b20312d629f9c4df28260b7ad2c3c4" +checksum = "f11ea1a0346b94ef188834a65c068a03aec181c94896d481d7a0a40d85b0ce95" dependencies = [ "serde", ] @@ -280,17 +316,34 @@ version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" +[[package]] +name = "byte-slice-cast" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" + [[package]] name = "bytes" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" +[[package]] +name = "cairo-compile" +version = "2.0.2" +dependencies = [ + "anyhow", + "cairo-lang-compiler", + "cairo-lang-utils", + "clap", + "log", +] + [[package]] name = "cairo-felt" -version = "0.3.0-rc1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a93dedd19b8edf685798f1f12e4e0ac21ac196ea5262c300783f69f3fa0cb28b" +checksum = "0f8de851723a7d13ed8b0b588a78ffa6b38d8e1f3eb4b6e71a96376510e5504a" dependencies = [ "lazy_static", "num-bigint", @@ -299,17 +352,33 @@ dependencies = [ "serde", ] +[[package]] +name = "cairo-format" +version = "2.0.2" +dependencies = [ + "anyhow", + "cairo-lang-formatter", + "cairo-lang-utils", + "clap", + "colored", + "ignore", + "log", +] + [[package]] name = "cairo-lang-casm" -version = "1.1.1" +version = "2.0.2" dependencies = [ "cairo-lang-utils", "env_logger", "indoc", - "itertools", + "itertools 0.11.0", "num-bigint", "num-traits 0.2.15", + "parity-scale-codec", + "parity-scale-codec-derive", "pretty_assertions", + "schemars", "serde", "test-case", "test-log", @@ -318,7 +387,7 @@ dependencies = [ [[package]] name = "cairo-lang-compiler" -version = "1.1.1" +version = "2.0.2" dependencies = [ "anyhow", "cairo-lang-defs", @@ -333,7 +402,6 @@ dependencies = [ "cairo-lang-sierra-generator", "cairo-lang-syntax", "cairo-lang-utils", - "clap", "log", "salsa", "smol_str", @@ -343,7 +411,7 @@ dependencies = [ [[package]] name = "cairo-lang-debug" -version = "1.1.1" +version = "2.0.2" dependencies = [ "cairo-lang-proc-macros", "cairo-lang-utils", @@ -354,7 +422,7 @@ dependencies = [ [[package]] name = "cairo-lang-defs" -version = "1.1.1" +version = "2.0.2" dependencies = [ "cairo-lang-debug", "cairo-lang-diagnostics", @@ -364,9 +432,9 @@ dependencies = [ "cairo-lang-test-utils", "cairo-lang-utils", "env_logger", - "indexmap", + "indexmap 2.0.0", "indoc", - "itertools", + "itertools 0.11.0", "pretty_assertions", "salsa", "smol_str", @@ -375,14 +443,15 @@ dependencies = [ [[package]] name = "cairo-lang-diagnostics" -version = "1.1.1" +version = "2.0.2" dependencies = [ + "cairo-lang-debug", "cairo-lang-filesystem", "cairo-lang-proc-macros", "cairo-lang-utils", "env_logger", "indoc", - "itertools", + "itertools 0.11.0", "pretty_assertions", "salsa", "test-log", @@ -390,21 +459,21 @@ dependencies = [ [[package]] name = "cairo-lang-eq-solver" -version = "1.1.1" +version = "2.0.2" dependencies = [ "cairo-lang-utils", "env_logger", "good_lp", - "indexmap", + "indexmap 2.0.0", "indoc", - "itertools", + "itertools 0.11.0", "test-case", "test-log", ] [[package]] name = "cairo-lang-filesystem" -version = "1.1.1" +version = "2.0.2" dependencies = [ "cairo-lang-debug", "cairo-lang-utils", @@ -419,7 +488,7 @@ dependencies = [ [[package]] name = "cairo-lang-formatter" -version = "1.1.1" +version = "2.0.2" dependencies = [ "anyhow", "cairo-lang-diagnostics", @@ -427,11 +496,10 @@ dependencies = [ "cairo-lang-parser", "cairo-lang-syntax", "cairo-lang-utils", - "clap", "colored", "diffy", "ignore", - "itertools", + "itertools 0.11.0", "log", "pretty_assertions", "salsa", @@ -442,7 +510,7 @@ dependencies = [ [[package]] name = "cairo-lang-language-server" -version = "1.1.1" +version = "2.0.2" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -474,7 +542,7 @@ dependencies = [ [[package]] name = "cairo-lang-lowering" -version = "1.1.1" +version = "2.0.2" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -489,9 +557,9 @@ dependencies = [ "cairo-lang-utils", "env_logger", "id-arena", - "indexmap", + "indexmap 2.0.0", "indoc", - "itertools", + "itertools 0.11.0", "log", "num-bigint", "num-traits 0.2.15", @@ -503,7 +571,7 @@ dependencies = [ [[package]] name = "cairo-lang-parser" -version = "1.1.1" +version = "2.0.2" dependencies = [ "cairo-lang-diagnostics", "cairo-lang-filesystem", @@ -513,7 +581,7 @@ dependencies = [ "cairo-lang-utils", "colored", "env_logger", - "itertools", + "itertools 0.11.0", "log", "num-bigint", "num-traits 0.2.15", @@ -527,7 +595,7 @@ dependencies = [ [[package]] name = "cairo-lang-plugins" -version = "1.1.1" +version = "2.0.2" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -540,7 +608,8 @@ dependencies = [ "cairo-lang-utils", "env_logger", "indoc", - "itertools", + "itertools 0.11.0", + "num-bigint", "salsa", "serde_json", "smol_str", @@ -550,18 +619,19 @@ dependencies = [ [[package]] name = "cairo-lang-proc-macros" -version = "1.1.1" +version = "2.0.2" dependencies = [ "cairo-lang-debug", "quote", - "syn 1.0.103", + "syn 2.0.26", ] [[package]] name = "cairo-lang-project" -version = "1.1.1" +version = "2.0.2" dependencies = [ "cairo-lang-filesystem", + "cairo-lang-utils", "indoc", "serde", "smol_str", @@ -572,11 +642,13 @@ dependencies = [ [[package]] name = "cairo-lang-runner" -version = "1.1.1" +version = "2.0.2" dependencies = [ "anyhow", - "ark-ff 0.4.0-alpha.7", - "ark-std 0.3.0", + "ark-ff", + "ark-secp256k1", + "ark-secp256r1", + "ark-std", "cairo-felt", "cairo-lang-casm", "cairo-lang-compiler", @@ -590,11 +662,11 @@ dependencies = [ "cairo-lang-sierra-gas", "cairo-lang-sierra-generator", "cairo-lang-sierra-to-casm", + "cairo-lang-sierra-type-size", "cairo-lang-starknet", "cairo-lang-utils", "cairo-vm", - "clap", - "itertools", + "itertools 0.11.0", "keccak", "num-bigint", "num-integer", @@ -607,7 +679,7 @@ dependencies = [ [[package]] name = "cairo-lang-semantic" -version = "1.1.1" +version = "2.0.2" dependencies = [ "assert_matches", "cairo-lang-debug", @@ -623,7 +695,7 @@ dependencies = [ "env_logger", "id-arena", "indoc", - "itertools", + "itertools 0.11.0", "log", "num-bigint", "num-traits 0.2.15", @@ -636,7 +708,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra" -version = "1.1.1" +version = "2.0.2" dependencies = [ "assert_matches", "bimap", @@ -646,7 +718,7 @@ dependencies = [ "derivative", "env_logger", "indoc", - "itertools", + "itertools 0.11.0", "lalrpop", "lalrpop-util", "num-bigint", @@ -664,14 +736,15 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-ap-change" -version = "1.1.1" +version = "2.0.2" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", + "cairo-lang-sierra-type-size", "cairo-lang-utils", "env_logger", "indoc", - "itertools", + "itertools 0.11.0", "test-case", "test-log", "thiserror", @@ -679,15 +752,16 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-gas" -version = "1.1.1" +version = "2.0.2" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", + "cairo-lang-sierra-type-size", "cairo-lang-test-utils", "cairo-lang-utils", "env_logger", "indoc", - "itertools", + "itertools 0.11.0", "pretty_assertions", "test-case", "test-log", @@ -696,7 +770,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-generator" -version = "1.1.1" +version = "2.0.2" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -713,9 +787,9 @@ dependencies = [ "cairo-lang-utils", "env_logger", "id-arena", - "indexmap", + "indexmap 2.0.0", "indoc", - "itertools", + "itertools 0.11.0", "log", "num-bigint", "pretty_assertions", @@ -727,20 +801,19 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-to-casm" -version = "1.1.1" +version = "2.0.2" dependencies = [ - "anyhow", "assert_matches", "cairo-felt", "cairo-lang-casm", "cairo-lang-sierra", "cairo-lang-sierra-ap-change", "cairo-lang-sierra-gas", + "cairo-lang-sierra-type-size", "cairo-lang-utils", - "clap", "env_logger", "indoc", - "itertools", + "itertools 0.11.0", "log", "num-bigint", "num-traits 0.2.15", @@ -750,9 +823,17 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cairo-lang-sierra-type-size" +version = "2.0.2" +dependencies = [ + "cairo-lang-sierra", + "cairo-lang-utils", +] + [[package]] name = "cairo-lang-starknet" -version = "1.1.1" +version = "2.0.2" dependencies = [ "anyhow", "cairo-felt", @@ -773,12 +854,12 @@ dependencies = [ "cairo-lang-syntax", "cairo-lang-test-utils", "cairo-lang-utils", - "clap", "convert_case", "env_logger", "genco", + "indent", "indoc", - "itertools", + "itertools 0.11.0", "log", "num-bigint", "num-integer", @@ -796,7 +877,7 @@ dependencies = [ [[package]] name = "cairo-lang-syntax" -version = "1.1.1" +version = "2.0.2" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -814,19 +895,17 @@ dependencies = [ [[package]] name = "cairo-lang-syntax-codegen" -version = "1.1.1" +version = "2.0.2" dependencies = [ - "cairo-lang-utils", "env_logger", "genco", - "log", "test-log", "xshell", ] [[package]] name = "cairo-lang-test-runner" -version = "1.1.1" +version = "2.0.2" dependencies = [ "anyhow", "cairo-felt", @@ -848,9 +927,8 @@ dependencies = [ "cairo-lang-syntax", "cairo-lang-utils", "cairo-vm", - "clap", "colored", - "itertools", + "itertools 0.11.0", "num-bigint", "num-traits 0.2.15", "rayon", @@ -860,7 +938,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-utils" -version = "1.1.1" +version = "2.0.2" dependencies = [ "cairo-lang-utils", "env_logger", @@ -871,15 +949,17 @@ dependencies = [ [[package]] name = "cairo-lang-utils" -version = "1.1.1" +version = "2.0.2" dependencies = [ "env_logger", - "indexmap", - "itertools", + "indexmap 2.0.0", + "itertools 0.11.0", "log", "num-bigint", "num-integer", "num-traits 0.2.15", + "parity-scale-codec", + "schemars", "serde", "serde_json", "test-case", @@ -888,27 +968,52 @@ dependencies = [ ] [[package]] -name = "cairo-take_until_unbalanced" -version = "0.24.2-rc1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4e174056df7cfe9b579376f32de405722e1090c74deb2540bb0cd9e7931772d" +name = "cairo-language-server" +version = "2.0.2" dependencies = [ - "nom", + "cairo-lang-language-server", + "cairo-lang-utils", + "log", + "tokio", +] + +[[package]] +name = "cairo-run" +version = "2.0.2" +dependencies = [ + "anyhow", + "cairo-lang-compiler", + "cairo-lang-diagnostics", + "cairo-lang-runner", + "cairo-lang-sierra", + "cairo-lang-sierra-generator", + "cairo-lang-starknet", + "cairo-lang-utils", + "clap", +] + +[[package]] +name = "cairo-test" +version = "2.0.2" +dependencies = [ + "anyhow", + "cairo-lang-compiler", + "cairo-lang-test-runner", + "clap", ] [[package]] name = "cairo-vm" -version = "0.3.0-rc1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f4af8c3e7be5ac46b7da4a3ab551ee4c8c8e2fdb501a4dda4dceef4c66dbcde" +checksum = "656c25c13b6ffcc75e081292f3c23f27e429b3d4b8d69ecdc327a441798e91f4" dependencies = [ "anyhow", "bincode", "bitvec", "cairo-felt", - "cairo-take_until_unbalanced", "generic-array", - "hashbrown 0.13.2", + "hashbrown 0.14.0", "hex", "keccak", "lazy_static", @@ -916,15 +1021,14 @@ dependencies = [ "nom", "num-bigint", "num-integer", + "num-prime", "num-traits 0.2.15", - "rand_core", + "rand", "serde", - "serde_bytes", "serde_json", "sha2", "sha3", "starknet-crypto", - "thiserror", "thiserror-no-std", ] @@ -1072,9 +1176,9 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "crypto-bigint" -version = "0.4.9" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" +checksum = "cf4c2f4e1afd912bc40bfd6fed5d9dc1f288e0ba01bfcc835cc5bc3eb13efe15" dependencies = [ "generic-array", "subtle", @@ -1101,41 +1205,6 @@ dependencies = [ "syn 1.0.103", ] -[[package]] -name = "darling" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn 1.0.103", -] - -[[package]] -name = "darling_macro" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" -dependencies = [ - "darling_core", - "quote", - "syn 1.0.103", -] - [[package]] name = "dashmap" version = "5.4.0" @@ -1160,37 +1229,6 @@ dependencies = [ "syn 1.0.103", ] -[[package]] -name = "derive_builder" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d67778784b508018359cbc8696edb3db78160bab2c2a28ba7f56ef6932997f8" -dependencies = [ - "derive_builder_macro", -] - -[[package]] -name = "derive_builder_core" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c11bdc11a0c47bc7d37d582b5285da6849c96681023680b906673c5707af7b0f" -dependencies = [ - "darling", - "proc-macro2", - "quote", - "syn 1.0.103", -] - -[[package]] -name = "derive_builder_macro" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebcda35c7a396850a55ffeac740804b40ffec779b98fffbb1738f4033f0ee79e" -dependencies = [ - "derive_builder_core", - "syn 1.0.103", -] - [[package]] name = "diff" version = "0.1.13" @@ -1208,18 +1246,9 @@ dependencies = [ [[package]] name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - -[[package]] -name = "digest" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", "crypto-common", @@ -1247,6 +1276,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "dyn-clone" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "304e6508efa593091e97a9abbc10f90aa7ca635b6d2784feff3c89d41dd12272" + [[package]] name = "either" version = "1.8.0" @@ -1264,17 +1299,23 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.9.3" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" dependencies = [ - "atty", "humantime", + "is-terminal", "log", "regex", "termcolor", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "errno" version = "0.2.8" @@ -1440,11 +1481,20 @@ dependencies = [ "syn 1.0.103", ] +[[package]] +name = "generate-syntax" +version = "2.0.2" +dependencies = [ + "cairo-lang-syntax-codegen", + "cairo-lang-utils", + "log", +] + [[package]] name = "generic-array" -version = "0.14.6" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", @@ -1452,9 +1502,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.8" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if", "js-sys", @@ -1463,13 +1513,19 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "globset" version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc" dependencies = [ - "aho-corasick", + "aho-corasick 0.7.20", "bstr", "fnv", "log", @@ -1491,6 +1547,9 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash 0.7.6", +] [[package]] name = "hashbrown" @@ -1498,7 +1557,17 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ - "ahash", + "ahash 0.8.3", +] + +[[package]] +name = "hashbrown" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +dependencies = [ + "ahash 0.8.3", + "allocator-api2", "serde", ] @@ -1544,7 +1613,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest 0.10.6", + "digest", ] [[package]] @@ -1565,12 +1634,6 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - [[package]] name = "idna" version = "0.3.0" @@ -1598,6 +1661,23 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "impl-trait-for-tuples" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.103", +] + +[[package]] +name = "indent" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9f1a0777d972970f204fdf8ef319f1f4f8459131636d7e3c96c5d59570d0fa6" + [[package]] name = "indexmap" version = "1.9.2" @@ -1609,6 +1689,17 @@ dependencies = [ "serde", ] +[[package]] +name = "indexmap" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +dependencies = [ + "equivalent", + "hashbrown 0.14.0", + "serde", +] + [[package]] name = "indoc" version = "2.0.1" @@ -1656,6 +1747,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.4" @@ -1673,25 +1773,25 @@ dependencies = [ [[package]] name = "keccak" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3afef3b6eff9ce9d8ff9b3601125eec7f0c8cbac7abd14f355d053fa56c98768" +checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" dependencies = [ "cpufeatures", ] [[package]] name = "lalrpop" -version = "0.19.9" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f34313ec00c2eb5c3c87ca6732ea02dcf3af99c3ff7a8fb622ffb99c9d860a87" +checksum = "da4081d44f4611b66c6dd725e6de3169f9f63905421e8626fcb86b6a898998b8" dependencies = [ "ascii-canvas", "bit-set", "diff", "ena", "is-terminal", - "itertools", + "itertools 0.10.5", "lalrpop-util", "petgraph", "pico-args", @@ -1705,9 +1805,9 @@ dependencies = [ [[package]] name = "lalrpop-util" -version = "0.19.9" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5c1f7869c94d214466c5fd432dfed12c379fd87786768d36455892d46b18edd" +checksum = "3f35c735096c0293d313e8f2a641627472b83d01b937177fe76e5e2708d31e0d" dependencies = [ "regex", ] @@ -1723,15 +1823,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.137" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libmimalloc-sys" -version = "0.1.28" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04d1c67deb83e6b75fa4fe3309e09cfeade12e7721d95322af500d3814ea60c9" +checksum = "f4ac0e912c8ef1b735e92369695618dc5b1819f5a7bf3f167301a3ba1cea515e" dependencies = [ "cc", "libc", @@ -1762,11 +1862,20 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "lru" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999beba7b6e8345721bd280141ed958096a2e4abdf74f67ff4ce49b4b54e47a" +dependencies = [ + "hashbrown 0.12.3", +] + [[package]] name = "lsp-types" -version = "0.93.2" +version = "0.94.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9be6e9c7e2d18f651974370d7aff703f9513e0df6e464fd795660edc77e6ca51" +checksum = "0b63735a13a1f9cd4f4835223d828ed9c2e35c8c5e61837774399f558b6a1237" dependencies = [ "bitflags", "serde", @@ -1801,9 +1910,9 @@ dependencies = [ [[package]] name = "mimalloc" -version = "0.1.32" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2374e2999959a7b583e1811a1ddbf1d3a4b9496eceb9746f1192a59d871eca" +checksum = "4e2894987a3459f3ffb755608bd82188f8ed00d0ae077f1edea29c068d639d98" dependencies = [ "libmimalloc-sys", ] @@ -1884,6 +1993,7 @@ dependencies = [ "autocfg", "num-integer", "num-traits 0.2.15", + "rand", "serde", ] @@ -1907,6 +2017,33 @@ dependencies = [ "num-traits 0.2.15", ] +[[package]] +name = "num-modular" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a5fe11d4135c3bcdf3a95b18b194afa9608a5f6ff034f5d857bc9a27fb0119" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits 0.2.15", +] + +[[package]] +name = "num-prime" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f4e3bc495f6e95bc15a6c0c55ac00421504a5a43d09e3cc455d1fea7015581d" +dependencies = [ + "bitvec", + "either", + "lru", + "num-bigint", + "num-integer", + "num-modular", + "num-traits 0.2.15", + "rand", +] + [[package]] name = "num-traits" version = "0.1.43" @@ -1977,6 +2114,31 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +[[package]] +name = "parity-scale-codec" +version = "3.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "756d439303e94fae44f288ba881ad29670c65b0c4b0e05674ca81061bb65f2c5" +dependencies = [ + "arrayvec", + "bitvec", + "byte-slice-cast", + "impl-trait-for-tuples", + "serde", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "3.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d884d78fcf214d70b1e239fcd1c6e5e95aa3be1881918da2e488cc946c7a476" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.103", +] + [[package]] name = "parking_lot" version = "0.11.2" @@ -2033,9 +2195,9 @@ checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" [[package]] name = "path-clean" -version = "0.1.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecba01bf2678719532c5e3059e0b5f0811273d94b397088b82e3bd0a78c78fdd" +checksum = "17359afc20d7ab31fdb42bb844c8b3bb1dabd7dcf7e68428492da7f16966fcef" [[package]] name = "percent-encoding" @@ -2043,16 +2205,6 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" -[[package]] -name = "pest" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a528564cc62c19a7acac4d81e01f39e53e25e17b934878f4c6d25cc2836e62f8" -dependencies = [ - "thiserror", - "ucd-trie", -] - [[package]] name = "petgraph" version = "0.6.2" @@ -2060,7 +2212,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5014253a1331579ce62aa67443b4a658c5e7dd03d4bc6d302b94474888143" dependencies = [ "fixedbitset", - "indexmap", + "indexmap 1.9.2", ] [[package]] @@ -2074,9 +2226,9 @@ dependencies = [ [[package]] name = "pico-args" -version = "0.4.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468" +checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" [[package]] name = "pin-project" @@ -2134,6 +2286,16 @@ dependencies = [ "yansi", ] +[[package]] +name = "proc-macro-crate" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +dependencies = [ + "once_cell", + "toml_edit", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -2160,18 +2322,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.52" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.26" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "5fe8a65d69dd0808184ebb5f836ab526bb259db23c657efa38711b1072ee47f0" dependencies = [ "proc-macro2", ] @@ -2188,6 +2350,7 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ + "libc", "rand_chacha", "rand_core", ] @@ -2207,6 +2370,9 @@ name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] [[package]] name = "rawpointer" @@ -2258,61 +2424,75 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.0" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" +dependencies = [ + "aho-corasick 1.0.2", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +checksum = "39354c10dd07468c2e73926b23bb9c2caca74c5501e38a35da70406f1d923310" dependencies = [ - "aho-corasick", + "aho-corasick 1.0.2", "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.6.28" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" [[package]] name = "relative-path" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0df32d82cedd1499386877b062ebe8721f806de80b08d183c70184ef17dd1d42" +checksum = "4bf2521270932c3c7bed1a59151222bd7643c79310f2916f01925e1e16255698" [[package]] name = "rfc6979" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" dependencies = [ - "crypto-bigint", "hmac", - "zeroize", + "subtle", ] [[package]] name = "rstest" -version = "0.16.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b07f2d176c472198ec1e6551dc7da28f1c089652f66a7b722676c2238ebc0edf" +checksum = "2b96577ca10cb3eade7b337eb46520108a67ca2818a24d0b63f41fd62bc9651c" dependencies = [ "futures", "futures-timer", "rstest_macros", - "rustc_version 0.4.0", + "rustc_version", ] [[package]] name = "rstest_macros" -version = "0.16.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7229b505ae0706e64f37ffc54a9c163e11022a6636d58fe1f3f52018257ff9f7" +checksum = "225e674cf31712b8bb15fdbca3ec0c1b9d825c5a24407ff2b7e005fb6a29ba03" dependencies = [ "cfg-if", + "glob", "proc-macro2", "quote", - "rustc_version 0.4.0", - "syn 1.0.103", + "regex", + "relative-path", + "rustc_version", + "syn 2.0.26", "unicode-ident", ] @@ -2322,22 +2502,13 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc_version" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" -dependencies = [ - "semver 0.11.0", -] - [[package]] name = "rustc_version" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.17", + "semver", ] [[package]] @@ -2373,7 +2544,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b84d9f96071f3f3be0dc818eae3327625d8ebc95b58da37d6850724f31d3403" dependencies = [ "crossbeam-utils", - "indexmap", + "indexmap 1.9.2", "lock_api", "log", "oorandom", @@ -2406,33 +2577,48 @@ dependencies = [ [[package]] name = "scarb-metadata" -version = "1.0.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2480a9a896395a1414feebcfe8550b35f4dce0e6a437eeaa0c3d79ec938ddf42" +checksum = "26ba10c59bd4ebde82de954e3a3d6d503eb17bd634106ef144af1356b28b8f0f" dependencies = [ "camino", - "derive_builder", - "semver 1.0.17", + "semver", "serde", "serde_json", "thiserror", ] [[package]] -name = "scopeguard" -version = "1.1.0" +name = "schemars" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "02c613288622e5f0c3fdc5dbd4db1c5fbe752746b1d1a56a0630b78fd00de44f" +dependencies = [ + "dyn-clone", + "indexmap 1.9.2", + "schemars_derive", + "serde", + "serde_json", +] [[package]] -name = "semver" -version = "0.11.0" +name = "schemars_derive" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +checksum = "109da1e6b197438deb6db99952990c7f959572794b80ff93707d55a232545e7c" dependencies = [ - "semver-parser", + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 1.0.103", ] +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + [[package]] name = "semver" version = "1.0.17" @@ -2442,49 +2628,42 @@ dependencies = [ "serde", ] -[[package]] -name = "semver-parser" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" -dependencies = [ - "pest", -] - [[package]] name = "serde" -version = "1.0.158" +version = "1.0.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "771d4d9c4163ee138805e12c710dd365e4f44be8be0503cb1bb9eb989425d9c9" +checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9" dependencies = [ "serde_derive", ] [[package]] -name = "serde_bytes" -version = "0.11.9" +name = "serde_derive" +version = "1.0.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "416bda436f9aab92e02c8e10d49a15ddd339cea90b6e340fe51ed97abb548294" +checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682" dependencies = [ - "serde", + "proc-macro2", + "quote", + "syn 2.0.26", ] [[package]] -name = "serde_derive" -version = "1.0.158" +name = "serde_derive_internals" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e801c1712f48475582b7696ac71e0ca34ebb30e09338425384269d9717c62cad" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.3", + "syn 1.0.103", ] [[package]] name = "serde_json" -version = "1.0.94" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea" +checksum = "d03b412469450d4404fe8499a268edd7f8b79fecb074b0d812ad64ca21f4031b" dependencies = [ "itoa", "ryu", @@ -2502,27 +2681,49 @@ dependencies = [ "syn 1.0.103", ] +[[package]] +name = "serde_spanned" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" +dependencies = [ + "serde", +] + [[package]] name = "sha2" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.6", + "digest", ] [[package]] name = "sha3" -version = "0.10.6" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdf0c33fae925bdc080598b84bc15c55e7b9a4a43b3c704da051f977469691c9" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" dependencies = [ - "digest 0.10.6", + "digest", "keccak", ] +[[package]] +name = "sierra-compile" +version = "2.0.2" +dependencies = [ + "anyhow", + "cairo-lang-sierra", + "cairo-lang-sierra-to-casm", + "cairo-lang-utils", + "clap", + "indoc", + "log", +] + [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -2589,11 +2790,21 @@ dependencies = [ "num-traits 0.1.43", ] +[[package]] +name = "starknet-compile" +version = "2.0.2" +dependencies = [ + "anyhow", + "cairo-lang-compiler", + "cairo-lang-starknet", + "clap", +] + [[package]] name = "starknet-crypto" -version = "0.4.2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d49eb65d58fa98a164ad2cd4d04775885386b83bdad6060f168a38ede77c9aed" +checksum = "693e6362f150f9276e429a910481fb7f3bcb8d6aa643743f587cfece0b374874" dependencies = [ "crypto-bigint", "hex", @@ -2604,43 +2815,65 @@ dependencies = [ "rfc6979", "sha2", "starknet-crypto-codegen", - "starknet-curve", + "starknet-curve 0.3.0", "starknet-ff", "zeroize", ] [[package]] name = "starknet-crypto-codegen" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af6527b845423542c8a16e060ea1bc43f67229848e7cd4c4d80be994a84220ce" +dependencies = [ + "starknet-curve 0.4.0", + "starknet-ff", + "syn 2.0.26", +] + +[[package]] +name = "starknet-curve" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff08f74f3ac785ac34ac05c68c5bd4df280107ab35df69dbcbde35183d89eba" +checksum = "252610baff59e4c4332ce3569f7469c5d3f9b415a2240d698fb238b2b4fc0942" dependencies = [ - "starknet-curve", "starknet-ff", - "syn 1.0.103", ] [[package]] name = "starknet-curve" -version = "0.2.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe0dbde7ef14d54c2117bc6d2efb68c2383005f1cd749b277c11df874d07b7af" +checksum = "a68a0d87ae56572abf83ddbfd44259a7c90dbeeee1629a1ffe223e7f9a8f3052" dependencies = [ "starknet-ff", ] [[package]] name = "starknet-ff" -version = "0.3.1" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78d484109da192f3a8cd58f674861c2d5e4b3e1765a466362c6f350ef213dfd1" +checksum = "db2cb1d9c0a50380cddab99cb202c6bfb3332728a2769bd0ca2ee80b0b390dd4" dependencies = [ - "ark-ff 0.3.0", + "ark-ff", "crypto-bigint", "getrandom", "hex", ] +[[package]] +name = "starknet-sierra-compile" +version = "2.0.2" +dependencies = [ + "anyhow", + "cairo-lang-sierra", + "cairo-lang-starknet", + "cairo-lang-utils", + "clap", + "serde", + "serde_json", +] + [[package]] name = "string_cache" version = "0.8.4" @@ -2679,9 +2912,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.3" +version = "2.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8234ae35e70582bfa0f1fedffa6daa248e41dd045310b19800c4a36382c8f60" +checksum = "45c3457aacde3c65315de5031ec191ce46604304d2446e803d71ade03308d970" dependencies = [ "proc-macro2", "quote", @@ -2728,18 +2961,18 @@ dependencies = [ [[package]] name = "test-case" -version = "2.2.2" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21d6cf5a7dffb3f9dceec8e6b8ca528d9bd71d36c9f074defb548ce161f598c0" +checksum = "2a1d6e7bde536b0412f20765b76e921028059adfd1b90d8974d33fd3c91b25df" dependencies = [ "test-case-macros", ] [[package]] -name = "test-case-macros" -version = "2.2.2" +name = "test-case-core" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e45b7bf6e19353ddd832745c8fcf77a17a93171df7151187f26623f2b75b5b26" +checksum = "d10394d5d1e27794f772b6fc854c7e91a2dc26e2cbf807ad523370c2a59c0cee" dependencies = [ "cfg-if", "proc-macro-error", @@ -2748,6 +2981,19 @@ dependencies = [ "syn 1.0.103", ] +[[package]] +name = "test-case-macros" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eeb9a44b1c6a54c1ba58b152797739dba2a83ca74e18168a68c980eb142f9404" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.103", + "test-case-core", +] + [[package]] name = "test-log" version = "0.2.11" @@ -2761,7 +3007,7 @@ dependencies = [ [[package]] name = "tests" -version = "1.1.1" +version = "2.0.2" dependencies = [ "assert_matches", "cairo-felt", @@ -2783,7 +3029,7 @@ dependencies = [ "cairo-lang-test-utils", "cairo-lang-utils", "env_logger", - "itertools", + "itertools 0.11.0", "log", "num-bigint", "once_cell", @@ -2811,7 +3057,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.3", + "syn 2.0.26", ] [[package]] @@ -2943,11 +3189,36 @@ dependencies = [ [[package]] name = "toml" -version = "0.4.10" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17e963a819c331dcacd7ab957d80bc2b9a9c1e71c804826d2f283dd65306542" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.19.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" +checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a" dependencies = [ + "indexmap 2.0.0", "serde", + "serde_spanned", + "toml_datetime", + "winnow", ] [[package]] @@ -2972,9 +3243,9 @@ checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" [[package]] name = "tower-lsp" -version = "0.17.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43e094780b4447366c59f79acfd65b1375ecaa84e61dddbde1421aa506334024" +checksum = "9b38fb0e6ce037835174256518aace3ca621c4f96383c56bb846cfc11b341910" dependencies = [ "async-trait", "auto_impl", @@ -2982,7 +3253,6 @@ dependencies = [ "dashmap", "futures", "httparse", - "log", "lsp-types", "memchr", "serde", @@ -2991,13 +3261,14 @@ dependencies = [ "tokio-util", "tower", "tower-lsp-macros", + "tracing", ] [[package]] name = "tower-lsp-macros" -version = "0.6.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebd99eec668d0a450c177acbc4d05e0d0d13b1f8d3db13cd706c52cbec4ac04" +checksum = "34723c06344244474fdde365b76aebef8050bf6be61a935b91ee9ff7c4e91157" dependencies = [ "proc-macro2", "quote", @@ -3018,9 +3289,21 @@ checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.26", +] + [[package]] name = "tracing-core" version = "0.1.30" @@ -3036,12 +3319,6 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" -[[package]] -name = "ucd-trie" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" - [[package]] name = "unescaper" version = "0.1.1" @@ -3285,6 +3562,15 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +[[package]] +name = "winnow" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fac9742fd1ad1bd9643b991319f72dd031016d44b77039a26977eb667141e7" +dependencies = [ + "memchr", +] + [[package]] name = "wyz" version = "0.5.1" @@ -3317,9 +3603,9 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" [[package]] name = "zeroize" -version = "1.5.7" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" dependencies = [ "zeroize_derive", ] diff --git a/Cargo.toml b/Cargo.toml index 3927b6991..753694083 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,6 @@ +[profile.release] +overflow-checks = true # Enable integer overflow checks. + [workspace] members = [ @@ -22,16 +25,26 @@ members = [ "cairo/crates/cairo-lang-sierra-gas", "cairo/crates/cairo-lang-sierra-generator", "cairo/crates/cairo-lang-sierra-to-casm", + "cairo/crates/cairo-lang-sierra-type-size", "cairo/crates/cairo-lang-starknet", "cairo/crates/cairo-lang-syntax", "cairo/crates/cairo-lang-syntax-codegen", "cairo/crates/cairo-lang-test-runner", "cairo/crates/cairo-lang-utils", + "cairo/crates/bin/cairo-language-server", + "cairo/crates/bin/cairo-compile", + "cairo/crates/bin/cairo-format", + "cairo/crates/bin/cairo-test", + "cairo/crates/bin/cairo-run", + "cairo/crates/bin/sierra-compile", + "cairo/crates/bin/starknet-compile", + "cairo/crates/bin/starknet-sierra-compile", + "cairo/crates/bin/generate-syntax", "cairo/tests", ] [workspace.package] -version = "1.1.1" +version = "2.0.2" edition = "2021" repository = "https://github.com/starkware-libs/cairo/" license = "Apache-2.0" @@ -40,53 +53,63 @@ license-file = "LICENSE" [workspace.dependencies] anyhow = "1.0.66" ark-ff = "0.4.0-alpha.7" -ark-std = "0.3.0" +ark-secp256k1 = "0.4.0" +ark-secp256r1 = "0.4.0" +ark-std = "0.4.0" assert_matches = "1.5" bimap = "0.6.2" -cairo-felt = "0.3.0-rc1" -cairo-vm = "0.3.0-rc1" +cairo-felt = "0.8.2" +cairo-vm = "0.8.2" clap = { version = "4.0", features = ["derive"] } colored = "2" const-fnv1a-hash = "1.1.0" convert_case = "0.6.0" derivative = "2.2.0" diffy = "0.3.0" -env_logger = "0.9.3" +env_logger = "0.10.0" genco = "0.17.0" good_lp = { version = "1.3.2", features = ["minilp"], default-features = false } id-arena = "2.2.1" ignore = "0.4.20" -indexmap = { version = "1.9.1", features = ["serde"] } +indent = "0.1.1" +indexmap = { version = "2.0.0", features = ["serde"] } indoc = "2.0.1" -itertools = "0.10.3" +itertools = "0.11.0" keccak = "0.1.3" -lalrpop-util = { version = "0.19.9", features = ["lexer"] } +lalrpop-util = { version = "0.20.0", features = ["lexer"] } log = "0.4" -lsp = { version = "0.93", package = "lsp-types" } +lsp = { version = "0.94", package = "lsp-types" } num-bigint = "0.4" num-integer = "0.1" num-traits = "0.2" once_cell = "1.17.1" -path-clean = "0.1.0" +parity-scale-codec = "3.5.0" +parity-scale-codec-derive = "3.1.4" +path-clean = "1.0.1" pretty_assertions = "1.2.1" proc-macro2 = "1.0" quote = "1.0.21" rayon = "1.7.0" -rstest = "0.16.0" +rstest = "0.18.1" salsa = "0.16.1" -scarb-metadata = "1.0.1" +scarb-metadata = "1.4.2" +schemars = { version = "0.8.12", features = ["preserve_order"] } serde = { version = "1.0.130", features = ["derive"] } serde_json = "1.0" sha3 = "0.10.6" smol_str = { version = "0.2.0", features = ["serde"] } -syn = { version = "1.0.99", features = ["full", "extra-traits"] } -test-case = "2.2.2" +syn = { version = "2.0.25", features = ["full", "extra-traits"] } +test-case = "3.1.0" test-case-macros = "2.2.2" test-log = "0.2.11" thiserror = "1.0.32" -time = { version = "0.3.20", features = ["formatting", "macros", "local-offset"] } +time = { version = "0.3.20", features = [ + "formatting", + "macros", + "local-offset", +] } tokio = { version = "1.18.2", features = ["full", "sync"] } -toml = "0.4.2" -tower-lsp = "0.17.0" +toml = "0.7.6" +tower-lsp = "0.19.0" unescaper = "0.1.1" xshell = "0.2.2" diff --git a/cairo b/cairo index c6b003cc4..06722bd86 160000 --- a/cairo +++ b/cairo @@ -1 +1 @@ -Subproject commit c6b003cc425907ac5fc846375a48737d5125f5b5 +Subproject commit 06722bd868b675500f61e87125cc5db519592e63 diff --git a/src/openzeppelin/introspection.cairo b/src/openzeppelin/introspection.cairo index 0819e4257..184f921e7 100644 --- a/src/openzeppelin/introspection.cairo +++ b/src/openzeppelin/introspection.cairo @@ -1,2 +1,3 @@ mod src5; mod dual_src5; +mod interface; diff --git a/src/openzeppelin/introspection/dual_src5.cairo b/src/openzeppelin/introspection/dual_src5.cairo index f693aac45..ca6868cae 100644 --- a/src/openzeppelin/introspection/dual_src5.cairo +++ b/src/openzeppelin/introspection/dual_src5.cairo @@ -2,7 +2,6 @@ use array::ArrayTrait; use starknet::ContractAddress; use openzeppelin::utils::selectors; -use openzeppelin::utils::serde::SerializedAppend; use openzeppelin::utils::try_selector_with_fallback; use openzeppelin::utils::UnwrapAndCast; @@ -17,8 +16,7 @@ trait DualCaseSRC5Trait { impl DualCaseSRC5Impl of DualCaseSRC5Trait { fn supports_interface(self: @DualCaseSRC5, interface_id: felt252) -> bool { - let mut args = ArrayTrait::new(); - args.append_serde(interface_id); + let mut args = array![interface_id]; try_selector_with_fallback( *self.contract_address, diff --git a/src/openzeppelin/introspection/src5.cairo b/src/openzeppelin/introspection/src5.cairo index 2b0384098..b4beeff1b 100644 --- a/src/openzeppelin/introspection/src5.cairo +++ b/src/openzeppelin/introspection/src5.cairo @@ -1,56 +1,50 @@ -const ISRC5_ID: felt252 = 0x3f918d17e5ee77373b56385708f855659a07f75997f365cf87748628532a055; - -#[abi] -trait ISRC5 { - fn supports_interface(interface_id: felt252) -> bool; -} - -#[abi] -trait ISRC5Camel { - fn supportsInterface(interfaceId: felt252) -> bool; -} - -#[contract] +#[starknet::contract] mod SRC5 { - use openzeppelin::introspection::src5; + use openzeppelin::introspection::interface; + #[storage] struct Storage { supported_interfaces: LegacyMap } - impl SRC5Impl of src5::ISRC5 { - fn supports_interface(interface_id: felt252) -> bool { - if interface_id == src5::ISRC5_ID { + #[external(v0)] + impl SRC5Impl of interface::ISRC5 { + fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { + if interface_id == interface::ISRC5_ID { return true; } - supported_interfaces::read(interface_id) + self.supported_interfaces.read(interface_id) } } - impl SRC5CamelImpl of src5::ISRC5Camel { - fn supportsInterface(interfaceId: felt252) -> bool { - SRC5Impl::supports_interface(interfaceId) + #[external(v0)] + impl SRC5CamelImpl of interface::ISRC5Camel { + fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { + SRC5Impl::supports_interface(self, interfaceId) } } - #[view] - fn supports_interface(interface_id: felt252) -> bool { - SRC5Impl::supports_interface(interface_id) - } + #[external(v0)] + impl RegisterImpl of interface::RegisterTrait { + fn register_interface(ref self: ContractState, interface_id: felt252) { + self.supported_interfaces.write(interface_id, true); + } - #[view] - fn supportsInterface(interfaceId: felt252) -> bool { - SRC5CamelImpl::supportsInterface(interfaceId) + fn deregister_interface(ref self: ContractState, interface_id: felt252) { + assert(interface_id != interface::ISRC5_ID, 'SRC5: invalid id'); + self.supported_interfaces.write(interface_id, false); + } } - #[internal] - fn register_interface(interface_id: felt252) { - supported_interfaces::write(interface_id, true); - } + #[external(v0)] + impl RegisterCamelImpl of interface::RegisterCamelTrait { + fn registerInterface(ref self: ContractState, interfaceId: felt252) { + self.supported_interfaces.write(interfaceId, true); + } - #[internal] - fn deregister_interface(interface_id: felt252) { - assert(interface_id != src5::ISRC5_ID, 'SRC5: invalid id'); - supported_interfaces::write(interface_id, false); + fn deregisterInterface(ref self: ContractState, interfaceId: felt252) { + assert(interfaceId != interface::ISRC5_ID, 'SRC5: invalid id'); + self.supported_interfaces.write(interfaceId, false); + } } } diff --git a/src/openzeppelin/lib.cairo b/src/openzeppelin/lib.cairo index 47d73c605..03d22fd58 100644 --- a/src/openzeppelin/lib.cairo +++ b/src/openzeppelin/lib.cairo @@ -1,7 +1,7 @@ -mod access; +// mod access; mod introspection; -mod security; -mod account; -mod token; +// mod security; +// mod account; +// mod token; mod tests; mod utils; diff --git a/src/openzeppelin/tests.cairo b/src/openzeppelin/tests.cairo index 0110b5abc..7f8a46378 100644 --- a/src/openzeppelin/tests.cairo +++ b/src/openzeppelin/tests.cairo @@ -1,9 +1,9 @@ -mod access; -mod test_reentrancyguard; +// mod access; +// mod test_reentrancyguard; mod introspection; -mod account; -mod token; -mod test_initializable; -mod test_pausable; +// mod account; +// mod token; +// mod test_initializable; +// mod test_pausable; mod mocks; mod utils; diff --git a/src/openzeppelin/tests/access/test_dual_accesscontrol.cairo b/src/openzeppelin/tests/access/test_dual_accesscontrol.cairo index 83908f95d..7a229576e 100644 --- a/src/openzeppelin/tests/access/test_dual_accesscontrol.cairo +++ b/src/openzeppelin/tests/access/test_dual_accesscontrol.cairo @@ -42,11 +42,8 @@ fn setup_snake() -> (DualCaseAccessControl, IAccessControlDispatcher) { calldata.append_serde(ADMIN()); let target = utils::deploy(SnakeAccessControlMock::TEST_CLASS_HASH, calldata); ( - DualCaseAccessControl { - contract_address: target - }, IAccessControlDispatcher { - contract_address: target - } + DualCaseAccessControl { contract_address: target }, + IAccessControlDispatcher { contract_address: target } ) } @@ -55,11 +52,8 @@ fn setup_camel() -> (DualCaseAccessControl, IAccessControlCamelDispatcher) { calldata.append_serde(ADMIN()); let target = utils::deploy(CamelAccessControlMock::TEST_CLASS_HASH, calldata); ( - DualCaseAccessControl { - contract_address: target - }, IAccessControlCamelDispatcher { - contract_address: target - } + DualCaseAccessControl { contract_address: target }, + IAccessControlCamelDispatcher { contract_address: target } ) } @@ -77,11 +71,8 @@ fn setup_accesscontrol_panic() -> (DualCaseAccessControl, DualCaseAccessControl) CamelAccessControlPanicMock::TEST_CLASS_HASH, ArrayTrait::new() ); ( - DualCaseAccessControl { - contract_address: snake_target - }, DualCaseAccessControl { - contract_address: camel_target - } + DualCaseAccessControl { contract_address: snake_target }, + DualCaseAccessControl { contract_address: camel_target } ) } diff --git a/src/openzeppelin/tests/access/test_dual_ownable.cairo b/src/openzeppelin/tests/access/test_dual_ownable.cairo index 87841fe8d..aa86d3874 100644 --- a/src/openzeppelin/tests/access/test_dual_ownable.cairo +++ b/src/openzeppelin/tests/access/test_dual_ownable.cairo @@ -47,11 +47,8 @@ fn setup_camel() -> (DualCaseOwnable, IOwnableCamelDispatcher) { calldata.append_serde(OWNER()); let target = utils::deploy(CamelOwnableMock::TEST_CLASS_HASH, calldata); ( - DualCaseOwnable { - contract_address: target - }, IOwnableCamelDispatcher { - contract_address: target - } + DualCaseOwnable { contract_address: target }, + IOwnableCamelDispatcher { contract_address: target } ) } @@ -65,11 +62,8 @@ fn setup_ownable_panic() -> (DualCaseOwnable, DualCaseOwnable) { let snake_target = utils::deploy(SnakeOwnablePanicMock::TEST_CLASS_HASH, ArrayTrait::new()); let camel_target = utils::deploy(CamelOwnablePanicMock::TEST_CLASS_HASH, ArrayTrait::new()); ( - DualCaseOwnable { - contract_address: snake_target - }, DualCaseOwnable { - contract_address: camel_target - } + DualCaseOwnable { contract_address: snake_target }, + DualCaseOwnable { contract_address: camel_target } ) } diff --git a/src/openzeppelin/tests/account/test_dual_account.cairo b/src/openzeppelin/tests/account/test_dual_account.cairo index 946119a6c..1d4e23840 100644 --- a/src/openzeppelin/tests/account/test_dual_account.cairo +++ b/src/openzeppelin/tests/account/test_dual_account.cairo @@ -33,11 +33,8 @@ fn setup_snake() -> (DualCaseAccount, AccountABIDispatcher) { calldata.append_serde(PUBLIC_KEY); let target = utils::deploy(SnakeAccountMock::TEST_CLASS_HASH, calldata); ( - DualCaseAccount { - contract_address: target - }, AccountABIDispatcher { - contract_address: target - } + DualCaseAccount { contract_address: target }, + AccountABIDispatcher { contract_address: target } ) } @@ -46,11 +43,8 @@ fn setup_camel() -> (DualCaseAccount, AccountABICamelDispatcher) { calldata.append_serde(PUBLIC_KEY); let target = utils::deploy(CamelAccountMock::TEST_CLASS_HASH, calldata); ( - DualCaseAccount { - contract_address: target - }, AccountABICamelDispatcher { - contract_address: target - } + DualCaseAccount { contract_address: target }, + AccountABICamelDispatcher { contract_address: target } ) } @@ -64,11 +58,8 @@ fn setup_account_panic() -> (DualCaseAccount, DualCaseAccount) { let snake_target = utils::deploy(SnakeAccountPanicMock::TEST_CLASS_HASH, ArrayTrait::new()); let camel_target = utils::deploy(CamelAccountPanicMock::TEST_CLASS_HASH, ArrayTrait::new()); ( - DualCaseAccount { - contract_address: snake_target - }, DualCaseAccount { - contract_address: camel_target - } + DualCaseAccount { contract_address: snake_target }, + DualCaseAccount { contract_address: camel_target } ) } diff --git a/src/openzeppelin/tests/introspection/test_dual_src5.cairo b/src/openzeppelin/tests/introspection/test_dual_src5.cairo index 5693b941c..4e47773cc 100644 --- a/src/openzeppelin/tests/introspection/test_dual_src5.cairo +++ b/src/openzeppelin/tests/introspection/test_dual_src5.cairo @@ -1,9 +1,9 @@ use array::ArrayTrait; -use openzeppelin::introspection::src5::ISRC5_ID; -use openzeppelin::introspection::src5::ISRC5Dispatcher; -use openzeppelin::introspection::src5::ISRC5DispatcherTrait; -use openzeppelin::introspection::src5::ISRC5CamelDispatcher; -use openzeppelin::introspection::src5::ISRC5CamelDispatcherTrait; +use openzeppelin::introspection::interface::ISRC5_ID; +use openzeppelin::introspection::interface::ISRC5Dispatcher; +use openzeppelin::introspection::interface::ISRC5DispatcherTrait; +use openzeppelin::introspection::interface::ISRC5CamelDispatcher; +use openzeppelin::introspection::interface::ISRC5CamelDispatcherTrait; use openzeppelin::introspection::dual_src5::DualCaseSRC5; use openzeppelin::introspection::dual_src5::DualCaseSRC5Trait; use openzeppelin::tests::mocks::src5_mocks::SnakeSRC5Mock; @@ -18,32 +18,29 @@ use openzeppelin::tests::utils; // fn setup_snake() -> DualCaseSRC5 { - let mut calldata = ArrayTrait::new(); + let mut calldata = array![]; let target = utils::deploy(SnakeSRC5Mock::TEST_CLASS_HASH, calldata); DualCaseSRC5 { contract_address: target } } fn setup_camel() -> DualCaseSRC5 { - let mut calldata = ArrayTrait::new(); + let mut calldata = array![]; let target = utils::deploy(CamelSRC5Mock::TEST_CLASS_HASH, calldata); DualCaseSRC5 { contract_address: target } } fn setup_non_src5() -> DualCaseSRC5 { - let calldata = ArrayTrait::new(); + let calldata = array![]; let target = utils::deploy(NonImplementingMock::TEST_CLASS_HASH, calldata); DualCaseSRC5 { contract_address: target } } fn setup_src5_panic() -> (DualCaseSRC5, DualCaseSRC5) { - let snake_target = utils::deploy(SnakeSRC5PanicMock::TEST_CLASS_HASH, ArrayTrait::new()); - let camel_target = utils::deploy(CamelSRC5PanicMock::TEST_CLASS_HASH, ArrayTrait::new()); + let snake_target = utils::deploy(SnakeSRC5PanicMock::TEST_CLASS_HASH, array![]); + let camel_target = utils::deploy(CamelSRC5PanicMock::TEST_CLASS_HASH, array![]); ( - DualCaseSRC5 { - contract_address: snake_target - }, DualCaseSRC5 { - contract_address: camel_target - } + DualCaseSRC5 { contract_address: snake_target }, + DualCaseSRC5 { contract_address: camel_target } ) } diff --git a/src/openzeppelin/tests/introspection/test_src5.cairo b/src/openzeppelin/tests/introspection/test_src5.cairo index 9b43bf894..5a0aab6ff 100644 --- a/src/openzeppelin/tests/introspection/test_src5.cairo +++ b/src/openzeppelin/tests/introspection/test_src5.cairo @@ -1,36 +1,44 @@ use openzeppelin::introspection::src5::SRC5; -use openzeppelin::introspection::src5::ISRC5_ID; +use openzeppelin::introspection::interface::ISRC5_ID; const OTHER_ID: felt252 = 0x12345678; +fn STATE() -> SRC5::ContractState { + SRC5::contract_state_for_testing() +} + #[test] #[available_gas(2000000)] fn test_default_behavior() { - let supports_default_interface: bool = SRC5::supports_interface(ISRC5_ID); + let supports_default_interface: bool = SRC5::SRC5Impl::supports_interface(@STATE(), ISRC5_ID); assert(supports_default_interface, 'Should support base interface'); } #[test] #[available_gas(2000000)] fn test_not_registered_interface() { - let supports_unregistered_interface: bool = SRC5::supports_interface(OTHER_ID); + let supports_unregistered_interface: bool = SRC5::SRC5Impl::supports_interface( + @STATE(), OTHER_ID + ); assert(!supports_unregistered_interface, 'Should not support unregistered'); } #[test] #[available_gas(2000000)] fn test_register_interface() { - SRC5::register_interface(OTHER_ID); - let supports_new_interface: bool = SRC5::supports_interface(OTHER_ID); + let mut state = STATE(); + SRC5::RegisterImpl::register_interface(ref state, OTHER_ID); + let supports_new_interface: bool = SRC5::SRC5Impl::supports_interface(@state, OTHER_ID); assert(supports_new_interface, 'Should support new interface'); } #[test] #[available_gas(2000000)] fn test_deregister_interface() { - SRC5::register_interface(OTHER_ID); - SRC5::deregister_interface(OTHER_ID); - let supports_old_interface: bool = SRC5::supports_interface(OTHER_ID); + let mut state = STATE(); + SRC5::RegisterImpl::register_interface(ref state, OTHER_ID); + SRC5::RegisterImpl::deregister_interface(ref state, OTHER_ID); + let supports_old_interface: bool = SRC5::SRC5Impl::supports_interface(@state, OTHER_ID); assert(!supports_old_interface, 'Should not support interface'); } @@ -38,5 +46,6 @@ fn test_deregister_interface() { #[available_gas(2000000)] #[should_panic(expected: ('SRC5: invalid id', ))] fn test_deregister_default_interface() { - SRC5::deregister_interface(ISRC5_ID); + let mut state = STATE(); + SRC5::RegisterImpl::deregister_interface(ref state, ISRC5_ID); } diff --git a/src/openzeppelin/tests/mocks.cairo b/src/openzeppelin/tests/mocks.cairo index 7ed138560..d8bdaa92b 100644 --- a/src/openzeppelin/tests/mocks.cairo +++ b/src/openzeppelin/tests/mocks.cairo @@ -1,21 +1,21 @@ -mod reentrancy_attacker_mock; -mod reentrancy_mock; -mod erc721_receiver; -mod erc721_panic_mock; -mod mock_pausable; -mod camel20_mock; -mod snake20_mock; -mod erc20_panic; -mod non721_mock; -mod accesscontrol_panic_mock; -mod account_panic_mock; -mod camel_accesscontrol_mock; -mod camel_account_mock; -mod snake_accesscontrol_mock; -mod snake_account_mock; -mod dual_ownable_mocks; -mod snake721_mock; -mod camel721_mock; +// mod reentrancy_attacker_mock; +// mod reentrancy_mock; +// mod erc721_receiver; +// mod erc721_panic_mock; +// mod mock_pausable; +// mod camel20_mock; +// mod snake20_mock; +// mod erc20_panic; +// mod non721_mock; +// mod accesscontrol_panic_mock; +// mod account_panic_mock; +// mod camel_accesscontrol_mock; +// mod camel_account_mock; +// mod snake_accesscontrol_mock; +// mod snake_account_mock; +// mod dual_ownable_mocks; +// mod snake721_mock; +// mod camel721_mock; mod non_implementing_mock; -mod dual721_receiver_mocks; +// mod dual721_receiver_mocks; mod src5_mocks; diff --git a/src/openzeppelin/tests/mocks/non_implementing_mock.cairo b/src/openzeppelin/tests/mocks/non_implementing_mock.cairo index d614d1da7..ffa12f857 100644 --- a/src/openzeppelin/tests/mocks/non_implementing_mock.cairo +++ b/src/openzeppelin/tests/mocks/non_implementing_mock.cairo @@ -1,7 +1,10 @@ -#[contract] +#[starknet::contract] mod NonImplementingMock { - #[view] - fn nope() -> bool { + #[storage] + struct Storage {} + + #[external(v0)] + fn nope(self: @ContractState) -> bool { false } } diff --git a/src/openzeppelin/tests/mocks/src5_mocks.cairo b/src/openzeppelin/tests/mocks/src5_mocks.cairo index 28ccf2b6b..cebdd0910 100644 --- a/src/openzeppelin/tests/mocks/src5_mocks.cairo +++ b/src/openzeppelin/tests/mocks/src5_mocks.cairo @@ -1,34 +1,48 @@ use openzeppelin::introspection::src5::SRC5; -#[contract] +#[starknet::contract] mod SnakeSRC5Mock { - #[view] - fn supports_interface(interface_id: felt252) -> bool { - super::SRC5::supports_interface(interface_id) + #[storage] + struct Storage {} + + #[external(v0)] + fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { + let unsafe_state = super::SRC5::unsafe_new_contract_state(); + super::SRC5::SRC5Impl::supports_interface(@unsafe_state, interface_id) } } -#[contract] +#[starknet::contract] mod CamelSRC5Mock { - #[view] - fn supportsInterface(interfaceId: felt252) -> bool { - super::SRC5::supportsInterface(interfaceId) + #[storage] + struct Storage {} + + #[external(v0)] + fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { + let unsafe_state = super::SRC5::unsafe_new_contract_state(); + super::SRC5::SRC5CamelImpl::supportsInterface(@unsafe_state, interfaceId) } } -#[contract] +#[starknet::contract] mod SnakeSRC5PanicMock { - #[view] - fn supports_interface(interface_id: felt252) -> bool { + #[storage] + struct Storage {} + + #[external(v0)] + fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { panic_with_felt252('Some error'); false } } -#[contract] +#[starknet::contract] mod CamelSRC5PanicMock { - #[view] - fn supportsInterface(interfaceId: felt252) -> bool { + #[storage] + struct Storage {} + + #[external(v0)] + fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { panic_with_felt252('Some error'); false } diff --git a/src/openzeppelin/tests/token/test_dual721.cairo b/src/openzeppelin/tests/token/test_dual721.cairo index 4adab5d29..b0e45e568 100644 --- a/src/openzeppelin/tests/token/test_dual721.cairo +++ b/src/openzeppelin/tests/token/test_dual721.cairo @@ -76,11 +76,8 @@ fn setup_camel() -> (DualCaseERC721, IERC721CamelDispatcher) { set_caller_address(OWNER()); let target = utils::deploy(CamelERC721Mock::TEST_CLASS_HASH, calldata); ( - DualCaseERC721 { - contract_address: target - }, IERC721CamelDispatcher { - contract_address: target - } + DualCaseERC721 { contract_address: target }, + IERC721CamelDispatcher { contract_address: target } ) } @@ -94,11 +91,8 @@ fn setup_erc721_panic() -> (DualCaseERC721, DualCaseERC721) { let snake_target = utils::deploy(SnakeERC721PanicMock::TEST_CLASS_HASH, ArrayTrait::new()); let camel_target = utils::deploy(CamelERC721PanicMock::TEST_CLASS_HASH, ArrayTrait::new()); ( - DualCaseERC721 { - contract_address: snake_target - }, DualCaseERC721 { - contract_address: camel_target - } + DualCaseERC721 { contract_address: snake_target }, + DualCaseERC721 { contract_address: camel_target } ) } diff --git a/src/openzeppelin/tests/token/test_dual721_receiver.cairo b/src/openzeppelin/tests/token/test_dual721_receiver.cairo index ef02380a9..a3197dddc 100644 --- a/src/openzeppelin/tests/token/test_dual721_receiver.cairo +++ b/src/openzeppelin/tests/token/test_dual721_receiver.cairo @@ -49,11 +49,8 @@ fn setup_snake() -> (DualCaseERC721Receiver, IERC721ReceiverDispatcher) { let mut calldata = ArrayTrait::new(); let target = utils::deploy(SnakeERC721ReceiverMock::TEST_CLASS_HASH, calldata); ( - DualCaseERC721Receiver { - contract_address: target - }, IERC721ReceiverDispatcher { - contract_address: target - } + DualCaseERC721Receiver { contract_address: target }, + IERC721ReceiverDispatcher { contract_address: target } ) } @@ -61,11 +58,8 @@ fn setup_camel() -> (DualCaseERC721Receiver, IERC721ReceiverCamelDispatcher) { let mut calldata = ArrayTrait::new(); let target = utils::deploy(CamelERC721ReceiverMock::TEST_CLASS_HASH, calldata); ( - DualCaseERC721Receiver { - contract_address: target - }, IERC721ReceiverCamelDispatcher { - contract_address: target - } + DualCaseERC721Receiver { contract_address: target }, + IERC721ReceiverCamelDispatcher { contract_address: target } ) } @@ -83,11 +77,8 @@ fn setup_erc721_receiver_panic() -> (DualCaseERC721Receiver, DualCaseERC721Recei CamelERC721ReceiverPanicMock::TEST_CLASS_HASH, ArrayTrait::new() ); ( - DualCaseERC721Receiver { - contract_address: snake_target - }, DualCaseERC721Receiver { - contract_address: camel_target - } + DualCaseERC721Receiver { contract_address: snake_target }, + DualCaseERC721Receiver { contract_address: camel_target } ) } diff --git a/src/openzeppelin/token/erc721/erc721.cairo b/src/openzeppelin/token/erc721/erc721.cairo index 3cda6ff3f..339c63ebd 100644 --- a/src/openzeppelin/token/erc721/erc721.cairo +++ b/src/openzeppelin/token/erc721/erc721.cairo @@ -454,12 +454,9 @@ mod ERC721 { fn _check_on_erc721_received( from: ContractAddress, to: ContractAddress, token_id: u256, data: Span ) -> bool { - if (DualCaseSRC5 { - contract_address: to - }.supports_interface(erc721::interface::IERC721_RECEIVER_ID)) { - DualCaseERC721Receiver { - contract_address: to - } + if (DualCaseSRC5 { contract_address: to } + .supports_interface(erc721::interface::IERC721_RECEIVER_ID)) { + DualCaseERC721Receiver { contract_address: to } .on_erc721_received( get_caller_address(), from, token_id, data ) == erc721::interface::IERC721_RECEIVER_ID diff --git a/src/openzeppelin/utils/serde.cairo b/src/openzeppelin/utils/serde.cairo index aca966485..45b33c8e4 100644 --- a/src/openzeppelin/utils/serde.cairo +++ b/src/openzeppelin/utils/serde.cairo @@ -1,22 +1,6 @@ use array::ArrayTrait; use array::SpanTrait; use serde::Serde; -use serde::serialize_array_helper; -use serde::deserialize_array_helper; - -impl SpanSerde< - T, impl TSerde: Serde, impl TCopy: Copy, impl TDrop: Drop -> of Serde> { - fn serialize(self: @Span, ref output: Array) { - (*self).len().serialize(ref output); - serialize_array_helper(*self, ref output); - } - fn deserialize(ref serialized: Span) -> Option> { - let length = *serialized.pop_front()?; - let mut arr = ArrayTrait::new(); - Option::Some(deserialize_array_helper(ref serialized, arr, length)?.span()) - } -} trait SerializedAppend { fn append_serde(ref self: Array, value: T); From 0b4592e5e9931a3d059a8e00fdf4d9316d8cf6dd Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Mon, 17 Jul 2023 23:04:46 +0200 Subject: [PATCH 2/7] feat: add interface.cairo --- .../introspection/interface.cairo | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/openzeppelin/introspection/interface.cairo diff --git a/src/openzeppelin/introspection/interface.cairo b/src/openzeppelin/introspection/interface.cairo new file mode 100644 index 000000000..bc2a5633d --- /dev/null +++ b/src/openzeppelin/introspection/interface.cairo @@ -0,0 +1,23 @@ +const ISRC5_ID: felt252 = 0x3f918d17e5ee77373b56385708f855659a07f75997f365cf87748628532a055; + +#[starknet::interface] +trait ISRC5 { + fn supports_interface(self: @TState, interface_id: felt252) -> bool; +} + +#[starknet::interface] +trait ISRC5Camel { + fn supportsInterface(self: @TState, interfaceId: felt252) -> bool; +} + +#[starknet::interface] +trait RegisterTrait { + fn register_interface(ref self: TState, interface_id: felt252); + fn deregister_interface(ref self: TState, interface_id: felt252); +} + +#[starknet::interface] +trait RegisterCamelTrait { + fn registerInterface(ref self: TState, interfaceId: felt252); + fn deregisterInterface(ref self: TState, interfaceId: felt252); +} From d570da4462d023d323f6eb68b76ef153c65f7d3c Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Tue, 18 Jul 2023 11:44:06 +0200 Subject: [PATCH 3/7] feat: apply review updates --- src/openzeppelin/introspection/interface.cairo | 12 ------------ src/openzeppelin/introspection/src5.cairo | 16 ++-------------- .../tests/introspection/test_src5.cairo | 8 ++++---- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/src/openzeppelin/introspection/interface.cairo b/src/openzeppelin/introspection/interface.cairo index bc2a5633d..68909245c 100644 --- a/src/openzeppelin/introspection/interface.cairo +++ b/src/openzeppelin/introspection/interface.cairo @@ -9,15 +9,3 @@ trait ISRC5 { trait ISRC5Camel { fn supportsInterface(self: @TState, interfaceId: felt252) -> bool; } - -#[starknet::interface] -trait RegisterTrait { - fn register_interface(ref self: TState, interface_id: felt252); - fn deregister_interface(ref self: TState, interface_id: felt252); -} - -#[starknet::interface] -trait RegisterCamelTrait { - fn registerInterface(ref self: TState, interfaceId: felt252); - fn deregisterInterface(ref self: TState, interfaceId: felt252); -} diff --git a/src/openzeppelin/introspection/src5.cairo b/src/openzeppelin/introspection/src5.cairo index b4beeff1b..2f9a9389e 100644 --- a/src/openzeppelin/introspection/src5.cairo +++ b/src/openzeppelin/introspection/src5.cairo @@ -24,8 +24,8 @@ mod SRC5 { } } - #[external(v0)] - impl RegisterImpl of interface::RegisterTrait { + #[generate_trait] + impl InternalImpl of InternalTrait { fn register_interface(ref self: ContractState, interface_id: felt252) { self.supported_interfaces.write(interface_id, true); } @@ -35,16 +35,4 @@ mod SRC5 { self.supported_interfaces.write(interface_id, false); } } - - #[external(v0)] - impl RegisterCamelImpl of interface::RegisterCamelTrait { - fn registerInterface(ref self: ContractState, interfaceId: felt252) { - self.supported_interfaces.write(interfaceId, true); - } - - fn deregisterInterface(ref self: ContractState, interfaceId: felt252) { - assert(interfaceId != interface::ISRC5_ID, 'SRC5: invalid id'); - self.supported_interfaces.write(interfaceId, false); - } - } } diff --git a/src/openzeppelin/tests/introspection/test_src5.cairo b/src/openzeppelin/tests/introspection/test_src5.cairo index 5a0aab6ff..97e48f719 100644 --- a/src/openzeppelin/tests/introspection/test_src5.cairo +++ b/src/openzeppelin/tests/introspection/test_src5.cairo @@ -27,7 +27,7 @@ fn test_not_registered_interface() { #[available_gas(2000000)] fn test_register_interface() { let mut state = STATE(); - SRC5::RegisterImpl::register_interface(ref state, OTHER_ID); + SRC5::InternalImpl::register_interface(ref state, OTHER_ID); let supports_new_interface: bool = SRC5::SRC5Impl::supports_interface(@state, OTHER_ID); assert(supports_new_interface, 'Should support new interface'); } @@ -36,8 +36,8 @@ fn test_register_interface() { #[available_gas(2000000)] fn test_deregister_interface() { let mut state = STATE(); - SRC5::RegisterImpl::register_interface(ref state, OTHER_ID); - SRC5::RegisterImpl::deregister_interface(ref state, OTHER_ID); + SRC5::InternalImpl::register_interface(ref state, OTHER_ID); + SRC5::InternalImpl::deregister_interface(ref state, OTHER_ID); let supports_old_interface: bool = SRC5::SRC5Impl::supports_interface(@state, OTHER_ID); assert(!supports_old_interface, 'Should not support interface'); } @@ -47,5 +47,5 @@ fn test_deregister_interface() { #[should_panic(expected: ('SRC5: invalid id', ))] fn test_deregister_default_interface() { let mut state = STATE(); - SRC5::RegisterImpl::deregister_interface(ref state, ISRC5_ID); + SRC5::InternalImpl::deregister_interface(ref state, ISRC5_ID); } From ae857a6e1f729a185ccd03ed784fb48f7f26269c Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Tue, 18 Jul 2023 12:04:00 +0200 Subject: [PATCH 4/7] refactor: improve readability --- .../tests/introspection/test_src5.cairo | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/openzeppelin/tests/introspection/test_src5.cairo b/src/openzeppelin/tests/introspection/test_src5.cairo index 97e48f719..7b0ea5418 100644 --- a/src/openzeppelin/tests/introspection/test_src5.cairo +++ b/src/openzeppelin/tests/introspection/test_src5.cairo @@ -1,4 +1,6 @@ use openzeppelin::introspection::src5::SRC5; +use openzeppelin::introspection::src5::SRC5::SRC5Impl; +use openzeppelin::introspection::src5::SRC5::InternalImpl; use openzeppelin::introspection::interface::ISRC5_ID; const OTHER_ID: felt252 = 0x12345678; @@ -10,16 +12,14 @@ fn STATE() -> SRC5::ContractState { #[test] #[available_gas(2000000)] fn test_default_behavior() { - let supports_default_interface: bool = SRC5::SRC5Impl::supports_interface(@STATE(), ISRC5_ID); + let supports_default_interface = SRC5Impl::supports_interface(@STATE(), ISRC5_ID); assert(supports_default_interface, 'Should support base interface'); } #[test] #[available_gas(2000000)] fn test_not_registered_interface() { - let supports_unregistered_interface: bool = SRC5::SRC5Impl::supports_interface( - @STATE(), OTHER_ID - ); + let supports_unregistered_interface = SRC5Impl::supports_interface(@STATE(), OTHER_ID); assert(!supports_unregistered_interface, 'Should not support unregistered'); } @@ -27,8 +27,8 @@ fn test_not_registered_interface() { #[available_gas(2000000)] fn test_register_interface() { let mut state = STATE(); - SRC5::InternalImpl::register_interface(ref state, OTHER_ID); - let supports_new_interface: bool = SRC5::SRC5Impl::supports_interface(@state, OTHER_ID); + InternalImpl::register_interface(ref state, OTHER_ID); + let supports_new_interface = SRC5Impl::supports_interface(@state, OTHER_ID); assert(supports_new_interface, 'Should support new interface'); } @@ -36,9 +36,9 @@ fn test_register_interface() { #[available_gas(2000000)] fn test_deregister_interface() { let mut state = STATE(); - SRC5::InternalImpl::register_interface(ref state, OTHER_ID); - SRC5::InternalImpl::deregister_interface(ref state, OTHER_ID); - let supports_old_interface: bool = SRC5::SRC5Impl::supports_interface(@state, OTHER_ID); + InternalImpl::register_interface(ref state, OTHER_ID); + InternalImpl::deregister_interface(ref state, OTHER_ID); + let supports_old_interface = SRC5Impl::supports_interface(@state, OTHER_ID); assert(!supports_old_interface, 'Should not support interface'); } @@ -47,5 +47,5 @@ fn test_deregister_interface() { #[should_panic(expected: ('SRC5: invalid id', ))] fn test_deregister_default_interface() { let mut state = STATE(); - SRC5::InternalImpl::deregister_interface(ref state, ISRC5_ID); + InternalImpl::deregister_interface(ref state, ISRC5_ID); } From ded80ca0aa6cdbcdd20883ab1f92c23a1bed243c Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Tue, 18 Jul 2023 13:17:08 +0200 Subject: [PATCH 5/7] fix: dual account tests --- src/openzeppelin/account.cairo | 4 +- src/openzeppelin/account/account.cairo | 278 +++-- src/openzeppelin/account/dual_account.cairo | 11 +- src/openzeppelin/account/interface.cairo | 21 +- src/openzeppelin/lib.cairo | 2 +- src/openzeppelin/tests.cairo | 2 +- .../tests/account/test_account.cairo | 979 +++++++++--------- .../tests/account/test_dual_account.cairo | 50 +- src/openzeppelin/tests/mocks.cairo | 30 +- .../tests/mocks/account_panic_mock.cairo | 43 +- .../tests/mocks/camel_account_mock.cairo | 39 +- .../tests/mocks/snake_account_mock.cairo | 72 +- 12 files changed, 758 insertions(+), 773 deletions(-) diff --git a/src/openzeppelin/account.cairo b/src/openzeppelin/account.cairo index d995b6329..fae14ac00 100644 --- a/src/openzeppelin/account.cairo +++ b/src/openzeppelin/account.cairo @@ -1,7 +1,7 @@ mod account; use account::{ - Account, AccountABIDispatcher, AccountABIDispatcherTrait, AccountABICamelDispatcher, - AccountABICamelDispatcherTrait, TRANSACTION_VERSION, QUERY_VERSION + Account, AccountCamelTraitDispatcher, AccountCamelTraitDispatcherTrait, AccountTraitDispatcher, + AccountTraitDispatcherTrait, TRANSACTION_VERSION, QUERY_VERSION }; mod dual_account; diff --git a/src/openzeppelin/account/account.cairo b/src/openzeppelin/account/account.cairo index 3c7a860ea..a3888f1fc 100644 --- a/src/openzeppelin/account/account.cairo +++ b/src/openzeppelin/account/account.cairo @@ -5,93 +5,91 @@ use serde::Serde; use starknet::ContractAddress; use openzeppelin::account::interface::Call; -use openzeppelin::utils::serde::SpanSerde; const TRANSACTION_VERSION: felt252 = 1; + // 2**128 + TRANSACTION_VERSION const QUERY_VERSION: felt252 = 340282366920938463463374607431768211457; -#[abi] -trait AccountABI { - #[external] - fn __execute__(calls: Array) -> Array>; - #[external] - fn __validate__(calls: Array) -> felt252; - #[external] - fn __validate_declare__(class_hash: felt252) -> felt252; - #[external] +#[starknet::interface] +trait AccountTrait { + fn __execute__(self: @TState, calls: Array) -> Array>; + fn __validate__(self: @TState, calls: Array) -> felt252; + fn __validate_declare__(self: @TState, class_hash: felt252) -> felt252; fn __validate_deploy__( - class_hash: felt252, contract_address_salt: felt252, _public_key: felt252 + self: @TState, class_hash: felt252, contract_address_salt: felt252, _public_key: felt252 ) -> felt252; - #[external] - fn set_public_key(new_public_key: felt252); - #[view] - fn get_public_key() -> felt252; - #[view] - fn is_valid_signature(hash: felt252, signature: Array) -> felt252; - #[view] - fn supports_interface(interface_id: felt252) -> bool; + fn set_public_key(ref self: TState, new_public_key: felt252); + fn get_public_key(self: @TState) -> felt252; + fn is_valid_signature(self: @TState, hash: felt252, signature: Array) -> felt252; + fn supports_interface(self: @TState, interface_id: felt252) -> bool; } // Entry points case-convention is enforced by the protocol -#[abi] -trait AccountABICamel { - #[external] - fn __execute__(calls: Array) -> Array>; - #[external] - fn __validate__(calls: Array) -> felt252; - #[external] - fn __validate_declare__(classHash: felt252) -> felt252; - #[external] +#[starknet::interface] +trait AccountCamelTrait { + fn __execute__(self: @TState, calls: Array) -> Array>; + fn __validate__(self: @TState, calls: Array) -> felt252; + fn __validate_declare__(self: @TState, classHash: felt252) -> felt252; fn __validate_deploy__( - classHash: felt252, contractAddressSalt: felt252, _publicKey: felt252 + self: @TState, classHash: felt252, contractAddressSalt: felt252, _publicKey: felt252 ) -> felt252; - #[external] - fn setPublicKey(newPublicKey: felt252); - #[view] - fn getPublicKey() -> felt252; - #[view] - fn isValidSignature(hash: felt252, signature: Array) -> felt252; - #[view] - fn supportsInterface(interfaceId: felt252) -> bool; + fn setPublicKey(ref self: TState, newPublicKey: felt252); + fn getPublicKey(self: @TState) -> felt252; + fn isValidSignature(self: @TState, hash: felt252, signature: Array) -> felt252; + fn supportsInterface(self: @TState, interfaceId: felt252) -> bool; +} + +#[starknet::interface] +trait PublicKeyTrait { + fn set_public_key(ref self: TState, new_public_key: felt252); + fn get_public_key(self: @TState) -> felt252; } -#[account_contract] +#[starknet::interface] +trait PublicKeyCamelTrait { + fn setPublicKey(ref self: TState, newPublicKey: felt252); + fn getPublicKey(self: @TState) -> felt252; +} + +#[starknet::contract] mod Account { use array::SpanTrait; use array::ArrayTrait; use box::BoxTrait; use ecdsa::check_ecdsa_signature; use option::OptionTrait; - use serde::ArraySerde; use starknet::get_tx_info; use starknet::get_caller_address; use starknet::get_contract_address; use zeroable::Zeroable; - use openzeppelin::account::interface::IDeclarer; - use openzeppelin::account::interface::ISRC6; - use openzeppelin::account::interface::ISRC6Camel; - use openzeppelin::account::interface::ISRC6_ID; - use openzeppelin::introspection::src5::ISRC5; + use openzeppelin::account::interface; + use openzeppelin::introspection::interface::ISRC5; + use openzeppelin::introspection::interface::ISRC5Camel; use openzeppelin::introspection::src5::SRC5; use super::Call; use super::QUERY_VERSION; - use super::SpanSerde; use super::TRANSACTION_VERSION; + #[storage] struct Storage { public_key: felt252 } #[constructor] - fn constructor(_public_key: felt252) { - initializer(_public_key); + fn constructor(ref self: ContractState, _public_key: felt252) { + self.initializer(_public_key); } - impl SRC6Impl of ISRC6 { - fn __execute__(mut calls: Array) -> Array> { + // + // External + // + + #[external(v0)] + impl SRC6Impl of interface::ISRC6 { + fn __execute__(self: @ContractState, mut calls: Array) -> Array> { // Avoid calls from other contracts // https://github.com/OpenZeppelin/cairo-contracts/issues/344 let sender = get_caller_address(); @@ -107,12 +105,14 @@ mod Account { _execute_calls(calls) } - fn __validate__(mut calls: Array) -> felt252 { - validate_transaction() + fn __validate__(self: @ContractState, mut calls: Array) -> felt252 { + self.validate_transaction() } - fn is_valid_signature(hash: felt252, signature: Array) -> felt252 { - if _is_valid_signature(hash, signature.span()) { + fn is_valid_signature( + self: @ContractState, hash: felt252, signature: Array + ) -> felt252 { + if self._is_valid_signature(hash, signature.span()) { starknet::VALIDATED } else { 0 @@ -120,111 +120,105 @@ mod Account { } } - impl SRC6CamelImpl of ISRC6Camel { - fn __execute__(mut calls: Array) -> Array> { - SRC6Impl::__execute__(calls) - } - - fn __validate__(mut calls: Array) -> felt252 { - SRC6Impl::__validate__(calls) + #[external(v0)] + impl SRC6CamelOnlyImpl of interface::ISRC6CamelOnly { + fn isValidSignature( + self: @ContractState, hash: felt252, signature: Array + ) -> felt252 { + SRC6Impl::is_valid_signature(self, hash, signature) } + } - fn isValidSignature(hash: felt252, signature: Array) -> felt252 { - SRC6Impl::is_valid_signature(hash, signature) + #[external(v0)] + impl DeclarerImpl of interface::IDeclarer { + fn __validate_declare__(self: @ContractState, class_hash: felt252) -> felt252 { + self.validate_transaction() } } - impl DeclarerImpl of IDeclarer { - fn __validate_declare__(class_hash: felt252) -> felt252 { - validate_transaction() + #[external(v0)] + impl SRC5Impl of ISRC5 { + fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { + let unsafe_state = SRC5::unsafe_new_contract_state(); + SRC5::SRC5Impl::supports_interface(@unsafe_state, interface_id) } } - impl SRC5Impl of ISRC5 { - fn supports_interface(interface_id: felt252) -> bool { - SRC5::supports_interface(interface_id) + #[external(v0)] + impl SRC5CamelImpl of ISRC5Camel { + fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { + let unsafe_state = SRC5::unsafe_new_contract_state(); + SRC5::SRC5CamelImpl::supportsInterface(@unsafe_state, interfaceId) } } - // - // Externals - // + #[external(v0)] + impl PublicKeyImpl of super::PublicKeyTrait { + fn get_public_key(self: @ContractState) -> felt252 { + self.public_key.read() + } - #[external] - fn __execute__(mut calls: Array) -> Array> { - SRC6Impl::__execute__(calls) + fn set_public_key(ref self: ContractState, new_public_key: felt252) { + assert_only_self(); + self.public_key.write(new_public_key); + } } - #[external] - fn __validate__(mut calls: Array) -> felt252 { - SRC6Impl::__validate__(calls) - } + #[external(v0)] + impl PublicKeyCamelImpl of super::PublicKeyCamelTrait { + fn getPublicKey(self: @ContractState) -> felt252 { + self.public_key.read() + } - #[external] - fn __validate_declare__(class_hash: felt252) -> felt252 { - DeclarerImpl::__validate_declare__(class_hash) + fn setPublicKey(ref self: ContractState, newPublicKey: felt252) { + assert_only_self(); + self.public_key.write(newPublicKey); + } } - #[external] + #[external(v0)] fn __validate_deploy__( - class_hash: felt252, contract_address_salt: felt252, _public_key: felt252 + self: @ContractState, + class_hash: felt252, + contract_address_salt: felt252, + _public_key: felt252 ) -> felt252 { - validate_transaction() - } - - #[external] - fn set_public_key(new_public_key: felt252) { - assert_only_self(); - public_key::write(new_public_key); - } - - #[external] - fn setPublicKey(newPublicKey: felt252) { - set_public_key(newPublicKey); + self.validate_transaction() } // - // View + // Internal // - #[view] - fn get_public_key() -> felt252 { - public_key::read() - } - - #[view] - fn getPublicKey() -> felt252 { - get_public_key() - } - - #[view] - fn is_valid_signature(hash: felt252, signature: Array) -> felt252 { - SRC6Impl::is_valid_signature(hash, signature) - } - - #[view] - fn isValidSignature(hash: felt252, signature: Array) -> felt252 { - SRC6CamelImpl::isValidSignature(hash, signature) - } - - #[view] - fn supports_interface(interface_id: felt252) -> bool { - SRC5Impl::supports_interface(interface_id) - } + #[generate_trait] + impl InternalImpl of InternalTrait { + fn initializer(ref self: ContractState, _public_key: felt252) { + let mut unsafe_state = SRC5::unsafe_new_contract_state(); + SRC5::InternalImpl::register_interface(ref unsafe_state, interface::ISRC6_ID); + self.public_key.write(_public_key); + } - #[view] - fn supportsInterface(interfaceId: felt252) -> bool { - supports_interface(interfaceId) - } + fn validate_transaction(self: @ContractState) -> felt252 { + let tx_info = get_tx_info().unbox(); + let tx_hash = tx_info.transaction_hash; + let signature = tx_info.signature; + assert(self._is_valid_signature(tx_hash, signature), 'Account: invalid signature'); + starknet::VALIDATED + } - // - // Internals - // + fn _is_valid_signature( + self: @ContractState, hash: felt252, signature: Span + ) -> bool { + let valid_length = signature.len() == 2_u32; - #[internal] - fn initializer(_public_key: felt252) { - SRC5::register_interface(ISRC6_ID); - public_key::write(_public_key); + if valid_length { + check_ecdsa_signature( + hash, self.public_key.read(), *signature.at(0_u32), *signature.at(1_u32) + ) + } else { + false + } + } } #[internal] @@ -234,28 +228,6 @@ mod Account { assert(self == caller, 'Account: unauthorized'); } - #[internal] - fn validate_transaction() -> felt252 { - let tx_info = get_tx_info().unbox(); - let tx_hash = tx_info.transaction_hash; - let signature = tx_info.signature; - assert(_is_valid_signature(tx_hash, signature), 'Account: invalid signature'); - starknet::VALIDATED - } - - #[internal] - fn _is_valid_signature(hash: felt252, signature: Span) -> bool { - let valid_length = signature.len() == 2_u32; - - if valid_length { - check_ecdsa_signature( - hash, public_key::read(), *signature.at(0_u32), *signature.at(1_u32) - ) - } else { - false - } - } - #[internal] fn _execute_calls(mut calls: Array) -> Array> { let mut res = ArrayTrait::new(); diff --git a/src/openzeppelin/account/dual_account.cairo b/src/openzeppelin/account/dual_account.cairo index ad6903659..ffd46f680 100644 --- a/src/openzeppelin/account/dual_account.cairo +++ b/src/openzeppelin/account/dual_account.cairo @@ -24,8 +24,7 @@ trait DualCaseAccountTrait { impl DualCaseAccountImpl of DualCaseAccountTrait { fn set_public_key(self: @DualCaseAccount, new_public_key: felt252) { - let mut args = ArrayTrait::new(); - args.append_serde(new_public_key); + let mut args = array![new_public_key]; try_selector_with_fallback( *self.contract_address, selectors::set_public_key, selectors::setPublicKey, args.span() @@ -34,7 +33,7 @@ impl DualCaseAccountImpl of DualCaseAccountTrait { } fn get_public_key(self: @DualCaseAccount) -> felt252 { - let mut args = ArrayTrait::new(); + let mut args = array![]; try_selector_with_fallback( *self.contract_address, selectors::get_public_key, selectors::getPublicKey, args.span() @@ -45,8 +44,7 @@ impl DualCaseAccountImpl of DualCaseAccountTrait { fn is_valid_signature( self: @DualCaseAccount, hash: felt252, signature: Array ) -> felt252 { - let mut args = ArrayTrait::new(); - args.append_serde(hash); + let mut args = array![hash]; args.append_serde(signature); try_selector_with_fallback( @@ -59,8 +57,7 @@ impl DualCaseAccountImpl of DualCaseAccountTrait { } fn supports_interface(self: @DualCaseAccount, interface_id: felt252) -> bool { - let mut args = ArrayTrait::new(); - args.append_serde(interface_id); + let mut args = array![interface_id]; try_selector_with_fallback( *self.contract_address, diff --git a/src/openzeppelin/account/interface.cairo b/src/openzeppelin/account/interface.cairo index af454163c..64a2c90f4 100644 --- a/src/openzeppelin/account/interface.cairo +++ b/src/openzeppelin/account/interface.cairo @@ -11,18 +11,19 @@ struct Call { calldata: Array } -trait ISRC6 { - fn __execute__(calls: Array) -> Array>; - fn __validate__(calls: Array) -> felt252; - fn is_valid_signature(hash: felt252, signature: Array) -> felt252; +#[starknet::interface] +trait ISRC6 { + fn __execute__(self: @TState, calls: Array) -> Array>; + fn __validate__(self: @TState, calls: Array) -> felt252; + fn is_valid_signature(self: @TState, hash: felt252, signature: Array) -> felt252; } -trait ISRC6Camel { - fn __execute__(calls: Array) -> Array>; - fn __validate__(calls: Array) -> felt252; - fn isValidSignature(hash: felt252, signature: Array) -> felt252; +#[starknet::interface] +trait ISRC6CamelOnly { + fn isValidSignature(self: @TState, hash: felt252, signature: Array) -> felt252; } -trait IDeclarer { - fn __validate_declare__(class_hash: felt252) -> felt252; +#[starknet::interface] +trait IDeclarer { + fn __validate_declare__(self: @TState, class_hash: felt252) -> felt252; } diff --git a/src/openzeppelin/lib.cairo b/src/openzeppelin/lib.cairo index 03d22fd58..81a2277a3 100644 --- a/src/openzeppelin/lib.cairo +++ b/src/openzeppelin/lib.cairo @@ -1,7 +1,7 @@ // mod access; mod introspection; // mod security; -// mod account; +mod account; // mod token; mod tests; mod utils; diff --git a/src/openzeppelin/tests.cairo b/src/openzeppelin/tests.cairo index 7f8a46378..5a46a6fc4 100644 --- a/src/openzeppelin/tests.cairo +++ b/src/openzeppelin/tests.cairo @@ -1,7 +1,7 @@ // mod access; // mod test_reentrancyguard; mod introspection; -// mod account; +mod account; // mod token; // mod test_initializable; // mod test_pausable; diff --git a/src/openzeppelin/tests/account/test_account.cairo b/src/openzeppelin/tests/account/test_account.cairo index 6ece0c5e9..d825d18cd 100644 --- a/src/openzeppelin/tests/account/test_account.cairo +++ b/src/openzeppelin/tests/account/test_account.cairo @@ -7,17 +7,16 @@ use starknet::ContractAddress; use starknet::testing; use openzeppelin::account::Account; -use openzeppelin::account::AccountABIDispatcher; -use openzeppelin::account::AccountABIDispatcherTrait; +use openzeppelin::account::AccountTraitDispatcher; use openzeppelin::account::interface::Call; use openzeppelin::account::interface::ISRC6_ID; use openzeppelin::account::QUERY_VERSION; use openzeppelin::account::TRANSACTION_VERSION; -use openzeppelin::introspection::src5::ISRC5_ID; +use openzeppelin::introspection::interface::ISRC5_ID; use openzeppelin::tests::utils; -use openzeppelin::token::erc20::ERC20; -use openzeppelin::token::erc20::interface::IERC20Dispatcher; -use openzeppelin::token::erc20::interface::IERC20DispatcherTrait; +// use openzeppelin::token::erc20::ERC20; +// use openzeppelin::token::erc20::interface::IERC20Dispatcher; +// use openzeppelin::token::erc20::interface::IERC20DispatcherTrait; use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; @@ -53,491 +52,487 @@ fn SIGNED_TX_DATA() -> SignedTransactionData { s: 3355728545224320878895493649495491771252432631648740019139167265522817576501 } } +// // +// // Setup +// // + +// fn setup_dispatcher(data: Option<@SignedTransactionData>) -> AccountABIDispatcher { +// // Set the transaction version +// testing::set_version(TRANSACTION_VERSION); + +// // Deploy the account contract +// let mut calldata = array![]; + +// if data.is_some() { +// let data = data.unwrap(); +// // Set the signature and transaction hash +// testing::set_signature(array![*data.r, *data.s].span()); +// testing::set_transaction_hash(*data.transaction_hash); + +// calldata.append(*data.public_key); +// } else { +// calldata.append(PUBLIC_KEY); +// } +// let address = utils::deploy(CLASS_HASH(), calldata); +// AccountABIDispatcher { contract_address: address } +// } + +// fn deploy_erc20(recipient: ContractAddress, initial_supply: u256) -> IERC20Dispatcher { +// let name = 0; +// let symbol = 0; +// let mut calldata = array![]; + +// calldata.append_serde(name); +// calldata.append_serde(symbol); +// calldata.append_serde(initial_supply); +// calldata.append_serde(recipient); + +// let address = utils::deploy(ERC20::TEST_CLASS_HASH, calldata); +// IERC20Dispatcher { contract_address: address } +// } + +// // +// // constructor +// // + +// #[test] +// #[available_gas(2000000)] +// fn test_constructor() { +// Account::constructor(PUBLIC_KEY); +// assert(Account::get_public_key() == PUBLIC_KEY, 'Should return public key'); +// } + +// // +// // supports_interface & supportsInterface +// // + +// #[test] +// #[available_gas(2000000)] +// fn test_supports_interface() { +// Account::constructor(PUBLIC_KEY); + +// let supports_default_interface = Account::supports_interface(ISRC5_ID); +// assert(supports_default_interface, 'Should support base interface'); + +// let supports_account_interface = Account::supports_interface(ISRC6_ID); +// assert(supports_account_interface, 'Should support account id'); +// } + +// #[test] +// #[available_gas(2000000)] +// fn test_supportsInterface() { +// Account::constructor(PUBLIC_KEY); + +// let supports_default_interface = Account::supportsInterface(ISRC5_ID); +// assert(supports_default_interface, 'Should support base interface'); + +// let supports_account_interface = Account::supportsInterface(ISRC6_ID); +// assert(supports_account_interface, 'Should support account id'); +// } + +// // +// // is_valid_signature & isValidSignature +// // + +// #[test] +// #[available_gas(2000000)] +// fn test_is_valid_signature() { +// let data = SIGNED_TX_DATA(); +// let hash = data.transaction_hash; + +// let mut good_signature = array![]; +// good_signature.append(data.r); +// good_signature.append(data.s); + +// let mut bad_signature = array![]; +// bad_signature.append(0x987); +// bad_signature.append(0x564); + +// Account::set_public_key(data.public_key); + +// let is_valid = Account::is_valid_signature(hash, good_signature); +// assert(is_valid == starknet::VALIDATED, 'Should accept valid signature'); + +// let is_valid = Account::is_valid_signature(hash, bad_signature); +// assert(is_valid == 0, 'Should reject invalid signature'); +// } + +// #[test] +// #[available_gas(2000000)] +// fn test_isValidSignature() { +// let data = SIGNED_TX_DATA(); +// let hash = data.transaction_hash; + +// let mut good_signature = array![]; +// good_signature.append(data.r); +// good_signature.append(data.s); + +// let mut bad_signature = array![]; +// bad_signature.append(0x987); +// bad_signature.append(0x564); + +// Account::set_public_key(data.public_key); + +// let is_valid = Account::is_valid_signature(hash, good_signature); +// assert(is_valid == starknet::VALIDATED, 'Should accept valid signature'); + +// let is_valid = Account::is_valid_signature(hash, bad_signature); +// assert(is_valid == 0, 'Should reject invalid signature'); +// } + +// // +// // Entry points +// // + +// #[test] +// #[available_gas(2000000)] +// fn test_validate_deploy() { +// let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); + +// // `__validate_deploy__` does not directly use the passed arguments. Their +// // values are already integrated in the tx hash. The passed arguments in this +// // testing context are decoupled from the signature and have no effect on the test. +// assert( +// account.__validate_deploy__(CLASS_HASH(), SALT, PUBLIC_KEY) == starknet::VALIDATED, +// 'Should validate correctly' +// ); +// } + +// #[test] +// #[available_gas(2000000)] +// #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] +// fn test_validate_deploy_invalid_signature_data() { +// let mut data = SIGNED_TX_DATA(); +// data.transaction_hash += 1; +// let account = setup_dispatcher(Option::Some(@data)); + +// account.__validate_deploy__(CLASS_HASH(), SALT, PUBLIC_KEY); +// } + +// #[test] +// #[available_gas(2000000)] +// #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] +// fn test_validate_deploy_invalid_signature_length() { +// let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); +// let mut signature = array![]; + +// signature.append(0x1); +// testing::set_signature(signature.span()); + +// account.__validate_deploy__(CLASS_HASH(), SALT, PUBLIC_KEY); +// } + +// #[test] +// #[available_gas(2000000)] +// #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] +// fn test_validate_deploy_empty_signature() { +// let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); +// let empty_sig = array![]; + +// testing::set_signature(empty_sig.span()); +// account.__validate_deploy__(CLASS_HASH(), SALT, PUBLIC_KEY); +// } + +// #[test] +// #[available_gas(2000000)] +// fn test_validate_declare() { +// let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); + +// // `__validate_declare__` does not directly use the class_hash argument. Its +// // value is already integrated in the tx hash. The class_hash argument in this +// // testing context is decoupled from the signature and has no effect on the test. +// assert( +// account.__validate_declare__(CLASS_HASH()) == starknet::VALIDATED, +// 'Should validate correctly' +// ); +// } + +// #[test] +// #[available_gas(2000000)] +// #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] +// fn test_validate_declare_invalid_signature_data() { +// let mut data = SIGNED_TX_DATA(); +// data.transaction_hash += 1; +// let account = setup_dispatcher(Option::Some(@data)); + +// account.__validate_declare__(CLASS_HASH()); +// } + +// #[test] +// #[available_gas(2000000)] +// #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] +// fn test_validate_declare_invalid_signature_length() { +// let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); +// let mut signature = array![]; + +// signature.append(0x1); +// testing::set_signature(signature.span()); + +// account.__validate_declare__(CLASS_HASH()); +// } + +// #[test] +// #[available_gas(2000000)] +// #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] +// fn test_validate_declare_empty_signature() { +// let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); +// let empty_sig = array![]; + +// testing::set_signature(empty_sig.span()); + +// account.__validate_declare__(CLASS_HASH()); +// } + +// fn test_execute_with_version(version: Option) { +// let data = SIGNED_TX_DATA(); +// let account = setup_dispatcher(Option::Some(@data)); +// let erc20 = deploy_erc20(account.contract_address, 1000); +// let recipient = contract_address_const::<0x123>(); + +// // Craft call and add to calls array +// let mut calldata = array![]; +// let amount: u256 = 200; +// calldata.append_serde(recipient); +// calldata.append_serde(amount); +// let call = Call { +// to: erc20.contract_address, selector: selectors::transfer, calldata: calldata +// }; +// let mut calls = array![]; +// calls.append(call); + +// // Handle version for test +// if version.is_some() { +// testing::set_version(version.unwrap()); +// } + +// // Execute +// let ret = account.__execute__(calls); + +// // Assert that the transfer was successful +// assert(erc20.balance_of(account.contract_address) == 800, 'Should have remainder'); +// assert(erc20.balance_of(recipient) == amount, 'Should have transferred'); + +// // Test return value +// let mut call_serialized_retval = *ret.at(0); +// let call_retval = Serde::::deserialize(ref call_serialized_retval); +// assert(call_retval.unwrap(), 'Should have succeeded'); +// } + +// #[test] +// #[available_gas(2000000)] +// fn test_execute() { +// test_execute_with_version(Option::None(())); +// } + +// #[test] +// #[available_gas(2000000)] +// fn test_execute_query_version() { +// test_execute_with_version(Option::Some(QUERY_VERSION)); +// } + +// #[test] +// #[available_gas(2000000)] +// #[should_panic(expected: ('Account: invalid tx version', 'ENTRYPOINT_FAILED'))] +// fn test_execute_invalid_version() { +// test_execute_with_version(Option::Some(TRANSACTION_VERSION - 1)); +// } + +// #[test] +// #[available_gas(2000000)] +// fn test_validate() { +// let calls = array![]; +// let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); + +// assert(account.__validate__(calls) == starknet::VALIDATED, 'Should validate correctly'); +// } + +// #[test] +// #[available_gas(2000000)] +// #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] +// fn test_validate_invalid() { +// let calls = array![]; +// let mut data = SIGNED_TX_DATA(); +// data.transaction_hash += 1; +// let account = setup_dispatcher(Option::Some(@data)); + +// account.__validate__(calls); +// } + +// #[test] +// #[available_gas(2000000)] +// fn test_multicall() { +// let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); +// let erc20 = deploy_erc20(account.contract_address, 1000); +// let recipient1 = contract_address_const::<0x123>(); +// let recipient2 = contract_address_const::<0x456>(); +// let mut calls = array![]; + +// // Craft call1 +// let mut calldata1 = array![]; +// let amount1: u256 = 300; +// calldata1.append_serde(recipient1); +// calldata1.append_serde(amount1); +// let call1 = Call { +// to: erc20.contract_address, selector: selectors::transfer, calldata: calldata1 +// }; + +// // Craft call2 +// let mut calldata2 = array![]; +// let amount2: u256 = 500; +// calldata2.append_serde(recipient2); +// calldata2.append_serde(amount2); +// let call2 = Call { +// to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2 +// }; + +// // Bundle calls and exeute +// calls.append(call1); +// calls.append(call2); +// let ret = account.__execute__(calls); + +// // Assert that the transfers were successful +// assert(erc20.balance_of(account.contract_address) == 200, 'Should have remainder'); +// assert(erc20.balance_of(recipient1) == 300, 'Should have transferred'); +// assert(erc20.balance_of(recipient2) == 500, 'Should have transferred'); + +// // Test return value +// let mut call1_serialized_retval = *ret.at(0); +// let mut call2_serialized_retval = *ret.at(1); +// let call1_retval = Serde::::deserialize(ref call1_serialized_retval); +// let call2_retval = Serde::::deserialize(ref call2_serialized_retval); +// assert(call1_retval.unwrap(), 'Should have succeeded'); +// assert(call2_retval.unwrap(), 'Should have succeeded'); +// } + +// #[test] +// #[available_gas(2000000)] +// fn test_multicall_zero_calls() { +// let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); +// let mut calls = array![]; + +// let ret = account.__execute__(calls); + +// // Test return value +// assert(ret.len() == 0, 'Should have an empty response'); +// } + +// #[test] +// #[available_gas(2000000)] +// #[should_panic(expected: ('Account: invalid caller', ))] +// fn test_account_called_from_contract() { +// let calls = array![]; +// let caller = contract_address_const::<0x123>(); +// testing::set_contract_address(ACCOUNT_ADDRESS()); +// testing::set_caller_address(caller); +// Account::__execute__(calls); +// } + +// // +// // set_public_key & get_public_key +// // + +// #[test] +// #[available_gas(2000000)] +// fn test_public_key_setter_and_getter() { +// testing::set_contract_address(ACCOUNT_ADDRESS()); +// testing::set_caller_address(ACCOUNT_ADDRESS()); +// Account::set_public_key(NEW_PUBKEY); + +// let public_key = Account::get_public_key(); +// assert(public_key == NEW_PUBKEY, 'Should update key'); +// } + +// #[test] +// #[available_gas(2000000)] +// #[should_panic(expected: ('Account: unauthorized', ))] +// fn test_public_key_setter_different_account() { +// let caller = contract_address_const::<0x123>(); +// testing::set_contract_address(ACCOUNT_ADDRESS()); +// testing::set_caller_address(caller); +// Account::set_public_key(NEW_PUBKEY); +// } + +// // +// // setPublicKey & getPublicKey +// // + +// #[test] +// #[available_gas(2000000)] +// fn test_public_key_setter_and_getter_camel() { +// testing::set_contract_address(ACCOUNT_ADDRESS()); +// testing::set_caller_address(ACCOUNT_ADDRESS()); +// Account::setPublicKey(NEW_PUBKEY); + +// let public_key = Account::getPublicKey(); +// assert(public_key == NEW_PUBKEY, 'Should update key'); +// } + +// #[test] +// #[available_gas(2000000)] +// #[should_panic(expected: ('Account: unauthorized', ))] +// fn test_public_key_setter_different_account_camel() { +// let caller = contract_address_const::<0x123>(); +// testing::set_contract_address(ACCOUNT_ADDRESS()); +// testing::set_caller_address(caller); +// Account::setPublicKey(NEW_PUBKEY); +// } + +// // +// // Test internals +// // + +// #[test] +// #[available_gas(2000000)] +// fn test_initializer() { +// Account::initializer(PUBLIC_KEY); +// assert(Account::get_public_key() == PUBLIC_KEY, 'Should return public key'); +// } + +// #[test] +// #[available_gas(2000000)] +// fn test_assert_only_self_true() { +// testing::set_contract_address(ACCOUNT_ADDRESS()); +// testing::set_caller_address(ACCOUNT_ADDRESS()); +// Account::assert_only_self(); +// } + +// #[test] +// #[available_gas(2000000)] +// #[should_panic(expected: ('Account: unauthorized', ))] +// fn test_assert_only_self_false() { +// testing::set_contract_address(ACCOUNT_ADDRESS()); +// let other = contract_address_const::<0x4567>(); +// testing::set_caller_address(other); +// Account::assert_only_self(); +// } + +// #[test] +// #[available_gas(2000000)] +// fn test__is_valid_signature() { +// let data = SIGNED_TX_DATA(); +// let hash = data.transaction_hash; + +// let mut good_signature = array![]; +// good_signature.append(data.r); +// good_signature.append(data.s); + +// let mut bad_signature = array![]; +// bad_signature.append(0x987); +// bad_signature.append(0x564); + +// let mut invalid_length_signature = array![]; +// invalid_length_signature.append(0x987); + +// Account::set_public_key(data.public_key); + +// let is_valid = Account::_is_valid_signature(hash, good_signature.span()); +// assert(is_valid, 'Should accept valid signature'); + +// let is_valid = Account::_is_valid_signature(hash, bad_signature.span()); +// assert(!is_valid, 'Should reject invalid signature'); + +// let is_valid = Account::_is_valid_signature(hash, invalid_length_signature.span()); +// assert(!is_valid, 'Should reject invalid length'); +// } -// -// Setup -// - -fn setup_dispatcher(data: Option<@SignedTransactionData>) -> AccountABIDispatcher { - // Set the transaction version - testing::set_version(TRANSACTION_VERSION); - - // Deploy the account contract - let mut calldata = ArrayTrait::new(); - - if data.is_some() { - let data = data.unwrap(); - - // Set the signature and transaction hash - let mut signature = ArrayTrait::new(); - signature.append(*data.r); - signature.append(*data.s); - testing::set_signature(signature.span()); - testing::set_transaction_hash(*data.transaction_hash); - - calldata.append(*data.public_key); - } else { - calldata.append(PUBLIC_KEY); - } - - let address = utils::deploy(CLASS_HASH(), calldata); - AccountABIDispatcher { contract_address: address } -} - -fn deploy_erc20(recipient: ContractAddress, initial_supply: u256) -> IERC20Dispatcher { - let name = 0; - let symbol = 0; - let mut calldata = ArrayTrait::new(); - - calldata.append_serde(name); - calldata.append_serde(symbol); - calldata.append_serde(initial_supply); - calldata.append_serde(recipient); - - let address = utils::deploy(ERC20::TEST_CLASS_HASH, calldata); - IERC20Dispatcher { contract_address: address } -} - -// -// constructor -// - -#[test] -#[available_gas(2000000)] -fn test_constructor() { - Account::constructor(PUBLIC_KEY); - assert(Account::get_public_key() == PUBLIC_KEY, 'Should return public key'); -} - -// -// supports_interface & supportsInterface -// - -#[test] -#[available_gas(2000000)] -fn test_supports_interface() { - Account::constructor(PUBLIC_KEY); - - let supports_default_interface = Account::supports_interface(ISRC5_ID); - assert(supports_default_interface, 'Should support base interface'); - - let supports_account_interface = Account::supports_interface(ISRC6_ID); - assert(supports_account_interface, 'Should support account id'); -} - -#[test] -#[available_gas(2000000)] -fn test_supportsInterface() { - Account::constructor(PUBLIC_KEY); - - let supports_default_interface = Account::supportsInterface(ISRC5_ID); - assert(supports_default_interface, 'Should support base interface'); - - let supports_account_interface = Account::supportsInterface(ISRC6_ID); - assert(supports_account_interface, 'Should support account id'); -} - -// -// is_valid_signature & isValidSignature -// - -#[test] -#[available_gas(2000000)] -fn test_is_valid_signature() { - let data = SIGNED_TX_DATA(); - let hash = data.transaction_hash; - - let mut good_signature = ArrayTrait::new(); - good_signature.append(data.r); - good_signature.append(data.s); - - let mut bad_signature = ArrayTrait::new(); - bad_signature.append(0x987); - bad_signature.append(0x564); - - Account::set_public_key(data.public_key); - - let is_valid = Account::is_valid_signature(hash, good_signature); - assert(is_valid == starknet::VALIDATED, 'Should accept valid signature'); - - let is_valid = Account::is_valid_signature(hash, bad_signature); - assert(is_valid == 0, 'Should reject invalid signature'); -} - -#[test] -#[available_gas(2000000)] -fn test_isValidSignature() { - let data = SIGNED_TX_DATA(); - let hash = data.transaction_hash; - - let mut good_signature = ArrayTrait::new(); - good_signature.append(data.r); - good_signature.append(data.s); - - let mut bad_signature = ArrayTrait::new(); - bad_signature.append(0x987); - bad_signature.append(0x564); - - Account::set_public_key(data.public_key); - - let is_valid = Account::is_valid_signature(hash, good_signature); - assert(is_valid == starknet::VALIDATED, 'Should accept valid signature'); - - let is_valid = Account::is_valid_signature(hash, bad_signature); - assert(is_valid == 0, 'Should reject invalid signature'); -} - -// -// Entry points -// - -#[test] -#[available_gas(2000000)] -fn test_validate_deploy() { - let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); - - // `__validate_deploy__` does not directly use the passed arguments. Their - // values are already integrated in the tx hash. The passed arguments in this - // testing context are decoupled from the signature and have no effect on the test. - assert( - account.__validate_deploy__(CLASS_HASH(), SALT, PUBLIC_KEY) == starknet::VALIDATED, - 'Should validate correctly' - ); -} - -#[test] -#[available_gas(2000000)] -#[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] -fn test_validate_deploy_invalid_signature_data() { - let mut data = SIGNED_TX_DATA(); - data.transaction_hash += 1; - let account = setup_dispatcher(Option::Some(@data)); - - account.__validate_deploy__(CLASS_HASH(), SALT, PUBLIC_KEY); -} - -#[test] -#[available_gas(2000000)] -#[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] -fn test_validate_deploy_invalid_signature_length() { - let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); - let mut signature = ArrayTrait::new(); - - signature.append(0x1); - testing::set_signature(signature.span()); - - account.__validate_deploy__(CLASS_HASH(), SALT, PUBLIC_KEY); -} - -#[test] -#[available_gas(2000000)] -#[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] -fn test_validate_deploy_empty_signature() { - let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); - let empty_sig = ArrayTrait::new(); - - testing::set_signature(empty_sig.span()); - account.__validate_deploy__(CLASS_HASH(), SALT, PUBLIC_KEY); -} - -#[test] -#[available_gas(2000000)] -fn test_validate_declare() { - let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); - - // `__validate_declare__` does not directly use the class_hash argument. Its - // value is already integrated in the tx hash. The class_hash argument in this - // testing context is decoupled from the signature and has no effect on the test. - assert( - account.__validate_declare__(CLASS_HASH()) == starknet::VALIDATED, - 'Should validate correctly' - ); -} - -#[test] -#[available_gas(2000000)] -#[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] -fn test_validate_declare_invalid_signature_data() { - let mut data = SIGNED_TX_DATA(); - data.transaction_hash += 1; - let account = setup_dispatcher(Option::Some(@data)); - - account.__validate_declare__(CLASS_HASH()); -} -#[test] -#[available_gas(2000000)] -#[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] -fn test_validate_declare_invalid_signature_length() { - let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); - let mut signature = ArrayTrait::new(); - - signature.append(0x1); - testing::set_signature(signature.span()); - - account.__validate_declare__(CLASS_HASH()); -} - -#[test] -#[available_gas(2000000)] -#[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] -fn test_validate_declare_empty_signature() { - let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); - let empty_sig = ArrayTrait::new(); - - testing::set_signature(empty_sig.span()); - - account.__validate_declare__(CLASS_HASH()); -} - -fn test_execute_with_version(version: Option) { - let data = SIGNED_TX_DATA(); - let account = setup_dispatcher(Option::Some(@data)); - let erc20 = deploy_erc20(account.contract_address, 1000); - let recipient = contract_address_const::<0x123>(); - - // Craft call and add to calls array - let mut calldata = ArrayTrait::new(); - let amount: u256 = 200; - calldata.append_serde(recipient); - calldata.append_serde(amount); - let call = Call { - to: erc20.contract_address, selector: selectors::transfer, calldata: calldata - }; - let mut calls = ArrayTrait::new(); - calls.append(call); - - // Handle version for test - if version.is_some() { - testing::set_version(version.unwrap()); - } - - // Execute - let ret = account.__execute__(calls); - - // Assert that the transfer was successful - assert(erc20.balance_of(account.contract_address) == 800, 'Should have remainder'); - assert(erc20.balance_of(recipient) == amount, 'Should have transferred'); - - // Test return value - let mut call_serialized_retval = *ret.at(0); - let call_retval = Serde::::deserialize(ref call_serialized_retval); - assert(call_retval.unwrap(), 'Should have succeeded'); -} - -#[test] -#[available_gas(2000000)] -fn test_execute() { - test_execute_with_version(Option::None(())); -} - -#[test] -#[available_gas(2000000)] -fn test_execute_query_version() { - test_execute_with_version(Option::Some(QUERY_VERSION)); -} - -#[test] -#[available_gas(2000000)] -#[should_panic(expected: ('Account: invalid tx version', 'ENTRYPOINT_FAILED'))] -fn test_execute_invalid_version() { - test_execute_with_version(Option::Some(TRANSACTION_VERSION - 1)); -} - -#[test] -#[available_gas(2000000)] -fn test_validate() { - let calls = ArrayTrait::new(); - let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); - - assert(account.__validate__(calls) == starknet::VALIDATED, 'Should validate correctly'); -} - -#[test] -#[available_gas(2000000)] -#[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] -fn test_validate_invalid() { - let calls = ArrayTrait::new(); - let mut data = SIGNED_TX_DATA(); - data.transaction_hash += 1; - let account = setup_dispatcher(Option::Some(@data)); - - account.__validate__(calls); -} - -#[test] -#[available_gas(2000000)] -fn test_multicall() { - let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); - let erc20 = deploy_erc20(account.contract_address, 1000); - let recipient1 = contract_address_const::<0x123>(); - let recipient2 = contract_address_const::<0x456>(); - let mut calls = ArrayTrait::new(); - - // Craft call1 - let mut calldata1 = ArrayTrait::new(); - let amount1: u256 = 300; - calldata1.append_serde(recipient1); - calldata1.append_serde(amount1); - let call1 = Call { - to: erc20.contract_address, selector: selectors::transfer, calldata: calldata1 - }; - - // Craft call2 - let mut calldata2 = ArrayTrait::new(); - let amount2: u256 = 500; - calldata2.append_serde(recipient2); - calldata2.append_serde(amount2); - let call2 = Call { - to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2 - }; - - // Bundle calls and exeute - calls.append(call1); - calls.append(call2); - let ret = account.__execute__(calls); - - // Assert that the transfers were successful - assert(erc20.balance_of(account.contract_address) == 200, 'Should have remainder'); - assert(erc20.balance_of(recipient1) == 300, 'Should have transferred'); - assert(erc20.balance_of(recipient2) == 500, 'Should have transferred'); - - // Test return value - let mut call1_serialized_retval = *ret.at(0); - let mut call2_serialized_retval = *ret.at(1); - let call1_retval = Serde::::deserialize(ref call1_serialized_retval); - let call2_retval = Serde::::deserialize(ref call2_serialized_retval); - assert(call1_retval.unwrap(), 'Should have succeeded'); - assert(call2_retval.unwrap(), 'Should have succeeded'); -} - -#[test] -#[available_gas(2000000)] -fn test_multicall_zero_calls() { - let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); - let mut calls = ArrayTrait::new(); - - let ret = account.__execute__(calls); - - // Test return value - assert(ret.len() == 0, 'Should have an empty response'); -} - -#[test] -#[available_gas(2000000)] -#[should_panic(expected: ('Account: invalid caller', ))] -fn test_account_called_from_contract() { - let calls = ArrayTrait::new(); - let caller = contract_address_const::<0x123>(); - testing::set_contract_address(ACCOUNT_ADDRESS()); - testing::set_caller_address(caller); - Account::__execute__(calls); -} - -// -// set_public_key & get_public_key -// - -#[test] -#[available_gas(2000000)] -fn test_public_key_setter_and_getter() { - testing::set_contract_address(ACCOUNT_ADDRESS()); - testing::set_caller_address(ACCOUNT_ADDRESS()); - Account::set_public_key(NEW_PUBKEY); - - let public_key = Account::get_public_key(); - assert(public_key == NEW_PUBKEY, 'Should update key'); -} - -#[test] -#[available_gas(2000000)] -#[should_panic(expected: ('Account: unauthorized', ))] -fn test_public_key_setter_different_account() { - let caller = contract_address_const::<0x123>(); - testing::set_contract_address(ACCOUNT_ADDRESS()); - testing::set_caller_address(caller); - Account::set_public_key(NEW_PUBKEY); -} - -// -// setPublicKey & getPublicKey -// - -#[test] -#[available_gas(2000000)] -fn test_public_key_setter_and_getter_camel() { - testing::set_contract_address(ACCOUNT_ADDRESS()); - testing::set_caller_address(ACCOUNT_ADDRESS()); - Account::setPublicKey(NEW_PUBKEY); - - let public_key = Account::getPublicKey(); - assert(public_key == NEW_PUBKEY, 'Should update key'); -} - -#[test] -#[available_gas(2000000)] -#[should_panic(expected: ('Account: unauthorized', ))] -fn test_public_key_setter_different_account_camel() { - let caller = contract_address_const::<0x123>(); - testing::set_contract_address(ACCOUNT_ADDRESS()); - testing::set_caller_address(caller); - Account::setPublicKey(NEW_PUBKEY); -} - -// -// Test internals -// - -#[test] -#[available_gas(2000000)] -fn test_initializer() { - Account::initializer(PUBLIC_KEY); - assert(Account::get_public_key() == PUBLIC_KEY, 'Should return public key'); -} - -#[test] -#[available_gas(2000000)] -fn test_assert_only_self_true() { - testing::set_contract_address(ACCOUNT_ADDRESS()); - testing::set_caller_address(ACCOUNT_ADDRESS()); - Account::assert_only_self(); -} - -#[test] -#[available_gas(2000000)] -#[should_panic(expected: ('Account: unauthorized', ))] -fn test_assert_only_self_false() { - testing::set_contract_address(ACCOUNT_ADDRESS()); - let other = contract_address_const::<0x4567>(); - testing::set_caller_address(other); - Account::assert_only_self(); -} - -#[test] -#[available_gas(2000000)] -fn test__is_valid_signature() { - let data = SIGNED_TX_DATA(); - let hash = data.transaction_hash; - - let mut good_signature = ArrayTrait::new(); - good_signature.append(data.r); - good_signature.append(data.s); - - let mut bad_signature = ArrayTrait::new(); - bad_signature.append(0x987); - bad_signature.append(0x564); - - let mut invalid_length_signature = ArrayTrait::new(); - invalid_length_signature.append(0x987); - - Account::set_public_key(data.public_key); - - let is_valid = Account::_is_valid_signature(hash, good_signature.span()); - assert(is_valid, 'Should accept valid signature'); - - let is_valid = Account::_is_valid_signature(hash, bad_signature.span()); - assert(!is_valid, 'Should reject invalid signature'); - - let is_valid = Account::_is_valid_signature(hash, invalid_length_signature.span()); - assert(!is_valid, 'Should reject invalid length'); -} diff --git a/src/openzeppelin/tests/account/test_dual_account.cairo b/src/openzeppelin/tests/account/test_dual_account.cairo index 1d4e23840..b1a9e4bfe 100644 --- a/src/openzeppelin/tests/account/test_dual_account.cairo +++ b/src/openzeppelin/tests/account/test_dual_account.cairo @@ -3,11 +3,11 @@ use starknet::testing; use openzeppelin::account::dual_account::DualCaseAccount; use openzeppelin::account::dual_account::DualCaseAccountTrait; -use openzeppelin::account::AccountABICamelDispatcher; -use openzeppelin::account::AccountABICamelDispatcherTrait; -use openzeppelin::account::AccountABIDispatcher; -use openzeppelin::account::AccountABIDispatcherTrait; -use openzeppelin::introspection::src5::ISRC5_ID; +use openzeppelin::account::AccountCamelTraitDispatcher; +use openzeppelin::account::AccountCamelTraitDispatcherTrait; +use openzeppelin::account::AccountTraitDispatcher; +use openzeppelin::account::AccountTraitDispatcherTrait; +use openzeppelin::introspection::interface::ISRC5_ID; use openzeppelin::tests::account::test_account::SIGNED_TX_DATA; use openzeppelin::tests::mocks::account_panic_mock::CamelAccountPanicMock; use openzeppelin::tests::mocks::account_panic_mock::SnakeAccountPanicMock; @@ -15,7 +15,6 @@ use openzeppelin::tests::mocks::camel_account_mock::CamelAccountMock; use openzeppelin::tests::mocks::non_implementing_mock::NonImplementingMock; use openzeppelin::tests::mocks::snake_account_mock::SnakeAccountMock; use openzeppelin::tests::utils; -use openzeppelin::utils::serde::SerializedAppend; // // Constants @@ -28,35 +27,33 @@ const NEW_PUBLIC_KEY: felt252 = 0x444444; // Setup // -fn setup_snake() -> (DualCaseAccount, AccountABIDispatcher) { - let mut calldata = ArrayTrait::new(); - calldata.append_serde(PUBLIC_KEY); +fn setup_snake() -> (DualCaseAccount, AccountTraitDispatcher) { + let mut calldata = array![PUBLIC_KEY]; let target = utils::deploy(SnakeAccountMock::TEST_CLASS_HASH, calldata); ( DualCaseAccount { contract_address: target }, - AccountABIDispatcher { contract_address: target } + AccountTraitDispatcher { contract_address: target } ) } -fn setup_camel() -> (DualCaseAccount, AccountABICamelDispatcher) { - let mut calldata = ArrayTrait::new(); - calldata.append_serde(PUBLIC_KEY); +fn setup_camel() -> (DualCaseAccount, AccountCamelTraitDispatcher) { + let mut calldata = array![PUBLIC_KEY]; let target = utils::deploy(CamelAccountMock::TEST_CLASS_HASH, calldata); ( DualCaseAccount { contract_address: target }, - AccountABICamelDispatcher { contract_address: target } + AccountCamelTraitDispatcher { contract_address: target } ) } fn setup_non_account() -> DualCaseAccount { - let calldata = ArrayTrait::new(); + let calldata = array![]; let target = utils::deploy(NonImplementingMock::TEST_CLASS_HASH, calldata); DualCaseAccount { contract_address: target } } fn setup_account_panic() -> (DualCaseAccount, DualCaseAccount) { - let snake_target = utils::deploy(SnakeAccountPanicMock::TEST_CLASS_HASH, ArrayTrait::new()); - let camel_target = utils::deploy(CamelAccountPanicMock::TEST_CLASS_HASH, ArrayTrait::new()); + let snake_target = utils::deploy(SnakeAccountPanicMock::TEST_CLASS_HASH, array![]); + let camel_target = utils::deploy(CamelAccountPanicMock::TEST_CLASS_HASH, array![]); ( DualCaseAccount { contract_address: snake_target }, DualCaseAccount { contract_address: camel_target } @@ -124,10 +121,7 @@ fn test_dual_is_valid_signature() { let data = SIGNED_TX_DATA(); let hash = data.transaction_hash; - - let mut signature = ArrayTrait::new(); - signature.append(data.r); - signature.append(data.s); + let mut signature = array![data.r, data.s]; testing::set_contract_address(snake_dispatcher.contract_address); target.set_public_key(data.public_key); @@ -141,7 +135,7 @@ fn test_dual_is_valid_signature() { #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND', ))] fn test_dual_no_is_valid_signature() { let hash = 0x0; - let signature = ArrayTrait::::new(); + let signature = array![]; let dispatcher = setup_non_account(); dispatcher.is_valid_signature(hash, signature); @@ -152,13 +146,12 @@ fn test_dual_no_is_valid_signature() { #[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED', ))] fn test_dual_is_valid_signature_exists_and_panics() { let hash = 0x0; - let signature = ArrayTrait::::new(); + let signature = array![]; let (dispatcher, _) = setup_account_panic(); dispatcher.is_valid_signature(hash, signature); } - #[test] #[available_gas(2000000)] fn test_dual_supports_interface() { @@ -227,10 +220,7 @@ fn test_dual_isValidSignature() { let data = SIGNED_TX_DATA(); let hash = data.transaction_hash; - - let mut signature = ArrayTrait::new(); - signature.append(data.r); - signature.append(data.s); + let mut signature = array![data.r, data.s]; testing::set_contract_address(camel_dispatcher.contract_address); target.setPublicKey(data.public_key); @@ -244,13 +234,12 @@ fn test_dual_isValidSignature() { #[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED', ))] fn test_dual_isValidSignature_exists_and_panics() { let hash = 0x0; - let signature = ArrayTrait::::new(); + let signature = array![]; let (_, dispatcher) = setup_account_panic(); dispatcher.is_valid_signature(hash, signature); } - #[test] #[available_gas(2000000)] fn test_dual_supportsInterface() { @@ -265,3 +254,4 @@ fn test_dual_supportsInterface_exists_and_panics() { let (_, dispatcher) = setup_account_panic(); dispatcher.supports_interface(ISRC5_ID); } + diff --git a/src/openzeppelin/tests/mocks.cairo b/src/openzeppelin/tests/mocks.cairo index d8bdaa92b..c3aa138b0 100644 --- a/src/openzeppelin/tests/mocks.cairo +++ b/src/openzeppelin/tests/mocks.cairo @@ -1,21 +1,21 @@ -// mod reentrancy_attacker_mock; -// mod reentrancy_mock; +// mod accesscontrol_panic_mock; +mod account_panic_mock; +// mod camel_accesscontrol_mock; +mod camel_account_mock; +// mod camel20_mock; +// mod camel721_mock; +// mod dual_ownable_mocks; +// mod dual721_receiver_mocks; +// mod erc20_panic; // mod erc721_receiver; // mod erc721_panic_mock; // mod mock_pausable; -// mod camel20_mock; -// mod snake20_mock; -// mod erc20_panic; // mod non721_mock; -// mod accesscontrol_panic_mock; -// mod account_panic_mock; -// mod camel_accesscontrol_mock; -// mod camel_account_mock; -// mod snake_accesscontrol_mock; -// mod snake_account_mock; -// mod dual_ownable_mocks; -// mod snake721_mock; -// mod camel721_mock; mod non_implementing_mock; -// mod dual721_receiver_mocks; +// mod reentrancy_attacker_mock; +// mod reentrancy_mock; +// mod snake20_mock; +// mod snake721_mock; +// mod snake_accesscontrol_mock; +mod snake_account_mock; mod src5_mocks; diff --git a/src/openzeppelin/tests/mocks/account_panic_mock.cairo b/src/openzeppelin/tests/mocks/account_panic_mock.cairo index f3809b807..12cf10207 100644 --- a/src/openzeppelin/tests/mocks/account_panic_mock.cairo +++ b/src/openzeppelin/tests/mocks/account_panic_mock.cairo @@ -4,53 +4,60 @@ // 3 for felt252 // false for bool -#[account_contract] +#[starknet::contract] mod SnakeAccountPanicMock { - #[external] - fn set_public_key(new_public_key: felt252) { + #[storage] + struct Storage {} + + #[external(v0)] + fn set_public_key(ref self: ContractState, new_public_key: felt252) { panic_with_felt252('Some error'); } - #[view] - fn get_public_key() -> felt252 { + #[external(v0)] + fn get_public_key(self: @ContractState) -> felt252 { panic_with_felt252('Some error'); 3 } - #[view] - fn is_valid_signature(hash: felt252, signature: Array) -> felt252 { + #[external(v0)] + fn is_valid_signature( + self: @ContractState, hash: felt252, signature: Array + ) -> felt252 { panic_with_felt252('Some error'); 3 } - #[view] - fn supports_interface(interface_id: felt252) -> bool { + #[external(v0)] + fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { panic_with_felt252('Some error'); false } } -#[account_contract] +#[starknet::contract] mod CamelAccountPanicMock { - #[external] - fn setPublicKey(newPublicKey: felt252) { + #[storage] + struct Storage {} + #[external(v0)] + fn setPublicKey(ref self: ContractState, newPublicKey: felt252) { panic_with_felt252('Some error'); } - #[view] - fn getPublicKey() -> felt252 { + #[external(v0)] + fn getPublicKey(self: @ContractState) -> felt252 { panic_with_felt252('Some error'); 3 } - #[view] - fn isValidSignature(hash: felt252, signature: Array) -> felt252 { + #[external(v0)] + fn isValidSignature(self: @ContractState, hash: felt252, signature: Array) -> felt252 { panic_with_felt252('Some error'); 3 } - #[view] - fn supportsInterface(interfaceId: felt252) -> bool { + #[external(v0)] + fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { panic_with_felt252('Some error'); false } diff --git a/src/openzeppelin/tests/mocks/camel_account_mock.cairo b/src/openzeppelin/tests/mocks/camel_account_mock.cairo index 01ee5b53e..10bde06b1 100644 --- a/src/openzeppelin/tests/mocks/camel_account_mock.cairo +++ b/src/openzeppelin/tests/mocks/camel_account_mock.cairo @@ -1,31 +1,38 @@ -#[account_contract] +#[starknet::contract] mod CamelAccountMock { use openzeppelin::account::interface::Call; use openzeppelin::account::Account; - use openzeppelin::utils::serde::SpanSerde; + + #[storage] + struct Storage {} #[constructor] - fn constructor(_publicKey: felt252) { - Account::initializer(_publicKey); + fn constructor(ref self: ContractState, _publicKey: felt252) { + let mut unsafe_state = Account::unsafe_new_contract_state(); + Account::InternalImpl::initializer(ref unsafe_state, _publicKey); } - #[external] - fn setPublicKey(newPublicKey: felt252) { - Account::setPublicKey(newPublicKey); + #[external(v0)] + fn setPublicKey(ref self: ContractState, newPublicKey: felt252) { + let mut unsafe_state = Account::unsafe_new_contract_state(); + Account::PublicKeyCamelImpl::setPublicKey(ref unsafe_state, newPublicKey); } - #[view] - fn getPublicKey() -> felt252 { - Account::getPublicKey() + #[external(v0)] + fn getPublicKey(self: @ContractState) -> felt252 { + let unsafe_state = Account::unsafe_new_contract_state(); + Account::PublicKeyCamelImpl::getPublicKey(@unsafe_state) } - #[view] - fn isValidSignature(hash: felt252, signature: Array) -> felt252 { - Account::isValidSignature(hash, signature) + #[external(v0)] + fn isValidSignature(self: @ContractState, hash: felt252, signature: Array) -> felt252 { + let unsafe_state = Account::unsafe_new_contract_state(); + Account::SRC6CamelOnlyImpl::isValidSignature(@unsafe_state, hash, signature) } - #[view] - fn supportsInterface(interfaceId: felt252) -> bool { - Account::supportsInterface(interfaceId) + #[external(v0)] + fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { + let unsafe_state = Account::unsafe_new_contract_state(); + Account::SRC5CamelImpl::supportsInterface(@unsafe_state, interfaceId) } } diff --git a/src/openzeppelin/tests/mocks/snake_account_mock.cairo b/src/openzeppelin/tests/mocks/snake_account_mock.cairo index 03b9cd05d..c4b9861b9 100644 --- a/src/openzeppelin/tests/mocks/snake_account_mock.cairo +++ b/src/openzeppelin/tests/mocks/snake_account_mock.cairo @@ -1,53 +1,69 @@ -#[account_contract] +#[starknet::contract] mod SnakeAccountMock { use openzeppelin::account::interface::Call; use openzeppelin::account::Account; - use openzeppelin::utils::serde::SpanSerde; + + #[storage] + struct Storage {} #[constructor] - fn constructor(_public_key: felt252) { - Account::initializer(_public_key); + fn constructor(ref self: ContractState, _public_key: felt252) { + let mut unsafe_state = Account::unsafe_new_contract_state(); + Account::InternalImpl::initializer(ref unsafe_state, _public_key); } - #[external] - fn __execute__(mut calls: Array) -> Array> { - Account::__execute__(calls) + #[external(v0)] + fn __execute__(self: @ContractState, mut calls: Array) -> Array> { + let mut unsafe_state = Account::unsafe_new_contract_state(); + Account::SRC6Impl::__execute__(@unsafe_state, calls) } - #[external] - fn __validate__(mut calls: Array) -> felt252 { - Account::__validate__(calls) + #[external(v0)] + fn __validate__(self: @ContractState, mut calls: Array) -> felt252 { + let mut unsafe_state = Account::unsafe_new_contract_state(); + Account::SRC6Impl::__validate__(@unsafe_state, calls) } - #[external] - fn __validate_declare__(class_hash: felt252) -> felt252 { - Account::__validate_declare__(class_hash) + #[external(v0)] + fn __validate_declare__(self: @ContractState, class_hash: felt252) -> felt252 { + let mut unsafe_state = Account::unsafe_new_contract_state(); + Account::DeclarerImpl::__validate_declare__(@unsafe_state, class_hash) } - #[external] + #[external(v0)] fn __validate_deploy__( - class_hash: felt252, contract_address_salt: felt252, _public_key: felt252 + self: @ContractState, + class_hash: felt252, + contract_address_salt: felt252, + _public_key: felt252 ) -> felt252 { - Account::__validate_deploy__(class_hash, contract_address_salt, _public_key) + let mut unsafe_state = Account::unsafe_new_contract_state(); + Account::__validate_deploy__(@unsafe_state, class_hash, contract_address_salt, _public_key) } - #[external] - fn set_public_key(new_public_key: felt252) { - Account::set_public_key(new_public_key); + #[external(v0)] + fn set_public_key(ref self: ContractState, new_public_key: felt252) { + let mut unsafe_state = Account::unsafe_new_contract_state(); + Account::PublicKeyImpl::set_public_key(ref unsafe_state, new_public_key); } - #[view] - fn get_public_key() -> felt252 { - Account::get_public_key() + #[external(v0)] + fn get_public_key(self: @ContractState) -> felt252 { + let unsafe_state = Account::unsafe_new_contract_state(); + Account::PublicKeyImpl::get_public_key(@unsafe_state) } - #[view] - fn is_valid_signature(hash: felt252, signature: Array) -> felt252 { - Account::is_valid_signature(hash, signature) + #[external(v0)] + fn is_valid_signature( + self: @ContractState, hash: felt252, signature: Array + ) -> felt252 { + let unsafe_state = Account::unsafe_new_contract_state(); + Account::SRC6Impl::is_valid_signature(@unsafe_state, hash, signature) } - #[view] - fn supports_interface(interface_id: felt252) -> bool { - Account::supports_interface(interface_id) + #[external(v0)] + fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { + let unsafe_state = Account::unsafe_new_contract_state(); + Account::SRC5Impl::supports_interface(@unsafe_state, interface_id) } } From bc9e3c90ff4afabc4ff9697e342b71dc11434cc8 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Tue, 18 Jul 2023 13:34:54 +0200 Subject: [PATCH 6/7] fix: account tests --- .../tests/account/test_account.cairo | 601 +++++++++--------- .../tests/account/test_dual_account.cairo | 1 - 2 files changed, 303 insertions(+), 299 deletions(-) diff --git a/src/openzeppelin/tests/account/test_account.cairo b/src/openzeppelin/tests/account/test_account.cairo index d825d18cd..4a83a9a5a 100644 --- a/src/openzeppelin/tests/account/test_account.cairo +++ b/src/openzeppelin/tests/account/test_account.cairo @@ -8,6 +8,7 @@ use starknet::testing; use openzeppelin::account::Account; use openzeppelin::account::AccountTraitDispatcher; +use openzeppelin::account::AccountTraitDispatcherTrait; use openzeppelin::account::interface::Call; use openzeppelin::account::interface::ISRC6_ID; use openzeppelin::account::QUERY_VERSION; @@ -37,6 +38,9 @@ struct SignedTransactionData { s: felt252 } +fn STATE() -> Account::ContractState { + Account::contract_state_for_testing() +} fn CLASS_HASH() -> felt252 { Account::TEST_CLASS_HASH } @@ -52,30 +56,27 @@ fn SIGNED_TX_DATA() -> SignedTransactionData { s: 3355728545224320878895493649495491771252432631648740019139167265522817576501 } } -// // -// // Setup -// // -// fn setup_dispatcher(data: Option<@SignedTransactionData>) -> AccountABIDispatcher { -// // Set the transaction version -// testing::set_version(TRANSACTION_VERSION); +// +// Setup +// -// // Deploy the account contract -// let mut calldata = array![]; +fn setup_dispatcher(data: Option<@SignedTransactionData>) -> AccountTraitDispatcher { + testing::set_version(TRANSACTION_VERSION); -// if data.is_some() { -// let data = data.unwrap(); -// // Set the signature and transaction hash -// testing::set_signature(array![*data.r, *data.s].span()); -// testing::set_transaction_hash(*data.transaction_hash); + let mut calldata = array![]; + if data.is_some() { + let data = data.unwrap(); + testing::set_signature(array![*data.r, *data.s].span()); + testing::set_transaction_hash(*data.transaction_hash); -// calldata.append(*data.public_key); -// } else { -// calldata.append(PUBLIC_KEY); -// } -// let address = utils::deploy(CLASS_HASH(), calldata); -// AccountABIDispatcher { contract_address: address } -// } + calldata.append(*data.public_key); + } else { + calldata.append(PUBLIC_KEY); + } + let address = utils::deploy(CLASS_HASH(), calldata); + AccountTraitDispatcher { contract_address: address } +} // fn deploy_erc20(recipient: ContractAddress, initial_supply: u256) -> IERC20Dispatcher { // let name = 0; @@ -91,197 +92,194 @@ fn SIGNED_TX_DATA() -> SignedTransactionData { // IERC20Dispatcher { contract_address: address } // } -// // -// // constructor -// // - -// #[test] -// #[available_gas(2000000)] -// fn test_constructor() { -// Account::constructor(PUBLIC_KEY); -// assert(Account::get_public_key() == PUBLIC_KEY, 'Should return public key'); -// } - -// // -// // supports_interface & supportsInterface -// // +// +// constructor +// -// #[test] -// #[available_gas(2000000)] -// fn test_supports_interface() { -// Account::constructor(PUBLIC_KEY); +#[test] +#[available_gas(2000000)] +fn test_constructor() { + let mut state = STATE(); + Account::constructor(ref state, PUBLIC_KEY); + assert( + Account::PublicKeyImpl::get_public_key(@state) == PUBLIC_KEY, 'Should return public key' + ); +} -// let supports_default_interface = Account::supports_interface(ISRC5_ID); -// assert(supports_default_interface, 'Should support base interface'); +// +// supports_interface & supportsInterface +// -// let supports_account_interface = Account::supports_interface(ISRC6_ID); -// assert(supports_account_interface, 'Should support account id'); -// } +#[test] +#[available_gas(2000000)] +fn test_supports_interface() { + let mut state = STATE(); + Account::constructor(ref state, PUBLIC_KEY); -// #[test] -// #[available_gas(2000000)] -// fn test_supportsInterface() { -// Account::constructor(PUBLIC_KEY); + let supports_default_interface = Account::SRC5Impl::supports_interface(@state, ISRC5_ID); + assert(supports_default_interface, 'Should support base interface'); -// let supports_default_interface = Account::supportsInterface(ISRC5_ID); -// assert(supports_default_interface, 'Should support base interface'); + let supports_account_interface = Account::SRC5Impl::supports_interface(@state, ISRC6_ID); + assert(supports_account_interface, 'Should support account id'); +} -// let supports_account_interface = Account::supportsInterface(ISRC6_ID); -// assert(supports_account_interface, 'Should support account id'); -// } +#[test] +#[available_gas(2000000)] +fn test_supportsInterface() { + let mut state = STATE(); + Account::constructor(ref state, PUBLIC_KEY); -// // -// // is_valid_signature & isValidSignature -// // + let supports_default_interface = Account::SRC5CamelImpl::supportsInterface(@state, ISRC5_ID); + assert(supports_default_interface, 'Should support base interface'); -// #[test] -// #[available_gas(2000000)] -// fn test_is_valid_signature() { -// let data = SIGNED_TX_DATA(); -// let hash = data.transaction_hash; + let supports_account_interface = Account::SRC5CamelImpl::supportsInterface(@state, ISRC6_ID); + assert(supports_account_interface, 'Should support account id'); +} -// let mut good_signature = array![]; -// good_signature.append(data.r); -// good_signature.append(data.s); +// +// is_valid_signature & isValidSignature +// -// let mut bad_signature = array![]; -// bad_signature.append(0x987); -// bad_signature.append(0x564); +#[test] +#[available_gas(2000000)] +fn test_is_valid_signature() { + let mut state = STATE(); + let data = SIGNED_TX_DATA(); + let hash = data.transaction_hash; -// Account::set_public_key(data.public_key); + let mut good_signature = array![data.r, data.s]; + let mut bad_signature = array![0x987, 0x564]; -// let is_valid = Account::is_valid_signature(hash, good_signature); -// assert(is_valid == starknet::VALIDATED, 'Should accept valid signature'); + Account::PublicKeyImpl::set_public_key(ref state, data.public_key); -// let is_valid = Account::is_valid_signature(hash, bad_signature); -// assert(is_valid == 0, 'Should reject invalid signature'); -// } + let is_valid = Account::SRC6Impl::is_valid_signature(@state, hash, good_signature); + assert(is_valid == starknet::VALIDATED, 'Should accept valid signature'); -// #[test] -// #[available_gas(2000000)] -// fn test_isValidSignature() { -// let data = SIGNED_TX_DATA(); -// let hash = data.transaction_hash; + let is_valid = Account::SRC6Impl::is_valid_signature(@state, hash, bad_signature); + assert(is_valid == 0, 'Should reject invalid signature'); +} -// let mut good_signature = array![]; -// good_signature.append(data.r); -// good_signature.append(data.s); +#[test] +#[available_gas(2000000)] +fn test_isValidSignature() { + let mut state = STATE(); + let data = SIGNED_TX_DATA(); + let hash = data.transaction_hash; -// let mut bad_signature = array![]; -// bad_signature.append(0x987); -// bad_signature.append(0x564); + let mut good_signature = array![data.r, data.s]; + let mut bad_signature = array![0x987, 0x564]; -// Account::set_public_key(data.public_key); + Account::PublicKeyImpl::set_public_key(ref state, data.public_key); -// let is_valid = Account::is_valid_signature(hash, good_signature); -// assert(is_valid == starknet::VALIDATED, 'Should accept valid signature'); + let is_valid = Account::SRC6CamelOnlyImpl::isValidSignature(@state, hash, good_signature); + assert(is_valid == starknet::VALIDATED, 'Should accept valid signature'); -// let is_valid = Account::is_valid_signature(hash, bad_signature); -// assert(is_valid == 0, 'Should reject invalid signature'); -// } + let is_valid = Account::SRC6CamelOnlyImpl::isValidSignature(@state, hash, bad_signature); + assert(is_valid == 0, 'Should reject invalid signature'); +} -// // -// // Entry points -// // +// +// Entry points +// -// #[test] -// #[available_gas(2000000)] -// fn test_validate_deploy() { -// let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); +#[test] +#[available_gas(2000000)] +fn test_validate_deploy() { + let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); + + // `__validate_deploy__` does not directly use the passed arguments. Their + // values are already integrated in the tx hash. The passed arguments in this + // testing context are decoupled from the signature and have no effect on the test. + assert( + account.__validate_deploy__(CLASS_HASH(), SALT, PUBLIC_KEY) == starknet::VALIDATED, + 'Should validate correctly' + ); +} -// // `__validate_deploy__` does not directly use the passed arguments. Their -// // values are already integrated in the tx hash. The passed arguments in this -// // testing context are decoupled from the signature and have no effect on the test. -// assert( -// account.__validate_deploy__(CLASS_HASH(), SALT, PUBLIC_KEY) == starknet::VALIDATED, -// 'Should validate correctly' -// ); -// } +#[test] +#[available_gas(2000000)] +#[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] +fn test_validate_deploy_invalid_signature_data() { + let mut data = SIGNED_TX_DATA(); + data.transaction_hash += 1; + let account = setup_dispatcher(Option::Some(@data)); -// #[test] -// #[available_gas(2000000)] -// #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] -// fn test_validate_deploy_invalid_signature_data() { -// let mut data = SIGNED_TX_DATA(); -// data.transaction_hash += 1; -// let account = setup_dispatcher(Option::Some(@data)); + account.__validate_deploy__(CLASS_HASH(), SALT, PUBLIC_KEY); +} -// account.__validate_deploy__(CLASS_HASH(), SALT, PUBLIC_KEY); -// } +#[test] +#[available_gas(2000000)] +#[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] +fn test_validate_deploy_invalid_signature_length() { + let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); + let mut signature = array![]; -// #[test] -// #[available_gas(2000000)] -// #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] -// fn test_validate_deploy_invalid_signature_length() { -// let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); -// let mut signature = array![]; + signature.append(0x1); + testing::set_signature(signature.span()); -// signature.append(0x1); -// testing::set_signature(signature.span()); + account.__validate_deploy__(CLASS_HASH(), SALT, PUBLIC_KEY); +} -// account.__validate_deploy__(CLASS_HASH(), SALT, PUBLIC_KEY); -// } +#[test] +#[available_gas(2000000)] +#[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] +fn test_validate_deploy_empty_signature() { + let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); + let empty_sig = array![]; -// #[test] -// #[available_gas(2000000)] -// #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] -// fn test_validate_deploy_empty_signature() { -// let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); -// let empty_sig = array![]; + testing::set_signature(empty_sig.span()); + account.__validate_deploy__(CLASS_HASH(), SALT, PUBLIC_KEY); +} -// testing::set_signature(empty_sig.span()); -// account.__validate_deploy__(CLASS_HASH(), SALT, PUBLIC_KEY); -// } +#[test] +#[available_gas(2000000)] +fn test_validate_declare() { + let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); + + // `__validate_declare__` does not directly use the class_hash argument. Its + // value is already integrated in the tx hash. The class_hash argument in this + // testing context is decoupled from the signature and has no effect on the test. + assert( + account.__validate_declare__(CLASS_HASH()) == starknet::VALIDATED, + 'Should validate correctly' + ); +} -// #[test] -// #[available_gas(2000000)] -// fn test_validate_declare() { -// let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); +#[test] +#[available_gas(2000000)] +#[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] +fn test_validate_declare_invalid_signature_data() { + let mut data = SIGNED_TX_DATA(); + data.transaction_hash += 1; + let account = setup_dispatcher(Option::Some(@data)); -// // `__validate_declare__` does not directly use the class_hash argument. Its -// // value is already integrated in the tx hash. The class_hash argument in this -// // testing context is decoupled from the signature and has no effect on the test. -// assert( -// account.__validate_declare__(CLASS_HASH()) == starknet::VALIDATED, -// 'Should validate correctly' -// ); -// } + account.__validate_declare__(CLASS_HASH()); +} -// #[test] -// #[available_gas(2000000)] -// #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] -// fn test_validate_declare_invalid_signature_data() { -// let mut data = SIGNED_TX_DATA(); -// data.transaction_hash += 1; -// let account = setup_dispatcher(Option::Some(@data)); +#[test] +#[available_gas(2000000)] +#[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] +fn test_validate_declare_invalid_signature_length() { + let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); + let mut signature = array![]; -// account.__validate_declare__(CLASS_HASH()); -// } + signature.append(0x1); + testing::set_signature(signature.span()); -// #[test] -// #[available_gas(2000000)] -// #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] -// fn test_validate_declare_invalid_signature_length() { -// let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); -// let mut signature = array![]; + account.__validate_declare__(CLASS_HASH()); +} -// signature.append(0x1); -// testing::set_signature(signature.span()); +#[test] +#[available_gas(2000000)] +#[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] +fn test_validate_declare_empty_signature() { + let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); + let empty_sig = array![]; -// account.__validate_declare__(CLASS_HASH()); -// } + testing::set_signature(empty_sig.span()); -// #[test] -// #[available_gas(2000000)] -// #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] -// fn test_validate_declare_empty_signature() { -// let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); -// let empty_sig = array![]; - -// testing::set_signature(empty_sig.span()); - -// account.__validate_declare__(CLASS_HASH()); -// } + account.__validate_declare__(CLASS_HASH()); +} // fn test_execute_with_version(version: Option) { // let data = SIGNED_TX_DATA(); @@ -337,26 +335,26 @@ fn SIGNED_TX_DATA() -> SignedTransactionData { // test_execute_with_version(Option::Some(TRANSACTION_VERSION - 1)); // } -// #[test] -// #[available_gas(2000000)] -// fn test_validate() { -// let calls = array![]; -// let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); +#[test] +#[available_gas(2000000)] +fn test_validate() { + let calls = array![]; + let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); -// assert(account.__validate__(calls) == starknet::VALIDATED, 'Should validate correctly'); -// } + assert(account.__validate__(calls) == starknet::VALIDATED, 'Should validate correctly'); +} -// #[test] -// #[available_gas(2000000)] -// #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] -// fn test_validate_invalid() { -// let calls = array![]; -// let mut data = SIGNED_TX_DATA(); -// data.transaction_hash += 1; -// let account = setup_dispatcher(Option::Some(@data)); +#[test] +#[available_gas(2000000)] +#[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] +fn test_validate_invalid() { + let calls = array![]; + let mut data = SIGNED_TX_DATA(); + data.transaction_hash += 1; + let account = setup_dispatcher(Option::Some(@data)); -// account.__validate__(calls); -// } + account.__validate__(calls); +} // #[test] // #[available_gas(2000000)] @@ -404,135 +402,142 @@ fn SIGNED_TX_DATA() -> SignedTransactionData { // assert(call2_retval.unwrap(), 'Should have succeeded'); // } -// #[test] -// #[available_gas(2000000)] -// fn test_multicall_zero_calls() { -// let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); -// let mut calls = array![]; +#[test] +#[available_gas(2000000)] +fn test_multicall_zero_calls() { + let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); + let mut calls = array![]; -// let ret = account.__execute__(calls); + let ret = account.__execute__(calls); -// // Test return value -// assert(ret.len() == 0, 'Should have an empty response'); -// } + // Test return value + assert(ret.len() == 0, 'Should have an empty response'); +} -// #[test] -// #[available_gas(2000000)] -// #[should_panic(expected: ('Account: invalid caller', ))] -// fn test_account_called_from_contract() { -// let calls = array![]; -// let caller = contract_address_const::<0x123>(); -// testing::set_contract_address(ACCOUNT_ADDRESS()); -// testing::set_caller_address(caller); -// Account::__execute__(calls); -// } +#[test] +#[available_gas(2000000)] +#[should_panic(expected: ('Account: invalid caller', ))] +fn test_account_called_from_contract() { + let calls = array![]; + let caller = contract_address_const::<0x123>(); -// // -// // set_public_key & get_public_key -// // + testing::set_contract_address(ACCOUNT_ADDRESS()); + testing::set_caller_address(caller); -// #[test] -// #[available_gas(2000000)] -// fn test_public_key_setter_and_getter() { -// testing::set_contract_address(ACCOUNT_ADDRESS()); -// testing::set_caller_address(ACCOUNT_ADDRESS()); -// Account::set_public_key(NEW_PUBKEY); + Account::SRC6Impl::__execute__(@STATE(), calls); +} -// let public_key = Account::get_public_key(); -// assert(public_key == NEW_PUBKEY, 'Should update key'); -// } +// +// set_public_key & get_public_key +// -// #[test] -// #[available_gas(2000000)] -// #[should_panic(expected: ('Account: unauthorized', ))] -// fn test_public_key_setter_different_account() { -// let caller = contract_address_const::<0x123>(); -// testing::set_contract_address(ACCOUNT_ADDRESS()); -// testing::set_caller_address(caller); -// Account::set_public_key(NEW_PUBKEY); -// } +#[test] +#[available_gas(2000000)] +fn test_public_key_setter_and_getter() { + let mut state = STATE(); + testing::set_contract_address(ACCOUNT_ADDRESS()); + testing::set_caller_address(ACCOUNT_ADDRESS()); -// // -// // setPublicKey & getPublicKey -// // + Account::PublicKeyImpl::set_public_key(ref state, NEW_PUBKEY); -// #[test] -// #[available_gas(2000000)] -// fn test_public_key_setter_and_getter_camel() { -// testing::set_contract_address(ACCOUNT_ADDRESS()); -// testing::set_caller_address(ACCOUNT_ADDRESS()); -// Account::setPublicKey(NEW_PUBKEY); + let public_key = Account::PublicKeyImpl::get_public_key(@state); + assert(public_key == NEW_PUBKEY, 'Should update key'); +} -// let public_key = Account::getPublicKey(); -// assert(public_key == NEW_PUBKEY, 'Should update key'); -// } +#[test] +#[available_gas(2000000)] +#[should_panic(expected: ('Account: unauthorized', ))] +fn test_public_key_setter_different_account() { + let mut state = STATE(); + let caller = contract_address_const::<0x123>(); + testing::set_contract_address(ACCOUNT_ADDRESS()); + testing::set_caller_address(caller); -// #[test] -// #[available_gas(2000000)] -// #[should_panic(expected: ('Account: unauthorized', ))] -// fn test_public_key_setter_different_account_camel() { -// let caller = contract_address_const::<0x123>(); -// testing::set_contract_address(ACCOUNT_ADDRESS()); -// testing::set_caller_address(caller); -// Account::setPublicKey(NEW_PUBKEY); -// } + Account::PublicKeyImpl::set_public_key(ref state, NEW_PUBKEY); +} -// // -// // Test internals -// // +// +// setPublicKey & getPublicKey +// -// #[test] -// #[available_gas(2000000)] -// fn test_initializer() { -// Account::initializer(PUBLIC_KEY); -// assert(Account::get_public_key() == PUBLIC_KEY, 'Should return public key'); -// } +#[test] +#[available_gas(2000000)] +fn test_public_key_setter_and_getter_camel() { + let mut state = STATE(); + testing::set_contract_address(ACCOUNT_ADDRESS()); + testing::set_caller_address(ACCOUNT_ADDRESS()); -// #[test] -// #[available_gas(2000000)] -// fn test_assert_only_self_true() { -// testing::set_contract_address(ACCOUNT_ADDRESS()); -// testing::set_caller_address(ACCOUNT_ADDRESS()); -// Account::assert_only_self(); -// } + Account::PublicKeyCamelImpl::setPublicKey(ref state, NEW_PUBKEY); -// #[test] -// #[available_gas(2000000)] -// #[should_panic(expected: ('Account: unauthorized', ))] -// fn test_assert_only_self_false() { -// testing::set_contract_address(ACCOUNT_ADDRESS()); -// let other = contract_address_const::<0x4567>(); -// testing::set_caller_address(other); -// Account::assert_only_self(); -// } + let public_key = Account::PublicKeyCamelImpl::getPublicKey(@state); + assert(public_key == NEW_PUBKEY, 'Should update key'); +} -// #[test] -// #[available_gas(2000000)] -// fn test__is_valid_signature() { -// let data = SIGNED_TX_DATA(); -// let hash = data.transaction_hash; +#[test] +#[available_gas(2000000)] +#[should_panic(expected: ('Account: unauthorized', ))] +fn test_public_key_setter_different_account_camel() { + let mut state = STATE(); + let caller = contract_address_const::<0x123>(); + testing::set_contract_address(ACCOUNT_ADDRESS()); + testing::set_caller_address(caller); + + Account::PublicKeyCamelImpl::setPublicKey(ref state, NEW_PUBKEY); +} -// let mut good_signature = array![]; -// good_signature.append(data.r); -// good_signature.append(data.s); +// +// Test internals +// -// let mut bad_signature = array![]; -// bad_signature.append(0x987); -// bad_signature.append(0x564); +#[test] +#[available_gas(2000000)] +fn test_initializer() { + let mut state = STATE(); + Account::InternalImpl::initializer(ref state, PUBLIC_KEY); + assert( + Account::PublicKeyImpl::get_public_key(@state) == PUBLIC_KEY, 'Should return public key' + ); +} -// let mut invalid_length_signature = array![]; -// invalid_length_signature.append(0x987); +#[test] +#[available_gas(2000000)] +fn test_assert_only_self_true() { + testing::set_contract_address(ACCOUNT_ADDRESS()); + testing::set_caller_address(ACCOUNT_ADDRESS()); + Account::assert_only_self(); +} -// Account::set_public_key(data.public_key); +#[test] +#[available_gas(2000000)] +#[should_panic(expected: ('Account: unauthorized', ))] +fn test_assert_only_self_false() { + testing::set_contract_address(ACCOUNT_ADDRESS()); + let other = contract_address_const::<0x4567>(); + testing::set_caller_address(other); + Account::assert_only_self(); +} -// let is_valid = Account::_is_valid_signature(hash, good_signature.span()); -// assert(is_valid, 'Should accept valid signature'); +#[test] +#[available_gas(2000000)] +fn test__is_valid_signature() { + let mut state = STATE(); + let data = SIGNED_TX_DATA(); + let hash = data.transaction_hash; -// let is_valid = Account::_is_valid_signature(hash, bad_signature.span()); -// assert(!is_valid, 'Should reject invalid signature'); + let mut good_signature = array![data.r, data.s]; + let mut bad_signature = array![0x987, 0x564]; + let mut invalid_length_signature = array![0x987]; -// let is_valid = Account::_is_valid_signature(hash, invalid_length_signature.span()); -// assert(!is_valid, 'Should reject invalid length'); -// } + Account::PublicKeyImpl::set_public_key(ref state, data.public_key); + let is_valid = Account::InternalImpl::_is_valid_signature(@state, hash, good_signature.span()); + assert(is_valid, 'Should accept valid signature'); + let is_valid = Account::InternalImpl::_is_valid_signature(@state, hash, bad_signature.span()); + assert(!is_valid, 'Should reject invalid signature'); + + let is_valid = Account::InternalImpl::_is_valid_signature( + @state, hash, invalid_length_signature.span() + ); + assert(!is_valid, 'Should reject invalid length'); +} diff --git a/src/openzeppelin/tests/account/test_dual_account.cairo b/src/openzeppelin/tests/account/test_dual_account.cairo index b1a9e4bfe..cf07d7e03 100644 --- a/src/openzeppelin/tests/account/test_dual_account.cairo +++ b/src/openzeppelin/tests/account/test_dual_account.cairo @@ -1,4 +1,3 @@ -use array::ArrayTrait; use starknet::testing; use openzeppelin::account::dual_account::DualCaseAccount; From 3dc48c5b3904a181f5f74d47507aaf241fb46b5d Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Wed, 19 Jul 2023 16:02:04 +0200 Subject: [PATCH 7/7] feat: apply review updates --- src/openzeppelin/account.cairo | 4 +-- src/openzeppelin/account/account.cairo | 8 ++--- src/openzeppelin/account/dual_account.cairo | 4 +-- src/openzeppelin/account/interface.cairo | 1 + .../tests/account/test_account.cairo | 10 +++---- .../tests/account/test_dual_account.cairo | 18 +++++------ .../tests/mocks/account_panic_mock.cairo | 1 + .../tests/mocks/camel_account_mock.cairo | 1 - .../tests/mocks/snake_account_mock.cairo | 30 ------------------- 9 files changed, 23 insertions(+), 54 deletions(-) diff --git a/src/openzeppelin/account.cairo b/src/openzeppelin/account.cairo index fae14ac00..47e57df8a 100644 --- a/src/openzeppelin/account.cairo +++ b/src/openzeppelin/account.cairo @@ -1,7 +1,7 @@ mod account; use account::{ - Account, AccountCamelTraitDispatcher, AccountCamelTraitDispatcherTrait, AccountTraitDispatcher, - AccountTraitDispatcherTrait, TRANSACTION_VERSION, QUERY_VERSION + Account, AccountCamelABIDispatcher, AccountCamelABIDispatcherTrait, AccountABIDispatcher, + AccountABIDispatcherTrait, TRANSACTION_VERSION, QUERY_VERSION }; mod dual_account; diff --git a/src/openzeppelin/account/account.cairo b/src/openzeppelin/account/account.cairo index a3888f1fc..714f1f89f 100644 --- a/src/openzeppelin/account/account.cairo +++ b/src/openzeppelin/account/account.cairo @@ -2,9 +2,9 @@ use array::ArrayTrait; use array::SpanTrait; use option::OptionTrait; use serde::Serde; +use starknet::account::Call; use starknet::ContractAddress; -use openzeppelin::account::interface::Call; const TRANSACTION_VERSION: felt252 = 1; @@ -12,7 +12,7 @@ const TRANSACTION_VERSION: felt252 = 1; const QUERY_VERSION: felt252 = 340282366920938463463374607431768211457; #[starknet::interface] -trait AccountTrait { +trait AccountABI { fn __execute__(self: @TState, calls: Array) -> Array>; fn __validate__(self: @TState, calls: Array) -> felt252; fn __validate_declare__(self: @TState, class_hash: felt252) -> felt252; @@ -27,7 +27,7 @@ trait AccountTrait { // Entry points case-convention is enforced by the protocol #[starknet::interface] -trait AccountCamelTrait { +trait AccountCamelABI { fn __execute__(self: @TState, calls: Array) -> Array>; fn __validate__(self: @TState, calls: Array) -> felt252; fn __validate_declare__(self: @TState, classHash: felt252) -> felt252; @@ -40,13 +40,11 @@ trait AccountCamelTrait { fn supportsInterface(self: @TState, interfaceId: felt252) -> bool; } -#[starknet::interface] trait PublicKeyTrait { fn set_public_key(ref self: TState, new_public_key: felt252); fn get_public_key(self: @TState) -> felt252; } -#[starknet::interface] trait PublicKeyCamelTrait { fn setPublicKey(ref self: TState, newPublicKey: felt252); fn getPublicKey(self: @TState) -> felt252; diff --git a/src/openzeppelin/account/dual_account.cairo b/src/openzeppelin/account/dual_account.cairo index ffd46f680..ee4e1c0b6 100644 --- a/src/openzeppelin/account/dual_account.cairo +++ b/src/openzeppelin/account/dual_account.cairo @@ -13,7 +13,7 @@ struct DualCaseAccount { contract_address: ContractAddress } -trait DualCaseAccountTrait { +trait DualCaseAccountABI { fn set_public_key(self: @DualCaseAccount, new_public_key: felt252); fn get_public_key(self: @DualCaseAccount) -> felt252; fn is_valid_signature( @@ -22,7 +22,7 @@ trait DualCaseAccountTrait { fn supports_interface(self: @DualCaseAccount, interface_id: felt252) -> bool; } -impl DualCaseAccountImpl of DualCaseAccountTrait { +impl DualCaseAccountImpl of DualCaseAccountABI { fn set_public_key(self: @DualCaseAccount, new_public_key: felt252) { let mut args = array![new_public_key]; diff --git a/src/openzeppelin/account/interface.cairo b/src/openzeppelin/account/interface.cairo index a683acf43..2027c0c99 100644 --- a/src/openzeppelin/account/interface.cairo +++ b/src/openzeppelin/account/interface.cairo @@ -1,5 +1,6 @@ use array::ArrayTrait; use array::SpanTrait; +use starknet::account::Call; use starknet::ContractAddress; const ISRC6_ID: felt252 = 0x2ceccef7f994940b3962a6c67e0ba4fcd37df7d131417c604f91e03caecc1cd; diff --git a/src/openzeppelin/tests/account/test_account.cairo b/src/openzeppelin/tests/account/test_account.cairo index 4a83a9a5a..48ab02685 100644 --- a/src/openzeppelin/tests/account/test_account.cairo +++ b/src/openzeppelin/tests/account/test_account.cairo @@ -2,14 +2,14 @@ use array::ArrayTrait; use core::traits::Into; use option::OptionTrait; use serde::Serde; +use starknet::account::Call; use starknet::contract_address_const; use starknet::ContractAddress; use starknet::testing; use openzeppelin::account::Account; -use openzeppelin::account::AccountTraitDispatcher; -use openzeppelin::account::AccountTraitDispatcherTrait; -use openzeppelin::account::interface::Call; +use openzeppelin::account::AccountABIDispatcher; +use openzeppelin::account::AccountABIDispatcherTrait; use openzeppelin::account::interface::ISRC6_ID; use openzeppelin::account::QUERY_VERSION; use openzeppelin::account::TRANSACTION_VERSION; @@ -61,7 +61,7 @@ fn SIGNED_TX_DATA() -> SignedTransactionData { // Setup // -fn setup_dispatcher(data: Option<@SignedTransactionData>) -> AccountTraitDispatcher { +fn setup_dispatcher(data: Option<@SignedTransactionData>) -> AccountABIDispatcher { testing::set_version(TRANSACTION_VERSION); let mut calldata = array![]; @@ -75,7 +75,7 @@ fn setup_dispatcher(data: Option<@SignedTransactionData>) -> AccountTraitDispatc calldata.append(PUBLIC_KEY); } let address = utils::deploy(CLASS_HASH(), calldata); - AccountTraitDispatcher { contract_address: address } + AccountABIDispatcher { contract_address: address } } // fn deploy_erc20(recipient: ContractAddress, initial_supply: u256) -> IERC20Dispatcher { diff --git a/src/openzeppelin/tests/account/test_dual_account.cairo b/src/openzeppelin/tests/account/test_dual_account.cairo index cf07d7e03..76ea9fb99 100644 --- a/src/openzeppelin/tests/account/test_dual_account.cairo +++ b/src/openzeppelin/tests/account/test_dual_account.cairo @@ -1,11 +1,11 @@ use starknet::testing; use openzeppelin::account::dual_account::DualCaseAccount; -use openzeppelin::account::dual_account::DualCaseAccountTrait; -use openzeppelin::account::AccountCamelTraitDispatcher; -use openzeppelin::account::AccountCamelTraitDispatcherTrait; -use openzeppelin::account::AccountTraitDispatcher; -use openzeppelin::account::AccountTraitDispatcherTrait; +use openzeppelin::account::dual_account::DualCaseAccountABI; +use openzeppelin::account::AccountCamelABIDispatcher; +use openzeppelin::account::AccountCamelABIDispatcherTrait; +use openzeppelin::account::AccountABIDispatcher; +use openzeppelin::account::AccountABIDispatcherTrait; use openzeppelin::introspection::interface::ISRC5_ID; use openzeppelin::tests::account::test_account::SIGNED_TX_DATA; use openzeppelin::tests::mocks::account_panic_mock::CamelAccountPanicMock; @@ -26,21 +26,21 @@ const NEW_PUBLIC_KEY: felt252 = 0x444444; // Setup // -fn setup_snake() -> (DualCaseAccount, AccountTraitDispatcher) { +fn setup_snake() -> (DualCaseAccount, AccountABIDispatcher) { let mut calldata = array![PUBLIC_KEY]; let target = utils::deploy(SnakeAccountMock::TEST_CLASS_HASH, calldata); ( DualCaseAccount { contract_address: target }, - AccountTraitDispatcher { contract_address: target } + AccountABIDispatcher { contract_address: target } ) } -fn setup_camel() -> (DualCaseAccount, AccountCamelTraitDispatcher) { +fn setup_camel() -> (DualCaseAccount, AccountCamelABIDispatcher) { let mut calldata = array![PUBLIC_KEY]; let target = utils::deploy(CamelAccountMock::TEST_CLASS_HASH, calldata); ( DualCaseAccount { contract_address: target }, - AccountCamelTraitDispatcher { contract_address: target } + AccountCamelABIDispatcher { contract_address: target } ) } diff --git a/src/openzeppelin/tests/mocks/account_panic_mock.cairo b/src/openzeppelin/tests/mocks/account_panic_mock.cairo index 12cf10207..0a85c890c 100644 --- a/src/openzeppelin/tests/mocks/account_panic_mock.cairo +++ b/src/openzeppelin/tests/mocks/account_panic_mock.cairo @@ -39,6 +39,7 @@ mod SnakeAccountPanicMock { mod CamelAccountPanicMock { #[storage] struct Storage {} + #[external(v0)] fn setPublicKey(ref self: ContractState, newPublicKey: felt252) { panic_with_felt252('Some error'); diff --git a/src/openzeppelin/tests/mocks/camel_account_mock.cairo b/src/openzeppelin/tests/mocks/camel_account_mock.cairo index 10bde06b1..19cf1725c 100644 --- a/src/openzeppelin/tests/mocks/camel_account_mock.cairo +++ b/src/openzeppelin/tests/mocks/camel_account_mock.cairo @@ -1,6 +1,5 @@ #[starknet::contract] mod CamelAccountMock { - use openzeppelin::account::interface::Call; use openzeppelin::account::Account; #[storage] diff --git a/src/openzeppelin/tests/mocks/snake_account_mock.cairo b/src/openzeppelin/tests/mocks/snake_account_mock.cairo index c4b9861b9..80dc1f715 100644 --- a/src/openzeppelin/tests/mocks/snake_account_mock.cairo +++ b/src/openzeppelin/tests/mocks/snake_account_mock.cairo @@ -1,6 +1,5 @@ #[starknet::contract] mod SnakeAccountMock { - use openzeppelin::account::interface::Call; use openzeppelin::account::Account; #[storage] @@ -12,35 +11,6 @@ mod SnakeAccountMock { Account::InternalImpl::initializer(ref unsafe_state, _public_key); } - #[external(v0)] - fn __execute__(self: @ContractState, mut calls: Array) -> Array> { - let mut unsafe_state = Account::unsafe_new_contract_state(); - Account::SRC6Impl::__execute__(@unsafe_state, calls) - } - - #[external(v0)] - fn __validate__(self: @ContractState, mut calls: Array) -> felt252 { - let mut unsafe_state = Account::unsafe_new_contract_state(); - Account::SRC6Impl::__validate__(@unsafe_state, calls) - } - - #[external(v0)] - fn __validate_declare__(self: @ContractState, class_hash: felt252) -> felt252 { - let mut unsafe_state = Account::unsafe_new_contract_state(); - Account::DeclarerImpl::__validate_declare__(@unsafe_state, class_hash) - } - - #[external(v0)] - fn __validate_deploy__( - self: @ContractState, - class_hash: felt252, - contract_address_salt: felt252, - _public_key: felt252 - ) -> felt252 { - let mut unsafe_state = Account::unsafe_new_contract_state(); - Account::__validate_deploy__(@unsafe_state, class_hash, contract_address_salt, _public_key) - } - #[external(v0)] fn set_public_key(ref self: ContractState, new_public_key: felt252) { let mut unsafe_state = Account::unsafe_new_contract_state();