use cosmwasm_std::{from_binary, to_binary}; use omniflix_std::types::{ cosmos::base::{query::v1beta1::PageResponse, v1beta1::Coin}, omniflix::onft::v1beta1::{ Collection, MsgCreateDenom, QueryCollectionResponse, WeightedAddress, }, }; use omniflix_std_derive::CosmwasmExt; use prost::{bytes::Buf, Message}; use serde::{de::IntoDeserializer, Deserialize, Deserializer}; #[derive( Clone, PartialEq, Eq, ::prost::Message, ::serde::Serialize, ::serde::Deserialize, schemars::JsonSchema, CosmwasmExt, )] #[proto_message(type_url = "/osmosis.lockup.MsgBeginUnlockingResponse")] pub struct MsgBeginUnlockingResponse { #[prost(bool, tag = "1")] pub success: bool, } #[derive( Clone, PartialEq, Eq, ::prost::Message, ::serde::Serialize, ::serde::Deserialize, schemars::JsonSchema, CosmwasmExt, )] #[proto_message(type_url = "/osmosis.lockup.MsgBeginUnlockingResponse")] pub struct NewMsgBeginUnlockingResponse { #[prost(bool, tag = "1")] pub success: bool, #[prost(uint64, tag = "2")] pub unlocking_lock_id: u64, } #[test] fn test_additional_fields_does_not_break_but_cause_lossy_json_deserialization() { let response = NewMsgBeginUnlockingResponse { success: true, unlocking_lock_id: 1, }; // to_binary() and from_binary() is using `serde_json_wasm` under the hood. let serialized = to_binary(&response).unwrap(); let deserialized: MsgBeginUnlockingResponse = from_binary(&serialized).unwrap(); // lossy deserialization assert_eq!(deserialized, MsgBeginUnlockingResponse { success: true }); } #[test] fn test_additional_fields_does_not_break_but_cause_lossy_proto_deserialization() { let response = NewMsgBeginUnlockingResponse { success: true, unlocking_lock_id: 1, }; let serialized = response.encode_to_vec(); let deserialized = MsgBeginUnlockingResponse::decode(&serialized[..]).unwrap(); // lossy deserialization assert_eq!(deserialized, MsgBeginUnlockingResponse { success: true }); } #[test] fn test_ser_deser_onft() { let msg = MsgCreateDenom { id: "id".to_string(), symbol: "symbol".to_string(), name: "name".to_string(), description: "description".to_string(), preview_uri: "preview_uri".to_string(), schema: "schema".to_string(), sender: "sender".to_string(), creation_fee: Some(Coin { denom: "denom".to_string(), amount: "amount".to_string(), }), data: "data".to_string(), uri: "uri".to_string(), uri_hash: "uri_hash".to_string(), royalty_receivers: [WeightedAddress { address: "address".to_string(), weight: "1".to_string(), }] .to_vec(), }; let serialized = to_binary(&msg).unwrap(); let deserialized: MsgCreateDenom = from_binary(&serialized).unwrap(); assert_eq!(deserialized, msg); } mod shim { pub struct Any { pub type_url: String, pub value: Vec, } }