-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for
GET /v1/chainhooks/<uuid>
route (#415)
### Description Add tests for chainhook service, fix a few things along the way. --- ### Checklist - [X] All tests pass - [X] Tests added in this PR (if applicable) Test coverage before: 37.72% Test coverage after: 47.07%
- Loading branch information
1 parent
1868a06
commit c6ca1ba
Showing
17 changed files
with
1,338 additions
and
473 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
components/chainhook-cli/src/service/tests/helpers/build_predicates.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use rocket::serde::json::Value as JsonValue; | ||
|
||
pub const DEFAULT_UUID: &str = "4ecc-4ecc-435b-9948-d5eeca1c3ce6"; | ||
|
||
pub fn get_random_uuid() -> String { | ||
let mut rng = rand::thread_rng(); | ||
let random_digit: u64 = rand::Rng::gen(&mut rng); | ||
format!("test-uuid-{random_digit}") | ||
} | ||
|
||
pub fn build_bitcoin_payload( | ||
network: Option<&str>, | ||
if_this: Option<JsonValue>, | ||
then_that: Option<JsonValue>, | ||
filter: Option<JsonValue>, | ||
uuid: Option<&str>, | ||
) -> JsonValue { | ||
let network = network.unwrap_or("mainnet"); | ||
let if_this = if_this.unwrap_or(json!({"scope":"block"})); | ||
let then_that = then_that.unwrap_or(json!("noop")); | ||
let filter = filter.unwrap_or(json!({})); | ||
|
||
let filter = filter.as_object().unwrap(); | ||
let mut network_val = json!({ | ||
"if_this": if_this, | ||
"then_that": then_that | ||
}); | ||
for (k, v) in filter.iter() { | ||
network_val[k] = v.to_owned(); | ||
} | ||
json!({ | ||
"chain": "bitcoin", | ||
"uuid": uuid.unwrap_or(DEFAULT_UUID), | ||
"name": "test", | ||
"version": 1, | ||
"networks": { | ||
network: network_val | ||
} | ||
}) | ||
} | ||
|
||
pub fn build_stacks_payload( | ||
network: Option<&str>, | ||
if_this: Option<JsonValue>, | ||
then_that: Option<JsonValue>, | ||
filter: Option<JsonValue>, | ||
uuid: Option<&str>, | ||
) -> JsonValue { | ||
let network = network.unwrap_or("mainnet"); | ||
let if_this = if_this.unwrap_or(json!({"scope":"txid", "equals": "0xfaaac1833dc4883e7ec28f61e35b41f896c395f8d288b1a177155de2abd6052f"})); | ||
let then_that = then_that.unwrap_or(json!("noop")); | ||
let filter = filter.unwrap_or(json!({})); | ||
|
||
let filter = filter.as_object().unwrap(); | ||
let mut network_val = json!({ | ||
"if_this": if_this, | ||
"then_that": then_that | ||
}); | ||
for (k, v) in filter.iter() { | ||
network_val[k] = v.to_owned(); | ||
} | ||
json!({ | ||
"chain": "stacks", | ||
"uuid": uuid.unwrap_or(DEFAULT_UUID), | ||
"name": "test", | ||
"version": 1, | ||
"networks": { | ||
network: network_val | ||
} | ||
}) | ||
} |
Oops, something went wrong.