diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..2ca43021 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,199 @@ +name: Tests + +on: + push: + branches: + - develop + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: "recursive" + + - name: Install solc + run: | + pip3 install solc-select + solc-select install 0.8.9 + solc-select use 0.8.9 + + - name: Install Monero Dependencies + run: | + sudo apt update + sudo apt install build-essential cmake pkg-config libboost-all-dev \ + libssl-dev libzmq3-dev libpgm-dev libunbound-dev \ + libsodium-dev ccache + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + default: true + + - name: Install WASM toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + profile: minimal + target: wasm32-unknown-unknown + + # Cache everything, not only for performance, yet to export these to the + # following jobs + - name: Monero cache + uses: actions/cache@v3 + with: + path: | + ./coins/monero/c/.build + ./coins/monero/c/monero/build + # Hash src, as theoretically, a different version of Monero warranting + # a rebuild would've changed *something* under src + key: ${{ runner.os }}-${{ hashFiles('./coins/monero/c/monero/src') }} + + - name: Cargo/Rust cache + uses: actions/cache@v3 + with: + path: | + ~/.cargo + ./target + key: ${{ runner.os }}-cargo-rust + + - name: Build + run: ARCH=default cargo build --all-features + + # Mirror the build job for Clippy + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: "recursive" + + - name: Install solc + run: | + pip3 install solc-select + solc-select install 0.8.9 + solc-select use 0.8.9 + + - name: Install Monero Dependencies + run: | + sudo apt update + sudo apt install build-essential cmake pkg-config libboost-all-dev \ + libssl-dev libzmq3-dev libpgm-dev libunbound-dev \ + libsodium-dev ccache + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + # Clippy requires nightly for some reason + toolchain: nightly + profile: minimal + default: true + components: clippy + + - name: Install WASM toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + profile: minimal + target: wasm32-unknown-unknown + + # Grab the Monero cache since it'll be unaffected by Rust versioning + - name: Monero cache + uses: actions/cache@v3 + with: + path: | + ./coins/monero/c/.build + ./coins/monero/c/monero/build + key: ${{ runner.os }}-${{ hashFiles('./coins/monero/c/monero/src') }} + + # Define a separate cache for nightly Rust + - name: Cargo/Rust nightly cache + uses: actions/cache@v3 + with: + path: | + ~/.cargo + ./target + key: ${{ runner.os }}-cargo-rust-nightly + + - name: Run Clippy + run: cargo clippy --all-features -- -D warnings -A clippy::type_complexity -A dead_code + + test: + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v3 + with: + submodules: "recursive" + + - name: Install solc + run: | + pip3 install solc-select + solc-select install 0.8.9 + solc-select use 0.8.9 + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + + - name: Install Monero Dependencies + run: | + sudo apt update + sudo apt install libboost-all-dev libssl-dev libzmq3-dev libpgm-dev \ + libunbound-dev libsodium-dev + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + default: true + + - name: Install WASM toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + profile: minimal + target: wasm32-unknown-unknown + + - name: Monero cache + uses: actions/cache@v3 + with: + path: | + ./coins/monero/c/.build + ./coins/monero/c/monero/build + key: ${{ runner.os }}-${{ hashFiles('./coins/monero/c/monero/src') }} + + - name: Cargo/Rust cache + uses: actions/cache@v3 + with: + path: | + ~/.cargo + ./target + key: ${{ runner.os }}-cargo-rust + + - name: Monero Regtest Daemon + run: ./coins/monero/c/monero/build/release/bin/monerod --regtest --offline --fixed-difficulty=1 --detach + + - name: Run tests + run: cargo test --all-features + + fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Install rustfmt + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + profile: minimal + components: rustfmt + + - name: Run rustfmt + run: cargo +nightly fmt -- --check diff --git a/coins/ethereum/build.rs b/coins/ethereum/build.rs index cd41215c..5ea99c7d 100644 --- a/coins/ethereum/build.rs +++ b/coins/ethereum/build.rs @@ -1,7 +1,8 @@ use ethers_solc::{Project, ProjectPathsConfig}; fn main() { - println!("cargo:rerun-if-changed=contracts/Schnorr.sol"); + println!("cargo:rerun-if-changed=contracts"); + println!("cargo:rerun-if-changed=artifacts"); // configure the project with all its paths, solc, cache etc. let project = Project::builder() diff --git a/coins/monero/build.rs b/coins/monero/build.rs index 3cb0cbc2..16697b16 100644 --- a/coins/monero/build.rs +++ b/coins/monero/build.rs @@ -26,12 +26,40 @@ fn main() { // If the signaling file was deleted, run this script again to rebuild Monero though println!("cargo:rerun-if-changed=c/.build/monero"); if !Path::new("c/.build/monero").exists() { - if !Command::new("make") - .arg(format!("-j{}", &env::var("THREADS").unwrap_or("2".to_string()))) + if !Command::new("mkdir") + .args(&["-p", "build/release"]) .current_dir(&Path::new("c/monero")) .status() .unwrap() .success() + { + panic!("failed to mkdir"); + } + + if !Command::new("cmake") + .args(&[ + "-D", + &format!("ARCH={}", &env::var("ARCH").unwrap_or_else(|_| "native".to_string())), + "-D", + "BUILD_TESTS=OFF", + "-D", + "CMAKE_BUILD_TYPE=Release", + "../..", + ]) + .current_dir(&Path::new("c/monero/build/release")) + .status() + .unwrap() + .success() + { + panic!("failed to call cmake. Please check your dependencies"); + } + + if !Command::new("make") + .arg(format!("-j{}", &env::var("THREADS").unwrap_or_else(|_| "2".to_string()))) + .current_dir(&Path::new("c/monero/build/release")) + .status() + .unwrap() + .success() { panic!("make failed to build Monero. Please check your dependencies"); } diff --git a/substrate/node/Cargo.toml b/substrate/node/Cargo.toml index b8b02851..71cbb8c8 100644 --- a/substrate/node/Cargo.toml +++ b/substrate/node/Cargo.toml @@ -49,13 +49,9 @@ frame-benchmarking-cli = { git = "https://github.com/serai-dex/substrate" } serai-consensus = { path = "../consensus" } serai-runtime = { path = "../runtime" } -# CLI-specific dependencies -try-runtime-cli = { git = "https://github.com/serai-dex/substrate", optional = true } - [build-dependencies] substrate-build-script-utils = { git = "https://github.com/serai-dex/substrate.git" } [features] default = [] runtime-benchmarks = ["serai-runtime/runtime-benchmarks"] -try-runtime = ["serai-runtime/try-runtime", "try-runtime-cli"] diff --git a/substrate/node/src/cli.rs b/substrate/node/src/cli.rs index effddac6..6ec72890 100644 --- a/substrate/node/src/cli.rs +++ b/substrate/node/src/cli.rs @@ -40,14 +40,6 @@ pub enum Subcommand { #[clap(subcommand)] Benchmark(frame_benchmarking_cli::BenchmarkCmd), - /// Try some command against the runtime state - #[cfg(feature = "try-runtime")] - TryRuntime(try_runtime_cli::TryRuntimeCmd), - - /// Try some command against the runtime state. Note: `try-runtime` feature must be enabled - #[cfg(not(feature = "try-runtime"))] - TryRuntime, - /// DB meta columns information ChainInfo(sc_cli::ChainInfoCmd), } diff --git a/substrate/node/src/command.rs b/substrate/node/src/command.rs index 51446c0c..8902a801 100644 --- a/substrate/node/src/command.rs +++ b/substrate/node/src/command.rs @@ -114,21 +114,6 @@ pub fn run() -> sc_cli::Result<()> { BenchmarkCmd::Machine(cmd) => cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone()), }), - #[cfg(feature = "try-runtime")] - Some(Subcommand::TryRuntime(cmd)) => cli.create_runner(cmd)?.async_run(|config| { - Ok(( - cmd.run::(config), - sc_service::TaskManager::new( - config.tokio_handle.clone(), - config.prometheus_config.as_ref().map(|cfg| &cfg.registry), - ) - .map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?, - )) - }), - - #[cfg(not(feature = "try-runtime"))] - Some(Subcommand::TryRuntime) => Err("TryRuntime wasn't enabled when building the node".into()), - Some(Subcommand::ChainInfo(cmd)) => { cli.create_runner(cmd)?.sync_run(|config| cmd.run::(&config)) } diff --git a/substrate/runtime/Cargo.toml b/substrate/runtime/Cargo.toml index eb6d2ed2..1faeb370 100644 --- a/substrate/runtime/Cargo.toml +++ b/substrate/runtime/Cargo.toml @@ -27,7 +27,6 @@ sp-api = { git = "https://github.com/serai-dex/substrate", default-features = fa frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false } frame-system = { git = "https://github.com/serai-dex/substrate", default-features = false } frame-executive = { git = "https://github.com/serai-dex/substrate", default-features = false } -frame-try-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false, optional = true } pallet-randomness-collective-flip = { git = "https://github.com/serai-dex/substrate", default-features = false } pallet-timestamp = { git = "https://github.com/serai-dex/substrate", default-features = false } @@ -92,15 +91,4 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", ] -try-runtime = [ - "frame-executive/try-runtime", - "frame-try-runtime", - "frame-system/try-runtime", - - "pallet-randomness-collective-flip/try-runtime", - "pallet-timestamp/try-runtime", - "pallet-balances/try-runtime", - "pallet-transaction-payment/try-runtime", -] - default = ["std"] diff --git a/substrate/runtime/src/lib.rs b/substrate/runtime/src/lib.rs index ba0643d1..f5c6093a 100644 --- a/substrate/runtime/src/lib.rs +++ b/substrate/runtime/src/lib.rs @@ -4,7 +4,6 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, @@ -280,11 +279,11 @@ construct_runtime!( UncheckedExtrinsic = UncheckedExtrinsic { System: frame_system, - RandomnessCollectiveFlip: pallet_randomness_collective_flip, + RandomnessCollectiveFlip: pallet_randomness_collective_flip, Timestamp: pallet_timestamp, Balances: pallet_balances, TransactionPayment: pallet_transaction_payment, - Contracts: pallet_contracts, + Contracts: pallet_contracts, } ); @@ -302,7 +301,7 @@ mod benches { ); } -impl_runtime_apis! { +sp_api::impl_runtime_apis! { impl sp_api::Core for Runtime { fn version() -> RuntimeVersion { VERSION @@ -396,6 +395,65 @@ impl_runtime_apis! { } } + impl pallet_contracts_rpc_runtime_api::ContractsApi + for Runtime + { + fn call( + origin: AccountId, + dest: AccountId, + value: Balance, + gas_limit: u64, + storage_deposit_limit: Option, + input_data: Vec, + ) -> pallet_contracts_primitives::ContractExecResult { + Contracts::bare_call( + origin, + dest, + value, + gas_limit, + storage_deposit_limit, + input_data, + CONTRACTS_DEBUG_OUTPUT + ) + } + + fn instantiate( + origin: AccountId, + value: Balance, + gas_limit: u64, + storage_deposit_limit: Option, + code: pallet_contracts_primitives::Code, + data: Vec, + salt: Vec, + ) -> pallet_contracts_primitives::ContractInstantiateResult { + Contracts::bare_instantiate( + origin, + value, + gas_limit, + storage_deposit_limit, + code, + data, + salt, + CONTRACTS_DEBUG_OUTPUT + ) + } + + fn upload_code( + origin: AccountId, + code: Vec, + storage_deposit_limit: Option, + ) -> pallet_contracts_primitives::CodeUploadResult { + Contracts::bare_upload_code(origin, code, storage_deposit_limit) + } + + fn get_storage( + address: AccountId, + key: Vec, + ) -> pallet_contracts_primitives::GetStorageResult { + Contracts::get_storage(address, key) + } + } + #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { fn benchmark_metadata(extra: bool) -> ( @@ -456,78 +514,4 @@ impl_runtime_apis! { Ok(batches) } } - - impl pallet_contracts_rpc_runtime_api::ContractsApi - for Runtime - { - fn call( - origin: AccountId, - dest: AccountId, - value: Balance, - gas_limit: u64, - storage_deposit_limit: Option, - input_data: Vec, - ) -> pallet_contracts_primitives::ContractExecResult { - Contracts::bare_call( - origin, - dest, - value, - gas_limit, - storage_deposit_limit, - input_data, - CONTRACTS_DEBUG_OUTPUT - ) - } - - fn instantiate( - origin: AccountId, - value: Balance, - gas_limit: u64, - storage_deposit_limit: Option, - code: pallet_contracts_primitives::Code, - data: Vec, - salt: Vec, - ) -> pallet_contracts_primitives::ContractInstantiateResult { - Contracts::bare_instantiate( - origin, - value, - gas_limit, - storage_deposit_limit, - code, - data, - salt, - CONTRACTS_DEBUG_OUTPUT - ) - } - - fn upload_code( - origin: AccountId, - code: Vec, - storage_deposit_limit: Option, - ) -> pallet_contracts_primitives::CodeUploadResult { - Contracts::bare_upload_code(origin, code, storage_deposit_limit) - } - - fn get_storage( - address: AccountId, - key: Vec, - ) -> pallet_contracts_primitives::GetStorageResult { - Contracts::get_storage(address, key) - } - } - - #[cfg(feature = "try-runtime")] - impl frame_try_runtime::TryRuntime for Runtime { - fn on_runtime_upgrade() -> (Weight, Weight) { - // NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to - // have a backtrace here. If any of the pre/post migration checks fail, we shall stop - // right here and right now. - let weight = Executive::try_runtime_upgrade().unwrap(); - (weight, BlockWeights::get().max_block) - } - - fn execute_block_no_check(block: Block) -> Weight { - Executive::execute_block_no_check(block) - } - } }