Skip to content

Commit ee58814

Browse files
committed
Add tests for POST /tx
1 parent a66615f commit ee58814

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/rest.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,23 @@ fn test_rest() -> Result<()> {
168168
tester.mine()?;
169169
assert_eq!(get_json("/mempool")?["count"].as_u64(), Some(0));
170170

171+
// Test POST /tx
172+
let txid = tester.send(&addr1, "9.9 BTC".parse().unwrap())?;
173+
let tx_hex = get_plain(&format!("/tx/{}/hex", txid))?;
174+
// Re-send the tx created by send(). It'll be accepted again since its still in the mempool.
175+
let broadcast1_resp = ureq::post(&format!("http://{}/tx", rest_addr)).send_string(&tx_hex)?;
176+
assert_eq!(broadcast1_resp.status(), 200);
177+
assert_eq!(broadcast1_resp.into_string()?, txid.to_string());
178+
// Mine the tx then submit it again. Should now fail.
179+
tester.mine()?;
180+
let broadcast2_res = ureq::post(&format!("http://{}/tx", rest_addr)).send_string(&tx_hex);
181+
let broadcast2_resp = broadcast2_res.unwrap_err().into_response().unwrap();
182+
assert_eq!(broadcast2_resp.status(), 400);
183+
assert_eq!(
184+
broadcast2_resp.into_string()?,
185+
"sendrawtransaction RPC error -27: Transaction already in block chain"
186+
);
187+
171188
// Elements-only tests
172189
#[cfg(feature = "liquid")]
173190
{

0 commit comments

Comments
 (0)