Skip to main content

tnt_core_fixtures/
lib.rs

1//! Local testnet fixture data for TNT Core.
2
3use std::io;
4use std::path::{Path, PathBuf};
5
6/// Default filename for the LocalTestnet state snapshot.
7pub const LOCALTESTNET_STATE_FILENAME: &str = "localtestnet-state.json";
8
9/// Default filename for the LocalTestnet broadcast snapshot.
10pub const LOCALTESTNET_BROADCAST_FILENAME: &str = "localtestnet-broadcast.json";
11
12/// Raw JSON for the LocalTestnet anvil state snapshot.
13pub const LOCALTESTNET_STATE_JSON: &str = include_str!("../fixtures/localtestnet-state.json");
14
15/// Raw JSON for the LocalTestnet deployment broadcast.
16pub const LOCALTESTNET_BROADCAST_JSON: &str =
17    include_str!("../fixtures/localtestnet-broadcast.json");
18
19/// Returns the LocalTestnet state snapshot JSON.
20pub fn localtestnet_state_json() -> &'static str {
21    LOCALTESTNET_STATE_JSON
22}
23
24/// Returns the LocalTestnet state snapshot JSON as bytes.
25pub fn localtestnet_state_bytes() -> &'static [u8] {
26    LOCALTESTNET_STATE_JSON.as_bytes()
27}
28
29/// Returns the LocalTestnet broadcast JSON.
30pub fn localtestnet_broadcast_json() -> &'static str {
31    LOCALTESTNET_BROADCAST_JSON
32}
33
34/// Returns the LocalTestnet broadcast JSON as bytes.
35pub fn localtestnet_broadcast_bytes() -> &'static [u8] {
36    LOCALTESTNET_BROADCAST_JSON.as_bytes()
37}
38
39/// Writes both fixtures to disk using the default filenames.
40pub fn write_localtestnet_fixtures<P: AsRef<Path>>(dir: P) -> io::Result<(PathBuf, PathBuf)> {
41    let dir = dir.as_ref();
42    std::fs::create_dir_all(dir)?;
43
44    let state_path = dir.join(LOCALTESTNET_STATE_FILENAME);
45    let broadcast_path = dir.join(LOCALTESTNET_BROADCAST_FILENAME);
46
47    std::fs::write(&state_path, LOCALTESTNET_STATE_JSON)?;
48    std::fs::write(&broadcast_path, LOCALTESTNET_BROADCAST_JSON)?;
49
50    Ok((state_path, broadcast_path))
51}