2020-01-20 14:40:58 +03:00
|
|
|
// Copyright 2020 The Grin Developers
|
2018-05-30 00:57:11 +03:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2018-12-08 02:59:40 +03:00
|
|
|
use grin_p2p as p2p;
|
2018-05-30 00:57:11 +03:00
|
|
|
|
|
|
|
use num::FromPrimitive;
|
|
|
|
|
|
|
|
// Test that Healthy == 0.
|
|
|
|
#[test]
|
|
|
|
fn test_store_state_enum() {
|
|
|
|
assert_eq!(p2p::State::from_i32(0), Some(p2p::State::Healthy));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_direction_enum() {
|
|
|
|
assert_eq!(p2p::Direction::from_i32(0), Some(p2p::Direction::Inbound));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_reason_for_ban_enum() {
|
|
|
|
assert_eq!(
|
|
|
|
p2p::types::ReasonForBan::from_i32(0),
|
|
|
|
Some(p2p::types::ReasonForBan::None)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_type_enum() {
|
|
|
|
assert_eq!(p2p::msg::Type::from_i32(0), Some(p2p::msg::Type::Error));
|
|
|
|
}
|
2018-11-07 14:15:37 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_capabilities() {
|
|
|
|
assert_eq!(
|
|
|
|
p2p::types::Capabilities::from_bits_truncate(0b00000000 as u32),
|
|
|
|
p2p::types::Capabilities::UNKNOWN
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
p2p::types::Capabilities::from_bits_truncate(0b10000000 as u32),
|
|
|
|
p2p::types::Capabilities::UNKNOWN
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2018-11-13 20:28:36 +03:00
|
|
|
p2p::types::Capabilities::from_bits_truncate(0b1111 as u32),
|
2018-11-07 14:15:37 +03:00
|
|
|
p2p::types::Capabilities::FULL_NODE
|
|
|
|
);
|
|
|
|
assert_eq!(
|
2018-11-13 20:28:36 +03:00
|
|
|
p2p::types::Capabilities::from_bits_truncate(0b00001111 as u32),
|
2018-11-07 14:15:37 +03:00
|
|
|
p2p::types::Capabilities::FULL_NODE
|
|
|
|
);
|
|
|
|
assert_eq!(
|
2018-11-13 20:28:36 +03:00
|
|
|
p2p::types::Capabilities::from_bits_truncate(0b11111111 as u32),
|
2018-11-07 14:15:37 +03:00
|
|
|
p2p::types::Capabilities::FULL_NODE
|
|
|
|
);
|
|
|
|
assert_eq!(
|
2018-11-13 20:28:36 +03:00
|
|
|
p2p::types::Capabilities::from_bits_truncate(0b00101111 as u32),
|
2018-11-07 14:15:37 +03:00
|
|
|
p2p::types::Capabilities::FULL_NODE
|
|
|
|
);
|
|
|
|
|
2018-11-13 20:28:36 +03:00
|
|
|
assert!(
|
|
|
|
p2p::types::Capabilities::from_bits_truncate(0b00101111 as u32)
|
|
|
|
.contains(p2p::types::Capabilities::FULL_NODE)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert!(
|
|
|
|
p2p::types::Capabilities::from_bits_truncate(0b00101111 as u32)
|
|
|
|
.contains(p2p::types::Capabilities::TX_KERNEL_HASH)
|
2018-11-07 14:15:37 +03:00
|
|
|
);
|
|
|
|
}
|