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

deps: bumped to CosmWasm v1.3+ #46

Merged
merged 9 commits into from
Jan 23, 2024
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ optimize = """docker run --rm -v "$(pwd)":/code \
[dependencies]
cosmwasm-schema = "1.5.0"
cosmwasm-std = { version = "1.5.0", features = [
"cosmwasm_1_2",
"cosmwasm_1_3",
# Enable this if you only deploy to chains that have CosmWasm 1.4 or higher
# "cosmwasm_1_4",
"stargate",
Expand Down
19 changes: 16 additions & 3 deletions e2e/interchaintest/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ func (s *ContractTestSuite) TestSendCosmosMsgsProtobufEncoding() {
// - Bank::Send
// - Stargate
// - VoteWeighted
// - FundCommunityPool
// - SetWithdrawAddress
func (s *ContractTestSuite) SendCosmosMsgsTestWithEncoding(encoding string) {
ctx := context.Background()
Expand Down Expand Up @@ -661,7 +662,7 @@ func (s *ContractTestSuite) SendCosmosMsgsTestWithEncoding(encoding string) {
s.Require().Equal(initialBalance.Sub(sdkmath.NewInt(10_000_000+5_000)), postBalance)
})

s.Run(fmt.Sprintf("TestDelegateAndVoteWeighted-%s", encoding), func() {
s.Run(fmt.Sprintf("TestDelegateAndVoteWeightedAndCommunityPool-%s", encoding), func() {
intialBalance, err := simd.GetBalance(ctx, s.IcaAddress, simd.Config().Denom)
s.Require().NoError(err)

Expand Down Expand Up @@ -699,10 +700,22 @@ func (s *ContractTestSuite) SendCosmosMsgsTestWithEncoding(encoding string) {
},
}

// Fund the community pool through CosmosMsgs:
fundPoolCosmosMsg := icacontroller.ContractCosmosMsg{
Distribution: &icacontroller.DistributionCosmosMsg{
FundCommunityPool: &icacontroller.DistributionFundCommunityPoolCosmosMsg{
Amount: []icacontroller.Coin{{
Denom: simd.Config().Denom,
Amount: "10000000",
}},
},
},
}

// Execute the contract:
sendCosmosMsgsExecMsg := icacontroller.ExecuteMsg{
SendCosmosMsgs: &icacontroller.ExecuteMsg_SendCosmosMsgs{
Messages: []icacontroller.ContractCosmosMsg{stakeCosmosMsg, voteCosmosMsg},
Messages: []icacontroller.ContractCosmosMsg{stakeCosmosMsg, voteCosmosMsg, fundPoolCosmosMsg},
},
}
err = s.Contract.Execute(ctx, wasmdUser.KeyName(), sendCosmosMsgsExecMsg)
Expand All @@ -720,7 +733,7 @@ func (s *ContractTestSuite) SendCosmosMsgsTestWithEncoding(encoding string) {
// Check if the delegation was successful:
postBalance, err := simd.GetBalance(ctx, s.IcaAddress, simd.Config().Denom)
s.Require().NoError(err)
s.Require().Equal(intialBalance.Sub(sdkmath.NewInt(10_000_000)), postBalance)
s.Require().Equal(intialBalance.Sub(sdkmath.NewInt(20_000_000)), postBalance)

delegationsQuerier := mysuite.NewGRPCQuerier[stakingtypes.QueryDelegationResponse](s.T(), simd, "/cosmos.staking.v1beta1.Query/Delegation")

Expand Down
122 changes: 72 additions & 50 deletions src/types/cosmos_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use cosmwasm_std::{BankMsg, Coin, CosmosMsg, IbcMsg};
/// - [`CosmosMsg::Staking`] with [`cosmwasm_std::StakingMsg::Redelegate`]
/// - [`CosmosMsg::Distribution`] with [`cosmwasm_std::DistributionMsg::WithdrawDelegatorReward`]
/// - [`CosmosMsg::Distribution`] with [`cosmwasm_std::DistributionMsg::SetWithdrawAddress`]
/// - [`CosmosMsg::Distribution`] with [`cosmwasm_std::DistributionMsg::FundCommunityPool`]
pub fn convert_to_proto_any(msg: CosmosMsg, from_address: String) -> Result<Any, EncodeError> {
match msg {
CosmosMsg::Stargate { type_url, value } => Ok(Any {
Expand Down Expand Up @@ -268,66 +269,73 @@ mod convert_to_any {

#[cfg(feature = "staking")]
pub fn staking(msg: StakingMsg, delegator_address: String) -> Result<Any, EncodeError> {
use cosmos_sdk_proto::cosmos::staking::v1beta1::{
MsgBeginRedelegate, MsgDelegate, MsgUndelegate,
};

match msg {
StakingMsg::Delegate { validator, amount } => Any::from_msg(&MsgDelegate {
delegator_address,
validator_address: validator,
amount: Some(ProtoCoin {
denom: amount.denom,
amount: amount.amount.to_string(),
}),
}),
StakingMsg::Undelegate { validator, amount } => Any::from_msg(&MsgUndelegate {
delegator_address,
validator_address: validator,
amount: Some(ProtoCoin {
denom: amount.denom,
amount: amount.amount.to_string(),
}),
}),
StakingMsg::Delegate { validator, amount } => {
Any::from_msg(&cosmos_sdk_proto::cosmos::staking::v1beta1::MsgDelegate {
delegator_address,
validator_address: validator,
amount: Some(ProtoCoin {
denom: amount.denom,
amount: amount.amount.to_string(),
}),
})
}
StakingMsg::Undelegate { validator, amount } => {
Any::from_msg(&cosmos_sdk_proto::cosmos::staking::v1beta1::MsgUndelegate {
delegator_address,
validator_address: validator,
amount: Some(ProtoCoin {
denom: amount.denom,
amount: amount.amount.to_string(),
}),
})
}
StakingMsg::Redelegate {
src_validator,
dst_validator,
amount,
} => Any::from_msg(&MsgBeginRedelegate {
delegator_address,
validator_src_address: src_validator,
validator_dst_address: dst_validator,
amount: Some(ProtoCoin {
denom: amount.denom,
amount: amount.amount.to_string(),
}),
}),
} => Any::from_msg(
&cosmos_sdk_proto::cosmos::staking::v1beta1::MsgBeginRedelegate {
delegator_address,
validator_src_address: src_validator,
validator_dst_address: dst_validator,
amount: Some(ProtoCoin {
denom: amount.denom,
amount: amount.amount.to_string(),
}),
},
),
_ => panic!("Unsupported StakingMsg"),
}
}

#[cfg(feature = "staking")]
pub fn distribution(
msg: DistributionMsg,
delegator_address: String,
) -> Result<Any, EncodeError> {
use cosmos_sdk_proto::cosmos::distribution::v1beta1::{
MsgSetWithdrawAddress, MsgWithdrawDelegatorReward,
};

pub fn distribution(msg: DistributionMsg, sender: String) -> Result<Any, EncodeError> {
match msg {
DistributionMsg::WithdrawDelegatorReward { validator } => {
Any::from_msg(&MsgWithdrawDelegatorReward {
delegator_address,
DistributionMsg::WithdrawDelegatorReward { validator } => Any::from_msg(
&cosmos_sdk_proto::cosmos::distribution::v1beta1::MsgWithdrawDelegatorReward {
delegator_address: sender,
validator_address: validator,
})
}
DistributionMsg::SetWithdrawAddress { address } => {
Any::from_msg(&MsgSetWithdrawAddress {
delegator_address,
},
),
DistributionMsg::SetWithdrawAddress { address } => Any::from_msg(
&cosmos_sdk_proto::cosmos::distribution::v1beta1::MsgSetWithdrawAddress {
delegator_address: sender,
withdraw_address: address,
})
}
},
),
DistributionMsg::FundCommunityPool { amount } => Any::from_msg(
&cosmos_sdk_proto::cosmos::distribution::v1beta1::MsgFundCommunityPool {
depositor: sender,
amount: amount
.into_iter()
.map(|coin| ProtoCoin {
denom: coin.denom,
amount: coin.amount.to_string(),
})
.collect(),
},
),
_ => panic!("Unsupported DistributionMsg"),
}
}
Expand All @@ -351,6 +359,7 @@ mod convert_to_any {
/// - [`CosmosMsg::Staking`] with [`cosmwasm_std::StakingMsg::Redelegate`]
/// - [`CosmosMsg::Distribution`] with [`cosmwasm_std::DistributionMsg::WithdrawDelegatorReward`]
/// - [`CosmosMsg::Distribution`] with [`cosmwasm_std::DistributionMsg::SetWithdrawAddress`]
/// - [`CosmosMsg::Distribution`] with [`cosmwasm_std::DistributionMsg::FundCommunityPool`]
#[must_use]
pub fn convert_to_proto3json(msg: CosmosMsg, from_address: String) -> String {
match msg {
Expand Down Expand Up @@ -482,20 +491,26 @@ mod convert_to_json {
}

#[cfg(feature = "staking")]
pub fn distribution(msg: DistributionMsg, delegator_address: String) -> String {
pub fn distribution(msg: DistributionMsg, sender: String) -> String {
match msg {
DistributionMsg::WithdrawDelegatorReward { validator } => {
CosmosMsgProto3JsonSerializer::WithdrawDelegatorReward {
delegator_address,
delegator_address: sender,
validator_address: validator,
}
}
DistributionMsg::SetWithdrawAddress { address } => {
CosmosMsgProto3JsonSerializer::SetWithdrawAddress {
delegator_address,
delegator_address: sender,
withdraw_address: address,
}
}
DistributionMsg::FundCommunityPool { amount } => {
CosmosMsgProto3JsonSerializer::FundCommunityPool {
depositor: sender,
amount,
}
}
_ => panic!("Unsupported DistributionMsg"),
}
.to_string()
Expand Down Expand Up @@ -599,6 +614,13 @@ mod convert_to_json {
delegator_address: String,
withdraw_address: String,
},
/// This is a Cosmos message to fund the community pool.
#[cfg(feature = "staking")]
#[serde(rename = "/cosmos.distribution.v1beta1.MsgFundCommunityPool")]
FundCommunityPool {
depositor: String,
amount: Vec<Coin>,
},
}

/// This is a helper struct to serialize the `WeightedVoteOption` struct in [`CosmosMsgProto3JsonSerializer`].
Expand Down
Loading