Skip to content

Commit

Permalink
Add a test for donate and withdraw from funding pool
Browse files Browse the repository at this point in the history
  • Loading branch information
ismellike committed Apr 28, 2024
1 parent 92a3f32 commit 76f48e7
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
42 changes: 41 additions & 1 deletion contracts/external/cw-abc/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ mod tests {
}

#[test]
fn should_donation_with_forwarding() -> Result<(), ContractError> {
fn should_donate_to_forwarding() -> Result<(), ContractError> {
let mut deps = mock_dependencies();
// this matches `linear_curve` test case from curves.rs
let curve_type = CurveType::SquareRoot {
Expand All @@ -680,6 +680,46 @@ mod tests {
Ok(())
}

#[test]
fn test_donate_and_withdraw() -> Result<(), ContractError> {
// Init
let mut deps = mock_dependencies();

let curve_type = CurveType::SquareRoot {
slope: Uint128::new(1),
scale: 1,
};
let init_msg = default_instantiate_msg(2, 8, curve_type);
mock_init(deps.as_mut(), init_msg)?;

// Donate
let donation_amount = 5;
let _res = exec_donate(deps.as_mut(), donation_amount)?;

// Check funding pool
let curve_state = CURVE_STATE.load(&deps.storage)?;
assert_that!(curve_state.funding).is_equal_to(Uint128::from(donation_amount));

// Check random can't withdraw from the funding pool
let result = withdraw(deps.as_mut(), mock_env(), mock_info("random", &[]), None);
assert_that!(result)
.is_err()
.is_equal_to(ContractError::Ownership(
cw_ownable::OwnershipError::NotOwner,
));

// Check owner can withdraw
let result = withdraw(
deps.as_mut(),
mock_env(),
mock_info(crate::testing::TEST_CREATOR, &[]),
None,
);
assert!(result.is_ok());

Ok(())
}

#[test]
fn test_pause() -> Result<(), ContractError> {
let mut deps = mock_dependencies();
Expand Down
2 changes: 1 addition & 1 deletion contracts/proposal/dao-proposal-single/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct InstantiateMsg {
/// The minimum amount of time a proposal must be open before
/// passing. A proposal may fail before this amount of time has
/// elapsed, but it will not pass. This can be useful for
/// preventing governance attacks wherein an attacker aquires a
/// preventing governance attacks wherein an attacker acquires a
/// large number of tokens and forces a proposal through.
pub min_voting_period: Option<Duration>,
/// If set to true only members may execute passed
Expand Down
8 changes: 4 additions & 4 deletions contracts/proposal/dao-proposal-single/src/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl SingleChoiceProposal {
// and there are possible votes, then this is
// rejected if there is a single no vote.
//
// We need this check becuase otherwise when
// We need this check because otherwise when
// we invert the threshold (`Decimal::one() -
// threshold`) we get a 0% requirement for no
// votes. Zero no votes do indeed meet a 0%
Expand Down Expand Up @@ -217,7 +217,7 @@ impl SingleChoiceProposal {
// and there are possible votes, then this is
// rejected if there is a single no vote.
//
// We need this check becuase
// We need this check because
// otherwise when we invert the
// threshold (`Decimal::one() -
// threshold`) we get a 0% requirement
Expand Down Expand Up @@ -954,7 +954,7 @@ mod test {
));
// Total power of 33. 13 total votes. 8 no votes, 3 yes, 2
// abstain. 39.3% turnout. Expired. As it is expired we see if
// the 8 no votes excede the 50% failing threshold, which they
// the 8 no votes exceed the 50% failing threshold, which they
// do.
assert!(check_is_rejected(
quorum.clone(),
Expand All @@ -980,7 +980,7 @@ mod test {
// Over quorum, but under threshold fails if the proposal is
// not expired. If the proposal is expired though it passes as
// the total vote count used is the number of votes, and not
// the total number of votes avaliable.
// the total number of votes available.
assert!(check_is_rejected(
quorum.clone(),
failing.clone(),
Expand Down
2 changes: 1 addition & 1 deletion packages/cw-paginate-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ where
}

/// Same as `paginate_map` but only returns the keys. For use with
/// `SnaphotMap`.
/// `SnapshotMap`.
pub fn paginate_snapshot_map_keys<'a, 'b, K, V, R: 'static>(
deps: Deps,
map: &SnapshotMap<'a, K, V>,
Expand Down
4 changes: 2 additions & 2 deletions packages/dao-voting/src/voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ impl Votes {

/// Computes the total number of votes cast.
///
/// NOTE: The total number of votes avaliable from a voting module
/// NOTE: The total number of votes available from a voting module
/// is a `Uint128`. As it is not possible to vote twice we know
/// that the sum of votes must be <= 2^128 and can safely return a
/// `Uint128` from this function. A missbehaving voting power
/// `Uint128` from this function. A misbehaving voting power
/// module may break this invariant.
pub fn total(&self) -> Uint128 {
self.yes + self.no + self.abstain
Expand Down

0 comments on commit 76f48e7

Please sign in to comment.