Skip to content

Commit

Permalink
Revert AcknowledgementStatus tests
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchen1991 committed Sep 6, 2024
1 parent 7ed66da commit 19bd0ce
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 50 deletions.
30 changes: 8 additions & 22 deletions ibc-apps/ics20-transfer/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,8 @@ mod test {
r#"{"result":"AQ=="}"#,
);
ser_json_assert_eq(
AcknowledgementStatus::error(
DecodingError::InvalidJson {
description: "failed to deserialize packet data".to_string(),
}
.into(),
),
r#"{"error":"invalid JSON data: `failed to deserialize packet data`"}"#,
AcknowledgementStatus::error(TokenTransferError::FailedToDeserializePacketData.into()),
r#"{"error":"failed to deserialize packet data"}"#,
);
}

Expand All @@ -353,20 +348,16 @@ mod test {

#[test]
fn test_ack_error_to_vec() {
let ack_error: Vec<u8> = AcknowledgementStatus::error(
DecodingError::InvalidJson {
description: "failed to deserialize packet data".to_string(),
}
.into(),
)
.into();
let ack_error: Vec<u8> =
AcknowledgementStatus::error(TokenTransferError::FailedToDeserializePacketData.into())
.into();

// Check that it's the same output as ibc-go
// Note: this also implicitly checks that the ack bytes are non-empty,
// which would make the conversion to `Acknowledgement` panic
assert_eq!(
ack_error,
br#"{"error":"invalid JSON data: `failed to deserialize packet data`"}"#
br#"{"error":"failed to deserialize packet data"}"#
);
}

Expand All @@ -382,13 +373,8 @@ mod test {
AcknowledgementStatus::success(ack_success_b64()),
);
de_json_assert_eq(
r#"{"error":"invalid JSON data: `failed to deserialize packet data`"}"#,
AcknowledgementStatus::error(
DecodingError::InvalidJson {
description: "failed to deserialize packet data".to_string(),
}
.into(),
),
r#"{"error":"failed to deserialize packet data"}"#,
AcknowledgementStatus::error(TokenTransferError::FailedToDeserializeAck.into()),
);

assert!(serde_json::from_str::<AcknowledgementStatus>(r#"{"success":"AQ=="}"#).is_err());
Expand Down
30 changes: 8 additions & 22 deletions ibc-apps/ics721-nft-transfer/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,8 @@ mod test {
r#"{"result":"AQ=="}"#,
);
ser_json_assert_eq(
AcknowledgementStatus::error(
DecodingError::InvalidJson {
description: "failed to deserialize packet data".to_string(),
}
.into(),
),
r#"{"error":"invalid JSON data: `failed to deserialize packet data`"}"#,
AcknowledgementStatus::error(NftTransferError::FailedToDeserializePacketData.into()),
r#"{"error":"failed to deserialize packet data"}"#,
);
}

Expand All @@ -351,20 +346,16 @@ mod test {

#[test]
fn test_ack_error_to_vec() {
let ack_error: Vec<u8> = AcknowledgementStatus::error(
DecodingError::InvalidJson {
description: "failed to deserialize packet data".to_string(),
}
.into(),
)
.into();
let ack_error: Vec<u8> =
AcknowledgementStatus::error(NftTransferError::FailedToDeserializePacketData.into())
.into();

// Check that it's the same output as ibc-go
// Note: this also implicitly checks that the ack bytes are non-empty,
// which would make the conversion to `Acknowledgement` panic
assert_eq!(
ack_error,
br#"{"error":"invalid JSON data: `failed to deserialize packet data`"}"#
br#"{"error":"failed to deserialize packet data"}"#
);
}

Expand All @@ -380,13 +371,8 @@ mod test {
AcknowledgementStatus::success(ack_success_b64()),
);
de_json_assert_eq(
r#"{"error":"invalid JSON data: `failed to deserialize packet data`"}"#,
AcknowledgementStatus::error(
DecodingError::InvalidJson {
description: "failed to deserialize packet data".to_string(),
}
.into(),
),
r#"{"error":"failed to deserialize packet data"}"#,
AcknowledgementStatus::error(NftTransferError::FailedToDeserializePacketData.into()),
);

assert!(serde_json::from_str::<AcknowledgementStatus>(r#"{"success":"AQ=="}"#).is_err());
Expand Down
6 changes: 0 additions & 6 deletions ibc-core/ics04-channel/types/src/acknowledgement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,3 @@ impl From<AcknowledgementStatus> for Acknowledgement {
.expect("token transfer internal error: ack is never supposed to be empty")
}
}

impl From<DecodingError> for StatusValue {
fn from(e: DecodingError) -> Self {
StatusValue::new(e.to_string()).expect("error message must not be empty")
}
}
6 changes: 6 additions & 0 deletions ibc-core/ics24-host/types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ impl From<ProtoError> for DecodingError {
}
}

impl From<IdentifierError> for DecodingError {
fn from(e: IdentifierError) -> Self {
Self::Identifier(e)
}
}

#[cfg(feature = "std")]
impl std::error::Error for IdentifierError {}

Expand Down

0 comments on commit 19bd0ce

Please sign in to comment.