9
9
//! - Lighthouse can issue valid requests to Web3Signer.
10
10
//! - The signatures generated by Web3Signer are identical to those which Lighthouse generates.
11
11
//!
12
- //! There is a build script in this crate which obtains the latest version of Web3Signer and makes
13
- //! it available via the `OUT_DIR`.
12
+ //! There is a `download_binary` function in the `get_web3signer` module which obtains the latest version of Web3Signer and makes
13
+ //! it available via the `TEMP_DIR`.
14
+ #![ cfg( all( test, unix, not( debug_assertions) ) ) ]
15
+
16
+ mod get_web3signer;
14
17
15
- #[ cfg( all( test, unix, not( debug_assertions) ) ) ]
16
18
mod tests {
19
+ use crate :: get_web3signer:: download_binary;
17
20
use account_utils:: validator_definitions:: {
18
21
SigningDefinition , ValidatorDefinition , ValidatorDefinitions , Web3SignerDefinition ,
19
22
} ;
20
23
use eth2_keystore:: KeystoreBuilder ;
21
24
use eth2_network_config:: Eth2NetworkConfig ;
25
+ use lazy_static:: lazy_static;
26
+ use parking_lot:: Mutex ;
22
27
use reqwest:: Client ;
23
28
use serde:: Serialize ;
24
29
use slot_clock:: { SlotClock , TestingSlotClock } ;
@@ -31,7 +36,8 @@ mod tests {
31
36
use std:: sync:: Arc ;
32
37
use std:: time:: { Duration , Instant } ;
33
38
use task_executor:: TaskExecutor ;
34
- use tempfile:: TempDir ;
39
+ use tempfile:: { tempdir, TempDir } ;
40
+ use tokio:: sync:: OnceCell ;
35
41
use tokio:: time:: sleep;
36
42
use types:: * ;
37
43
use url:: Url ;
@@ -51,6 +57,13 @@ mod tests {
51
57
/// debugging.
52
58
const SUPPRESS_WEB3SIGNER_LOGS : bool = true ;
53
59
60
+ lazy_static ! {
61
+ static ref TEMP_DIR : Arc <Mutex <TempDir >> = Arc :: new( Mutex :: new(
62
+ tempdir( ) . expect( "Failed to create temporary directory" )
63
+ ) ) ;
64
+ static ref GET_WEB3SIGNER_BIN : OnceCell <( ) > = OnceCell :: new( ) ;
65
+ }
66
+
54
67
type E = MainnetEthSpec ;
55
68
56
69
/// This marker trait is implemented for objects that we wish to compare to ensure Web3Signer
@@ -99,7 +112,10 @@ mod tests {
99
112
100
113
/// The location of the Web3Signer binary generated by the build script.
101
114
fn web3signer_binary ( ) -> PathBuf {
102
- PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) )
115
+ TEMP_DIR
116
+ . lock ( )
117
+ . path ( )
118
+ . to_path_buf ( )
103
119
. join ( "web3signer" )
104
120
. join ( "bin" )
105
121
. join ( "web3signer" )
@@ -143,6 +159,19 @@ mod tests {
143
159
144
160
impl Web3SignerRig {
145
161
pub async fn new ( network : & str , listen_address : & str , listen_port : u16 ) -> Self {
162
+ GET_WEB3SIGNER_BIN
163
+ . get_or_init ( || async {
164
+ // Read a Github API token from the environment. This is intended to prevent rate-limits on CI.
165
+ // We use a name that is unlikely to accidentally collide with anything the user has configured.
166
+ let github_token = env:: var ( "LIGHTHOUSE_GITHUB_TOKEN" ) ;
167
+ download_binary (
168
+ TEMP_DIR . lock ( ) . path ( ) . to_path_buf ( ) ,
169
+ github_token. as_deref ( ) . unwrap_or ( "" ) ,
170
+ )
171
+ . await ;
172
+ } )
173
+ . await ;
174
+
146
175
let keystore_dir = TempDir :: new ( ) . unwrap ( ) ;
147
176
let keypair = testing_keypair ( ) ;
148
177
let keystore =
0 commit comments