From 16c49100fa615567bf64d0a1322091b56d92d8f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Mon, 26 Aug 2024 14:39:46 +0100 Subject: [PATCH 1/7] core: remove `ByteBuf` and re-export `HEXLOWER` and `HEXUPPER` --- crates/core/Cargo.toml | 1 + crates/core/src/bytes.rs | 25 ++----------------------- crates/core/src/chain.rs | 5 ++--- crates/merkle_tree/src/lib.rs | 6 +++--- 4 files changed, 8 insertions(+), 29 deletions(-) diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index affc2339b5..c597070c59 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -94,6 +94,7 @@ tokio = { workspace = true, optional = true, default-features = false, features [dev-dependencies] assert_matches.workspace = true +lazy_static.workspace = true proptest.workspace = true rand.workspace = true rand_core.workspace = true diff --git a/crates/core/src/bytes.rs b/crates/core/src/bytes.rs index e157c80428..f2768446da 100644 --- a/crates/core/src/bytes.rs +++ b/crates/core/src/bytes.rs @@ -1,24 +1,3 @@ -//! A helper module for dealing with bytes +//! Bytes hex formatting -use std::fmt::Display; - -/// A helper to show bytes in hex -pub struct ByteBuf<'a>(pub &'a [u8]); - -impl<'a> std::fmt::LowerHex for ByteBuf<'a> { - fn fmt( - &self, - f: &mut std::fmt::Formatter<'_>, - ) -> std::result::Result<(), std::fmt::Error> { - for byte in self.0 { - f.write_fmt(format_args!("{:02x}", byte))?; - } - Ok(()) - } -} - -impl<'a> Display for ByteBuf<'a> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:x}", self) - } -} +pub use data_encoding::{HEXLOWER, HEXUPPER}; diff --git a/crates/core/src/chain.rs b/crates/core/src/chain.rs index 16b0f2bd08..44f76556af 100644 --- a/crates/core/src/chain.rs +++ b/crates/core/src/chain.rs @@ -5,7 +5,7 @@ use std::num::ParseIntError; use std::str::FromStr; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use data_encoding::HEXUPPER; +use data_encoding::{HEXLOWER, HEXUPPER}; use namada_macros::BorshDeserializer; #[cfg(feature = "migrations")] use namada_migrations::*; @@ -13,7 +13,6 @@ use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use thiserror::Error; -use crate::bytes::ByteBuf; use crate::hash::Hash; use crate::time::DateTimeUtc; @@ -287,7 +286,7 @@ pub enum ParseBlockHashError { impl core::fmt::Debug for BlockHash { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let hash = format!("{}", ByteBuf(&self.0)); + let hash = HEXLOWER.encode(&self.0); f.debug_tuple("BlockHash").field(&hash).finish() } } diff --git a/crates/merkle_tree/src/lib.rs b/crates/merkle_tree/src/lib.rs index a499c5d8c8..72aa5ffacf 100644 --- a/crates/merkle_tree/src/lib.rs +++ b/crates/merkle_tree/src/lib.rs @@ -36,7 +36,7 @@ use ics23::{ExistenceProof, NonExistenceProof}; use ics23_specs::ibc_leaf_spec; use namada_core::address::{Address, InternalAddress}; use namada_core::borsh::{BorshDeserialize, BorshSerialize, BorshSerializeExt}; -use namada_core::bytes::ByteBuf; +use namada_core::bytes::HEXLOWER; pub use namada_core::chain::{BlockHeight, Epoch}; use namada_core::eth_bridge_pool::{is_pending_transfer_key, PendingTransfer}; pub use namada_core::hash::{Hash, StorageHasher}; @@ -470,7 +470,7 @@ pub struct MerkleTree { impl core::fmt::Debug for MerkleTree { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let root_hash = format!("{}", ByteBuf(self.base.root().as_slice())); + let root_hash = HEXLOWER.encode(self.base.root().as_slice()); f.debug_struct("MerkleTree") .field("root_hash", &root_hash) .finish() @@ -846,7 +846,7 @@ impl From for Hash { impl fmt::Display for MerkleRoot { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", ByteBuf(&self.0)) + write!(f, "{}", HEXLOWER.encode(&self.0)) } } From ac430600685b58809ceab2a97b13d82250ccd219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Mon, 26 Aug 2024 14:59:52 +0100 Subject: [PATCH 2/7] test/core/ibc: add basic unit tests --- crates/core/src/ibc.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/crates/core/src/ibc.rs b/crates/core/src/ibc.rs index 757d5a512b..aa250e38a7 100644 --- a/crates/core/src/ibc.rs +++ b/crates/core/src/ibc.rs @@ -164,3 +164,41 @@ impl borsh::BorshSchema for PGFIbcTarget { std::any::type_name::().into() } } + +#[cfg(test)] +mod test { + use super::*; + use crate::{decode, encode}; + + #[test] + fn test_ibc_token_hash() { + let hash = IbcTokenHash([ + 0_u8, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ]); + + let hash_str = hash.to_string(); + assert_eq!("00ff000000000000000000000000000000000000", &hash_str); + + let decoded = IbcTokenHash::from_str(&hash_str).unwrap(); + assert_eq!(decoded, hash); + + // Hex decoding is case-insensitive + let decoded = + IbcTokenHash::from_str("00FF000000000000000000000000000000000000") + .unwrap(); + assert_eq!(decoded, hash); + } + + #[test] + fn test_ibc_pgf_target() { + let target = PGFIbcTarget { + target: "123".to_string(), + amount: token::Amount::from_u64(123456789), + port_id: PortId::new("10".to_string()).unwrap(), + channel_id: ChannelId::new(5), + }; + let bytes = encode(&target); + let decoded: PGFIbcTarget = decode(bytes).unwrap(); + assert_eq!(target, decoded); + } +} From 984e9d32aacde0c30de25e2a1ac7a67d932af5fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Mon, 26 Aug 2024 15:15:26 +0100 Subject: [PATCH 3/7] test/core/masp: test basics --- crates/core/src/masp.rs | 103 ++++++++++++++++++++++++----- crates/core/src/string_encoding.rs | 15 +++++ 2 files changed, 103 insertions(+), 15 deletions(-) diff --git a/crates/core/src/masp.rs b/crates/core/src/masp.rs index 7bc4429b27..1ae82ee00a 100644 --- a/crates/core/src/masp.rs +++ b/crates/core/src/masp.rs @@ -10,6 +10,7 @@ use borsh_ext::BorshSerializeExt; use masp_primitives::asset_type::AssetType; use masp_primitives::sapling::ViewingKey; use masp_primitives::transaction::TransparentAddress; +pub use masp_primitives::transaction::TxId as TxIdInner; use namada_macros::BorshDeserializer; #[cfg(feature = "migrations")] use namada_migrations::*; @@ -27,10 +28,7 @@ use crate::string_encoding::{ use crate::token::{Denomination, MaspDigitPos}; /// Serialize the given TxId -pub fn serialize_txid( - txid: &masp_primitives::transaction::TxId, - s: S, -) -> Result +pub fn serialize_txid(txid: &TxIdInner, s: S) -> Result where S: Serializer, { @@ -38,15 +36,13 @@ where } /// Deserialize the given TxId -pub fn deserialize_txid<'de, D>( - deserializer: D, -) -> Result +pub fn deserialize_txid<'de, D>(deserializer: D) -> Result where D: Deserializer<'de>, { - Ok(masp_primitives::transaction::TxId::from_bytes( - Deserialize::deserialize(deserializer)?, - )) + Ok(TxIdInner::from_bytes(Deserialize::deserialize( + deserializer, + )?)) } /// Wrapper for masp_primitive's TxId @@ -71,11 +67,11 @@ pub struct MaspTxId( serialize_with = "serialize_txid", deserialize_with = "deserialize_txid" )] - masp_primitives::transaction::TxId, + TxIdInner, ); -impl From for MaspTxId { - fn from(txid: masp_primitives::transaction::TxId) -> Self { +impl From for MaspTxId { + fn from(txid: TxIdInner) -> Self { Self(txid) } } @@ -111,8 +107,8 @@ impl FromStr for MaspEpoch { type Err = ParseIntError; fn from_str(s: &str) -> std::result::Result { - let raw: u64 = u64::from_str(s)?; - Ok(Self(Epoch(raw))) + let inner: Epoch = Epoch::from_str(s)?; + Ok(Self(inner)) } } @@ -467,6 +463,18 @@ impl string_encoding::Format for ExtendedSpendingKey { impl_display_and_from_str_via_format!(ExtendedSpendingKey); +impl ExtendedSpendingKey { + /// Derive a viewing key + pub fn to_viewing_key(&self) -> ExtendedViewingKey { + ExtendedViewingKey::from( + #[allow(deprecated)] + { + self.0.to_extended_full_viewing_key() + }, + ) + } +} + impl From for masp_primitives::zip32::ExtendedSpendingKey { fn from(key: ExtendedSpendingKey) -> Self { key.0 @@ -775,3 +783,68 @@ impl FromStr for MaspTxRefs { serde_json::from_str(s) } } + +#[cfg(test)] +mod test { + use super::*; + use crate::address; + + #[test] + fn test_masp_tx_id_basics() { + let tx_id = MaspTxId::from(TxIdInner::from_bytes([ + 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ])); + let tx_id_str = serde_json::to_string(&tx_id).unwrap(); + let decoded: MaspTxId = serde_json::from_str(&tx_id_str).unwrap(); + assert_eq!(tx_id, decoded); + } + + #[test] + fn test_masp_epoch_basics() { + let epoch = MaspEpoch::new(123); + let epoch_str = epoch.to_string(); + assert_eq!(&epoch_str, "123"); + let decoded = MaspEpoch::from_str(&epoch_str).unwrap(); + assert_eq!(epoch, decoded); + } + + #[test] + fn test_masp_asset_data_basics() { + let mut data = AssetData { + token: address::testing::nam(), + denom: Denomination(6), + position: MaspDigitPos::One, + epoch: None, + }; + + data.undate(); + assert!(data.epoch.is_none()); + + let epoch_0 = MaspEpoch::new(3); + let old = data.redate(epoch_0); + assert!(old.is_none()); + assert!(data.epoch.is_none()); + data.epoch = Some(epoch_0); + + let epoch_1 = MaspEpoch::new(5); + let old = data.redate(epoch_1); + assert_eq!(old, Some(epoch_0)); + assert_eq!(data.epoch, Some(epoch_1)); + } + + #[test] + fn test_masp_keys_basics() { + let sk = ExtendedSpendingKey::from( + masp_primitives::zip32::ExtendedSpendingKey::master(&[0_u8]), + ); + string_encoding::testing::test_string_formatting(&sk); + + let vk = sk.to_viewing_key(); + string_encoding::testing::test_string_formatting(&vk); + + let (_diversifier, pa) = sk.0.default_address(); + let pa = PaymentAddress::from(pa); + string_encoding::testing::test_string_formatting(&pa); + } +} diff --git a/crates/core/src/string_encoding.rs b/crates/core/src/string_encoding.rs index c853fde433..90b04470f1 100644 --- a/crates/core/src/string_encoding.rs +++ b/crates/core/src/string_encoding.rs @@ -224,3 +224,18 @@ where let val_str: String = serde::Deserialize::deserialize(deserializer)?; FromStr::from_str(&val_str).map_err(serde::de::Error::custom) } + +/// Testing helpers +#[cfg(any(test, feature = "testing"))] +pub mod testing { + use core::fmt::Debug; + + use super::Format; + + /// String encoding roundtrip test + pub fn test_string_formatting(val: &T) { + let str = Format::encode(val); + let decoded: T = Format::decode(str).unwrap(); + assert_eq!(val, &decoded) + } +} From 6a1a8af714fed9b1974ea7e5ecfa5132a9231765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 27 Aug 2024 11:23:19 +0100 Subject: [PATCH 4/7] codecov: ignore more utils & testing code --- codecov.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/codecov.yml b/codecov.yml index d17d314298..c401ce211f 100644 --- a/codecov.yml +++ b/codecov.yml @@ -37,4 +37,6 @@ ignore: - crates/apps/src/bin - crates/apps_lib/src/cli - crates/apps_lib/src/client - - crates/apps_lib/src/wasm_loader \ No newline at end of file + - crates/apps_lib/src/wasm_loader + - crates/node/src/bench_utils + - crates/node/src/shell/testing From ff5f6ba57e5a0974477a11b12d462478a0e295c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 27 Aug 2024 13:17:56 +0100 Subject: [PATCH 5/7] tests: remove "integration" feature --- .github/workflows/ci.yml | 2 +- Makefile | 11 +++------ crates/apps_lib/Cargo.toml | 3 +-- crates/apps_lib/src/config/genesis.rs | 5 +--- crates/core/Cargo.toml | 2 +- crates/node/Cargo.toml | 3 +-- crates/node/src/shell/init_chain.rs | 33 ++++++++++----------------- crates/node/src/shell/mod.rs | 32 ++++++++++++++------------ crates/sdk/Cargo.toml | 2 +- crates/state/Cargo.toml | 2 +- crates/tests/Cargo.toml | 1 - 11 files changed, 40 insertions(+), 56 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 876458ef07..9e7d081315 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -388,7 +388,7 @@ jobs: name: wasm-for-tests-${{ github.event.pull_request.head.sha|| github.sha }} path: wasm_for_tests - name: Run integration tests - run: cargo +${{ env.NIGHTLY }} nextest run -E 'test(integration)' --test-threads 1 --no-fail-fast --features integration + run: cargo +${{ env.NIGHTLY }} nextest run -E 'test(integration)' --test-threads 1 --no-fail-fast env: RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=/usr/local/bin/mold -Z threads=8" - name: Clean cargo cache diff --git a/Makefile b/Makefile index 8f232d1521..cc792d58e1 100644 --- a/Makefile +++ b/Makefile @@ -155,15 +155,10 @@ audit: test: test-unit test-e2e test-wasm test-benches test-coverage: - # Run integration tests separately because they require `integration` - # feature (and without coverage) $(cargo) +$(nightly) llvm-cov --output-path lcov.info \ --lcov \ - -- --skip e2e --skip pos_state_machine_test --skip integration \ - -Z unstable-options --report-time && \ - $(cargo) +$(nightly) test integration:: \ - --features integration \ - -- -Z unstable-options --report-time + -- --skip e2e --skip pos_state_machine_test \ + -Z unstable-options --report-time # NOTE: `TEST_FILTER` is prepended with `e2e::`. Since filters in `cargo test` # work with a substring search, TEST_FILTER only works if it contains a string @@ -183,7 +178,7 @@ test-e2e: # Run integration tests test-integration: RUST_BACKTRACE=$(RUST_BACKTRACE) \ - $(cargo) +$(nightly) test --lib $(jobs) integration::$(TEST_FILTER) --features integration \ + $(cargo) +$(nightly) test --lib $(jobs) integration::$(TEST_FILTER) \ -Z unstable-options \ -- \ --test-threads=1 \ diff --git a/crates/apps_lib/Cargo.toml b/crates/apps_lib/Cargo.toml index c5b76cc2ea..d86d20844a 100644 --- a/crates/apps_lib/Cargo.toml +++ b/crates/apps_lib/Cargo.toml @@ -17,10 +17,9 @@ default = ["migrations"] mainnet = [ "namada_sdk/mainnet", ] -# for integration tests and test utilities +# for tests and test utilities testing = ["lazy_static", "namada_sdk/testing"] benches = ["lazy_static", "namada_sdk/benches"] -integration = [] migrations = [ "namada_migrations", "namada_sdk/migrations", diff --git a/crates/apps_lib/src/config/genesis.rs b/crates/apps_lib/src/config/genesis.rs index 794ac01c7d..af8face842 100644 --- a/crates/apps_lib/src/config/genesis.rs +++ b/crates/apps_lib/src/config/genesis.rs @@ -422,10 +422,7 @@ pub struct Parameters { /// This includes adding the Ethereum bridge parameters and /// adding a specified number of validators. #[allow(clippy::arithmetic_side_effects)] -#[cfg(all( - any(test, feature = "benches", feature = "testing"), - not(feature = "integration") -))] +#[cfg(any(test, feature = "benches", feature = "testing"))] pub fn make_dev_genesis( num_validators: u64, target_chain_dir: &std::path::Path, diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index c597070c59..17a1e1e462 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -19,7 +19,7 @@ rand = ["dep:rand", "rand_core"] ethers-derive = [ "ethbridge-structs/ethers-derive" ] -# for integration tests and test utilities +# for tests and test utilities testing = [ "rand", "proptest", diff --git a/crates/node/Cargo.toml b/crates/node/Cargo.toml index 8c10c79ab1..5492fafd27 100644 --- a/crates/node/Cargo.toml +++ b/crates/node/Cargo.toml @@ -17,7 +17,7 @@ default = ["migrations"] mainnet = [ "namada_sdk/mainnet", ] -# for integration tests and test utilities +# for tests and test utilities testing = [ "namada_apps_lib/testing", "namada_test_utils", @@ -31,7 +31,6 @@ benches = [ "tracing-subscriber", "rand_core" ] -integration = ["namada_apps_lib/integration"] jemalloc = ["rocksdb/jemalloc"] migrations = [ "namada_migrations", diff --git a/crates/node/src/shell/init_chain.rs b/crates/node/src/shell/init_chain.rs index 7f26a5c106..ca13aa6cc2 100644 --- a/crates/node/src/shell/init_chain.rs +++ b/crates/node/src/shell/init_chain.rs @@ -86,7 +86,7 @@ where &mut self, init: request::InitChain, #[cfg(any(test, feature = "testing", feature = "benches"))] - _num_validators: u64, + num_validators: u64, ) -> ShellResult { let mut response = response::InitChain::default(); let chain_id = self.state.in_mem().chain_id.as_str(); @@ -127,38 +127,29 @@ where } // Read the genesis files - #[cfg(any( - feature = "integration", - not(any(test, fuzzing, feature = "benches")) - ))] + #[cfg(not(any(test, fuzzing, feature = "benches")))] let genesis = { let chain_dir = self.base_dir.join(chain_id); genesis::chain::Finalized::read_toml_files(&chain_dir) .expect("Missing genesis files") }; - #[cfg(all( - any(test, fuzzing, feature = "benches"), - not(feature = "integration") - ))] + #[cfg(any(test, fuzzing, feature = "benches"))] let genesis = { let chain_dir = self.base_dir.join(chain_id); - genesis::make_dev_genesis(_num_validators, &chain_dir) + if chain_dir.join(genesis::chain::METADATA_FILE_NAME).exists() { + genesis::chain::Finalized::read_toml_files(&chain_dir) + .expect("Missing genesis files") + } else { + genesis::make_dev_genesis(num_validators, &chain_dir) + } }; - #[cfg(all( - any(test, fuzzing, feature = "benches"), - not(feature = "integration") - ))] - { - // update the native token from the genesis file - let native_token = genesis.get_native_token().clone(); - self.state.in_mem_mut().native_token = native_token; - } + let mut validation = InitChainValidation::new(self, false); validation.run( init, genesis, #[cfg(any(test, feature = "testing"))] - _num_validators, + num_validators, ); // propagate errors or panic validation.error_out()?; @@ -969,7 +960,7 @@ impl Policy { } } -#[cfg(all(test, not(feature = "integration")))] +#[cfg(test)] mod test { use std::str::FromStr; diff --git a/crates/node/src/shell/mod.rs b/crates/node/src/shell/mod.rs index 457129ee56..728a141ddb 100644 --- a/crates/node/src/shell/mod.rs +++ b/crates/node/src/shell/mod.rs @@ -493,23 +493,27 @@ where .expect("Creating directory for Namada should not fail"); } - // For all tests except integration use hard-coded native token addr ... - #[cfg(all( - any(test, fuzzing, feature = "testing", feature = "benches"), - not(feature = "integration"), - ))] - let native_token = namada_sdk::address::testing::nam(); + // For tests, fuzzing and benches use hard-coded native token addr ... + #[cfg(any(test, fuzzing, feature = "benches"))] + let native_token = { + let chain_dir = base_dir.join(chain_id.as_str()); + // Use genesis file only if it exists + if chain_dir + .join(genesis::templates::TOKENS_FILE_NAME) + .exists() + { + genesis::chain::Finalized::read_native_token(&chain_dir) + .expect("Missing genesis files") + } else { + namada_sdk::address::testing::nam() + } + }; // ... Otherwise, look it up from the genesis file - #[cfg(not(all( - any(test, fuzzing, feature = "testing", feature = "benches"), - not(feature = "integration"), - )))] + #[cfg(not(any(test, fuzzing, feature = "benches")))] let native_token = { let chain_dir = base_dir.join(chain_id.as_str()); - let genesis = - genesis::chain::Finalized::read_toml_files(&chain_dir) - .expect("Missing genesis files"); - genesis.get_native_token().clone() + genesis::chain::Finalized::read_native_token(&chain_dir) + .expect("Missing genesis files") }; // load last state from storage diff --git a/crates/sdk/Cargo.toml b/crates/sdk/Cargo.toml index ff5209547c..6cad716918 100644 --- a/crates/sdk/Cargo.toml +++ b/crates/sdk/Cargo.toml @@ -24,7 +24,7 @@ namada-eth-bridge = ["namada_ethereum_bridge/namada-eth-bridge"] benches = ["namada_core/benches", "namada_core/testing", "namada_state/benches"] wasm-runtime = ["namada_vm/wasm-runtime"] -# for integration tests and test utilities +# for tests and test utilities testing = [ "masp_primitives/test-dependencies", "namada_account/testing", diff --git a/crates/state/Cargo.toml b/crates/state/Cargo.toml index bc327a7aaf..b535d6ecc7 100644 --- a/crates/state/Cargo.toml +++ b/crates/state/Cargo.toml @@ -15,7 +15,7 @@ version.workspace = true [features] default = [] -# for integration tests and test utilities +# for tests and test utilities testing = [ "namada_core/testing", "namada_merkle_tree/testing", diff --git a/crates/tests/Cargo.toml b/crates/tests/Cargo.toml index 263d1bc826..6f0134b207 100644 --- a/crates/tests/Cargo.toml +++ b/crates/tests/Cargo.toml @@ -17,7 +17,6 @@ default = [] mainnet = [ "namada_sdk/mainnet", ] -integration = ["namada_node/integration", "namada_apps_lib/integration"] migrations = [ "namada_sdk/migrations", "namada_core/migrations", From dcd356b684fe1203f3d24aefaf87e4f560837dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Wed, 28 Aug 2024 11:34:01 +0100 Subject: [PATCH 6/7] make: add `test-unit-with-coverage` --- Makefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index cc792d58e1..486f40f92b 100644 --- a/Makefile +++ b/Makefile @@ -202,7 +202,16 @@ test-unit-with-eth-bridge: test-unit-with-coverage: $(cargo) +$(nightly) llvm-cov --output-path lcov.info \ --lcov \ - -- --skip e2e --skip pos_state_machine_test --skip integration \ + -- --lib \ + --skip e2e --skip pos_state_machine_test --skip integration \ + -Z unstable-options --report-time + +test-integration-with-coverage: + $(cargo) +$(nightly) llvm-cov --output-path lcov.info \ + --lcov \ + -- integration \ + --lib \ + --test-threads=1 \ -Z unstable-options --report-time test-unit-mainnet: From c7ea77d216608d29d8c42151f1f48ff6993ec367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Wed, 28 Aug 2024 11:42:20 +0100 Subject: [PATCH 7/7] ci: run integration tests with coverage --- .github/workflows/ci.yml | 44 ++++++++++++++++++++++++++++++++-------- Makefile | 8 +++----- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e7d081315..209bb3e875 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -290,12 +290,11 @@ jobs: # run: cargo +${{ env.NIGHTLY }} llvm-cov nextest run -E 'not test(e2e)' -E 'not test(integration)' -E 'not test(pos_state_machine_test)' --features namada/testing --no-fail-fast --lcov --output-path lcov.info env: RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=/usr/local/bin/mold -Z threads=8" - - name: Upload coverage - uses: codecov/codecov-action@v4 + - name: Store coverage file artifact + uses: actions/upload-artifact@v4 with: - files: lcov.info - fail_ci_if_error: true - token: ${{ secrets.CODECOV_TOKEN }} + name: unit-cov-${{ github.event.pull_request.head.sha || github.sha }}.info + path: lcov.info # output of `make test-unit-with-coverage` - name: Clean cargo cache if: steps.cache.outputs.cache-hit != 'true' run: cargo cache --autoclean-expensive @@ -387,10 +386,16 @@ jobs: with: name: wasm-for-tests-${{ github.event.pull_request.head.sha|| github.sha }} path: wasm_for_tests - - name: Run integration tests - run: cargo +${{ env.NIGHTLY }} nextest run -E 'test(integration)' --test-threads 1 --no-fail-fast + - name: Run integration tests with coverage + run: make test-integration-with-coverage + # run: cargo +${{ env.NIGHTLY }} nextest run -E 'test(integration)' --test-threads 1 --no-fail-fast env: RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=/usr/local/bin/mold -Z threads=8" + - name: Store coverage file artifact + uses: actions/upload-artifact@v4 + with: + name: integration-cov-${{ github.event.pull_request.head.sha || github.sha }}.info + path: lcov.info # output of `make test-integration-with-coverage` - name: Clean cargo cache if: steps.cache.outputs.cache-hit != 'true' run: cargo cache --autoclean-expensive @@ -607,4 +612,27 @@ jobs: run: cargo cache --autoclean-expensive - name: Stop sccache if: always() && steps.sccache.conclusion == 'success' - run: sccache --stop-server || true \ No newline at end of file + run: sccache --stop-server || true + + upload-coverage: + runs-on: [ubuntu-latest] + timeout-minutes: 20 + needs: [test-unit, test-integration] + + steps: + - name: Download unit coverage artifacts + uses: actions/download-artifact@v4 + with: + name: unit-cov-${{ github.event.pull_request.head.sha || github.sha }}.info + path: unit-cov.info + - name: Download integration coverage artifacts + uses: actions/download-artifact@v4 + with: + name: integration-cov-${{ github.event.pull_request.head.sha || github.sha }}.info + path: integration-cov.info + - name: Upload coverage to codecov + uses: codecov/codecov-action@v4 + with: + files: integration-cov.info, unit-cov.info + fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/Makefile b/Makefile index 486f40f92b..3105c234f1 100644 --- a/Makefile +++ b/Makefile @@ -200,17 +200,15 @@ test-unit-with-eth-bridge: -Z unstable-options --report-time test-unit-with-coverage: - $(cargo) +$(nightly) llvm-cov --output-path lcov.info \ + $(cargo) +$(nightly) llvm-cov --lib --output-path lcov.info \ --lcov \ - -- --lib \ - --skip e2e --skip pos_state_machine_test --skip integration \ + -- --skip e2e --skip pos_state_machine_test --skip integration \ -Z unstable-options --report-time test-integration-with-coverage: - $(cargo) +$(nightly) llvm-cov --output-path lcov.info \ + $(cargo) +$(nightly) llvm-cov --lib --output-path lcov.info \ --lcov \ -- integration \ - --lib \ --test-threads=1 \ -Z unstable-options --report-time