diff --git a/Cargo.lock b/Cargo.lock index 0d62a27497..066d9f0fba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,15 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" +dependencies = [ + "lazy_static", + "regex", +] + [[package]] name = "adler32" version = "1.0.4" @@ -681,6 +691,17 @@ dependencies = [ "syn 0.15.44", ] +[[package]] +name = "derive_more" +version = "0.99.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "298998b1cf6b5b2c8a7b023dfd45821825ce3ba8a8af55c921a0e734e4653f76" +dependencies = [ + "proc-macro2 1.0.10", + "quote 1.0.3", + "syn 1.0.17", +] + [[package]] name = "difference" version = "2.0.0" @@ -872,6 +893,18 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "fixed-hash" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11498d382790b7a8f2fd211780bec78619bba81cdad3a283997c0c41f836759c" +dependencies = [ + "byteorder 1.3.4", + "rand 0.7.3", + "rustc-hex", + "static_assertions", +] + [[package]] name = "fixedbitset" version = "0.1.9" @@ -922,6 +955,91 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05f8140122fa0d5dcb9fc8627cfce2b37cc1500f752636d46ea28bc26785c2f9" +[[package]] +name = "frame-metadata" +version = "11.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "parity-scale-codec", + "serde", + "sp-core", + "sp-std", +] + +[[package]] +name = "frame-support" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "bitmask", + "frame-metadata", + "frame-support-procedural", + "impl-trait-for-tuples", + "log", + "once_cell 1.4.0", + "parity-scale-codec", + "paste", + "serde", + "smallvec 1.4.1", + "sp-arithmetic", + "sp-core", + "sp-inherents", + "sp-io", + "sp-runtime", + "sp-state-machine", + "sp-std", + "sp-tracing", +] + +[[package]] +name = "frame-support-procedural" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "frame-support-procedural-tools", + "proc-macro2 1.0.10", + "quote 1.0.3", + "syn 1.0.17", +] + +[[package]] +name = "frame-support-procedural-tools" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "frame-support-procedural-tools-derive", + "proc-macro-crate", + "proc-macro2 1.0.10", + "quote 1.0.3", + "syn 1.0.17", +] + +[[package]] +name = "frame-support-procedural-tools-derive" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "proc-macro2 1.0.10", + "quote 1.0.3", + "syn 1.0.17", +] + +[[package]] +name = "frame-system" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "frame-support", + "impl-trait-for-tuples", + "parity-scale-codec", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "sp-version", +] + [[package]] name = "fs-swap" version = "0.2.4" @@ -1552,6 +1670,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "0.4.5" @@ -2416,7 +2543,19 @@ dependencies = [ "ahash", "hash-db", "hashbrown 0.6.3", - "parity-util-mem", + "parity-util-mem 0.2.1", +] + +[[package]] +name = "memory-db" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb2999ff7a65d5a1d72172f6d51fa2ea03024b51aee709ba5ff81c3c629a2410" +dependencies = [ + "ahash", + "hash-db", + "hashbrown 0.6.3", + "parity-util-mem 0.6.1", ] [[package]] @@ -2437,6 +2576,18 @@ dependencies = [ "zeroize 1.1.0", ] +[[package]] +name = "merlin" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6feca46f4fa3443a01769d768727f10c10a20fdb65e52dc16a81f0c8269bb78" +dependencies = [ + "byteorder 1.3.4", + "keccak", + "rand_core 0.5.1", + "zeroize 1.1.0", +] + [[package]] name = "miniz_oxide" version = "0.3.6" @@ -2707,6 +2858,15 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d584f08c2d717d5c23a6414fc2822b71c651560713e54fa7eace675f758a355e" +[[package]] +name = "once_cell" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" +dependencies = [ + "parking_lot 0.10.0", +] + [[package]] name = "opaque-debug" version = "0.2.3" @@ -2722,6 +2882,21 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "pallet-content-directory" +version = "3.0.0" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "serde", + "sp-arithmetic", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "parity-bytes" version = "0.1.0" @@ -2795,9 +2970,9 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "1.3.0" +version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "329c8f7f4244ddb5c37c103641027a76c530e65e8e4b8240b29f81ea40508b17" +checksum = "34d38aeaffc032ec69faa476b3caaca8d4dd7f3f798137ff30359e5c7869ceb6" dependencies = [ "arrayvec 0.5.1", "bitvec", @@ -2808,9 +2983,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a0ec292e92e8ec7c58e576adacc1e3f399c597c8f263c42f18420abe58e7245" +checksum = "cd20ff7e0399b274a5f5bb37b712fccb5b3a64b9128200d1c3cc40fe709cb073" dependencies = [ "proc-macro-crate", "proc-macro2 1.0.10", @@ -2835,12 +3010,43 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "parity-util-mem" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c6e2583649a3ca84894d1d71da249abcfda54d5aca24733d72ca10d0f02361c" +dependencies = [ + "cfg-if", + "impl-trait-for-tuples", + "parity-util-mem-derive", + "parking_lot 0.10.0", + "primitive-types 0.7.1", + "winapi 0.3.8", +] + +[[package]] +name = "parity-util-mem-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f557c32c6d268a07c921471619c0295f5efad3a0e76d4f97a05c091a51d110b2" +dependencies = [ + "proc-macro2 1.0.10", + "syn 1.0.17", + "synstructure", +] + [[package]] name = "parity-wasm" version = "0.40.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e39faaa292a687ea15120b1ac31899b13586446521df6c149e46f1584671e0f" +[[package]] +name = "parity-wasm" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865" + [[package]] name = "parking_lot" version = "0.6.4" @@ -2960,7 +3166,7 @@ dependencies = [ "cloudabi", "libc", "redox_syscall", - "smallvec 1.2.0", + "smallvec 1.4.1", "winapi 0.3.8", ] @@ -3082,7 +3288,19 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4336f4f5d5524fa60bcbd6fe626f9223d8142a50e7053e979acdf0da41ab975" dependencies = [ - "fixed-hash", + "fixed-hash 0.5.2", + "impl-codec", + "impl-serde 0.3.0", + "uint", +] + +[[package]] +name = "primitive-types" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dedac218327b6b55fff5ef05f63ce5127024e1a36342836da7e92cbfac4531" +dependencies = [ + "fixed-hash 0.6.1", "impl-codec", "impl-serde 0.3.0", "uint", @@ -3172,7 +3390,7 @@ checksum = "eb788126ea840817128183f8f603dce02cb7aea25c2a0b764359d8e20010702e" dependencies = [ "bytes 0.4.12", "heck", - "itertools", + "itertools 0.8.2", "log", "multimap", "petgraph", @@ -3189,7 +3407,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e7dc378b94ac374644181a2247cebf59a6ec1c88b49ac77f3a94b86b79d0e11" dependencies = [ "failure", - "itertools", + "itertools 0.8.2", "proc-macro2 0.4.30", "quote 0.6.13", "syn 0.15.44", @@ -3291,7 +3509,7 @@ dependencies = [ "rand_isaac", "rand_jitter", "rand_os", - "rand_pcg", + "rand_pcg 0.1.2", "rand_xorshift", "winapi 0.3.8", ] @@ -3307,6 +3525,7 @@ dependencies = [ "rand_chacha 0.2.2", "rand_core 0.5.1", "rand_hc 0.2.0", + "rand_pcg 0.2.1", ] [[package]] @@ -3415,6 +3634,15 @@ dependencies = [ "rand_core 0.4.2", ] +[[package]] +name = "rand_pcg" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" +dependencies = [ + "rand_core 0.5.1", +] + [[package]] name = "rand_xorshift" version = "0.1.1" @@ -3463,6 +3691,26 @@ version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +[[package]] +name = "ref-cast" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "745c1787167ddae5569661d5ffb8b25ae5fedbf46717eaa92d652221cec72623" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d21b475ab879ef0e315ad99067fa25778c3b0377f57f1b00207448dac1a3144" +dependencies = [ + "proc-macro2 1.0.10", + "quote 1.0.3", + "syn 1.0.17", +] + [[package]] name = "regex" version = "1.3.6" @@ -3490,6 +3738,27 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "rental" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8545debe98b2b139fb04cad8618b530e9b07c152d99a5de83c860b877d67847f" +dependencies = [ + "rental-impl", + "stable_deref_trait", +] + +[[package]] +name = "rental-impl" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "475e68978dc5b743f2f40d8e0a8fdc83f1c5e78cbf4b8fa5e74e73beebc340de" +dependencies = [ + "proc-macro2 1.0.10", + "quote 1.0.3", + "syn 1.0.17", +] + [[package]] name = "ring" version = "0.16.12" @@ -3531,6 +3800,12 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc-hex" version = "2.1.0" @@ -3593,7 +3868,7 @@ checksum = "eacd8381b3c37840c9c9f40472af529e49975bdcbc24f83c31059fd6539023d3" dependencies = [ "curve25519-dalek 1.2.3", "failure", - "merlin", + "merlin 1.3.0", "rand 0.6.5", "rand_core 0.4.2", "rand_os", @@ -3602,6 +3877,24 @@ dependencies = [ "zeroize 0.9.3", ] +[[package]] +name = "schnorrkel" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "021b403afe70d81eea68f6ea12f6b3c9588e5d536a94c3bf80f15e7faa267862" +dependencies = [ + "arrayref", + "arrayvec 0.5.1", + "curve25519-dalek 2.0.0", + "getrandom", + "merlin 2.0.0", + "rand 0.7.3", + "rand_core 0.5.1", + "sha2", + "subtle 2.2.2", + "zeroize 1.1.0", +] + [[package]] name = "scopeguard" version = "0.3.3" @@ -3801,9 +4094,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.2.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c2fb2ec9bcd216a5b0d0ccf31ab17b5ed1d627960edff65bbe95d3ce221cefc" +checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f" [[package]] name = "snow" @@ -3838,6 +4131,270 @@ dependencies = [ "tokio-io", ] +[[package]] +name = "sp-application-crypto" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "parity-scale-codec", + "serde", + "sp-core", + "sp-io", + "sp-std", +] + +[[package]] +name = "sp-arithmetic" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "integer-sqrt", + "num-traits", + "parity-scale-codec", + "serde", + "sp-debug-derive", + "sp-std", +] + +[[package]] +name = "sp-core" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "base58", + "blake2-rfc", + "byteorder 1.3.4", + "derive_more 0.99.9", + "ed25519-dalek 1.0.0-pre.3", + "futures 0.3.4", + "hash-db", + "hash256-std-hasher", + "hex 0.4.2", + "impl-serde 0.3.0", + "lazy_static", + "libsecp256k1", + "log", + "merlin 2.0.0", + "num-traits", + "parity-scale-codec", + "parity-util-mem 0.6.1", + "parking_lot 0.10.0", + "primitive-types 0.7.1", + "rand 0.7.3", + "regex", + "schnorrkel 0.9.1", + "serde", + "sha2", + "sp-debug-derive", + "sp-externalities", + "sp-runtime-interface", + "sp-std", + "sp-storage", + "substrate-bip39 0.4.1", + "tiny-bip39 0.7.3", + "tiny-keccak 2.0.2", + "twox-hash", + "wasmi 0.6.2", + "zeroize 1.1.0", +] + +[[package]] +name = "sp-debug-derive" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "proc-macro2 1.0.10", + "quote 1.0.3", + "syn 1.0.17", +] + +[[package]] +name = "sp-externalities" +version = "0.8.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "environmental", + "parity-scale-codec", + "sp-std", + "sp-storage", +] + +[[package]] +name = "sp-inherents" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "derive_more 0.99.9", + "parity-scale-codec", + "parking_lot 0.10.0", + "sp-core", + "sp-std", +] + +[[package]] +name = "sp-io" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "futures 0.3.4", + "hash-db", + "libsecp256k1", + "log", + "parity-scale-codec", + "parking_lot 0.10.0", + "sp-core", + "sp-externalities", + "sp-runtime-interface", + "sp-state-machine", + "sp-std", + "sp-tracing", + "sp-trie", + "sp-wasm-interface", +] + +[[package]] +name = "sp-panic-handler" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "backtrace", + "log", +] + +[[package]] +name = "sp-runtime" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "either", + "hash256-std-hasher", + "impl-trait-for-tuples", + "log", + "parity-scale-codec", + "parity-util-mem 0.6.1", + "paste", + "rand 0.7.3", + "serde", + "sp-application-crypto", + "sp-arithmetic", + "sp-core", + "sp-inherents", + "sp-io", + "sp-std", +] + +[[package]] +name = "sp-runtime-interface" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "parity-scale-codec", + "primitive-types 0.7.1", + "sp-externalities", + "sp-runtime-interface-proc-macro", + "sp-std", + "sp-tracing", + "sp-wasm-interface", + "static_assertions", +] + +[[package]] +name = "sp-runtime-interface-proc-macro" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "Inflector", + "proc-macro-crate", + "proc-macro2 1.0.10", + "quote 1.0.3", + "syn 1.0.17", +] + +[[package]] +name = "sp-state-machine" +version = "0.8.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "hash-db", + "itertools 0.9.0", + "log", + "num-traits", + "parity-scale-codec", + "parking_lot 0.10.0", + "rand 0.7.3", + "smallvec 1.4.1", + "sp-core", + "sp-externalities", + "sp-panic-handler", + "sp-trie", + "trie-db 0.21.0", + "trie-root 0.16.0", +] + +[[package]] +name = "sp-std" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" + +[[package]] +name = "sp-storage" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "impl-serde 0.2.3", + "ref-cast", + "serde", + "sp-debug-derive", + "sp-std", +] + +[[package]] +name = "sp-tracing" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "log", + "rental", + "tracing", +] + +[[package]] +name = "sp-trie" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "hash-db", + "memory-db 0.21.0", + "parity-scale-codec", + "sp-core", + "sp-std", + "trie-db 0.21.0", + "trie-root 0.16.0", +] + +[[package]] +name = "sp-version" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "impl-serde 0.2.3", + "parity-scale-codec", + "serde", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "sp-wasm-interface" +version = "2.0.0-rc4" +source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4" +dependencies = [ + "impl-trait-for-tuples", + "parity-scale-codec", + "sp-std", + "wasmi 0.6.2", +] + [[package]] name = "spin" version = "0.5.2" @@ -3884,7 +4441,7 @@ dependencies = [ "substrate-primitives", "substrate-state-machine", "substrate-trie", - "tiny-keccak", + "tiny-keccak 1.5.0", ] [[package]] @@ -4457,7 +5014,19 @@ checksum = "3be511be555a3633e71739a79e4ddff6a6aaa6579fa6114182a51d72c3eb93c5" dependencies = [ "hmac", "pbkdf2", - "schnorrkel", + "schnorrkel 0.8.5", + "sha2", +] + +[[package]] +name = "substrate-bip39" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c004e8166d6e0aa3a9d5fa673e5b7098ff25f930de1013a21341988151e681bb" +dependencies = [ + "hmac", + "pbkdf2", + "schnorrkel 0.9.1", "sha2", ] @@ -4597,7 +5166,7 @@ dependencies = [ "futures-preview", "futures-timer", "log", - "merlin", + "merlin 1.3.0", "num-bigint", "num-rational", "num-traits", @@ -4605,7 +5174,7 @@ dependencies = [ "parking_lot 0.9.0", "pdqselect", "rand 0.7.3", - "schnorrkel", + "schnorrkel 0.8.5", "sr-io", "sr-primitives", "sr-version", @@ -4630,7 +5199,7 @@ version = "2.0.0" source = "git+https://github.com/paritytech/substrate.git?rev=c37bb08535c49a12320af7facfd555ce05cce2e8#c37bb08535c49a12320af7facfd555ce05cce2e8" dependencies = [ "parity-scale-codec", - "schnorrkel", + "schnorrkel 0.8.5", "sr-primitives", "sr-std", "substrate-application-crypto", @@ -4689,24 +5258,6 @@ dependencies = [ "substrate-primitives", ] -[[package]] -name = "substrate-content-directory-module" -version = "1.0.1" -dependencies = [ - "hex-literal 0.1.4", - "parity-scale-codec", - "quote 0.6.13", - "serde", - "sr-io", - "sr-primitives", - "sr-std", - "srml-support", - "srml-support-procedural", - "srml-system", - "srml-timestamp", - "substrate-primitives", -] - [[package]] name = "substrate-content-working-group-module" version = "1.0.0" @@ -4752,7 +5303,7 @@ dependencies = [ "libsecp256k1", "log", "parity-scale-codec", - "parity-wasm", + "parity-wasm 0.40.3", "parking_lot 0.9.0", "sr-io", "sr-version", @@ -4762,8 +5313,8 @@ dependencies = [ "substrate-serializer", "substrate-trie", "substrate-wasm-interface", - "tiny-keccak", - "wasmi", + "tiny-keccak 1.5.0", + "wasmi 0.5.1", ] [[package]] @@ -4772,7 +5323,7 @@ version = "2.0.0" source = "git+https://github.com/paritytech/substrate.git?rev=c37bb08535c49a12320af7facfd555ce05cce2e8#c37bb08535c49a12320af7facfd555ce05cce2e8" dependencies = [ "environmental", - "primitive-types", + "primitive-types 0.6.2", "sr-std", "substrate-primitives-storage", ] @@ -5087,22 +5638,22 @@ dependencies = [ "num-traits", "parity-scale-codec", "parking_lot 0.9.0", - "primitive-types", + "primitive-types 0.6.2", "rand 0.7.3", "regex", "rustc-hex", - "schnorrkel", + "schnorrkel 0.8.5", "serde", "sha2", "sr-std", - "substrate-bip39", + "substrate-bip39 0.3.1", "substrate-debug-derive", "substrate-externalities", "substrate-primitives-storage", - "tiny-bip39", - "tiny-keccak", + "tiny-bip39 0.6.2", + "tiny-keccak 1.5.0", "twox-hash", - "wasmi", + "wasmi 0.5.1", "zeroize 0.10.1", ] @@ -5422,8 +5973,8 @@ dependencies = [ "substrate-panic-handler", "substrate-primitives", "substrate-trie", - "trie-db", - "trie-root", + "trie-db 0.15.2", + "trie-root 0.15.2", ] [[package]] @@ -5523,12 +6074,12 @@ version = "2.0.0" source = "git+https://github.com/paritytech/substrate.git?rev=c37bb08535c49a12320af7facfd555ce05cce2e8#c37bb08535c49a12320af7facfd555ce05cce2e8" dependencies = [ "hash-db", - "memory-db", + "memory-db 0.15.3", "parity-scale-codec", "sr-std", "substrate-primitives", - "trie-db", - "trie-root", + "trie-db 0.15.2", + "trie-root 0.15.2", ] [[package]] @@ -5582,7 +6133,7 @@ name = "substrate-wasm-interface" version = "2.0.0" source = "git+https://github.com/paritytech/substrate.git?rev=c37bb08535c49a12320af7facfd555ce05cce2e8#c37bb08535c49a12320af7facfd555ce05cce2e8" dependencies = [ - "wasmi", + "wasmi 0.5.1", ] [[package]] @@ -5741,6 +6292,22 @@ dependencies = [ "sha2", ] +[[package]] +name = "tiny-bip39" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0165e045cc2ae1660270ca65e1676dbaab60feb0f91b10f7d0665e9b47e31f2" +dependencies = [ + "failure", + "hmac", + "once_cell 1.4.0", + "pbkdf2", + "rand 0.7.3", + "rustc-hash", + "sha2", + "unicode-normalization", +] + [[package]] name = "tiny-keccak" version = "1.5.0" @@ -5750,6 +6317,15 @@ dependencies = [ "crunchy", ] +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + [[package]] name = "tokio" version = "0.1.22" @@ -5978,6 +6554,37 @@ dependencies = [ "serde", ] +[[package]] +name = "tracing" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbdf4ccd1652592b01286a5dbe1e2a77d78afaa34beadd9872a5f7396f92aaa9" +dependencies = [ + "cfg-if", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0693bf8d6f2bf22c690fc61a9d21ac69efdbb894a17ed596b9af0f01e64b84b" +dependencies = [ + "proc-macro2 1.0.10", + "quote 1.0.3", + "syn 1.0.17", +] + +[[package]] +name = "tracing-core" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94ae75f0d28ae10786f3b1895c55fe72e79928fd5ccdebb5438c75e93fec178f" +dependencies = [ + "lazy_static", +] + [[package]] name = "treeline" version = "0.1.0" @@ -5997,6 +6604,19 @@ dependencies = [ "rand 0.6.5", ] +[[package]] +name = "trie-db" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb230c24c741993b04cfccbabb45acff6f6480c5f00d3ed8794ea43db3a9d727" +dependencies = [ + "hash-db", + "hashbrown 0.6.3", + "log", + "rustc-hex", + "smallvec 1.4.1", +] + [[package]] name = "trie-root" version = "0.15.2" @@ -6006,6 +6626,15 @@ dependencies = [ "hash-db", ] +[[package]] +name = "trie-root" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "652931506d2c1244d7217a70b99f56718a7b4161b37f04e7cd868072a99f68cd" +dependencies = [ + "hash-db", +] + [[package]] name = "try-lock" version = "0.2.2" @@ -6040,9 +6669,9 @@ checksum = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" [[package]] name = "uint" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e75a4cdd7b87b28840dba13c483b9a88ee6bbf16ba5c951ee1ecfcf723078e0d" +checksum = "173cd16430c206dc1a430af8a89a0e9c076cf15cb42b4aedb10e8cc8fee73681" dependencies = [ "byteorder 1.3.4", "crunchy", @@ -6074,7 +6703,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5479532badd04e128284890390c1e876ef7a993d0570b3597ae43dfa1d59afa4" dependencies = [ - "smallvec 1.2.0", + "smallvec 1.4.1", ] [[package]] @@ -6293,8 +6922,22 @@ dependencies = [ "memory_units", "num-rational", "num-traits", - "parity-wasm", - "wasmi-validation", + "parity-wasm 0.40.3", + "wasmi-validation 0.2.0", +] + +[[package]] +name = "wasmi" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf617d864d25af3587aa745529f7aaa541066c876d57e050c0d0c85c61c92aff" +dependencies = [ + "libc", + "memory_units", + "num-rational", + "num-traits", + "parity-wasm 0.41.0", + "wasmi-validation 0.3.0", ] [[package]] @@ -6303,7 +6946,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bc0356e3df56e639fc7f7d8a99741915531e27ed735d911ed83d7e1339c8188" dependencies = [ - "parity-wasm", + "parity-wasm 0.40.3", +] + +[[package]] +name = "wasmi-validation" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea78c597064ba73596099281e2f4cfc019075122a65cdda3205af94f0b264d93" +dependencies = [ + "parity-wasm 0.41.0", ] [[package]] diff --git a/runtime-modules/content-directory/Cargo.toml b/runtime-modules/content-directory/Cargo.toml index 1be0f7f5af..89330b46a8 100755 --- a/runtime-modules/content-directory/Cargo.toml +++ b/runtime-modules/content-directory/Cargo.toml @@ -1,40 +1,30 @@ [package] -name = 'substrate-content-directory-module' -version = '1.0.1' +name = 'pallet-content-directory' +version = '3.0.0' authors = ['Joystream contributors'] edition = '2018' [dependencies] -hex-literal = '0.1.0' -codec = { package = 'parity-scale-codec', version = '1.0.0', default-features = false, features = ['derive'] } -rstd = { package = 'sr-std', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'} -runtime-primitives = { package = 'sr-primitives', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'} -srml-support = { package = 'srml-support', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'} -srml-support-procedural = { package = 'srml-support-procedural', git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'} -system = { package = 'srml-system', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'} -timestamp = { package = 'srml-timestamp', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'} -runtime-io = { package = 'sr-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'} -# https://users.rust-lang.org/t/failure-derive-compilation-error/39062 -quote = '<=1.0.2' - -[dependencies.serde] -features = ['derive'] -optional = true -version = '1.0.101' +sp-std = { package = 'sp-std', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'} +sp-runtime = { package = 'sp-runtime', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'} +frame-support = { package = 'frame-support', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'} +system = { package = 'frame-system', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'} +sp-arithmetic = { package = 'sp-arithmetic', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'} +codec = { package = 'parity-scale-codec', version = '1.3.1', default-features = false, features = ['derive'] } +serde = {version = '1.0.101', features = ['derive'], optional = true} [dev-dependencies] -runtime-io = { package = 'sr-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'} -primitives = { package = 'substrate-primitives', git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'} +sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'} +sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'} [features] default = ['std'] std = [ - 'serde', - 'codec/std', - 'rstd/std', - 'runtime-io/std', - 'runtime-primitives/std', - 'srml-support/std', + 'sp-std/std', + 'sp-runtime/std', + 'frame-support/std', 'system/std', - 'timestamp/std', + 'sp-arithmetic/std', + 'codec/std', + 'serde', ] diff --git a/runtime-modules/content-directory/src/class.rs b/runtime-modules/content-directory/src/class.rs index 08546beda1..3903fa25f0 100644 --- a/runtime-modules/content-directory/src/class.rs +++ b/runtime-modules/content-directory/src/class.rs @@ -161,26 +161,26 @@ impl Class { } /// Ensure `Class` `Schema` under given index exist, return corresponding `Schema` - pub fn ensure_schema_exists(&self, schema_index: SchemaId) -> Result<&Schema, &'static str> { + pub fn ensure_schema_exists(&self, schema_index: SchemaId) -> Result<&Schema, Error> { self.schemas .get(schema_index as usize) - .ok_or(ERROR_UNKNOWN_CLASS_SCHEMA_ID) + .ok_or(Error::::UnknownClassSchemaId) } /// Ensure `schema_id` is a valid index of `Class` schemas vector - pub fn ensure_schema_id_exists(&self, schema_id: SchemaId) -> dispatch::Result { + pub fn ensure_schema_id_exists(&self, schema_id: SchemaId) -> Result<(), Error> { ensure!( schema_id < self.schemas.len() as SchemaId, - ERROR_UNKNOWN_CLASS_SCHEMA_ID + Error::::UnknownClassSchemaId ); Ok(()) } /// Ensure `Schema`s limit per `Class` not reached - pub fn ensure_schemas_limit_not_reached(&self) -> dispatch::Result { + pub fn ensure_schemas_limit_not_reached(&self) -> Result<(), Error> { ensure!( (self.schemas.len() as MaxNumber) < T::MaxNumberOfSchemasPerClass::get(), - ERROR_CLASS_SCHEMAS_LIMIT_REACHED + Error::::ClassSchemasLimitReached ); Ok(()) } @@ -189,20 +189,20 @@ impl Class { pub fn ensure_properties_limit_not_reached( &self, new_properties: &[Property], - ) -> dispatch::Result { + ) -> Result<(), Error> { ensure!( T::MaxNumberOfPropertiesPerSchema::get() >= (self.properties.len() + new_properties.len()) as MaxNumber, - ERROR_SCHEMA_PROPERTIES_LIMIT_REACHED + Error::::SchemaPropertiesLimitReached ); Ok(()) } /// Ensure `Class` specific entities limit not reached - pub fn ensure_maximum_entities_count_limit_not_reached(&self) -> dispatch::Result { + pub fn ensure_maximum_entities_count_limit_not_reached(&self) -> Result<(), Error> { ensure!( self.current_number_of_entities < self.maximum_entities_count, - ERROR_MAX_NUMBER_OF_ENTITIES_PER_CLASS_LIMIT_REACHED + Error::::NumberOfEntitiesPerClassLimitReached ); Ok(()) } @@ -213,7 +213,7 @@ impl Class { &self, in_class_schema_property_id: PropertyId, entity_access_level: EntityAccessLevel, - ) -> Result, &'static str> { + ) -> Result, Error> { // Ensure property values were not locked on Class level self.ensure_property_values_unlocked()?; @@ -223,7 +223,7 @@ impl Class { .get(in_class_schema_property_id as usize) // Throw an error if a property was not found on class // by an in-class index of a property. - .ok_or(ERROR_CLASS_PROP_NOT_FOUND)?; + .ok_or(Error::::ClassPropertyNotFound)?; // Ensure Property is unlocked from Actor with given EntityAccessLevel class_property.ensure_unlocked_from(entity_access_level)?; @@ -232,12 +232,12 @@ impl Class { } /// Ensure property values were not locked on `Class` level - pub fn ensure_property_values_unlocked(&self) -> dispatch::Result { + pub fn ensure_property_values_unlocked(&self) -> Result<(), Error> { ensure!( !self .get_permissions_ref() .all_entity_property_values_locked(), - ERROR_ALL_PROP_WERE_LOCKED_ON_CLASS_LEVEL + Error::::AllPropertiesWereLockedOnClassLevel ); Ok(()) } diff --git a/runtime-modules/content-directory/src/entity.rs b/runtime-modules/content-directory/src/entity.rs index 9bf5f3d723..8cf1fae688 100644 --- a/runtime-modules/content-directory/src/entity.rs +++ b/runtime-modules/content-directory/src/entity.rs @@ -104,9 +104,9 @@ impl Entity { } /// Ensure `Schema` under given id is not added to given `Entity` yet - pub fn ensure_schema_id_is_not_added(&self, schema_id: SchemaId) -> dispatch::Result { + pub fn ensure_schema_id_is_not_added(&self, schema_id: SchemaId) -> Result<(), Error> { let schema_not_added = !self.supported_schemas.contains(&schema_id); - ensure!(schema_not_added, ERROR_SCHEMA_ALREADY_ADDED_TO_THE_ENTITY); + ensure!(schema_not_added, Error::::SchemaAlreadyAddedToTheEntity); Ok(()) } @@ -114,12 +114,12 @@ impl Entity { pub fn ensure_property_values_are_not_added( &self, property_values: &BTreeMap>, - ) -> dispatch::Result { + ) -> Result<(), Error> { ensure!( property_values .keys() .all(|key| !self.values.contains_key(key)), - ERROR_ENTITY_ALREADY_CONTAINS_GIVEN_PROPERTY_ID + Error::::EntityAlreadyContainsGivenPropertyId ); Ok(()) } @@ -128,32 +128,32 @@ impl Entity { pub fn ensure_property_value_is_vec( &self, in_class_schema_property_id: PropertyId, - ) -> Result, &'static str> { + ) -> Result, Error> { self.values .get(&in_class_schema_property_id) // Throw an error if a property was not found on entity // by an in-class index of a property. - .ok_or(ERROR_UNKNOWN_ENTITY_PROP_ID)? + .ok_or(Error::::UnknownEntityPropertyId)? .as_vec_property_value() .map(|property_value_vec| property_value_vec.to_owned()) // Ensure prop value under given class schema property id is vector - .ok_or(ERROR_PROP_VALUE_UNDER_GIVEN_INDEX_IS_NOT_A_VECTOR) + .ok_or(Error::::PropertyValueUnderGivenIndexIsNotAVector) } /// Ensure any `InputPropertyValue` from external entity does not point to the given `Entity` - pub fn ensure_rc_is_zero(&self) -> dispatch::Result { + pub fn ensure_rc_is_zero(&self) -> Result<(), Error> { ensure!( self.reference_counter.is_total_equal_to_zero(), - ERROR_ENTITY_RC_DOES_NOT_EQUAL_TO_ZERO + Error::::EntityRcDoesNotEqualToZero ); Ok(()) } /// Ensure any inbound `InputPropertyValue` with `same_owner` flag set points to the given `Entity` - pub fn ensure_inbound_same_owner_rc_is_zero(&self) -> dispatch::Result { + pub fn ensure_inbound_same_owner_rc_is_zero(&self) -> Result<(), Error> { ensure!( self.reference_counter.is_same_owner_equal_to_zero(), - ERROR_ENTITY_SAME_OWNER_RC_DOES_NOT_EQUAL_TO_ZERO + Error::::EntityInboundSameOwnerRcDoesNotEqualToZero ); Ok(()) } diff --git a/runtime-modules/content-directory/src/errors.rs b/runtime-modules/content-directory/src/errors.rs index 6545b43f8b..0ed2dcbf60 100644 --- a/runtime-modules/content-directory/src/errors.rs +++ b/runtime-modules/content-directory/src/errors.rs @@ -1,126 +1,236 @@ -// Validation errors -// -------------------------------------- - -pub const ERROR_PROPERTY_NAME_TOO_SHORT: &str = "Property name is too short"; -pub const ERROR_PROPERTY_NAME_TOO_LONG: &str = "Property name is too long"; -pub const ERROR_PROPERTY_DESCRIPTION_TOO_SHORT: &str = "Property description is too short"; -pub const ERROR_PROPERTY_DESCRIPTION_TOO_LONG: &str = "Property description is too long"; - -pub const ERROR_CLASS_NAME_TOO_SHORT: &str = "Class name is too short"; -pub const ERROR_CLASS_NAME_TOO_LONG: &str = "Class name is too long"; -pub const ERROR_CLASS_DESCRIPTION_TOO_SHORT: &str = "Class description is too long"; -pub const ERROR_CLASS_DESCRIPTION_TOO_LONG: &str = "Class description is too long"; - -pub const ERROR_CLASS_LIMIT_REACHED: &str = "Maximum number of classes limit reached"; -pub const ERROR_CLASS_SCHEMAS_LIMIT_REACHED: &str = - "Maximum number of given class schemas limit reached"; -pub const ERROR_SCHEMA_PROPERTIES_LIMIT_REACHED: &str = - "Maximum number of properties in schema limit reached"; -pub const ERROR_PER_CONTROLLER_ENTITIES_CREATION_LIMIT_EXCEEDS_OVERALL_LIMIT: &str = - "Entities creation limit per controller should be less than overall entities creation limit"; -pub const ERROR_ENTITIES_NUMBER_PER_CLASS_CONSTRAINT_VIOLATED: &str = - "Number of entities per class is to big"; -pub const ERROR_NUMBER_OF_CLASS_ENTITIES_PER_ACTOR_CONSTRAINT_VIOLATED: &str = - "Number of class entities per actor constraint violated"; -pub const ERROR_INDIVIDUAL_NUMBER_OF_CLASS_ENTITIES_PER_ACTOR_IS_TOO_BIG: &str = - "Individual number of class entities per actor is too big"; -pub const ERROR_NEW_ENTITIES_MAX_COUNT_IS_LESS_THAN_NUMBER_OF_ALREADY_CREATED: &str = - "Cannot set voucher entities count to be less than number of already created entities"; -pub const ERROR_MAX_NUMBER_OF_OPERATIONS_DURING_ATOMIC_BATCHING_LIMIT_REACHED: &str = - "Number of operations during atomic batching limit reached"; -pub const ERROR_TEXT_PROP_IS_TOO_LONG: &str = "Text property is too long"; -pub const ERROR_HASHED_TEXT_PROP_IS_TOO_LONG: &str = "Text property to be hashed is too long"; -pub const ERROR_VEC_PROP_IS_TOO_LONG: &str = "Vector property is too long"; -pub const ERROR_ENTITY_PROP_VALUE_VECTOR_IS_TOO_LONG: &str = - "Propery value vector can`t contain more values"; -pub const ERROR_ENTITY_PROP_VALUE_VECTOR_INDEX_IS_OUT_OF_RANGE: &str = - "Given property value vector index is out of range"; - -// Main logic errors -// -------------------------------------- - -pub const ERROR_CLASS_NOT_FOUND: &str = "Class was not found by id"; -pub const ERROR_UNKNOWN_CLASS_SCHEMA_ID: &str = "Unknown class schema id"; -pub const ERROR_CLASS_SCHEMA_NOT_ACTIVE: &str = "Given class schema is not active"; -pub const ERROR_CLASS_SCHEMA_REFERS_UNKNOWN_PROP_INDEX: &str = - "New class schema refers to an unknown property index"; -pub const ERROR_CLASS_SCHEMA_REFERS_UNKNOWN_CLASS: &str = - "New class schema refers to an unknown class id"; -pub const ERROR_NO_PROPS_IN_CLASS_SCHEMA: &str = - "Cannot add a class schema with an empty list of properties"; -pub const ERROR_ENTITY_NOT_FOUND: &str = "Entity was not found by id"; -pub const ERROR_SCHEMA_ALREADY_ADDED_TO_THE_ENTITY: &str = - "Cannot add a schema that is already added to this entity"; -pub const ERROR_PROP_VALUE_DONT_MATCH_TYPE: &str = - "Some of the provided property values don't match the expected property type"; -pub const ERROR_PROP_VALUE_DONT_MATCH_VEC_TYPE: &str = - "Property value don't match the expected vector property type"; -pub const ERROR_PROP_VALUE_UNDER_GIVEN_INDEX_IS_NOT_A_VECTOR: &str = - "Property value under given index is not a vector"; -pub const ERROR_PROP_VALUE_VEC_NONCES_DOES_NOT_MATCH: &str = - "Current property value vector nonce does not equal to provided one"; -pub const ERROR_PROP_NAME_NOT_UNIQUE_IN_A_CLASS: &str = - "Property name is not unique within its class"; -pub const ERROR_MISSING_REQUIRED_PROP: &str = - "Some required property was not found when adding schema support to entity"; -pub const ERROR_SCHEMA_DOES_NOT_CONTAIN_PROVIDED_PROPERTY_ID: &str = - "Schema under provided schema_id does not contain given property"; -pub const ERROR_UNKNOWN_ENTITY_PROP_ID: &str = - "Some of the provided property ids cannot be found on the current list of propery values of this entity"; -pub const ERROR_ENTITY_ALREADY_CONTAINS_GIVEN_PROPERTY_ID: &str = - "Entity already contains property under provided index"; -pub const ERROR_PROP_VALUE_TYPE_DOESNT_MATCH_INTERNAL_ENTITY_VECTOR_TYPE: &str = - "Propery value type does not match internal entity vector type"; -pub const ERROR_REFERENCED_ENTITY_DOES_NOT_MATCH_ITS_CLASS: &str - = "Provided property references entity, which class_id is not equal to class_id, declared in corresponding property type"; -pub const ERROR_ENTITY_RC_DOES_NOT_EQUAL_TO_ZERO: &str = - "Entity removal can`t be completed, as there are some property values pointing to given entity"; -pub const ERROR_ENTITY_SAME_OWNER_RC_DOES_NOT_EQUAL_TO_ZERO: &str = - "Entity removal can`t be completed, as there are some property value references with same owner flag set pointing to given entity"; -pub const ERROR_ENTITY_INBOUND_SAME_OWNER_RC_DOES_NOT_EQUAL_TO_ZERO: &str = - "Entity ownership transfer can`t be completed, as there are some property values pointing to given entity with same owner flag set"; -pub const ERROR_CLASS_PROP_NOT_FOUND: &str = "Class property under given index not found"; -pub const ERROR_CURATOR_GROUP_REMOVAL_FORBIDDEN: &str = - "Curator group can`t be removed, as it currently maintains at least one class"; -pub const ERROR_PROVIDED_ENTITY_CONTROLLER_IS_EQUAL_TO_CURRENT_ONE: &str = - "Provided entity controller is equal to the current one"; -pub const ERROR_ALL_PROVIDED_PROPERTY_VALUE_IDS_MUST_BE_REFERENCES_WITH_SAME_OWNER_FLAG_SET: &str = - "All ids of new property value references with same owner flag set should match their respective Properties defined on Class level"; -// Permission errors - -pub const ERROR_ALL_PROP_WERE_LOCKED_ON_CLASS_LEVEL: &str = - "All property values, related to a given entity were locked on class level"; -pub const ERROR_CURATOR_IS_NOT_A_MEMBER_OF_A_GIVEN_CURATOR_GROUP: &str = - "Curator under provided curator id is not a member of curaror group under given id"; -pub const ERROR_CURATOR_GROUP_DOES_NOT_EXIST: &str = "Given curator group does not exist"; -pub const ERROR_SAME_CONTROLLER_CONSTRAINT_VIOLATION: &str = - "Entity should be referenced from the entity, owned by the same controller"; -pub const ERROR_MAINTAINER_DOES_NOT_EXIST: &str = "Given maintainer does not exist"; -pub const ERROR_MAINTAINER_ALREADY_EXISTS: &str = "Given maintainer already exist"; -pub const ERROR_ACTOR_CAN_NOT_CREATE_ENTITIES: &str = - "Provided actor can`t create entities of given class"; -pub const ERROR_MAX_NUMBER_OF_ENTITIES_PER_CLASS_LIMIT_REACHED: &str = - "Maximum numbers of entities per class limit reached"; -pub const ERROR_ENTITY_CREATION_BLOCKED: &str = "Current class entities creation blocked"; -pub const ERROR_VOUCHER_LIMIT_REACHED: &str = "Entities voucher limit reached"; -pub const ERROR_LEAD_AUTH_FAILED: &str = "Lead authentication failed"; -pub const ERROR_MEMBER_AUTH_FAILED: &str = "Member authentication failed"; -pub const ERROR_CURATOR_AUTH_FAILED: &str = "Curator authentication failed"; -pub const ERROR_BAD_ORIGIN: &str = "Expected root or signed origin"; -pub const ERROR_ENTITY_REMOVAL_ACCESS_DENIED: &str = "Entity removal access denied"; -pub const ERROR_ENTITY_ADD_SCHEMA_SUPPORT_ACCESS_DENIED: &str = - "Add entity schema support access denied"; -pub const ERROR_CLASS_ACCESS_DENIED: &str = "Class access denied"; -pub const ERROR_ENTITY_ACCESS_DENIED: &str = "Entity access denied"; -pub const ERROR_ENTITY_CAN_NOT_BE_REFERENCED: &str = "Given entity can`t be referenced"; -pub const ERROR_CLASS_PROPERTY_TYPE_IS_LOCKED_FOR_GIVEN_ACTOR: &str = - "Given class property type is locked for given actor"; -pub const ERROR_NUMBER_OF_MAINTAINERS_PER_CLASS_LIMIT_REACHED: &str = - "Class maintainers limit reached"; -pub const ERROR_NUMBER_OF_CURATORS_PER_GROUP_LIMIT_REACHED: &str = - "Max number of curators per group limit reached"; -pub const ERROR_CURATOR_GROUP_IS_NOT_ACTIVE: &str = "Curator group is not active"; -pub const ERROR_ORIGIN_CANNOT_BE_MADE_INTO_RAW_ORIGIN: &str = - "Origin cannot be made into raw origin"; -pub const ERROR_PROPERTY_VALUE_SHOULD_BE_UNIQUE: &str = - "Property value should be unique across all Entities of this Class"; +use crate::*; +use frame_support::decl_error; + +decl_error! { + /// Content directory errors + pub enum Error for Module { + + /// Validation errors + /// -------------------------------------- + + + /// Property name is too short + PropertyNameTooShort, + + /// Property name is too long + PropertyNameTooLong, + + /// Property description is too short + PropertyDescriptionTooShort, + + /// Property description is too long + PropertyDescriptionTooLong, + + /// Class name is too short + ClassNameTooShort, + + /// Class name is too long + ClassNameTooLong, + + /// Class description is too short + ClassDescriptionTooShort, + + /// Class description is too long + ClassDescriptionTooLong, + + /// Maximum number of classes limit reached + ClassLimitReached, + + /// Maximum number of given class schemas limit reached + ClassSchemasLimitReached, + + /// Maximum number of properties in schema limit reached + SchemaPropertiesLimitReached, + + /// Entities creation limit per controller should be less than overall entities creation limit + PerControllerEntitiesCreationLimitExceedsOverallLimit, + + /// Number of entities per class is to big + EntitiesNumberPerClassConstraintViolated, + + /// Number of class entities per actor constraint violated + NumberOfClassEntitiesPerActorConstraintViolated, + + /// Individual number of class entities per actor is too big + IndividualNumberOfClassEntitiesPerActorIsTooBig, + + /// Number of operations during atomic batching limit reached + NumberOfOperationsDuringAtomicBatchingLimitReached, + + /// Text property is too long + TextPropertyTooLong, + + /// Text property to be hashed is too long + HashedTextPropertyTooLong, + + /// Vector property is too long + VecPropertyTooLong, + + /// Propery value vector can`t contain more values + EntityPropertyValueVectorIsTooLong, + + /// Given property value vector index is out of range + EntityPropertyValueVectorIndexIsOutOfRange, + + + /// Main logic errors + /// -------------------------------------- + + + /// Class was not found by id + ClassNotFound, + + /// Class property under given index not found + ClassPropertyNotFound, + + /// Unknown class schema id + UnknownClassSchemaId, + + /// Given class schema is not active + ClassSchemaNotActive, + + /// New class schema refers to an unknown property index + ClassSchemaRefersUnknownPropertyIndex, + + /// New class schema refers to an unknown class id + ClassSchemaRefersUnknownClass, + + /// Cannot add a class schema with an empty list of properties + NoPropertiesInClassSchema, + + /// Entity was not found by id + EntityNotFound, + + /// Cannot add a schema that is already added to this entity + SchemaAlreadyAddedToTheEntity, + + /// Some of the provided property values don't match the expected property type + PropertyValueDoNotMatchType, + + /// Property value don't match the expected vector property type + PropertyValueDoNotMatchVecType, + + /// Property value under given index is not a vector + PropertyValueUnderGivenIndexIsNotAVector, + + /// Current property value vector nonce does not equal to provided one + PropertyValueVecNoncesDoesNotMatch, + + /// Property name is not unique within its class + PropertyNameNotUniqueInAClass, + + /// Some required property was not found when adding schema support to entity + MissingRequiredProperty, + + /// Schema under provided schema_id does not contain given property + SchemaDoesNotContainProvidedPropertyId, + + /// Some of the provided property ids cannot be found on the current list of propery values of this entity + UnknownEntityPropertyId, + + /// Entity already contains property under provided index + EntityAlreadyContainsGivenPropertyId, + + /// Propery value type does not match internal entity vector type + PropertyValueTypeDoesNotMatchInternalVectorType, + + /// Provided property references entity, which class_id is not equal to class_id, declared in corresponding property type + ReferencedEntityDoesNotMatchItsClass, + + /// Entity removal can`t be completed, as there are some property values pointing to given entity + EntityRcDoesNotEqualToZero, + + /// Entity ownership transfer can`t be completed, as there are some property values pointing to given entity with same owner flag set + EntityInboundSameOwnerRcDoesNotEqualToZero, + + /// Provided entity controller is equal to the current one + ProvidedEntityControllerIsEqualToTheCurrentOne, + + /// All ids of new property value references with same owner flag set should match their respective Properties defined on Class level + AllProvidedPropertyValueIdsMustBeReferencesWithSameOwnerFlagSet, + + /// Entity was not created in batched transaction + EntityNotCreatedByOperation, + + /// Permission errors + /// -------------------------------------- + + /// Curator group can`t be removed, as it currently maintains at least one class + CuratorGroupRemovalForbidden, + + /// All property values, related to a given Entity were locked on Class level + AllPropertiesWereLockedOnClassLevel, + + /// Curator under provided curator id is not a member of curaror group under given id + CuratorIsNotAMemberOfGivenCuratorGroup, + + /// Given curator group does not exist + CuratorGroupDoesNotExist, + + /// Entity should be referenced from the entity, owned by the same controller + SameControllerConstraintViolation, + + /// Given maintainer does not exist + MaintainerDoesNotExist, + + /// Given maintainer already exist + MaintainerAlreadyExists, + + /// Provided actor can`t create entities of given class + ActorCanNotCreateEntities, + + /// Maximum numbers of entities per class limit reached + NumberOfEntitiesPerClassLimitReached, + + /// Current class entities creation blocked + EntitiesCreationBlocked, + + /// Entities voucher limit reached + VoucherLimitReached, + + /// Lead authentication failed + LeadAuthFailed, + + /// Member authentication failed + MemberAuthFailed, + + /// Curator authentication failed + CuratorAuthFailed, + + /// Expected root or signed origin + BadOrigin, + + /// Entity removal access denied + EntityRemovalAccessDenied, + + /// Add entity schema support access denied + EntityAddSchemaSupportAccessDenied, + + /// Class access denied + ClassAccessDenied, + + /// Entity access denied + EntityAccessDenied, + + /// Given entity can`t be referenced + EntityCanNotBeReferenced, + + /// Given class property type is locked for given actor + ClassPropertyTypeLockedForGivenActor, + + /// Number of maintainers per class limit reached + ClassMaintainersLimitReached, + + /// Max number of curators per group limit reached + CuratorsPerGroupLimitReached, + + /// Curator group is not active + CuratorGroupIsNotActive, + + /// Origin cannot be made into raw origin + OriginCanNotBeMadeIntoRawOrigin, + + /// Property value should be unique across all Entities of this Class + PropertyValueShouldBeUnique + } +} diff --git a/runtime-modules/content-directory/src/helpers.rs b/runtime-modules/content-directory/src/helpers.rs index 6436712bd3..8151eddbc5 100644 --- a/runtime-modules/content-directory/src/helpers.rs +++ b/runtime-modules/content-directory/src/helpers.rs @@ -57,12 +57,12 @@ impl<'a, T: Trait> InputValuesForExistingProperties<'a, T> { pub fn from( properties: &'a [Property], property_values: &'a BTreeMap>, - ) -> Result { + ) -> Result> { let mut values_for_existing_properties = InputValuesForExistingProperties::::default(); for (&property_id, property_value) in property_values { let property = properties .get(property_id as usize) - .ok_or(ERROR_CLASS_PROP_NOT_FOUND)?; + .ok_or(Error::::ClassPropertyNotFound)?; values_for_existing_properties.insert( property_id, InputValueForExistingProperty::new(property, property_value), @@ -136,13 +136,13 @@ impl<'a, T: Trait> StoredValuesForExistingProperties<'a, T> { pub fn from( properties: &'a [Property], property_values: &'a BTreeMap>, - ) -> Result { + ) -> Result> { let mut values_for_existing_properties = StoredValuesForExistingProperties::::default(); for (&property_id, property_value) in property_values { let property = properties .get(property_id as usize) - .ok_or(ERROR_CLASS_PROP_NOT_FOUND)?; + .ok_or(Error::::ClassPropertyNotFound)?; values_for_existing_properties.insert( property_id, StoredValueForExistingProperty::new(property, property_value), @@ -184,6 +184,7 @@ pub struct InputValidationLengthConstraint { } impl InputValidationLengthConstraint { + /// Create new `InputValidationLengthConstraint` constraint pub fn new(min: u16, max_min_diff: u16) -> Self { Self { min, max_min_diff } } @@ -193,16 +194,18 @@ impl InputValidationLengthConstraint { self.min + self.max_min_diff } + /// Retrieve min length value pub fn min(self) -> u16 { self.min } - pub fn ensure_valid( + /// Ensure length is valid + pub fn ensure_valid( self, len: usize, - too_short_msg: &'static str, - too_long_msg: &'static str, - ) -> dispatch::Result { + too_short_msg: Error, + too_long_msg: Error, + ) -> Result<(), Error> { let length = len as u16; if length < self.min { Err(too_short_msg) diff --git a/runtime-modules/content-directory/src/lib.rs b/runtime-modules/content-directory/src/lib.rs index 4e396b649b..9ab28a2bd9 100755 --- a/runtime-modules/content-directory/src/lib.rs +++ b/runtime-modules/content-directory/src/lib.rs @@ -27,23 +27,27 @@ use core::hash::Hash; use core::ops::AddAssign; use codec::{Codec, Decode, Encode}; -use rstd::collections::{btree_map::BTreeMap, btree_set::BTreeSet}; -use rstd::prelude::*; -use runtime_primitives::traits::{MaybeSerializeDeserialize, Member, One, SimpleArithmetic, Zero}; -use srml_support::{ - decl_event, decl_module, decl_storage, dispatch, ensure, traits::Get, Parameter, - StorageDoubleMap, +use frame_support::storage::IterableStorageMap; +use frame_support::{ + decl_event, decl_module, decl_storage, dispatch::DispatchResult, ensure, traits::Get, Parameter, }; +use sp_arithmetic::traits::{BaseArithmetic, One, Zero}; +use sp_runtime::traits::{MaybeSerializeDeserialize, Member}; +use sp_std::collections::{btree_map::BTreeMap, btree_set::BTreeSet}; +use sp_std::vec::Vec; use system::ensure_signed; #[cfg(feature = "std")] pub use serde::{Deserialize, Serialize}; +pub use errors::Error; + use core::debug_assert; /// Type, used in diffrent numeric constraints representations type MaxNumber = u32; +/// Module configuration trait for this Substrate module. pub trait Trait: system::Trait + ActorAuthenticator + Debug + Clone { /// The overarching event type. type Event: From> + Into<::Event>; @@ -51,7 +55,7 @@ pub trait Trait: system::Trait + ActorAuthenticator + Debug + Clone { /// Nonce type is used to avoid data race update conditions, when performing property value vector operations type Nonce: Parameter + Member - + SimpleArithmetic + + BaseArithmetic + Codec + Default + Copy @@ -67,7 +71,7 @@ pub trait Trait: system::Trait + ActorAuthenticator + Debug + Clone { /// Type of identifier for classes type ClassId: Parameter + Member - + SimpleArithmetic + + BaseArithmetic + Codec + Default + Copy @@ -83,7 +87,7 @@ pub trait Trait: system::Trait + ActorAuthenticator + Debug + Clone { /// Type of identifier for entities type EntityId: Parameter + Member - + SimpleArithmetic + + BaseArithmetic + Codec + Default + Copy @@ -96,8 +100,6 @@ pub trait Trait: system::Trait + ActorAuthenticator + Debug + Clone { + PartialEq + Ord; - //type SimplifiedPropertyHash: From + EncodeLike + Hash + Default + PartialEq + Eq + Ord + Codec + MaybeSerializeDeserialize; - /// Security/configuration constraints /// Type, representing min & max property name length constraints @@ -150,32 +152,30 @@ decl_storage! { trait Store for Module as ContentDirectory { /// Map, representing ClassId -> Class relation - pub ClassById get(class_by_id) config(): linked_map T::ClassId => Class; + pub ClassById get(fn class_by_id) config(): map hasher(blake2_128_concat) T::ClassId => Class; /// Map, representing EntityId -> Entity relation - pub EntityById get(entity_by_id) config(): map T::EntityId => Entity; + pub EntityById get(fn entity_by_id) config(): map hasher(blake2_128_concat) T::EntityId => Entity; /// Map, representing CuratorGroupId -> CuratorGroup relation - pub CuratorGroupById get(curator_group_by_id) config(): map T::CuratorGroupId => CuratorGroup; - - /// Used to enforce uniqueness of a property value across all Entities that have this property in a given Class. + pub CuratorGroupById get(fn curator_group_by_id) config(): map hasher(blake2_128_concat) T::CuratorGroupId => CuratorGroup; /// Mapping of class id and its property id to the respective entity id and property value hash. - pub UniquePropertyValueHashes get(unique_property_value_hashes): double_map hasher(blake2_128) (T::ClassId, PropertyId), blake2_128(T::Hash) => (); + pub UniquePropertyValueHashes get(fn unique_property_value_hashes): double_map hasher(blake2_128_concat) (T::ClassId, PropertyId), hasher(blake2_128_concat) T::Hash => (); /// Next runtime storage values used to maintain next id value, used on creation of respective curator groups, classes and entities - pub NextClassId get(next_class_id) config(): T::ClassId; + pub NextClassId get(fn next_class_id) config(): T::ClassId; - pub NextEntityId get(next_entity_id) config(): T::EntityId; + pub NextEntityId get(fn next_entity_id) config(): T::EntityId; - pub NextCuratorGroupId get(next_curator_group_id) config(): T::CuratorGroupId; + pub NextCuratorGroupId get(fn next_curator_group_id) config(): T::CuratorGroupId; // The voucher associated with entity creation for a given class and controller. // Is updated whenever an entity is created in a given class by a given controller. // Constraint is updated by Root, an initial value comes from `ClassPermissions::default_entity_creation_voucher_upper_bound`. - pub EntityCreationVouchers get(entity_creation_vouchers): - double_map hasher(blake2_128) T::ClassId, blake2_128(EntityController) => EntityCreationVoucher; + pub EntityCreationVouchers get(fn entity_creation_vouchers): + double_map hasher(blake2_128_concat) T::ClassId, hasher(blake2_128_concat) EntityController => EntityCreationVoucher; } } @@ -186,13 +186,14 @@ decl_module! { // Next set of extrinsics can only be invoked by lead. // ====== - // Initializing events + /// Initializing events fn deposit_event() = default; /// Add new curator group to runtime storage + #[weight = 10_000_000] // TODO: adjust weight pub fn add_curator_group( origin, - ) -> dispatch::Result { + ) -> DispatchResult { // Ensure given origin is lead ensure_is_lead::(origin)?; @@ -215,10 +216,11 @@ decl_module! { } /// Remove curator group under given `curator_group_id` from runtime storage + #[weight = 10_000_000] // TODO: adjust weight pub fn remove_curator_group( origin, curator_group_id: T::CuratorGroupId, - ) -> dispatch::Result { + ) -> DispatchResult { // Ensure given origin is lead ensure_is_lead::(origin)?; @@ -243,11 +245,12 @@ decl_module! { } /// Set `is_active` status for curator group under given `curator_group_id` + #[weight = 10_000_000] // TODO: adjust weight pub fn set_curator_group_status( origin, curator_group_id: T::CuratorGroupId, is_active: bool, - ) -> dispatch::Result { + ) -> DispatchResult { // Ensure given origin is lead ensure_is_lead::(origin)?; @@ -270,11 +273,12 @@ decl_module! { } /// Add curator to curator group under given `curator_group_id` + #[weight = 10_000_000] // TODO: adjust weight pub fn add_curator_to_group( origin, curator_group_id: T::CuratorGroupId, curator_id: T::CuratorId, - ) -> dispatch::Result { + ) -> DispatchResult { // Ensure given origin is lead ensure_is_lead::(origin)?; @@ -300,11 +304,12 @@ decl_module! { } /// Remove curator from a given curator group + #[weight = 10_000_000] // TODO: adjust weight pub fn remove_curator_from_group( origin, curator_group_id: T::CuratorGroupId, curator_id: T::CuratorId, - ) -> dispatch::Result { + ) -> DispatchResult { // Ensure given origin is lead ensure_is_lead::(origin)?; @@ -330,11 +335,12 @@ decl_module! { } /// Add curator group under given `curator_group_id` as `Class` maintainer + #[weight = 10_000_000] // TODO: adjust weight pub fn add_maintainer_to_class( origin, class_id: T::ClassId, curator_group_id: T::CuratorGroupId, - ) -> dispatch::Result { + ) -> DispatchResult { // Ensure given origin is lead ensure_is_lead::(origin)?; @@ -374,11 +380,12 @@ decl_module! { } /// Remove curator group under given `curator_group_id` from `Class` maintainers set + #[weight = 10_000_000] // TODO: adjust weight pub fn remove_maintainer_from_class( origin, class_id: T::ClassId, curator_group_id: T::CuratorGroupId, - ) -> dispatch::Result { + ) -> DispatchResult { // Ensure given origin is lead ensure_is_lead::(origin)?; @@ -410,12 +417,13 @@ decl_module! { } /// Updates or creates new `EntityCreationVoucher` for given `EntityController` with individual limit + #[weight = 10_000_000] // TODO: adjust weight pub fn update_entity_creation_voucher( origin, class_id: T::ClassId, controller: EntityController, maximum_entities_count: T::EntityId - ) -> dispatch::Result { + ) -> DispatchResult { // Ensure given origin is lead ensure_is_lead::(origin)?; @@ -427,7 +435,7 @@ decl_module! { Self::ensure_valid_number_of_class_entities_per_actor_constraint(maximum_entities_count)?; // Check voucher existance - let voucher_exists = >::exists(class_id, &controller); + let voucher_exists = >::contains_key(class_id, &controller); // // == MUTATION SAFE == @@ -460,6 +468,7 @@ decl_module! { } /// Create new `Class` with provided parameters + #[weight = 10_000_000] // TODO: adjust weight pub fn create_class( origin, name: Vec, @@ -467,7 +476,7 @@ decl_module! { class_permissions: ClassPermissions, maximum_entities_count: T::EntityId, default_entity_creation_voucher_upper_bound: T::EntityId - ) -> dispatch::Result { + ) -> DispatchResult { // Ensure given origin is lead ensure_is_lead::(origin)?; @@ -511,6 +520,7 @@ decl_module! { } /// Update `ClassPermissions` under specific `class_id` + #[weight = 10_000_000] // TODO: adjust weight pub fn update_class_permissions( origin, class_id: T::ClassId, @@ -518,7 +528,7 @@ decl_module! { updated_entity_creation_blocked: Option, updated_all_entity_property_values_locked: Option, updated_maintainers: Option>, - ) -> dispatch::Result { + ) -> DispatchResult { // Ensure given origin is lead ensure_is_lead::(origin)?; @@ -559,12 +569,13 @@ decl_module! { } /// Create new class schema from existing property ids and new properties + #[weight = 10_000_000] // TODO: adjust weight pub fn add_class_schema( origin, class_id: T::ClassId, existing_properties: BTreeSet, new_properties: Vec> - ) -> dispatch::Result { + ) -> DispatchResult { // Ensure given origin is lead ensure_is_lead::(origin)?; @@ -618,12 +629,13 @@ decl_module! { } /// Update `schema_status` under specific `schema_id` in `Class` + #[weight = 10_000_000] // TODO: adjust weight pub fn update_class_schema_status( origin, class_id: T::ClassId, schema_id: SchemaId, schema_status: bool - ) -> dispatch::Result { + ) -> DispatchResult { // Ensure given origin is lead ensure_is_lead::(origin)?; @@ -649,12 +661,13 @@ decl_module! { } /// Update entity permissions + #[weight = 10_000_000] // TODO: adjust weight pub fn update_entity_permissions( origin, entity_id: T::EntityId, updated_frozen: Option, updated_referenceable: Option - ) -> dispatch::Result { + ) -> DispatchResult { // Ensure given origin is lead ensure_is_lead::(origin)?; @@ -687,12 +700,13 @@ decl_module! { /// Transfer ownership to new `EntityController` for `Entity` under given `entity_id` /// `new_property_value_references_with_same_owner_flag_set` should be provided manually + #[weight = 10_000_000] // TODO: adjust weight pub fn transfer_entity_ownership( origin, entity_id: T::EntityId, new_controller: EntityController, new_property_value_references_with_same_owner_flag_set: BTreeMap> - ) -> dispatch::Result { + ) -> DispatchResult { // Ensure given origin is lead ensure_is_lead::(origin)?; @@ -717,7 +731,7 @@ decl_module! { Ok(values_for_existing_properties) => values_for_existing_properties, Err(e) => { debug_assert!(false, "Should not fail! {:?}", e); - return Err(e) + return Err(e.into()) } }; @@ -831,11 +845,12 @@ decl_module! { /// Create an entity. /// If someone is making an entity of this class for first time, /// then a voucher is also added with the class limit as the default limit value. + #[weight = 10_000_000] // TODO: adjust weight pub fn create_entity( origin, class_id: T::ClassId, actor: Actor, - ) -> dispatch::Result { + ) -> DispatchResult { let account_id = ensure_signed(origin)?; @@ -856,7 +871,7 @@ decl_module! { let entity_controller = EntityController::from_actor(&actor); // Check if entity creation voucher exists - let voucher_exists = if >::exists(class_id, &entity_controller) { + let voucher_exists = if >::contains_key(class_id, &entity_controller) { // Ensure voucher limit not reached Self::entity_creation_vouchers(class_id, &entity_controller).ensure_voucher_limit_not_reached()?; @@ -915,14 +930,17 @@ decl_module! { } /// Remove `Entity` under provided `entity_id` + #[weight = 10_000_000] // TODO: adjust weight pub fn remove_entity( origin, actor: Actor, entity_id: T::EntityId, - ) -> dispatch::Result { + ) -> DispatchResult { - // Retrieve Entity and EntityAccessLevel for the actor, attemting to perform operation - let (class, entity, access_level) = Self::ensure_class_entity_and_access_level(origin, entity_id, &actor)?; + let account_id = ensure_signed(origin)?; + + // Retrieve Class, Entity and EntityAccessLevel for the actor, attemting to perform operation + let (class, entity, access_level) = Self::ensure_class_entity_and_access_level(account_id, entity_id, &actor)?; // Ensure actor with given EntityAccessLevel can remove entity EntityPermissions::::ensure_group_can_remove_entity(access_level)?; @@ -940,7 +958,7 @@ decl_module! { Ok(values_for_existing_properties) => values_for_existing_properties.compute_unique_hashes(), Err(e) => { debug_assert!(false, "Should not fail! {:?}", e); - return Err(e) + return Err(e.into()) } }; @@ -970,16 +988,19 @@ decl_module! { } /// Add schema support to entity under given `schema_id` and provided `property_values` + #[weight = 10_000_000] // TODO: adjust weight pub fn add_schema_support_to_entity( origin, actor: Actor, entity_id: T::EntityId, schema_id: SchemaId, new_property_values: BTreeMap> - ) -> dispatch::Result { + ) -> DispatchResult { - // Retrieve Class, Entity and ensure given have access to the Entity under given entity_id - let (class, entity, _) = Self::ensure_class_entity_and_access_level(origin, entity_id, &actor)?; + let account_id = ensure_signed(origin)?; + + // Retrieve Class, Entity and EntityAccessLevel for the actor, attemting to perform operation + let (class, entity, _) = Self::ensure_class_entity_and_access_level(account_id, entity_id, &actor)?; // Ensure Class Schema under given index exists, return corresponding Schema let schema = class.ensure_schema_exists(schema_id)?.to_owned(); @@ -996,7 +1017,7 @@ decl_module! { entity.ensure_property_values_are_not_added(&new_property_values)?; // Ensure provided schema can be added to the Entity - schema.ensure_is_active()?; + schema.ensure_is_active::()?; // Ensure all provided new property values are for properties in the given schema schema.ensure_has_properties(&new_property_values)?; @@ -1067,15 +1088,18 @@ decl_module! { } /// Update `Entity` `InputPropertyValue`'s with provided ones + #[weight = 10_000_000] // TODO: adjust weight pub fn update_entity_property_values( origin, actor: Actor, entity_id: T::EntityId, new_property_values: BTreeMap> - ) -> dispatch::Result { + ) -> DispatchResult { + + let account_id = ensure_signed(origin)?; // Retrieve Class, Entity and EntityAccessLevel for the actor, attemting to perform operation - let (class, entity, access_level) = Self::ensure_class_entity_and_access_level(origin, entity_id, &actor)?; + let (class, entity, access_level) = Self::ensure_class_entity_and_access_level(account_id, entity_id, &actor)?; // Ensure property values were not locked on Class level class.ensure_property_values_unlocked()?; @@ -1163,15 +1187,18 @@ decl_module! { } /// Clear `PropertyValueVec` under given `entity_id` & `in_class_schema_property_id` + #[weight = 10_000_000] // TODO: adjust weight pub fn clear_entity_property_vector( origin, actor: Actor, entity_id: T::EntityId, in_class_schema_property_id: PropertyId - ) -> dispatch::Result { + ) -> DispatchResult { + + let account_id = ensure_signed(origin)?; // Retrieve Class, Entity and EntityAccessLevel for the actor, attemting to perform operation - let (class, entity, access_level) = Self::ensure_class_entity_and_access_level(origin, entity_id, &actor)?; + let (class, entity, access_level) = Self::ensure_class_entity_and_access_level(account_id, entity_id, &actor)?; // Ensure Property under given PropertyId is unlocked from actor with given EntityAccessLevel // Retrieve corresponding Property by value @@ -1239,7 +1266,8 @@ decl_module! { } /// Remove value at given `index_in_property_vector` - /// from `PropertyValueVec` under in_class_schema_property_id + /// from `PropertyValueVec` under in_`class_schema_property_id` + #[weight = 10_000_000] // TODO: adjust weight pub fn remove_at_entity_property_vector( origin, actor: Actor, @@ -1247,10 +1275,12 @@ decl_module! { in_class_schema_property_id: PropertyId, index_in_property_vector: VecMaxLength, nonce: T::Nonce - ) -> dispatch::Result { + ) -> DispatchResult { + + let account_id = ensure_signed(origin)?; // Retrieve Class, Entity and EntityAccessLevel for the actor, attemting to perform operation - let (class, entity, access_level) = Self::ensure_class_entity_and_access_level(origin, entity_id, &actor)?; + let (class, entity, access_level) = Self::ensure_class_entity_and_access_level(account_id, entity_id, &actor)?; // Ensure Property under given PropertyId is unlocked from actor with given EntityAccessLevel // Retrieve corresponding Property by value @@ -1341,6 +1371,7 @@ decl_module! { /// Insert `SingleInputPropertyValue` at given `index_in_property_vector` /// into `PropertyValueVec` under `in_class_schema_property_id` + #[weight = 10_000_000] // TODO: adjust weight pub fn insert_at_entity_property_vector( origin, actor: Actor, @@ -1349,10 +1380,12 @@ decl_module! { index_in_property_vector: VecMaxLength, value: InputValue, nonce: T::Nonce - ) -> dispatch::Result { + ) -> DispatchResult { + + let account_id = ensure_signed(origin)?; // Retrieve Class, Entity and EntityAccessLevel for the actor, attemting to perform operation - let (class, entity, access_level) = Self::ensure_class_entity_and_access_level(origin, entity_id, &actor)?; + let (class, entity, access_level) = Self::ensure_class_entity_and_access_level(account_id, entity_id, &actor)?; // Ensure Property under given PropertyId is unlocked from actor with given EntityAccessLevel // Retrieve corresponding Property by value @@ -1445,7 +1478,8 @@ decl_module! { Ok(()) } - pub fn transaction(origin, actor: Actor, operations: Vec>) -> dispatch::Result { + #[weight = 10_000_000] // TODO: adjust weight + pub fn transaction(origin, actor: Actor, operations: Vec>) -> DispatchResult { // Ensure maximum number of operations during atomic batching limit not reached Self::ensure_number_of_operations_during_atomic_batching_limit_not_reached(&operations)?; @@ -1458,7 +1492,7 @@ decl_module! { let mut entity_created_in_operation = BTreeMap::new(); // Create raw origin - let raw_origin = origin.into().map_err(|_| ERROR_ORIGIN_CANNOT_BE_MADE_INTO_RAW_ORIGIN)?; + let raw_origin = origin.into().map_err(|_| Error::::OriginCanNotBeMadeIntoRawOrigin)?; for (index, operation_type) in operations.into_iter().enumerate() { let origin = T::Origin::from(raw_origin.clone()); @@ -1722,7 +1756,7 @@ impl Module { class_properties: Vec>, entity_property_values: BTreeMap>, new_output_property_values: BTreeMap>, - ) -> Result>, &'static str> { + ) -> Result>, Error> { // Filter entity_property_values to get only those, which will be substituted with new_property_values let entity_property_values_to_update: BTreeMap> = entity_property_values @@ -1870,13 +1904,13 @@ impl Module { class_id: T::ClassId, property_id: PropertyId, unique_property_value_hash: &T::Hash, - ) -> Result<(), &'static str> { + ) -> Result<(), Error> { ensure!( - !>::exists( + !>::contains_key( (class_id, property_id), unique_property_value_hash ), - ERROR_PROPERTY_VALUE_SHOULD_BE_UNIQUE + Error::::PropertyValueShouldBeUnique ); Ok(()) } @@ -1885,7 +1919,7 @@ impl Module { pub fn ensure_property_value_hashes_unique_option_satisfied( class_id: T::ClassId, unique_property_value_hashes: &BTreeMap, - ) -> Result<(), &'static str> { + ) -> Result<(), Error> { for (&property_id, unique_property_value_hash) in unique_property_value_hashes { Self::ensure_property_value_hash_unique_option_satisfied( class_id, @@ -1903,7 +1937,7 @@ impl Module { in_class_schema_property_id: PropertyId, property_value_vector_updated: &StoredPropertyValue, property_value_vector: VecStoredPropertyValue, - ) -> Result<(T::Hash, T::Hash), &'static str> { + ) -> Result<(T::Hash, T::Hash), Error> { // Compute new hash from unique property value and its respective property id let new_property_value_hash = property_value_vector_updated.compute_unique_hash(in_class_schema_property_id); @@ -1927,7 +1961,7 @@ impl Module { pub fn ensure_new_property_values_respect_uniquness( class_id: T::ClassId, new_output_values_for_existing_properties: StoredValuesForExistingProperties, - ) -> Result, &'static str> { + ) -> Result, Error> { let new_unique_property_value_hashes = new_output_values_for_existing_properties.compute_unique_hashes(); @@ -1941,19 +1975,20 @@ impl Module { } /// Returns the stored `Class` if exist, error otherwise. - fn ensure_class_exists(class_id: T::ClassId) -> Result, &'static str> { - ensure!(>::exists(class_id), ERROR_CLASS_NOT_FOUND); + fn ensure_class_exists(class_id: T::ClassId) -> Result, Error> { + ensure!( + >::contains_key(class_id), + Error::::ClassNotFound + ); Ok(Self::class_by_id(class_id)) } /// Returns `Class` and `Entity` under given id, if exists, and `EntityAccessLevel` corresponding to `origin`, if permitted fn ensure_class_entity_and_access_level( - origin: T::Origin, + account_id: T::AccountId, entity_id: T::EntityId, actor: &Actor, - ) -> Result<(Class, Entity, EntityAccessLevel), &'static str> { - let account_id = ensure_signed(origin)?; - + ) -> Result<(Class, Entity, EntityAccessLevel), Error> { // Ensure Entity under given id exists, retrieve corresponding one let entity = Self::ensure_known_entity_id(entity_id)?; @@ -1974,7 +2009,7 @@ impl Module { /// Ensure `Entity` under given `entity_id` exists, retrieve corresponding `Entity` & `Class` pub fn ensure_known_entity_and_class( entity_id: T::EntityId, - ) -> Result<(Entity, Class), &'static str> { + ) -> Result<(Entity, Class), Error> { // Ensure Entity under given id exists, retrieve corresponding one let entity = Self::ensure_known_entity_id(entity_id)?; @@ -2007,15 +2042,15 @@ impl Module { .collect() } - // Ensure all ids of provided `new_property_value_references_with_same_owner_flag_set` - // corresponding to property ids of respective Class Property references with same owner flag set + /// Ensure all ids of provided `new_property_value_references_with_same_owner_flag_set` + /// corresponding to property ids of respective Class Property references with same owner flag set pub fn ensure_only_reference_ids_with_same_owner_flag_set_provided( entity_property_id_references_with_same_owner_flag_set: &BTreeSet, new_property_value_references_with_same_owner_flag_set: &BTreeMap< PropertyId, InputPropertyValue, >, - ) -> dispatch::Result { + ) -> Result<(), Error> { let new_property_value_id_references_with_same_owner_flag_set: BTreeSet = new_property_value_references_with_same_owner_flag_set .keys() @@ -2025,7 +2060,7 @@ impl Module { ensure!( new_property_value_id_references_with_same_owner_flag_set .is_subset(entity_property_id_references_with_same_owner_flag_set), - ERROR_ALL_PROVIDED_PROPERTY_VALUE_IDS_MUST_BE_REFERENCES_WITH_SAME_OWNER_FLAG_SET + Error::::AllProvidedPropertyValueIdsMustBeReferencesWithSameOwnerFlagSet ); Ok(()) } @@ -2034,7 +2069,7 @@ impl Module { fn ensure_are_valid_references_with_same_owner_flag_set( new_property_value_references_with_same_owner_flag_set: InputValuesForExistingProperties, new_controller: &EntityController, - ) -> dispatch::Result { + ) -> Result<(), Error> { for updated_value_for_existing_property in new_property_value_references_with_same_owner_flag_set.values() { @@ -2087,7 +2122,7 @@ impl Module { } } - // Update InboundReferenceCounter, based on previously calculated entities_inbound_rcs_delta, for each Entity involved + /// Update InboundReferenceCounter, based on previously calculated entities_inbound_rcs_delta, for each Entity involved pub fn update_entities_rcs( entities_inbound_rcs_delta: &Option>, ) { @@ -2128,14 +2163,17 @@ impl Module { pub fn ensure_all_required_properties_provided( class_properties: &[Property], unused_schema_property_ids: &BTreeSet, - ) -> dispatch::Result { + ) -> Result<(), Error> { for &unused_schema_property_id in unused_schema_property_ids { let class_property = &class_properties .get(unused_schema_property_id as usize) - .ok_or(ERROR_CLASS_PROP_NOT_FOUND)?; + .ok_or(Error::::ClassPropertyNotFound)?; // All required property values should be provided - ensure!(!class_property.required, ERROR_MISSING_REQUIRED_PROP); + ensure!( + !class_property.required, + Error::::MissingRequiredProperty + ); } Ok(()) } @@ -2145,7 +2183,7 @@ impl Module { pub fn ensure_property_values_are_valid( entity_controller: &EntityController, values_for_existing_properties: &InputValuesForExistingProperties, - ) -> dispatch::Result { + ) -> Result<(), Error> { for value_for_existing_property in values_for_existing_properties.values() { let (property, value) = value_for_existing_property.unzip(); @@ -2160,12 +2198,12 @@ impl Module { pub fn ensure_all_property_values_are_already_added( entity_property_values: &BTreeMap>, new_property_values: &BTreeMap>, - ) -> dispatch::Result { + ) -> Result<(), Error> { ensure!( new_property_values .keys() .all(|key| entity_property_values.contains_key(key)), - ERROR_UNKNOWN_ENTITY_PROP_ID + Error::::UnknownEntityPropertyId ); Ok(()) } @@ -2174,7 +2212,7 @@ impl Module { pub fn ensure_all_property_values_are_unlocked_from( new_values_for_existing_properties: &InputValuesForExistingProperties, access_level: EntityAccessLevel, - ) -> dispatch::Result { + ) -> Result<(), Error> { for value_for_new_property in new_values_for_existing_properties.values() { // Ensure Property is unlocked from Actor with given EntityAccessLevel value_for_new_property @@ -2269,24 +2307,30 @@ impl Module { } /// Ensure `Class` under given id exists, return corresponding one - pub fn ensure_known_class_id(class_id: T::ClassId) -> Result, &'static str> { - ensure!(>::exists(class_id), ERROR_CLASS_NOT_FOUND); + pub fn ensure_known_class_id(class_id: T::ClassId) -> Result, Error> { + ensure!( + >::contains_key(class_id), + Error::::ClassNotFound + ); Ok(Self::class_by_id(class_id)) } /// Ensure `Entity` under given id exists, return corresponding one - pub fn ensure_known_entity_id(entity_id: T::EntityId) -> Result, &'static str> { - ensure!(>::exists(entity_id), ERROR_ENTITY_NOT_FOUND); + pub fn ensure_known_entity_id(entity_id: T::EntityId) -> Result, Error> { + ensure!( + >::contains_key(entity_id), + Error::::EntityNotFound + ); Ok(Self::entity_by_id(entity_id)) } /// Ensure `CuratorGroup` under given id exists pub fn ensure_curator_group_under_given_id_exists( curator_group_id: &T::CuratorGroupId, - ) -> dispatch::Result { + ) -> Result<(), Error> { ensure!( - >::exists(curator_group_id), - ERROR_CURATOR_GROUP_DOES_NOT_EXIST + >::contains_key(curator_group_id), + Error::::CuratorGroupDoesNotExist ); Ok(()) } @@ -2294,7 +2338,7 @@ impl Module { /// Ensure `CuratorGroup` under given id exists, return corresponding one pub fn ensure_curator_group_exists( curator_group_id: &T::CuratorGroupId, - ) -> Result, &'static str> { + ) -> Result, Error> { Self::ensure_curator_group_under_given_id_exists(curator_group_id)?; Ok(Self::curator_group_by_id(curator_group_id)) } @@ -2302,10 +2346,10 @@ impl Module { /// Ensure `MaxNumberOfMaintainersPerClass` constraint satisfied pub fn ensure_maintainers_limit_not_reached( curator_groups: &BTreeSet, - ) -> dispatch::Result { + ) -> Result<(), Error> { ensure!( curator_groups.len() < T::MaxNumberOfMaintainersPerClass::get() as usize, - ERROR_NUMBER_OF_MAINTAINERS_PER_CLASS_LIMIT_REACHED + Error::::ClassMaintainersLimitReached ); Ok(()) } @@ -2313,7 +2357,7 @@ impl Module { /// Ensure all `CuratorGroup`'s under given ids exist pub fn ensure_curator_groups_exist( curator_groups: &BTreeSet, - ) -> dispatch::Result { + ) -> Result<(), Error> { for curator_group in curator_groups { // Ensure CuratorGroup under given id exists Self::ensure_curator_group_exists(curator_group)?; @@ -2324,11 +2368,11 @@ impl Module { /// Perform security checks to ensure provided `class_maintainers` are valid pub fn ensure_class_maintainers_are_valid( class_maintainers: &BTreeSet, - ) -> dispatch::Result { + ) -> Result<(), Error> { // Ensure max number of maintainers per Class constraint satisfied ensure!( class_maintainers.len() <= T::MaxNumberOfMaintainersPerClass::get() as usize, - ERROR_NUMBER_OF_MAINTAINERS_PER_CLASS_LIMIT_REACHED + Error::::ClassMaintainersLimitReached ); // Ensure all curator groups provided are already exist in runtime @@ -2340,36 +2384,36 @@ impl Module { pub fn ensure_non_empty_schema( existing_properties: &BTreeSet, new_properties: &[Property], - ) -> dispatch::Result { + ) -> Result<(), Error> { // Schema is empty if both existing_properties and new_properties are empty let non_empty_schema = !existing_properties.is_empty() || !new_properties.is_empty(); - ensure!(non_empty_schema, ERROR_NO_PROPS_IN_CLASS_SCHEMA); + ensure!(non_empty_schema, Error::::NoPropertiesInClassSchema); Ok(()) } /// Ensure `ClassNameLengthConstraint` conditions satisfied - pub fn ensure_class_name_is_valid(text: &[u8]) -> dispatch::Result { + pub fn ensure_class_name_is_valid(text: &[u8]) -> Result<(), Error> { T::ClassNameLengthConstraint::get().ensure_valid( text.len(), - ERROR_CLASS_NAME_TOO_SHORT, - ERROR_CLASS_NAME_TOO_LONG, + Error::::ClassNameTooShort, + Error::::ClassNameTooLong, ) } /// Ensure `ClassDescriptionLengthConstraint` conditions satisfied - pub fn ensure_class_description_is_valid(text: &[u8]) -> dispatch::Result { + pub fn ensure_class_description_is_valid(text: &[u8]) -> Result<(), Error> { T::ClassDescriptionLengthConstraint::get().ensure_valid( text.len(), - ERROR_CLASS_DESCRIPTION_TOO_SHORT, - ERROR_CLASS_DESCRIPTION_TOO_LONG, + Error::::ClassDescriptionTooShort, + Error::::ClassDescriptionTooLong, ) } /// Ensure `MaxNumberOfClasses` constraint satisfied - pub fn ensure_class_limit_not_reached() -> dispatch::Result { + pub fn ensure_class_limit_not_reached() -> Result<(), Error> { ensure!( - (>::enumerate().count() as MaxNumber) < T::MaxNumberOfClasses::get(), - ERROR_CLASS_LIMIT_REACHED + (>::iter().count() as MaxNumber) < T::MaxNumberOfClasses::get(), + Error::::ClassLimitReached ); Ok(()) } @@ -2377,10 +2421,10 @@ impl Module { /// Ensure `MaxNumberOfEntitiesPerClass` constraint satisfied pub fn ensure_valid_number_of_entities_per_class( maximum_entities_count: T::EntityId, - ) -> dispatch::Result { + ) -> Result<(), Error> { ensure!( maximum_entities_count <= T::MaxNumberOfEntitiesPerClass::get(), - ERROR_ENTITIES_NUMBER_PER_CLASS_CONSTRAINT_VIOLATED + Error::::EntitiesNumberPerClassConstraintViolated ); Ok(()) } @@ -2388,10 +2432,10 @@ impl Module { /// Ensure `IndividualEntitiesCreationLimit` constraint satisfied pub fn ensure_valid_number_of_class_entities_per_actor_constraint( number_of_class_entities_per_actor: T::EntityId, - ) -> dispatch::Result { + ) -> Result<(), Error> { ensure!( number_of_class_entities_per_actor <= T::IndividualEntitiesCreationLimit::get(), - ERROR_NUMBER_OF_CLASS_ENTITIES_PER_ACTOR_CONSTRAINT_VIOLATED + Error::::NumberOfClassEntitiesPerActorConstraintViolated ); Ok(()) } @@ -2400,11 +2444,11 @@ impl Module { pub fn ensure_entities_creation_limits_are_valid( maximum_entities_count: T::EntityId, default_entity_creation_voucher_upper_bound: T::EntityId, - ) -> dispatch::Result { + ) -> Result<(), Error> { // Ensure `per_controller_entities_creation_limit` does not exceed ensure!( default_entity_creation_voucher_upper_bound < maximum_entities_count, - ERROR_PER_CONTROLLER_ENTITIES_CREATION_LIMIT_EXCEEDS_OVERALL_LIMIT + Error::::PerControllerEntitiesCreationLimitExceedsOverallLimit ); // Ensure maximum_entities_count does not exceed MaxNumberOfEntitiesPerClass limit @@ -2419,16 +2463,16 @@ impl Module { /// Ensure maximum number of operations during atomic batching constraint satisfied pub fn ensure_number_of_operations_during_atomic_batching_limit_not_reached( operations: &[OperationType], - ) -> dispatch::Result { + ) -> Result<(), Error> { ensure!( operations.len() <= T::MaxNumberOfOperationsDuringAtomicBatching::get() as usize, - ERROR_MAX_NUMBER_OF_OPERATIONS_DURING_ATOMIC_BATCHING_LIMIT_REACHED + Error::::NumberOfOperationsDuringAtomicBatchingLimitReached ); Ok(()) } /// Complete all checks to ensure each `Property` is valid - pub fn ensure_all_properties_are_valid(new_properties: &[Property]) -> dispatch::Result { + pub fn ensure_all_properties_are_valid(new_properties: &[Property]) -> Result<(), Error> { for new_property in new_properties.iter() { // Ensure PropertyNameLengthConstraint satisfied new_property.ensure_name_is_valid()?; @@ -2449,7 +2493,7 @@ impl Module { pub fn ensure_all_property_names_are_unique( class_properties: &[Property], new_properties: &[Property], - ) -> dispatch::Result { + ) -> Result<(), Error> { // Used to ensure all property names are unique within class let mut unique_prop_names = BTreeSet::new(); @@ -2461,7 +2505,7 @@ impl Module { // Ensure name of a new property is unique within its class. ensure!( !unique_prop_names.contains(&new_property.name), - ERROR_PROP_NAME_NOT_UNIQUE_IN_A_CLASS + Error::::PropertyNameNotUniqueInAClass ); unique_prop_names.insert(new_property.name.to_owned()); @@ -2474,13 +2518,13 @@ impl Module { pub fn ensure_schema_properties_are_valid_indices( existing_properties: &BTreeSet, class_properties: &[Property], - ) -> dispatch::Result { + ) -> Result<(), Error> { let has_unknown_properties = existing_properties .iter() .any(|&prop_id| prop_id >= class_properties.len() as PropertyId); ensure!( !has_unknown_properties, - ERROR_CLASS_SCHEMA_REFERS_UNKNOWN_PROP_INDEX + Error::::ClassSchemaRefersUnknownPropertyIndex ); Ok(()) } diff --git a/runtime-modules/content-directory/src/mock.rs b/runtime-modules/content-directory/src/mock.rs index 05dfcc1128..24117b5eb6 100644 --- a/runtime-modules/content-directory/src/mock.rs +++ b/runtime-modules/content-directory/src/mock.rs @@ -3,14 +3,16 @@ use crate::InputValidationLengthConstraint; use crate::*; use core::iter::FromIterator; -use primitives::H256; -use runtime_primitives::{ +use frame_support::traits::{OnFinalize, OnInitialize}; +pub use frame_support::{ + assert_err, assert_ok, impl_outer_event, impl_outer_origin, parameter_types, +}; +use sp_core::H256; +use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, Perbill, }; -pub use srml_support::{assert_err, assert_ok}; -use srml_support::{impl_outer_event, impl_outer_origin, parameter_types}; use std::cell::RefCell; /// Runtime Types @@ -67,12 +69,6 @@ pub const SECOND_SCHEMA_ID: SchemaId = 1; pub const FIRST_PROPERTY_ID: SchemaId = 0; pub const SECOND_PROPERTY_ID: SchemaId = 1; -// Nonces - -// pub const ZERO_NONCE: Nonce = 0; -// pub const FIRST_NONCE: Nonce = 1; -// pub const SECOND_NONCE: Nonce = 2; - impl_outer_origin! { pub enum Origin for Runtime {} } @@ -217,9 +213,10 @@ impl Get for IndividualEntitiesCreationLimit { } impl system::Trait for Runtime { + type BaseCallFilter = (); type Origin = Origin; - type Index = u64; type Call = (); + type Index = u64; type BlockNumber = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -229,9 +226,17 @@ impl system::Trait for Runtime { type Event = TestEvent; type BlockHashCount = BlockHashCount; type MaximumBlockWeight = MaximumBlockWeight; + type DbWeight = (); + type BlockExecutionWeight = (); + type ExtrinsicBaseWeight = (); + type MaximumExtrinsicWeight = (); type MaximumBlockLength = MaximumBlockLength; type AvailableBlockRatio = AvailableBlockRatio; type Version = (); + type ModuleToIndex = (); + type AccountData = (); + type OnNewAccount = (); + type OnKilledAccount = (); } mod test_events { @@ -241,6 +246,7 @@ mod test_events { impl_outer_event! { pub enum TestEvent for Runtime { test_events, + system, } } @@ -384,7 +390,7 @@ impl ExtBuilder { .with(|v| *v.borrow_mut() = self.individual_entities_creation_limit); } - pub fn build(self, config: GenesisConfig) -> runtime_io::TestExternalities { + pub fn build(self, config: GenesisConfig) -> sp_io::TestExternalities { self.set_associated_consts(); let mut t = system::GenesisConfig::default() .build_storage::() @@ -410,9 +416,19 @@ fn default_content_directory_genesis_config() -> GenesisConfig { pub fn with_test_externalities R>(f: F) -> R { let default_genesis_config = default_content_directory_genesis_config(); + /* + Events are not emitted on block 0. + So any dispatchable calls made during genesis block formation will have no events emitted. + https://substrate.dev/recipes/2-appetizers/4-events.html + */ + let func = || { + run_to_block(1); + f() + }; + ExtBuilder::default() .build(default_genesis_config) - .execute_with(f) + .execute_with(func) } pub fn generate_text(len: usize) -> Vec { @@ -465,8 +481,8 @@ pub fn assert_event_success(tested_event: TestEvent, number_of_events_after_call } pub fn assert_failure( - call_result: Result<(), &str>, - expected_error: &str, + call_result: DispatchResult, + expected_error: Error, number_of_events_before_call: usize, ) { // Ensure call result is equal to expected error @@ -482,14 +498,11 @@ pub fn next_curator_group_id() -> CuratorGroupId { TestModule::next_curator_group_id() } -pub fn add_curator_group(lead_origin: u64) -> Result<(), &'static str> { +pub fn add_curator_group(lead_origin: u64) -> DispatchResult { TestModule::add_curator_group(Origin::signed(lead_origin)) } -pub fn remove_curator_group( - lead_origin: u64, - curator_group_id: CuratorGroupId, -) -> Result<(), &'static str> { +pub fn remove_curator_group(lead_origin: u64, curator_group_id: CuratorGroupId) -> DispatchResult { TestModule::remove_curator_group(Origin::signed(lead_origin), curator_group_id) } @@ -497,7 +510,7 @@ pub fn add_curator_to_group( lead_origin: u64, curator_group_id: CuratorGroupId, curator_id: CuratorId, -) -> Result<(), &'static str> { +) -> DispatchResult { TestModule::add_curator_to_group(Origin::signed(lead_origin), curator_group_id, curator_id) } @@ -505,7 +518,7 @@ pub fn remove_curator_from_group( lead_origin: u64, curator_group_id: CuratorGroupId, curator_id: CuratorId, -) -> Result<(), &'static str> { +) -> DispatchResult { TestModule::remove_curator_from_group(Origin::signed(lead_origin), curator_group_id, curator_id) } @@ -513,7 +526,7 @@ pub fn set_curator_group_status( lead_origin: u64, curator_group_id: CuratorGroupId, is_active: bool, -) -> Result<(), &'static str> { +) -> DispatchResult { TestModule::set_curator_group_status(Origin::signed(lead_origin), curator_group_id, is_active) } @@ -522,7 +535,7 @@ pub fn curator_group_by_id(curator_group_id: CuratorGroupId) -> CuratorGroup bool { - CuratorGroupById::::exists(curator_group_id) + CuratorGroupById::::contains_key(curator_group_id) } // Classes @@ -540,7 +553,7 @@ pub enum ClassType { CuratorGroupDoesNotExist, } -pub fn create_simple_class(lead_origin: u64, class_type: ClassType) -> Result<(), &'static str> { +pub fn create_simple_class(lead_origin: u64, class_type: ClassType) -> DispatchResult { let mut class = create_class_with_default_permissions(); match class_type { ClassType::Valid => (), @@ -613,7 +626,7 @@ pub fn add_maintainer_to_class( lead_origin: u64, class_id: ClassId, curator_group_id: CuratorGroupId, -) -> Result<(), &'static str> { +) -> DispatchResult { TestModule::add_maintainer_to_class(Origin::signed(lead_origin), class_id, curator_group_id) } @@ -621,7 +634,7 @@ pub fn remove_maintainer_from_class( lead_origin: u64, class_id: ClassId, curator_group_id: CuratorGroupId, -) -> Result<(), &'static str> { +) -> DispatchResult { TestModule::remove_maintainer_from_class( Origin::signed(lead_origin), class_id, @@ -636,7 +649,7 @@ pub fn update_class_permissions( updated_entity_creation_blocked: Option, updated_all_entity_property_values_locked: Option, updated_maintainers: Option>, -) -> Result<(), &'static str> { +) -> DispatchResult { TestModule::update_class_permissions( Origin::signed(lead_origin), class_id, @@ -652,7 +665,7 @@ pub fn add_class_schema( class_id: ClassId, existing_properties: BTreeSet, new_properties: Vec>, -) -> Result<(), &'static str> { +) -> DispatchResult { TestModule::add_class_schema( Origin::signed(lead_origin), class_id, @@ -666,7 +679,7 @@ pub fn update_class_schema_status( class_id: ClassId, schema_id: SchemaId, status: bool, -) -> Result<(), &'static str> { +) -> DispatchResult { TestModule::update_class_schema_status(Origin::signed(lead_origin), class_id, schema_id, status) } @@ -679,7 +692,7 @@ pub fn class_by_id(class_id: ClassId) -> Class { } pub fn class_exists(class_id: ClassId) -> bool { - ClassById::::exists(class_id) + ClassById::::contains_key(class_id) } // Vouchers @@ -689,7 +702,7 @@ pub fn update_entity_creation_voucher( class_id: ClassId, controller: EntityController, maximum_entities_count: EntityId, -) -> Result<(), &'static str> { +) -> DispatchResult { TestModule::update_entity_creation_voucher( Origin::signed(lead_origin), class_id, @@ -709,13 +722,13 @@ pub fn entity_creation_voucher_exists( class_id: ClassId, entity_controller: &EntityController, ) -> bool { - EntityCreationVouchers::::exists(class_id, entity_controller) + EntityCreationVouchers::::contains_key(class_id, entity_controller) } // Entities pub fn entity_exists(entity_id: EntityId) -> bool { - EntityById::::exists(entity_id) + EntityById::::contains_key(entity_id) } pub fn entity_by_id(entity_id: EntityId) -> Entity { @@ -726,19 +739,11 @@ pub fn next_entity_id() -> EntityId { TestModule::next_entity_id() } -pub fn create_entity( - origin: u64, - class_id: ClassId, - actor: Actor, -) -> Result<(), &'static str> { +pub fn create_entity(origin: u64, class_id: ClassId, actor: Actor) -> DispatchResult { TestModule::create_entity(Origin::signed(origin), class_id, actor) } -pub fn remove_entity( - origin: u64, - actor: Actor, - entity_id: EntityId, -) -> Result<(), &'static str> { +pub fn remove_entity(origin: u64, actor: Actor, entity_id: EntityId) -> DispatchResult { TestModule::remove_entity(Origin::signed(origin), actor, entity_id) } @@ -747,7 +752,7 @@ pub fn update_entity_permissions( entity_id: EntityId, updated_frozen: Option, updated_referenceable: Option, -) -> Result<(), &'static str> { +) -> DispatchResult { TestModule::update_entity_permissions( Origin::signed(lead_origin), entity_id, @@ -762,7 +767,7 @@ pub fn add_schema_support_to_entity( entity_id: EntityId, schema_id: SchemaId, new_property_values: BTreeMap>, -) -> Result<(), &'static str> { +) -> DispatchResult { TestModule::add_schema_support_to_entity( Origin::signed(origin), actor, @@ -777,7 +782,7 @@ pub fn update_entity_property_values( actor: Actor, entity_id: EntityId, new_property_values: BTreeMap>, -) -> Result<(), &'static str> { +) -> DispatchResult { TestModule::update_entity_property_values( Origin::signed(origin), actor, @@ -791,7 +796,7 @@ pub fn clear_entity_property_vector( actor: Actor, entity_id: EntityId, in_class_schema_property_id: PropertyId, -) -> Result<(), &'static str> { +) -> DispatchResult { TestModule::clear_entity_property_vector( Origin::signed(origin), actor, @@ -808,7 +813,7 @@ pub fn insert_at_entity_property_vector( index_in_property_vector: VecMaxLength, property_value: InputValue, nonce: Nonce, -) -> Result<(), &'static str> { +) -> DispatchResult { TestModule::insert_at_entity_property_vector( Origin::signed(origin), actor, @@ -827,7 +832,7 @@ pub fn remove_at_entity_property_vector( in_class_schema_property_id: PropertyId, index_in_property_vector: VecMaxLength, nonce: Nonce, -) -> Result<(), &'static str> { +) -> DispatchResult { TestModule::remove_at_entity_property_vector( Origin::signed(origin), actor, @@ -846,7 +851,7 @@ pub fn transfer_entity_ownership( PropertyId, InputPropertyValue, >, -) -> Result<(), &'static str> { +) -> DispatchResult { TestModule::transfer_entity_ownership( Origin::signed(origin), entity_id, @@ -861,7 +866,7 @@ pub fn transaction( origin: u64, actor: Actor, operations: Vec>, -) -> Result<(), &'static str> { +) -> DispatchResult { TestModule::transaction(Origin::signed(origin), actor, operations) } @@ -1041,3 +1046,15 @@ impl PropertyLockingPolicy { // Assign back to type variables so we can make dispatched calls of these modules later. pub type System = system::Module; pub type TestModule = Module; + +// Recommendation from Parity on testing on_finalize +// https://substrate.dev/docs/en/next/development/module/tests +pub fn run_to_block(n: u64) { + while System::block_number() < n { + >::on_finalize(System::block_number()); + >::on_finalize(System::block_number()); + System::set_block_number(System::block_number() + 1); + >::on_initialize(System::block_number()); + >::on_initialize(System::block_number()); + } +} diff --git a/runtime-modules/content-directory/src/operations.rs b/runtime-modules/content-directory/src/operations.rs index af53141d56..e074da2161 100644 --- a/runtime-modules/content-directory/src/operations.rs +++ b/runtime-modules/content-directory/src/operations.rs @@ -1,8 +1,9 @@ -use crate::{InputPropertyValue, InputValue, PropertyId, SchemaId, Trait, VecInputValue}; +use crate::{Error, InputPropertyValue, InputValue, PropertyId, SchemaId, Trait, VecInputValue}; use codec::{Decode, Encode}; -use rstd::collections::btree_map::BTreeMap; -use rstd::prelude::*; +use sp_std::collections::btree_map::BTreeMap; +use sp_std::prelude::*; +/// Parametrized entity property value #[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)] pub enum ParametrizedPropertyValue { /// Same fields as normal InputPropertyValue @@ -15,12 +16,14 @@ pub enum ParametrizedPropertyValue { InternalEntityVec(Vec>), } +/// Parametrized entity #[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)] pub enum ParameterizedEntity { InternalEntityJustAdded(u32), ExistingEntity(T::EntityId), } +/// Parametrized class property value #[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)] pub struct ParametrizedClassPropertyValue { /// Index is into properties vector of class. @@ -30,24 +33,34 @@ pub struct ParametrizedClassPropertyValue { pub value: ParametrizedPropertyValue, } +/// Operation, that represents `Entity` creation #[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)] pub struct CreateEntityOperation { + /// Class of an Entity pub class_id: T::ClassId, } +/// Operation, that represents property values update #[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)] pub struct UpdatePropertyValuesOperation { + /// Entity id to perfrom operation pub entity_id: ParameterizedEntity, + /// Property values, that should be updated pub new_parametrized_property_values: Vec>, } +/// Operation, that represents adding `Entity` `Schema` support #[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)] pub struct AddSchemaSupportToEntityOperation { + /// Entity id to perfrom operation pub entity_id: ParameterizedEntity, + /// Schema id defined on `Class` level to be added to the `Entity` pub schema_id: SchemaId, + /// Property values, that should be added for the underlying schema_id pub parametrized_property_values: Vec>, } +/// The type of operation performed #[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)] pub enum OperationType { CreateEntity(CreateEntityOperation), @@ -55,25 +68,27 @@ pub enum OperationType { AddSchemaSupportToEntity(AddSchemaSupportToEntityOperation), } +/// Retrieve entity_id of parametrized `Entity` pub fn parametrized_entity_to_entity_id( created_entities: &BTreeMap, entity: ParameterizedEntity, -) -> Result { +) -> Result> { match entity { ParameterizedEntity::ExistingEntity(entity_id) => Ok(entity_id), ParameterizedEntity::InternalEntityJustAdded(op_index_u32) => { let op_index = op_index_u32 as usize; Ok(*created_entities .get(&op_index) - .ok_or("EntityNotCreatedByOperation")?) + .ok_or(Error::::EntityNotCreatedByOperation)?) } } } +/// Convert parametrized property values into property values pub fn parametrized_property_values_to_property_values( created_entities: &BTreeMap, parametrized_property_values: Vec>, -) -> Result>, &'static str> { +) -> Result>, Error> { let mut class_property_values = BTreeMap::new(); for parametrized_class_property_value in parametrized_property_values.into_iter() { @@ -86,7 +101,7 @@ pub fn parametrized_property_values_to_property_values( let op_index = entity_created_in_operation_index as usize; let entity_id = created_entities .get(&op_index) - .ok_or("EntityNotCreatedByOperation")?; + .ok_or(Error::::EntityNotCreatedByOperation)?; InputPropertyValue::Single(InputValue::Reference(*entity_id)) } ParametrizedPropertyValue::InternalEntityVec(parametrized_entities) => { @@ -101,7 +116,7 @@ pub fn parametrized_property_values_to_property_values( let op_index = entity_created_in_operation_index as usize; let entity_id = created_entities .get(&op_index) - .ok_or("EntityNotCreatedByOperation")?; + .ok_or(Error::::EntityNotCreatedByOperation)?; entities.push(*entity_id); } } diff --git a/runtime-modules/content-directory/src/permissions.rs b/runtime-modules/content-directory/src/permissions.rs index 5acd758df6..fa5416dddd 100644 --- a/runtime-modules/content-directory/src/permissions.rs +++ b/runtime-modules/content-directory/src/permissions.rs @@ -12,18 +12,18 @@ pub use crate::errors::*; use crate::*; pub use codec::{Codec, Decode, Encode}; use core::fmt::Debug; -use runtime_primitives::traits::{MaybeSerializeDeserialize, Member, SimpleArithmetic}; - +use frame_support::{ensure, Parameter}; #[cfg(feature = "std")] pub use serde::{Deserialize, Serialize}; -use srml_support::{dispatch, ensure, Parameter}; +use sp_arithmetic::traits::BaseArithmetic; +use sp_runtime::traits::{MaybeSerializeDeserialize, Member}; /// Model of authentication manager. pub trait ActorAuthenticator: system::Trait + Debug { /// Curator identifier type CuratorId: Parameter + Member - + SimpleArithmetic + + BaseArithmetic + Codec + Default + Copy @@ -36,7 +36,7 @@ pub trait ActorAuthenticator: system::Trait + Debug { /// Member identifier type MemberId: Parameter + Member - + SimpleArithmetic + + BaseArithmetic + Codec + Default + Copy @@ -49,7 +49,7 @@ pub trait ActorAuthenticator: system::Trait + Debug { /// Curator group identifier type CuratorGroupId: Parameter + Member - + SimpleArithmetic + + BaseArithmetic + Codec + One + Default @@ -71,41 +71,39 @@ pub trait ActorAuthenticator: system::Trait + Debug { } /// Ensure curator authorization performed succesfully -pub fn ensure_curator_auth_success( +pub fn ensure_curator_auth_success( curator_id: &T::CuratorId, account_id: &T::AccountId, -) -> dispatch::Result { +) -> Result<(), Error> { ensure!( T::is_curator(curator_id, account_id), - ERROR_CURATOR_AUTH_FAILED + Error::::CuratorAuthFailed ); Ok(()) } /// Ensure member authorization performed succesfully -pub fn ensure_member_auth_success( +pub fn ensure_member_auth_success( member_id: &T::MemberId, account_id: &T::AccountId, -) -> dispatch::Result { +) -> Result<(), Error> { ensure!( T::is_member(member_id, account_id), - ERROR_MEMBER_AUTH_FAILED + Error::::MemberAuthFailed ); Ok(()) } /// Ensure lead authorization performed succesfully -pub fn ensure_lead_auth_success( - account_id: &T::AccountId, -) -> dispatch::Result { - ensure!(T::is_lead(account_id), ERROR_LEAD_AUTH_FAILED); +pub fn ensure_lead_auth_success(account_id: &T::AccountId) -> Result<(), Error> { + ensure!(T::is_lead(account_id), Error::::LeadAuthFailed); Ok(()) } /// Ensure given `Origin` is lead -pub fn ensure_is_lead(origin: T::Origin) -> dispatch::Result { +pub fn ensure_is_lead(origin: T::Origin) -> DispatchResult { let account_id = ensure_signed(origin)?; - ensure_lead_auth_success::(&account_id) + Ok(ensure_lead_auth_success::(&account_id)?) } /// Enum, representing all possible `Actor`s diff --git a/runtime-modules/content-directory/src/permissions/class.rs b/runtime-modules/content-directory/src/permissions/class.rs index 5d90bb6ff9..9685156d32 100644 --- a/runtime-modules/content-directory/src/permissions/class.rs +++ b/runtime-modules/content-directory/src/permissions/class.rs @@ -88,7 +88,7 @@ impl ClassPermissions { &self, account_id: &T::AccountId, actor: &Actor, - ) -> dispatch::Result { + ) -> Result<(), Error> { let can_create = match &actor { Actor::Lead => { // Ensure lead authorization performed succesfully @@ -113,13 +113,16 @@ impl ClassPermissions { } _ => false, }; - ensure!(can_create, ERROR_ACTOR_CAN_NOT_CREATE_ENTITIES); + ensure!(can_create, Error::::ActorCanNotCreateEntities); Ok(()) } /// Ensure entities creation is not blocked on `Class` level - pub fn ensure_entity_creation_not_blocked(&self) -> dispatch::Result { - ensure!(!self.entity_creation_blocked, ERROR_ENTITY_CREATION_BLOCKED); + pub fn ensure_entity_creation_not_blocked(&self) -> Result<(), Error> { + ensure!( + !self.entity_creation_blocked, + Error::::EntitiesCreationBlocked + ); Ok(()) } @@ -127,10 +130,10 @@ impl ClassPermissions { pub fn ensure_maintainer_exists( &self, curator_group_id: &T::CuratorGroupId, - ) -> dispatch::Result { + ) -> Result<(), Error> { ensure!( self.maintainers.contains(curator_group_id), - ERROR_MAINTAINER_DOES_NOT_EXIST + Error::::MaintainerDoesNotExist ); Ok(()) } @@ -139,10 +142,10 @@ impl ClassPermissions { pub fn ensure_maintainer_does_not_exist( &self, curator_group_id: &T::CuratorGroupId, - ) -> dispatch::Result { + ) -> Result<(), Error> { ensure!( !self.maintainers.contains(curator_group_id), - ERROR_MAINTAINER_ALREADY_EXISTS + Error::::MaintainerAlreadyExists ); Ok(()) } diff --git a/runtime-modules/content-directory/src/permissions/curator_group.rs b/runtime-modules/content-directory/src/permissions/curator_group.rs index dd520333ee..f2e9e997f0 100644 --- a/runtime-modules/content-directory/src/permissions/curator_group.rs +++ b/runtime-modules/content-directory/src/permissions/curator_group.rs @@ -62,28 +62,31 @@ impl CuratorGroup { } /// Ensure curator group does not maintain any `Class` - pub fn ensure_curator_group_maintains_no_classes(&self) -> dispatch::Result { + pub fn ensure_curator_group_maintains_no_classes(&self) -> Result<(), Error> { ensure!( self.number_of_classes_maintained == 0, - ERROR_CURATOR_GROUP_REMOVAL_FORBIDDEN + Error::::CuratorGroupRemovalForbidden ); Ok(()) } /// Ensure `MaxNumberOfCuratorsPerGroup` constraint satisfied - pub fn ensure_max_number_of_curators_limit_not_reached(&self) -> dispatch::Result { + pub fn ensure_max_number_of_curators_limit_not_reached(&self) -> Result<(), Error> { ensure!( self.curators.len() < T::MaxNumberOfCuratorsPerGroup::get() as usize, - ERROR_NUMBER_OF_CURATORS_PER_GROUP_LIMIT_REACHED + Error::::CuratorsPerGroupLimitReached ); Ok(()) } /// Ensure curator under given `curator_id` exists in `CuratorGroup` - pub fn ensure_curator_in_group_exists(&self, curator_id: &T::CuratorId) -> dispatch::Result { + pub fn ensure_curator_in_group_exists( + &self, + curator_id: &T::CuratorId, + ) -> Result<(), Error> { ensure!( self.get_curators().contains(curator_id), - ERROR_CURATOR_IS_NOT_A_MEMBER_OF_A_GIVEN_CURATOR_GROUP + Error::::CuratorIsNotAMemberOfGivenCuratorGroup ); Ok(()) } @@ -93,7 +96,7 @@ impl CuratorGroup { curator_id: &T::CuratorId, curator_group_id: &T::CuratorGroupId, account_id: &T::AccountId, - ) -> dispatch::Result { + ) -> Result<(), Error> { // Ensure curator authorization performed succesfully ensure_curator_auth_success::(curator_id, account_id)?; @@ -101,7 +104,10 @@ impl CuratorGroup { let curator_group = Module::::curator_group_by_id(curator_group_id); // Ensure curator group is active - ensure!(curator_group.is_active(), ERROR_CURATOR_GROUP_IS_NOT_ACTIVE); + ensure!( + curator_group.is_active(), + Error::::CuratorGroupIsNotActive + ); // Ensure curator under given curator_id exists in CuratorGroup Self::ensure_curator_in_group_exists(&curator_group, curator_id)?; diff --git a/runtime-modules/content-directory/src/permissions/entity.rs b/runtime-modules/content-directory/src/permissions/entity.rs index 5657798d3a..a0eb16c638 100644 --- a/runtime-modules/content-directory/src/permissions/entity.rs +++ b/runtime-modules/content-directory/src/permissions/entity.rs @@ -93,11 +93,11 @@ impl EntityPermissions { } /// Ensure actor with given `EntityAccessLevel` can remove entity - pub fn ensure_group_can_remove_entity(access_level: EntityAccessLevel) -> dispatch::Result { + pub fn ensure_group_can_remove_entity(access_level: EntityAccessLevel) -> Result<(), Error> { match access_level { EntityAccessLevel::EntityController => Ok(()), EntityAccessLevel::EntityControllerAndMaintainer => Ok(()), - _ => Err(ERROR_ENTITY_REMOVAL_ACCESS_DENIED), + _ => Err(Error::::EntityRemovalAccessDenied), } } @@ -105,10 +105,10 @@ impl EntityPermissions { pub fn ensure_controllers_are_not_equal( &self, new_entity_controller: &EntityController, - ) -> dispatch::Result { + ) -> Result<(), Error> { ensure!( !self.controller_is_equal_to(new_entity_controller), - ERROR_PROVIDED_ENTITY_CONTROLLER_IS_EQUAL_TO_CURRENT_ONE + Error::::ProvidedEntityControllerIsEqualToTheCurrentOne ); Ok(()) } @@ -135,7 +135,7 @@ impl EntityAccessLevel { entity_permissions: &EntityPermissions, class_permissions: &ClassPermissions, actor: &Actor, - ) -> Result { + ) -> Result> { let controller = EntityController::::from_actor(actor); match actor { Actor::Lead if entity_permissions.controller_is_equal_to(&controller) => { @@ -161,10 +161,10 @@ impl EntityAccessLevel { (true, true) => Ok(Self::EntityControllerAndMaintainer), (false, true) => Ok(Self::EntityMaintainer), // Curator cannot be controller, but not maintainer simultaneously - _ => Err(ERROR_ENTITY_ACCESS_DENIED), + _ => Err(Error::::EntityAccessDenied), } } - _ => Err(ERROR_ENTITY_ACCESS_DENIED), + _ => Err(Error::::EntityAccessDenied), } } } diff --git a/runtime-modules/content-directory/src/permissions/entity_creation_voucher.rs b/runtime-modules/content-directory/src/permissions/entity_creation_voucher.rs index 24d687e2ba..9430228978 100644 --- a/runtime-modules/content-directory/src/permissions/entity_creation_voucher.rs +++ b/runtime-modules/content-directory/src/permissions/entity_creation_voucher.rs @@ -48,21 +48,9 @@ impl EntityCreationVoucher { self.entities_created < self.maximum_entities_count } - /// Ensure new voucher`s max entities count is less than number of already created entities in this `EntityCreationVoucher` - pub fn ensure_new_max_entities_count_is_valid( - self, - maximum_entities_count: T::EntityId, - ) -> dispatch::Result { - ensure!( - maximum_entities_count >= self.entities_created, - ERROR_NEW_ENTITIES_MAX_COUNT_IS_LESS_THAN_NUMBER_OF_ALREADY_CREATED - ); - Ok(()) - } - /// Ensure voucher limit not reached - pub fn ensure_voucher_limit_not_reached(&self) -> dispatch::Result { - ensure!(self.limit_not_reached(), ERROR_VOUCHER_LIMIT_REACHED); + pub fn ensure_voucher_limit_not_reached(&self) -> Result<(), Error> { + ensure!(self.limit_not_reached(), Error::::VoucherLimitReached); Ok(()) } } diff --git a/runtime-modules/content-directory/src/schema.rs b/runtime-modules/content-directory/src/schema.rs index c0e3bfac88..2c9b814cc9 100644 --- a/runtime-modules/content-directory/src/schema.rs +++ b/runtime-modules/content-directory/src/schema.rs @@ -34,7 +34,9 @@ pub type SameController = bool; #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Encode, Default, Decode, Clone, Copy, PartialEq, Eq, Debug)] pub struct PropertyLockingPolicy { + /// If property is locked from maintainer pub is_locked_from_maintainer: bool, + /// If property is locked from controller pub is_locked_from_controller: bool, } @@ -81,6 +83,7 @@ impl Default for VecPropertyType { } impl VecPropertyType { + /// Create new `VecPropertyType` from provided `type` and `max_length` pub fn new(vec_type: Type, max_length: VecMaxLength) -> Self { Self { vec_type, @@ -89,31 +92,31 @@ impl VecPropertyType { } /// Ensure `Type` specific `TextMaxLengthConstraint` & `VecMaxLengthConstraint` satisfied - fn ensure_property_type_size_is_valid(&self) -> dispatch::Result { + fn ensure_property_type_size_is_valid(&self) -> Result<(), Error> { if let Type::Text(text_max_len) = self.vec_type { ensure!( text_max_len <= T::TextMaxLengthConstraint::get(), - ERROR_TEXT_PROP_IS_TOO_LONG + Error::::TextPropertyTooLong ); } if let Type::Hash(hash_text_max_len) = self.vec_type { ensure!( hash_text_max_len <= T::HashedTextMaxLengthConstraint::get(), - ERROR_HASHED_TEXT_PROP_IS_TOO_LONG + Error::::HashedTextPropertyTooLong ); } ensure!( self.max_length <= T::VecMaxLengthConstraint::get(), - ERROR_VEC_PROP_IS_TOO_LONG + Error::::VecPropertyTooLong ); Ok(()) } - pub fn get_vec_type(&self) -> &Type { + fn get_vec_type(&self) -> &Type { &self.vec_type } - pub fn get_max_len(&self) -> VecMaxLength { + fn get_max_len(&self) -> VecMaxLength { self.max_length } } @@ -131,18 +134,18 @@ impl Default for SingleValuePropertyType { impl SingleValuePropertyType { /// Ensure `Type` specific `TextMaxLengthConstraint` or `HashedTextMaxLengthConstraint` satisfied - fn ensure_property_type_size_is_valid(&self) -> dispatch::Result { + fn ensure_property_type_size_is_valid(&self) -> Result<(), Error> { if let Type::Text(text_max_len) = self.0 { ensure!( text_max_len <= T::TextMaxLengthConstraint::get(), - ERROR_TEXT_PROP_IS_TOO_LONG + Error::::TextPropertyTooLong ); } if let Type::Hash(hashed_text_max_len) = self.0 { ensure!( hashed_text_max_len <= T::HashedTextMaxLengthConstraint::get(), - ERROR_HASHED_TEXT_PROP_IS_TOO_LONG + Error::::HashedTextPropertyTooLong ); } @@ -173,7 +176,7 @@ impl Default for PropertyType { } impl PropertyType { - pub fn as_single_value_type(&self) -> Option<&Type> { + fn as_single_value_type(&self) -> Option<&Type> { if let PropertyType::Single(single_value_property_type) = self { Some(single_value_property_type) } else { @@ -181,7 +184,7 @@ impl PropertyType { } } - pub fn as_vec_type(&self) -> Option<&VecPropertyType> { + fn as_vec_type(&self) -> Option<&VecPropertyType> { if let PropertyType::Vector(single_value_property_type) = self { Some(single_value_property_type) } else { @@ -189,7 +192,7 @@ impl PropertyType { } } - pub fn get_inner_type(&self) -> &Type { + fn get_inner_type(&self) -> &Type { match self { PropertyType::Single(single_property_type) => single_property_type, PropertyType::Vector(vec_property_type) => vec_property_type.get_vec_type(), @@ -243,8 +246,8 @@ impl Schema { } /// Ensure schema in `active` status - pub fn ensure_is_active(&self) -> dispatch::Result { - ensure!(self.is_active, ERROR_CLASS_SCHEMA_NOT_ACTIVE); + pub fn ensure_is_active(&self) -> Result<(), Error> { + ensure!(self.is_active, Error::::ClassSchemaNotActive); Ok(()) } @@ -257,13 +260,13 @@ impl Schema { pub fn ensure_has_properties( &self, property_values: &BTreeMap>, - ) -> dispatch::Result { + ) -> Result<(), Error> { let property_value_indices: BTreeSet = property_values.keys().cloned().collect(); ensure!( property_value_indices.is_subset(&self.properties), - ERROR_SCHEMA_DOES_NOT_CONTAIN_PROVIDED_PROPERTY_ID + Error::::SchemaDoesNotContainProvidedPropertyId ); Ok(()) @@ -284,13 +287,17 @@ impl Schema { #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)] pub struct Property { + /// The type of `Property` pub property_type: PropertyType, /// If property value can be skipped, when adding entity schema support pub required: bool, /// Used to enforce uniquness of a property across all entities that have this property pub unique: bool, + /// Property name pub name: Vec, + /// Property description pub description: Vec, + /// Locking policy, representing `Property` locking status for both controller and maintainer pub locking_policy: PropertyLockingPolicy, } @@ -322,10 +329,10 @@ impl Property { } /// Ensure `Property` is unlocked from `Actor` with given `EntityAccessLevel` - pub fn ensure_unlocked_from(&self, access_level: EntityAccessLevel) -> dispatch::Result { + pub fn ensure_unlocked_from(&self, access_level: EntityAccessLevel) -> Result<(), Error> { ensure!( !self.is_locked_from(access_level), - ERROR_CLASS_PROPERTY_TYPE_IS_LOCKED_FOR_GIVEN_ACTOR + Error::::ClassPropertyTypeLockedForGivenActor ); Ok(()) } @@ -336,7 +343,7 @@ impl Property { &self, value: &InputPropertyValue, current_entity_controller: &EntityController, - ) -> dispatch::Result { + ) -> Result<(), Error> { // Ensure provided InputPropertyValue matches its Type self.ensure_property_value_matches_its_type(value)?; @@ -351,6 +358,18 @@ impl Property { Ok(()) } + /// Ensure property vector length after value inserted is valid + fn validate_property_vector_length_after_value_insert( + vec: &[V], + max_len: VecMaxLength, + ) -> Result<(), Error> { + ensure!( + vec.len() < max_len as usize, + Error::::EntityPropertyValueVectorIsTooLong + ); + Ok(()) + } + /// Ensure `SingleInputPropertyValue` type is equal to the `VecInputPropertyValue` type /// and check all constraints pub fn ensure_property_value_can_be_inserted_at_property_vector( @@ -359,26 +378,14 @@ impl Property { vec_value: &VecStoredPropertyValue, index_in_property_vec: VecMaxLength, current_entity_controller: &EntityController, - ) -> dispatch::Result { + ) -> Result<(), Error> { // Ensure, provided index_in_property_vec is valid index of VecInputValue vec_value.ensure_index_in_property_vector_is_valid(index_in_property_vec)?; - /// Ensure property vector length after value inserted is valid - fn validate_property_vector_length_after_value_insert( - vec: &[T], - max_len: VecMaxLength, - ) -> dispatch::Result { - ensure!( - vec.len() < max_len as usize, - ERROR_ENTITY_PROP_VALUE_VECTOR_IS_TOO_LONG - ); - Ok(()) - } - let property_type_vec = self .property_type .as_vec_type() - .ok_or(ERROR_PROP_VALUE_TYPE_DOESNT_MATCH_INTERNAL_ENTITY_VECTOR_TYPE)?; + .ok_or(Error::::PropertyValueTypeDoesNotMatchInternalVectorType)?; let max_vec_len = property_type_vec.get_max_len(); @@ -389,29 +396,29 @@ impl Property { ) { // Single values (InputValue::Bool(_), VecStoredValue::Bool(vec), Type::Bool) => { - validate_property_vector_length_after_value_insert(vec, max_vec_len) + Self::validate_property_vector_length_after_value_insert(vec, max_vec_len) } (InputValue::Uint16(_), VecStoredValue::Uint16(vec), Type::Uint16) => { - validate_property_vector_length_after_value_insert(vec, max_vec_len) + Self::validate_property_vector_length_after_value_insert(vec, max_vec_len) } (InputValue::Uint32(_), VecStoredValue::Uint32(vec), Type::Uint32) => { - validate_property_vector_length_after_value_insert(vec, max_vec_len) + Self::validate_property_vector_length_after_value_insert(vec, max_vec_len) } (InputValue::Uint64(_), VecStoredValue::Uint64(vec), Type::Uint64) => { - validate_property_vector_length_after_value_insert(vec, max_vec_len) + Self::validate_property_vector_length_after_value_insert(vec, max_vec_len) } (InputValue::Int16(_), VecStoredValue::Int16(vec), Type::Int16) => { - validate_property_vector_length_after_value_insert(vec, max_vec_len) + Self::validate_property_vector_length_after_value_insert(vec, max_vec_len) } (InputValue::Int32(_), VecStoredValue::Int32(vec), Type::Int32) => { - validate_property_vector_length_after_value_insert(vec, max_vec_len) + Self::validate_property_vector_length_after_value_insert(vec, max_vec_len) } (InputValue::Int64(_), VecStoredValue::Int64(vec), Type::Int64) => { - validate_property_vector_length_after_value_insert(vec, max_vec_len) + Self::validate_property_vector_length_after_value_insert(vec, max_vec_len) } (InputValue::Text(text_item), VecStoredValue::Text(vec), Type::Text(text_max_len)) => { Self::validate_max_len_of_text(text_item, *text_max_len)?; - validate_property_vector_length_after_value_insert(vec, max_vec_len) + Self::validate_property_vector_length_after_value_insert(vec, max_vec_len) } ( InputValue::TextToHash(text_item), @@ -421,7 +428,7 @@ impl Property { if let Some(text_max_len) = text_max_len { Self::validate_max_len_of_text_to_be_hashed(text_item, *text_max_len)?; } - validate_property_vector_length_after_value_insert(vec, max_vec_len) + Self::validate_property_vector_length_after_value_insert(vec, max_vec_len) } ( InputValue::Reference(entity_id), @@ -438,9 +445,9 @@ impl Property { *same_controller_status, current_entity_controller, )?; - validate_property_vector_length_after_value_insert(vec, max_vec_len) + Self::validate_property_vector_length_after_value_insert(vec, max_vec_len) } - _ => Err(ERROR_PROP_VALUE_TYPE_DOESNT_MATCH_INTERNAL_ENTITY_VECTOR_TYPE), + _ => Err(Error::::PropertyValueTypeDoesNotMatchInternalVectorType), } } @@ -448,7 +455,7 @@ impl Property { pub fn validate_max_len_if_text_property( &self, value: &InputPropertyValue, - ) -> dispatch::Result { + ) -> Result<(), Error> { let single_value = value.as_single_value(); match (single_value, &self.property_type.as_single_value_type()) { @@ -466,27 +473,30 @@ impl Property { } } - pub fn validate_max_len_of_text(text: &[u8], text_max_len: TextMaxLength) -> dispatch::Result { + fn validate_max_len_of_text(text: &[u8], text_max_len: TextMaxLength) -> Result<(), Error> { ensure!( text.len() <= text_max_len as usize, - ERROR_TEXT_PROP_IS_TOO_LONG + Error::::TextPropertyTooLong ); Ok(()) } - pub fn validate_max_len_of_text_to_be_hashed( + fn validate_max_len_of_text_to_be_hashed( text_to_be_hashed: &[u8], text_to_be_hashed_max_len: u16, - ) -> dispatch::Result { + ) -> Result<(), Error> { ensure!( text_to_be_hashed.len() <= text_to_be_hashed_max_len as usize, - ERROR_HASHED_TEXT_PROP_IS_TOO_LONG + Error::::HashedTextPropertyTooLong ); Ok(()) } - fn validate_vec_len(vec: &[V], max_len: VecMaxLength) -> dispatch::Result { - ensure!(vec.len() <= max_len as usize, ERROR_VEC_PROP_IS_TOO_LONG); + fn validate_vec_len(vec: &[V], max_len: VecMaxLength) -> Result<(), Error> { + ensure!( + vec.len() <= max_len as usize, + Error::::VecPropertyTooLong + ); Ok(()) } @@ -494,7 +504,7 @@ impl Property { pub fn validate_max_len_if_vec_property( &self, value: &InputPropertyValue, - ) -> dispatch::Result { + ) -> Result<(), Error> { let (vec_value, vec_property_type) = if let (Some(vec_value), Some(vec_property_type)) = (value.as_vec_value(), self.property_type.as_vec_type()) { @@ -544,10 +554,10 @@ impl Property { pub fn ensure_property_value_matches_its_type( &self, value: &InputPropertyValue, - ) -> dispatch::Result { + ) -> Result<(), Error> { ensure!( self.does_prop_value_match_type(value), - ERROR_PROP_VALUE_DONT_MATCH_TYPE + Error::::PropertyValueDoNotMatchType ); Ok(()) } @@ -601,7 +611,7 @@ impl Property { &self, value: &InputPropertyValue, current_entity_controller: &EntityController, - ) -> dispatch::Result { + ) -> Result<(), Error> { match (value, &self.property_type) { ( InputPropertyValue::Single(single_property_value), @@ -659,14 +669,14 @@ impl Property { pub fn ensure_referenced_entity_match_its_class( entity_id: T::EntityId, class_id: T::ClassId, - ) -> Result, &'static str> { + ) -> Result, Error> { // Ensure Entity under given id exists Module::::ensure_known_entity_id(entity_id)?; let entity = Module::::entity_by_id(entity_id); ensure!( entity.get_class_id() == class_id, - ERROR_REFERENCED_ENTITY_DOES_NOT_MATCH_ITS_CLASS + Error::::ReferencedEntityDoesNotMatchItsClass ); Ok(entity) } @@ -676,45 +686,45 @@ impl Property { entity: Entity, same_controller_status: bool, current_entity_controller: &EntityController, - ) -> dispatch::Result { + ) -> Result<(), Error> { let entity_permissions = entity.get_permissions(); // Ensure Entity is referencable ensure!( entity_permissions.is_referancable(), - ERROR_ENTITY_CAN_NOT_BE_REFERENCED + Error::::EntityCanNotBeReferenced ); if same_controller_status { // Ensure Entity controller is equal to the provided one ensure!( entity_permissions.controller_is_equal_to(current_entity_controller), - ERROR_SAME_CONTROLLER_CONSTRAINT_VIOLATION + Error::::SameControllerConstraintViolation ); } Ok(()) } /// Ensure `PropertyNameLengthConstraint` satisfied - pub fn ensure_name_is_valid(&self) -> dispatch::Result { + pub fn ensure_name_is_valid(&self) -> Result<(), Error> { T::PropertyNameLengthConstraint::get().ensure_valid( self.name.len(), - ERROR_PROPERTY_NAME_TOO_SHORT, - ERROR_PROPERTY_NAME_TOO_LONG, + Error::::PropertyNameTooShort, + Error::::PropertyNameTooLong, ) } /// Ensure `PropertyDescriptionLengthConstraint` satisfied - pub fn ensure_description_is_valid(&self) -> dispatch::Result { + pub fn ensure_description_is_valid(&self) -> Result<(), Error> { T::PropertyDescriptionLengthConstraint::get().ensure_valid( self.description.len(), - ERROR_PROPERTY_DESCRIPTION_TOO_SHORT, - ERROR_PROPERTY_DESCRIPTION_TOO_LONG, + Error::::PropertyDescriptionTooShort, + Error::::PropertyDescriptionTooLong, ) } /// Ensure `Type` specific constraints satisfied - pub fn ensure_property_type_size_is_valid(&self) -> dispatch::Result { + pub fn ensure_property_type_size_is_valid(&self) -> Result<(), Error> { match &self.property_type { PropertyType::Single(single_property_type) => { // Ensure Type specific TextMaxLengthConstraint satisfied @@ -728,17 +738,17 @@ impl Property { } /// Ensure refers to existing `class_id`, if If `Property` `Type` is `Reference`, - pub fn ensure_property_type_reference_is_valid(&self) -> dispatch::Result { + pub fn ensure_property_type_reference_is_valid(&self) -> Result<(), Error> { let has_unknown_reference = if let Type::Reference(other_class_id, _) = self.property_type.get_inner_type() { - !>::exists(other_class_id) + !>::contains_key(other_class_id) } else { false }; ensure!( !has_unknown_reference, - ERROR_CLASS_SCHEMA_REFERS_UNKNOWN_CLASS + Error::::ClassSchemaRefersUnknownClass ); Ok(()) diff --git a/runtime-modules/content-directory/src/schema/convert.rs b/runtime-modules/content-directory/src/schema/convert.rs index 8516a1350e..56968877fc 100644 --- a/runtime-modules/content-directory/src/schema/convert.rs +++ b/runtime-modules/content-directory/src/schema/convert.rs @@ -1,5 +1,5 @@ use super::*; -use runtime_primitives::traits::Hash; +use sp_runtime::traits::Hash; impl From> for StoredPropertyValue { fn from(input_property_value: InputPropertyValue) -> Self { diff --git a/runtime-modules/content-directory/src/schema/output.rs b/runtime-modules/content-directory/src/schema/output.rs index 48c5c85db9..368a44ee3b 100644 --- a/runtime-modules/content-directory/src/schema/output.rs +++ b/runtime-modules/content-directory/src/schema/output.rs @@ -1,5 +1,5 @@ use super::*; -use runtime_primitives::traits::Hash; +use sp_runtime::traits::Hash; /// Enum, representing either `StoredValue` or `VecStoredPropertyValue` #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] @@ -10,6 +10,7 @@ pub enum StoredPropertyValue { } impl StoredPropertyValue { + /// Returns single property value by reference if `StoredPropertyValue` is Single pub fn as_single_value(&self) -> Option<&StoredValue> { if let StoredPropertyValue::Single(single_value) = self { Some(single_value) @@ -18,6 +19,7 @@ impl StoredPropertyValue { } } + /// Returns vector property value by reference if `StoredPropertyValue` is Single pub fn as_vec_property_value(&self) -> Option<&VecStoredPropertyValue> { if let StoredPropertyValue::Vector(vec_property_value) = self { Some(vec_property_value) @@ -26,6 +28,7 @@ impl StoredPropertyValue { } } + /// Returns vector property value by mutable reference if `StoredPropertyValue` is Single pub fn as_vec_property_value_mut(&mut self) -> Option<&mut VecStoredPropertyValue> { if let StoredPropertyValue::Vector(vec_property_value) = self { Some(vec_property_value) @@ -134,6 +137,7 @@ impl VecStoredPropertyValue { self.nonce } + /// Create new `VecStoredPropertyValue` from `vec value` provided and `nonce` pub fn new(vec_value: VecStoredValue, nonce: T::Nonce) -> Self { Self { vec_value, nonce } } @@ -249,10 +253,10 @@ impl VecStoredPropertyValue { /// Ensure `VecStoredPropertyValue` nonce is equal to the provided one. /// Used to to avoid possible data races, when performing vector specific operations - pub fn ensure_nonce_equality(&self, new_nonce: T::Nonce) -> dispatch::Result { + pub fn ensure_nonce_equality(&self, new_nonce: T::Nonce) -> Result<(), Error> { ensure!( self.nonce == new_nonce, - ERROR_PROP_VALUE_VEC_NONCES_DOES_NOT_MATCH + Error::::PropertyValueVecNoncesDoesNotMatch ); Ok(()) } @@ -261,10 +265,10 @@ impl VecStoredPropertyValue { pub fn ensure_index_in_property_vector_is_valid( &self, index_in_property_vec: VecMaxLength, - ) -> dispatch::Result { + ) -> Result<(), Error> { ensure!( (index_in_property_vec as usize) <= self.len(), - ERROR_ENTITY_PROP_VALUE_VECTOR_INDEX_IS_OUT_OF_RANGE + Error::::EntityPropertyValueVectorIndexIsOutOfRange ); Ok(()) diff --git a/runtime-modules/content-directory/src/tests/add_class_schema.rs b/runtime-modules/content-directory/src/tests/add_class_schema.rs index c4ccf8cfb9..96bebbb925 100644 --- a/runtime-modules/content-directory/src/tests/add_class_schema.rs +++ b/runtime-modules/content-directory/src/tests/add_class_schema.rs @@ -81,7 +81,7 @@ fn add_class_schema_lead_auth_failied() { // Failure checked assert_failure( add_class_schema_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -109,7 +109,7 @@ fn add_class_schema_class_does_not_exist() { // Failure checked assert_failure( add_class_schema_result, - ERROR_CLASS_NOT_FOUND, + Error::::ClassNotFound, number_of_events_before_call, ); }) @@ -155,7 +155,7 @@ fn add_class_schema_limit_reached() { // Failure checked assert_failure( add_class_schema_result, - ERROR_CLASS_SCHEMAS_LIMIT_REACHED, + Error::::ClassSchemasLimitReached, number_of_events_before_call + number_of_schemas_added, ); }) @@ -179,7 +179,7 @@ fn add_class_schema_no_props_in_schema() { // Failure checked assert_failure( add_class_schema_result, - ERROR_NO_PROPS_IN_CLASS_SCHEMA, + Error::::NoPropertiesInClassSchema, number_of_events_before_call, ); }) @@ -213,7 +213,7 @@ fn add_class_schema_properties_limit_reached() { // Failure checked assert_failure( add_class_schema_result, - ERROR_SCHEMA_PROPERTIES_LIMIT_REACHED, + Error::::SchemaPropertiesLimitReached, number_of_events_before_call, ); }) @@ -255,7 +255,7 @@ fn add_class_schema_prop_name_not_unique() { // Failure checked assert_failure( add_class_schema_result, - ERROR_PROP_NAME_NOT_UNIQUE_IN_A_CLASS, + Error::::PropertyNameNotUniqueInAClass, number_of_events_before_call, ); }) @@ -286,7 +286,7 @@ fn add_class_schema_refers_invalid_property_index() { // Failure checked assert_failure( add_class_schema_result, - ERROR_CLASS_SCHEMA_REFERS_UNKNOWN_PROP_INDEX, + Error::::ClassSchemaRefersUnknownPropertyIndex, number_of_events_before_call, ); }) @@ -312,7 +312,7 @@ fn add_class_schema_property_name_too_long() { // Failure checked assert_failure( add_class_schema_result, - ERROR_PROPERTY_NAME_TOO_LONG, + Error::::PropertyNameTooLong, number_of_events_before_call, ); }) @@ -338,7 +338,7 @@ fn add_class_schema_property_name_too_short() { // Failure checked assert_failure( add_class_schema_result, - ERROR_PROPERTY_NAME_TOO_SHORT, + Error::::PropertyNameTooShort, number_of_events_before_call, ); }) @@ -364,7 +364,7 @@ fn add_class_schema_property_description_too_long() { // Failure checked assert_failure( add_class_schema_result, - ERROR_PROPERTY_DESCRIPTION_TOO_LONG, + Error::::PropertyDescriptionTooLong, number_of_events_before_call, ); }) @@ -390,7 +390,7 @@ fn add_class_schema_property_description_too_short() { // Failure checked assert_failure( add_class_schema_result, - ERROR_PROPERTY_DESCRIPTION_TOO_SHORT, + Error::::PropertyDescriptionTooShort, number_of_events_before_call, ); }) @@ -416,7 +416,7 @@ fn add_class_schema_text_property_is_too_long() { // Failure checked assert_failure( add_class_schema_result, - ERROR_TEXT_PROP_IS_TOO_LONG, + Error::::TextPropertyTooLong, number_of_events_before_call, ); }) @@ -443,7 +443,7 @@ fn add_class_schema_text_hash_property_is_too_long() { // Failure checked assert_failure( add_class_schema_result, - ERROR_HASHED_TEXT_PROP_IS_TOO_LONG, + Error::::HashedTextPropertyTooLong, number_of_events_before_call, ); }) @@ -469,7 +469,7 @@ fn add_class_schema_property_vec_property_is_too_long() { // Failure checked assert_failure( add_class_schema_result, - ERROR_VEC_PROP_IS_TOO_LONG, + Error::::VecPropertyTooLong, number_of_events_before_call, ); }) @@ -500,7 +500,7 @@ fn add_class_schema_property_refers_unknown_class() { // Failure checked assert_failure( add_class_schema_result, - ERROR_CLASS_SCHEMA_REFERS_UNKNOWN_CLASS, + Error::::ClassSchemaRefersUnknownClass, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/add_curator_group.rs b/runtime-modules/content-directory/src/tests/add_curator_group.rs index 8d7bdd1a15..dbedef6395 100644 --- a/runtime-modules/content-directory/src/tests/add_curator_group.rs +++ b/runtime-modules/content-directory/src/tests/add_curator_group.rs @@ -52,7 +52,7 @@ fn add_curator_group_lead_auth_failed() { // Failure checked assert_failure( add_curator_group_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/add_curator_to_group.rs b/runtime-modules/content-directory/src/tests/add_curator_to_group.rs index b8b708e8ce..39bd75d5a7 100644 --- a/runtime-modules/content-directory/src/tests/add_curator_to_group.rs +++ b/runtime-modules/content-directory/src/tests/add_curator_to_group.rs @@ -59,7 +59,7 @@ fn add_curator_to_group_lead_auth_failed() { // Failure checked assert_failure( add_curator_to_group_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -80,7 +80,7 @@ fn add_curator_to_non_existent_group() { // Failure checked assert_failure( add_curator_to_group_result, - ERROR_CURATOR_GROUP_DOES_NOT_EXIST, + Error::::CuratorGroupDoesNotExist, number_of_events_before_call, ); }) @@ -124,7 +124,7 @@ fn add_curator_to_group_curators_limit_reached() { // Failure checked assert_failure( add_curator_to_group_result, - ERROR_NUMBER_OF_CURATORS_PER_GROUP_LIMIT_REACHED, + Error::::CuratorsPerGroupLimitReached, number_of_events_before_call + number_of_curators_added as usize, ); }) diff --git a/runtime-modules/content-directory/src/tests/add_maintainer_to_class.rs b/runtime-modules/content-directory/src/tests/add_maintainer_to_class.rs index fd4c0635b3..11c89b1f17 100644 --- a/runtime-modules/content-directory/src/tests/add_maintainer_to_class.rs +++ b/runtime-modules/content-directory/src/tests/add_maintainer_to_class.rs @@ -60,7 +60,7 @@ fn add_maintainer_to_class_lead_auth_failed() { // Failure checked assert_failure( add_maintainer_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -84,7 +84,7 @@ fn add_non_existent_maintainer_to_class() { // Failure checked assert_failure( add_maintainer_result, - ERROR_CURATOR_GROUP_DOES_NOT_EXIST, + Error::::CuratorGroupDoesNotExist, number_of_events_before_call, ); }) @@ -107,7 +107,7 @@ fn add_maintainer_to_non_existent_class() { // Failure checked assert_failure( add_maintainer_result, - ERROR_CLASS_NOT_FOUND, + Error::::ClassNotFound, number_of_events_before_call, ); }) @@ -154,7 +154,7 @@ fn add_maintainer_to_class_limit_reached() { // Failure checked assert_failure( add_maintainer_result, - ERROR_NUMBER_OF_MAINTAINERS_PER_CLASS_LIMIT_REACHED, + Error::::ClassMaintainersLimitReached, number_of_events_before_call + number_of_maintainers_added_to_class, ); }) @@ -188,7 +188,7 @@ fn add_maintainer_that_is_already_exist() { // Failure checked assert_failure( add_maintainer_result, - ERROR_MAINTAINER_ALREADY_EXISTS, + Error::::MaintainerAlreadyExists, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/add_schema_support_to_entity.rs b/runtime-modules/content-directory/src/tests/add_schema_support_to_entity.rs index 4018067731..3e860a9677 100644 --- a/runtime-modules/content-directory/src/tests/add_schema_support_to_entity.rs +++ b/runtime-modules/content-directory/src/tests/add_schema_support_to_entity.rs @@ -54,7 +54,7 @@ fn add_schema_support_to_non_existent_entity() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_ENTITY_NOT_FOUND, + Error::::EntityNotFound, number_of_events_before_call, ); }) @@ -100,7 +100,7 @@ fn add_schema_support_lead_auth_failed() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -146,7 +146,7 @@ fn add_schema_support_member_auth_failed() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_MEMBER_AUTH_FAILED, + Error::::MemberAuthFailed, number_of_events_before_call, ); }) @@ -199,7 +199,7 @@ fn add_schema_support_curator_group_is_not_active() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_CURATOR_GROUP_IS_NOT_ACTIVE, + Error::::CuratorGroupIsNotActive, number_of_events_before_call, ); }) @@ -246,7 +246,7 @@ fn add_schema_support_curator_auth_failed() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_CURATOR_AUTH_FAILED, + Error::::CuratorAuthFailed, number_of_events_before_call, ); }) @@ -293,7 +293,7 @@ fn add_schema_support_curator_not_found_in_curator_group() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_CURATOR_IS_NOT_A_MEMBER_OF_A_GIVEN_CURATOR_GROUP, + Error::::CuratorIsNotAMemberOfGivenCuratorGroup, number_of_events_before_call, ); }) @@ -340,7 +340,7 @@ fn add_schema_support_access_denied() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_ENTITY_ACCESS_DENIED, + Error::::EntityAccessDenied, number_of_events_before_call, ); }) @@ -378,7 +378,7 @@ fn add_schema_support_to_entity_schema_does_not_exist() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_UNKNOWN_CLASS_SCHEMA_ID, + Error::::UnknownClassSchemaId, number_of_events_before_call, ); }) @@ -429,7 +429,7 @@ fn add_schema_support_to_entity_class_property_not_found() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_CLASS_PROP_NOT_FOUND, + Error::::ClassPropertyNotFound, number_of_events_before_call, ); }) @@ -488,7 +488,7 @@ fn add_schema_support_already_added_to_the_entity() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_SCHEMA_ALREADY_ADDED_TO_THE_ENTITY, + Error::::SchemaAlreadyAddedToTheEntity, number_of_events_before_call, ); }) @@ -570,7 +570,7 @@ fn add_schema_support_already_contains_given_property_id() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_ENTITY_ALREADY_CONTAINS_GIVEN_PROPERTY_ID, + Error::::EntityAlreadyContainsGivenPropertyId, number_of_events_before_call, ); }) @@ -629,7 +629,7 @@ fn add_schema_support_is_not_active() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_CLASS_SCHEMA_NOT_ACTIVE, + Error::::ClassSchemaNotActive, number_of_events_before_call, ); }) @@ -693,7 +693,7 @@ fn add_schema_support_does_not_contain_provided_property_id() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_SCHEMA_DOES_NOT_CONTAIN_PROVIDED_PROPERTY_ID, + Error::::SchemaDoesNotContainProvidedPropertyId, number_of_events_before_call, ); }) @@ -753,7 +753,7 @@ fn add_schema_support_missing_required_property() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_MISSING_REQUIRED_PROP, + Error::::MissingRequiredProperty, number_of_events_before_call, ); }) @@ -808,7 +808,7 @@ fn add_schema_support_dont_match_type() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_PROP_VALUE_DONT_MATCH_TYPE, + Error::::PropertyValueDoNotMatchType, number_of_events_before_call, ); }) @@ -877,7 +877,7 @@ fn add_schema_support_referenced_entity_does_not_match_class() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_REFERENCED_ENTITY_DOES_NOT_MATCH_ITS_CLASS, + Error::::ReferencedEntityDoesNotMatchItsClass, number_of_events_before_call, ); }) @@ -941,7 +941,7 @@ fn add_schema_support_referenced_entity_does_not_exist() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_ENTITY_NOT_FOUND, + Error::::EntityNotFound, number_of_events_before_call, ); }) @@ -1011,7 +1011,7 @@ fn add_schema_support_entity_can_not_be_referenced() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_ENTITY_CAN_NOT_BE_REFERENCED, + Error::::EntityCanNotBeReferenced, number_of_events_before_call, ); }) @@ -1087,7 +1087,7 @@ fn add_schema_support_same_controller_constraint_violation() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_SAME_CONTROLLER_CONSTRAINT_VIOLATION, + Error::::SameControllerConstraintViolation, number_of_events_before_call, ); }) @@ -1147,7 +1147,7 @@ fn add_schema_support_text_property_is_too_long() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_TEXT_PROP_IS_TOO_LONG, + Error::::TextPropertyTooLong, number_of_events_before_call, ); }) @@ -1211,7 +1211,7 @@ fn add_schema_support_text_hash_property_is_too_long() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_HASHED_TEXT_PROP_IS_TOO_LONG, + Error::::HashedTextPropertyTooLong, number_of_events_before_call, ); }) @@ -1286,7 +1286,7 @@ fn add_schema_support_vec_property_is_too_long() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_VEC_PROP_IS_TOO_LONG, + Error::::VecPropertyTooLong, number_of_events_before_call, ); }) @@ -1359,7 +1359,7 @@ fn add_schema_support_property_should_be_unique() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_PROPERTY_VALUE_SHOULD_BE_UNIQUE, + Error::::PropertyValueShouldBeUnique, number_of_events_before_call, ); }) @@ -1451,7 +1451,7 @@ fn add_schema_support_properties_should_be_unique() { // Failure checked assert_failure( add_schema_support_to_entity_result, - ERROR_PROPERTY_VALUE_SHOULD_BE_UNIQUE, + Error::::PropertyValueShouldBeUnique, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/clear_entity_property_vector.rs b/runtime-modules/content-directory/src/tests/clear_entity_property_vector.rs index f03bbaabca..4c0ec8cc8c 100644 --- a/runtime-modules/content-directory/src/tests/clear_entity_property_vector.rs +++ b/runtime-modules/content-directory/src/tests/clear_entity_property_vector.rs @@ -83,7 +83,7 @@ fn clear_entity_property_vector_entity_not_found() { // Failure checked assert_failure( clear_entity_property_vector_result, - ERROR_ENTITY_NOT_FOUND, + Error::::EntityNotFound, number_of_events_before_call, ); }) @@ -116,7 +116,7 @@ fn clear_entity_property_vector_lead_auth_failed() { // Failure checked assert_failure( clear_entity_property_vector_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -149,7 +149,7 @@ fn clear_entity_property_vector_member_auth_failed() { // Failure checked assert_failure( clear_entity_property_vector_result, - ERROR_MEMBER_AUTH_FAILED, + Error::::MemberAuthFailed, number_of_events_before_call, ); }) @@ -178,7 +178,7 @@ fn clear_entity_property_vector_curator_auth_failed() { // Failure checked assert_failure( clear_entity_property_vector_result, - ERROR_CURATOR_AUTH_FAILED, + Error::::CuratorAuthFailed, number_of_events_before_call, ); }) @@ -218,7 +218,7 @@ fn clear_entity_property_vector_curator_group_is_not_active() { // Failure checked assert_failure( clear_entity_property_vector_result, - ERROR_CURATOR_GROUP_IS_NOT_ACTIVE, + Error::::CuratorGroupIsNotActive, number_of_events_before_call, ); }) @@ -254,7 +254,7 @@ fn clear_entity_property_vector_curator_not_found_in_curator_group() { // Failure checked assert_failure( clear_entity_property_vector_result, - ERROR_CURATOR_IS_NOT_A_MEMBER_OF_A_GIVEN_CURATOR_GROUP, + Error::::CuratorIsNotAMemberOfGivenCuratorGroup, number_of_events_before_call, ); }) @@ -287,7 +287,7 @@ fn clear_entity_property_vector_entity_access_denied() { // Failure checked assert_failure( clear_entity_property_vector_result, - ERROR_ENTITY_ACCESS_DENIED, + Error::::EntityAccessDenied, number_of_events_before_call, ); }) @@ -316,7 +316,7 @@ fn clear_entity_property_vector_values_locked_on_class_level() { // Failure checked assert_failure( clear_entity_property_vector_result, - ERROR_ALL_PROP_WERE_LOCKED_ON_CLASS_LEVEL, + Error::::AllPropertiesWereLockedOnClassLevel, number_of_events_before_call, ); }) @@ -346,7 +346,7 @@ fn clear_entity_property_vector_class_property_not_found() { // Failure checked assert_failure( clear_entity_property_vector_result, - ERROR_CLASS_PROP_NOT_FOUND, + Error::::ClassPropertyNotFound, number_of_events_before_call, ); }) @@ -411,7 +411,7 @@ fn clear_entity_property_vector_is_locked_for_given_actor() { // Failure checked assert_failure( clear_entity_property_vector_result, - ERROR_CLASS_PROPERTY_TYPE_IS_LOCKED_FOR_GIVEN_ACTOR, + Error::::ClassPropertyTypeLockedForGivenActor, number_of_events_before_call, ); }) @@ -444,7 +444,7 @@ fn clear_entity_property_vector_unknown_entity_property_id() { // Failure checked assert_failure( clear_entity_property_vector_result, - ERROR_UNKNOWN_ENTITY_PROP_ID, + Error::::UnknownEntityPropertyId, number_of_events_before_call, ); }) @@ -499,7 +499,7 @@ fn clear_entity_property_vector_value_under_given_index_is_not_a_vector() { // Failure checked assert_failure( clear_entity_property_vector_result, - ERROR_PROP_VALUE_UNDER_GIVEN_INDEX_IS_NOT_A_VECTOR, + Error::::PropertyValueUnderGivenIndexIsNotAVector, number_of_events_before_call, ); }) @@ -550,7 +550,7 @@ fn clear_entity_property_vector_property_should_be_unique() { // Failure checked assert_failure( clear_entity_property_vector_result, - ERROR_PROPERTY_VALUE_SHOULD_BE_UNIQUE, + Error::::PropertyValueShouldBeUnique, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/create_class.rs b/runtime-modules/content-directory/src/tests/create_class.rs index 50bcf79376..f05f3cf605 100644 --- a/runtime-modules/content-directory/src/tests/create_class.rs +++ b/runtime-modules/content-directory/src/tests/create_class.rs @@ -41,7 +41,7 @@ fn create_class_lead_auth_failed() { // Failure checked assert_failure( create_class_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -76,7 +76,7 @@ fn create_class_limit_reached() { // Failure checked assert_failure( create_class_result, - ERROR_CLASS_LIMIT_REACHED, + Error::::ClassLimitReached, number_of_events_before_call + number_of_classes_created, ); }) @@ -96,7 +96,7 @@ fn create_class_name_is_too_long() { // Failure checked assert_failure( create_class_result, - ERROR_CLASS_NAME_TOO_LONG, + Error::::ClassNameTooLong, number_of_events_before_call, ); }) @@ -116,7 +116,7 @@ fn create_class_name_is_too_short() { // Failure checked assert_failure( create_class_result, - ERROR_CLASS_NAME_TOO_SHORT, + Error::::ClassNameTooShort, number_of_events_before_call, ); }) @@ -136,7 +136,7 @@ fn create_class_description_is_too_long() { // Failure checked assert_failure( create_class_result, - ERROR_CLASS_DESCRIPTION_TOO_LONG, + Error::::ClassDescriptionTooLong, number_of_events_before_call, ); }) @@ -156,7 +156,7 @@ fn create_class_description_is_too_short() { // Failure checked assert_failure( create_class_result, - ERROR_CLASS_DESCRIPTION_TOO_SHORT, + Error::::ClassDescriptionTooShort, number_of_events_before_call, ); }) @@ -177,7 +177,7 @@ fn create_class_invalid_maximum_entities_count() { // Failure checked assert_failure( create_class_result, - ERROR_ENTITIES_NUMBER_PER_CLASS_CONSTRAINT_VIOLATED, + Error::::EntitiesNumberPerClassConstraintViolated, number_of_events_before_call, ); }) @@ -198,7 +198,7 @@ fn create_class_invalid_default_voucher_upper_bound() { // Failure checked assert_failure( create_class_result, - ERROR_NUMBER_OF_CLASS_ENTITIES_PER_ACTOR_CONSTRAINT_VIOLATED, + Error::::NumberOfClassEntitiesPerActorConstraintViolated, number_of_events_before_call, ); }) @@ -221,7 +221,7 @@ fn create_class_per_controller_creation_limit_exceeds_overall_limit() { // Failure checked assert_failure( create_class_result, - ERROR_PER_CONTROLLER_ENTITIES_CREATION_LIMIT_EXCEEDS_OVERALL_LIMIT, + Error::::PerControllerEntitiesCreationLimitExceedsOverallLimit, number_of_events_before_call, ); }) @@ -247,7 +247,7 @@ fn create_class_maintainers_limit_reached() { // Failure checked assert_failure( create_class_result, - ERROR_NUMBER_OF_MAINTAINERS_PER_CLASS_LIMIT_REACHED, + Error::::ClassMaintainersLimitReached, number_of_events_before_call, ); }) @@ -268,7 +268,7 @@ fn create_class_curator_group_does_not_exist() { // Failure checked assert_failure( create_class_result, - ERROR_CURATOR_GROUP_DOES_NOT_EXIST, + Error::::CuratorGroupDoesNotExist, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/create_entity.rs b/runtime-modules/content-directory/src/tests/create_entity.rs index 465259dcab..3d0db317aa 100644 --- a/runtime-modules/content-directory/src/tests/create_entity.rs +++ b/runtime-modules/content-directory/src/tests/create_entity.rs @@ -94,7 +94,7 @@ fn create_entity_of_non_existent_class() { // Failure checked assert_failure( create_entity_result, - ERROR_CLASS_NOT_FOUND, + Error::::ClassNotFound, number_of_events_before_call, ); }) @@ -148,7 +148,7 @@ fn create_entity_creation_limit_reached() { // Failure checked assert_failure( create_entity_result, - ERROR_MAX_NUMBER_OF_ENTITIES_PER_CLASS_LIMIT_REACHED, + Error::::NumberOfEntitiesPerClassLimitReached, number_of_events_before_call + number_of_entities_created as usize, ); }) @@ -185,7 +185,7 @@ fn create_entity_creation_blocked_on_class_level() { // Failure checked assert_failure( create_entity_result, - ERROR_ENTITY_CREATION_BLOCKED, + Error::::EntitiesCreationBlocked, number_of_events_before_call, ); }) @@ -210,7 +210,7 @@ fn create_entity_lead_auth_failed() { // Failure checked assert_failure( create_entity_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -245,7 +245,7 @@ fn create_entity_member_auth_failed() { // Failure checked assert_failure( create_entity_result, - ERROR_MEMBER_AUTH_FAILED, + Error::::MemberAuthFailed, number_of_events_before_call, ); }) @@ -270,7 +270,7 @@ fn create_entity_actor_can_not_create_entities() { // Failure checked assert_failure( create_entity_result, - ERROR_ACTOR_CAN_NOT_CREATE_ENTITIES, + Error::::ActorCanNotCreateEntities, number_of_events_before_call, ); }) @@ -313,7 +313,7 @@ fn create_entity_unknown_curator_id() { // Failure checked assert_failure( create_entity_result, - ERROR_CURATOR_AUTH_FAILED, + Error::::CuratorAuthFailed, number_of_events_before_call, ); }) @@ -356,7 +356,7 @@ fn create_entity_curator_group_is_not_active() { // Failure checked assert_failure( create_entity_result, - ERROR_CURATOR_GROUP_IS_NOT_ACTIVE, + Error::::CuratorGroupIsNotActive, number_of_events_before_call, ); }) @@ -399,7 +399,7 @@ fn create_entity_curator_not_found_in_curator_group() { // Failure checked assert_failure( create_entity_result, - ERROR_CURATOR_IS_NOT_A_MEMBER_OF_A_GIVEN_CURATOR_GROUP, + Error::::CuratorIsNotAMemberOfGivenCuratorGroup, number_of_events_before_call, ); }) @@ -439,7 +439,7 @@ fn create_entity_voucher_limit_reached() { // Failure checked assert_failure( create_entity_result, - ERROR_VOUCHER_LIMIT_REACHED, + Error::::VoucherLimitReached, number_of_events_before_call + number_of_entities_created as usize, ); }) diff --git a/runtime-modules/content-directory/src/tests/insert_at_entity_property_vector.rs b/runtime-modules/content-directory/src/tests/insert_at_entity_property_vector.rs index 6057dd4b7b..8d01ff3d1c 100644 --- a/runtime-modules/content-directory/src/tests/insert_at_entity_property_vector.rs +++ b/runtime-modules/content-directory/src/tests/insert_at_entity_property_vector.rs @@ -105,7 +105,7 @@ fn insert_at_entity_property_vector_entity_not_found() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_ENTITY_NOT_FOUND, + Error::::EntityNotFound, number_of_events_before_call, ); }) @@ -145,7 +145,7 @@ fn insert_at_entity_property_vector_lead_auth_failed() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -185,7 +185,7 @@ fn insert_at_entity_property_vector_member_auth_failed() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_MEMBER_AUTH_FAILED, + Error::::MemberAuthFailed, number_of_events_before_call, ); }) @@ -232,7 +232,7 @@ fn insert_at_entity_property_vector_curator_group_is_not_active() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_CURATOR_GROUP_IS_NOT_ACTIVE, + Error::::CuratorGroupIsNotActive, number_of_events_before_call, ); }) @@ -275,7 +275,7 @@ fn insert_at_entity_property_vector_curator_auth_failed() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_CURATOR_AUTH_FAILED, + Error::::CuratorAuthFailed, number_of_events_before_call, ); }) @@ -319,7 +319,7 @@ fn insert_at_entity_property_vector_curator_not_found_in_curator_group() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_CURATOR_IS_NOT_A_MEMBER_OF_A_GIVEN_CURATOR_GROUP, + Error::::CuratorIsNotAMemberOfGivenCuratorGroup, number_of_events_before_call, ); }) @@ -360,7 +360,7 @@ fn insert_at_entity_property_vector_access_denied() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_ENTITY_ACCESS_DENIED, + Error::::EntityAccessDenied, number_of_events_before_call, ); }) @@ -401,7 +401,7 @@ fn insert_at_entity_property_vector_values_locked_on_class_level() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_ALL_PROP_WERE_LOCKED_ON_CLASS_LEVEL, + Error::::AllPropertiesWereLockedOnClassLevel, number_of_events_before_call, ); }) @@ -443,7 +443,7 @@ fn insert_at_entity_property_vector_class_property_not_found() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_CLASS_PROP_NOT_FOUND, + Error::::ClassPropertyNotFound, number_of_events_before_call, ); }) @@ -521,7 +521,7 @@ fn insert_at_entity_property_vector_is_locked_for_given_actor() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_CLASS_PROPERTY_TYPE_IS_LOCKED_FOR_GIVEN_ACTOR, + Error::::ClassPropertyTypeLockedForGivenActor, number_of_events_before_call, ); }) @@ -566,7 +566,7 @@ fn insert_at_entity_property_vector_unknown_entity_property_id() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_UNKNOWN_ENTITY_PROP_ID, + Error::::UnknownEntityPropertyId, number_of_events_before_call, ); }) @@ -633,7 +633,7 @@ fn insert_at_entity_property_vector_value_under_given_index_is_not_a_vector() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_PROP_VALUE_UNDER_GIVEN_INDEX_IS_NOT_A_VECTOR, + Error::::PropertyValueUnderGivenIndexIsNotAVector, number_of_events_before_call, ); }) @@ -678,7 +678,7 @@ fn insert_at_entity_property_vector_nonces_does_not_match() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_PROP_VALUE_VEC_NONCES_DOES_NOT_MATCH, + Error::::PropertyValueVecNoncesDoesNotMatch, number_of_events_before_call, ); }) @@ -739,7 +739,7 @@ fn insert_at_entity_property_vector_index_is_out_of_range() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_ENTITY_PROP_VALUE_VECTOR_INDEX_IS_OUT_OF_RANGE, + Error::::EntityPropertyValueVectorIndexIsOutOfRange, number_of_events_before_call, ); }) @@ -800,7 +800,7 @@ fn insert_at_entity_property_vector_is_too_long() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_ENTITY_PROP_VALUE_VECTOR_IS_TOO_LONG, + Error::::EntityPropertyValueVectorIsTooLong, number_of_events_before_call, ); }) @@ -878,7 +878,7 @@ fn insert_at_entity_property_vector_text_prop_is_too_long() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_TEXT_PROP_IS_TOO_LONG, + Error::::TextPropertyTooLong, number_of_events_before_call, ); }) @@ -959,7 +959,7 @@ fn insert_at_entity_property_vector_hashed_text_prop_is_too_long() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_HASHED_TEXT_PROP_IS_TOO_LONG, + Error::::HashedTextPropertyTooLong, number_of_events_before_call, ); }) @@ -1036,7 +1036,7 @@ fn insert_at_entity_property_vector_prop_type_does_not_match_internal_vec_proper // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_PROP_VALUE_TYPE_DOESNT_MATCH_INTERNAL_ENTITY_VECTOR_TYPE, + Error::::PropertyValueTypeDoesNotMatchInternalVectorType, number_of_events_before_call, ); }) @@ -1081,7 +1081,7 @@ fn insert_at_entity_property_vector_referenced_entity_not_found() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_ENTITY_NOT_FOUND, + Error::::EntityNotFound, number_of_events_before_call, ); }) @@ -1137,7 +1137,7 @@ fn insert_at_entity_property_vector_entity_can_not_be_referenced() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_ENTITY_CAN_NOT_BE_REFERENCED, + Error::::EntityCanNotBeReferenced, number_of_events_before_call, ); }) @@ -1199,7 +1199,7 @@ fn insert_at_entity_property_vector_same_controller_constraint_violation() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_SAME_CONTROLLER_CONSTRAINT_VIOLATION, + Error::::SameControllerConstraintViolation, number_of_events_before_call, ); }) @@ -1264,7 +1264,7 @@ fn insert_at_entity_property_vector_property_should_be_unique() { // Failure checked assert_failure( insert_at_entity_property_vector_result, - ERROR_PROPERTY_VALUE_SHOULD_BE_UNIQUE, + Error::::PropertyValueShouldBeUnique, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/remove_at_entity_property_vector.rs b/runtime-modules/content-directory/src/tests/remove_at_entity_property_vector.rs index 85e93d1bef..e0b86dd3f3 100644 --- a/runtime-modules/content-directory/src/tests/remove_at_entity_property_vector.rs +++ b/runtime-modules/content-directory/src/tests/remove_at_entity_property_vector.rs @@ -98,7 +98,7 @@ fn remove_at_entity_property_vector_entity_not_found() { // Failure checked assert_failure( remove_at_entity_property_vector_result, - ERROR_ENTITY_NOT_FOUND, + Error::::EntityNotFound, number_of_events_before_call, ); }) @@ -136,7 +136,7 @@ fn remove_at_entity_property_vector_lead_auth_failed() { // Failure checked assert_failure( remove_at_entity_property_vector_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -174,7 +174,7 @@ fn remove_at_entity_property_vector_member_auth_failed() { // Failure checked assert_failure( remove_at_entity_property_vector_result, - ERROR_MEMBER_AUTH_FAILED, + Error::::MemberAuthFailed, number_of_events_before_call, ); }) @@ -219,7 +219,7 @@ fn remove_at_entity_property_vector_curator_group_is_not_active() { // Failure checked assert_failure( remove_at_entity_property_vector_result, - ERROR_CURATOR_GROUP_IS_NOT_ACTIVE, + Error::::CuratorGroupIsNotActive, number_of_events_before_call, ); }) @@ -257,7 +257,7 @@ fn remove_at_entity_property_vector_curator_auth_failed() { // Failure checked assert_failure( remove_at_entity_property_vector_result, - ERROR_CURATOR_AUTH_FAILED, + Error::::CuratorAuthFailed, number_of_events_before_call, ); }) @@ -299,7 +299,7 @@ fn remove_at_entity_property_vector_curator_not_found_in_curator_group() { // Failure checked assert_failure( remove_at_entity_property_vector_result, - ERROR_CURATOR_IS_NOT_A_MEMBER_OF_A_GIVEN_CURATOR_GROUP, + Error::::CuratorIsNotAMemberOfGivenCuratorGroup, number_of_events_before_call, ); }) @@ -338,7 +338,7 @@ fn remove_at_entity_property_vector_access_denied() { // Failure checked assert_failure( remove_at_entity_property_vector_result, - ERROR_ENTITY_ACCESS_DENIED, + Error::::EntityAccessDenied, number_of_events_before_call, ); }) @@ -377,7 +377,7 @@ fn remove_at_entity_property_vector_values_locked_on_class_level() { // Failure checked assert_failure( remove_at_entity_property_vector_result, - ERROR_ALL_PROP_WERE_LOCKED_ON_CLASS_LEVEL, + Error::::AllPropertiesWereLockedOnClassLevel, number_of_events_before_call, ); }) @@ -417,7 +417,7 @@ fn remove_at_entity_property_vector_class_property_not_found() { // Failure checked assert_failure( remove_at_entity_property_vector_result, - ERROR_CLASS_PROP_NOT_FOUND, + Error::::ClassPropertyNotFound, number_of_events_before_call, ); }) @@ -493,7 +493,7 @@ fn remove_at_entity_property_vector_is_locked_for_given_actor() { // Failure checked assert_failure( remove_at_entity_property_vector_result, - ERROR_CLASS_PROPERTY_TYPE_IS_LOCKED_FOR_GIVEN_ACTOR, + Error::::ClassPropertyTypeLockedForGivenActor, number_of_events_before_call, ); }) @@ -536,7 +536,7 @@ fn remove_at_entity_property_vector_unknown_entity_property_id() { // Failure checked assert_failure( remove_at_entity_property_vector_result, - ERROR_UNKNOWN_ENTITY_PROP_ID, + Error::::UnknownEntityPropertyId, number_of_events_before_call, ); }) @@ -601,7 +601,7 @@ fn remove_at_entity_property_vector_value_under_given_index_is_not_a_vector() { // Failure checked assert_failure( remove_at_entity_property_vector_result, - ERROR_PROP_VALUE_UNDER_GIVEN_INDEX_IS_NOT_A_VECTOR, + Error::::PropertyValueUnderGivenIndexIsNotAVector, number_of_events_before_call, ); }) @@ -644,7 +644,7 @@ fn remove_at_entity_property_vector_nonces_does_not_match() { // Failure checked assert_failure( remove_at_entity_property_vector_result, - ERROR_PROP_VALUE_VEC_NONCES_DOES_NOT_MATCH, + Error::::PropertyValueVecNoncesDoesNotMatch, number_of_events_before_call, ); }) @@ -703,7 +703,7 @@ fn remove_at_entity_property_vector_index_is_out_of_range() { // Failure checked assert_failure( remove_at_entity_property_vector_result, - ERROR_ENTITY_PROP_VALUE_VECTOR_INDEX_IS_OUT_OF_RANGE, + Error::::EntityPropertyValueVectorIndexIsOutOfRange, number_of_events_before_call, ); }) @@ -769,7 +769,7 @@ fn remove_at_entity_property_vector_property_should_be_unique() { // Failure checked assert_failure( remove_at_entity_property_vector_result, - ERROR_PROPERTY_VALUE_SHOULD_BE_UNIQUE, + Error::::PropertyValueShouldBeUnique, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/remove_curator_from_group.rs b/runtime-modules/content-directory/src/tests/remove_curator_from_group.rs index 254b7fb50a..e0e99098a3 100644 --- a/runtime-modules/content-directory/src/tests/remove_curator_from_group.rs +++ b/runtime-modules/content-directory/src/tests/remove_curator_from_group.rs @@ -79,7 +79,7 @@ fn remove_curator_from_group_lead_auth_failed() { // Failure checked assert_failure( remove_curator_from_group_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -103,7 +103,7 @@ fn remove_curator_from_group_curator_is_not_a_member() { // Failure checked assert_failure( remove_curator_from_group_result, - ERROR_CURATOR_IS_NOT_A_MEMBER_OF_A_GIVEN_CURATOR_GROUP, + Error::::CuratorIsNotAMemberOfGivenCuratorGroup, number_of_events_before_call, ); }) @@ -124,7 +124,7 @@ fn remove_curator_from_non_existent_group() { // Failure checked assert_failure( remove_curator_from_group_result, - ERROR_CURATOR_GROUP_DOES_NOT_EXIST, + Error::::CuratorGroupDoesNotExist, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/remove_curator_group.rs b/runtime-modules/content-directory/src/tests/remove_curator_group.rs index e76cc5d8bf..a61cbe54c5 100644 --- a/runtime-modules/content-directory/src/tests/remove_curator_group.rs +++ b/runtime-modules/content-directory/src/tests/remove_curator_group.rs @@ -49,7 +49,7 @@ fn remove_curator_group_lead_auth_failed() { // Failure checked assert_failure( remove_curator_group_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -70,7 +70,7 @@ fn remove_non_existent_curator_group() { // Failure checked assert_failure( remove_curator_group_result, - ERROR_CURATOR_GROUP_DOES_NOT_EXIST, + Error::::CuratorGroupDoesNotExist, number_of_events_before_call, ); }) @@ -103,7 +103,7 @@ fn curator_group_removal_forbidden() { // Failure checked assert_failure( remove_curator_group_result, - ERROR_CURATOR_GROUP_REMOVAL_FORBIDDEN, + Error::::CuratorGroupRemovalForbidden, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/remove_entity.rs b/runtime-modules/content-directory/src/tests/remove_entity.rs index f4751de6f0..82d3e34f8a 100644 --- a/runtime-modules/content-directory/src/tests/remove_entity.rs +++ b/runtime-modules/content-directory/src/tests/remove_entity.rs @@ -60,7 +60,7 @@ fn remove_non_existent_entity() { // Failure checked assert_failure( remove_entity_result, - ERROR_ENTITY_NOT_FOUND, + Error::::EntityNotFound, number_of_events_before_call, ); }) @@ -84,7 +84,7 @@ fn remove_entity_lead_auth_failed() { // Failure checked assert_failure( remove_entity_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -108,7 +108,7 @@ fn remove_entity_member_auth_failed() { // Failure checked assert_failure( remove_entity_result, - ERROR_MEMBER_AUTH_FAILED, + Error::::MemberAuthFailed, number_of_events_before_call, ); }) @@ -139,7 +139,7 @@ fn create_entity_curator_group_is_not_active() { // Failure checked assert_failure( remove_entity_result, - ERROR_CURATOR_GROUP_IS_NOT_ACTIVE, + Error::::CuratorGroupIsNotActive, number_of_events_before_call, ); }) @@ -163,7 +163,7 @@ fn remove_entity_curator_auth_failed() { // Failure checked assert_failure( remove_entity_result, - ERROR_CURATOR_AUTH_FAILED, + Error::::CuratorAuthFailed, number_of_events_before_call, ); }) @@ -188,7 +188,7 @@ fn remove_entity_curator_not_found_in_curator_group() { // Failure checked assert_failure( remove_entity_result, - ERROR_CURATOR_IS_NOT_A_MEMBER_OF_A_GIVEN_CURATOR_GROUP, + Error::::CuratorIsNotAMemberOfGivenCuratorGroup, number_of_events_before_call, ); }) @@ -212,7 +212,7 @@ fn remove_entity_access_denied() { // Failure checked assert_failure( remove_entity_result, - ERROR_ENTITY_ACCESS_DENIED, + Error::::EntityAccessDenied, number_of_events_before_call, ); }) @@ -264,7 +264,7 @@ fn remove_entity_removal_access_denied() { // Failure checked assert_failure( remove_entity_result, - ERROR_ENTITY_REMOVAL_ACCESS_DENIED, + Error::::EntityRemovalAccessDenied, number_of_events_before_call, ); }) @@ -289,7 +289,7 @@ fn remove_entity_rc_does_not_equal_to_zero() { // Failure checked assert_failure( remove_entity_result, - ERROR_ENTITY_RC_DOES_NOT_EQUAL_TO_ZERO, + Error::::EntityRcDoesNotEqualToZero, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/remove_maintainer_from_class.rs b/runtime-modules/content-directory/src/tests/remove_maintainer_from_class.rs index 0484a44743..6b99070802 100644 --- a/runtime-modules/content-directory/src/tests/remove_maintainer_from_class.rs +++ b/runtime-modules/content-directory/src/tests/remove_maintainer_from_class.rs @@ -89,7 +89,7 @@ fn remove_maintainer_from_class_lead_auth_failed() { // Failure checked assert_failure( remove_maintainer_from_class_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -113,7 +113,7 @@ fn remove_maintainer_from_non_existent_class() { // Failure checked assert_failure( remove_maintainer_from_class_result, - ERROR_CLASS_NOT_FOUND, + Error::::ClassNotFound, number_of_events_before_call, ); }) @@ -140,7 +140,7 @@ fn remove_maintainer_that_was_not_added_to_class_maintainers_set() { // Failure checked assert_failure( remove_maintainer_from_class_result, - ERROR_MAINTAINER_DOES_NOT_EXIST, + Error::::MaintainerDoesNotExist, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/set_curator_group_status.rs b/runtime-modules/content-directory/src/tests/set_curator_group_status.rs index 8a2d485ea3..92dc040e4f 100644 --- a/runtime-modules/content-directory/src/tests/set_curator_group_status.rs +++ b/runtime-modules/content-directory/src/tests/set_curator_group_status.rs @@ -56,7 +56,7 @@ fn set_curator_group_status_lead_auth_failed() { // Failure checked assert_failure( set_curator_group_status_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -77,7 +77,7 @@ fn set_curator_group_status_for_non_existent_curator_group() { // Failure checked assert_failure( set_curator_group_status_result, - ERROR_CURATOR_GROUP_DOES_NOT_EXIST, + Error::::CuratorGroupDoesNotExist, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/transaction.rs b/runtime-modules/content-directory/src/tests/transaction.rs index a897177560..31a87df670 100644 --- a/runtime-modules/content-directory/src/tests/transaction.rs +++ b/runtime-modules/content-directory/src/tests/transaction.rs @@ -100,7 +100,7 @@ fn transaction_limit_reached() { // Failure checked assert_failure( transaction_result, - ERROR_MAX_NUMBER_OF_OPERATIONS_DURING_ATOMIC_BATCHING_LIMIT_REACHED, + Error::::NumberOfOperationsDuringAtomicBatchingLimitReached, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/transfer_entity_ownership.rs b/runtime-modules/content-directory/src/tests/transfer_entity_ownership.rs index 06d73dc113..c7a6c78932 100644 --- a/runtime-modules/content-directory/src/tests/transfer_entity_ownership.rs +++ b/runtime-modules/content-directory/src/tests/transfer_entity_ownership.rs @@ -88,7 +88,7 @@ fn transfer_entity_ownership_lead_auth_failed() { // Failure checked assert_failure( transfer_entity_ownership_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -119,7 +119,7 @@ fn transfer_entity_ownership_entity_not_found() { // Failure checked assert_failure( transfer_entity_ownership_result, - ERROR_ENTITY_NOT_FOUND, + Error::::EntityNotFound, number_of_events_before_call, ); }) @@ -155,7 +155,7 @@ fn transfer_entity_ownership_provided_entity_controller_is_equal_to_the_current_ // Failure checked assert_failure( transfer_entity_ownership_result, - ERROR_PROVIDED_ENTITY_CONTROLLER_IS_EQUAL_TO_CURRENT_ONE, + Error::::ProvidedEntityControllerIsEqualToTheCurrentOne, number_of_events_before_call, ); }) @@ -212,7 +212,7 @@ fn transfer_entity_ownership_inbound_same_owner_rc_does_not_equal_to_zero() { // Failure checked assert_failure( transfer_entity_ownership_result, - ERROR_ENTITY_SAME_OWNER_RC_DOES_NOT_EQUAL_TO_ZERO, + Error::::EntityInboundSameOwnerRcDoesNotEqualToZero, number_of_events_before_call, ); }) @@ -295,7 +295,7 @@ fn transfer_entity_ownership_provided_property_value_ids_must_be_references_with // Failure checked assert_failure( transfer_entity_ownership_result, - ERROR_ALL_PROVIDED_PROPERTY_VALUE_IDS_MUST_BE_REFERENCES_WITH_SAME_OWNER_FLAG_SET, + Error::::AllProvidedPropertyValueIdsMustBeReferencesWithSameOwnerFlagSet, number_of_events_before_call, ); }) @@ -386,7 +386,7 @@ fn transfer_entity_ownership_provided_new_property_value_referencing_entity_that // Failure checked assert_failure( transfer_entity_ownership_result, - ERROR_ENTITY_CAN_NOT_BE_REFERENCED, + Error::::EntityCanNotBeReferenced, number_of_events_before_call, ); }) @@ -451,7 +451,7 @@ fn transfer_entity_ownership_provided_new_property_value_referencing_non_existen // Failure checked assert_failure( transfer_entity_ownership_result, - ERROR_ENTITY_NOT_FOUND, + Error::::EntityNotFound, number_of_events_before_call, ); }) @@ -530,7 +530,7 @@ fn transfer_entity_ownership_provided_new_property_value_referencing_entity_cont // Failure checked assert_failure( transfer_entity_ownership_result, - ERROR_SAME_CONTROLLER_CONSTRAINT_VIOLATION, + Error::::SameControllerConstraintViolation, number_of_events_before_call, ); }) @@ -603,7 +603,7 @@ fn transfer_entity_ownership_required_property_was_not_provided() { // Failure checked assert_failure( transfer_entity_ownership_result, - ERROR_MISSING_REQUIRED_PROP, + Error::::MissingRequiredProperty, number_of_events_before_call, ); }) @@ -731,7 +731,7 @@ fn transfer_entity_ownership_unique_constraint_violation() { // Failure checked assert_failure( transfer_entity_ownership_result, - ERROR_PROPERTY_VALUE_SHOULD_BE_UNIQUE, + Error::::PropertyValueShouldBeUnique, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/update_class_permissions.rs b/runtime-modules/content-directory/src/tests/update_class_permissions.rs index e2895aeea8..875efcd451 100644 --- a/runtime-modules/content-directory/src/tests/update_class_permissions.rs +++ b/runtime-modules/content-directory/src/tests/update_class_permissions.rs @@ -83,7 +83,7 @@ fn update_class_permissions_lead_auth_failed() { // Failure checked assert_failure( update_class_permissions_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -102,7 +102,7 @@ fn update_class_permissions_of_non_existent_class() { // Failure checked assert_failure( update_class_permissions_result, - ERROR_CLASS_NOT_FOUND, + Error::::ClassNotFound, number_of_events_before_call, ); }) @@ -132,7 +132,7 @@ fn update_class_permissions_curator_group_does_not_exist() { // Failure checked assert_failure( update_class_permissions_result, - ERROR_CURATOR_GROUP_DOES_NOT_EXIST, + Error::::CuratorGroupDoesNotExist, number_of_events_before_call, ); }) @@ -171,7 +171,7 @@ fn update_class_permissions_maintainers_limit_reached() { // Failure checked assert_failure( update_class_permissions_result, - ERROR_NUMBER_OF_MAINTAINERS_PER_CLASS_LIMIT_REACHED, + Error::::ClassMaintainersLimitReached, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/update_class_schema_status.rs b/runtime-modules/content-directory/src/tests/update_class_schema_status.rs index 2236ed3c2e..dfca46d9c1 100644 --- a/runtime-modules/content-directory/src/tests/update_class_schema_status.rs +++ b/runtime-modules/content-directory/src/tests/update_class_schema_status.rs @@ -84,7 +84,7 @@ fn update_class_schema_status_lead_auth_failed() { // Failure checked assert_failure( update_class_schema_status_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -103,7 +103,7 @@ fn update_class_schema_status_of_non_existent_class() { // Failure checked assert_failure( update_class_schema_status_result, - ERROR_CLASS_NOT_FOUND, + Error::::ClassNotFound, number_of_events_before_call, ); }) @@ -138,7 +138,7 @@ fn update_class_schema_status_for_non_existent_schema() { // Failure checked assert_failure( update_class_schema_status_result, - ERROR_UNKNOWN_CLASS_SCHEMA_ID, + Error::::UnknownClassSchemaId, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/update_entity_creation_voucher.rs b/runtime-modules/content-directory/src/tests/update_entity_creation_voucher.rs index 0c93eea98f..fc855d58e0 100644 --- a/runtime-modules/content-directory/src/tests/update_entity_creation_voucher.rs +++ b/runtime-modules/content-directory/src/tests/update_entity_creation_voucher.rs @@ -132,7 +132,7 @@ fn update_entity_creation_voucher_lead_auth_failed() { // Failure checked assert_failure( update_entity_creation_voucher_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -159,7 +159,7 @@ fn update_entity_creation_voucher_class_does_not_exist() { // Failure checked assert_failure( update_entity_creation_voucher_result, - ERROR_CLASS_NOT_FOUND, + Error::::ClassNotFound, number_of_events_before_call, ); }) @@ -190,7 +190,7 @@ fn update_entity_creation_voucher_individual_creation_limit_exceed() { // Failure checked assert_failure( update_entity_creation_voucher_result, - ERROR_NUMBER_OF_CLASS_ENTITIES_PER_ACTOR_CONSTRAINT_VIOLATED, + Error::::NumberOfClassEntitiesPerActorConstraintViolated, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/update_entity_permissions.rs b/runtime-modules/content-directory/src/tests/update_entity_permissions.rs index 19f3ff3b74..e49d30a15a 100644 --- a/runtime-modules/content-directory/src/tests/update_entity_permissions.rs +++ b/runtime-modules/content-directory/src/tests/update_entity_permissions.rs @@ -73,7 +73,7 @@ fn update_entity_permissions_lead_auth_failed() { // Failure checked assert_failure( update_entity_permissions_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -97,7 +97,7 @@ fn update_entity_permissions_of_non_existent_entity() { // Failure checked assert_failure( update_entity_permissions_result, - ERROR_ENTITY_NOT_FOUND, + Error::::EntityNotFound, number_of_events_before_call, ); }) diff --git a/runtime-modules/content-directory/src/tests/update_entity_property_values.rs b/runtime-modules/content-directory/src/tests/update_entity_property_values.rs index a7c158d987..3fc8b17438 100644 --- a/runtime-modules/content-directory/src/tests/update_entity_property_values.rs +++ b/runtime-modules/content-directory/src/tests/update_entity_property_values.rs @@ -94,7 +94,7 @@ fn update_entity_property_values_entity_not_found() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_ENTITY_NOT_FOUND, + Error::::EntityNotFound, number_of_events_before_call, ); }) @@ -132,7 +132,7 @@ fn update_entity_property_values_lead_auth_failed() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_LEAD_AUTH_FAILED, + Error::::LeadAuthFailed, number_of_events_before_call, ); }) @@ -170,7 +170,7 @@ fn update_entity_property_values_member_auth_failed() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_MEMBER_AUTH_FAILED, + Error::::MemberAuthFailed, number_of_events_before_call, ); }) @@ -218,7 +218,7 @@ fn update_entity_property_values_curator_group_is_not_active() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_CURATOR_GROUP_IS_NOT_ACTIVE, + Error::::CuratorGroupIsNotActive, number_of_events_before_call, ); }) @@ -259,7 +259,7 @@ fn update_entity_property_values_curator_auth_failed() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_CURATOR_AUTH_FAILED, + Error::::CuratorAuthFailed, number_of_events_before_call, ); }) @@ -300,7 +300,7 @@ fn update_entity_property_values_curator_not_found_in_curator_group() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_CURATOR_IS_NOT_A_MEMBER_OF_A_GIVEN_CURATOR_GROUP, + Error::::CuratorIsNotAMemberOfGivenCuratorGroup, number_of_events_before_call, ); }) @@ -339,7 +339,7 @@ fn update_entity_property_values_entity_access_denied() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_ENTITY_ACCESS_DENIED, + Error::::EntityAccessDenied, number_of_events_before_call, ); }) @@ -378,7 +378,7 @@ fn update_entity_property_values_locked_on_class_level() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_ALL_PROP_WERE_LOCKED_ON_CLASS_LEVEL, + Error::::AllPropertiesWereLockedOnClassLevel, number_of_events_before_call, ); }) @@ -457,7 +457,7 @@ fn update_entity_property_values_is_locked_for_given_actor() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_CLASS_PROPERTY_TYPE_IS_LOCKED_FOR_GIVEN_ACTOR, + Error::::ClassPropertyTypeLockedForGivenActor, number_of_events_before_call, ); }) @@ -500,7 +500,7 @@ fn update_entity_property_values_unknown_entity_property_id() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_UNKNOWN_ENTITY_PROP_ID, + Error::::UnknownEntityPropertyId, number_of_events_before_call, ); }) @@ -542,7 +542,7 @@ fn update_entity_property_values_prop_value_do_not_match_type() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_PROP_VALUE_DONT_MATCH_TYPE, + Error::::PropertyValueDoNotMatchType, number_of_events_before_call, ); }) @@ -587,7 +587,7 @@ fn update_entity_property_values_vec_prop_is_too_long() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_VEC_PROP_IS_TOO_LONG, + Error::::VecPropertyTooLong, number_of_events_before_call, ); }) @@ -661,7 +661,7 @@ fn update_entity_property_values_text_prop_is_too_long() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_TEXT_PROP_IS_TOO_LONG, + Error::::TextPropertyTooLong, number_of_events_before_call, ); }) @@ -740,7 +740,7 @@ fn update_entity_property_values_hashed_text_prop_is_too_long() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_HASHED_TEXT_PROP_IS_TOO_LONG, + Error::::HashedTextPropertyTooLong, number_of_events_before_call, ); }) @@ -785,7 +785,7 @@ fn update_entity_property_values_referenced_entity_not_found() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_ENTITY_NOT_FOUND, + Error::::EntityNotFound, number_of_events_before_call, ); }) @@ -836,7 +836,7 @@ fn update_entity_property_values_referenced_entity_does_not_match_its_class() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_REFERENCED_ENTITY_DOES_NOT_MATCH_ITS_CLASS, + Error::::ReferencedEntityDoesNotMatchItsClass, number_of_events_before_call, ); }) @@ -892,7 +892,7 @@ fn update_entity_property_values_entity_can_not_be_referenced() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_ENTITY_CAN_NOT_BE_REFERENCED, + Error::::EntityCanNotBeReferenced, number_of_events_before_call, ); }) @@ -954,7 +954,7 @@ fn update_entity_property_values_same_controller_constraint_violation() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_SAME_CONTROLLER_CONSTRAINT_VIOLATION, + Error::::SameControllerConstraintViolation, number_of_events_before_call, ); }) @@ -1018,7 +1018,7 @@ fn update_entity_property_values_property_should_be_unique() { // Failure checked assert_failure( update_entity_property_values_result, - ERROR_PROPERTY_VALUE_SHOULD_BE_UNIQUE, + Error::::PropertyValueShouldBeUnique, number_of_events_before_call, ); })