      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173

    // Copyright 2015-2017 Parity Technologies (UK) Ltd.
    // This file is part of Parity.

    // Parity is free software: you can redistribute it and/or modify
    // it under the terms of the GNU General Public License as published by
    // the Free Software Foundation, either version 3 of the License, or
    // (at your option) any later version.

    // Parity is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    // GNU General Public License for more details.

    // You should have received a copy of the GNU General Public License
    // along with Parity.  If not, see <http://www.gnu.org/licenses/>.

    #[cfg(test)]
    mod tests {

    	use super::super::service::*;
    	use super::super::binary::*;
    	use super::super::nested::{DBClient, DBWriter};
    	use ipc::*;
    	use devtools::*;
    	use semver::Version;
    	use std::sync::Arc;

    	#[test]
    	fn call_service() {
    		// method_num = 0, f = 10 (method Service::commit)
    		let mut socket = TestSocket::new_ready(vec![
    			0, 16,
    			0, 0, 0, 0, 0, 0, 0, 0,
    			4, 0, 0, 0, 0, 0, 0, 0,
    			10, 0, 0, 0]);

    		let service = Arc::new(Service::new());
    		assert_eq!(0, *service.commits.read().unwrap());

    		service.dispatch(&mut socket);

    		assert_eq!(10, *service.commits.read().unwrap());
    	}

    	#[test]
    	fn call_service_client() {
    		let mut socket = TestSocket::new();
    		socket.read_buffer = vec![10, 0, 0, 0];
    		let service_client = ServiceClient::init(socket);

    		let result = service_client.commit(5);

    		assert_eq!(
    			vec![0, 16,
    				0, 0, 0, 0, 0, 0, 0, 0,
    				4, 0, 0, 0, 0, 0, 0, 0,
    				5, 0, 0, 0],
    			service_client.socket().write().unwrap().write_buffer.clone());
    		assert_eq!(10, result);
    	}

    	#[test]
    	fn call_service_client_optional() {
    		let mut socket = TestSocket::new();
    		socket.read_buffer = vec![10, 0, 0, 0];
    		let service_client = ServiceClient::init(socket);

    		let result = service_client.rollback(Some(5), 10);

    		assert_eq!(vec![
    			0, 17,
    			1, 0, 0, 0, 0, 0, 0, 0,
    			4, 0, 0, 0, 0, 0, 0, 0,
    			8, 0, 0, 0, 0, 0, 0, 0,
    			5, 0, 0, 0, 10, 0, 0, 0], service_client.socket().write().unwrap().write_buffer.clone());
    		assert_eq!(10, result);
    	}

    	#[test]
    	fn query_default_version() {
    		let ver = Service::protocol_version();
    		assert_eq!(ver, Version::parse("1.0.0").unwrap());
    		let ver = Service::api_version();
    		assert_eq!(ver, Version::parse("1.0.0").unwrap());
    	}

    	#[test]
    	fn call_service_client_handshake() {
    		let mut socket = TestSocket::new();
    		socket.read_buffer = vec![1];
    		let service_client = ServiceClient::init(socket);

    		let result = service_client.handshake();

    		assert!(result.is_ok());
    	}

    	#[test]
    	fn can_use_custom_params() {
    		let mut socket = TestSocket::new();
    		socket.read_buffer = vec![1];
    		let service_client = ServiceClient::init(socket);

    		let result = service_client.push_custom(CustomData { a: 3, b: 11});

    		assert_eq!(vec![
    			// message num..
    			0, 18,
    			// variable size length-s
    			1, 0, 0, 0, 0, 0, 0, 0,
    			16, 0, 0, 0, 0, 0, 0, 0,
    			// total length
    			16, 0, 0, 0, 0, 0, 0, 0,
    			// items
    			3, 0, 0, 0, 0, 0, 0, 0,
    			11, 0, 0, 0, 0, 0, 0, 0],
    			service_client.socket().write().unwrap().write_buffer.clone());
    		assert_eq!(true, result);
    	}

    	#[test]
    	fn can_invoke_generic_service() {
    		let mut socket = TestSocket::new();
    		socket.read_buffer = vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
    		let db_client = DBClient::<u64, _>::init(socket);
    		let result = db_client.write(vec![1u8; 1]);
    		assert_eq!(vec![0, 16, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1],
    			db_client.socket().write().unwrap().write_buffer.clone());
    		assert!(result.is_ok());
    	}

    	#[test]
    	fn can_handshake_generic_service() {
    		let mut socket = TestSocket::new();
    		socket.read_buffer = vec![1];
    		let db_client = DBClient::<u64, _>::init(socket);

    		let result = db_client.handshake();

    		assert!(result.is_ok());
    	}

    	#[test]
    	fn can_serialize_dummy_structs() {
    		let mut socket = TestSocket::new();

    		let struct_ = DoubleRoot { x1: 0, x2: 100, x3: 100000};
    		let res = ::ipc::binary::serialize_into(&struct_, &mut socket);

    		assert!(res.is_ok());

    		let mut read_socket = TestSocket::new_ready(socket.write_buffer.clone());
    		let new_struct: DoubleRoot = ::ipc::binary::deserialize_from(&mut read_socket).unwrap();

    		assert_eq!(struct_, new_struct);
    	}

    	#[test]
    	fn can_call_void_method() {
    		let mut socket = TestSocket::new();
    		socket.read_buffer = vec![1];
    		let service_client = ServiceClient::init(socket);

    		service_client.void(99);

    		assert_eq!(vec![
    			0, 19,
    			0, 0, 0, 0, 0, 0, 0, 0,
    			8, 0, 0, 0, 0, 0, 0, 0,
    			99, 0, 0, 0, 0, 0, 0, 0],
    			service_client.socket().write().unwrap().write_buffer.clone());
    	}
    }

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result
+
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)