referrerpolicy=no-referrer-when-downgrade

sc_network_light/
schema.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19//! Include sources generated from protobuf definitions.
20
21pub(crate) mod v1 {
22	pub(crate) mod light {
23		include!(concat!(env!("OUT_DIR"), "/api.v1.light.rs"));
24	}
25}
26
27#[cfg(test)]
28mod tests {
29	use prost::Message as _;
30
31	#[test]
32	fn empty_proof_encodes_correctly() {
33		let encoded = super::v1::light::Response {
34			response: Some(super::v1::light::response::Response::RemoteReadResponse(
35				super::v1::light::RemoteReadResponse { proof: Some(Vec::new()) },
36			)),
37		}
38		.encode_to_vec();
39
40		// Make sure that the response contains one field of number 2 and wire type 2 (message),
41		// then another field of number 2 and wire type 2 (bytes), then a length of 0.
42		assert_eq!(encoded, vec![(2 << 3) | 2, 2, (2 << 3) | 2, 0]);
43	}
44
45	#[test]
46	fn no_proof_encodes_correctly() {
47		let encoded = super::v1::light::Response {
48			response: Some(super::v1::light::response::Response::RemoteReadResponse(
49				super::v1::light::RemoteReadResponse { proof: None },
50			)),
51		}
52		.encode_to_vec();
53
54		// Make sure that the response contains one field of number 2 and wire type 2 (message).
55		assert_eq!(encoded, vec![(2 << 3) | 2, 0]);
56	}
57
58	#[test]
59	fn proof_encodes_correctly() {
60		let encoded = super::v1::light::Response {
61			response: Some(super::v1::light::response::Response::RemoteReadResponse(
62				super::v1::light::RemoteReadResponse { proof: Some(vec![1, 2, 3, 4]) },
63			)),
64		}
65		.encode_to_vec();
66
67		assert_eq!(encoded, vec![(2 << 3) | 2, 6, (2 << 3) | 2, 4, 1, 2, 3, 4]);
68	}
69}