This repository was archived by the owner on Dec 4, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,3 +23,6 @@ tracing-subscriber.workspace = true
2323tracing.workspace = true
2424url.workspace = true
2525rs_merkle.workspace = true
26+
27+ [dev-dependencies ]
28+ reqwest = { workspace = true , features = [" json" , " blocking" ] }
Original file line number Diff line number Diff line change 1+ use std:: env;
2+
3+ use reqwest:: blocking:: Client ;
4+ use serde_json:: json;
5+ use url:: Url ;
6+
7+ pub fn project_name ( ) -> String {
8+ env:: var ( "PROJECT_NAME" ) . unwrap ( )
9+ }
10+
11+ pub fn bitcoin_url ( ) -> Url {
12+ let base = project_name ( ) ;
13+ Url :: parse ( & format ! ( "http://{base}-bitcoin-1:18443" ) ) . unwrap ( )
14+ }
15+
16+ pub fn electrs_url ( ) -> Url {
17+ let base = project_name ( ) ;
18+ Url :: parse ( & format ! ( "tcp://{base}-electrs-1:60401" ) ) . unwrap ( )
19+ }
20+
21+ pub fn generate_blocks ( blocks : u64 , ctx : & Client , address : & str ) {
22+ let endpoint = bitcoin_url ( ) ;
23+ let user = "devnet" ;
24+ let password = "devnet" ;
25+ let body = json ! ( {
26+ "jsonrpc" : "1.0" ,
27+ "id" : "1" ,
28+ "method" : "generatetoaddress" ,
29+ //developer's
30+ "params" : [ blocks, address]
31+ } ) ;
32+
33+ let response_json: serde_json:: Value = ctx
34+ . post ( endpoint)
35+ . basic_auth ( user, Some ( password) )
36+ . header ( reqwest:: header:: CONTENT_TYPE , "application/json" )
37+ . json ( & body)
38+ . send ( )
39+ . unwrap ( )
40+ . json ( )
41+ . unwrap ( ) ;
42+
43+ assert_eq ! ( response_json[ "error" ] , serde_json:: Value :: Null ) ;
44+ }
45+
46+ #[ test]
47+ fn mine_empty_block ( ) {
48+ let client = Client :: new ( ) ;
49+ generate_blocks ( 10 , & client, "mqVnk6NPRdhntvfm4hh9vvjiRkFDUuSYsH" ) ;
50+ }
You can’t perform that action at this time.
0 commit comments