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

[Merged by Bors] - CI fix: move download web3signer binary out of build script #4163

Closed
Closed
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions testing/web3signer_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name = "web3signer_tests"
version = "0.1.0"
edition = "2021"

build = "build.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand All @@ -27,9 +25,7 @@ serde = "1.0.116"
serde_derive = "1.0.116"
serde_yaml = "0.8.13"
eth2_network_config = { path = "../../common/eth2_network_config" }

[build-dependencies]
tokio = { version = "1.14.0", features = ["rt-multi-thread", "macros"] }
reqwest = { version = "0.11.0", features = ["json","stream"] }
serde_json = "1.0.58"
zip = "0.5.13"
lazy_static = "1.4.0"
parking_lot = "0.12.0"
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ use zip::ZipArchive;
/// Use `Some("21.8.1")` to download a specific version.
const FIXED_VERSION_STRING: Option<&str> = None;

#[tokio::main]
async fn main() {
let out_dir = env::var("OUT_DIR").unwrap();

// Read a Github API token from the environment. This is intended to prevent rate-limits on CI.
// We use a name that is unlikely to accidentally collide with anything the user has configured.
let github_token = env::var("LIGHTHOUSE_GITHUB_TOKEN");

download_binary(out_dir.into(), github_token.as_deref().unwrap_or("")).await;
}

pub async fn download_binary(dest_dir: PathBuf, github_token: &str) {
let version_file = dest_dir.join("version");

Expand Down
37 changes: 33 additions & 4 deletions testing/web3signer_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@
//! - The signatures generated by Web3Signer are identical to those which Lighthouse generates.
//!
//! There is a build script in this crate which obtains the latest version of Web3Signer and makes
michaelsproul marked this conversation as resolved.
Show resolved Hide resolved
//! it available via the `OUT_DIR`.
//! it available via the `TEMP_DIR`.
#![cfg(all(test, unix, not(debug_assertions)))]

mod get_web3signer;

#[cfg(all(test, unix, not(debug_assertions)))]
mod tests {
use crate::get_web3signer::download_binary;
use account_utils::validator_definitions::{
SigningDefinition, ValidatorDefinition, ValidatorDefinitions, Web3SignerDefinition,
};
use eth2_keystore::KeystoreBuilder;
use eth2_network_config::Eth2NetworkConfig;
use lazy_static::lazy_static;
use parking_lot::Mutex;
use reqwest::Client;
use serde::Serialize;
use slot_clock::{SlotClock, TestingSlotClock};
Expand All @@ -31,7 +36,8 @@ mod tests {
use std::sync::Arc;
use std::time::{Duration, Instant};
use task_executor::TaskExecutor;
use tempfile::TempDir;
use tempfile::{tempdir, TempDir};
use tokio::sync::OnceCell;
use tokio::time::sleep;
use types::*;
use url::Url;
Expand All @@ -51,6 +57,13 @@ mod tests {
/// debugging.
const SUPPRESS_WEB3SIGNER_LOGS: bool = true;

lazy_static! {
static ref TEMP_DIR: Arc<Mutex<TempDir>> = Arc::new(Mutex::new(
tempdir().expect("Failed to create temporary directory")
));
static ref GET_WEB3SIGNER_BIN: OnceCell<()> = OnceCell::new();
}

type E = MainnetEthSpec;

/// This marker trait is implemented for objects that we wish to compare to ensure Web3Signer
Expand Down Expand Up @@ -99,7 +112,10 @@ mod tests {

/// The location of the Web3Signer binary generated by the build script.
fn web3signer_binary() -> PathBuf {
PathBuf::from(env::var("OUT_DIR").unwrap())
TEMP_DIR
.lock()
.path()
.to_path_buf()
.join("web3signer")
.join("bin")
.join("web3signer")
Expand Down Expand Up @@ -143,6 +159,19 @@ mod tests {

impl Web3SignerRig {
pub async fn new(network: &str, listen_address: &str, listen_port: u16) -> Self {
GET_WEB3SIGNER_BIN
.get_or_init(|| async {
// Read a Github API token from the environment. This is intended to prevent rate-limits on CI.
// We use a name that is unlikely to accidentally collide with anything the user has configured.
let github_token = env::var("LIGHTHOUSE_GITHUB_TOKEN");
download_binary(
TEMP_DIR.lock().path().to_path_buf(),
github_token.as_deref().unwrap_or(""),
)
.await;
})
.await;

let keystore_dir = TempDir::new().unwrap();
let keypair = testing_keypair();
let keystore =
Expand Down