Skip to content

Commit

Permalink
Merge pull request #45 from multiformats/dependabot/cargo/rand-0.8.4
Browse files Browse the repository at this point in the history
Update rand requirement from 0.7.2 to 0.8.4
  • Loading branch information
mxinden committed Jun 16, 2021
2 parents 1e263d1 + dc92286 commit 658be9d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

- Update to multihash v0.14.0 (see [PR 44]).

- Update to rand v0.8.4 (see [PR 45]).

[PR 44]: https://github.com/multiformats/rust-multiaddr/pull/44
[PR 45]: https://github.com/multiformats/rust-multiaddr/pull/45

# 0.12.0 [2021-05-26]

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ url = { version = "2.1.0", optional = true, default-features = false }
[dev-dependencies]
bincode = "1"
quickcheck = "0.9.0"
rand = "0.7.2"
rand = "0.8.4"
serde_json = "1.0"
36 changes: 21 additions & 15 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ use data_encoding::HEXUPPER;
use multihash::Multihash;
use multiaddr::*;
use quickcheck::{Arbitrary, Gen, QuickCheck};
use rand::Rng;
use std::{
borrow::Cow,
convert::TryFrom,
iter::FromIterator,
convert::{TryFrom, TryInto},
iter::{FromIterator, self},
net::{Ipv4Addr, Ipv6Addr},
str::FromStr
};
Expand Down Expand Up @@ -87,8 +86,8 @@ struct Proto(Protocol<'static>);
impl Arbitrary for Proto {
fn arbitrary<G: Gen>(g: &mut G) -> Self {
use Protocol::*;
match g.gen_range(0, 25) { // TODO: Add Protocol::Quic
0 => Proto(Dccp(g.gen())),
match u8::arbitrary(g) % 25 { // TODO: Add Protocol::Quic
0 => Proto(Dccp(Arbitrary::arbitrary(g))),
1 => Proto(Dns(Cow::Owned(SubString::arbitrary(g).0))),
2 => Proto(Dns4(Cow::Owned(SubString::arbitrary(g).0))),
3 => Proto(Dns6(Cow::Owned(SubString::arbitrary(g).0))),
Expand All @@ -99,28 +98,35 @@ impl Arbitrary for Proto {
8 => Proto(P2pWebRtcDirect),
9 => Proto(P2pWebRtcStar),
10 => Proto(P2pWebSocketStar),
11 => Proto(Memory(g.gen())),
11 => Proto(Memory(Arbitrary::arbitrary(g))),
// TODO: impl Arbitrary for Multihash:
12 => Proto(P2p(multihash("QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"))),
13 => Proto(P2pCircuit),
14 => Proto(Quic),
15 => Proto(Sctp(g.gen())),
16 => Proto(Tcp(g.gen())),
17 => Proto(Udp(g.gen())),
15 => Proto(Sctp(Arbitrary::arbitrary(g))),
16 => Proto(Tcp(Arbitrary::arbitrary(g))),
17 => Proto(Udp(Arbitrary::arbitrary(g))),
18 => Proto(Udt),
19 => Proto(Unix(Cow::Owned(SubString::arbitrary(g).0))),
20 => Proto(Utp),
21 => Proto(Ws("/".into())),
22 => Proto(Wss("/".into())),
23 => {
let mut a = [0; 10];
g.fill(&mut a);
Proto(Onion(Cow::Owned(a), g.gen_range(1, std::u16::MAX)))

let a = iter::repeat_with(|| u8::arbitrary(g))
.take(10)
.collect::<Vec<_>>()
.try_into()
.unwrap();
Proto(Onion(Cow::Owned(a), std::cmp::max(1, u16::arbitrary(g))))
},
24 => {
let mut a = [0; 35];
g.fill_bytes(&mut a);
Proto(Onion3((a, g.gen_range(1, std::u16::MAX)).into()))
let a: [u8;35] = iter::repeat_with(|| u8::arbitrary(g))
.take(35)
.collect::<Vec<_>>()
.try_into()
.unwrap();
Proto(Onion3((a, std::cmp::max(1, u16::arbitrary(g))).into()))
},
_ => panic!("outside range")
}
Expand Down

0 comments on commit 658be9d

Please sign in to comment.