Skip to content

Commit

Permalink
Merge pull request #1752 from CosmWasm/add-fund-cp-simon
Browse files Browse the repository at this point in the history
Add FundCommunityPool to supported Distribution Msgs (Simon)
  • Loading branch information
webmaster128 committed Jun 28, 2023
2 parents 732710a + f588694 commit c91b410
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ and this project adheres to
([#1647])
- cosmwasm-std: Add `DistributionQuery::DelegatorWithdrawAddress`. Also needs
the `cosmwasm_1_3` feature (see above). ([#1593])
- cosmwasm-std: Add `DistributionMsg::FundCommunityPool`. Also needs the
`cosmwasm_1_3` feature (see above). ([#1747])
- cosmwasm-std: Add `FromStr` impl for `Coin`. ([#1684])
- cosmwasm-std: Add `Coins` helper to handle multiple coins. ([#1687])
- cosmwasm-vm: Add `Cache::save_wasm_unchecked` to save Wasm blobs that have
Expand All @@ -33,6 +35,7 @@ and this project adheres to
[#1684]: https://github.com/CosmWasm/cosmwasm/pull/1684
[#1687]: https://github.com/CosmWasm/cosmwasm/pull/1687
[#1727]: https://github.com/CosmWasm/cosmwasm/issues/1727
[#1747]: https://github.com/CosmWasm/cosmwasm/pull/1747
[#1748]: https://github.com/CosmWasm/cosmwasm/pull/1748

### Changed
Expand Down
8 changes: 4 additions & 4 deletions docs/CAPABILITIES-BUILT-IN.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ might define others.
CosmWasm `1.1.0` or higher support this.
- `cosmwasm_1_2` enables the `GovMsg::VoteWeighted` and `WasmMsg::Instantiate2`
messages. Only chains running CosmWasm `1.2.0` or higher support this.
- `cosmwasm_1_3` enables the `BankQuery::AllDenomMetadata` and
`BankQuery::DenomMetadata` queries, as well as
`DistributionQuery::DelegatorWithdrawAddress`. Only chains running CosmWasm
`1.3.0` or higher support this.
- `cosmwasm_1_3` enables the `BankQuery::AllDenomMetadata`,
`BankQuery::DenomMetadata` and `DistributionQuery::DelegatorWithdrawAddress`
queries, as well as `DistributionMsg::FundCommunityPool`. Only chains running
CosmWasm `1.3.0` or higher support this.
40 changes: 40 additions & 0 deletions packages/std/src/results/cosmos_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ pub enum DistributionMsg {
/// The `validator_address`
validator: String,
},
/// This is translated to a [[MsgFundCommunityPool](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#LL69C1-L76C2).
/// `depositor` is automatically filled with the current contract's address.
#[cfg(feature = "cosmwasm_1_3")]
FundCommunityPool {
/// The amount to spend
amount: Vec<Coin>,
},
}

fn binary_to_string(data: &Binary, fmt: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
Expand Down Expand Up @@ -463,6 +470,39 @@ mod tests {
}
}

#[test]
#[cfg(feature = "cosmwasm_1_3")]
fn msg_distribution_serializes_to_correct_json() {
// FundCommunityPool
let fund_coins = vec![coin(200, "feathers"), coin(200, "stones")];
let fund_msg = DistributionMsg::FundCommunityPool { amount: fund_coins };
let fund_json = to_binary(&fund_msg).unwrap();
assert_eq!(
String::from_utf8_lossy(&fund_json),
r#"{"fund_community_pool":{"amount":[{"denom":"feathers","amount":"200"},{"denom":"stones","amount":"200"}]}}"#,
);

// SetWithdrawAddress
let set_msg = DistributionMsg::SetWithdrawAddress {
address: String::from("withdrawer"),
};
let set_json = to_binary(&set_msg).unwrap();
assert_eq!(
String::from_utf8_lossy(&set_json),
r#"{"set_withdraw_address":{"address":"withdrawer"}}"#,
);

// WithdrawDelegatorRewards
let withdraw_msg = DistributionMsg::WithdrawDelegatorReward {
validator: String::from("fancyoperator"),
};
let withdraw_json = to_binary(&withdraw_msg).unwrap();
assert_eq!(
String::from_utf8_lossy(&withdraw_json),
r#"{"withdraw_delegator_reward":{"validator":"fancyoperator"}}"#
);
}

#[test]
fn wasm_msg_debug_decodes_binary_string_when_possible() {
#[cosmwasm_schema::cw_serde]
Expand Down

0 comments on commit c91b410

Please sign in to comment.