Skip to content

Commit

Permalink
Add test fixtures generated from local Gaia instance
Browse files Browse the repository at this point in the history
Signed-off-by: Thane Thomson <connect@thanethomson.com>
  • Loading branch information
thanethomson committed Dec 17, 2021
1 parent 5d166e3 commit ec10cf9
Show file tree
Hide file tree
Showing 33 changed files with 2,878 additions and 0 deletions.
92 changes: 92 additions & 0 deletions rpc/tests/gaia_fixtures.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
use std::fs;
use std::path::PathBuf;
use tendermint_rpc::event::Event;
use tendermint_rpc::{endpoint, Response};
use walkdir::WalkDir;

fn find_fixtures(in_out_folder_name: &str) -> Vec<PathBuf> {
WalkDir::new(
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests")
.join("gaia_fixtures")
.join(in_out_folder_name),
)
.into_iter()
.filter_map(|e| e.ok())
.filter(|e| {
e.file_type().is_file()
&& e.path().extension().is_some()
&& e.path().extension().unwrap() == "json"
})
.map(|e| e.into_path())
.collect::<Vec<PathBuf>>()
}

#[test]
fn incoming_fixtures() {
for json_file in find_fixtures("incoming") {
let file_name = json_file
.file_name()
.unwrap()
.to_str()
.unwrap()
.strip_suffix(".json")
.unwrap();
let content = fs::read_to_string(&json_file).unwrap();
match file_name {
"abci_info" => {
let r = endpoint::abci_info::Response::from_string(content);
assert!(r.is_ok(), "{:?}", r)
}
"block_at_height_0" => {
assert!(endpoint::block::Response::from_string(content).is_err())
}
"block_at_height_1" => {
assert!(endpoint::block::Response::from_string(content).is_ok())
}
"block_at_height_10" => {
assert!(endpoint::block::Response::from_string(content).is_ok())
}
"block_results_at_height_10" => {
let r = endpoint::block_results::Response::from_string(content);
assert!(r.is_ok(), "block_results_at_height_10: {:?}", r);
}
"blockchain_from_1_to_10" => {
assert!(endpoint::blockchain::Response::from_string(content).is_ok())
}
"commit_at_height_10" => {
assert!(endpoint::commit::Response::from_string(content).is_ok())
}
"consensus_params" => {
assert!(endpoint::consensus_params::Response::from_string(content).is_ok())
}
"consensus_state" => {
assert!(endpoint::consensus_state::Response::from_string(content).is_ok())
}
"genesis" => {
assert!(endpoint::genesis::Response::from_string(content).is_ok())
}
"net_info" => {
assert!(endpoint::net_info::Response::from_string(content).is_ok())
}
"status" => {
assert!(endpoint::status::Response::from_string(content).is_ok())
}
"subscribe_newblock" => {
let r = endpoint::subscribe::Response::from_string(content);
assert!(r.is_err(), "{:?}", r);
}
_ => {
if file_name.starts_with("subscribe_newblock_") {
let r = Event::from_string(content);
assert!(r.is_ok(), "failed to parse event {}: {:?}", file_name, r);
} else {
panic!("unhandled incoming fixture: {}", file_name);
}
}
}
}
}

#[test]
fn outgoing_fixtures() {}
11 changes: 11 additions & 0 deletions rpc/tests/gaia_fixtures/incoming/abci_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": "279cb095-9064-4620-bcaa-3c9383847575",
"jsonrpc": "2.0",
"result": {
"response": {
"data": "GaiaApp",
"last_block_app_hash": "vMfcSlXF/bB/xdsaQeFALAzVoY6AKqiFwchFz9ZUguc=",
"last_block_height": "154"
}
}
}
9 changes: 9 additions & 0 deletions rpc/tests/gaia_fixtures/incoming/block_at_height_0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"error": {
"code": -32603,
"data": "height must be greater than 0, but got 0",
"message": "Internal error"
},
"id": "29b5f462-d1cb-4b33-ab23-f0c96aa462b0",
"jsonrpc": "2.0"
}
57 changes: 57 additions & 0 deletions rpc/tests/gaia_fixtures/incoming/block_at_height_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"id": "6b12587c-a02b-441b-9350-6a8a5ee6fb3b",
"jsonrpc": "2.0",
"result": {
"block": {
"data": {
"txs": []
},
"evidence": {
"evidence": []
},
"header": {
"app_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
"chain_id": "ibc-0",
"consensus_hash": "048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F",
"data_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
"evidence_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
"height": "1",
"last_block_id": {
"hash": "",
"parts": {
"hash": "",
"total": 0
}
},
"last_commit_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
"last_results_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
"next_validators_hash": "0A6CA9001DB07E985DF9043045B392588DF7C1C720E30EBAEFDC8A848C551D6A",
"proposer_address": "BB22AD764B674CC08753B24175E2FC61B22B1419",
"time": "2021-12-17T20:27:28.966992937Z",
"validators_hash": "0A6CA9001DB07E985DF9043045B392588DF7C1C720E30EBAEFDC8A848C551D6A",
"version": {
"block": "11"
}
},
"last_commit": {
"block_id": {
"hash": "",
"parts": {
"hash": "",
"total": 0
}
},
"height": "0",
"round": 0,
"signatures": []
}
},
"block_id": {
"hash": "739127E7942BEF14DFF0C3C9C4A9BF0DF1A97BEFF085153817B8960273830439",
"parts": {
"hash": "AF225F2883AFC75DB7F481E5BDEE396CE9B5787399F8F9876CA980BD026C02D1",
"total": 1
}
}
}
}
64 changes: 64 additions & 0 deletions rpc/tests/gaia_fixtures/incoming/block_at_height_10.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"id": "9ba09d2c-3d72-4a7f-8e12-eae2496a65fa",
"jsonrpc": "2.0",
"result": {
"block": {
"data": {
"txs": []
},
"evidence": {
"evidence": []
},
"header": {
"app_hash": "A7139E6F28A9506629C60E3FDFD1A325E99177A4A3C8FA131732B6170C113C8E",
"chain_id": "ibc-0",
"consensus_hash": "048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F",
"data_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
"evidence_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
"height": "10",
"last_block_id": {
"hash": "CD0A81D2658C56FD65587E4502E4BC89955002B5B89F986C7D63A5AF184FBC92",
"parts": {
"hash": "6E41BBA804019240A672F9AC6625BAA6D40B3887D6F6BE3E64CF54D93F021B76",
"total": 1
}
},
"last_commit_hash": "3A9BEC015F1A923C17EF81007945F552AD4E35DDA445AFA91296564DCB748357",
"last_results_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
"next_validators_hash": "0A6CA9001DB07E985DF9043045B392588DF7C1C720E30EBAEFDC8A848C551D6A",
"proposer_address": "BB22AD764B674CC08753B24175E2FC61B22B1419",
"time": "2021-12-17T20:27:47.875954829Z",
"validators_hash": "0A6CA9001DB07E985DF9043045B392588DF7C1C720E30EBAEFDC8A848C551D6A",
"version": {
"block": "11"
}
},
"last_commit": {
"block_id": {
"hash": "CD0A81D2658C56FD65587E4502E4BC89955002B5B89F986C7D63A5AF184FBC92",
"parts": {
"hash": "6E41BBA804019240A672F9AC6625BAA6D40B3887D6F6BE3E64CF54D93F021B76",
"total": 1
}
},
"height": "9",
"round": 0,
"signatures": [
{
"block_id_flag": 2,
"signature": "d1qUrZd0jrJRGDnI3I69LXTTHh2HBLHY8U5r4YFwy7Zn+kdo30Xs0eAdhmpt7kUG/XZSr1zwyLTneRXPipn9DQ==",
"timestamp": "2021-12-17T20:27:47.875954829Z",
"validator_address": "BB22AD764B674CC08753B24175E2FC61B22B1419"
}
]
}
},
"block_id": {
"hash": "EB917FF229E0987637F20EDB8114CAC3F967D843C5CC480969D64D7A368F077F",
"parts": {
"hash": "ABFFFBEDF37CB50B0F5617D2A85110B838EA2B3E3E56CCA1E09A27DCD5BBF769",
"total": 1
}
}
}
}
Loading

0 comments on commit ec10cf9

Please sign in to comment.