Skip to content

Commit

Permalink
Merge pull request #119 from public-awesome/shanev/wl-refactor
Browse files Browse the repository at this point in the history
Whitelist refactor
  • Loading branch information
shanev authored Mar 4, 2022
2 parents d389ad9 + 0d3a8aa commit bc1f695
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 160 deletions.
8 changes: 4 additions & 4 deletions contracts/minter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::state::{
use sg_std::{burn_and_distribute_fee, StargazeMsgWrapper, GENESIS_MINT_START_TIME, NATIVE_DENOM};
use whitelist::msg::{
ConfigResponse as WhitelistConfigResponse, HasMemberResponse, QueryMsg as WhitelistQueryMsg,
UnitPriceResponse,
};

pub type Response = cosmwasm_std::Response<StargazeMsgWrapper>;
Expand Down Expand Up @@ -484,6 +483,7 @@ pub fn mint_price(deps: Deps, admin_no_fee: bool) -> Result<Coin, StdError> {
let wl_config: WhitelistConfigResponse = deps
.querier
.query_wasm_smart(whitelist, &WhitelistQueryMsg::Config {})?;

if wl_config.is_active {
wl_config.unit_price
} else {
Expand Down Expand Up @@ -554,10 +554,10 @@ fn query_mint_price(deps: Deps) -> StdResult<MintPriceResponse> {
let current_price = mint_price(deps, false)?;
let public_price = config.unit_price;
let whitelist_price: Option<Coin> = if let Some(whitelist) = config.whitelist {
let unit_price: UnitPriceResponse = deps
let wl_config: WhitelistConfigResponse = deps
.querier
.query_wasm_smart(whitelist, &WhitelistQueryMsg::UnitPrice {})?;
Some(unit_price.unit_price)
.query_wasm_smart(whitelist, &WhitelistQueryMsg::Config {})?;
Some(wl_config.unit_price)
} else {
None
};
Expand Down
39 changes: 14 additions & 25 deletions contracts/minter/src/contract_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use sg721::msg::{InstantiateMsg as Sg721InstantiateMsg, RoyaltyInfoResponse};
use sg721::state::CollectionInfo;
use sg_std::{StargazeMsgWrapper, GENESIS_MINT_START_TIME, NATIVE_DENOM};
use whitelist::msg::InstantiateMsg as WhitelistInstantiateMsg;
use whitelist::msg::{ExecuteMsg as WhitelistExecuteMsg, UpdateMembersMsg};
use whitelist::msg::{AddMembersMsg, ExecuteMsg as WhitelistExecuteMsg};

use crate::contract::instantiate;
use crate::msg::{
Expand Down Expand Up @@ -227,9 +227,7 @@ fn initialization() {
},
},
};
let res = instantiate(deps.as_mut(), mock_env(), info, msg);
println!("{:?}", res);
assert!(res.is_err());
instantiate(deps.as_mut(), mock_env(), info, msg).unwrap_err();

// Invalid uri returns error
let info = mock_info("creator", &coins(INITIAL_BALANCE, NATIVE_DENOM));
Expand Down Expand Up @@ -257,8 +255,7 @@ fn initialization() {
},
},
};
let res = instantiate(deps.as_mut(), mock_env(), info, msg);
assert!(res.is_err());
instantiate(deps.as_mut(), mock_env(), info, msg).unwrap_err();

// invalid denom returns error
let wrong_denom = "uosmo";
Expand Down Expand Up @@ -287,8 +284,7 @@ fn initialization() {
},
},
};
let res = instantiate(deps.as_mut(), mock_env(), info, msg);
assert!(res.is_err());
instantiate(deps.as_mut(), mock_env(), info, msg).unwrap_err();

// insufficient mint price returns error
let info = mock_info("creator", &coins(INITIAL_BALANCE, NATIVE_DENOM));
Expand Down Expand Up @@ -316,8 +312,7 @@ fn initialization() {
},
},
};
let res = instantiate(deps.as_mut(), mock_env(), info, msg);
assert!(res.is_err());
instantiate(deps.as_mut(), mock_env(), info, msg).unwrap_err();

// over max token limit
let info = mock_info("creator", &coins(INITIAL_BALANCE, NATIVE_DENOM));
Expand Down Expand Up @@ -345,8 +340,7 @@ fn initialization() {
},
},
};
let res = instantiate(deps.as_mut(), mock_env(), info, msg);
assert!(res.is_err());
instantiate(deps.as_mut(), mock_env(), info, msg).unwrap_err();

// under min token limit
let info = mock_info("creator", &coins(INITIAL_BALANCE, NATIVE_DENOM));
Expand Down Expand Up @@ -588,11 +582,10 @@ fn mint_count_query() {
);
assert!(res.is_ok());

let inner_msg = UpdateMembersMsg {
add: vec![buyer.to_string()],
remove: vec![],
let inner_msg = AddMembersMsg {
to_add: vec![buyer.to_string()],
};
let wasm_msg = WhitelistExecuteMsg::UpdateMembers(inner_msg);
let wasm_msg = WhitelistExecuteMsg::AddMembers(inner_msg);
let res = router.execute_contract(
creator.clone(),
whitelist_addr,
Expand Down Expand Up @@ -786,11 +779,10 @@ fn whitelist_access_len_add_remove_expiration() {
);
assert!(res.is_err());

let inner_msg = UpdateMembersMsg {
add: vec![buyer.to_string()],
remove: vec![],
let inner_msg = AddMembersMsg {
to_add: vec![buyer.to_string()],
};
let wasm_msg = WhitelistExecuteMsg::UpdateMembers(inner_msg);
let wasm_msg = WhitelistExecuteMsg::AddMembers(inner_msg);
let res = router.execute_contract(
creator.clone(),
whitelist_addr.clone(),
Expand Down Expand Up @@ -882,11 +874,8 @@ fn whitelist_access_len_add_remove_expiration() {
);

// remove buyer from whitelist
let inner_msg = UpdateMembersMsg {
add: vec![],
remove: vec![buyer.to_string()],
};
let wasm_msg = WhitelistExecuteMsg::UpdateMembers(inner_msg);
let inner_msg = AddMembersMsg { to_add: vec![] };
let wasm_msg = WhitelistExecuteMsg::AddMembers(inner_msg);
let res = router.execute_contract(
creator.clone(),
whitelist_addr,
Expand Down
67 changes: 43 additions & 24 deletions contracts/whitelist/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,23 @@
{
"type": "object",
"required": [
"update_members"
"add_members"
],
"properties": {
"update_members": {
"$ref": "#/definitions/UpdateMembersMsg"
"add_members": {
"$ref": "#/definitions/AddMembersMsg"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"remove_members"
],
"properties": {
"remove_members": {
"$ref": "#/definitions/RemoveMembersMsg"
}
},
"additionalProperties": false
Expand All @@ -54,6 +66,20 @@
}
],
"definitions": {
"AddMembersMsg": {
"type": "object",
"required": [
"to_add"
],
"properties": {
"to_add": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"Expiration": {
"description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)",
"oneOf": [
Expand Down Expand Up @@ -100,6 +126,20 @@
}
]
},
"RemoveMembersMsg": {
"type": "object",
"required": [
"to_remove"
],
"properties": {
"to_remove": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"Timestamp": {
"description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```",
"allOf": [
Expand All @@ -111,27 +151,6 @@
"Uint64": {
"description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```",
"type": "string"
},
"UpdateMembersMsg": {
"type": "object",
"required": [
"add",
"remove"
],
"properties": {
"add": {
"type": "array",
"items": {
"type": "string"
}
},
"remove": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
}
36 changes: 0 additions & 36 deletions contracts/whitelist/schema/query_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,6 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "QueryMsg",
"oneOf": [
{
"type": "object",
"required": [
"start_time"
],
"properties": {
"start_time": {
"type": "object"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"end_time"
],
"properties": {
"end_time": {
"type": "object"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
Expand Down Expand Up @@ -94,18 +70,6 @@
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"unit_price"
],
"properties": {
"unit_price": {
"type": "object"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
Expand Down
Loading

0 comments on commit bc1f695

Please sign in to comment.