forked from captainbuckkets/peercoin-ord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.rs
91 lines (78 loc) Β· 2.11 KB
/
core.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use super::*;
struct KillOnDrop(std::process::Child);
impl Drop for KillOnDrop {
fn drop(&mut self) {
assert!(Command::new("kill")
.arg(self.0.id().to_string())
.status()
.unwrap()
.success());
}
}
#[test]
#[ignore]
fn preview() {
let port = TcpListener::bind("127.0.0.1:0")
.unwrap()
.local_addr()
.unwrap()
.port();
let builder = CommandBuilder::new(format!(
"preview --http-port {port} --files alert.html inscription.txt --batches batch_1.yaml batch_2.yaml --blocktime 1"
))
.write("inscription.txt", "Hello World")
.write("alert.html", "<script>alert('LFG!')</script>")
.write("poem.txt", "Sphinx of black quartz, judge my vow.")
.write("tulip.png", [0; 555])
.write("meow.wav", [0; 2048])
.write(
"batch_1.yaml",
"mode: shared-output\ninscriptions:\n- file: poem.txt\n- file: tulip.png\n",
)
.write(
"batch_2.yaml",
"mode: shared-output\ninscriptions:\n- file: meow.wav\n",
);
let _child = KillOnDrop(builder.command().spawn().unwrap());
for attempt in 0.. {
if let Ok(response) = reqwest::blocking::get(format!("http://127.0.0.1:{port}/status")) {
if response.status() == 200 {
assert_eq!(response.text().unwrap(), "OK");
break;
}
}
if attempt == 100 {
panic!("Server did not respond to status check",);
}
thread::sleep(Duration::from_millis(500));
}
assert_regex_match!(
reqwest::blocking::get(format!("http://127.0.0.1:{port}/inscriptions"))
.unwrap()
.text()
.unwrap(),
format!(".*(<a href=/inscription/.*){{{}}}.*", 5)
);
let blockheight = reqwest::blocking::get(format!("http://127.0.0.1:{port}/blockheight"))
.unwrap()
.text()
.unwrap()
.parse::<u64>()
.unwrap();
for attempt in 0.. {
if attempt == 20 {
panic!("Bitcoin Core did not mine blocks",);
}
if reqwest::blocking::get(format!("http://127.0.0.1:{port}/blockheight"))
.unwrap()
.text()
.unwrap()
.parse::<u64>()
.unwrap()
> blockheight
{
break;
}
thread::sleep(Duration::from_millis(250));
}
}