Skip to content
Open
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
39 changes: 0 additions & 39 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ pub fn execute(
env,
info,
),
ExecuteMsg::SetRefundable { campaign_id } => set_refundable(
deps,
env,
info,
campaign_id,
),
ExecuteMsg::Cancel { campaign_id } => cancel(
deps,
env,
Expand Down Expand Up @@ -168,7 +162,6 @@ pub fn deposit(
&Campaign {
owner: info.sender,
amount: amount_sent,
refundable: false,
},
)?
}
Expand Down Expand Up @@ -396,33 +389,6 @@ pub fn withdraw_fee(
return Ok(res)
}

pub fn set_refundable(
deps: DepsMut,
_env: Env,
info: MessageInfo,
campaign_id: String,
) -> Result<Response, StdError> {
let state = STATE.load(deps.storage)?;

if deps.api.addr_canonicalize(info.sender.as_str())? != state.owner {
return Err(StdError::generic_err("Only contract owner can make the campaign refundable"));
}

if !CAMPAIGN_POOL.has(deps.storage, campaign_id.clone()){
return Err(StdError::generic_err("Campaign does not exist"))
}

CAMPAIGN_POOL.update(deps.storage, campaign_id, |campaign| {
let mut campaign = campaign.unwrap();
campaign.refundable = true;
Ok::<Campaign, StdError>(campaign)
})?;

return Ok(Response::new()
.add_attribute("method", "set_refundable")
);
}

pub fn cancel(
deps: DepsMut,
_env: Env,
Expand All @@ -437,10 +403,6 @@ pub fn cancel(
return Err(StdError::generic_err("Only campaign owner can cancel the campaign"));
}

if !campaign.refundable {
return Err(StdError::generic_err("Campaign was not set to be refundable"));
}

if campaign.amount < Uint128::one() {
CAMPAIGN_POOL.remove(deps.storage, campaign_id);
return Ok(Response::new()
Expand Down Expand Up @@ -489,7 +451,6 @@ pub fn set_cpool(
CAMPAIGN_POOL.save(deps.storage, campaign_id, &Campaign {
owner: info.sender,
amount,
refundable: false,
})
}
}?;
Expand Down
3 changes: 0 additions & 3 deletions src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ pub enum ExecuteMsg {
amount: Uint128,
},
WithdrawFee {},
SetRefundable {
campaign_id: String
},
Cancel {
campaign_id: String
},
Expand Down
1 change: 0 additions & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use serde::{Deserialize, Serialize};
pub struct Campaign {
pub amount: Uint128,
pub owner: Addr,
pub refundable: bool,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
Expand Down
57 changes: 1 addition & 56 deletions src/tests/execute/cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use cosmwasm_std::{

use crate::contract::{
cancel, check, claim, deposit, instantiate, reward_all, set_claim_fee, set_cpool,
set_refundable, set_upool, withdraw, withdraw_fee,
set_upool, withdraw, withdraw_fee,
};
use crate::msg::{
CampaignCheckRequest, CampaignCheckResponse, InstantiateMsg, UserRewardRequest,
Expand Down Expand Up @@ -41,13 +41,6 @@ fn test_cancel_as_contract_owner() {
)
.unwrap();

set_refundable(
deps.as_mut(),
env.clone(),
mock_info("creator", &[]),
"test_campaign_1".to_string(),
)
.unwrap();

let resp = cancel(
deps.as_mut(),
Expand Down Expand Up @@ -94,14 +87,6 @@ fn test_cancel_as_campaign_owner() {
)
.unwrap();

set_refundable(
deps.as_mut(),
env.clone(),
mock_info("creator", &[]),
"test_campaign_1".to_string(),
)
.unwrap();

let resp = cancel(
deps.as_mut(),
env.clone(),
Expand All @@ -124,46 +109,6 @@ fn test_cancel_as_campaign_owner() {
);
}

#[test]
fn test_cancel_non_refundable_campaign() {
let mut deps = mock_dependencies();
let env = mock_env();

instantiate(
deps.as_mut(),
env.clone(),
mock_info("creator", &[]),
InstantiateMsg {
claim_reward_fee: Some(Uint128::new(999)),
},
)
.unwrap();

deposit(
deps.as_mut(),
env.clone(),
mock_info("sender1", &coins(100, "")),
"test_campaign_1".to_string(),
)
.unwrap();

let res = cancel(
deps.as_mut(),
env.clone(),
mock_info("creator", &[]),
"test_campaign_1".to_string(),
);

assert_eq!(
res,
Err(StdError::generic_err(
"Campaign was not set to be refundable"
))
);

assert!(CAMPAIGN_POOL.has(deps.as_ref().storage, "test_campaign_1".to_string()));
}

#[test]
fn test_cancel_non_existent_campaign() {
let mut deps = mock_dependencies();
Expand Down
5 changes: 1 addition & 4 deletions src/tests/execute/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use cosmwasm_std::{

use crate::contract::{
cancel, check, claim, deposit, instantiate, reward_all, set_claim_fee, set_cpool,
set_refundable, set_upool, withdraw, withdraw_fee,
set_upool, withdraw, withdraw_fee,
};
use crate::msg::{
CampaignCheckRequest, CampaignCheckResponse, InstantiateMsg, UserRewardRequest,
Expand Down Expand Up @@ -93,7 +93,6 @@ fn test_check() {
Campaign {
amount: Uint128::new(50),
owner: Addr::unchecked("sender1"),
refundable: false,
}
);

Expand All @@ -106,7 +105,6 @@ fn test_check() {
Campaign {
amount: Uint128::new(80),
owner: Addr::unchecked("sender2"),
refundable: false,
}
);

Expand Down Expand Up @@ -173,7 +171,6 @@ fn test_check_nonexistent_campaign() {
Campaign {
amount: Uint128::new(50),
owner: Addr::unchecked("sender1"),
refundable: false,
}
);

Expand Down
2 changes: 1 addition & 1 deletion src/tests/execute/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use cosmwasm_std::{

use crate::contract::{
cancel, check, claim, deposit, instantiate, reward_all, set_claim_fee, set_cpool,
set_refundable, set_upool, withdraw, withdraw_fee,
set_upool, withdraw, withdraw_fee,
};
use crate::msg::{
CampaignCheckRequest, CampaignCheckResponse, InstantiateMsg, UserRewardRequest,
Expand Down
4 changes: 1 addition & 3 deletions src/tests/execute/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use cosmwasm_std::{

use crate::contract::{
cancel, check, claim, deposit, instantiate, reward_all, set_claim_fee, set_cpool,
set_refundable, set_upool, withdraw, withdraw_fee,
set_upool, withdraw, withdraw_fee,
};
use crate::msg::{
CampaignCheckRequest, CampaignCheckResponse, InstantiateMsg, UserRewardRequest,
Expand Down Expand Up @@ -48,7 +48,6 @@ fn test_deposit() {
Ok(Campaign {
amount: Uint128::new(1000000),
owner: Addr::unchecked("sender"),
refundable: false,
})
);

Expand All @@ -67,7 +66,6 @@ fn test_deposit() {
Ok(Campaign {
amount: Uint128::new(2000000),
owner: Addr::unchecked("sender"),
refundable: false,
})
);
}
1 change: 0 additions & 1 deletion src/tests/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mod deposit;
mod reward_all;
mod set_claim_fee;
mod set_cpool;
mod set_refundable;
mod set_upool;
mod withdraw;
mod withdraw_fee;
3 changes: 1 addition & 2 deletions src/tests/execute/reward_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use cosmwasm_std::{

use crate::contract::{
cancel, check, claim, deposit, instantiate, reward_all, set_claim_fee, set_cpool,
set_refundable, set_upool, withdraw, withdraw_fee,
set_upool, withdraw, withdraw_fee,
};
use crate::msg::{
CampaignCheckRequest, CampaignCheckResponse, InstantiateMsg, UserRewardRequest,
Expand Down Expand Up @@ -88,7 +88,6 @@ fn test_reward_all() {
Campaign {
amount: Uint128::new(1),
owner: Addr::unchecked("sender"),
refundable: false,
}
);

Expand Down
2 changes: 1 addition & 1 deletion src/tests/execute/set_claim_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use cosmwasm_std::{

use crate::contract::{
cancel, check, claim, deposit, instantiate, reward_all, set_claim_fee, set_cpool,
set_refundable, set_upool, withdraw, withdraw_fee,
set_upool, withdraw, withdraw_fee,
};
use crate::msg::{
CampaignCheckRequest, CampaignCheckResponse, InstantiateMsg, UserRewardRequest,
Expand Down
4 changes: 1 addition & 3 deletions src/tests/execute/set_cpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use cosmwasm_std::{

use crate::contract::{
cancel, check, claim, deposit, instantiate, reward_all, set_claim_fee, set_cpool,
set_refundable, set_upool, withdraw, withdraw_fee,
set_upool, withdraw, withdraw_fee,
};
use crate::msg::{
CampaignCheckRequest, CampaignCheckResponse, InstantiateMsg, UserRewardRequest,
Expand Down Expand Up @@ -51,7 +51,6 @@ fn test_set_new_cpool() {
Campaign {
amount: Uint128::new(100),
owner: Addr::unchecked("creator"),
refundable: false,
}
);
}
Expand Down Expand Up @@ -97,7 +96,6 @@ fn test_set_existing_cpool() {
Campaign {
amount: Uint128::new(2000),
owner: Addr::unchecked("sender1"),
refundable: false,
}
);
}
Expand Down
Loading