From 0d9e035adb0c876ae6ec7c916aca1f1e9f8b4192 Mon Sep 17 00:00:00 2001 From: Noah Saso Date: Fri, 19 Jul 2024 14:12:08 -0400 Subject: [PATCH] add info query to pre-propose-base --- .../dao-pre-propose-approval-single.json | 48 +++++++++++++++++++ .../src/tests.rs | 16 +++++++ .../schema/dao-pre-propose-approver.json | 48 +++++++++++++++++++ .../dao-pre-propose-approver/src/tests.rs | 16 +++++++ .../schema/dao-pre-propose-multiple.json | 48 +++++++++++++++++++ .../dao-pre-propose-multiple/src/tests.rs | 16 +++++++ .../schema/dao-pre-propose-single.json | 48 +++++++++++++++++++ .../dao-pre-propose-single/src/tests.rs | 16 +++++++ packages/dao-pre-propose-base/src/execute.rs | 3 ++ packages/dao-pre-propose-base/src/msg.rs | 4 ++ 10 files changed, 263 insertions(+) diff --git a/contracts/pre-propose/dao-pre-propose-approval-single/schema/dao-pre-propose-approval-single.json b/contracts/pre-propose/dao-pre-propose-approval-single/schema/dao-pre-propose-approval-single.json index 9ea6e7bde..bc211ecd8 100644 --- a/contracts/pre-propose/dao-pre-propose-approval-single/schema/dao-pre-propose-approval-single.json +++ b/contracts/pre-propose/dao-pre-propose-approval-single/schema/dao-pre-propose-approval-single.json @@ -1897,6 +1897,20 @@ }, "additionalProperties": false }, + { + "description": "Returns contract version info.", + "type": "object", + "required": [ + "info" + ], + "properties": { + "info": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, { "description": "Gets the module's configuration.", "type": "object", @@ -2613,6 +2627,40 @@ } } }, + "info": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InfoResponse", + "type": "object", + "required": [ + "info" + ], + "properties": { + "info": { + "$ref": "#/definitions/ContractVersion" + } + }, + "additionalProperties": false, + "definitions": { + "ContractVersion": { + "type": "object", + "required": [ + "contract", + "version" + ], + "properties": { + "contract": { + "description": "contract is the crate name of the implementing contract, eg. `crate:cw20-base` we will use other prefixes for other languages, and their standard global namespacing", + "type": "string" + }, + "version": { + "description": "version is any string that this implementation knows. It may be simple counter \"1\", \"2\". or semantic version on release tags \"v0.7.0\", or some custom feature flag list. the only code that needs to understand the version parsing is code that knows how to migrate from the given contract (and is tied to it's implementation somehow)", + "type": "string" + } + }, + "additionalProperties": false + } + } + }, "proposal_module": { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Addr", diff --git a/contracts/pre-propose/dao-pre-propose-approval-single/src/tests.rs b/contracts/pre-propose/dao-pre-propose-approval-single/src/tests.rs index 0705780fc..9c0748b6c 100644 --- a/contracts/pre-propose/dao-pre-propose-approval-single/src/tests.rs +++ b/contracts/pre-propose/dao-pre-propose-approval-single/src/tests.rs @@ -4,6 +4,7 @@ use cw20::Cw20Coin; use cw_denom::UncheckedDenom; use cw_multi_test::{App, BankSudo, Contract, ContractWrapper, Executor}; use cw_utils::Duration; +use dao_interface::proposal::InfoResponse; use dao_interface::state::ProposalModule; use dao_interface::state::{Admin, ModuleInstantiateInfo}; use dao_pre_propose_base::{error::PreProposeError, msg::DepositInfoResponse, state::Config}; @@ -179,6 +180,15 @@ fn setup_default_test( get_proposal_module(app, pre_propose.clone()) ); assert_eq!(core_addr, get_dao(app, pre_propose.clone())); + assert_eq!( + InfoResponse { + info: ContractVersion { + contract: "crates.io:dao-pre-propose-approval-single".to_string(), + version: env!("CARGO_PKG_VERSION").to_string() + } + }, + get_info(app, pre_propose.clone()) + ); DefaultTestSetup { core_addr, @@ -297,6 +307,12 @@ fn get_dao(app: &App, module: Addr) -> Addr { .unwrap() } +fn get_info(app: &App, module: Addr) -> InfoResponse { + app.wrap() + .query_wasm_smart(module, &QueryMsg::Info {}) + .unwrap() +} + fn get_proposal_module(app: &App, module: Addr) -> Addr { app.wrap() .query_wasm_smart(module, &QueryMsg::ProposalModule {}) diff --git a/contracts/pre-propose/dao-pre-propose-approver/schema/dao-pre-propose-approver.json b/contracts/pre-propose/dao-pre-propose-approver/schema/dao-pre-propose-approver.json index 769cd499d..477b52d77 100644 --- a/contracts/pre-propose/dao-pre-propose-approver/schema/dao-pre-propose-approver.json +++ b/contracts/pre-propose/dao-pre-propose-approver/schema/dao-pre-propose-approver.json @@ -712,6 +712,20 @@ }, "additionalProperties": false }, + { + "description": "Returns contract version info.", + "type": "object", + "required": [ + "info" + ], + "properties": { + "info": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, { "description": "Gets the module's configuration.", "type": "object", @@ -1227,6 +1241,40 @@ } } }, + "info": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InfoResponse", + "type": "object", + "required": [ + "info" + ], + "properties": { + "info": { + "$ref": "#/definitions/ContractVersion" + } + }, + "additionalProperties": false, + "definitions": { + "ContractVersion": { + "type": "object", + "required": [ + "contract", + "version" + ], + "properties": { + "contract": { + "description": "contract is the crate name of the implementing contract, eg. `crate:cw20-base` we will use other prefixes for other languages, and their standard global namespacing", + "type": "string" + }, + "version": { + "description": "version is any string that this implementation knows. It may be simple counter \"1\", \"2\". or semantic version on release tags \"v0.7.0\", or some custom feature flag list. the only code that needs to understand the version parsing is code that knows how to migrate from the given contract (and is tied to it's implementation somehow)", + "type": "string" + } + }, + "additionalProperties": false + } + } + }, "proposal_module": { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Addr", diff --git a/contracts/pre-propose/dao-pre-propose-approver/src/tests.rs b/contracts/pre-propose/dao-pre-propose-approver/src/tests.rs index 9cae15ff8..2e62af1da 100644 --- a/contracts/pre-propose/dao-pre-propose-approver/src/tests.rs +++ b/contracts/pre-propose/dao-pre-propose-approver/src/tests.rs @@ -3,6 +3,7 @@ use cw2::ContractVersion; use cw20::Cw20Coin; use cw_denom::UncheckedDenom; use cw_multi_test::{App, BankSudo, Contract, ContractWrapper, Executor}; +use dao_interface::proposal::InfoResponse; use dao_voting::pre_propose::{PreProposeSubmissionPolicy, PreProposeSubmissionPolicyError}; use dps::query::{ProposalListResponse, ProposalResponse}; @@ -300,6 +301,15 @@ fn setup_default_test( approver_core_addr, get_dao(app, pre_propose_approver.clone()) ); + assert_eq!( + InfoResponse { + info: ContractVersion { + contract: "crates.io:dao-pre-propose-approver".to_string(), + version: env!("CARGO_PKG_VERSION").to_string() + } + }, + get_info(app, pre_propose_approver.clone()) + ); DefaultTestSetup { core_addr, @@ -418,6 +428,12 @@ fn get_dao(app: &App, module: Addr) -> Addr { .unwrap() } +fn get_info(app: &App, module: Addr) -> InfoResponse { + app.wrap() + .query_wasm_smart(module, &QueryMsg::Info {}) + .unwrap() +} + fn get_proposal_module(app: &App, module: Addr) -> Addr { app.wrap() .query_wasm_smart(module, &QueryMsg::ProposalModule {}) diff --git a/contracts/pre-propose/dao-pre-propose-multiple/schema/dao-pre-propose-multiple.json b/contracts/pre-propose/dao-pre-propose-multiple/schema/dao-pre-propose-multiple.json index a13061598..b4f9a74c2 100644 --- a/contracts/pre-propose/dao-pre-propose-multiple/schema/dao-pre-propose-multiple.json +++ b/contracts/pre-propose/dao-pre-propose-multiple/schema/dao-pre-propose-multiple.json @@ -1842,6 +1842,20 @@ }, "additionalProperties": false }, + { + "description": "Returns contract version info.", + "type": "object", + "required": [ + "info" + ], + "properties": { + "info": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, { "description": "Gets the module's configuration.", "type": "object", @@ -2298,6 +2312,40 @@ } } }, + "info": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InfoResponse", + "type": "object", + "required": [ + "info" + ], + "properties": { + "info": { + "$ref": "#/definitions/ContractVersion" + } + }, + "additionalProperties": false, + "definitions": { + "ContractVersion": { + "type": "object", + "required": [ + "contract", + "version" + ], + "properties": { + "contract": { + "description": "contract is the crate name of the implementing contract, eg. `crate:cw20-base` we will use other prefixes for other languages, and their standard global namespacing", + "type": "string" + }, + "version": { + "description": "version is any string that this implementation knows. It may be simple counter \"1\", \"2\". or semantic version on release tags \"v0.7.0\", or some custom feature flag list. the only code that needs to understand the version parsing is code that knows how to migrate from the given contract (and is tied to it's implementation somehow)", + "type": "string" + } + }, + "additionalProperties": false + } + } + }, "proposal_module": { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Addr", diff --git a/contracts/pre-propose/dao-pre-propose-multiple/src/tests.rs b/contracts/pre-propose/dao-pre-propose-multiple/src/tests.rs index 48a01a2aa..1e7a41681 100644 --- a/contracts/pre-propose/dao-pre-propose-multiple/src/tests.rs +++ b/contracts/pre-propose/dao-pre-propose-multiple/src/tests.rs @@ -5,6 +5,7 @@ use cw20::Cw20Coin; use cw_denom::UncheckedDenom; use cw_multi_test::{App, BankSudo, Contract, ContractWrapper, Executor}; use cw_utils::Duration; +use dao_interface::proposal::InfoResponse; use dao_interface::state::ProposalModule; use dao_interface::state::{Admin, ModuleInstantiateInfo}; use dao_pre_propose_base::{error::PreProposeError, msg::DepositInfoResponse, state::Config}; @@ -178,6 +179,15 @@ fn setup_default_test( get_proposal_module(app, pre_propose.clone()) ); assert_eq!(core_addr, get_dao(app, pre_propose.clone())); + assert_eq!( + InfoResponse { + info: ContractVersion { + contract: "crates.io:dao-pre-propose-multiple".to_string(), + version: env!("CARGO_PKG_VERSION").to_string() + } + }, + get_info(app, pre_propose.clone()) + ); DefaultTestSetup { core_addr, @@ -350,6 +360,12 @@ fn get_dao(app: &App, module: Addr) -> Addr { .unwrap() } +fn get_info(app: &App, module: Addr) -> InfoResponse { + app.wrap() + .query_wasm_smart(module, &QueryMsg::Info {}) + .unwrap() +} + fn get_proposal_module(app: &App, module: Addr) -> Addr { app.wrap() .query_wasm_smart(module, &QueryMsg::ProposalModule {}) diff --git a/contracts/pre-propose/dao-pre-propose-single/schema/dao-pre-propose-single.json b/contracts/pre-propose/dao-pre-propose-single/schema/dao-pre-propose-single.json index 507c69ae8..f96180633 100644 --- a/contracts/pre-propose/dao-pre-propose-single/schema/dao-pre-propose-single.json +++ b/contracts/pre-propose/dao-pre-propose-single/schema/dao-pre-propose-single.json @@ -1816,6 +1816,20 @@ }, "additionalProperties": false }, + { + "description": "Returns contract version info.", + "type": "object", + "required": [ + "info" + ], + "properties": { + "info": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, { "description": "Gets the module's configuration.", "type": "object", @@ -2272,6 +2286,40 @@ } } }, + "info": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InfoResponse", + "type": "object", + "required": [ + "info" + ], + "properties": { + "info": { + "$ref": "#/definitions/ContractVersion" + } + }, + "additionalProperties": false, + "definitions": { + "ContractVersion": { + "type": "object", + "required": [ + "contract", + "version" + ], + "properties": { + "contract": { + "description": "contract is the crate name of the implementing contract, eg. `crate:cw20-base` we will use other prefixes for other languages, and their standard global namespacing", + "type": "string" + }, + "version": { + "description": "version is any string that this implementation knows. It may be simple counter \"1\", \"2\". or semantic version on release tags \"v0.7.0\", or some custom feature flag list. the only code that needs to understand the version parsing is code that knows how to migrate from the given contract (and is tied to it's implementation somehow)", + "type": "string" + } + }, + "additionalProperties": false + } + } + }, "proposal_module": { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Addr", diff --git a/contracts/pre-propose/dao-pre-propose-single/src/tests.rs b/contracts/pre-propose/dao-pre-propose-single/src/tests.rs index f579ad398..96d575e65 100644 --- a/contracts/pre-propose/dao-pre-propose-single/src/tests.rs +++ b/contracts/pre-propose/dao-pre-propose-single/src/tests.rs @@ -4,6 +4,7 @@ use cw20::Cw20Coin; use cw_denom::UncheckedDenom; use cw_multi_test::{App, BankSudo, Contract, ContractWrapper, Executor}; use cw_utils::Duration; +use dao_interface::proposal::InfoResponse; use dao_interface::state::ProposalModule; use dao_interface::state::{Admin, ModuleInstantiateInfo}; use dao_pre_propose_base::{error::PreProposeError, msg::DepositInfoResponse, state::Config}; @@ -176,6 +177,15 @@ fn setup_default_test( get_proposal_module(app, pre_propose.clone()) ); assert_eq!(core_addr, get_dao(app, pre_propose.clone())); + assert_eq!( + InfoResponse { + info: ContractVersion { + contract: "crates.io:dao-pre-propose-single".to_string(), + version: env!("CARGO_PKG_VERSION").to_string() + } + }, + get_info(app, pre_propose.clone()) + ); DefaultTestSetup { core_addr, @@ -325,6 +335,12 @@ fn get_dao(app: &App, module: Addr) -> Addr { .unwrap() } +fn get_info(app: &App, module: Addr) -> InfoResponse { + app.wrap() + .query_wasm_smart(module, &QueryMsg::Info {}) + .unwrap() +} + fn query_hooks(app: &App, module: Addr) -> cw_hooks::HooksResponse { app.wrap() .query_wasm_smart(module, &QueryMsg::ProposalSubmittedHooks {}) diff --git a/packages/dao-pre-propose-base/src/execute.rs b/packages/dao-pre-propose-base/src/execute.rs index 223e08b2d..21bcee3a5 100644 --- a/packages/dao-pre-propose-base/src/execute.rs +++ b/packages/dao-pre-propose-base/src/execute.rs @@ -567,6 +567,9 @@ where to_json_binary(&self.proposal_module.load(deps.storage)?) } QueryMsg::Dao {} => to_json_binary(&self.dao.load(deps.storage)?), + QueryMsg::Info {} => to_json_binary(&dao_interface::proposal::InfoResponse { + info: cw2::get_contract_version(deps.storage)?, + }), QueryMsg::Config {} => to_json_binary(&self.config.load(deps.storage)?), QueryMsg::DepositInfo { proposal_id } => { let (deposit_info, proposer) = self.deposits.load(deps.storage, proposal_id)?; diff --git a/packages/dao-pre-propose-base/src/msg.rs b/packages/dao-pre-propose-base/src/msg.rs index f3391cf71..e795969e9 100644 --- a/packages/dao-pre-propose-base/src/msg.rs +++ b/packages/dao-pre-propose-base/src/msg.rs @@ -1,5 +1,6 @@ use cosmwasm_schema::{cw_serde, schemars::JsonSchema, QueryResponses}; use cw_denom::UncheckedDenom; +use dao_interface::proposal::InfoResponse; use dao_voting::{ deposit::{CheckedDepositInfo, UncheckedDepositInfo}, pre_propose::PreProposeSubmissionPolicy, @@ -118,6 +119,9 @@ where /// with. Returns `Addr`. #[returns(cosmwasm_std::Addr)] Dao {}, + /// Returns contract version info. + #[returns(InfoResponse)] + Info {}, /// Gets the module's configuration. #[returns(crate::state::Config)] Config {},