diff --git a/src/msgs/assert_json.rs b/src/msgs/assert_json.rs index 3a4da20..5604a19 100644 --- a/src/msgs/assert_json.rs +++ b/src/msgs/assert_json.rs @@ -2,8 +2,7 @@ //! if cosmwasm feature is enabled, also assert that we can deserialize the json back to the msg #[track_caller] -#[cfg(not(feature = "cosmwasm"))] -pub fn assert_json_ok(msg: M, expected_json: serde_json::Value) +pub fn assert_json_ser(msg: M, expected_json: serde_json::Value) where M: serde::Serialize + std::fmt::Debug + PartialEq, { @@ -12,8 +11,7 @@ where } #[track_caller] -#[cfg(feature = "cosmwasm")] -pub fn assert_json_ok(msg: M, expected_json: serde_json::Value) +pub fn assert_json_deser(msg: M, expected_json: serde_json::Value) where M: serde::Serialize + std::fmt::Debug + PartialEq + serde::de::DeserializeOwned, { diff --git a/src/msgs/data_requests/execute_tests.rs b/src/msgs/data_requests/execute_tests.rs index c6c88d6..aa6c288 100644 --- a/src/msgs/data_requests/execute_tests.rs +++ b/src/msgs/data_requests/execute_tests.rs @@ -4,7 +4,7 @@ use serde_json::json; #[cfg(feature = "cosmwasm")] use super::Bytes; use super::{execute::*, ExecuteMsg, PostDataRequestArgs, RevealBody}; -use crate::msgs::assert_json_ok; +use crate::msgs::*; #[test] fn json_commit_result() { @@ -23,7 +23,10 @@ fn json_commit_result() { proof: "proof".to_string(), } .into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } #[test] @@ -98,7 +101,10 @@ fn json_post_request() { payback_address, } .into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } #[test] @@ -140,5 +146,8 @@ fn json_reveal_result() { stdout: vec!["some-output".to_string()], } .into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } diff --git a/src/msgs/data_requests/query_tests.rs b/src/msgs/data_requests/query_tests.rs index 08d8d51..82ef6c3 100644 --- a/src/msgs/data_requests/query_tests.rs +++ b/src/msgs/data_requests/query_tests.rs @@ -1,7 +1,7 @@ use serde_json::json; use super::{data_requests::DataRequestStatus, query::QueryMsg as DrQueryMsg, QueryMsg}; -use crate::msgs::assert_json_ok; +use crate::msgs::*; #[test] fn json_get_data_request() { @@ -14,7 +14,10 @@ fn json_get_data_request() { dr_id: "dr_id".to_string(), } .into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } #[test] @@ -30,7 +33,10 @@ fn json_get_data_request_commitment() { public_key: "public_key".to_string(), } .into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } #[test] @@ -44,7 +50,10 @@ fn json_get_data_request_commitments() { dr_id: "dr_id".to_string(), } .into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } #[test] @@ -60,21 +69,27 @@ fn json_get_data_request_reveal() { public_key: "public_key".to_string(), } .into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } #[test] fn json_get_data_request_reveals() { let expected_json = json!({ - "get_data_request_reveals": { - "dr_id": "dr_id", - } + "get_data_request_reveals": { + "dr_id": "dr_id", + } }); let msg: QueryMsg = DrQueryMsg::GetDataRequestReveals { dr_id: "dr_id".to_string(), } .into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } #[test] @@ -88,7 +103,10 @@ fn json_get_data_result() { dr_id: "dr_id".to_string(), } .into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } #[test] @@ -106,5 +124,8 @@ fn json_get_data_requests_by_status() { limit: 10, } .into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } diff --git a/src/msgs/data_requests/sudo_tests.rs b/src/msgs/data_requests/sudo_tests.rs index 9b7b5d0..b6ad463 100644 --- a/src/msgs/data_requests/sudo_tests.rs +++ b/src/msgs/data_requests/sudo_tests.rs @@ -4,7 +4,7 @@ use serde_json::json; #[cfg(feature = "cosmwasm")] use super::Bytes; use super::{sudo::*, DataResult, SudoMsg}; -use crate::msgs::assert_json_ok; +use crate::msgs::*; #[test] fn json_post_result() { @@ -58,5 +58,8 @@ fn json_post_result() { exit_code: 0, } .into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } diff --git a/src/msgs/data_requests/types_tests.rs b/src/msgs/data_requests/types_tests.rs index 7683e02..5069eb6 100644 --- a/src/msgs/data_requests/types_tests.rs +++ b/src/msgs/data_requests/types_tests.rs @@ -5,7 +5,7 @@ use serde_json::json; #[cfg(feature = "cosmwasm")] use super::Bytes; use super::{DataRequest, DataResult, HashSelf, PostDataRequestArgs, RevealBody, U128}; -use crate::msgs::assert_json_ok; +use crate::msgs::*; #[test] fn json_data_request() { @@ -44,7 +44,7 @@ fn json_data_request() { let reveals = HashMap::new(); let height = 1; - let serialized = json!({ + let expected_json = json!({ "id": id, "version": version, "dr_binary_id": dr_binary_id, @@ -63,7 +63,7 @@ fn json_data_request() { "height": height, }); - let data_request = DataRequest { + let msg = DataRequest { id, version: version.parse().unwrap(), dr_binary_id, @@ -82,7 +82,10 @@ fn json_data_request() { height, }; - assert_json_ok(data_request, serialized); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } #[test] @@ -106,7 +109,7 @@ fn json_data_result() { #[cfg(feature = "cosmwasm")] let seda_payload: Bytes = "seda_payload".as_bytes().into(); - let serialized = json!({ + let expected_json = json!({ "version": version, "dr_id": dr_id, "consensus": consensus, @@ -117,7 +120,7 @@ fn json_data_result() { "payback_address": payback_address, "seda_payload": seda_payload, }); - let result = DataResult { + let msg = DataResult { version: version.parse().unwrap(), dr_id, consensus, @@ -129,7 +132,10 @@ fn json_data_result() { seda_payload, }; - assert_json_ok(result, serialized); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } #[test] @@ -142,21 +148,24 @@ fn json_reveal_body() { #[cfg(feature = "cosmwasm")] let reveal: Bytes = "reveal".as_bytes().into(); - let serialized = json!({ + let expected_json = json!({ "salt": salt, "exit_code": exit_code, "gas_used": gas_used, "reveal": reveal, }); - let reveal_body = RevealBody { + let msg = RevealBody { salt, exit_code, gas_used, reveal, }; - assert_json_ok(reveal_body, serialized); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } // pub struct PostDataRequestArgs { @@ -197,7 +206,7 @@ fn json_post_data_request_args() { #[cfg(feature = "cosmwasm")] let memo: Bytes = "memo".as_bytes().into(); - let serialized = json!({ + let expected_json = json!({ "version": version, "dr_binary_id": dr_binary_id, "dr_inputs": dr_inputs, @@ -210,7 +219,7 @@ fn json_post_data_request_args() { "memo": memo, }); - let args = PostDataRequestArgs { + let msg = PostDataRequestArgs { version: version.parse().unwrap(), dr_binary_id, dr_inputs, @@ -223,5 +232,5 @@ fn json_post_data_request_args() { memo, }; - assert_json_ok(args, serialized); + assert_json_ser(msg, expected_json); } diff --git a/src/msgs/mod.rs b/src/msgs/mod.rs index 34f8f66..a9f732d 100644 --- a/src/msgs/mod.rs +++ b/src/msgs/mod.rs @@ -12,7 +12,7 @@ pub mod staking; #[cfg(test)] mod assert_json; #[cfg(test)] -pub use assert_json::assert_json_ok; +pub use assert_json::*; #[cfg_attr(feature = "cosmwasm", cw_serde)] #[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] diff --git a/src/msgs/owner/execute_tests.rs b/src/msgs/owner/execute_tests.rs index f04600a..efb54f1 100644 --- a/src/msgs/owner/execute_tests.rs +++ b/src/msgs/owner/execute_tests.rs @@ -1,7 +1,7 @@ use serde_json::json; use super::{execute::*, ExecuteMsg}; -use crate::msgs::assert_json_ok; +use crate::msgs::*; #[test] fn json_accept_ownership() { @@ -10,7 +10,10 @@ fn json_accept_ownership() { "accept_ownership": {} }); let msg: ExecuteMsg = accept_ownership::Execute {}.into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } #[test] @@ -24,7 +27,10 @@ fn json_add_to_allowlist() { public_key: "public_key".to_string(), } .into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } #[test] @@ -38,7 +44,10 @@ fn json_remove_from_allowlist() { public_key: "public_key".to_string(), } .into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } #[test] @@ -52,5 +61,8 @@ fn json_transfer_ownership() { new_owner: "new_owner".to_string(), } .into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } diff --git a/src/msgs/owner/query_tests.rs b/src/msgs/owner/query_tests.rs index 8e49d57..4cf94ae 100644 --- a/src/msgs/owner/query_tests.rs +++ b/src/msgs/owner/query_tests.rs @@ -1,7 +1,7 @@ use serde_json::json; use super::{query::QueryMsg as OwnerQueryMsg, QueryMsg}; -use crate::msgs::assert_json_ok; +use crate::msgs::*; #[test] fn json_get_owner() { @@ -10,7 +10,10 @@ fn json_get_owner() { "get_owner": {} }); let msg: QueryMsg = OwnerQueryMsg::GetOwner {}.into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } #[test] @@ -20,5 +23,8 @@ fn json_get_pending_owner() { "get_pending_owner": {} }); let msg: QueryMsg = OwnerQueryMsg::GetPendingOwner {}.into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } diff --git a/src/msgs/staking/execute_tests.rs b/src/msgs/staking/execute_tests.rs index 4f58df5..7ab2435 100644 --- a/src/msgs/staking/execute_tests.rs +++ b/src/msgs/staking/execute_tests.rs @@ -1,7 +1,7 @@ use serde_json::json; use super::{execute::*, ExecuteMsg, U128}; -use crate::msgs::assert_json_ok; +use crate::msgs::*; #[test] fn json_stake() { @@ -18,7 +18,10 @@ fn json_stake() { memo: None, } .into(); - assert_json_ok(msg_no_memo, serialized_no_memo); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg_no_memo, serialized_no_memo); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg_no_memo, serialized_no_memo); #[cfg(not(feature = "cosmwasm"))] let memo = "memo".to_string(); @@ -38,7 +41,10 @@ fn json_stake() { memo: Some(memo), } .into(); - assert_json_ok(msg_with_memo, serialized_with_memo); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg_with_memo, serialized_with_memo); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg_with_memo, serialized_with_memo); } #[test] @@ -57,7 +63,10 @@ fn json_unstake() { amount, } .into(); - assert_json_ok(msg, serialized); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, serialized); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, serialized); } #[test] @@ -76,5 +85,8 @@ fn json_withdraw() { amount, } .into(); - assert_json_ok(msg, serialized); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, serialized); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, serialized); } diff --git a/src/msgs/staking/query_tests.rs b/src/msgs/staking/query_tests.rs index b94a1a8..70456e7 100644 --- a/src/msgs/staking/query_tests.rs +++ b/src/msgs/staking/query_tests.rs @@ -1,7 +1,7 @@ use serde_json::json; use super::{query::QueryMsg as StakingQueryMsg, QueryMsg}; -use crate::msgs::assert_json_ok; +use crate::msgs::*; #[test] fn json_get_staker() { @@ -14,7 +14,10 @@ fn json_get_staker() { public_key: "public_key".to_string(), } .into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } #[test] @@ -28,7 +31,10 @@ fn json_get_account_seq() { public_key: "public_key".to_string(), } .into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } #[test] @@ -42,7 +48,10 @@ fn json_get_staker_and_seq() { public_key: "public_key".to_string(), } .into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } #[test] @@ -58,7 +67,10 @@ fn json_is_executor_eligible() { dr_id: "dr_id".to_string(), } .into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } #[test] @@ -67,5 +79,8 @@ fn json_get_staking_config() { "get_staking_config": {} }); let msg: QueryMsg = StakingQueryMsg::GetStakingConfig {}.into(); - assert_json_ok(msg, expected_json); + #[cfg(not(feature = "cosmwasm"))] + assert_json_ser(msg, expected_json); + #[cfg(feature = "cosmwasm")] + assert_json_deser(msg, expected_json); } diff --git a/src/msgs/staking/types_tests.rs b/src/msgs/staking/types_tests.rs index 3c3858d..1855568 100644 --- a/src/msgs/staking/types_tests.rs +++ b/src/msgs/staking/types_tests.rs @@ -1,7 +1,7 @@ use serde_json::json; use super::{Staker, StakingConfig}; -use crate::msgs::assert_json_ok; +use crate::msgs::*; #[test] fn json_staker() { @@ -16,7 +16,7 @@ fn json_staker() { tokens_pending_withdrawal: 0u128.into(), }; - assert_json_ok(staker_with_no_memo, serialized_with_no_memo); + assert_json_deser(staker_with_no_memo, serialized_with_no_memo); #[cfg(not(feature = "cosmwasm"))] let memo = "memo".to_string(); @@ -34,23 +34,23 @@ fn json_staker() { tokens_pending_withdrawal: 0u128.into(), }; - assert_json_ok(staker_with_memo, serialized_with_memo); + assert_json_deser(staker_with_memo, serialized_with_memo); } #[test] fn json_staking_config() { - let serialized = json!({ + let expected_json = json!({ "minimum_stake_to_register": "100", "minimum_stake_for_committee_eligibility": "100", "allowlist_enabled": true, }); - let config = StakingConfig { + let msg = StakingConfig { minimum_stake_to_register: 100u128.into(), minimum_stake_for_committee_eligibility: 100u128.into(), allowlist_enabled: true, }; - assert_json_ok(config, serialized); + assert_json_deser(msg, expected_json); } #[test] @@ -64,7 +64,7 @@ fn json_staker_and_seq() { seq: 100u128.into(), }; - assert_json_ok(staker_and_seq_with_no_staker, serialized_with_no_staker); + assert_json_deser(staker_and_seq_with_no_staker, serialized_with_no_staker); #[cfg(not(feature = "cosmwasm"))] let memo = "memo".to_string(); @@ -88,5 +88,5 @@ fn json_staker_and_seq() { seq: 100u128.into(), }; - assert_json_ok(staker_and_seq_with_staker, serialized_with_staker); + assert_json_deser(staker_and_seq_with_staker, serialized_with_staker); }