Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FundCommunityPool to supported Distribution Msgs (Simon) #1752

Merged
merged 6 commits into from
Jun 28, 2023
Merged
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
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