Skip to content

Commit

Permalink
fix bug on bounty update (#730)
Browse files Browse the repository at this point in the history
* check Bounty is correct in all tests

* fix update bounty with lower amount and owner accidentally send funds

* cleanup and test update with sending wrong denom
  • Loading branch information
taitruong authored and JakeHartnell committed Dec 29, 2023
1 parent d425832 commit 1ab952c
Show file tree
Hide file tree
Showing 2 changed files with 463 additions and 191 deletions.
8 changes: 5 additions & 3 deletions contracts/external/cw-bounties/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use cosmwasm_std::{
};
use cw2::set_contract_version;
use cw_paginate_storage::paginate_map_values;
use cw_utils::must_pay;
use cw_utils::{may_pay, must_pay};

use crate::{
error::ContractError,
Expand Down Expand Up @@ -243,7 +243,7 @@ pub fn update(
};

// Check if amount is greater or less than original amount
let old_amount = bounty.amount;
let old_amount = bounty.amount.clone();
match new_amount.amount.cmp(&old_amount.amount) {
Ordering::Greater => {
// If new amount is greater, check funds sent plus
Expand All @@ -259,7 +259,9 @@ pub fn update(
}
Ordering::Less => {
// If new amount is less, pay out difference to owner
let diff = old_amount.amount - new_amount.amount;
// in case owner accidentally sent funds, send back as well
let funds_send = may_pay(&info, &bounty.amount.denom)?;
let diff = old_amount.amount - new_amount.amount + funds_send;
let msg = BankMsg::Send {
to_address: info.sender.to_string(),
amount: vec![Coin {
Expand Down
Loading

0 comments on commit 1ab952c

Please sign in to comment.