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 #1747

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ and this project adheres to

## [Unreleased]

- cosmwasm-std: Add `DistributionMsg::FundCommunityPool` ([#1747])

### Added

- cosmwasm-std: Implement `BankQuery::AllDenomMetadata` to allow querying all
Expand Down
45 changes: 45 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 {
fragwuerdig marked this conversation as resolved.
Show resolved Hide resolved
/// 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 @@ -462,6 +469,44 @@ mod tests {
);
}
}

#[test]
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() {
Expand Down