Skip to content
This repository was archived by the owner on Apr 9, 2024. It is now read-only.

Commit f58cbf4

Browse files
authored
feat: Add indexer API test cases (#364)
* feat: Add get_cells_capacity integration test cases * feat: Add get_tip integration test cases * feat: Add get_transactions integration test cases * feat: Add get_cells integration test cases * feature: Enhance test cases * feature: Add README.md in ./tests
1 parent 54d6639 commit f58cbf4

File tree

6 files changed

+657
-0
lines changed

6 files changed

+657
-0
lines changed

tests/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Mercury integration test
2+
3+
- Run all test cases: `MERCURY_TESTNET_HOST=http://127.0.0.1:8116 cargo test`
4+
- Run all test cases in single file :`MERCURY_TESTNET_HOST=http://127.0.0.1:8116 cargo test get_balance::`
5+
- Run specified test case: `MERCURY_TESTNET_HOST=http://127.0.0.1:8116 cargo test get_balance::test_address_ckb`

tests/tests/rpc/get_cells.rs

+343
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,343 @@
1+
use super::common::post_http_request;
2+
3+
#[test]
4+
fn test_lock_script() {
5+
let resp = post_http_request(
6+
r#"{
7+
"id": 2,
8+
"jsonrpc": "2.0",
9+
"method": "get_cells",
10+
"params": [
11+
{
12+
"script": {
13+
"code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
14+
"hash_type": "type",
15+
"args": "0x0c24d18f16e3c43272695e5db006a22cb9ddde51"
16+
},
17+
"script_type": "lock"
18+
},
19+
"asc",
20+
"0x5"
21+
]
22+
}"#,
23+
);
24+
let r = &resp["result"];
25+
26+
let cells = r["objects"].as_array().unwrap();
27+
assert_eq!(cells.len(), 5);
28+
assert_eq!(cells[0]["block_number"], "0x219817");
29+
assert_eq!(cells[0]["out_point"]["index"], "0x2");
30+
assert_eq!(
31+
cells[0]["out_point"]["tx_hash"],
32+
"0xf04f3389c99a5d646b4e78b7fb5e1d8e150fa833790519b652194c848b79f533"
33+
);
34+
assert_eq!(cells[4]["block_number"], "0x21a37a");
35+
assert_eq!(cells[4]["out_point"]["index"], "0x1");
36+
assert_eq!(
37+
cells[4]["out_point"]["tx_hash"],
38+
"0xfcb4a627f5ab3cca0b9c77b4878f6379fbb3ddc9c1dbc5feead33284b75f8138"
39+
);
40+
}
41+
42+
#[test]
43+
fn test_lock_script_desc() {
44+
let resp = post_http_request(
45+
r#"{
46+
"id": 2,
47+
"jsonrpc": "2.0",
48+
"method": "get_cells",
49+
"params": [
50+
{
51+
"script": {
52+
"code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
53+
"hash_type": "type",
54+
"args": "0x0c24d18f16e3c43272695e5db006a22cb9ddde51"
55+
},
56+
"script_type": "lock"
57+
},
58+
"desc",
59+
"0x5"
60+
]
61+
}"#,
62+
);
63+
let r = &resp["result"];
64+
65+
let cells = r["objects"].as_array().unwrap();
66+
assert_eq!(cells.len(), 5);
67+
assert_eq!(cells[0]["block_number"], "0x21a37a");
68+
assert_eq!(cells[0]["out_point"]["index"], "0x1");
69+
assert_eq!(
70+
cells[0]["out_point"]["tx_hash"],
71+
"0xfcb4a627f5ab3cca0b9c77b4878f6379fbb3ddc9c1dbc5feead33284b75f8138"
72+
);
73+
assert_eq!(cells[4]["block_number"], "0x219817");
74+
assert_eq!(cells[4]["out_point"]["index"], "0x2");
75+
assert_eq!(
76+
cells[4]["out_point"]["tx_hash"],
77+
"0xf04f3389c99a5d646b4e78b7fb5e1d8e150fa833790519b652194c848b79f533"
78+
);
79+
}
80+
81+
#[test]
82+
fn test_nonexistent_lock_script() {
83+
let resp = post_http_request(
84+
r#"{
85+
"id": 2,
86+
"jsonrpc": "2.0",
87+
"method": "get_cells",
88+
"params": [
89+
{
90+
"script": {
91+
"code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
92+
"hash_type": "type",
93+
"args": "0x0c24d18f16e3c43272695e5db006a22cb9ddde52"
94+
},
95+
"script_type": "lock"
96+
},
97+
"desc",
98+
"0x5"
99+
]
100+
}"#,
101+
);
102+
let r = &resp["result"];
103+
104+
let cells = r["objects"].as_array().unwrap();
105+
assert_eq!(cells.len(), 0);
106+
}
107+
108+
#[test]
109+
fn test_type_script() {
110+
let resp = post_http_request(
111+
r#"{
112+
"id": 2,
113+
"jsonrpc": "2.0",
114+
"method": "get_cells",
115+
"params": [
116+
{
117+
"script": {
118+
"code_hash": "0xc5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4",
119+
"hash_type": "type",
120+
"args": "0x7c7f0ee1d582c385342367792946cff3767fe02f26fd7f07dba23ae3c65b28bc"
121+
},
122+
"script_type": "type"
123+
},
124+
"desc",
125+
"0x5"
126+
]
127+
}"#,
128+
);
129+
let r = &resp["result"];
130+
let cells = r["objects"].as_array().unwrap();
131+
assert_eq!(cells.len(), 5);
132+
assert_eq!(cells[0]["block_number"], "0x3a67ce");
133+
assert_eq!(cells[0]["out_point"]["index"], "0x2");
134+
assert_eq!(
135+
cells[0]["out_point"]["tx_hash"],
136+
"0x3b5c1c80c207bf9ca4b548bbb6477b825a718de91592c04c683e508708b0b71b"
137+
);
138+
assert_eq!(cells[4]["block_number"], "0x399435");
139+
assert_eq!(cells[4]["out_point"]["index"], "0x1");
140+
assert_eq!(
141+
cells[4]["out_point"]["tx_hash"],
142+
"0x8f932cf2c9d1059d2c2ebc9cab6e9bbb34d3b090de309cac5b97de9c4f596c30"
143+
);
144+
}
145+
146+
#[test]
147+
fn test_lock_and_type_script() {
148+
let resp = post_http_request(
149+
r#"{
150+
"id": 2,
151+
"jsonrpc": "2.0",
152+
"method": "get_cells",
153+
"params": [
154+
{
155+
"script": {
156+
"code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
157+
"hash_type": "type",
158+
"args": "0x0c24d18f16e3c43272695e5db006a22cb9ddde51"
159+
},
160+
"script_type": "lock",
161+
"filter": {
162+
"script": {
163+
"code_hash": "0xc5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4",
164+
"hash_type": "type",
165+
"args": "0x7c7f0ee1d582c385342367792946cff3767fe02f26fd7f07dba23ae3c65b28bc"
166+
}
167+
}
168+
},
169+
"desc",
170+
"0x5"
171+
]
172+
}"#,
173+
);
174+
let r = &resp["result"];
175+
let cells = r["objects"].as_array().unwrap();
176+
assert_eq!(cells.len(), 1);
177+
assert_eq!(cells[0]["block_number"], "0x219993");
178+
assert_eq!(cells[0]["out_point"]["index"], "0x1");
179+
assert_eq!(
180+
cells[0]["out_point"]["tx_hash"],
181+
"0xeb7ebb26f7c0f7822925001bf2eaea0b00b8f742bde38c30dc3e43efb6947b51"
182+
);
183+
}
184+
185+
#[test]
186+
fn test_type_and_lock_script() {
187+
let resp = post_http_request(
188+
r#"{
189+
"id": 2,
190+
"jsonrpc": "2.0",
191+
"method": "get_cells",
192+
"params": [
193+
{
194+
"script": {
195+
"code_hash": "0xc5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4",
196+
"hash_type": "type",
197+
"args": "0x7c7f0ee1d582c385342367792946cff3767fe02f26fd7f07dba23ae3c65b28bc"
198+
},
199+
"script_type": "type",
200+
"filter": {
201+
"script": {
202+
"code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
203+
"hash_type": "type",
204+
"args": "0x0c24d18f16e3c43272695e5db006a22cb9ddde51"
205+
}
206+
}
207+
},
208+
"desc",
209+
"0x5"
210+
]
211+
}"#,
212+
);
213+
let r = &resp["result"];
214+
let cells = r["objects"].as_array().unwrap();
215+
assert_eq!(cells.len(), 1);
216+
assert_eq!(cells[0]["block_number"], "0x219993");
217+
assert_eq!(cells[0]["out_point"]["index"], "0x1");
218+
assert_eq!(
219+
cells[0]["out_point"]["tx_hash"],
220+
"0xeb7ebb26f7c0f7822925001bf2eaea0b00b8f742bde38c30dc3e43efb6947b51"
221+
);
222+
}
223+
224+
#[ignore = "Need fix. Indexer returns sUDT cells while mercury does not."]
225+
#[test]
226+
fn test_output_data_len_range() {
227+
let resp = post_http_request(
228+
r#"{
229+
"id": 2,
230+
"jsonrpc": "2.0",
231+
"method": "get_cells",
232+
"params": [
233+
{
234+
"script": {
235+
"code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
236+
"hash_type": "type",
237+
"args": "0x0c24d18f16e3c43272695e5db006a22cb9ddde51"
238+
},
239+
"script_type": "lock",
240+
"filter": {
241+
"output_data_len_range": ["0x0", "0x2"]
242+
}
243+
},
244+
"desc",
245+
"0x5"
246+
]
247+
}"#,
248+
);
249+
let r = &resp["result"];
250+
251+
let cells = r["objects"].as_array().unwrap();
252+
assert_eq!(cells.len(), 4);
253+
assert_eq!(cells[0]["block_number"], "0x21a37a");
254+
assert_eq!(cells[0]["out_point"]["index"], "0x1");
255+
assert_eq!(
256+
cells[0]["out_point"]["tx_hash"],
257+
"0xfcb4a627f5ab3cca0b9c77b4878f6379fbb3ddc9c1dbc5feead33284b75f8138"
258+
);
259+
assert_eq!(cells[4]["block_number"], "0x219817");
260+
assert_eq!(cells[4]["out_point"]["index"], "0x2");
261+
assert_eq!(
262+
cells[4]["out_point"]["tx_hash"],
263+
"0xf04f3389c99a5d646b4e78b7fb5e1d8e150fa833790519b652194c848b79f533"
264+
);
265+
}
266+
267+
#[test]
268+
fn test_output_capacity_range() {
269+
let resp = post_http_request(
270+
r#"{
271+
"id": 2,
272+
"jsonrpc": "2.0",
273+
"method": "get_cells",
274+
"params": [
275+
{
276+
"script": {
277+
"code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
278+
"hash_type": "type",
279+
"args": "0x0c24d18f16e3c43272695e5db006a22cb9ddde51"
280+
},
281+
"script_type": "lock",
282+
"filter": {
283+
"output_capacity_range": ["0x0", "0x1000000000"]
284+
}
285+
},
286+
"desc",
287+
"0x5"
288+
]
289+
}"#,
290+
);
291+
let r = &resp["result"];
292+
293+
let cells = r["objects"].as_array().unwrap();
294+
assert_eq!(cells.len(), 3);
295+
assert_eq!(cells[0]["block_number"], "0x21a37a");
296+
assert_eq!(cells[0]["out_point"]["index"], "0x1");
297+
assert_eq!(
298+
cells[0]["out_point"]["tx_hash"],
299+
"0xfcb4a627f5ab3cca0b9c77b4878f6379fbb3ddc9c1dbc5feead33284b75f8138"
300+
);
301+
assert_eq!(cells[2]["block_number"], "0x219993");
302+
assert_eq!(cells[2]["out_point"]["index"], "0x1");
303+
assert_eq!(
304+
cells[2]["out_point"]["tx_hash"],
305+
"0xeb7ebb26f7c0f7822925001bf2eaea0b00b8f742bde38c30dc3e43efb6947b51"
306+
);
307+
}
308+
309+
#[test]
310+
fn test_block_range() {
311+
let resp = post_http_request(
312+
r#"{
313+
"id": 2,
314+
"jsonrpc": "2.0",
315+
"method": "get_cells",
316+
"params": [
317+
{
318+
"script": {
319+
"code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
320+
"hash_type": "type",
321+
"args": "0x0c24d18f16e3c43272695e5db006a22cb9ddde51"
322+
},
323+
"script_type": "lock",
324+
"filter": {
325+
"block_range": ["0x2191c0", "0x219990"]
326+
}
327+
},
328+
"desc",
329+
"0x5"
330+
]
331+
}"#,
332+
);
333+
let r = &resp["result"];
334+
335+
let cells = r["objects"].as_array().unwrap();
336+
assert_eq!(cells.len(), 1);
337+
assert_eq!(cells[0]["block_number"], "0x219817");
338+
assert_eq!(cells[0]["out_point"]["index"], "0x2");
339+
assert_eq!(
340+
cells[0]["out_point"]["tx_hash"],
341+
"0xf04f3389c99a5d646b4e78b7fb5e1d8e150fa833790519b652194c848b79f533"
342+
);
343+
}

0 commit comments

Comments
 (0)