Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump borsh to v1 #1245

Merged
merged 7 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Switch to using borsh::from_slice
  • Loading branch information
seanchen1991 committed May 31, 2024
commit 1b3aed9d8dbbe645e6aa4e49547dc48cf9f2cbb3
4 changes: 1 addition & 3 deletions ibc-apps/ics20-transfer/types/src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
let mut buf = [0; 32];
let bytes_read = reader.read(&mut buf)?;
if bytes_read != 32 {
return Err(borsh::io::Error::new(
borsh::io::ErrorKind::InvalidInput,

Check warning on line 52 in ibc-apps/ics20-transfer/types/src/amount.rs

View check run for this annotation

Codecov / codecov/patch

ibc-apps/ics20-transfer/types/src/amount.rs#L51-L52

Added lines #L51 - L52 were not covered by tests
format!("Expected to read 32 bytes, read {bytes_read}"),
));
}
Expand Down Expand Up @@ -145,15 +145,13 @@
#[cfg(feature = "borsh")]
#[test]
fn borsh_amount() {
use borsh::BorshDeserialize;

let value = Amount::from(42);
let serialized = borsh::to_vec(&value).unwrap();

// Amount is supposed to be a U256 according to the spec, which is 32 bytes
assert_eq!(serialized.len(), 32);

let value_deserialized = Amount::try_from_slice(&serialized).unwrap();
let value_deserialized = borsh::from_slice::<Amount>(&serialized).unwrap();

assert_eq!(value, value_deserialized);
}
Expand Down
4 changes: 1 addition & 3 deletions ibc-apps/ics721-nft-transfer/types/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,8 @@ mod tests {
#[test]
fn test_borsh_roundtrip() {
fn borsh_roundtrip(class_uri: ClassUri) {
use borsh::BorshDeserialize;

let class_uri_bytes = borsh::to_vec(&class_uri).unwrap();
let res = ClassUri::try_from_slice(&class_uri_bytes).unwrap();
let res = borsh::from_slice::<ClassUri>(&class_uri_bytes).unwrap();

assert_eq!(class_uri, res);
}
Expand Down
4 changes: 1 addition & 3 deletions ibc-apps/ics721-nft-transfer/types/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,8 @@ mod tests {
#[test]
fn test_borsh_roundtrip() {
fn borsh_roundtrip(data_value: DataValue) {
use borsh::BorshDeserialize;

let data_value_bytes = borsh::to_vec(&data_value).unwrap();
rnbguy marked this conversation as resolved.
Show resolved Hide resolved
let res = DataValue::try_from_slice(&data_value_bytes).unwrap();
let res = borsh::from_slice::<DataValue>(&data_value_bytes).unwrap();

assert_eq!(data_value, res);
}
Expand Down
4 changes: 1 addition & 3 deletions ibc-apps/ics721-nft-transfer/types/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,8 @@ mod tests {
#[test]
fn test_borsh_roundtrip() {
fn borsh_roundtrip(token_uri: TokenUri) {
use borsh::BorshDeserialize;

let token_uri_bytes = borsh::to_vec(&token_uri).unwrap();
let res = TokenUri::try_from_slice(&token_uri_bytes).unwrap();
let res = borsh::from_slice::<TokenUri>(&token_uri_bytes).unwrap();

assert_eq!(token_uri, res);
}
Expand Down
9 changes: 3 additions & 6 deletions ibc-core/ics24-host/types/src/identifiers/chain_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,17 +440,14 @@ mod tests {
#[rstest]
#[case(b"\x06\0\0\0foo-42\x45\0\0\0\0\0\0\0")]
fn test_invalid_chain_id_borsh_deserialization(#[case] chain_id_bytes: &[u8]) {
use borsh::BorshDeserialize;

assert!(ChainId::try_from_slice(chain_id_bytes).is_err())
assert!(borsh::from_slice::<ChainId>(chain_id_bytes).is_err())
}

#[cfg(feature = "borsh")]
fn borsh_ser_de_roundtrip(chain_id: ChainId) {
use borsh::BorshDeserialize;

let chain_id_bytes = borsh::to_vec(&chain_id).unwrap();
let res = ChainId::try_from_slice(&chain_id_bytes).unwrap();
let res = borsh::from_slice::<ChainId>(&chain_id_bytes).unwrap();

assert_eq!(chain_id, res);
}

Expand Down
4 changes: 1 addition & 3 deletions ibc-primitives/src/types/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,9 @@ mod tests {
#[test]
#[cfg(feature = "borsh")]
fn test_timestamp_borsh_ser_der() {
use borsh::BorshDeserialize;

let timestamp = Timestamp::now();
let encode_timestamp = borsh::to_vec(&timestamp).unwrap();
let _ = Timestamp::try_from_slice(&encode_timestamp).unwrap();
let _ = borsh::from_slice::<Timestamp>(&encode_timestamp).unwrap();
}

#[test]
Expand Down
4 changes: 1 addition & 3 deletions ibc-testkit/src/fixtures/core/connection/conn_open_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ mod tests {

let serialized = borsh::to_vec(&msg).unwrap();

let msg_deserialized =
<MsgConnectionOpenInit as borsh::BorshDeserialize>::try_from_slice(&serialized)
.unwrap();
let msg_deserialized = borsh::from_slice::<MsgConnectionOpenInit>(&serialized).unwrap();

assert_eq!(msg, msg_deserialized);
}
Expand Down
3 changes: 1 addition & 2 deletions ibc-testkit/src/fixtures/core/connection/conn_open_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ mod tests {

let serialized = borsh::to_vec(&msg).unwrap();

let msg_deserialized =
<MsgConnectionOpenTry as borsh::BorshDeserialize>::try_from_slice(&serialized).unwrap();
let msg_deserialized = borsh::from_slice::<MsgConnectionOpenTry>(&serialized).unwrap();

assert_eq!(msg, msg_deserialized);
}
Expand Down
Loading