#![allow(dead_code)]
pub mod node;
use std::path::PathBuf;
use df_elysium_core::account::LocalKey;
use df_elysium_core::utils::{Address, hex};
use df_elysium_core::{B256, U256};
use serde_json::Value;
pub const KEY: &str = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
pub fn key() -> LocalKey {
LocalKey::from_hex(KEY).unwrap()
}
pub fn fixture(path: &str) -> String {
read(&root().join("fixtures").join(path))
}
pub fn vector(path: &str) -> String {
read(&root().join("vectors").join(path))
}
pub fn elysium() -> Value {
serde_json::from_str(&vector("elysium_testnet.json")).unwrap()
}
pub fn hyperevm() -> Value {
serde_json::from_str(&vector("hyperevm_testnet.json")).unwrap()
}
pub fn arbitrum_sdk() -> Value {
serde_json::from_str(&vector("arbitrum_sdk.json")).unwrap()
}
pub fn call(method: &str, nth: usize) -> Value {
let file = elysium();
let found = file["calls"].as_array().unwrap().iter().filter(|call| call["method"] == method).nth(nth);
found.unwrap_or_else(|| panic!("no {method} #{nth}")).clone()
}
pub fn nitro(name: &str, nth: usize) -> Value {
let file = elysium();
let found = file["nitro"].as_array().unwrap().iter().filter(|call| call["name"] == name).nth(nth);
found.unwrap_or_else(|| panic!("no nitro {name} #{nth}")).clone()
}
pub fn step(journey: &str, step: &str) -> Value {
let file = elysium();
let found = &file["journeys"][journey][step];
assert!(found.is_object(), "no {journey}.{step}");
found.clone()
}
pub fn parent(name: &str) -> Value {
let file = hyperevm();
let found = file["calls"].as_array().unwrap().iter().find(|call| call["name"] == name);
found.unwrap_or_else(|| panic!("no parent {name}")).clone()
}
pub fn answer(entry: &Value) -> &str {
text(&entry["answer"])
}
pub fn result(entry: &Value) -> Value {
serde_json::from_str::<Value>(answer(entry)).unwrap()["result"].clone()
}
pub fn text(value: &Value) -> &str {
value.as_str().unwrap_or_else(|| panic!("{value} is not text"))
}
pub fn bytes(value: &Value) -> Vec<u8> {
hex::decode(text(value)).unwrap()
}
pub fn address(text: &str) -> Address {
text.parse().unwrap()
}
pub fn word(text: &str) -> B256 {
text.parse().unwrap()
}
pub fn number(value: &Value) -> U256 {
text(value).parse().unwrap()
}
fn root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
}
fn read(path: &PathBuf) -> String {
std::fs::read_to_string(path).unwrap_or_else(|error| panic!("{}: {error}", path.display()))
}