forked from ordinals/ord
-
Notifications
You must be signed in to change notification settings - Fork 21
/
json_api.rs
86 lines (70 loc) Β· 2.33 KB
/
json_api.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
use {
super::*, ord::inscription_id::InscriptionId, ord::rarity::Rarity, ord::templates::sat::SatJson,
ord::SatPoint,
};
#[test]
fn get_sat_without_sat_index() {
let rpc_server = test_bitcoincore_rpc::spawn();
let response = TestServer::spawn_with_args(&rpc_server, &["--enable-json-api"])
.json_request("/sat/2099999997689999");
assert_eq!(response.status(), StatusCode::OK);
let mut sat_json: SatJson = serde_json::from_str(&response.text().unwrap()).unwrap();
// this is a hack to ignore the timestamp, since it changes for every request
sat_json.timestamp = "".into();
pretty_assert_eq!(
sat_json,
SatJson {
number: 2099999997689999,
decimal: "6929999.0".into(),
degree: "5Β°209999β²1007β³0β΄".into(),
name: "a".into(),
block: 6929999,
cycle: 5,
epoch: 32,
period: 3437,
offset: 0,
rarity: Rarity::Uncommon,
percentile: "100%".into(),
satpoint: None,
timestamp: "".into(),
inscriptions: vec![],
}
)
}
#[test]
fn get_sat_with_inscription_and_sat_index() {
let rpc_server = test_bitcoincore_rpc::spawn();
create_wallet(&rpc_server);
let Inscribe { reveal, .. } = inscribe(&rpc_server);
let inscription_id = InscriptionId::from(reveal);
let response = TestServer::spawn_with_args(&rpc_server, &["--index-sats", "--enable-json-api"])
.json_request(format!("/sat/{}", 50 * COIN_VALUE));
assert_eq!(response.status(), StatusCode::OK);
let sat_json: SatJson = serde_json::from_str(&response.text().unwrap()).unwrap();
pretty_assert_eq!(
sat_json,
SatJson {
number: 50 * COIN_VALUE,
decimal: "1.0".into(),
degree: "0Β°1β²1β³0β΄".into(),
name: "nvtcsezkbth".into(),
block: 1,
cycle: 0,
epoch: 0,
period: 0,
offset: 0,
rarity: Rarity::Uncommon,
percentile: "0.00023809523835714296%".into(),
satpoint: Some(SatPoint::from_str(&format!("{}:{}:{}", reveal, 0, 0)).unwrap()),
timestamp: "1970-01-01 00:00:01 UTC".into(),
inscriptions: vec![inscription_id],
}
)
}
#[test]
fn json_request_fails_when_not_enabled() {
let rpc_server = test_bitcoincore_rpc::spawn();
let response =
TestServer::spawn_with_args(&rpc_server, &[]).json_request("/sat/2099999997689999");
assert_eq!(response.status(), StatusCode::NOT_ACCEPTABLE);
}