diff --git a/Cargo.lock b/Cargo.lock index 5f9deb55a..cdee7569e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -438,7 +438,7 @@ dependencies = [ "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "sled 0.29.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tendermint 0.10.0 (git+https://github.com/crypto-com/tendermint-rs.git?rev=95823039071a44dabc24825b777d3c5b95a6665b)", + "tendermint 0.10.0 (git+https://github.com/crypto-com/tendermint-rs.git?rev=bb27fdc5dd0ce59767badab246d1d4c203cf3d23)", "websocket 0.24.0 (registry+https://github.com/rust-lang/crates.io-index)", "zeroize 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1008,15 +1008,6 @@ name = "hex" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "hkdf" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "hmac 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "hmac" version = "0.7.1" @@ -2662,14 +2653,11 @@ dependencies = [ [[package]] name = "tendermint" version = "0.10.0" -source = "git+https://github.com/crypto-com/tendermint-rs.git?rev=95823039071a44dabc24825b777d3c5b95a6665b#95823039071a44dabc24825b777d3c5b95a6665b" +source = "git+https://github.com/crypto-com/tendermint-rs.git?rev=bb27fdc5dd0ce59767badab246d1d4c203cf3d23#bb27fdc5dd0ce59767badab246d1d4c203cf3d23" dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", - "digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "hkdf 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)", "prost-amino 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "prost-amino-derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2684,7 +2672,6 @@ dependencies = [ "tai64 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", - "x25519-dalek 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "zeroize 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3282,16 +3269,6 @@ dependencies = [ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "x25519-dalek" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "yasna" version = "0.3.1" @@ -3445,7 +3422,6 @@ dependencies = [ "checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "023b39be39e3a2da62a94feb433e91e8bcd37676fbc8bea371daf52b7a769a3e" -"checksum hkdf 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "35e8f9d776bbe83f1ff24951f7cc19140fb7ff8d0378463c4c4955f6b0d3e503" "checksum hmac 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695" "checksum http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "d7e06e336150b178206af098a055e3621e8336027e2b4d126bda0bc64824baaf" "checksum http-body 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6741c859c1b2463a423a1dbce98d418e6c3c3fc720fb0d45528657320920292d" @@ -3628,7 +3604,7 @@ dependencies = [ "checksum tai64 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4014289c3d2b8168880ae86633247e73712fcc579969aff0ca7c5dcd17456b82" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" -"checksum tendermint 0.10.0 (git+https://github.com/crypto-com/tendermint-rs.git?rev=95823039071a44dabc24825b777d3c5b95a6665b)" = "" +"checksum tendermint 0.10.0 (git+https://github.com/crypto-com/tendermint-rs.git?rev=bb27fdc5dd0ce59767badab246d1d4c203cf3d23)" = "" "checksum termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e" "checksum termion 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a8fb22f7cde82c8220e5aeacb3258ed7ce996142c77cba193f203515e26c330" "checksum termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72b620c5ea021d75a735c943269bb07d30c9b77d6ac6b236bc8b5c496ef05625" @@ -3694,7 +3670,6 @@ dependencies = [ "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum wincolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -"checksum x25519-dalek 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7ee1585dc1484373cbc1cee7aafda26634665cf449436fd6e24bfd1fad230538" "checksum yasna 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a563d10ead87e2d798e357d44f40f495ad70bcee4d5c0d3f77a5b1b7376645d9" "checksum zeroize 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8ddfeb6eee2fb3b262ef6e0898a52b7563bb8e0d5955a313b3cf2f808246ea14" "checksum zeroize 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "45af6a010d13e4cf5b54c94ba5a2b2eba5596b9e46bf5875612d332a1f2b3f86" diff --git a/client-common/Cargo.toml b/client-common/Cargo.toml index e9892ace4..5dcd1b51f 100644 --- a/client-common/Cargo.toml +++ b/client-common/Cargo.toml @@ -23,7 +23,7 @@ jsonrpc = { version = "0.11", optional = true } serde_json = { version = "1.0", optional = true } parity-scale-codec = { features = ["derive"], version = "1.0" } websocket = { version = "0.24", default-features = false, features = ["sync"], optional = true } -tendermint = { git = "https://github.com/crypto-com/tendermint-rs.git", rev="95823039071a44dabc24825b777d3c5b95a6665b" } +tendermint = { git = "https://github.com/crypto-com/tendermint-rs.git", rev = "bb27fdc5dd0ce59767badab246d1d4c203cf3d23" } [features] default = ["sled", "websocket-rpc"] diff --git a/client-common/src/tendermint/types.rs b/client-common/src/tendermint/types.rs index 70078accb..6aa5d081f 100644 --- a/client-common/src/tendermint/types.rs +++ b/client-common/src/tendermint/types.rs @@ -1,17 +1,17 @@ -//! Structures used in Tendermint RPC (auto-generated) +//! Structures used in Tendermint RPC mod block_results; +pub mod mock; use base64::decode; use parity_scale_codec::Decode; use serde::{Deserialize, Serialize}; -pub use self::block_results::*; use crate::{ErrorKind, Result, ResultExt, Transaction}; - use chain_core::init::config::InitConfig; use chain_core::tx::fee::LinearFee; use chain_core::tx::{TxAux, TxEnclaveAux}; +pub use self::block_results::*; pub use tendermint::rpc::endpoint::{ abci_query::AbciQuery, abci_query::Response as AbciQueryResponse, block::Response as BlockResponse, broadcast::tx_sync::Response as BroadcastTxResponse, diff --git a/client-common/src/tendermint/types/mock.rs b/client-common/src/tendermint/types/mock.rs new file mode 100644 index 000000000..aeaf31f7c --- /dev/null +++ b/client-common/src/tendermint/types/mock.rs @@ -0,0 +1,121 @@ +#![allow(missing_docs)] +use super::*; +use serde_json; +use std::str::FromStr; +use tendermint::{ + account, block, chain, channel, net, node, validator, vote, Moniker, PrivateKey, PublicKey, + Version, +}; + +static DEFAULT_VALIDATOR_KEY: &str = "{ + \"type\": \"tendermint/PrivKeyEd25519\", + \"value\": \"gJWgIetdLxRc/C2t/XjV65NCqZLTqHS9pU69kBzRmyOKCHDqT/6bKPmKajdBp+KCbYtu9ttTX7+MXrEQOw8Kqg==\" +}"; +static BLOCK_VERSION: u64 = 10; +static APP_VERSION: u64 = 0; +static APP_HASH: &str = "93E6C15E5A52CAAB971A810E5F6F9C4965AA102C81120FCEDCB7F8A112270380"; + +pub fn validator_priv_key() -> PrivateKey { + serde_json::from_str(DEFAULT_VALIDATOR_KEY).unwrap() +} + +pub fn validator_pub_key() -> PublicKey { + validator_priv_key().public_key() +} + +pub fn validator_account_id() -> account::Id { + validator_pub_key().into() +} + +pub fn default_chain_id() -> chain::Id { + chain::Id::from_str("test-chain-ktDVXo-AB").unwrap() +} + +pub fn validator_info() -> validator::Info { + validator::Info { + address: validator_account_id(), + pub_key: validator_pub_key(), + voting_power: vote::Power::new(12500000000), + proposer_priority: None, + } +} + +pub fn node_info() -> node::Info { + node::Info { + protocol_version: node::info::ProtocolVersionInfo { + p2p: 7, + block: BLOCK_VERSION, + app: APP_VERSION, + }, + id: node::Id::from_str("7edc638f79308dfdfcd77b743e1375b8e1cea6f2").unwrap(), + listen_addr: node::info::ListenAddress::new("tcp://0.0.0.0:26656".to_owned()), + network: default_chain_id(), + version: Version::default(), + channels: channel::Channels::default(), + moniker: Moniker::from_str("test").unwrap(), + other: node::info::OtherInfo { + tx_index: node::info::TxIndexStatus::On, + rpc_address: net::Address::from_str("tcp://127.0.0.1:26657").unwrap(), + }, + } +} + +pub fn default_header() -> Header { + Header { + version: block::header::Version { + block: BLOCK_VERSION, + app: APP_VERSION, + }, + chain_id: default_chain_id(), + height: Height::default(), + time: Time::default(), + num_txs: 0, + total_txs: 0, + last_block_id: block::Id::default(), + last_commit_hash: Hash::default(), + data_hash: Hash::default(), + validators_hash: Hash::default(), + next_validators_hash: Hash::default(), + consensus_hash: Hash::default(), + app_hash: Hash::from_str(APP_HASH).unwrap(), + last_results_hash: Hash::default(), + evidence_hash: Hash::default(), + proposer_address: validator_account_id(), + } +} + +pub fn default_block() -> Block { + Block { + header: default_header(), + data: Default::default(), + evidence: Default::default(), + last_commit: block::Commit { + block_id: Default::default(), + precommits: Default::default(), + }, + } +} + +pub fn status_response() -> Status { + Status { + node_info: node_info(), + sync_info: status::SyncInfo::default(), + validator_info: validator_info(), + } +} + +#[cfg(test)] +mod tests { + use super::*; + use serde_json; + + #[test] + fn check_status_response() { + println!("{}", serde_json::to_string(&status_response()).unwrap()); + } + + #[test] + fn check_default_header() { + println!("{}", serde_json::to_string(&default_header()).unwrap()); + } +} diff --git a/client-core/src/synchronizer/manual_synchronizer.rs b/client-core/src/synchronizer/manual_synchronizer.rs index 278eff0f4..212eac719 100644 --- a/client-core/src/synchronizer/manual_synchronizer.rs +++ b/client-core/src/synchronizer/manual_synchronizer.rs @@ -295,6 +295,7 @@ mod tests { }; use chain_core::tx::TxAux; use client_common::storage::MemoryStorage; + use client_common::tendermint::types::mock::*; use client_common::tendermint::types::*; use client_common::ErrorKind; @@ -361,7 +362,7 @@ mod tests { .unwrap(), ..Default::default() }, - ..Default::default() + ..status_response() }) } @@ -375,9 +376,9 @@ mod tests { .unwrap(), height: height.into(), time: Time::from_str("2019-04-09T09:38:41.735577Z").unwrap(), - ..Default::default() + ..default_header() }, - ..Default::default() + ..default_block() }) } else if height == 2 { Ok(Block { @@ -388,10 +389,10 @@ mod tests { .unwrap(), height: height.into(), time: Time::from_str("2019-04-10T09:38:41.735577Z").unwrap(), - ..Default::default() + ..default_header() }, data: Data::new(vec![abci::Transaction::new(unbond_transaction().encode())]), - ..Default::default() + ..default_block() }) } else { Err(ErrorKind::InvalidInput.into()) diff --git a/client-rpc/src/rpc/wallet_rpc.rs b/client-rpc/src/rpc/wallet_rpc.rs index 899308a68..145ccf3e4 100644 --- a/client-rpc/src/rpc/wallet_rpc.rs +++ b/client-rpc/src/rpc/wallet_rpc.rs @@ -281,6 +281,7 @@ pub mod tests { use chain_core::tx::fee::{Fee, FeeAlgorithm}; use chain_core::tx::{PlainTxAux, TransactionId, TxAux, TxObfuscated}; use client_common::storage::MemoryStorage; + use client_common::tendermint::types::mock::*; use client_common::tendermint::types::*; use client_common::tendermint::Client; use client_common::{ @@ -384,7 +385,7 @@ pub mod tests { .unwrap(), ..Default::default() }, - ..Default::default() + ..status_response() }) } @@ -396,9 +397,9 @@ pub mod tests { ) .unwrap(), time: Time::from_str("2019-04-09T09:38:41.735577Z").unwrap(), - ..Default::default() + ..default_header() }, - ..Default::default() + ..default_block() }) } @@ -413,9 +414,9 @@ pub mod tests { ) .unwrap(), time: Time::from_str("2019-04-09T09:38:41.735577Z").unwrap(), - ..Default::default() + ..default_header() }, - ..Default::default() + ..default_block() }]) }