From afc2b21ad02fac0a1b17524b7713083c7948686c Mon Sep 17 00:00:00 2001 From: Gancho Manev Date: Wed, 29 Jan 2025 13:11:37 +0200 Subject: [PATCH 1/3] feat: introduce a release query to any contract --- platform/contracts/admin/src/endpoints.rs | 3 ++ platform/contracts/admin/src/msg.rs | 7 ++- platform/contracts/timealarms/src/contract.rs | 3 ++ platform/contracts/timealarms/src/msg.rs | 2 + platform/contracts/treasury/src/contract.rs | 3 ++ platform/contracts/treasury/src/msg.rs | 2 + platform/packages/versioning/src/lib.rs | 4 +- .../packages/versioning/src/release/mod.rs | 4 ++ .../packages/versioning/src/release/query.rs | 52 +++++++++++++++++++ .../contracts/lease/examples/lease_schema.rs | 4 +- protocol/contracts/lease/src/api/query.rs | 12 +++-- .../contracts/lease/src/contract/endpoins.rs | 27 +++++----- protocol/contracts/leaser/src/contract.rs | 1 + protocol/contracts/leaser/src/msg.rs | 2 + protocol/contracts/lpp/src/contract/mod.rs | 1 + protocol/contracts/lpp/src/msg.rs | 2 + protocol/contracts/oracle/src/api/contract.rs | 3 ++ protocol/contracts/oracle/src/contract/mod.rs | 1 + protocol/contracts/profit/src/contract.rs | 1 + protocol/contracts/profit/src/msg.rs | 2 + protocol/contracts/reserve/src/api.rs | 2 + protocol/contracts/reserve/src/contract.rs | 10 ++-- tests/src/common/lease.rs | 4 +- 23 files changed, 126 insertions(+), 26 deletions(-) create mode 100644 platform/packages/versioning/src/release/query.rs diff --git a/platform/contracts/admin/src/endpoints.rs b/platform/contracts/admin/src/endpoints.rs index b8bbae827..66f7015b6 100644 --- a/platform/contracts/admin/src/endpoints.rs +++ b/platform/contracts/admin/src/endpoints.rs @@ -224,6 +224,9 @@ pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> ContractResult .and_then(|ref protocol| { cosmwasm_std::to_json_binary::(protocol).map_err(Into::into) }), + QueryMsg::PlatformPackageRelease {} => { + cosmwasm_std::to_json_binary(&CURRENT_RELEASE).map_err(Into::into) + } } } diff --git a/platform/contracts/admin/src/msg.rs b/platform/contracts/admin/src/msg.rs index df08acb92..9e2369f47 100644 --- a/platform/contracts/admin/src/msg.rs +++ b/platform/contracts/admin/src/msg.rs @@ -93,10 +93,15 @@ where Uint64: Into, CodeId: Into, { - InstantiateAddress { code_id: Uint64, protocol: String }, + InstantiateAddress { + code_id: Uint64, + protocol: String, + }, Protocols {}, Platform {}, Protocol(String), + /// Implementation of [versioning::query::PlatformPackage::Release] + PlatformPackageRelease {}, } pub type ProtocolsQueryResponse = Vec; diff --git a/platform/contracts/timealarms/src/contract.rs b/platform/contracts/timealarms/src/contract.rs index 831fb3cc0..f8fde9e4c 100644 --- a/platform/contracts/timealarms/src/contract.rs +++ b/platform/contracts/timealarms/src/contract.rs @@ -83,6 +83,9 @@ pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> ContractResult QueryMsg::AlarmsStatus {} => Ok(to_json_binary( &TimeAlarms::new(deps.storage).try_any_alarm(env.block.time)?, )?), + QueryMsg::PlatformPackageRelease {} => { + cosmwasm_std::to_json_binary(&CURRENT_RELEASE).map_err(Into::into) + } } .inspect_err(platform_error::log(deps.api)) } diff --git a/platform/contracts/timealarms/src/msg.rs b/platform/contracts/timealarms/src/msg.rs index fd22962e2..d732f04c5 100644 --- a/platform/contracts/timealarms/src/msg.rs +++ b/platform/contracts/timealarms/src/msg.rs @@ -42,6 +42,8 @@ pub enum SudoMsg {} pub enum QueryMsg { ContractVersion {}, AlarmsStatus {}, + /// Implementation of [versioning::query::PlatformPackage::Release] + PlatformPackageRelease {}, } #[derive(Serialize, Deserialize, Clone, Copy, Eq, PartialEq, JsonSchema)] diff --git a/platform/contracts/treasury/src/contract.rs b/platform/contracts/treasury/src/contract.rs index aed512f61..0cc8b72d6 100644 --- a/platform/contracts/treasury/src/contract.rs +++ b/platform/contracts/treasury/src/contract.rs @@ -107,6 +107,9 @@ pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> ContractResult } QueryMsg::CalculateRewards {} => query_reward_apr(deps.storage, deps.querier, &env) .and_then(|ref apr| to_json_binary(apr).map_err(ContractError::Serialize)), + QueryMsg::PlatformPackageRelease {} => { + cosmwasm_std::to_json_binary(&CURRENT_RELEASE).map_err(Into::into) + } } .inspect_err(platform_error::log(deps.api)) } diff --git a/platform/contracts/treasury/src/msg.rs b/platform/contracts/treasury/src/msg.rs index f1c6d0709..f78a1cc07 100644 --- a/platform/contracts/treasury/src/msg.rs +++ b/platform/contracts/treasury/src/msg.rs @@ -41,6 +41,8 @@ pub enum SudoMsg { pub enum QueryMsg { Config {}, CalculateRewards {}, + /// Implementation of [versioning::query::PlatformPackage::Release] + PlatformPackageRelease {}, } // We define a custom struct for each query response diff --git a/platform/packages/versioning/src/lib.rs b/platform/packages/versioning/src/lib.rs index ae29e649a..4e745038b 100644 --- a/platform/packages/versioning/src/lib.rs +++ b/platform/packages/versioning/src/lib.rs @@ -6,8 +6,8 @@ pub use crate::{ error::Error, protocol::Release as ProtocolRelease, release::{ - Id as ReleaseId, PlatformPackageRelease, ProtocolPackageRelease, ProtocolPackageReleaseId, - UpdatablePackage, + query, Id as ReleaseId, PlatformPackageRelease, ProtocolPackageRelease, + ProtocolPackageReleaseId, UpdatablePackage, }, software::{PackageRelease as SoftwarePackageRelease, VersionSegment}, }; diff --git a/platform/packages/versioning/src/release/mod.rs b/platform/packages/versioning/src/release/mod.rs index cf6d7e2e4..1366ee9f3 100644 --- a/platform/packages/versioning/src/release/mod.rs +++ b/platform/packages/versioning/src/release/mod.rs @@ -9,6 +9,7 @@ pub use self::id::Id; #[cfg(feature = "protocol_contract")] mod current; mod id; +pub mod query; pub trait UpdatablePackage where @@ -26,12 +27,15 @@ where } pub type PlatformPackageRelease = SoftwarePackageRelease; +#[derive(Serialize, Deserialize)] +#[serde(deny_unknown_fields, rename_all = "snake_case")] pub struct ProtocolPackageRelease { software: SoftwarePackageRelease, protocol: ProtocolRelease, } #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] +#[serde(deny_unknown_fields, rename_all = "snake_case")] pub struct ProtocolPackageReleaseId { software: Id, protocol: Id, diff --git a/platform/packages/versioning/src/release/query.rs b/platform/packages/versioning/src/release/query.rs new file mode 100644 index 000000000..ebe93d57b --- /dev/null +++ b/platform/packages/versioning/src/release/query.rs @@ -0,0 +1,52 @@ +use serde::Serialize; +use thiserror::Error; + +use sdk::cosmwasm_std::{Addr, QuerierWrapper, StdError}; + +use super::{PlatformPackageRelease, ProtocolPackageRelease}; + +/// A common versioning API of each platform package +#[derive(Serialize)] +#[serde(deny_unknown_fields, rename_all = "snake_case")] +pub enum PlatformPackage { + /// Query the platform package for its release. + /// + /// The result is [versioning::PlatformPackageRelease] + #[serde(rename = "platform_package_release")] + Release {}, +} + +/// A common versioning API of each protocol package +#[derive(Serialize)] +#[serde(deny_unknown_fields, rename_all = "snake_case")] +pub enum ProtocolPackage { + /// Query the protocol package for its release. + /// + /// The result is [versioning::ProtocolPackageRelease] + #[serde(rename = "protocol_package_release")] + Release {}, +} + +#[derive(Error, Debug, PartialEq)] +pub enum Error { + #[error("[Versioning][Query] {0}")] + Transmission(StdError), +} + +pub fn platform_release( + contract: Addr, + querier: QuerierWrapper<'_>, +) -> Result { + querier + .query_wasm_smart(contract, &PlatformPackage::Release {}) + .map_err(Error::Transmission) +} + +pub fn protocol_release( + contract: Addr, + querier: QuerierWrapper<'_>, +) -> Result { + querier + .query_wasm_smart(contract, &ProtocolPackage::Release {}) + .map_err(Error::Transmission) +} diff --git a/protocol/contracts/lease/examples/lease_schema.rs b/protocol/contracts/lease/examples/lease_schema.rs index 9f4d26dc0..c64e77570 100644 --- a/protocol/contracts/lease/examples/lease_schema.rs +++ b/protocol/contracts/lease/examples/lease_schema.rs @@ -1,9 +1,9 @@ -use lease::api::{open::NewLeaseForm, query::StateQuery, ExecuteMsg}; +use lease::api::{open::NewLeaseForm, query::QueryMsg, ExecuteMsg}; use sdk::cosmwasm_schema::{export_schema, schema_for}; fn main() { let out_dir = schema::prep_out_dir().expect("The output directory should be valid"); export_schema(&schema_for!(NewLeaseForm), &out_dir); export_schema(&schema_for!(ExecuteMsg), &out_dir); - export_schema(&schema_for!(StateQuery), &out_dir); + export_schema(&schema_for!(QueryMsg), &out_dir); } diff --git a/protocol/contracts/lease/src/api/query.rs b/protocol/contracts/lease/src/api/query.rs index 1974d2890..9da1c4913 100644 --- a/protocol/contracts/lease/src/api/query.rs +++ b/protocol/contracts/lease/src/api/query.rs @@ -19,12 +19,18 @@ pub use opened::ClosePolicy; #[derive(Deserialize, JsonSchema)] #[cfg_attr(any(test, feature = "testing"), derive(Clone, Debug, Serialize))] #[serde(deny_unknown_fields, rename_all = "snake_case")] -pub struct StateQuery { +pub enum QueryMsg { /// Ask for estimation of the due and overdue amounts and periods in that point of time /// + /// Return a [StateResponse] + /// /// The value is meaningfull only if the lease is in Opened state. - #[serde(default, rename = "due_projection_secs")] - pub due_projection: Seconds, + State { + #[serde(default, rename = "due_projection_secs")] + due_projection: Seconds, + }, + /// Implementation of [versioning::query::ProtocolPackage::Release] + ProtocolPackageRelease {}, } #[derive(Serialize)] diff --git a/protocol/contracts/lease/src/contract/endpoins.rs b/protocol/contracts/lease/src/contract/endpoins.rs index f1a650583..2e7b89680 100644 --- a/protocol/contracts/lease/src/contract/endpoins.rs +++ b/protocol/contracts/lease/src/contract/endpoins.rs @@ -13,7 +13,7 @@ use versioning::{ }; use crate::{ - api::{open::NewLeaseContract, query::StateQuery, ExecuteMsg, MigrateMsg}, + api::{open::NewLeaseContract, query::QueryMsg, ExecuteMsg, MigrateMsg}, contract::api::Contract, error::{ContractError, ContractResult}, }; @@ -93,17 +93,20 @@ pub fn sudo(deps: DepsMut<'_>, env: Env, msg: SudoMsg) -> ContractResult, env: Env, msg: StateQuery) -> ContractResult { - state::load(deps.storage) - .and_then(|state| { - state.state( - env.block.time, - Duration::from_secs(msg.due_projection), - deps.querier, - ) - }) - .and_then(|resp| to_json_binary(&resp).map_err(Into::into)) - .inspect_err(platform_error::log(deps.api)) +pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> ContractResult { + match msg { + QueryMsg::State { due_projection } => state::load(deps.storage) + .and_then(|state| { + state.state( + env.block.time, + Duration::from_secs(due_projection), + deps.querier, + ) + }) + .and_then(|resp| to_json_binary(&resp).map_err(Into::into)), + QueryMsg::ProtocolPackageRelease {} => to_json_binary(&CURRENT_RELEASE).map_err(Into::into), + } + .inspect_err(platform_error::log(deps.api)) } fn process_lease( diff --git a/protocol/contracts/leaser/src/contract.rs b/protocol/contracts/leaser/src/contract.rs index 82299de5b..bf56e00a5 100644 --- a/protocol/contracts/leaser/src/contract.rs +++ b/protocol/contracts/leaser/src/contract.rs @@ -179,6 +179,7 @@ pub fn sudo(deps: DepsMut<'_>, _env: Env, msg: SudoMsg) -> ContractResult, _env: Env, msg: QueryMsg) -> ContractResult { match msg { QueryMsg::Config {} => to_json_binary(&Leaser::new(deps).config()?), + QueryMsg::ProtocolPackageRelease {} => to_json_binary(&CURRENT_RELEASE), QueryMsg::Quote { downpayment, lease_asset, diff --git a/protocol/contracts/leaser/src/msg.rs b/protocol/contracts/leaser/src/msg.rs index d833283f1..21a8c1af8 100644 --- a/protocol/contracts/leaser/src/msg.rs +++ b/protocol/contracts/leaser/src/msg.rs @@ -126,6 +126,8 @@ pub enum ForceClose { #[serde(deny_unknown_fields, rename_all = "snake_case")] pub enum QueryMsg { Config {}, + /// Implementation of [versioning::query::ProtocolPackage::Release] + ProtocolPackageRelease {}, Quote { downpayment: DownpaymentCoin, lease_asset: CurrencyDTO, diff --git a/protocol/contracts/lpp/src/contract/mod.rs b/protocol/contracts/lpp/src/contract/mod.rs index daa706b3d..3105488cd 100644 --- a/protocol/contracts/lpp/src/contract/mod.rs +++ b/protocol/contracts/lpp/src/contract/mod.rs @@ -156,6 +156,7 @@ pub fn sudo(deps: DepsMut<'_>, _env: Env, msg: SudoMsg) -> Result { pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> Result { match msg { QueryMsg::Config() => Config::load(deps.storage).and_then(|ref resp| to_json_binary(resp)), + QueryMsg::ProtocolPackageRelease {} => to_json_binary(&CURRENT_RELEASE), QueryMsg::Lpn() => to_json_binary(LpnCurrency::definition().dto()), QueryMsg::Balance { address } => { lender::query_balance(deps.storage, address).and_then(|ref resp| to_json_binary(resp)) diff --git a/protocol/contracts/lpp/src/msg.rs b/protocol/contracts/lpp/src/msg.rs index d1f18e900..7662107ed 100644 --- a/protocol/contracts/lpp/src/msg.rs +++ b/protocol/contracts/lpp/src/msg.rs @@ -94,6 +94,8 @@ where Lpns: Group, { Config(), + /// Implementation of [versioning::query::ProtocolPackage::Release] + ProtocolPackageRelease {}, /// Report the Lpn currency as [CurrencyDTO] Lpn(), Quote { diff --git a/protocol/contracts/oracle/src/api/contract.rs b/protocol/contracts/oracle/src/api/contract.rs index 365d8b025..100b1c29b 100644 --- a/protocol/contracts/oracle/src/api/contract.rs +++ b/protocol/contracts/oracle/src/api/contract.rs @@ -87,6 +87,9 @@ where // Returns contract's semantic version as a package, which is set in `Cargo.toml`. ContractVersion {}, + /// Implementation of [versioning::query::ProtocolPackage::Release] + ProtocolPackageRelease {}, + // returns the contract configuration Config {}, diff --git a/protocol/contracts/oracle/src/contract/mod.rs b/protocol/contracts/oracle/src/contract/mod.rs index f89236953..f349807ed 100644 --- a/protocol/contracts/oracle/src/contract/mod.rs +++ b/protocol/contracts/oracle/src/contract/mod.rs @@ -81,6 +81,7 @@ pub fn migrate( pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> ContractResult { match msg { QueryMsg::ContractVersion {} => to_json_binary(CURRENT_VERSION), + QueryMsg::ProtocolPackageRelease {} => to_json_binary(&CURRENT_RELEASE), QueryMsg::Config {} => to_json_binary(&query_config(deps.storage)?), QueryMsg::Feeders {} => Feeders::get(deps.storage) .map_err(ContractError::LoadFeeders) diff --git a/protocol/contracts/profit/src/contract.rs b/protocol/contracts/profit/src/contract.rs index 05d138d4b..be96368e3 100644 --- a/protocol/contracts/profit/src/contract.rs +++ b/protocol/contracts/profit/src/contract.rs @@ -222,6 +222,7 @@ pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> ContractResult env.block.time, deps.querier, )?), + QueryMsg::ProtocolPackageRelease {} => to_json_binary(&CURRENT_RELEASE), } .map_err(Into::into) } diff --git a/protocol/contracts/profit/src/msg.rs b/protocol/contracts/profit/src/msg.rs index f11e1fb08..8534b4d64 100644 --- a/protocol/contracts/profit/src/msg.rs +++ b/protocol/contracts/profit/src/msg.rs @@ -51,6 +51,8 @@ pub enum ExecuteMsg { #[serde(deny_unknown_fields, rename_all = "snake_case")] pub enum QueryMsg { Config {}, + /// Implementation of [versioning::query::ProtocolPackage::Release] + ProtocolPackageRelease {}, } // We define a custom struct for each query response diff --git a/protocol/contracts/reserve/src/api.rs b/protocol/contracts/reserve/src/api.rs index a082ad090..94cd70c12 100644 --- a/protocol/contracts/reserve/src/api.rs +++ b/protocol/contracts/reserve/src/api.rs @@ -49,6 +49,8 @@ pub enum QueryMsg { ReserveLpn(), // the name contains the contract name to help distinguish from simmilar queries to other contracts /// Return a [ConfigResponse] Config(), + /// Implementation of [versioning::query::ProtocolPackage::Release] + ProtocolPackageRelease {}, } #[derive(Serialize, Deserialize, Clone, Eq, PartialEq, JsonSchema)] diff --git a/protocol/contracts/reserve/src/contract.rs b/protocol/contracts/reserve/src/contract.rs index 906a99027..25f9bde96 100644 --- a/protocol/contracts/reserve/src/contract.rs +++ b/protocol/contracts/reserve/src/contract.rs @@ -110,15 +110,17 @@ pub fn execute( #[entry_point] pub fn query(deps: Deps<'_>, _env: Env, msg: QueryMsg) -> Result { match msg { - QueryMsg::Config() => Config::load(deps.storage) - .map(ConfigResponse::from) - .and_then(|config| cosmwasm_std::to_json_binary(&config).map_err(Into::into)), QueryMsg::ReserveLpn() => cosmwasm_std::to_json_binary( ¤cy::to_string::(LpnCurrency::definition()), ) .map_err(Into::into), + QueryMsg::Config() => Config::load(deps.storage) + .map(ConfigResponse::from) + .and_then(|config| cosmwasm_std::to_json_binary(&config).map_err(Into::into)), + QueryMsg::ProtocolPackageRelease {} => { + cosmwasm_std::to_json_binary(&CURRENT_RELEASE).map_err(Into::into) + } } - .map_err(Into::into) .inspect_err(platform_error::log(deps.api)) } diff --git a/tests/src/common/lease.rs b/tests/src/common/lease.rs index b17954869..f2eea6178 100644 --- a/tests/src/common/lease.rs +++ b/tests/src/common/lease.rs @@ -12,7 +12,7 @@ use lease::{ ConnectionParams, Ics20Channel, LoanForm, NewLeaseContract, NewLeaseForm, PositionSpecDTO, }, - query::{StateQuery, StateResponse}, + query::{QueryMsg, StateResponse}, }, contract::{execute, instantiate, query, reply, sudo}, }; @@ -351,7 +351,7 @@ pub(crate) fn fetch_state(app: &App, lease: Addr) -> StateResponse { app.query() .query_wasm_smart( lease, - &StateQuery { + &QueryMsg::State { due_projection: Seconds::default(), }, ) From d059e3ddaefbe90a56b7214abdbf45edb029780e Mon Sep 17 00:00:00 2001 From: Gancho Manev Date: Wed, 29 Jan 2025 13:22:40 +0200 Subject: [PATCH 2/3] chore: [lint] forbid unfulfilled lint expectations --- scripts/check/lint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/check/lint.sh b/scripts/check/lint.sh index 2085d1475..7fc512108 100644 --- a/scripts/check/lint.sh +++ b/scripts/check/lint.sh @@ -34,6 +34,7 @@ append_lint_flags() { --deny "rust-2021-compatibility" \ --deny "rust-2024-compatibility" \ --allow "impl-trait-overcaptures" \ + --forbid "unfulfilled_lint_expectations" \ --deny "unused" \ --deny "warnings" } From bc6766095aa6544e8fb70af3e4008d843dd2221a Mon Sep 17 00:00:00 2001 From: Gancho Manev Date: Thu, 30 Jan 2025 09:25:11 +0200 Subject: [PATCH 3/3] test: all contracts comply to the release query --- platform/contracts/admin/Cargo.toml | 2 ++ platform/contracts/admin/src/endpoints.rs | 16 ++++++++++ platform/contracts/timealarms/src/msg.rs | 17 ++++++++++ platform/contracts/treasury/Cargo.toml | 1 + platform/contracts/treasury/src/msg.rs | 16 ++++++++++ platform/packages/platform/src/tests.rs | 14 ++++++-- protocol/contracts/lease/src/api/query.rs | 22 ++++++++++++- protocol/contracts/leaser/src/msg.rs | 32 +++++++++++++------ protocol/contracts/lpp/src/msg.rs | 22 ++++++++++++- protocol/contracts/oracle/src/api/contract.rs | 20 ++++++++++++ protocol/contracts/oracle/src/contract/mod.rs | 11 ++++++- protocol/contracts/profit/Cargo.toml | 1 + protocol/contracts/profit/src/msg.rs | 16 ++++++++++ protocol/contracts/reserve/src/api.rs | 18 ++++++++++- 14 files changed, 193 insertions(+), 15 deletions(-) diff --git a/platform/contracts/admin/Cargo.toml b/platform/contracts/admin/Cargo.toml index 195ee61cc..7beec0d9e 100644 --- a/platform/contracts/admin/Cargo.toml +++ b/platform/contracts/admin/Cargo.toml @@ -34,5 +34,7 @@ serde = { workspace = true, features = ["derive"] } thiserror = { workspace = true } [dev-dependencies] +platform = { workspace = true, features = ["testing"] } + schema = { workspace = true } serde_test = { workspace = true } diff --git a/platform/contracts/admin/src/endpoints.rs b/platform/contracts/admin/src/endpoints.rs index 66f7015b6..1dfc8b90f 100644 --- a/platform/contracts/admin/src/endpoints.rs +++ b/platform/contracts/admin/src/endpoints.rs @@ -324,3 +324,19 @@ fn check_release_label( Ok(()) } + +#[cfg(test)] +mod test { + + use platform::tests as platform_tests; + + use super::QueryMsg; + + #[test] + fn release() { + assert_eq!( + Ok(QueryMsg::PlatformPackageRelease {}), + platform_tests::ser_de(&versioning::query::PlatformPackage::Release {}), + ); + } +} diff --git a/platform/contracts/timealarms/src/msg.rs b/platform/contracts/timealarms/src/msg.rs index d732f04c5..d21f5da26 100644 --- a/platform/contracts/timealarms/src/msg.rs +++ b/platform/contracts/timealarms/src/msg.rs @@ -38,6 +38,7 @@ pub enum ExecuteMsg { pub enum SudoMsg {} #[derive(Serialize, Deserialize)] +#[cfg_attr(any(test, feature = "testing"), derive(Debug, PartialEq, Eq))] #[serde(deny_unknown_fields, rename_all = "snake_case")] pub enum QueryMsg { ContractVersion {}, @@ -65,3 +66,19 @@ pub struct DispatchAlarmsResponse(pub AlarmsCount); pub struct AlarmsStatusResponse { pub remaining_alarms: bool, } + +#[cfg(test)] +mod test { + + use platform::tests as platform_tests; + + use super::QueryMsg; + + #[test] + fn release() { + assert_eq!( + Ok(QueryMsg::PlatformPackageRelease {}), + platform_tests::ser_de(&versioning::query::PlatformPackage::Release {}), + ); + } +} diff --git a/platform/contracts/treasury/Cargo.toml b/platform/contracts/treasury/Cargo.toml index 7351b11be..d0bcd9010 100644 --- a/platform/contracts/treasury/Cargo.toml +++ b/platform/contracts/treasury/Cargo.toml @@ -39,6 +39,7 @@ serde = { workspace = true, features = ["derive"] } currency = { workspace = true, features = ["testing"] } lpp-platform = { workspace = true, features = ["testing"] } oracle-platform = { workspace = true, features = ["testing"] } +platform = { workspace = true, features = ["testing"] } schema = { workspace = true } sdk = { workspace = true, default-features = false, features = ["testing"] } diff --git a/platform/contracts/treasury/src/msg.rs b/platform/contracts/treasury/src/msg.rs index f78a1cc07..27fbc32c1 100644 --- a/platform/contracts/treasury/src/msg.rs +++ b/platform/contracts/treasury/src/msg.rs @@ -53,3 +53,19 @@ pub struct ConfigResponse { } pub type RewardScaleResponse = RewardScale; + +#[cfg(test)] +mod test { + + use platform::tests as platform_tests; + + use super::QueryMsg; + + #[test] + fn release() { + assert_eq!( + Ok(QueryMsg::PlatformPackageRelease {}), + platform_tests::ser_de(&versioning::query::PlatformPackage::Release {}), + ); + } +} diff --git a/platform/packages/platform/src/tests.rs b/platform/packages/platform/src/tests.rs index f428467ed..30d76141a 100644 --- a/platform/packages/platform/src/tests.rs +++ b/platform/packages/platform/src/tests.rs @@ -1,5 +1,7 @@ -use sdk::cosmwasm_std::{from_json, Binary, Event}; -use serde::de::DeserializeOwned; +use std::fmt::Debug; + +use sdk::cosmwasm_std::{self, from_json, Binary, Event, StdError}; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; pub trait EventSource<'a> { type EventIter: Iterator; @@ -34,3 +36,11 @@ where resp.as_ref() .map(|data| from_json(data).expect("deserialization succeed")) } + +pub fn ser_de(obj: &T) -> Result +where + T: Serialize, + R: Debug + for<'a> Deserialize<'a> + PartialEq, +{ + cosmwasm_std::from_json(cosmwasm_std::to_json_vec(obj).expect("serialization succeed")) +} diff --git a/protocol/contracts/lease/src/api/query.rs b/protocol/contracts/lease/src/api/query.rs index 9da1c4913..365e8adb9 100644 --- a/protocol/contracts/lease/src/api/query.rs +++ b/protocol/contracts/lease/src/api/query.rs @@ -17,7 +17,10 @@ use super::{DownpaymentCoin, LeaseAssetCurrencies, LeaseCoin}; pub use opened::ClosePolicy; #[derive(Deserialize, JsonSchema)] -#[cfg_attr(any(test, feature = "testing"), derive(Clone, Debug, Serialize))] +#[cfg_attr( + any(test, feature = "testing"), + derive(Clone, Debug, PartialEq, Serialize) +)] #[serde(deny_unknown_fields, rename_all = "snake_case")] pub enum QueryMsg { /// Ask for estimation of the due and overdue amounts and periods in that point of time @@ -187,3 +190,20 @@ pub(crate) mod paid { TransferInFinish, } } + +#[cfg(test)] +mod test { + use platform::tests as platform_tests; + + use super::QueryMsg; + #[test] + fn release() { + assert_eq!( + Ok(QueryMsg::ProtocolPackageRelease {}), + platform_tests::ser_de(&versioning::query::ProtocolPackage::Release {}), + ); + + platform_tests::ser_de::<_, QueryMsg>(&versioning::query::PlatformPackage::Release {}) + .unwrap_err(); + } +} diff --git a/protocol/contracts/leaser/src/msg.rs b/protocol/contracts/leaser/src/msg.rs index 21a8c1af8..d7ef70db3 100644 --- a/protocol/contracts/leaser/src/msg.rs +++ b/protocol/contracts/leaser/src/msg.rs @@ -159,20 +159,34 @@ pub struct QuoteResponse { #[cfg(test)] mod test { - use crate::msg::ExecuteMsg; use lease::api::FinalizerExecuteMsg; + use platform::tests as platform_tests; use sdk::cosmwasm_std::Addr; + use crate::msg::ExecuteMsg; + + use super::QueryMsg; + #[test] fn finalize_api_match() { - use sdk::cosmwasm_std::{from_json, to_json_vec}; - let customer = Addr::unchecked("c"); - let finalize_bin = to_json_vec(&ExecuteMsg::FinalizeLease { - customer: customer.clone(), - }) - .expect("serialization passed"); - let msg_out: FinalizerExecuteMsg = from_json(finalize_bin).expect("deserialization passed"); - assert_eq!(FinalizerExecuteMsg::FinalizeLease { customer }, msg_out); + + assert_eq!( + Ok(FinalizerExecuteMsg::FinalizeLease { + customer: customer.clone() + }), + platform_tests::ser_de(&ExecuteMsg::FinalizeLease { customer }), + ); + } + + #[test] + fn release() { + assert_eq!( + Ok(QueryMsg::ProtocolPackageRelease {}), + platform_tests::ser_de(&versioning::query::ProtocolPackage::Release {}), + ); + + platform_tests::ser_de::<_, QueryMsg>(&versioning::query::PlatformPackage::Release {}) + .unwrap_err(); } } diff --git a/protocol/contracts/lpp/src/msg.rs b/protocol/contracts/lpp/src/msg.rs index 7662107ed..579e18070 100644 --- a/protocol/contracts/lpp/src/msg.rs +++ b/protocol/contracts/lpp/src/msg.rs @@ -83,7 +83,7 @@ pub enum SudoMsg { } #[derive(Serialize, Deserialize, Clone, Eq, PartialEq, JsonSchema)] -#[cfg_attr(feature = "testing", derive(Debug))] +#[cfg_attr(any(test, feature = "testing"), derive(Debug))] #[serde( deny_unknown_fields, rename_all = "snake_case", @@ -178,3 +178,23 @@ where pub struct RewardsResponse { pub rewards: Coin, } + +#[cfg(test)] +mod test { + use super::QueryMsg; + use currencies::Lpns; + use platform::tests as platform_tests; + + #[test] + fn release() { + assert_eq!( + Ok(QueryMsg::::ProtocolPackageRelease {}), + platform_tests::ser_de(&versioning::query::ProtocolPackage::Release {}), + ); + + platform_tests::ser_de::<_, QueryMsg>( + &versioning::query::PlatformPackage::Release {}, + ) + .unwrap_err(); + } +} diff --git a/protocol/contracts/oracle/src/api/contract.rs b/protocol/contracts/oracle/src/api/contract.rs index 100b1c29b..45d6d6687 100644 --- a/protocol/contracts/oracle/src/api/contract.rs +++ b/protocol/contracts/oracle/src/api/contract.rs @@ -274,3 +274,23 @@ where Deserialize::deserialize(deserializer).map(|(from, to)| Self { from, to }) } } + +#[cfg(test)] +mod test { + use super::QueryMsg; + use currencies::Lpns; + use platform::tests as platform_tests; + + #[test] + fn release() { + assert_eq!( + Ok(QueryMsg::::ProtocolPackageRelease {}), + platform_tests::ser_de(&versioning::query::ProtocolPackage::Release {}), + ); + + platform_tests::ser_de::<_, QueryMsg>( + &versioning::query::PlatformPackage::Release {}, + ) + .unwrap_err(); + } +} diff --git a/protocol/contracts/oracle/src/contract/mod.rs b/protocol/contracts/oracle/src/contract/mod.rs index f349807ed..e0e0508e3 100644 --- a/protocol/contracts/oracle/src/contract/mod.rs +++ b/protocol/contracts/oracle/src/contract/mod.rs @@ -210,9 +210,10 @@ where mod tests { use currencies::{ testing::{LeaseC1, PaymentC1, PaymentC9}, - LeaseGroup, Lpn, Lpns, + LeaseGroup, Lpn, Lpns, PaymentGroup, }; use finance::{duration::Duration, percent::Percent, price}; + use platform::tests as platform_tests; use sdk::cosmwasm_std::{self, testing::mock_env}; use crate::{ @@ -306,4 +307,12 @@ mod tests { query_api ); } + + #[test] + fn release() { + assert_eq!( + Ok(QueryMsg::::ProtocolPackageRelease {}), + platform_tests::ser_de(&versioning::query::ProtocolPackage::Release {}), + ); + } } diff --git a/protocol/contracts/profit/Cargo.toml b/protocol/contracts/profit/Cargo.toml index c5ab6a320..69470b11f 100644 --- a/protocol/contracts/profit/Cargo.toml +++ b/protocol/contracts/profit/Cargo.toml @@ -87,5 +87,6 @@ dex = { workspace = true, features = ["testing"] } finance = { workspace = true } oracle = { workspace = true, features = ["testing"] } oracle-platform = { workspace = true, features = ["testing"] } +platform = { workspace = true, features = ["testing"] } schema = { workspace = true } timealarms = { workspace = true, features = ["testing"] } diff --git a/protocol/contracts/profit/src/msg.rs b/protocol/contracts/profit/src/msg.rs index 8534b4d64..d0f7072c1 100644 --- a/protocol/contracts/profit/src/msg.rs +++ b/protocol/contracts/profit/src/msg.rs @@ -62,3 +62,19 @@ pub enum QueryMsg { pub struct ConfigResponse { pub cadence_hours: CadenceHours, } + +#[cfg(test)] +mod test { + + use platform::tests as platform_tests; + + use super::QueryMsg; + + #[test] + fn release() { + assert_eq!( + Ok(QueryMsg::ProtocolPackageRelease {}), + platform_tests::ser_de(&versioning::query::ProtocolPackage::Release {}), + ); + } +} diff --git a/protocol/contracts/reserve/src/api.rs b/protocol/contracts/reserve/src/api.rs index 94cd70c12..7ced396ef 100644 --- a/protocol/contracts/reserve/src/api.rs +++ b/protocol/contracts/reserve/src/api.rs @@ -42,7 +42,7 @@ pub enum ExecuteMsg { pub enum SudoMsg {} #[derive(Serialize, Deserialize, Clone, Eq, PartialEq, JsonSchema)] -#[cfg_attr(feature = "testing", derive(Debug))] +#[cfg_attr(any(test, feature = "testing"), derive(Debug))] #[serde(deny_unknown_fields, rename_all = "snake_case")] pub enum QueryMsg { /// Return a [LpnCurrencyDTO] of the Lpn this reserve holds @@ -66,3 +66,19 @@ impl ConfigResponse { } } } + +#[cfg(test)] +mod test { + + use platform::tests as platform_tests; + + use super::QueryMsg; + + #[test] + fn release() { + assert_eq!( + Ok(QueryMsg::ProtocolPackageRelease {}), + platform_tests::ser_de(&versioning::query::ProtocolPackage::Release {}), + ); + } +}