-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ser/de for
IpAddr
type; schema for Ipv4Addr
/Ipv6Addr
/`IpA…
…ddr` types (#309) * WIP: add serialization and deserialization for IpAddr type * WIP: add IpAddr to fuzzer * add a test * WIP: add IpAddr to schema * fix: serializer refers to existing ones * fixes * test: roundtrip test for IpAddr * chore: remove assertion * ci: fmt * chore: revert adding implementation for Schema * feat: add derived schema implementation for ipaddr types * ci: remove pkg downgrade section * test: de-macro added rountrip test --------- Co-authored-by: dj8yf0μl <[email protected]>
- Loading branch information
Showing
14 changed files
with
366 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ip_addr__ipaddr_vec_roundtrip.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
source: borsh/tests/roundtrip/test_ip_addr.rs | ||
expression: encoded | ||
--- | ||
[ | ||
3, | ||
0, | ||
0, | ||
0, | ||
0, | ||
192, | ||
168, | ||
0, | ||
1, | ||
1, | ||
32, | ||
1, | ||
13, | ||
184, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
1, | ||
1, | ||
254, | ||
128, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
1, | ||
] |
10 changes: 10 additions & 0 deletions
10
borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ip_addr__ipv4_addr_roundtrip.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
source: borsh/tests/roundtrip/test_ip_addr.rs | ||
expression: encoded | ||
--- | ||
[ | ||
192, | ||
168, | ||
0, | ||
1, | ||
] |
11 changes: 11 additions & 0 deletions
11
...h/tests/roundtrip/snapshots/tests__roundtrip__test_ip_addr__ipv4_addr_roundtrip_enum.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
source: borsh/tests/roundtrip/test_ip_addr.rs | ||
expression: encoded | ||
--- | ||
[ | ||
0, | ||
192, | ||
168, | ||
0, | ||
1, | ||
] |
22 changes: 22 additions & 0 deletions
22
borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ip_addr__ipv6_addr_roundtrip.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
source: borsh/tests/roundtrip/test_ip_addr.rs | ||
expression: encoded | ||
--- | ||
[ | ||
32, | ||
1, | ||
13, | ||
184, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
1, | ||
] |
23 changes: 23 additions & 0 deletions
23
...h/tests/roundtrip/snapshots/tests__roundtrip__test_ip_addr__ipv6_addr_roundtrip_enum.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
source: borsh/tests/roundtrip/test_ip_addr.rs | ||
expression: encoded | ||
--- | ||
[ | ||
1, | ||
32, | ||
1, | ||
13, | ||
184, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
1, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; | ||
|
||
#[test] | ||
fn test_ipv4_addr_roundtrip_enum() { | ||
let original = IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)); | ||
let encoded = borsh::to_vec(&original).expect("Serialization failed"); | ||
#[cfg(feature = "std")] | ||
insta::assert_debug_snapshot!(encoded); | ||
let decoded = borsh::from_slice::<IpAddr>(&encoded).expect("Deserialization failed"); | ||
assert_eq!(original, decoded); | ||
} | ||
|
||
#[test] | ||
fn test_ipv4_addr_roundtrip() { | ||
let original = Ipv4Addr::new(192, 168, 0, 1); | ||
let encoded = borsh::to_vec(&original).expect("Serialization failed"); | ||
#[cfg(feature = "std")] | ||
insta::assert_debug_snapshot!(encoded); | ||
let decoded = borsh::from_slice::<Ipv4Addr>(&encoded).expect("Deserialization failed"); | ||
assert_eq!(original, decoded); | ||
} | ||
|
||
#[test] | ||
fn test_ipv6_addr_roundtrip_enum() { | ||
let original = IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1)); | ||
let encoded = borsh::to_vec(&original).expect("Serialization failed"); | ||
#[cfg(feature = "std")] | ||
insta::assert_debug_snapshot!(encoded); | ||
let decoded = borsh::from_slice::<IpAddr>(&encoded).expect("Deserialization failed"); | ||
assert_eq!(original, decoded); | ||
} | ||
|
||
#[test] | ||
fn test_ipv6_addr_roundtrip() { | ||
let original = Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1); | ||
let encoded = borsh::to_vec(&original).expect("Serialization failed"); | ||
#[cfg(feature = "std")] | ||
insta::assert_debug_snapshot!(encoded); | ||
let decoded = borsh::from_slice::<Ipv6Addr>(&encoded).expect("Deserialization failed"); | ||
assert_eq!(original, decoded); | ||
} | ||
|
||
#[test] | ||
fn test_ipaddr_vec_roundtrip() { | ||
let original = vec![ | ||
IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), | ||
IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1)), | ||
IpAddr::V6(Ipv6Addr::new(0xfe80, 0, 0, 0, 0, 0, 0, 1)), | ||
]; | ||
let encoded = borsh::to_vec(&original).expect("Serialization failed"); | ||
#[cfg(feature = "std")] | ||
insta::assert_debug_snapshot!(encoded); | ||
let decoded = borsh::from_slice::<Vec<IpAddr>>(&encoded).expect("Deserialization failed"); | ||
assert_eq!(original, decoded); | ||
} |
Oops, something went wrong.