Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(rpc): test snapshots for Eth* methods #5165

Merged
merged 6 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ slow-timeout = { period = "120s", terminate-after = 3 }
filter = 'test(create_manifest_json)'
slow-timeout = { period = "120s", terminate-after = 3 }

# This test downloads RPC test snapshot files from the network, which can take a while.
# It is only run on CI, so we can afford to be more patient.
[[profile.default.overrides]]
filter = 'test(tool::subcommands::api_cmd::test_snapshot::tests::rpc_regression_tests)'
slow-timeout = { period = "120s", terminate-after = 3 }

[[profile.default.overrides]]
# lint runs `cargo check` for source file discovery, which can take a while
filter = 'binary(lint)'
Expand Down
17 changes: 16 additions & 1 deletion src/tool/subcommands/api_cmd/test_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,21 @@ async fn ctx(
mod tests {
use super::*;
use crate::{daemon::db_util::download_to, utils::net::global_http_client};
use backon::{ExponentialBuilder, Retryable as _};
use directories::ProjectDirs;
use futures::{stream::FuturesUnordered, StreamExt};
use itertools::Itertools as _;
use md5::{Digest as _, Md5};
use std::time::Duration;
use url::Url;

#[tokio::test]
async fn rpc_regression_tests() {
// Skip for debug build on CI as the downloading is slow and flaky
if crate::utils::is_ci() && crate::utils::is_debug_build() {
return;
}

let urls = include_str!("test_snapshots.txt")
.trim()
.split("\n")
Expand Down Expand Up @@ -202,7 +209,15 @@ mod tests {
}

async fn get_digital_ocean_space_url_etag(url: Url) -> anyhow::Result<Option<String>> {
let response = global_http_client().head(url).send().await?;
const TIMEOUT: Duration = Duration::from_secs(5);
let response = (|| {
global_http_client()
.head(url.clone())
.timeout(TIMEOUT)
.send()
})
.retry(ExponentialBuilder::default())
.await?;
Ok(response
.headers()
.get("etag")
Expand Down
16 changes: 16 additions & 0 deletions src/tool/subcommands/api_cmd/test_snapshots.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ filecoin_chainhasobj_1736937942818251.rpcsnap.json.zst
filecoin_chainreadobj_1736937942818676.rpcsnap.json.zst
filecoin_chainstatobj_1736937942819063.rpcsnap.json.zst
filecoin_chaintipsetweight_1736937942819105.rpcsnap.json.zst
filecoin_ethaccounts_1737446676689764.rpcsnap.json.zst
filecoin_ethaddresstofilecoinaddress_1737446676692760.rpcsnap.json.zst
filecoin_ethcall_1737446676693468.rpcsnap.json.zst
filecoin_ethchainid_1736937942819147.rpcsnap.json.zst
filecoin_ethfeehistory_1737446676883828.rpcsnap.json.zst
filecoin_ethgetbalance_1737446676695335.rpcsnap.json.zst
filecoin_ethgetblockbynumber_1737446676696328.rpcsnap.json.zst
filecoin_ethgetblocktransactioncountbynumber_1737446676697272.rpcsnap.json.zst
filecoin_ethgetcode_1737446676697285.rpcsnap.json.zst
filecoin_ethgetlogs_1737446676697398.rpcsnap.json.zst
filecoin_ethgetmessagecidbytransactionhash_1737446676697418.rpcsnap.json.zst
filecoin_ethgetstorageat_1737446676697795.rpcsnap.json.zst
filecoin_ethgettransactionhashbycid_1737446676698540.rpcsnap.json.zst
filecoin_ethprotocolversion_1737446676698826.rpcsnap.json.zst
filecoin_ethtraceblock_1737446676736475.rpcsnap.json.zst
filecoin_ethuninstallfilter_1737446676698857.rpcsnap.json.zst
filecoin_minergetbaseinfo_1737022538680883.rpcsnap.json.zst
filecoin_minergetbaseinfo_1737022538681402.rpcsnap.json.zst
filecoin_stategetallallocations_1733735079961566.rpcsnap.json.zst
Expand Down
11 changes: 11 additions & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ pub enum RetryError {
RetriesExceeded,
}

#[cfg(test)]
pub fn is_debug_build() -> bool {
cfg!(debug_assertions)
}

#[cfg(test)]
pub fn is_ci() -> bool {
// https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#default-environment-variables
misc::env::is_env_truthy("CI")
}

#[cfg(test)]
mod tests {
mod files;
Expand Down
Loading