Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Hide generated interface types in sv module #245

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
# Contract intefaces
"interfaces/cw1",
"interfaces/whitelist",
"interfaces/cw4",
"interfaces/cw20-allowances",
"interfaces/cw20-minting",
Expand Down
4 changes: 2 additions & 2 deletions examples/contracts/custom/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use cosmwasm_std::{CosmosMsg, QueryRequest, Response, StdResult};
use sylvia::types::{ExecCtx, InstantiateCtx, QueryCtx};
use sylvia::{contract, entry_points, schemars};
use sylvia::{contract, schemars};

use crate::messages::{CountResponse, CounterMsg, CounterQuery};

pub struct CustomContract;

#[cfg_attr(not(feature = "mt"), entry_points)]
#[cfg_attr(not(feature = "mt"), sylvia::entry_points)]
#[contract]
#[sv::custom(query=CounterQuery, msg=CounterMsg)]
impl CustomContract {
Expand Down
1 change: 1 addition & 0 deletions examples/contracts/cw1-subkeys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ cw-multi-test = { version = "0.16.2", optional = true }
cw-storage-plus = "1.0"
cw-utils = "1.0"
cw1 = { path = "../../interfaces/cw1" }
whitelist = { path = "../../interfaces/whitelist" }
cw1-whitelist = { path = "../cw1-whitelist", features = ["library"] }
cw2 = "1.0"
getrandom = { version = "0.2.8", features = ["js"] }
Expand Down
1 change: 0 additions & 1 deletion examples/contracts/cw1-subkeys/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use cosmwasm_std::{
StakingMsg, StdResult,
};
use cw1_whitelist::contract::Cw1WhitelistContract;
use cw1_whitelist::whitelist;
use cw2::set_contract_version;
use cw_storage_plus::{Bound, Map};
use cw_utils::Expiration;
Expand Down
4 changes: 2 additions & 2 deletions examples/contracts/cw1-subkeys/src/whitelist.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use cosmwasm_std::{Response, StdResult};
use cw1_whitelist::responses::AdminListResponse;
use cw1_whitelist::whitelist::{self, Whitelist};
use sylvia::contract;
use sylvia::types::{ExecCtx, QueryCtx};
use whitelist::responses::AdminListResponse;
use whitelist::Whitelist;

use crate::contract::Cw1SubkeysContract;
use crate::error::ContractError;
Expand Down
1 change: 1 addition & 0 deletions examples/contracts/cw1-whitelist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ cosmwasm-schema = "1.2"
serde = { version = "1.0", default-features = false, features = ["derive"] }
sylvia = { path = "../../../sylvia" }
cw1 = { path = "../../interfaces/cw1" }
whitelist = { path = "../../interfaces/whitelist" }
cw-storage-plus = "1.0"
thiserror = { version = "1.0" }
cw2 = "1.0"
Expand Down
25 changes: 11 additions & 14 deletions examples/contracts/cw1-whitelist/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::error::ContractError;
use crate::whitelist;
use cosmwasm_std::{Addr, Deps, Empty, Response};

use cw2::set_contract_version;
Expand Down Expand Up @@ -57,11 +56,11 @@ impl Cw1WhitelistContract<'_> {
#[cfg(test)]
mod tests {
use super::*;
use crate::responses::AdminListResponse;
use crate::whitelist::{self, Whitelist};
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::{coin, coins, to_binary, BankMsg, CosmosMsg, StakingMsg, SubMsg, WasmMsg};
use cw1::Cw1;
use whitelist::responses::AdminListResponse;
use whitelist::Whitelist;

#[test]
fn instantiate_and_modify_config() {
Expand Down Expand Up @@ -182,7 +181,7 @@ mod tests {
)
.unwrap();

let freeze = whitelist::ExecMsg::Freeze {};
let freeze = whitelist::sv::ExecMsg::Freeze {};
let msgs = vec![
BankMsg::Send {
to_address: bob.to_string(),
Expand Down Expand Up @@ -289,15 +288,13 @@ mod tests {
}

mod msgs {
use super::*;

use cosmwasm_std::{from_binary, from_slice, to_binary, BankMsg};

use crate::contract::{ContractExecMsg, ContractQueryMsg};

#[test]
fn freeze() {
let original = whitelist::ExecMsg::Freeze {};
let original = whitelist::sv::ExecMsg::Freeze {};
let serialized = to_binary(&original).unwrap();
let deserialized = from_binary(&serialized).unwrap();

Expand All @@ -309,14 +306,14 @@ mod tests {
let deserialized = from_slice(json).unwrap();

assert_eq!(
ContractExecMsg::Whitelist(whitelist::ExecMsg::Freeze {}),
ContractExecMsg::Whitelist(whitelist::sv::ExecMsg::Freeze {}),
deserialized
);
}

#[test]
fn update_admins() {
let original = whitelist::ExecMsg::UpdateAdmins {
let original = whitelist::sv::ExecMsg::UpdateAdmins {
admins: vec!["admin1".to_owned(), "admin2".to_owned()],
};
let serialized = to_binary(&original).unwrap();
Expand All @@ -332,7 +329,7 @@ mod tests {
let deserialized = from_slice(json).unwrap();

assert_eq!(
ContractExecMsg::Whitelist(whitelist::ExecMsg::UpdateAdmins {
ContractExecMsg::Whitelist(whitelist::sv::ExecMsg::UpdateAdmins {
admins: vec!["admin1".to_owned(), "admin3".to_owned()]
}),
deserialized
Expand All @@ -341,7 +338,7 @@ mod tests {

#[test]
fn admin_list() {
let original = whitelist::QueryMsg::AdminList {};
let original = whitelist::sv::QueryMsg::AdminList {};
let serialized = to_binary(&original).unwrap();
let deserialized = from_binary(&serialized).unwrap();

Expand All @@ -353,14 +350,14 @@ mod tests {
let deserialized = from_slice(json).unwrap();

assert_eq!(
ContractQueryMsg::Whitelist(whitelist::QueryMsg::AdminList {}),
ContractQueryMsg::Whitelist(whitelist::sv::QueryMsg::AdminList {}),
deserialized
);
}

#[test]
fn execute() {
let original = cw1::ExecMsg::Execute {
let original = cw1::sv::ExecMsg::Execute {
msgs: vec![BankMsg::Send {
to_address: "admin1".to_owned(),
amount: vec![],
Expand All @@ -374,7 +371,7 @@ mod tests {

#[test]
fn can_execute() {
let original = cw1::QueryMsg::CanExecute {
let original = cw1::sv::QueryMsg::CanExecute {
sender: "admin".to_owned(),
msg: BankMsg::Send {
to_address: "admin1".to_owned(),
Expand Down
1 change: 0 additions & 1 deletion examples/contracts/cw1-whitelist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ mod cw1;
pub mod error;
#[cfg(any(test, feature = "tests"))]
pub mod multitest;
pub mod responses;
pub mod whitelist;
5 changes: 2 additions & 3 deletions examples/contracts/cw1-whitelist/src/multitest.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#[cfg(test)]
mod test {
use cosmwasm_std::{to_binary, WasmMsg};
use whitelist::responses::AdminListResponse;

use crate::contract::multitest_utils::CodeId;
use crate::cw1::test_utils::Cw1;
use crate::error::ContractError;
use crate::responses::AdminListResponse;
use crate::whitelist;
use crate::whitelist::test_utils::Whitelist;
use assert_matches::assert_matches;
use sylvia::multitest::App;
Expand All @@ -30,7 +29,7 @@ mod test {
.call(owner)
.unwrap();

let freeze = whitelist::ExecMsg::Freeze {};
let freeze = whitelist::sv::ExecMsg::Freeze {};
let freeze = WasmMsg::Execute {
contract_addr: second_contract.contract_addr.to_string(),
msg: to_binary(&freeze).unwrap(),
Expand Down
20 changes: 4 additions & 16 deletions examples/contracts/cw1-whitelist/src/whitelist.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
use cosmwasm_std::{Empty, Order, Response, StdResult};
use sylvia::contract;
use sylvia::types::{ExecCtx, QueryCtx};
use sylvia::{contract, interface, schemars};
use whitelist::responses::AdminListResponse;
use whitelist::Whitelist;

use crate::contract::Cw1WhitelistContract;
use crate::error::ContractError;
use crate::responses::AdminListResponse;

#[interface]
pub trait Whitelist {
type Error: From<cosmwasm_std::StdError>;

#[msg(exec)]
fn freeze(&self, ctx: ExecCtx) -> Result<Response, Self::Error>;

#[msg(exec)]
fn update_admins(&self, ctx: ExecCtx, admins: Vec<String>) -> Result<Response, Self::Error>;

#[msg(query)]
fn admin_list(&self, ctx: QueryCtx) -> StdResult<AdminListResponse>;
}

#[contract(module=crate::contract)]
#[messages(whitelist as Whitelist)]
impl Whitelist for Cw1WhitelistContract<'_> {
type Error = ContractError;

Expand Down
16 changes: 8 additions & 8 deletions examples/interfaces/custom-and-generic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,33 @@ mod tests {
use cosmwasm_std::{Addr, CosmosMsg, Empty, QuerierWrapper};
use sylvia::types::{InterfaceMessages, SvCustomMsg};

use crate::Querier;
use crate::sv::Querier;

#[test]
fn construct_messages() {
let contract = Addr::unchecked("contract");

// Direct message construction
let _ = super::QueryMsg::<_, Empty>::custom_generic_query(SvCustomMsg {});
let _ = super::ExecMsg::custom_generic_execute(vec![CosmosMsg::Custom(SvCustomMsg {})]);
let _ = super::ExecMsg::custom_generic_execute(vec![CosmosMsg::Custom(SvCustomMsg {})]);
let _ = super::sv::QueryMsg::<_, Empty>::custom_generic_query(SvCustomMsg {});
let _ = super::sv::ExecMsg::custom_generic_execute(vec![CosmosMsg::Custom(SvCustomMsg {})]);
let _ = super::sv::ExecMsg::custom_generic_execute(vec![CosmosMsg::Custom(SvCustomMsg {})]);

// Querier
let deps = mock_dependencies();
let querier_wrapper: QuerierWrapper = QuerierWrapper::new(&deps.querier);

let querier = super::BoundQuerier::borrowed(&contract, &querier_wrapper);
let querier = super::sv::BoundQuerier::borrowed(&contract, &querier_wrapper);
let _: Result<SvCustomMsg, _> =
super::Querier::custom_generic_query(&querier, SvCustomMsg {});
super::sv::Querier::custom_generic_query(&querier, SvCustomMsg {});
let _: Result<SvCustomMsg, _> = querier.custom_generic_query(SvCustomMsg {});

// Construct messages with Interface extension
let _ =
<super::InterfaceTypes<SvCustomMsg, _, SvCustomMsg> as InterfaceMessages>::Query::custom_generic_query(
<super::sv::InterfaceTypes<SvCustomMsg, _, SvCustomMsg> as InterfaceMessages>::Query::custom_generic_query(
SvCustomMsg {},
);
let _=
<super::InterfaceTypes<_, SvCustomMsg, cosmwasm_std::Empty> as InterfaceMessages>::Exec::custom_generic_execute(
<super::sv::InterfaceTypes<_, SvCustomMsg, cosmwasm_std::Empty> as InterfaceMessages>::Exec::custom_generic_execute(
vec![ CosmosMsg::Custom(SvCustomMsg{}),
]);
}
Expand Down
10 changes: 4 additions & 6 deletions examples/interfaces/cw1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ pub trait Cw1 {
mod tests {
use cosmwasm_std::{coins, from_binary, from_slice, to_binary, BankMsg};

use super::*;

#[test]
fn execute() {
let original = ExecMsg::Execute {
let original = super::sv::ExecMsg::Execute {
msgs: vec![BankMsg::Send {
to_address: "receiver".to_owned(),
amount: coins(10, "atom"),
Expand All @@ -57,12 +55,12 @@ mod tests {
#[test]
fn execute_from_slice() {
let deserialized = from_slice(br#"{"execute": { "msgs": [] }}"#).unwrap();
assert_eq!(ExecMsg::Execute { msgs: vec![] }, deserialized);
assert_eq!(super::sv::ExecMsg::Execute { msgs: vec![] }, deserialized);
}

#[test]
fn query() {
let original = QueryMsg::CanExecute {
let original = super::sv::QueryMsg::CanExecute {
sender: "sender".to_owned(),
msg: BankMsg::Send {
to_address: "receiver".to_owned(),
Expand Down Expand Up @@ -99,7 +97,7 @@ mod tests {
)
.unwrap();
assert_eq!(
QueryMsg::CanExecute {
super::sv::QueryMsg::CanExecute {
sender: "address".to_owned(),
msg: BankMsg::Send {
to_address: "receiver".to_owned(),
Expand Down
2 changes: 1 addition & 1 deletion examples/interfaces/cw4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub trait Cw4 {
mod tests {
use cosmwasm_std::{from_binary, from_slice, to_binary};

use super::*;
use super::sv::*;

#[test]
fn execute() {
Expand Down
16 changes: 8 additions & 8 deletions examples/interfaces/generic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,32 @@ mod tests {
use cosmwasm_std::{testing::mock_dependencies, Addr, CosmosMsg, Empty, QuerierWrapper};
use sylvia::types::{InterfaceMessages, SvCustomMsg};

use crate::Querier;
use crate::sv::Querier;

#[test]
fn construct_messages() {
let contract = Addr::unchecked("contract");

// Direct message construction
let _ = super::QueryMsg::<_, Empty>::generic_query(SvCustomMsg {});
let _ = super::ExecMsg::generic_exec(vec![CosmosMsg::Custom(SvCustomMsg {})]);
let _ = super::ExecMsg::generic_exec(vec![CosmosMsg::Custom(SvCustomMsg {})]);
let _ = super::sv::QueryMsg::<_, Empty>::generic_query(SvCustomMsg {});
let _ = super::sv::ExecMsg::generic_exec(vec![CosmosMsg::Custom(SvCustomMsg {})]);
let _ = super::sv::ExecMsg::generic_exec(vec![CosmosMsg::Custom(SvCustomMsg {})]);

// Querier
let deps = mock_dependencies();
let querier_wrapper: QuerierWrapper = QuerierWrapper::new(&deps.querier);

let querier = super::BoundQuerier::borrowed(&contract, &querier_wrapper);
let _: Result<SvCustomMsg, _> = super::Querier::generic_query(&querier, SvCustomMsg {});
let querier = super::sv::BoundQuerier::borrowed(&contract, &querier_wrapper);
let _: Result<SvCustomMsg, _> = super::sv::Querier::generic_query(&querier, SvCustomMsg {});
let _: Result<SvCustomMsg, _> = querier.generic_query(SvCustomMsg {});

// Construct messages with Interface extension
let _ =
<super::InterfaceTypes<SvCustomMsg, _, SvCustomMsg> as InterfaceMessages>::Query::generic_query(
<super::sv::InterfaceTypes<SvCustomMsg, _, SvCustomMsg> as InterfaceMessages>::Query::generic_query(
SvCustomMsg {},
);
let _=
<super::InterfaceTypes<_, SvCustomMsg, cosmwasm_std::Empty> as InterfaceMessages>::Exec::generic_exec(vec![
<super::sv::InterfaceTypes<_, SvCustomMsg, cosmwasm_std::Empty> as InterfaceMessages>::Exec::generic_exec(vec![
CosmosMsg::Custom(SvCustomMsg{}),
]);
}
Expand Down
Loading
Loading