Skip to content

Commit 206d886

Browse files
committed
Use serde_json instead of serde_json_wasm
1 parent 161628c commit 206d886

File tree

5 files changed

+12
-26
lines changed

5 files changed

+12
-26
lines changed

Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/std/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ hex = "0.4"
6565
schemars = { workspace = true }
6666
sha2 = "0.10.3"
6767
serde = { workspace = true, features = ["std"] }
68-
serde-json-wasm = { version = "1.0.1", default-features = false, features = [
69-
"std",
70-
] }
68+
serde_json = "1.0.81"
7169
static_assertions = "1.1.0"
7270
thiserror = "1.0.26"
7371
rmp-serde = "1.3.0"
@@ -93,4 +91,3 @@ proptest = { version = "1.5.0", default-features = false, features = [
9391
"attr-macro",
9492
"std",
9593
] }
96-
serde_json = "1.0.81"

packages/std/src/ibc.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ impl<T> IbcReceiveResponse<T> {
896896
#[cfg(test)]
897897
mod tests {
898898
use super::*;
899-
use serde_json_wasm::to_string;
899+
use crate::to_json_string;
900900

901901
#[test]
902902
// added this to check json format for go compat, as I was unsure how some messages are snake encoded
@@ -908,7 +908,7 @@ mod tests {
908908
timeout: IbcTimeout::with_timestamp(Timestamp::from_nanos(1234567890)),
909909
memo: None,
910910
};
911-
let encoded = to_string(&msg).unwrap();
911+
let encoded = to_json_string(&msg).unwrap();
912912
let expected = r#"{"transfer":{"channel_id":"channel-123","to_address":"my-special-addr","amount":{"denom":"uatom","amount":"12345678"},"timeout":{"block":null,"timestamp":"1234567890"},"memo":null}}"#;
913913
assert_eq!(encoded.as_str(), expected);
914914
}
@@ -917,14 +917,14 @@ mod tests {
917917
fn ibc_timeout_serialize() {
918918
let timestamp = IbcTimeout::with_timestamp(Timestamp::from_nanos(684816844));
919919
let expected = r#"{"block":null,"timestamp":"684816844"}"#;
920-
assert_eq!(to_string(&timestamp).unwrap(), expected);
920+
assert_eq!(to_json_string(&timestamp).unwrap(), expected);
921921

922922
let block = IbcTimeout::with_block(IbcTimeoutBlock {
923923
revision: 12,
924924
height: 129,
925925
});
926926
let expected = r#"{"block":{"revision":12,"height":129},"timestamp":null}"#;
927-
assert_eq!(to_string(&block).unwrap(), expected);
927+
assert_eq!(to_json_string(&block).unwrap(), expected);
928928

929929
let both = IbcTimeout::with_both(
930930
IbcTimeoutBlock {
@@ -934,7 +934,7 @@ mod tests {
934934
Timestamp::from_nanos(684816844),
935935
);
936936
let expected = r#"{"block":{"revision":12,"height":129},"timestamp":"684816844"}"#;
937-
assert_eq!(to_string(&both).unwrap(), expected);
937+
assert_eq!(to_json_string(&both).unwrap(), expected);
938938
}
939939

940940
#[test]
@@ -998,7 +998,7 @@ mod tests {
998998
),
999999
};
10001000
let expected = r#"{"data":"Zm9v","src":{"port_id":"their-port","channel_id":"channel-1234"},"dest":{"port_id":"our-port","channel_id":"chan33"},"sequence":27,"timeout":{"block":{"revision":1,"height":12345678},"timestamp":"4611686018427387904"}}"#;
1001-
assert_eq!(to_string(&packet).unwrap(), expected);
1001+
assert_eq!(to_json_string(&packet).unwrap(), expected);
10021002

10031003
let no_timestamp = IbcPacket {
10041004
data: b"foo".into(),
@@ -1017,6 +1017,6 @@ mod tests {
10171017
}),
10181018
};
10191019
let expected = r#"{"data":"Zm9v","src":{"port_id":"their-port","channel_id":"channel-1234"},"dest":{"port_id":"our-port","channel_id":"chan33"},"sequence":27,"timeout":{"block":{"revision":1,"height":12345678},"timestamp":null}}"#;
1020-
assert_eq!(to_string(&no_timestamp).unwrap(), expected);
1020+
assert_eq!(to_json_string(&no_timestamp).unwrap(), expected);
10211021
}
10221022
}

packages/std/src/serde.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,23 @@ use crate::{StdError, StdResult};
1313
///
1414
/// Errors if the input is not valid JSON or cannot be deserialized to the given type.
1515
pub fn from_json<T: DeserializeOwned>(value: impl AsRef<[u8]>) -> StdResult<T> {
16-
serde_json_wasm::from_slice(value.as_ref())
17-
.map_err(|e| StdError::parse_err(type_name::<T>(), e))
16+
serde_json::from_slice(value.as_ref()).map_err(|e| StdError::parse_err(type_name::<T>(), e))
1817
}
1918

2019
/// Serializes the given data structure as a JSON byte vector.
2120
pub fn to_json_vec<T>(data: &T) -> StdResult<Vec<u8>>
2221
where
2322
T: Serialize + ?Sized,
2423
{
25-
serde_json_wasm::to_vec(data).map_err(|e| StdError::serialize_err(type_name::<T>(), e))
24+
serde_json::to_vec(data).map_err(|e| StdError::serialize_err(type_name::<T>(), e))
2625
}
2726

2827
/// Serializes the given data structure as a JSON string.
2928
pub fn to_json_string<T>(data: &T) -> StdResult<String>
3029
where
3130
T: Serialize + ?Sized,
3231
{
33-
serde_json_wasm::to_string(data).map_err(|e| StdError::serialize_err(type_name::<T>(), e))
32+
serde_json::to_string(data).map_err(|e| StdError::serialize_err(type_name::<T>(), e))
3433
}
3534

3635
/// Serializes the given data structure as JSON bytes.

packages/std/src/testing/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2637,7 +2637,7 @@ mod tests {
26372637
});
26382638
match result {
26392639
SystemResult::Ok(ContractResult::Err(err)) => {
2640-
assert_eq!(err, "Error parsing into type cosmwasm_std::testing::mock::tests::wasm_querier_works::{{closure}}::MyMsg: Invalid type")
2640+
assert_eq!(err, "Error parsing into type cosmwasm_std::testing::mock::tests::wasm_querier_works::{{closure}}::MyMsg: expected value at line 1 column 1")
26412641
}
26422642
res => panic!("Unexpected result: {res:?}"),
26432643
}

0 commit comments

Comments
 (0)