Skip to content

Commit

Permalink
add mock testing for lite client
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Nov 26, 2019
1 parent 8b1d3dc commit 9e00e99
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
1 change: 1 addition & 0 deletions tendermint/src/lite/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ pub trait Vote {
fn signature(&self) -> &[u8];
}

#[derive(Debug)]
pub enum Error {
Expired,
NonSequentialHeight,
Expand Down
28 changes: 28 additions & 0 deletions tendermint/tests/lite.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use serde::{Deserialize, Serialize};
use serde_json;
use std::{fs, path::PathBuf};
use tendermint::{lite, rpc::endpoint::commit::SignedHeader, validator};

#[derive(Serialize, Deserialize, Clone, Debug)]
struct TestSuite {
signed_header: SignedHeader,
last_validators: Vec<validator::Info>,
validators: Vec<validator::Info>,
}

fn read_json_fixture(name: &str) -> String {
fs::read_to_string(PathBuf::from("./tests/support/lite/").join(name.to_owned() + ".json"))
.unwrap()
}

#[test]
fn check_verifier_with_mock_data() {
let suite: TestSuite = serde_json::from_str(&read_json_fixture("basic")).unwrap();
lite::verify_trusting(
suite.signed_header.header.clone(),
suite.signed_header,
validator::Set::new(suite.last_validators),
validator::Set::new(suite.validators),
)
.expect("verify_trusting failed");
}
78 changes: 78 additions & 0 deletions tendermint/tests/support/lite/basic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"signed_header": {
"header": {
"version": {
"block": "10",
"app": "0"
},
"chain_id": "test-chain-y3m1e6-AB",
"height": "1",
"time": "2019-11-19T07:56:45.46738Z",
"num_txs": "0",
"total_txs": "0",
"last_block_id": {
"hash": "",
"parts": {
"total": "0",
"hash": ""
}
},
"last_commit_hash": "",
"data_hash": "",
"validators_hash": "1F0F3E080DCE3253C88394F2CE479C074C5A25FE94A6C8560C76B6F2281BD685",
"next_validators_hash": "1F0F3E080DCE3253C88394F2CE479C074C5A25FE94A6C8560C76B6F2281BD685",
"consensus_hash": "048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F",
"app_hash": "2E419E5A3CDD1F718EA956E9AF91E57FD4FD5D8C8DDEA43FB3D8728E8E41852D",
"last_results_hash": "",
"evidence_hash": "",
"proposer_address": "30B3C78C25BB72796960B63AA06CA7ED5F648951"
},
"commit": {
"block_id": {
"hash": "0D06FAEB490248DC504CDD2B4318BEFCB2FD06F866BACAE9864CC5B7373D2A82",
"parts": {
"total": "1",
"hash": "C74C19586564ECC8A348BAE68D505230618B9FABB291549FFD59A6322E961865"
}
},
"precommits": [
{
"type": 2,
"height": "1",
"round": "0",
"block_id": {
"hash": "0D06FAEB490248DC504CDD2B4318BEFCB2FD06F866BACAE9864CC5B7373D2A82",
"parts": {
"total": "1",
"hash": "C74C19586564ECC8A348BAE68D505230618B9FABB291549FFD59A6322E961865"
}
},
"timestamp": "2019-11-19T07:57:02.408782Z",
"validator_address": "30B3C78C25BB72796960B63AA06CA7ED5F648951",
"validator_index": "0",
"signature": "C/AVaOIcMyXozkyMiWFAB2/hHZeBKCZ97W+ivbJtBlgwYxyVRZeQQhBF+8uxr0vvpbKDEKUIxaq8Zng1nN5LAA=="
}
]
}
},
"last_validators": [
{
"address": "30B3C78C25BB72796960B63AA06CA7ED5F648951",
"pub_key": {
"type": "tendermint/PubKeyEd25519",
"value": "ZncnqXOpTbsTYZqkbdzHne9y1h8Z1gp3Xlayfi4QzW0="
},
"voting_power": "12500000000"
}
],
"validators": [
{
"address": "30B3C78C25BB72796960B63AA06CA7ED5F648951",
"pub_key": {
"type": "tendermint/PubKeyEd25519",
"value": "ZncnqXOpTbsTYZqkbdzHne9y1h8Z1gp3Xlayfi4QzW0="
},
"voting_power": "12500000000"
}
]
}

0 comments on commit 9e00e99

Please sign in to comment.