Skip to content

Commit

Permalink
omit whitelisted collection, use komple mint module
Browse files Browse the repository at this point in the history
  • Loading branch information
janfabian committed Jun 29, 2023
1 parent d5664c0 commit 8bfc665
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 21 deletions.
3 changes: 0 additions & 3 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@ pub fn instantiate(
let admin = msg.admin.unwrap_or_else(|| info.sender.into_string());
deps.api.addr_validate(&admin)?;

let whitelisted_collections = msg.whitelisted_collections.unwrap_or_default();

INFORMATION.save(
deps.storage,
&ContractInformationResponse {
admin,
whitelisted_collections,
komple_mint_addr: msg.komple_mint_addr,
},
)?;
Expand Down
2 changes: 0 additions & 2 deletions src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::state::{FarmProfile, FarmProfileDto};
pub struct InstantiateMsg {
pub admin: Option<String>,
pub komple_mint_addr: Option<String>,
pub whitelisted_collections: Option<Vec<KompleCollection>>,
}

#[cw_serde]
Expand Down Expand Up @@ -51,6 +50,5 @@ pub struct KompleCollection {
#[cw_serde]
pub struct ContractInformationResponse {
pub admin: String,
pub whitelisted_collections: Vec<KompleCollection>,
pub komple_mint_addr: Option<String>,
}
68 changes: 53 additions & 15 deletions src/receive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod seed;
use cw721::Cw721ReceiveMsg;
use cw721_base::QueryMsg as Cw721QueryMsg;
use komple_framework_metadata_module::msg::{MetadataResponse, QueryMsg as KompleMetadataQueryMsg};
use komple_framework_mint_module::msg::{CollectionsResponse, QueryMsg as KompleMintQueryMsg};
use komple_framework_token_module::msg::QueryMsg as KompleTokenQueryMsg;
use komple_framework_types::{modules::token::SubModules, shared::query::ResponseWrapper};
use seed::seed;
Expand All @@ -21,10 +22,20 @@ pub fn receive(
) -> Result<Response, ContractError> {
let config = INFORMATION.load(deps.storage)?;

let collection = config
.whitelisted_collections
.iter()
.find(|c| info.sender.eq(&c.addr));
if config.komple_mint_addr.is_none() {
return Err(throw_err(&format!("Komple mint address not provided",)));

Check warning on line 26 in src/receive/mod.rs

View workflow job for this annotation

GitHub Actions / Lints

useless use of `format!`
}

let collections: ResponseWrapper<Vec<CollectionsResponse>> = deps.querier.query_wasm_smart(
config.komple_mint_addr.unwrap(),
&KompleMintQueryMsg::Collections {
blacklist: false,
start_after: None,
limit: None,
},
)?;

let collection = collections.data.iter().find(|c| info.sender.eq(&c.address));

if collection.is_none() {
return Err(throw_err(&format!("Unauthorized collection",)));

Check warning on line 41 in src/receive/mod.rs

View workflow job for this annotation

GitHub Actions / Lints

useless use of `format!`
Expand All @@ -33,7 +44,7 @@ pub fn receive(
let collection = collection.unwrap();

let submodules: ResponseWrapper<SubModules> = deps.querier.query_wasm_smart(
&collection.addr,
&collection.address,
&Cw721QueryMsg::Extension {
msg: KompleTokenQueryMsg::SubModules {},
},
Expand Down Expand Up @@ -65,7 +76,7 @@ pub fn receive(

let komple = KomplePlant {
metadata_id: metadata.data.metadata_id,
collection_id: collection.id,
collection_id: collection.collection_id,
};

match from_binary(&msg.msg)? {
Expand All @@ -84,17 +95,18 @@ pub fn receive(

#[cfg(test)]
mod test {
use cosmwasm_std::{testing::mock_info, to_binary, Addr, SystemResult, WasmQuery};
use cosmwasm_std::{testing::mock_info, to_binary, SystemResult, WasmQuery};
use cw721::Cw721ReceiveMsg;
use komple_framework_metadata_module::{
msg::MetadataResponse,
state::{MetaInfo, Metadata, Trait},
};
use komple_framework_mint_module::msg::CollectionsResponse;
use komple_framework_types::{modules::token::SubModules, shared::query::ResponseWrapper};

use crate::{
contract::execute,
msg::{Cw721HookMsg, ExecuteMsg, InstantiateMsg, KompleCollection},
msg::{Cw721HookMsg, ExecuteMsg, InstantiateMsg},
tests::{general_handle_wasm_query, get_komple_addrs, init_farm, setup_test, till},
};

Expand All @@ -103,10 +115,27 @@ mod test {
fn unauthorized_collection() {
let (mut deps, env) = setup_test(Some(InstantiateMsg {
admin: None,
whitelisted_collections: None,
komple_mint_addr: None,
komple_mint_addr: Some(get_komple_addrs().mint.to_string()),
}));

deps.querier
.update_wasm(move |wasm_query| match wasm_query {
WasmQuery::Smart {
contract_addr,
msg: _msg,
} if *contract_addr == get_komple_addrs().mint => SystemResult::Ok(
to_binary(&ResponseWrapper::new(
"collections",
vec![CollectionsResponse {
address: "collection".to_string(),
collection_id: 1,
}],
))
.into(),
),
_ => general_handle_wasm_query(wasm_query),
});

let collection_addr = "collection_addr";
let auth_info = mock_info(collection_addr, &vec![]);
let nft_owner = "nft_owner";
Expand All @@ -126,11 +155,7 @@ mod test {
let collection_addr = "collection_addr";
let (mut deps, env) = setup_test(Some(InstantiateMsg {
admin: None,
whitelisted_collections: Some(vec![KompleCollection {
addr: Addr::unchecked(collection_addr),
id: 1,
}]),
komple_mint_addr: None,
komple_mint_addr: Some(get_komple_addrs().mint.to_string()),
}));

deps.querier
Expand Down Expand Up @@ -173,6 +198,19 @@ mod test {
))
.into(),
),
WasmQuery::Smart {
contract_addr,
msg: _msg,
} if *contract_addr == get_komple_addrs().mint => SystemResult::Ok(
to_binary(&ResponseWrapper::new(
"collections",
vec![CollectionsResponse {
address: collection_addr.to_string(),
collection_id: 1,
}],
))
.into(),
),
_ => general_handle_wasm_query(wasm_query),
});

Expand Down
1 change: 0 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ fn proper_initialization() {

let msg = InstantiateMsg {
admin: None,
whitelisted_collections: None,
komple_mint_addr: None,
};
let info = mock_info("creator", &vec![]);
Expand Down

0 comments on commit 8bfc665

Please sign in to comment.