diff --git a/Cargo.lock b/Cargo.lock index 0902ad6de..b272f1327 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,11 +23,11 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.24.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" dependencies = [ - "gimli 0.31.0", + "gimli 0.31.1", ] [[package]] @@ -680,11 +680,11 @@ version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ - "addr2line 0.24.1", + "addr2line 0.24.2", "cfg-if", "libc", "miniz_oxide", - "object 0.36.4", + "object 0.36.5", "rustc-demangle", "windows-targets 0.52.6", ] @@ -892,9 +892,9 @@ dependencies = [ [[package]] name = "bounded-collections" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32385ecb91a31bddaf908e8dcf4a15aef1bcd3913cc03ebfad02ff6d568abc1" +checksum = "db436177db0d505b1507f03aca56a41442ae6efdf8b6eaa855d73e52c5b078dc" dependencies = [ "log", "parity-scale-codec", @@ -926,6 +926,12 @@ dependencies = [ "semver 0.6.0", ] +[[package]] +name = "build-print" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a2128d00b7061b82b72844a351e80acd29e05afc60e9261e2ac90dca9ecc2ac" + [[package]] name = "bumpalo" version = "3.16.0" @@ -1017,9 +1023,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.24" +version = "1.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "812acba72f0a070b003d3697490d2b55b837230ae7c6c6497f05cc2ddbb8d938" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" dependencies = [ "jobserver", "libc", @@ -1164,9 +1170,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.19" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7be5744db7978a28d9df86a214130d106a89ce49644cbc4e3f0c22c3fba30615" +checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" dependencies = [ "clap_builder", "clap_derive", @@ -1174,9 +1180,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.19" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5fbc17d3ef8278f55b282b2a2e75ae6f6c7d4bb70ed3d0382375104bfafdb4b" +checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" dependencies = [ "anstream", "anstyle", @@ -2164,8 +2170,8 @@ dependencies = [ "fixed-hash", "impl-rlp", "impl-serde", - "primitive-types", - "uint", + "primitive-types 0.12.2", + "uint 0.9.5", ] [[package]] @@ -2357,6 +2363,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "foreign-types" version = "0.3.2" @@ -2713,9 +2725,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" dependencies = [ "futures-channel", "futures-core", @@ -2738,9 +2750,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -2748,15 +2760,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" dependencies = [ "futures-core", "futures-task", @@ -2766,9 +2778,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-lite" @@ -2782,9 +2794,9 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", @@ -2803,15 +2815,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-timer" @@ -2821,9 +2833,9 @@ checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-channel", "futures-core", @@ -2930,9 +2942,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.31.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "glob" @@ -3071,6 +3083,11 @@ name = "hashbrown" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] [[package]] name = "hashlink" @@ -3449,6 +3466,26 @@ dependencies = [ "parity-scale-codec", ] +[[package]] +name = "impl-codec" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67aa010c1e3da95bf151bd8b4c059b2ed7e75387cdb969b4f8f2723a43f9941" +dependencies = [ + "parity-scale-codec", +] + +[[package]] +name = "impl-num-traits" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "803d15461ab0dcc56706adf266158acbc44ccf719bf7d0af30705f58b90a4b8c" +dependencies = [ + "integer-sqrt", + "num-traits", + "uint 0.10.0", +] + [[package]] name = "impl-rlp" version = "0.3.0" @@ -3576,9 +3613,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.10.0" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" [[package]] name = "is-terminal" @@ -3650,9 +3687,9 @@ dependencies = [ [[package]] name = "jsonrpsee" -version = "0.24.5" +version = "0.24.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "126b48a5acc3c52fbd5381a77898cb60e145123179588a29e7ac48f9c06e401b" +checksum = "02f01f48e04e0d7da72280ab787c9943695699c9b32b99158ece105e8ad0afea" dependencies = [ "jsonrpsee-core", "jsonrpsee-proc-macros", @@ -3664,9 +3701,9 @@ dependencies = [ [[package]] name = "jsonrpsee-core" -version = "0.24.5" +version = "0.24.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0e503369a76e195b65af35058add0e6900b794a4e9a9316900ddd3a87a80477" +checksum = "3c2709a32915d816a6e8f625bf72cf74523ebe5d8829f895d6b041b1d3137818" dependencies = [ "async-trait", "bytes", @@ -3687,9 +3724,9 @@ dependencies = [ [[package]] name = "jsonrpsee-proc-macros" -version = "0.24.5" +version = "0.24.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc660a9389e2748e794a40673a4155d501f32db667757cdb80edeff0306b489b" +checksum = "3a9a4b2eaba8cc928f49c4ccf4fcfa65b690a73997682da99ed08f3393b51f07" dependencies = [ "heck 0.5.0", "proc-macro-crate 3.2.0", @@ -3700,9 +3737,9 @@ dependencies = [ [[package]] name = "jsonrpsee-server" -version = "0.24.5" +version = "0.24.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af6e6c9b6d975edcb443565d648b605f3e85a04ec63aa6941811a8894cc9cded" +checksum = "e30110d0f2d7866c8cc6c86483bdab2eb9f4d2f0e20db55518b2bca84651ba8e" dependencies = [ "futures-util", "http 1.1.0", @@ -3727,9 +3764,9 @@ dependencies = [ [[package]] name = "jsonrpsee-types" -version = "0.24.5" +version = "0.24.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8fb16314327cbc94fdf7965ef7e4422509cd5597f76d137bd104eb34aeede67" +checksum = "1ca331cd7b3fe95b33432825c2d4c9f5a43963e207fdc01ae67f9fd80ab0930f" dependencies = [ "http 1.1.0", "serde", @@ -3953,7 +3990,7 @@ dependencies = [ "libp2p-identity", "libp2p-swarm", "log", - "lru 0.12.4", + "lru 0.12.5", "quick-protobuf", "quick-protobuf-codec", "smallvec", @@ -4003,7 +4040,7 @@ dependencies = [ "sha2 0.10.8", "smallvec", "thiserror", - "uint", + "uint 0.9.5", "unsigned-varint 0.7.2", "void", ] @@ -4454,7 +4491,7 @@ dependencies = [ "tokio-util", "tracing", "trust-dns-resolver", - "uint", + "uint 0.9.5", "unsigned-varint 0.8.0", "url", "webpki", @@ -4491,11 +4528,11 @@ dependencies = [ [[package]] name = "lru" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ee39891760e7d94734f6f63fedc29a2e4a152f836120753a72503f09fcf904" +checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" dependencies = [ - "hashbrown 0.14.5", + "hashbrown 0.15.0", ] [[package]] @@ -5329,9 +5366,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.4" +version = "0.36.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" dependencies = [ "memchr", ] @@ -5356,12 +5393,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.20.1" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" -dependencies = [ - "portable-atomic", -] +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "opaque-debug" @@ -5917,7 +5951,7 @@ dependencies = [ "lru 0.8.1", "parity-util-mem-derive", "parking_lot 0.12.3", - "primitive-types", + "primitive-types 0.12.2", "smallvec", "winapi", ] @@ -6104,18 +6138,18 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +checksum = "baf123a161dde1e524adf36f90bc5d8d3462824a9c43553ad07a8183161189ec" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8" dependencies = [ "proc-macro2", "quote", @@ -6359,11 +6393,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" dependencies = [ "fixed-hash", - "impl-codec", + "impl-codec 0.6.0", "impl-rlp", "impl-serde", "scale-info", - "uint", + "uint 0.9.5", +] + +[[package]] +name = "primitive-types" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d15600a7d856470b7d278b3fe0e311fe28c2526348549f8ef2ff7db3299c87f5" +dependencies = [ + "fixed-hash", + "impl-codec 0.7.0", + "impl-num-traits", + "uint 0.10.0", ] [[package]] @@ -6433,9 +6479,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" dependencies = [ "unicode-ident", ] @@ -8341,9 +8387,9 @@ checksum = "f0cded6518aa0bd6c1be2b88ac81bf7044992f0f154bfbabd5ad34f43512abcb" [[package]] name = "schannel" -version = "0.1.24" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" dependencies = [ "windows-sys 0.59.0", ] @@ -9024,7 +9070,7 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.12.3", "paste", - "primitive-types", + "primitive-types 0.12.2", "rand", "scale-info", "schnorrkel", @@ -9048,7 +9094,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#90ff47d989b0498e4e88366b432486e06b1398d8" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -9124,7 +9170,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#90ff47d989b0498e4e88366b432486e06b1398d8" dependencies = [ "proc-macro2", "quote", @@ -9144,7 +9190,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#90ff47d989b0498e4e88366b432486e06b1398d8" dependencies = [ "environmental", "parity-scale-codec", @@ -9318,7 +9364,7 @@ dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", "polkavm-derive", - "primitive-types", + "primitive-types 0.12.2", "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=v1.16.0-rc1)", "sp-runtime-interface-proc-macro 17.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=v1.16.0-rc1)", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=v1.16.0-rc1)", @@ -9331,13 +9377,13 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#90ff47d989b0498e4e88366b432486e06b1398d8" dependencies = [ "bytes", "impl-trait-for-tuples", "parity-scale-codec", "polkavm-derive", - "primitive-types", + "primitive-types 0.13.1", "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk)", "sp-runtime-interface-proc-macro 17.0.0 (git+https://github.com/paritytech/polkadot-sdk)", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk)", @@ -9363,7 +9409,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#90ff47d989b0498e4e88366b432486e06b1398d8" dependencies = [ "Inflector", "expander", @@ -9452,7 +9498,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=v1.16.0-rc1#a42 [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#90ff47d989b0498e4e88366b432486e06b1398d8" [[package]] name = "sp-storage" @@ -9469,7 +9515,7 @@ dependencies = [ [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#90ff47d989b0498e4e88366b432486e06b1398d8" dependencies = [ "impl-serde", "parity-scale-codec", @@ -9504,7 +9550,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#90ff47d989b0498e4e88366b432486e06b1398d8" dependencies = [ "parity-scale-codec", "tracing", @@ -9601,7 +9647,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#90ff47d989b0498e4e88366b432486e06b1398d8" dependencies = [ "anyhow", "impl-trait-for-tuples", @@ -9656,9 +9702,9 @@ dependencies = [ [[package]] name = "ss58-registry" -version = "1.50.0" +version = "1.51.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43fce22ed1df64d04b262351c8f9d5c6da4f76f79f25ad15529792f893fad25d" +checksum = "19409f13998e55816d1c728395af0b52ec066206341d939e22e7766df9b494b8" dependencies = [ "Inflector", "num-format", @@ -9871,16 +9917,31 @@ dependencies = [ name = "subtensor" version = "0.1.0" dependencies = [ + "build-print", "node-subtensor", "node-subtensor-runtime", "proc-macro2", "quote", "rayon", + "subtensor-code-coverage", "subtensor-linting", "syn 2.0.79", "walkdir", ] +[[package]] +name = "subtensor-code-coverage" +version = "0.1.0" +dependencies = [ + "build-print", + "proc-macro2", + "procedural-fork", + "quote", + "rayon", + "syn 2.0.79", + "walkdir", +] + [[package]] name = "subtensor-custom-rpc" version = "0.0.2" @@ -10584,6 +10645,18 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "uint" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "909988d098b2f738727b161a106cfc7cab00c539c2687a8836f8e565976fb53e" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + [[package]] name = "unicode-bidi" version = "0.3.17" diff --git a/Cargo.toml b/Cargo.toml index 54de1b0a0..b99d8ac4d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,11 +15,13 @@ node-subtensor-runtime = { path = "runtime", version = "4.0.0-dev" } [build-dependencies] subtensor-linting = { path = "support/linting", version = "0.1.0" } +subtensor-code-coverage = { path = "support/code-coverage", version = "0.1.0" } +build-print.workspace = true syn.workspace = true quote.workspace = true proc-macro2.workspace = true walkdir.workspace = true -rayon = "1.10" +rayon.workspace = true [workspace] members = [ @@ -34,8 +36,8 @@ members = [ "support/macros", "support/linting", "support/procedural-fork", + "support/code-coverage", ] -exclude = ["support/procedural-fork"] resolver = "2" [workspace.lints.clippy] @@ -46,6 +48,8 @@ unwrap-used = "deny" manual_inspect = "allow" [workspace.dependencies] +rayon = "1" +build-print = "0.1" cargo-husky = { version = "1", default-features = false } clap = "4.5.4" codec = { version = "3.2.2", default-features = false } @@ -157,6 +161,8 @@ substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.16.0-rc1" } frame-metadata = "16" +procedural-fork = { version = "1.10.0-rc3", path = "support/procedural-fork" } + [profile.release] panic = "unwind" diff --git a/build.rs b/build.rs index 7261a28e1..ed2eb1a20 100644 --- a/build.rs +++ b/build.rs @@ -1,11 +1,6 @@ use rayon::prelude::*; -use std::{ - env, fs, - path::{Path, PathBuf}, - str::FromStr, - sync::mpsc::channel, -}; -use walkdir::WalkDir; +use std::{env, fs, path::Path, str::FromStr, sync::mpsc::channel}; +use subtensor_code_coverage::collect_rust_files; use subtensor_linting::*; @@ -14,7 +9,6 @@ fn main() { println!("cargo:rerun-if-changed=pallets"); println!("cargo:rerun-if-changed=node"); println!("cargo:rerun-if-changed=runtime"); - println!("cargo:rerun-if-changed=lints"); println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=src"); println!("cargo:rerun-if-changed=support"); @@ -25,6 +19,9 @@ fn main() { // Collect all Rust source files in the workspace let rust_files = collect_rust_files(workspace_root); + // Generate code coverage report + subtensor_code_coverage::analyze_files(&rust_files, workspace_root); + // Channel used to communicate errors back to the main thread from the parallel processing // as we process each Rust file let (tx, rx) = channel(); @@ -49,8 +46,7 @@ fn main() { for error in errors { let loc = error.span().start(); let file_path = relative_path.display(); - // note that spans can't go across thread boundaries without losing their location - // info so we we serialize here and send a String + // note that spans can't go across thread boundaries so we serialize here and send a String tx.send(format!( "cargo:warning={}:{}:{}: {}", file_path, loc.line, loc.column, error, @@ -59,6 +55,7 @@ fn main() { } }; + track_lint(DisallowV1Benchmarks::lint(&parsed_file)); track_lint(ForbidAsPrimitiveConversion::lint(&parsed_file)); track_lint(RequireFreezeStruct::lint(&parsed_file)); track_lint(RequireExplicitPalletIndex::lint(&parsed_file)); @@ -71,30 +68,3 @@ fn main() { println!("{error}"); } } - -/// Recursively collects all Rust files in the given directory -fn collect_rust_files(dir: &Path) -> Vec { - let mut rust_files = Vec::new(); - - for entry in WalkDir::new(dir) { - let Ok(entry) = entry else { - continue; - }; - let path = entry.path(); - - // Skip any path that contains "target" directory - if path - .components() - .any(|component| component.as_os_str() == "target") - || path.ends_with("build.rs") - { - continue; - } - - if path.is_file() && path.extension().and_then(|ext| ext.to_str()) == Some("rs") { - rust_files.push(path.to_path_buf()); - } - } - - rust_files -} diff --git a/pallets/subtensor/src/benchmarking.rs b/pallets/subtensor/src/benchmarking.rs new file mode 100644 index 000000000..7f0fbc370 --- /dev/null +++ b/pallets/subtensor/src/benchmarking.rs @@ -0,0 +1,645 @@ +//! Subtensor pallet benchmarking. +#![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)] +#![cfg(feature = "runtime-benchmarks")] + +use super::*; +use crate::Pallet as Subtensor; +use frame_benchmarking::v2::*; +use frame_support::assert_ok; +use frame_system::RawOrigin; +use sp_core::H256; +use sp_runtime::traits::{BlakeTwo256, Hash}; +use sp_std::vec; + +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn register() { + let netuid: u16 = 1; //11 is the benchmark network. + let tempo: u16 = 1; + let hotkey: T::AccountId = account("Alice", 0, 1); + let coldkey: T::AccountId = account("Test", 0, 2); + + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_network_registration_allowed(netuid, true); + Subtensor::::set_network_pow_registration_allowed(netuid, true); + + let block_number: u64 = Subtensor::::get_current_block_as_u64(); + let (nonce, work): (u64, Vec) = + Subtensor::::create_work_for_block_number(netuid, block_number, 3, &hotkey); + + #[extrinsic_call] + _( + RawOrigin::Signed(hotkey.clone()), + netuid, + block_number, + nonce, + work, + hotkey.clone(), + coldkey.clone(), + ); + } + + #[benchmark] + fn set_weights() { + // This is a whitelisted caller who can make transaction without weights. + let netuid: u16 = 1; + let version_key: u64 = 1; + let tempo: u16 = 1; + + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_max_allowed_uids(netuid, 4096); + + Subtensor::::set_network_registration_allowed(netuid, true); + Subtensor::::set_max_registrations_per_block(netuid, 4096); + Subtensor::::set_target_registrations_per_interval(netuid, 4096); + + let mut seed: u32 = 1; + let mut dests: Vec = vec![]; + let mut weights: Vec = vec![]; + let signer: T::AccountId = account("Alice", 0, seed); + + for id in 0..4096_u16 { + let hotkey: T::AccountId = account("Alice", 0, seed); + let coldkey: T::AccountId = account("Test", 0, seed); + seed += 1; + + Subtensor::::set_burn(netuid, 1); + let amount_to_be_staked = 1000000u32.into(); + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); + + Subtensor::::do_burned_registration( + RawOrigin::Signed(coldkey.clone()).into(), + netuid, + hotkey.clone(), + ) + .unwrap(); + + let uid = Subtensor::::get_uid_for_net_and_hotkey(netuid, &hotkey.clone()).unwrap(); + Subtensor::::set_validator_permit_for_uid(netuid, uid, true); + dests.push(id); + weights.push(id); + } + + #[extrinsic_call] + _( + RawOrigin::Signed(signer.clone()), + netuid, + dests, + weights, + version_key, + ); + } + + #[benchmark] + fn become_delegate() { + // This is a whitelisted caller who can make transaction without weights. + let netuid: u16 = 1; + let tempo: u16 = 1; + let seed: u32 = 1; + + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_burn(netuid, 1); + Subtensor::::set_max_allowed_uids(netuid, 4096); + + Subtensor::::set_network_registration_allowed(netuid, true); + assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + + let coldkey: T::AccountId = account("Test", 0, seed); + let hotkey: T::AccountId = account("Alice", 0, seed); + + let amount_to_be_staked = 1000000000u32.into(); + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); + + assert_ok!(Subtensor::::do_burned_registration( + RawOrigin::Signed(coldkey.clone()).into(), + netuid, + hotkey.clone() + )); + + #[extrinsic_call] + _(RawOrigin::Signed(coldkey.clone()), hotkey.clone()); + } + + #[benchmark] + fn add_stake() { + let netuid: u16 = 1; + let tempo: u16 = 1; + let seed: u32 = 1; + + Subtensor::::set_target_stakes_per_interval(100); + + Subtensor::::init_new_network(netuid, tempo); + + Subtensor::::set_burn(netuid, 1); + Subtensor::::set_network_registration_allowed(netuid, true); + + Subtensor::::set_max_allowed_uids(netuid, 4096); + assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + + let coldkey: T::AccountId = account("Test", 0, seed); + let hotkey: T::AccountId = account("Alice", 0, seed); + + let amount: u64 = 1; + let amount_to_be_staked = 1000000000u64; + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); + + assert_ok!(Subtensor::::do_burned_registration( + RawOrigin::Signed(coldkey.clone()).into(), + netuid, + hotkey.clone() + )); + + #[extrinsic_call] + _(RawOrigin::Signed(coldkey.clone()), hotkey, amount); + } + + #[benchmark] + fn remove_stake() { + let netuid: u16 = 1; + let tempo: u16 = 1; + let seed: u32 = 1; + + Subtensor::::set_target_stakes_per_interval(100); + + // Set our total stake to 1000 TAO + Subtensor::::increase_total_stake(1_000_000_000_000); + + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_network_registration_allowed(netuid, true); + + Subtensor::::set_max_allowed_uids(netuid, 4096); + assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + + let coldkey: T::AccountId = account("Test", 0, seed); + let hotkey: T::AccountId = account("Alice", 0, seed); + Subtensor::::set_burn(netuid, 1); + + let wallet_bal = 1000000u32.into(); + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), wallet_bal); + + assert_ok!(Subtensor::::do_burned_registration( + RawOrigin::Signed(coldkey.clone()).into(), + netuid, + hotkey.clone() + )); + assert_ok!(Subtensor::::do_become_delegate( + RawOrigin::Signed(coldkey.clone()).into(), + hotkey.clone(), + Subtensor::::get_default_delegate_take() + )); + + // Stake 10% of our current total staked TAO + let u64_staked_amt = 100_000_000_000; + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), u64_staked_amt); + + assert_ok!(Subtensor::::add_stake( + RawOrigin::Signed(coldkey.clone()).into(), + hotkey.clone(), + u64_staked_amt + )); + + let amount_unstaked: u64 = u64_staked_amt - 1; + + #[extrinsic_call] + _( + RawOrigin::Signed(coldkey.clone()), + hotkey.clone(), + amount_unstaked, + ); + } + + #[benchmark] + fn serve_axon() { + let caller: T::AccountId = whitelisted_caller::>(); + let caller_origin = + ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); + let netuid: u16 = 1; + let tempo: u16 = 1; + + let version: u32 = 2; + let ip: u128 = 1676056785; + let port: u16 = 128; + let ip_type: u8 = 4; + let protocol: u8 = 0; + let placeholder1: u8 = 0; + let placeholder2: u8 = 0; + + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_max_allowed_uids(netuid, 4096); + assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + + Subtensor::::set_burn(netuid, 1); + let amount_to_be_staked = 1000000u32.into(); + Subtensor::::add_balance_to_coldkey_account(&caller.clone(), amount_to_be_staked); + + assert_ok!(Subtensor::::do_burned_registration( + caller_origin.clone(), + netuid, + caller.clone() + )); + + Subtensor::::set_serving_rate_limit(netuid, 0); + + #[extrinsic_call] + _( + RawOrigin::Signed(caller.clone()), + netuid, + version, + ip, + port, + ip_type, + protocol, + placeholder1, + placeholder2, + ); + } + + #[benchmark] + fn serve_prometheus() { + let caller: T::AccountId = whitelisted_caller::>(); + let caller_origin = + ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); + let netuid: u16 = 1; + let tempo: u16 = 1; + + let version: u32 = 2; + let ip: u128 = 1676056785; + let port: u16 = 128; + let ip_type: u8 = 4; + + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_max_allowed_uids(netuid, 4096); + assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + + Subtensor::::set_burn(netuid, 1); + let amount_to_be_staked = 1000000u32.into(); + Subtensor::::add_balance_to_coldkey_account(&caller.clone(), amount_to_be_staked); + + assert_ok!(Subtensor::::do_burned_registration( + caller_origin.clone(), + netuid, + caller.clone() + )); + Subtensor::::set_serving_rate_limit(netuid, 0); + + #[extrinsic_call] + _( + RawOrigin::Signed(caller.clone()), + netuid, + version, + ip, + port, + ip_type, + ); + } + + /* + benchmark_sudo_register { + let caller: T::AccountId = whitelisted_caller::>(); + let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); + let netuid: u16 = 1; + let tempo: u16 = 0; + let modality: u16 = 0; + let stake: u64 = 10; + let balance: u64 = 1000000000; + + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_max_allowed_uids( netuid, 4096 ); + assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + + let seed : u32 = 1; + let block_number: u64 = Subtensor::::get_current_block_as_u64(); + let hotkey: T::AccountId = account("Alice", 0, seed); + let coldkey: T::AccountId = account("Test", 0, seed); + + let amount_to_be_staked = balance.into(); + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); + + }: sudo_register(RawOrigin::>::Root, netuid, hotkey, coldkey, stake, balance) + */ + #[benchmark] + fn burned_register() { + let netuid: u16 = 1; + let seed: u32 = 1; + let hotkey: T::AccountId = account("Alice", 0, seed); + let coldkey: T::AccountId = account("Test", 0, seed); + let tempo: u16 = 1; + + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_burn(netuid, 1); + + let amount_to_be_staked = 1000000u32.into(); + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); + + #[extrinsic_call] + _(RawOrigin::Signed(coldkey.clone()), netuid, hotkey); + } + + #[benchmark] + fn root_register() { + let netuid: u16 = 1; + let tempo: u16 = 1; + let seed: u32 = 1; + + Subtensor::::init_new_network(netuid, tempo); + + Subtensor::::set_burn(netuid, 1); + Subtensor::::set_network_registration_allowed(netuid, true); + + Subtensor::::set_max_allowed_uids(netuid, 4096); + assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + + let coldkey: T::AccountId = account("Test", 0, seed); + let hotkey: T::AccountId = account("Alice", 0, seed); + + let amount_to_be_staked = 100_000_000_000_000u64; + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); + + assert_ok!(Subtensor::::do_burned_registration( + RawOrigin::Signed(coldkey.clone()).into(), + netuid, + hotkey.clone() + )); + + #[extrinsic_call] + _(RawOrigin::Signed(coldkey), hotkey); + } + + #[benchmark] + fn register_network() { + let seed: u32 = 1; + + let coldkey: T::AccountId = account("Test", 0, seed); + + Subtensor::::set_network_rate_limit(1); + + let amount_to_be_staked = 100_000_000_000_000u64; + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); + + #[extrinsic_call] + _(RawOrigin::Signed(coldkey)); + } + + #[benchmark] + fn dissolve_network() { + let seed: u32 = 1; + + let coldkey: T::AccountId = account("Test", 0, seed); + + Subtensor::::set_network_rate_limit(0); + + let amount_to_be_staked = 100_000_000_000_000u64; + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); + assert_ok!(Subtensor::::register_network( + RawOrigin::Signed(coldkey.clone()).into() + )); + + #[extrinsic_call] + _(RawOrigin::Root, coldkey.clone(), 1); + } + + // swap_hotkey { + // let seed: u32 = 1; + // let coldkey: T::AccountId = account("Alice", 0, seed); + // let old_hotkey: T::AccountId = account("Bob", 0, seed); + // let new_hotkey: T::AccountId = account("Charlie", 0, seed); + + // let netuid = 1u16; + // Subtensor::::init_new_network(netuid, 100); + // Subtensor::::set_min_burn(netuid, 1); + // Subtensor::::set_max_burn(netuid, 1); + // Subtensor::::set_target_registrations_per_interval(netuid, 256); + // Subtensor::::set_max_registrations_per_block(netuid, 256); + + // Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), 10_000_000_000u64); + // assert_ok!(Subtensor::::burned_register(RawOrigin::Signed(coldkey.clone()).into(), netuid, old_hotkey.clone())); + // assert_ok!(Subtensor::::become_delegate(RawOrigin::Signed(coldkey.clone()).into(), old_hotkey.clone())); + + // let max_uids = Subtensor::::get_max_allowed_uids(netuid) as u32; + // for i in 0..max_uids - 1 { + // let coldkey: T::AccountId = account("Axon", 0, i); + // let hotkey: T::AccountId = account("Hotkey", 0, i); + + // Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), 10_000_000_000u64); + // assert_ok!(Subtensor::::burned_register(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey)); + // assert_ok!(Subtensor::::add_stake(RawOrigin::Signed(coldkey).into(), old_hotkey.clone(), 1_000_000_000)); + // } + // }: _(RawOrigin::Signed(coldkey), old_hotkey, new_hotkey) + + #[benchmark] + fn commit_weights() { + let tempo: u16 = 1; + let netuid: u16 = 1; + let version_key: u64 = 0; + let uids: Vec = vec![0]; + let weight_values: Vec = vec![10]; + let hotkey: T::AccountId = account("hot", 0, 1); + let coldkey: T::AccountId = account("cold", 0, 2); + let start_nonce = 300000; + + let commit_hash: H256 = BlakeTwo256::hash_of(&( + hotkey.clone(), + netuid, + uids.clone(), + weight_values.clone(), + version_key, + )); + + Subtensor::::init_new_network(netuid, tempo); + + let block_number: u64 = Subtensor::::get_current_block_as_u64(); + let (nonce, work): (u64, Vec) = Subtensor::::create_work_for_block_number( + netuid, + block_number, + start_nonce, + &hotkey, + ); + Subtensor::::register( + ::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())), + netuid, + block_number, + nonce, + work, + hotkey.clone(), + coldkey, + ) + .unwrap(); + Subtensor::::set_validator_permit_for_uid(netuid, 0, true); + + #[extrinsic_call] + _(RawOrigin::Signed(hotkey.clone()), netuid, commit_hash); + } + + #[benchmark] + fn reveal_weights() { + let tempo: u16 = 0; + let netuid: u16 = 1; + let version_key: u64 = 0; + let uids: Vec = vec![0]; + let weight_values: Vec = vec![10]; + let salt: Vec = vec![8]; + let hotkey: T::AccountId = account("hot", 0, 1); + let coldkey: T::AccountId = account("cold", 1, 2); + + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_network_registration_allowed(netuid, true); + Subtensor::::set_network_pow_registration_allowed(netuid, true); + + let block_number: u64 = Subtensor::::get_current_block_as_u64(); + let (nonce, work): (u64, Vec) = + Subtensor::::create_work_for_block_number(netuid, block_number, 3, &hotkey); + + let _ = Subtensor::::register( + ::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())), + netuid, + block_number, + nonce, + work.clone(), + hotkey.clone(), + coldkey.clone(), + ); + + Subtensor::::set_validator_permit_for_uid(netuid, 0, true); + Subtensor::::set_commit_reveal_weights_interval(netuid, 0); + + let commit_hash: H256 = BlakeTwo256::hash_of(&( + hotkey.clone(), + netuid, + uids.clone(), + weight_values.clone(), + salt.clone(), + version_key, + )); + let _ = Subtensor::::commit_weights( + ::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())), + netuid, + commit_hash, + ); + + #[extrinsic_call] + _( + RawOrigin::Signed(hotkey.clone()), + netuid, + uids, + weight_values, + salt, + version_key, + ); + } + + #[benchmark] + fn schedule_swap_coldkey() { + let old_coldkey: T::AccountId = account("old_cold", 0, 1); + let new_coldkey: T::AccountId = account("new_cold", 1, 2); + + #[extrinsic_call] + _(RawOrigin::Signed(old_coldkey.clone()), new_coldkey.clone()); + } + + #[benchmark] + fn schedule_dissolve_network() { + let coldkey: T::AccountId = account("coldkey", 0, 1); + let netuid = 1; + + #[extrinsic_call] + _(RawOrigin::Signed(coldkey.clone()), netuid); + } + + #[benchmark] + fn sudo_set_tx_childkey_take_rate_limit() { + // We don't need to set up any initial state for this benchmark + // as it's a simple setter function that only requires root origin + let new_rate_limit: u64 = 100; + + #[extrinsic_call] + _(RawOrigin::Root, new_rate_limit); + } + + #[benchmark] + fn set_childkey_take() { + // Setup + let netuid: u16 = 1; + let tempo: u16 = 1; + let seed: u32 = 1; + let coldkey: T::AccountId = account("Cold", 0, seed); + let hotkey: T::AccountId = account("Hot", 0, seed); + let take: u16 = 1000; // 10% in basis points + + // Initialize the network + Subtensor::::init_new_network(netuid, tempo); + + // Register the hotkey + Subtensor::::set_burn(netuid, 1); + let amount_to_be_staked = 1_000_000u32.into(); + Subtensor::::add_balance_to_coldkey_account(&coldkey, amount_to_be_staked); + assert_ok!(Subtensor::::do_burned_registration( + RawOrigin::Signed(coldkey.clone()).into(), + netuid, + hotkey.clone() + )); + + #[extrinsic_call] + _(RawOrigin::Signed(coldkey), hotkey, netuid, take); + } + + #[benchmark] + fn swap_coldkey() { + // Set up initial state + let old_coldkey: T::AccountId = account("old_coldkey", 0, 0); + let new_coldkey: T::AccountId = account("new_coldkey", 0, 0); + let hotkey1: T::AccountId = account("hotkey1", 0, 0); + let netuid = 1u16; + let stake_amount1 = 1000u64; + let stake_amount2 = 2000u64; + let swap_cost = Subtensor::::get_key_swap_cost(); + let free_balance_old = 12345u64 + swap_cost; + let tempo: u16 = 1; + + // Setup initial state + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_network_registration_allowed(netuid, true); + Subtensor::::set_network_pow_registration_allowed(netuid, true); + + let block_number: u64 = Subtensor::::get_current_block_as_u64(); + let (nonce, work): (u64, Vec) = + Subtensor::::create_work_for_block_number(netuid, block_number, 3, &hotkey1); + + let _ = Subtensor::::register( + ::RuntimeOrigin::from(RawOrigin::Signed( + old_coldkey.clone(), + )), + netuid, + block_number, + nonce, + work.clone(), + hotkey1.clone(), + old_coldkey.clone(), + ); + + // Add balance to old coldkey + Subtensor::::add_balance_to_coldkey_account( + &old_coldkey, + stake_amount1 + stake_amount2 + free_balance_old, + ); + + // Insert an Identity + let name: Vec = b"The fourth Coolest Identity".to_vec(); + let identity: ChainIdentity = ChainIdentity { + name: name.clone(), + url: vec![], + image: vec![], + discord: vec![], + description: vec![], + additional: vec![], + }; + + Identities::::insert(&old_coldkey, identity); + + // Benchmark setup complete, now execute the extrinsic + #[extrinsic_call] + _(RawOrigin::Root, old_coldkey.clone(), new_coldkey.clone()); + } +} diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs deleted file mode 100644 index 4915bb3ac..000000000 --- a/pallets/subtensor/src/benchmarks.rs +++ /dev/null @@ -1,524 +0,0 @@ -//! Subtensor pallet benchmarking. -#![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)] -#![cfg(feature = "runtime-benchmarks")] - -use crate::Pallet as Subtensor; -use crate::*; -use frame_benchmarking::{account, benchmarks, whitelisted_caller}; -use frame_support::assert_ok; -use frame_system::RawOrigin; -pub use pallet::*; -use sp_core::H256; -use sp_runtime::traits::{BlakeTwo256, Hash}; -use sp_std::vec; - -benchmarks! { - // Add individual benchmarks here - benchmark_register { - let netuid: u16 = 1; //11 is the benchmark network. - let tempo: u16 = 1; - let modality: u16 = 0; - let hotkey: T::AccountId = account("Alice", 0, 1); - let coldkey: T::AccountId = account("Test", 0, 2); - - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_network_registration_allowed(netuid, true); - Subtensor::::set_network_pow_registration_allowed(netuid, true); - - let block_number: u64 = Subtensor::::get_current_block_as_u64(); - let (nonce, work): (u64, Vec) = Subtensor::::create_work_for_block_number( - netuid, - block_number, - 3, - &hotkey, - ); - - - }: register( RawOrigin::Signed( hotkey.clone() ), netuid, block_number, nonce, work, hotkey.clone(), coldkey.clone() ) - - benchmark_set_weights { - - // This is a whitelisted caller who can make transaction without weights. - let netuid: u16 = 1; - let version_key: u64 = 1; - let tempo: u16 = 1; - let modality: u16 = 0; - - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_max_allowed_uids( netuid, 4096 ); - - Subtensor::::set_network_registration_allowed( netuid, true ); - Subtensor::::set_max_registrations_per_block( netuid, 4096 ); - Subtensor::::set_target_registrations_per_interval( netuid, 4096 ); - - let mut seed : u32 = 1; - let mut dests: Vec = vec![]; - let mut weights: Vec = vec![]; - let signer : T::AccountId = account("Alice", 0, seed); - - for id in 0..4096_u16 { - let hotkey: T::AccountId = account("Alice", 0, seed); - let coldkey: T::AccountId = account("Test", 0, seed); - seed += 1; - - Subtensor::::set_burn(netuid, 1); - let amount_to_be_staked = 1000000u32.into(); - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - - Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())?; - - let uid = Subtensor::::get_uid_for_net_and_hotkey(netuid, &hotkey.clone()).unwrap(); - Subtensor::::set_validator_permit_for_uid(netuid, uid, true); - dests.push(id); - weights.push(id); - } - - }: set_weights(RawOrigin::Signed( signer.clone() ), netuid, dests, weights, version_key) - - - benchmark_become_delegate { - // This is a whitelisted caller who can make transaction without weights. - let caller: T::AccountId = whitelisted_caller::>(); - let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); - let netuid: u16 = 1; - let version_key: u64 = 1; - let tempo: u16 = 1; - let modality: u16 = 0; - let seed : u32 = 1; - - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_burn(netuid, 1); - Subtensor::::set_max_allowed_uids( netuid, 4096 ); - - Subtensor::::set_network_registration_allowed( netuid, true); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); - - let coldkey: T::AccountId = account("Test", 0, seed); - let hotkey: T::AccountId = account("Alice", 0, seed); - - let amount_to_be_staked = 1000000000u32.into(); - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - - assert_ok!(Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())); - }: become_delegate(RawOrigin::Signed( coldkey.clone() ), hotkey.clone()) - - benchmark_add_stake { - let caller: T::AccountId = whitelisted_caller::>(); - let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); - let netuid: u16 = 1; - let version_key: u64 = 1; - let tempo: u16 = 1; - let modality: u16 = 0; - let seed : u32 = 1; - - Subtensor::::set_target_stakes_per_interval(100); - - Subtensor::::init_new_network(netuid, tempo); - - Subtensor::::set_burn(netuid, 1); - Subtensor::::set_network_registration_allowed( netuid, true ); - - Subtensor::::set_max_allowed_uids( netuid, 4096 ); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); - - let coldkey: T::AccountId = account("Test", 0, seed); - let hotkey: T::AccountId = account("Alice", 0, seed); - - let amount: u64 = 1; - let amount_to_be_staked = 1000000000u64; - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - - assert_ok!(Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())); - }: add_stake(RawOrigin::Signed( coldkey.clone() ), hotkey, amount) - - benchmark_remove_stake{ - let caller: T::AccountId = whitelisted_caller::>(); - let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); - let netuid: u16 = 1; - let version_key: u64 = 1; - let tempo: u16 = 1; - let modality: u16 = 0; - let seed : u32 = 1; - - Subtensor::::set_target_stakes_per_interval(100); - - // Set our total stake to 1000 TAO - Subtensor::::increase_total_stake(1_000_000_000_000); - - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_network_registration_allowed( netuid, true ); - - Subtensor::::set_max_allowed_uids( netuid, 4096 ); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); - - let coldkey: T::AccountId = account("Test", 0, seed); - let hotkey: T::AccountId = account("Alice", 0, seed); - Subtensor::::set_burn(netuid, 1); - - let wallet_bal = 1000000u32.into(); - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), wallet_bal); - - assert_ok!(Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())); - assert_ok!(Subtensor::::do_become_delegate(RawOrigin::Signed(coldkey.clone()).into(), hotkey.clone(), Subtensor::::get_default_delegate_take())); - - // Stake 10% of our current total staked TAO - let u64_staked_amt = 100_000_000_000; - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), u64_staked_amt); - - assert_ok!( Subtensor::::add_stake(RawOrigin::Signed( coldkey.clone() ).into() , hotkey.clone(), u64_staked_amt)); - - let amount_unstaked: u64 = u64_staked_amt - 1; - }: remove_stake(RawOrigin::Signed( coldkey.clone() ), hotkey.clone(), amount_unstaked) - - benchmark_serve_axon{ - let caller: T::AccountId = whitelisted_caller::>(); - let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); - let netuid: u16 = 1; - let tempo: u16 = 1; - let modality: u16 = 0; - - let version: u32 = 2; - let ip: u128 = 1676056785; - let port: u16 = 128; - let ip_type: u8 = 4; - let protocol: u8 = 0; - let placeholder1: u8 = 0; - let placeholder2: u8 = 0; - - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_max_allowed_uids( netuid, 4096 ); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); - - Subtensor::::set_burn(netuid, 1); - let amount_to_be_staked = 1000000u32.into(); - Subtensor::::add_balance_to_coldkey_account(&caller.clone(), amount_to_be_staked); - - assert_ok!(Subtensor::::do_burned_registration(caller_origin.clone(), netuid, caller.clone())); - - Subtensor::::set_serving_rate_limit(netuid, 0); - - }: serve_axon(RawOrigin::Signed( caller.clone() ), netuid, version, ip, port, ip_type, protocol, placeholder1, placeholder2) - - benchmark_serve_prometheus { - let caller: T::AccountId = whitelisted_caller::>(); - let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); - let netuid: u16 = 1; - let tempo: u16 = 1; - let modality: u16 = 0; - - let version: u32 = 2; - let ip: u128 = 1676056785; - let port: u16 = 128; - let ip_type: u8 = 4; - - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_max_allowed_uids( netuid, 4096 ); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); - - Subtensor::::set_burn(netuid, 1); - let amount_to_be_staked = 1000000u32.into(); - Subtensor::::add_balance_to_coldkey_account(&caller.clone(), amount_to_be_staked); - - assert_ok!(Subtensor::::do_burned_registration(caller_origin.clone(), netuid, caller.clone())); - Subtensor::::set_serving_rate_limit(netuid, 0); - - }: serve_prometheus(RawOrigin::Signed( caller.clone() ), netuid, version, ip, port, ip_type) - - /* - benchmark_sudo_register { - let caller: T::AccountId = whitelisted_caller::>(); - let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); - let netuid: u16 = 1; - let tempo: u16 = 0; - let modality: u16 = 0; - let stake: u64 = 10; - let balance: u64 = 1000000000; - - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_max_allowed_uids( netuid, 4096 ); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); - - let seed : u32 = 1; - let block_number: u64 = Subtensor::::get_current_block_as_u64(); - let hotkey: T::AccountId = account("Alice", 0, seed); - let coldkey: T::AccountId = account("Test", 0, seed); - - let amount_to_be_staked = balance.into(); - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - - }: sudo_register(RawOrigin::>::Root, netuid, hotkey, coldkey, stake, balance) - */ - benchmark_burned_register { - let netuid: u16 = 1; - let seed : u32 = 1; - let hotkey: T::AccountId = account("Alice", 0, seed); - let coldkey: T::AccountId = account("Test", 0, seed); - let modality: u16 = 0; - let tempo: u16 = 1; - - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_burn(netuid, 1); - - let amount_to_be_staked = 1000000u32.into(); - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - - }: burned_register(RawOrigin::Signed( coldkey.clone() ), netuid, hotkey) - - - benchmark_root_register { - let netuid: u16 = 1; - let version_key: u64 = 1; - let tempo: u16 = 1; - let seed : u32 = 1; - - Subtensor::::init_new_network(netuid, tempo); - - Subtensor::::set_burn(netuid, 1); - Subtensor::::set_network_registration_allowed( netuid, true); - - Subtensor::::set_max_allowed_uids( netuid, 4096 ); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); - - let coldkey: T::AccountId = account("Test", 0, seed); - let hotkey: T::AccountId = account("Alice", 0, seed); - - let amount: u64 = 1; - let amount_to_be_staked = 100_000_000_000_000u64; - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - - assert_ok!(Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())); - }: root_register(RawOrigin::Signed(coldkey), hotkey) - - benchmark_register_network { - let seed : u32 = 1; - - let coldkey: T::AccountId = account("Test", 0, seed); - - Subtensor::::set_network_rate_limit(1); - - let amount: u64 = 1; - let amount_to_be_staked = 100_000_000_000_000u64; - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - }: register_network(RawOrigin::Signed(coldkey)) - - benchmark_dissolve_network { - let seed : u32 = 1; - - let coldkey: T::AccountId = account("Test", 0, seed); - - Subtensor::::set_network_rate_limit(0); - - let amount: u64 = 1; - let amount_to_be_staked = 100_000_000_000_000u64; - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - assert_ok!(Subtensor::::register_network(RawOrigin::Signed(coldkey.clone()).into())); - }: dissolve_network(RawOrigin::Root, coldkey.clone(), 1) - - - // swap_hotkey { - // let seed: u32 = 1; - // let coldkey: T::AccountId = account("Alice", 0, seed); - // let old_hotkey: T::AccountId = account("Bob", 0, seed); - // let new_hotkey: T::AccountId = account("Charlie", 0, seed); - - // let netuid = 1u16; - // Subtensor::::init_new_network(netuid, 100); - // Subtensor::::set_min_burn(netuid, 1); - // Subtensor::::set_max_burn(netuid, 1); - // Subtensor::::set_target_registrations_per_interval(netuid, 256); - // Subtensor::::set_max_registrations_per_block(netuid, 256); - - // Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), 10_000_000_000u64); - // assert_ok!(Subtensor::::burned_register(RawOrigin::Signed(coldkey.clone()).into(), netuid, old_hotkey.clone())); - // assert_ok!(Subtensor::::become_delegate(RawOrigin::Signed(coldkey.clone()).into(), old_hotkey.clone())); - - // let max_uids = Subtensor::::get_max_allowed_uids(netuid) as u32; - // for i in 0..max_uids - 1 { - // let coldkey: T::AccountId = account("Axon", 0, i); - // let hotkey: T::AccountId = account("Hotkey", 0, i); - - // Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), 10_000_000_000u64); - // assert_ok!(Subtensor::::burned_register(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey)); - // assert_ok!(Subtensor::::add_stake(RawOrigin::Signed(coldkey).into(), old_hotkey.clone(), 1_000_000_000)); - // } - // }: _(RawOrigin::Signed(coldkey), old_hotkey, new_hotkey) - - commit_weights { - let tempo: u16 = 1; - let netuid: u16 = 1; - let version_key: u64 = 0; - let uids: Vec = vec![0]; - let weight_values: Vec = vec![10]; - let hotkey: T::AccountId = account("hot", 0, 1); - let coldkey: T::AccountId = account("cold", 0, 2); - let start_nonce = 300000; - - let commit_hash: H256 = BlakeTwo256::hash_of(&( - hotkey.clone(), - netuid, - uids.clone(), - weight_values.clone(), - version_key, - )); - - Subtensor::::init_new_network(netuid, tempo); - - let block_number: u64 = Subtensor::::get_current_block_as_u64(); - let (nonce, work): (u64, Vec) = Subtensor::::create_work_for_block_number( - netuid, - block_number, - start_nonce, - &hotkey, - ); - let result = Subtensor::::register( - ::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())), - netuid, - block_number, - nonce, - work, - hotkey.clone(), - coldkey, - ); - Subtensor::::set_validator_permit_for_uid(netuid, 0, true); - -}: commit_weights(RawOrigin::Signed(hotkey.clone()), netuid, commit_hash) - -reveal_weights { - let tempo: u16 = 0; - let netuid: u16 = 1; - let version_key: u64 = 0; - let uids: Vec = vec![0]; - let weight_values: Vec = vec![10]; - let salt: Vec = vec![8]; - let hotkey: T::AccountId = account("hot", 0, 1); - let coldkey: T::AccountId = account("cold", 1, 2); - - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_network_registration_allowed(netuid, true); - Subtensor::::set_network_pow_registration_allowed(netuid, true); - - let block_number: u64 = Subtensor::::get_current_block_as_u64(); - let (nonce, work): (u64, Vec) = Subtensor::::create_work_for_block_number( - netuid, - block_number, - 3, - &hotkey, - ); - - let _ = Subtensor::::register( - ::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())), - netuid, - block_number, - nonce, - work.clone(), - hotkey.clone(), - coldkey.clone(), - ); - - Subtensor::::set_validator_permit_for_uid(netuid, 0, true); - Subtensor::::set_commit_reveal_weights_interval(netuid, 0); - - let commit_hash: H256 = BlakeTwo256::hash_of(&( - hotkey.clone(), - netuid, - uids.clone(), - weight_values.clone(), - salt.clone(), - version_key, - )); - let _ = Subtensor::::commit_weights(::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())), netuid, commit_hash); - - }: reveal_weights(RawOrigin::Signed(hotkey.clone()), netuid, uids, weight_values, salt, version_key) - - schedule_swap_coldkey { - let old_coldkey: T::AccountId = account("old_cold", 0, 1); - let new_coldkey: T::AccountId = account("new_cold", 1, 2); - }: schedule_swap_coldkey(RawOrigin::Signed(old_coldkey.clone()), new_coldkey.clone()) - - schedule_dissolve_network { - let coldkey: T::AccountId = account("coldkey", 0, 1); - let netuid = 1; - }: schedule_dissolve_network(RawOrigin::Signed(coldkey.clone()), netuid) - benchmark_sudo_set_tx_childkey_take_rate_limit { - // We don't need to set up any initial state for this benchmark - // as it's a simple setter function that only requires root origin - let new_rate_limit: u64 = 100; -}: sudo_set_tx_childkey_take_rate_limit(RawOrigin::Root, new_rate_limit) - - benchmark_set_childkey_take { - // Setup - let netuid: u16 = 1; - let tempo: u16 = 1; - let seed: u32 = 1; - let coldkey: T::AccountId = account("Cold", 0, seed); - let hotkey: T::AccountId = account("Hot", 0, seed); - let take: u16 = 1000; // 10% in basis points - - // Initialize the network - Subtensor::::init_new_network(netuid, tempo); - - // Register the hotkey - Subtensor::::set_burn(netuid, 1); - let amount_to_be_staked = 1_000_000u32.into(); - Subtensor::::add_balance_to_coldkey_account(&coldkey, amount_to_be_staked); - assert_ok!(Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())); -}: set_childkey_take(RawOrigin::Signed(coldkey), hotkey, netuid, take) - - swap_coldkey { - // Set up initial state - let old_coldkey: T::AccountId = account("old_coldkey", 0, 0); - let new_coldkey: T::AccountId = account("new_coldkey", 0, 0); - let hotkey1: T::AccountId = account("hotkey1", 0, 0); - let netuid = 1u16; - let stake_amount1 = 1000u64; - let stake_amount2 = 2000u64; - let swap_cost = Subtensor::::get_key_swap_cost(); - let free_balance_old = 12345u64 + swap_cost; - let tempo: u16 = 1; - - // Setup initial state - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_network_registration_allowed(netuid, true); - Subtensor::::set_network_pow_registration_allowed(netuid, true); - - let block_number: u64 = Subtensor::::get_current_block_as_u64(); - let (nonce, work): (u64, Vec) = Subtensor::::create_work_for_block_number( - netuid, - block_number, - 3, - &hotkey1, - ); - - let _ = Subtensor::::register( - ::RuntimeOrigin::from(RawOrigin::Signed(old_coldkey.clone())), - netuid, - block_number, - nonce, - work.clone(), - hotkey1.clone(), - old_coldkey.clone(), - ); - - // Add balance to old coldkey - Subtensor::::add_balance_to_coldkey_account( - &old_coldkey, - stake_amount1 + stake_amount2 + free_balance_old, - ); - - // Insert an Identity - let name: Vec = b"The fourth Coolest Identity".to_vec(); - let identity: ChainIdentity = ChainIdentity { - name: name.clone(), - url: vec![], - image: vec![], - discord: vec![], - description: vec![], - additional: vec![], - }; - - Identities::::insert(&old_coldkey, identity); - - // Benchmark setup complete, now execute the extrinsic -}: swap_coldkey(RawOrigin::Root, old_coldkey.clone(), new_coldkey.clone()) - -} diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index cc3d7d025..ebd3baefd 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -31,7 +31,7 @@ use sp_std::marker::PhantomData; // ============================ // ==== Benchmark Imports ===== // ============================ -mod benchmarks; +mod benchmarking; // ========================= // ==== Pallet Imports ===== diff --git a/support/code-coverage/Cargo.toml b/support/code-coverage/Cargo.toml new file mode 100644 index 000000000..0e19c2bb4 --- /dev/null +++ b/support/code-coverage/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "subtensor-code-coverage" +version = "0.1.0" +edition = "2021" + +[dependencies] +build-print.workspace = true +syn.workspace = true +quote.workspace = true +proc-macro2.workspace = true +procedural-fork.workspace = true +walkdir.workspace = true +rayon.workspace = true + +[lints] +workspace = true diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs new file mode 100644 index 000000000..ee3ab42cd --- /dev/null +++ b/support/code-coverage/src/lib.rs @@ -0,0 +1,601 @@ +use build_print::*; +use proc_macro2::TokenStream as TokenStream2; +use procedural_fork::{exports::pallet::parse::Def, simulate_manifest_dir}; +use quote::ToTokens; +use rayon::{ + iter::{IntoParallelRefIterator, ParallelIterator}, + slice::ParallelSliceMut, +}; +use std::{ + collections::{HashMap, HashSet}, + ffi::OsStr, + fs::{self}, + path::{Path, PathBuf}, + str::FromStr, +}; +use syn::{visit::Visit, Attribute, File, Ident, ItemFn, ItemMod}; +use walkdir::WalkDir; + +/// Code coverage information for a pallet +#[derive(Default, Debug, PartialEq, Eq, Clone)] +pub struct PalletInfo { + pub path: PathBuf, + pub pallet_name: String, + pub methods: Vec, +} + +/// Recursively collects all Rust files in the given directory +pub fn collect_rust_files(dir: &Path) -> Vec { + let mut rust_files = Vec::new(); + + for entry in WalkDir::new(dir) { + let Ok(entry) = entry else { + continue; + }; + let path = entry.path(); + + // Skip any path that contains "target" directory + if path.components().any(|component| { + component.as_os_str() == "target" || component.as_os_str() == "procedural-fork" + }) || path.ends_with("build.rs") + { + continue; + } + + if path.is_file() && path.extension().and_then(|ext| ext.to_str()) == Some("rs") { + rust_files.push(path.to_path_buf()); + } + } + + rust_files +} + +pub fn analyze_files(rust_files: &[PathBuf], workspace_root: &Path) -> Vec { + custom_println!("[code-coverage]", cyan, "generating coverage report..."); + let start = std::time::Instant::now(); + custom_println!( + "[code-coverage]", + cyan, + "searching {} rust files for pallets in parallel...", + rust_files.len() + ); + let infos = rust_files + .par_iter() + .map(|path| { + if path.display().to_string().contains("test") { + return Vec::new(); + } + analyze_file(path, workspace_root) + }) + .reduce(Vec::new, |mut acc, mut infos| { + acc.append(&mut infos); + acc + }); + + custom_println!( + "[code-coverage]", + cyan, + "searching {} rust files for tests in parallel...", + rust_files.len() + ); + let tests = find_tests(rust_files); + let benchmarks = find_benchmarks(rust_files); + + let methods = infos + .iter() + .flat_map(|i| i.methods.iter()) + .collect::>(); + + custom_println!("[code-coverage]", green, "found {} tests", tests.len()); + custom_println!( + "[code-coverage]", + green, + "found {} benchmarks", + benchmarks.len() + ); + + custom_println!( + "[code-coverage]", + green, + "found {} unique calls across {} pallets", + methods.len(), + infos.len(), + ); + + custom_println!("[code-coverage]", cyan, "compiling statistics..."); + + let mut coverage: HashMap = HashMap::new(); + // this takes about 6ms serially so better to keep serial for now + for method in &methods { + coverage + .entry(method.strip_prefix("sudo_").unwrap_or(method).to_string()) + .or_insert(0); + } + for test in &tests { + for method in &test.method_calls { + let method = method.strip_prefix("sudo_").unwrap_or(method); + let Some(count) = coverage.get_mut(method) else { + continue; + }; + *count += 1; + } + } + // if a call is in a benchmark, we can consider it tested since a benchmark test is + // auto-generated + for benchmark in &benchmarks { + for call in &benchmark.calls { + let call = call.strip_prefix("sudo_").unwrap_or(call); + let Some(count) = coverage.get_mut(call) else { + continue; + }; + *count += 1; + } + } + let mut coverage = coverage.into_iter().collect::>(); + coverage.par_sort_by_key(|(_, v)| *v); + + let (covered, uncovered) = coverage.iter().partition::, _>(|(_, v)| *v > 0); + + custom_println!( + "[code-coverage]", + cyan, + " total covered: {}", + covered.len() + ); + custom_println!( + "[code-coverage]", + cyan, + " total uncovered: {}", + uncovered.len() + ); + custom_println!( + "[code-coverage]", + cyan, + " total coverage: {:.2}%", + covered.len() as f64 / methods.len() as f64 * 100.0 + ); + + let finish = std::time::Instant::now(); + custom_println!( + "[code-coverage]", + green, + "coverage report generated in {:?}", + finish - start + ); + infos +} + +fn analyze_file(path: &Path, root_path: &Path) -> Vec { + let Ok(content) = fs::read_to_string(path) else { + return Vec::new(); + }; + let Ok(parsed_tokens) = TokenStream2::from_str(&content) else { + return Vec::new(); + }; + let Ok(file) = syn::parse2::(parsed_tokens) else { + return Vec::new(); + }; + let mut infos = Vec::new(); + PalletVisitor::for_each_pallet(&file, path, root_path, |_item_mod, pallet: &Def| { + custom_println!( + "[code-coverage]", + green, + "parsed pallet '{}' ({})", + extract_pallet_name(path).unwrap_or("unknown".to_string()), + strip_common_suffix("/src/lib.rs".as_ref(), strip_common_prefix(root_path, path)) + .display(), + ); + let mut info = PalletInfo::default(); + info.path = path.to_path_buf(); + info.pallet_name = extract_pallet_name(path).unwrap_or("pallet".to_string()); + + // collect all Call methods + if let Some(call) = &pallet.call { + info.methods + .append(&mut call.methods.iter().map(|m| m.name.to_string()).collect()); + } + + infos.push(info); + }); + infos +} + +#[derive(Default, Debug, Clone, PartialEq, Eq)] +pub struct TestInfo { + pub path: PathBuf, + pub name: String, + pub method_calls: HashSet, +} + +/// Finds all tests in the given set of rust files, using a parallel map-reduce. +pub fn find_tests(rust_files: &[PathBuf]) -> Vec { + rust_files + .par_iter() + .map(|path| { + let Ok(content) = fs::read_to_string(path) else { + return Vec::new(); + }; + let Ok(file) = syn::parse_file(&content) else { + return Vec::new(); + }; + let mut visitor = TestVisitor { tests: Vec::new() }; + visitor.visit_file(&file); + visitor + .tests + .into_iter() + .map(|f| { + let mut method_calls = HashSet::new(); + let mut visitor = MethodCallVisitor { + method_calls: &mut method_calls, + }; + visitor.visit_item_fn(&f); + TestInfo { + path: path.clone(), + name: f.sig.ident.to_string(), + method_calls, + } + }) + .collect() + }) + .reduce(Vec::new, |mut acc, mut infos| { + acc.append(&mut infos); + acc + }) +} + +#[derive(Default, Debug, Clone, PartialEq, Eq)] +pub struct BenchmarkInfo { + pub calls: HashSet, +} + +/// Finds all benchmarks in the given set of rust files, using a parallel map-reduce +pub fn find_benchmarks(rust_files: &[PathBuf]) -> Vec { + rust_files + .par_iter() + .map(|path| { + let Ok(content) = fs::read_to_string(path) else { + return Vec::new(); + }; + let Ok(file) = syn::parse_file(&content) else { + return Vec::new(); + }; + let mut visitor = BenchmarkVisitor { + benchmarks: Vec::new(), + }; + visitor.visit_file(&file); + visitor + .benchmarks + .into_iter() + .map(|f| { + let mut calls = HashSet::new(); + let mut visitor = CallVisitor { calls: &mut calls }; + visitor.visit_item_fn(&f); + BenchmarkInfo { calls } + }) + .collect() + }) + .reduce(Vec::new, |mut acc, mut infos| { + acc.append(&mut infos); + acc + }) +} + +pub struct CallVisitor<'a> { + pub calls: &'a mut HashSet, +} + +impl<'ast> Visit<'ast> for CallVisitor<'_> { + fn visit_expr_call(&mut self, i: &'ast syn::ExprCall) { + if let syn::Expr::Path(expr) = &*i.func { + if let Some(seg) = expr.path.segments.last() { + self.calls.insert(seg.ident.to_string()); + } + } + syn::visit::visit_expr_call(self, i); + } +} + +pub struct MethodCallVisitor<'a> { + pub method_calls: &'a mut HashSet, +} + +impl<'ast> Visit<'ast> for MethodCallVisitor<'_> { + fn visit_expr_method_call(&mut self, i: &'ast syn::ExprMethodCall) { + self.method_calls.insert(i.method.to_string()); + syn::visit::visit_expr_method_call(self, i); + } + + fn visit_expr_path(&mut self, i: &'ast syn::ExprPath) { + self.method_calls + .insert(i.path.segments.last().unwrap().ident.to_string()); + syn::visit::visit_expr_path(self, i); + } +} + +pub struct TestVisitor { + pub tests: Vec, +} + +impl<'ast> Visit<'ast> for TestVisitor { + fn visit_item_fn(&mut self, item_fn: &'ast ItemFn) { + if item_fn.attrs.iter().any(|attr| { + let Some(seg) = attr.path().segments.last() else { + return false; + }; + seg.ident == "test" || seg.ident == "should_panic" + }) { + self.tests.push(item_fn.clone()); + } + syn::visit::visit_item_fn(self, item_fn); + } +} + +pub struct BenchmarkVisitor { + pub benchmarks: Vec, +} + +impl<'ast> Visit<'ast> for BenchmarkVisitor { + fn visit_item_fn(&mut self, item_fn: &'ast ItemFn) { + if item_fn.attrs.iter().any(|attr| { + let Some(seg) = attr.path().segments.last() else { + return false; + }; + seg.ident == "benchmark" + }) { + self.benchmarks.push(item_fn.clone()); + } + syn::visit::visit_item_fn(self, item_fn); + } +} + +/// Tries to parse a pallet from a module +pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path, root_path: &Path) -> Option { + simulate_manifest_dir("pallets/subtensor", || -> Option { + // skip non-inline modules + let mut item_mod = item_mod.clone(); + let Some((_, ref mut content)) = item_mod.content else { + return None; + }; + + // skip non-pallet modules + if item_mod.ident != "pallet" { + return None; + } + + let mut section_announced = false; + + // manually import foreign sections defined by the `#[import_section]` attribute + for attr in item_mod.attrs.iter() { + if attr.meta.path().segments.last().unwrap().ident != "import_section" { + continue; + } + + // Extract the section name from the attribute's args + let Ok(inner_path) = attr.parse_args::() else { + continue; + }; + let section_name = &inner_path.segments.last().unwrap().ident; + + if !section_announced { + custom_println!( + "[code-coverage]", + cyan, + "importing pallet sections for '{}' ({})...", + extract_pallet_name(file_path).unwrap_or("unknown".to_string()), + strip_common_suffix( + "/src/lib.rs".as_ref(), + strip_common_prefix(root_path, file_path) + ) + .display(), + ); + section_announced = true; + } + + if let Some((section_mod, section_path)) = + find_matching_pallet_section(file_path, section_name) + { + let Some((_, mut section_content)) = section_mod.content else { + continue; + }; + content.append(&mut section_content); + custom_println!( + "[code-coverage]", + cyan, + "└ imported '{}' ({})", + section_name, + strip_common_suffix( + "/src/lib.rs".as_ref(), + strip_common_prefix(file_path, §ion_path) + ) + .display() + ); + } else { + custom_println!( + "[code-coverage]", + red, + "could not find matching section for: '{}'", + section_name, + ); + } + } + + if let Ok(pallet) = Def::try_from(item_mod.clone(), false) { + Some(pallet) + } else if let Ok(pallet) = Def::try_from(item_mod.clone(), true) { + Some(pallet) + } else { + let err = match Def::try_from(item_mod.clone(), false) { + Err(e) => e, + Ok(_) => unreachable!(), + }; + custom_println!( + "[code-coverage]", + red, + "unable to parse pallet in {}:", + file_path.display() + ); + custom_println!("[code-coverage]", red, "{}", err); + None + } + }) +} + +fn find_matching_pallet_section( + src_path: &Path, + section_name: &Ident, +) -> Option<(ItemMod, PathBuf)> { + let Some(base_path) = src_path.parent() else { + return None; + }; + let rust_files = WalkDir::new(base_path.parent().unwrap()) + .into_iter() + .filter_map(Result::ok) + .filter(|e| { + e.path() != src_path + && e.path().is_file() + && e.path().extension() == Some(OsStr::new("rs")) + }) + .map(|e| e.path().to_path_buf()) + .collect::>(); + let section_name = section_name.to_string().trim().to_string(); + rust_files + .par_iter() + .find_map_any(|path| { + if path.display().to_string().contains("test") { + return None; + } + let Ok(content) = fs::read_to_string(path) else { + return None; + }; + let Ok(file) = syn::parse_file(&content) else { + return None; + }; + for item in file.items { + let syn::Item::Mod(item_mod) = item else { + continue; + }; + if item_mod.ident != section_name { + continue; + } + if item_mod.attrs.iter().any(is_pallet_section) { + // can't move ItemMod across thread boundaries + return Some((item_mod.to_token_stream().to_string(), path.to_path_buf())); + } + } + None + }) + .map(|(s, p)| (syn::parse_str::(&s).unwrap(), p)) // can't move ItemMod across thread boundaries +} + +fn is_pallet_section(attr: &Attribute) -> bool { + attr.meta.path().segments.last().unwrap().ident != "pallet_section" +} + +/// A visitor that collects pallets from a file/module +#[derive(Default)] +pub struct PalletVisitor { + pub pallets: Vec<(ItemMod, Def)>, + pub file_path: PathBuf, + pub workspace_root_path: PathBuf, +} + +impl PalletVisitor { + pub fn for_each_pallet(file: &File, file_path: &Path, root_path: &Path, mut f: F) -> Self + where + F: FnMut(&ItemMod, &Def), + { + let mut visitor = PalletVisitor { + pallets: Vec::new(), + file_path: file_path.to_path_buf(), + workspace_root_path: root_path.to_path_buf(), + }; + visitor.visit_file(file); + for (item_mod, pallet) in &visitor.pallets { + f(item_mod, pallet); + } + visitor + } +} + +impl<'ast> Visit<'ast> for PalletVisitor { + fn visit_item_mod(&mut self, item_mod: &'ast ItemMod) { + if let Some(pallet) = try_parse_pallet(item_mod, &self.file_path, &self.workspace_root_path) + { + self.pallets.push((item_mod.clone(), pallet)); + } + syn::visit::visit_item_mod(self, item_mod); + } +} + +/// Extracts the pallet name from a path +pub fn extract_pallet_name(path: &Path) -> Option { + // Try to get the parent directory, then the directory name + path.parent()? + .parent()? // Go up one level to the "pallets" directory + .file_name() // Get the directory name "subtensor" + .and_then(|os_str| os_str.to_str()) // Convert OsStr to &str + .map(|s| s.to_string()) // Convert &str to String +} + +/// Strips the longest common prefix from two paths (i.e. base is allowed to have more +/// components that are not shared with target and these are ignored) +pub fn strip_common_prefix<'a>(base: &'a Path, target: &'a Path) -> &'a Path { + let mut base_components = base.components(); + let mut target_components = target.components(); + let mut common_length = 0; + + // Find the longest common prefix + while let (Some(bc), Some(tc)) = (base_components.next(), target_components.next()) { + if bc == tc { + common_length += 1; + } else { + break; + } + } + + // Create a Path that skips the common prefix + let mut remaining = target; + for _ in 0..common_length { + remaining = remaining + .strip_prefix(remaining.components().next().unwrap()) + .unwrap_or(remaining); + } + + remaining +} + +/// Strips the longest common suffix from two paths (i.e. base is allowed to have more +/// leading components that are not shared with target and these are ignored) +pub fn strip_common_suffix<'a>(base: &'a Path, target: &'a Path) -> &'a Path { + let base_components: Vec<_> = base.components().collect(); + let target_components: Vec<_> = target.components().collect(); + + let mut common_suffix_length = 0; + + // Reverse iterate over both paths to find the longest common suffix + for (bc, tc) in base_components + .iter() + .rev() + .zip(target_components.iter().rev()) + { + if bc == tc { + common_suffix_length += 1; + } else { + break; + } + } + + // If there is no common suffix, return target verbatim + if common_suffix_length == 0 { + return target; + } + + // Create a new path without the common suffix + let mut remaining = target; + + for _ in 0..common_suffix_length { + remaining = remaining.parent().unwrap_or(target); + } + + remaining +} diff --git a/support/linting/Cargo.toml b/support/linting/Cargo.toml index 4378ca9dd..64ce7071b 100644 --- a/support/linting/Cargo.toml +++ b/support/linting/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" syn.workspace = true quote.workspace = true proc-macro2.workspace = true -procedural-fork = { version = "1.10.0-rc3", path = "../procedural-fork" } +procedural-fork.workspace = true [lints] workspace = true diff --git a/support/linting/src/disallow_v1_benchmarks.rs b/support/linting/src/disallow_v1_benchmarks.rs new file mode 100644 index 000000000..593a361f2 --- /dev/null +++ b/support/linting/src/disallow_v1_benchmarks.rs @@ -0,0 +1,72 @@ +use super::*; +use syn::{spanned::Spanned, visit::Visit}; + +pub struct DisallowV1Benchmarks; + +impl Lint for DisallowV1Benchmarks { + fn lint(source: &syn::File) -> Result { + let mut visitor = ExprMacroVisitor::new(); + visitor.visit_file(source); + + if !visitor.errors.is_empty() { + return Err(visitor.errors); + } + + Ok(()) + } +} + +struct ExprMacroVisitor { + errors: Vec, +} + +impl<'ast> syn::visit::Visit<'ast> for ExprMacroVisitor { + fn visit_expr_macro(&mut self, i: &'ast syn::ExprMacro) { + let Some(segment) = i.mac.path.segments.last() else { + return; + }; + + if segment.ident == "benchmarks" { + self.errors.push(syn::Error::new( + segment.span(), + "V1 benchmark syntax is disallowed!".to_owned(), + )); + } + } +} + +impl ExprMacroVisitor { + fn new() -> Self { + Self { errors: Vec::new() } + } +} + +#[cfg(test)] +#[allow(clippy::unwrap_used)] +mod tests { + use super::*; + use quote::quote; + + fn lint_macro(input: proc_macro2::TokenStream) -> Result { + let expr_macro: syn::ExprMacro = syn::parse2(input).unwrap(); + let mut visitor = ExprMacroVisitor::new(); + visitor.visit_expr_macro(&expr_macro); + if !visitor.errors.is_empty() { + return Err(visitor.errors); + } + Ok(()) + } + + #[test] + fn test_disallow_benchmarks_v1() { + let input = quote! { + benchmarks! { + benchmark_test { + + }: _(RawOrigin::Root) + } + }; + + lint_macro(input).unwrap_err(); + } +} diff --git a/support/linting/src/lib.rs b/support/linting/src/lib.rs index 7aaf471c7..9a04149b1 100644 --- a/support/linting/src/lib.rs +++ b/support/linting/src/lib.rs @@ -1,10 +1,12 @@ pub mod lint; pub use lint::*; +mod disallow_v1_benchmarks; mod forbid_as_primitive; mod pallet_index; mod require_freeze_struct; +pub use disallow_v1_benchmarks::DisallowV1Benchmarks; pub use forbid_as_primitive::ForbidAsPrimitiveConversion; pub use pallet_index::RequireExplicitPalletIndex; pub use require_freeze_struct::RequireFreezeStruct; diff --git a/support/procedural-fork/Cargo.toml b/support/procedural-fork/Cargo.toml index 503c81f1f..e434378bf 100644 --- a/support/procedural-fork/Cargo.toml +++ b/support/procedural-fork/Cargo.toml @@ -19,6 +19,7 @@ frame-support-procedural-tools = { version = "10.0.0" } proc-macro-warning = { version = "1", default-features = false } expander = "2" sp-crypto-hashing = { default-features = false, version = "0.1.0" } +regex = "1" [dev-dependencies] regex = "1" diff --git a/support/procedural-fork/src/benchmark.rs b/support/procedural-fork/src/benchmark.rs index 0eb3c330a..045454dd9 100644 --- a/support/procedural-fork/src/benchmark.rs +++ b/support/procedural-fork/src/benchmark.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/call.rs b/support/procedural-fork/src/construct_runtime/expand/call.rs index cc467c31d..aeab0afa6 100644 --- a/support/procedural-fork/src/construct_runtime/expand/call.rs +++ b/support/procedural-fork/src/construct_runtime/expand/call.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/composite_helper.rs b/support/procedural-fork/src/construct_runtime/expand/composite_helper.rs index be6b2f085..dea809ac7 100644 --- a/support/procedural-fork/src/construct_runtime/expand/composite_helper.rs +++ b/support/procedural-fork/src/construct_runtime/expand/composite_helper.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/config.rs b/support/procedural-fork/src/construct_runtime/expand/config.rs index ff715e584..e70506779 100644 --- a/support/procedural-fork/src/construct_runtime/expand/config.rs +++ b/support/procedural-fork/src/construct_runtime/expand/config.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/freeze_reason.rs b/support/procedural-fork/src/construct_runtime/expand/freeze_reason.rs index 131c919ef..797263433 100644 --- a/support/procedural-fork/src/construct_runtime/expand/freeze_reason.rs +++ b/support/procedural-fork/src/construct_runtime/expand/freeze_reason.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/hold_reason.rs b/support/procedural-fork/src/construct_runtime/expand/hold_reason.rs index 58870a321..17ee803f9 100644 --- a/support/procedural-fork/src/construct_runtime/expand/hold_reason.rs +++ b/support/procedural-fork/src/construct_runtime/expand/hold_reason.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/inherent.rs b/support/procedural-fork/src/construct_runtime/expand/inherent.rs index 9705f9703..2467c0a74 100644 --- a/support/procedural-fork/src/construct_runtime/expand/inherent.rs +++ b/support/procedural-fork/src/construct_runtime/expand/inherent.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/lock_id.rs b/support/procedural-fork/src/construct_runtime/expand/lock_id.rs index 67c2fb933..ac4bafd7e 100644 --- a/support/procedural-fork/src/construct_runtime/expand/lock_id.rs +++ b/support/procedural-fork/src/construct_runtime/expand/lock_id.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/metadata.rs b/support/procedural-fork/src/construct_runtime/expand/metadata.rs index 9f3d9cd4a..004dc350b 100644 --- a/support/procedural-fork/src/construct_runtime/expand/metadata.rs +++ b/support/procedural-fork/src/construct_runtime/expand/metadata.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/mod.rs b/support/procedural-fork/src/construct_runtime/expand/mod.rs index 88f9a3c6e..eff0cccc1 100644 --- a/support/procedural-fork/src/construct_runtime/expand/mod.rs +++ b/support/procedural-fork/src/construct_runtime/expand/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/origin.rs b/support/procedural-fork/src/construct_runtime/expand/origin.rs index 58c8adec5..0d1f9dd73 100644 --- a/support/procedural-fork/src/construct_runtime/expand/origin.rs +++ b/support/procedural-fork/src/construct_runtime/expand/origin.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/outer_enums.rs b/support/procedural-fork/src/construct_runtime/expand/outer_enums.rs index 28e39c7a2..48a29a086 100644 --- a/support/procedural-fork/src/construct_runtime/expand/outer_enums.rs +++ b/support/procedural-fork/src/construct_runtime/expand/outer_enums.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/slash_reason.rs b/support/procedural-fork/src/construct_runtime/expand/slash_reason.rs index 0695d8102..50cba8d73 100644 --- a/support/procedural-fork/src/construct_runtime/expand/slash_reason.rs +++ b/support/procedural-fork/src/construct_runtime/expand/slash_reason.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/task.rs b/support/procedural-fork/src/construct_runtime/expand/task.rs index 94a5f52bb..fdfc4d268 100644 --- a/support/procedural-fork/src/construct_runtime/expand/task.rs +++ b/support/procedural-fork/src/construct_runtime/expand/task.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/unsigned.rs b/support/procedural-fork/src/construct_runtime/expand/unsigned.rs index 109f7081c..ad81c9c08 100644 --- a/support/procedural-fork/src/construct_runtime/expand/unsigned.rs +++ b/support/procedural-fork/src/construct_runtime/expand/unsigned.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/mod.rs b/support/procedural-fork/src/construct_runtime/mod.rs index 9bc271fdc..f38a47631 100644 --- a/support/procedural-fork/src/construct_runtime/mod.rs +++ b/support/procedural-fork/src/construct_runtime/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/parse.rs b/support/procedural-fork/src/construct_runtime/parse.rs index e5e60b3ff..09ca2d351 100644 --- a/support/procedural-fork/src/construct_runtime/parse.rs +++ b/support/procedural-fork/src/construct_runtime/parse.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/crate_version.rs b/support/procedural-fork/src/crate_version.rs index 63e7c7279..f65b4cbd5 100644 --- a/support/procedural-fork/src/crate_version.rs +++ b/support/procedural-fork/src/crate_version.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/derive_impl.rs b/support/procedural-fork/src/derive_impl.rs index e91f9c534..866be5bab 100644 --- a/support/procedural-fork/src/derive_impl.rs +++ b/support/procedural-fork/src/derive_impl.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. @@ -247,6 +248,7 @@ pub fn derive_impl( } #[test] +#[ignore] fn test_derive_impl_attr_args_parsing() { parse2::(quote!( some::path::TestDefaultConfig as some::path::DefaultConfig @@ -264,6 +266,7 @@ fn test_derive_impl_attr_args_parsing() { } #[test] +#[ignore] fn test_runtime_type_with_doc() { trait TestTrait { type Test; @@ -286,6 +289,7 @@ fn test_runtime_type_with_doc() { } #[test] +#[ignore] fn test_disambiguation_path() { let foreign_impl: ItemImpl = parse_quote!(impl SomeTrait for SomeType {}); let default_impl_path: Path = parse_quote!(SomeScope::SomeType); diff --git a/support/procedural-fork/src/dummy_part_checker.rs b/support/procedural-fork/src/dummy_part_checker.rs index 6bed541d1..a226c8f21 100644 --- a/support/procedural-fork/src/dummy_part_checker.rs +++ b/support/procedural-fork/src/dummy_part_checker.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/dynamic_params.rs b/support/procedural-fork/src/dynamic_params.rs index e1f9f626c..1dd96c258 100644 --- a/support/procedural-fork/src/dynamic_params.rs +++ b/support/procedural-fork/src/dynamic_params.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/key_prefix.rs b/support/procedural-fork/src/key_prefix.rs index aea60ce3b..51f7af1fe 100644 --- a/support/procedural-fork/src/key_prefix.rs +++ b/support/procedural-fork/src/key_prefix.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/lib.rs b/support/procedural-fork/src/lib.rs index c7f1472b2..7564514cd 100644 --- a/support/procedural-fork/src/lib.rs +++ b/support/procedural-fork/src/lib.rs @@ -12,63 +12,50 @@ #![recursion_limit = "512"] #![allow(warnings)] #![allow(clippy::all)] +#![ignore] // ensure procedural-fork tests are not run extern crate proc_macro; -#[cfg(not(test))] mod benchmark; -#[cfg(not(test))] mod construct_runtime; -#[cfg(not(test))] mod crate_version; -#[cfg(not(test))] mod derive_impl; -#[cfg(not(test))] mod dummy_part_checker; -#[cfg(not(test))] mod dynamic_params; -#[cfg(not(test))] mod key_prefix; -#[cfg(not(test))] mod match_and_insert; -#[cfg(not(test))] mod no_bound; -#[cfg(not(test))] mod pallet; -#[cfg(not(test))] mod pallet_error; -#[cfg(not(test))] mod runtime; -#[cfg(not(test))] mod storage_alias; -#[cfg(not(test))] mod transactional; -#[cfg(not(test))] mod tt_macro; -#[cfg(not(test))] -use std::{cell::RefCell, str::FromStr}; -#[cfg(not(test))] +use std::{ + cell::RefCell, + env::{set_var, var}, + path::PathBuf, + str::FromStr, + sync::Mutex, +}; + pub(crate) const INHERENT_INSTANCE_NAME: &str = "__InherentHiddenInstance"; /// The number of module instances supported by the runtime, starting at index 1, /// and up to `NUMBER_OF_INSTANCE`. -#[cfg(not(test))] pub(crate) const NUMBER_OF_INSTANCE: u8 = 16; thread_local! { /// A global counter, can be used to generate a relatively unique identifier. - #[cfg(not(test))] static COUNTER: RefCell = const { RefCell::new(Counter(0)) }; } /// Counter to generate a relatively unique identifier for macros. This is necessary because /// declarative macros gets hoisted to the crate root, which shares the namespace with other pallets /// containing the very same macros. -#[cfg(not(test))] struct Counter(u64); -#[cfg(not(test))] impl Counter { fn inc(&mut self) -> u64 { let ret = self.0; @@ -80,7 +67,6 @@ impl Counter { /// Get the value from the given environment variable set by cargo. /// /// The value is parsed into the requested destination type. -#[cfg(not(test))] fn get_cargo_env_var(version_env: &str) -> std::result::Result { let version = std::env::var(version_env) .unwrap_or_else(|_| panic!("`{}` is always set by cargo; qed", version_env)); @@ -90,13 +76,32 @@ fn get_cargo_env_var(version_env: &str) -> std::result::Result String { format!("CounterFor{}", prefix) } -#[cfg(not(test))] +/// Improvement on [`exports::simulate_manifest_dir`] that allows for an arbitrary return type +pub fn simulate_manifest_dir(path: P, closure: F) -> R +where + P: AsRef, + F: FnOnce() -> R + std::panic::UnwindSafe, +{ + static MANIFEST_DIR_LOCK: Mutex<()> = Mutex::new(()); + let guard = MANIFEST_DIR_LOCK.lock().unwrap(); + let orig = PathBuf::from( + var("CARGO_MANIFEST_DIR").expect("failed to read ENV var `CARGO_MANIFEST_DIR`"), + ); + set_var("CARGO_MANIFEST_DIR", orig.join(path.as_ref())); + let result = std::panic::catch_unwind(closure); + set_var("CARGO_MANIFEST_DIR", &orig); + drop(guard); + result.unwrap() +} + +#[cfg(not(doc))] pub mod exports { + pub use crate::pallet::parse::tests::simulate_manifest_dir; + pub mod benchmark { pub use crate::benchmark::*; } diff --git a/support/procedural-fork/src/match_and_insert.rs b/support/procedural-fork/src/match_and_insert.rs index a80b6e95f..475136c13 100644 --- a/support/procedural-fork/src/match_and_insert.rs +++ b/support/procedural-fork/src/match_and_insert.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/no_bound/clone.rs b/support/procedural-fork/src/no_bound/clone.rs index 17039bdc8..8071e82d9 100644 --- a/support/procedural-fork/src/no_bound/clone.rs +++ b/support/procedural-fork/src/no_bound/clone.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/no_bound/debug.rs b/support/procedural-fork/src/no_bound/debug.rs index 8034bb5ec..3a171f1a0 100644 --- a/support/procedural-fork/src/no_bound/debug.rs +++ b/support/procedural-fork/src/no_bound/debug.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/no_bound/default.rs b/support/procedural-fork/src/no_bound/default.rs index 3f896da35..108ceef84 100644 --- a/support/procedural-fork/src/no_bound/default.rs +++ b/support/procedural-fork/src/no_bound/default.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/no_bound/mod.rs b/support/procedural-fork/src/no_bound/mod.rs index 9e0377dda..f33bf0911 100644 --- a/support/procedural-fork/src/no_bound/mod.rs +++ b/support/procedural-fork/src/no_bound/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/no_bound/ord.rs b/support/procedural-fork/src/no_bound/ord.rs index 20f30eb9d..4b700280a 100644 --- a/support/procedural-fork/src/no_bound/ord.rs +++ b/support/procedural-fork/src/no_bound/ord.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/no_bound/partial_eq.rs b/support/procedural-fork/src/no_bound/partial_eq.rs index 8833f6e5f..0b5b3a788 100644 --- a/support/procedural-fork/src/no_bound/partial_eq.rs +++ b/support/procedural-fork/src/no_bound/partial_eq.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/no_bound/partial_ord.rs b/support/procedural-fork/src/no_bound/partial_ord.rs index c73199d4e..dfd33872d 100644 --- a/support/procedural-fork/src/no_bound/partial_ord.rs +++ b/support/procedural-fork/src/no_bound/partial_ord.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/call.rs b/support/procedural-fork/src/pallet/expand/call.rs index a39e81fd1..cd6536fcf 100644 --- a/support/procedural-fork/src/pallet/expand/call.rs +++ b/support/procedural-fork/src/pallet/expand/call.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/composite.rs b/support/procedural-fork/src/pallet/expand/composite.rs index 49c0ad675..aacf70bf6 100644 --- a/support/procedural-fork/src/pallet/expand/composite.rs +++ b/support/procedural-fork/src/pallet/expand/composite.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/config.rs b/support/procedural-fork/src/pallet/expand/config.rs index 836c74ae7..56811626c 100644 --- a/support/procedural-fork/src/pallet/expand/config.rs +++ b/support/procedural-fork/src/pallet/expand/config.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/constants.rs b/support/procedural-fork/src/pallet/expand/constants.rs index 19862a8a6..74b71b97a 100644 --- a/support/procedural-fork/src/pallet/expand/constants.rs +++ b/support/procedural-fork/src/pallet/expand/constants.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/doc_only.rs b/support/procedural-fork/src/pallet/expand/doc_only.rs index 3e60e9a9b..87579bcde 100644 --- a/support/procedural-fork/src/pallet/expand/doc_only.rs +++ b/support/procedural-fork/src/pallet/expand/doc_only.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/documentation.rs b/support/procedural-fork/src/pallet/expand/documentation.rs index 62b2e8b8b..6d6abdcf1 100644 --- a/support/procedural-fork/src/pallet/expand/documentation.rs +++ b/support/procedural-fork/src/pallet/expand/documentation.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/error.rs b/support/procedural-fork/src/pallet/expand/error.rs index 1b76034ef..66d156220 100644 --- a/support/procedural-fork/src/pallet/expand/error.rs +++ b/support/procedural-fork/src/pallet/expand/error.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/event.rs b/support/procedural-fork/src/pallet/expand/event.rs index 931dcd95a..eb7d5b123 100644 --- a/support/procedural-fork/src/pallet/expand/event.rs +++ b/support/procedural-fork/src/pallet/expand/event.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/genesis_build.rs b/support/procedural-fork/src/pallet/expand/genesis_build.rs index c6089550d..42d413ddc 100644 --- a/support/procedural-fork/src/pallet/expand/genesis_build.rs +++ b/support/procedural-fork/src/pallet/expand/genesis_build.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/genesis_config.rs b/support/procedural-fork/src/pallet/expand/genesis_config.rs index e171e2468..a5deb70d6 100644 --- a/support/procedural-fork/src/pallet/expand/genesis_config.rs +++ b/support/procedural-fork/src/pallet/expand/genesis_config.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/hooks.rs b/support/procedural-fork/src/pallet/expand/hooks.rs index 8ff0e8f30..6f1bb2ab2 100644 --- a/support/procedural-fork/src/pallet/expand/hooks.rs +++ b/support/procedural-fork/src/pallet/expand/hooks.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/inherent.rs b/support/procedural-fork/src/pallet/expand/inherent.rs index 0a80d672a..b685b071f 100644 --- a/support/procedural-fork/src/pallet/expand/inherent.rs +++ b/support/procedural-fork/src/pallet/expand/inherent.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/instances.rs b/support/procedural-fork/src/pallet/expand/instances.rs index 12423409c..f0515fd14 100644 --- a/support/procedural-fork/src/pallet/expand/instances.rs +++ b/support/procedural-fork/src/pallet/expand/instances.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/mod.rs b/support/procedural-fork/src/pallet/expand/mod.rs index ff4423f85..4b07a83fb 100644 --- a/support/procedural-fork/src/pallet/expand/mod.rs +++ b/support/procedural-fork/src/pallet/expand/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/origin.rs b/support/procedural-fork/src/pallet/expand/origin.rs index 167445ad6..e1470d4d8 100644 --- a/support/procedural-fork/src/pallet/expand/origin.rs +++ b/support/procedural-fork/src/pallet/expand/origin.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/pallet_struct.rs b/support/procedural-fork/src/pallet/expand/pallet_struct.rs index 64e5d533c..5b1b152c6 100644 --- a/support/procedural-fork/src/pallet/expand/pallet_struct.rs +++ b/support/procedural-fork/src/pallet/expand/pallet_struct.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/storage.rs b/support/procedural-fork/src/pallet/expand/storage.rs index 95b046670..efd8b3570 100644 --- a/support/procedural-fork/src/pallet/expand/storage.rs +++ b/support/procedural-fork/src/pallet/expand/storage.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/tasks.rs b/support/procedural-fork/src/pallet/expand/tasks.rs index 8a0bd2252..c1eb88d86 100644 --- a/support/procedural-fork/src/pallet/expand/tasks.rs +++ b/support/procedural-fork/src/pallet/expand/tasks.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] //! Contains logic for expanding task-related items. // This file is part of Substrate. diff --git a/support/procedural-fork/src/pallet/expand/tt_default_parts.rs b/support/procedural-fork/src/pallet/expand/tt_default_parts.rs index 8e7dc39d8..7d924a565 100644 --- a/support/procedural-fork/src/pallet/expand/tt_default_parts.rs +++ b/support/procedural-fork/src/pallet/expand/tt_default_parts.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/type_value.rs b/support/procedural-fork/src/pallet/expand/type_value.rs index 84db3e431..b38a2b5ea 100644 --- a/support/procedural-fork/src/pallet/expand/type_value.rs +++ b/support/procedural-fork/src/pallet/expand/type_value.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/validate_unsigned.rs b/support/procedural-fork/src/pallet/expand/validate_unsigned.rs index 28c78a1c6..532fd4d07 100644 --- a/support/procedural-fork/src/pallet/expand/validate_unsigned.rs +++ b/support/procedural-fork/src/pallet/expand/validate_unsigned.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/warnings.rs b/support/procedural-fork/src/pallet/expand/warnings.rs index 3d71b83af..e75a2389d 100644 --- a/support/procedural-fork/src/pallet/expand/warnings.rs +++ b/support/procedural-fork/src/pallet/expand/warnings.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/mod.rs b/support/procedural-fork/src/pallet/mod.rs index d3796662f..21f08fc79 100644 --- a/support/procedural-fork/src/pallet/mod.rs +++ b/support/procedural-fork/src/pallet/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/call.rs b/support/procedural-fork/src/pallet/parse/call.rs index 865c63473..cbe509c44 100644 --- a/support/procedural-fork/src/pallet/parse/call.rs +++ b/support/procedural-fork/src/pallet/parse/call.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/composite.rs b/support/procedural-fork/src/pallet/parse/composite.rs index 239b4fd4b..f971fd234 100644 --- a/support/procedural-fork/src/pallet/parse/composite.rs +++ b/support/procedural-fork/src/pallet/parse/composite.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/config.rs b/support/procedural-fork/src/pallet/parse/config.rs index 95b4143b6..0f9e388c2 100644 --- a/support/procedural-fork/src/pallet/parse/config.rs +++ b/support/procedural-fork/src/pallet/parse/config.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/error.rs b/support/procedural-fork/src/pallet/parse/error.rs index 7aab5732b..37840bfba 100644 --- a/support/procedural-fork/src/pallet/parse/error.rs +++ b/support/procedural-fork/src/pallet/parse/error.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/event.rs b/support/procedural-fork/src/pallet/parse/event.rs index 6102dd31f..280440cde 100644 --- a/support/procedural-fork/src/pallet/parse/event.rs +++ b/support/procedural-fork/src/pallet/parse/event.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/extra_constants.rs b/support/procedural-fork/src/pallet/parse/extra_constants.rs index 431fcf677..5457565bf 100644 --- a/support/procedural-fork/src/pallet/parse/extra_constants.rs +++ b/support/procedural-fork/src/pallet/parse/extra_constants.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/genesis_build.rs b/support/procedural-fork/src/pallet/parse/genesis_build.rs index 936c929af..7e0999d40 100644 --- a/support/procedural-fork/src/pallet/parse/genesis_build.rs +++ b/support/procedural-fork/src/pallet/parse/genesis_build.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/genesis_config.rs b/support/procedural-fork/src/pallet/parse/genesis_config.rs index 1c52345eb..90defee72 100644 --- a/support/procedural-fork/src/pallet/parse/genesis_config.rs +++ b/support/procedural-fork/src/pallet/parse/genesis_config.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/helper.rs b/support/procedural-fork/src/pallet/parse/helper.rs index 1105046c2..061e786b0 100644 --- a/support/procedural-fork/src/pallet/parse/helper.rs +++ b/support/procedural-fork/src/pallet/parse/helper.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/hooks.rs b/support/procedural-fork/src/pallet/parse/hooks.rs index bca1a3383..b625ad724 100644 --- a/support/procedural-fork/src/pallet/parse/hooks.rs +++ b/support/procedural-fork/src/pallet/parse/hooks.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/inherent.rs b/support/procedural-fork/src/pallet/parse/inherent.rs index 911de2ffe..f05eb71e9 100644 --- a/support/procedural-fork/src/pallet/parse/inherent.rs +++ b/support/procedural-fork/src/pallet/parse/inherent.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/mod.rs b/support/procedural-fork/src/pallet/parse/mod.rs index 69f921733..38384dcfd 100644 --- a/support/procedural-fork/src/pallet/parse/mod.rs +++ b/support/procedural-fork/src/pallet/parse/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. @@ -37,7 +38,6 @@ pub mod tasks; pub mod type_value; pub mod validate_unsigned; -#[cfg(test)] pub mod tests; use composite::{keyword::CompositeKeyword, CompositeDef}; diff --git a/support/procedural-fork/src/pallet/parse/origin.rs b/support/procedural-fork/src/pallet/parse/origin.rs index 8232719d6..2be9db85e 100644 --- a/support/procedural-fork/src/pallet/parse/origin.rs +++ b/support/procedural-fork/src/pallet/parse/origin.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/pallet_struct.rs b/support/procedural-fork/src/pallet/parse/pallet_struct.rs index 320cf01fa..389d3eccf 100644 --- a/support/procedural-fork/src/pallet/parse/pallet_struct.rs +++ b/support/procedural-fork/src/pallet/parse/pallet_struct.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/storage.rs b/support/procedural-fork/src/pallet/parse/storage.rs index 811832427..dcc88f629 100644 --- a/support/procedural-fork/src/pallet/parse/storage.rs +++ b/support/procedural-fork/src/pallet/parse/storage.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/tasks.rs b/support/procedural-fork/src/pallet/parse/tasks.rs index 2a8d14826..524fdc404 100644 --- a/support/procedural-fork/src/pallet/parse/tasks.rs +++ b/support/procedural-fork/src/pallet/parse/tasks.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. @@ -595,6 +596,7 @@ fn partition_task_attrs(item: &ImplItemFn) -> (Vec, Vec(quote!(#[pallet::task_list(Something::iter())])).unwrap(); parse2::(quote!(#[pallet::task_list(Numbers::::iter_keys())])).unwrap(); @@ -610,6 +612,7 @@ fn test_parse_task_list_() { } #[test] +#[ignore] fn test_parse_task_index() { parse2::(quote!(#[pallet::task_index(3)])).unwrap(); parse2::(quote!(#[pallet::task_index(0)])).unwrap(); @@ -629,6 +632,7 @@ fn test_parse_task_index() { } #[test] +#[ignore] fn test_parse_task_condition() { parse2::(quote!(#[pallet::task_condition(|x| x.is_some())])).unwrap(); parse2::(quote!(#[pallet::task_condition(|_x| some_expr())])).unwrap(); @@ -637,6 +641,7 @@ fn test_parse_task_condition() { } #[test] +#[ignore] fn test_parse_tasks_attr() { parse2::(quote!(#[pallet::tasks_experimental])).unwrap(); assert_parse_error_matches!( @@ -658,6 +663,7 @@ fn test_parse_tasks_attr() { } #[test] +#[ignore] fn test_parse_tasks_def_basic() { simulate_manifest_dir("../../examples/basic", || { let parsed = parse2::(quote! { @@ -684,6 +690,7 @@ fn test_parse_tasks_def_basic() { } #[test] +#[ignore] fn test_parse_tasks_def_basic_increment_decrement() { simulate_manifest_dir("../../examples/basic", || { let parsed = parse2::(quote! { @@ -736,6 +743,7 @@ fn test_parse_tasks_def_basic_increment_decrement() { } #[test] +#[ignore] fn test_parse_tasks_def_duplicate_index() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -765,6 +773,7 @@ fn test_parse_tasks_def_duplicate_index() { } #[test] +#[ignore] fn test_parse_tasks_def_missing_task_list() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -784,6 +793,7 @@ fn test_parse_tasks_def_missing_task_list() { } #[test] +#[ignore] fn test_parse_tasks_def_missing_task_condition() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -803,6 +813,7 @@ fn test_parse_tasks_def_missing_task_condition() { } #[test] +#[ignore] fn test_parse_tasks_def_missing_task_index() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -822,6 +833,7 @@ fn test_parse_tasks_def_missing_task_index() { } #[test] +#[ignore] fn test_parse_tasks_def_missing_task_weight() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -842,6 +854,7 @@ fn test_parse_tasks_def_missing_task_weight() { } #[test] +#[ignore] fn test_parse_tasks_def_unexpected_extra_task_list_attr() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -864,6 +877,7 @@ fn test_parse_tasks_def_unexpected_extra_task_list_attr() { } #[test] +#[ignore] fn test_parse_tasks_def_unexpected_extra_task_condition_attr() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -886,6 +900,7 @@ fn test_parse_tasks_def_unexpected_extra_task_condition_attr() { } #[test] +#[ignore] fn test_parse_tasks_def_unexpected_extra_task_index_attr() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -908,6 +923,7 @@ fn test_parse_tasks_def_unexpected_extra_task_index_attr() { } #[test] +#[ignore] fn test_parse_tasks_def_extra_tasks_attribute() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -922,6 +938,7 @@ fn test_parse_tasks_def_extra_tasks_attribute() { } #[test] +#[ignore] fn test_parse_task_enum_def_basic() { simulate_manifest_dir("../../examples/basic", || { parse2::(quote! { @@ -936,6 +953,7 @@ fn test_parse_task_enum_def_basic() { } #[test] +#[ignore] fn test_parse_task_enum_def_non_task_name() { simulate_manifest_dir("../../examples/basic", || { parse2::(quote! { @@ -949,6 +967,7 @@ fn test_parse_task_enum_def_non_task_name() { } #[test] +#[ignore] fn test_parse_task_enum_def_missing_attr_allowed() { simulate_manifest_dir("../../examples/basic", || { parse2::(quote! { @@ -962,6 +981,7 @@ fn test_parse_task_enum_def_missing_attr_allowed() { } #[test] +#[ignore] fn test_parse_task_enum_def_missing_attr_alternate_name_allowed() { simulate_manifest_dir("../../examples/basic", || { parse2::(quote! { @@ -974,6 +994,7 @@ fn test_parse_task_enum_def_missing_attr_alternate_name_allowed() { } #[test] +#[ignore] fn test_parse_task_enum_def_wrong_attr() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -990,6 +1011,7 @@ fn test_parse_task_enum_def_wrong_attr() { } #[test] +#[ignore] fn test_parse_task_enum_def_wrong_item() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( diff --git a/support/procedural-fork/src/pallet/parse/tests/mod.rs b/support/procedural-fork/src/pallet/parse/tests/mod.rs index fd7dc2dbe..631afcb0a 100644 --- a/support/procedural-fork/src/pallet/parse/tests/mod.rs +++ b/support/procedural-fork/src/pallet/parse/tests/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. @@ -223,6 +224,7 @@ pub fn simulate_manifest_dir, F: FnOnce() + std::panic mod tasks; #[test] +#[ignore] fn test_parse_minimal_pallet() { assert_pallet_parses! { #[manifest_dir("../../examples/basic")] @@ -238,6 +240,7 @@ fn test_parse_minimal_pallet() { } #[test] +#[ignore] fn test_parse_pallet_missing_pallet() { assert_pallet_parse_error! { #[manifest_dir("../../examples/basic")] @@ -251,6 +254,7 @@ fn test_parse_pallet_missing_pallet() { } #[test] +#[ignore] fn test_parse_pallet_missing_config() { assert_pallet_parse_error! { #[manifest_dir("../../examples/basic")] diff --git a/support/procedural-fork/src/pallet/parse/tests/tasks.rs b/support/procedural-fork/src/pallet/parse/tests/tasks.rs index 0097ed047..0694eb3ff 100644 --- a/support/procedural-fork/src/pallet/parse/tests/tasks.rs +++ b/support/procedural-fork/src/pallet/parse/tests/tasks.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. @@ -18,6 +19,7 @@ use syn::parse_quote; #[test] +#[ignore] fn test_parse_pallet_with_task_enum_missing_impl() { assert_pallet_parse_error! { #[manifest_dir("../../examples/basic")] @@ -39,6 +41,7 @@ fn test_parse_pallet_with_task_enum_missing_impl() { } #[test] +#[ignore] fn test_parse_pallet_with_task_enum_wrong_attribute() { assert_pallet_parse_error! { #[manifest_dir("../../examples/basic")] @@ -66,6 +69,7 @@ fn test_parse_pallet_with_task_enum_wrong_attribute() { } #[test] +#[ignore] fn test_parse_pallet_missing_task_enum() { assert_pallet_parses! { #[manifest_dir("../../examples/basic")] @@ -88,6 +92,7 @@ fn test_parse_pallet_missing_task_enum() { } #[test] +#[ignore] fn test_parse_pallet_task_list_in_wrong_place() { assert_pallet_parse_error! { #[manifest_dir("../../examples/basic")] @@ -113,6 +118,7 @@ fn test_parse_pallet_task_list_in_wrong_place() { } #[test] +#[ignore] fn test_parse_pallet_manual_tasks_impl_without_manual_tasks_enum() { assert_pallet_parse_error! { #[manifest_dir("../../examples/basic")] @@ -141,6 +147,7 @@ fn test_parse_pallet_manual_tasks_impl_without_manual_tasks_enum() { } #[test] +#[ignore] fn test_parse_pallet_manual_task_enum_non_manual_impl() { assert_pallet_parses! { #[manifest_dir("../../examples/basic")] @@ -166,6 +173,7 @@ fn test_parse_pallet_manual_task_enum_non_manual_impl() { } #[test] +#[ignore] fn test_parse_pallet_non_manual_task_enum_manual_impl() { assert_pallet_parses! { #[manifest_dir("../../examples/basic")] @@ -191,6 +199,7 @@ fn test_parse_pallet_non_manual_task_enum_manual_impl() { } #[test] +#[ignore] fn test_parse_pallet_manual_task_enum_manual_impl() { assert_pallet_parses! { #[manifest_dir("../../examples/basic")] @@ -215,6 +224,7 @@ fn test_parse_pallet_manual_task_enum_manual_impl() { } #[test] +#[ignore] fn test_parse_pallet_manual_task_enum_mismatch_ident() { assert_pallet_parses! { #[manifest_dir("../../examples/basic")] diff --git a/support/procedural-fork/src/pallet/parse/type_value.rs b/support/procedural-fork/src/pallet/parse/type_value.rs index 1054fd74c..9a086fe56 100644 --- a/support/procedural-fork/src/pallet/parse/type_value.rs +++ b/support/procedural-fork/src/pallet/parse/type_value.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/validate_unsigned.rs b/support/procedural-fork/src/pallet/parse/validate_unsigned.rs index 3fcbe09e8..3c8b3885d 100644 --- a/support/procedural-fork/src/pallet/parse/validate_unsigned.rs +++ b/support/procedural-fork/src/pallet/parse/validate_unsigned.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet_error.rs b/support/procedural-fork/src/pallet_error.rs index bdf8330cd..4c58d064e 100644 --- a/support/procedural-fork/src/pallet_error.rs +++ b/support/procedural-fork/src/pallet_error.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/runtime/expand/mod.rs b/support/procedural-fork/src/runtime/expand/mod.rs index a1a6d4d07..d70c054db 100644 --- a/support/procedural-fork/src/runtime/expand/mod.rs +++ b/support/procedural-fork/src/runtime/expand/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/runtime/mod.rs b/support/procedural-fork/src/runtime/mod.rs index a96b21cd1..20b06b61c 100644 --- a/support/procedural-fork/src/runtime/mod.rs +++ b/support/procedural-fork/src/runtime/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/runtime/parse/helper.rs b/support/procedural-fork/src/runtime/parse/helper.rs index 17e362410..da5ae2761 100644 --- a/support/procedural-fork/src/runtime/parse/helper.rs +++ b/support/procedural-fork/src/runtime/parse/helper.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/runtime/parse/mod.rs b/support/procedural-fork/src/runtime/parse/mod.rs index a6a49e814..df8382a42 100644 --- a/support/procedural-fork/src/runtime/parse/mod.rs +++ b/support/procedural-fork/src/runtime/parse/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/runtime/parse/pallet.rs b/support/procedural-fork/src/runtime/parse/pallet.rs index 591c05930..576873434 100644 --- a/support/procedural-fork/src/runtime/parse/pallet.rs +++ b/support/procedural-fork/src/runtime/parse/pallet.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/runtime/parse/pallet_decl.rs b/support/procedural-fork/src/runtime/parse/pallet_decl.rs index fab826eee..0b6fc65b5 100644 --- a/support/procedural-fork/src/runtime/parse/pallet_decl.rs +++ b/support/procedural-fork/src/runtime/parse/pallet_decl.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/runtime/parse/runtime_struct.rs b/support/procedural-fork/src/runtime/parse/runtime_struct.rs index 82c6470d7..2788d2d9e 100644 --- a/support/procedural-fork/src/runtime/parse/runtime_struct.rs +++ b/support/procedural-fork/src/runtime/parse/runtime_struct.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/runtime/parse/runtime_types.rs b/support/procedural-fork/src/runtime/parse/runtime_types.rs index 4d8c8358c..da25cdeed 100644 --- a/support/procedural-fork/src/runtime/parse/runtime_types.rs +++ b/support/procedural-fork/src/runtime/parse/runtime_types.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/storage_alias.rs b/support/procedural-fork/src/storage_alias.rs index 7099239f9..be2dd6ac2 100644 --- a/support/procedural-fork/src/storage_alias.rs +++ b/support/procedural-fork/src/storage_alias.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/transactional.rs b/support/procedural-fork/src/transactional.rs index 73a841d9b..d034ef132 100644 --- a/support/procedural-fork/src/transactional.rs +++ b/support/procedural-fork/src/transactional.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/tt_macro.rs b/support/procedural-fork/src/tt_macro.rs index 3f280013f..651828a06 100644 --- a/support/procedural-fork/src/tt_macro.rs +++ b/support/procedural-fork/src/tt_macro.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/update.sh b/support/procedural-fork/update.sh index 0cb933b33..ed21c2db3 100755 --- a/support/procedural-fork/update.sh +++ b/support/procedural-fork/update.sh @@ -13,6 +13,7 @@ TMP_DIR=$(mktemp -d) # Define source and destination directories SRC_DIR="substrate/frame/support/procedural/src" DEST_DIR="$(pwd)/src" # Absolute path to `src` directory of procedural-fork +PARENT_DIR="$(dirname "$DEST_DIR")" # Get the parent directory of DEST_DIR # Check if DEST_DIR exists if [ ! -d "$DEST_DIR" ]; then @@ -36,11 +37,35 @@ git sparse-checkout set "$SRC_DIR" echo "Contents of $TMP_DIR/$SRC_DIR after sparse-checkout:" ls -l "$TMP_DIR/$SRC_DIR" || { echo "Error: Sparse checkout failed, $SRC_DIR not found."; rm -rf "$TMP_DIR"; exit 1; } -# Copy all files from `src` except `lib.rs` to the destination folder +# Copy all files from `src` except `$DEST_DIR/lib.rs` to the destination folder echo "Copying files to $DEST_DIR ..." rsync -a --exclude='lib.rs' "$TMP_DIR/$SRC_DIR/" "$DEST_DIR/" +# Prepend only `#![cfg(not(doc))]` to the top of each Rust file, except the `lib.rs` in $DEST_DIR +find "$DEST_DIR" -name '*.rs' -not -path "$DEST_DIR/lib.rs" | while read -r file; do + echo "Prepending configuration to $file ..." + # Use awk to prepend only `#![cfg(not(doc))]` + awk 'BEGIN {print "#![cfg(not(doc))]"} {print}' "$file" > "$file.tmp" && mv "$file.tmp" "$file" +done + +# Remove all `#[cfg(test)]` lines from `pallet/parse/mod.rs` +MOD_RS="$DEST_DIR/pallet/parse/mod.rs" +if [ -f "$MOD_RS" ]; then + echo "Removing #[cfg(test)] from $MOD_RS ..." + grep -v '#\[cfg(test)\]' "$MOD_RS" > "$MOD_RS.tmp" && mv "$MOD_RS.tmp" "$MOD_RS" +fi + +# Replace all #[test] with #[test]\n#[ignore] using awk +echo "Replacing #[test] with #[ignore] ..." +find "$DEST_DIR" -name '*.rs' | while read -r file; do + awk '{if ($0 == "#[test]") print $0 "\n#[ignore]"; else print $0}' "$file" > "$file.tmp" && mv "$file.tmp" "$file" +done + +# Change directory to the parent of $DEST_DIR to run cargo fmt +echo "Changing directory to $PARENT_DIR and running cargo fmt --all ..." +cd "$PARENT_DIR" && cargo fmt --all + # Clean up the temporary directory rm -rf "$TMP_DIR" -echo "Update completed successfully." +echo "Update and formatting completed successfully."