Skip to content

Commit

Permalink
clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberHoward committed May 30, 2024
1 parent 09dac0b commit 8e3633c
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 62 deletions.
28 changes: 12 additions & 16 deletions contracts/interchain-gov/src/handlers/execute.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
use abstract_adapter::objects::chain_name::ChainName;
use abstract_adapter::objects::module::ModuleInfo;
use abstract_adapter::sdk::{AbstractSdkResult, Execution, IbcInterface, TransferInterface};
use abstract_adapter::sdk::{AbstractSdkResult, IbcInterface};
use abstract_adapter::std::ibc::CallbackInfo;
use abstract_adapter::std::AbstractResult;
use abstract_adapter::traits::AbstractResponse;
use abstract_adapter::traits::ModuleIdentification;
use base64::Engine;
use cosmwasm_std::{
coins, to_json_binary, CosmosMsg, DepsMut, Env, MessageInfo, Order, StdResult, Storage, SubMsg,
WasmQuery,
to_json_binary, CosmosMsg, DepsMut, Env, MessageInfo, Order, StdResult, Storage, WasmQuery,
};

use ibc_sync_state::DataState;
use neutron_query::gov::create_gov_proposal_keys;
use neutron_query::icq::IcqInterface;
use neutron_query::QueryType;

use crate::ibc_callbacks::{FINALIZE_CALLBACK_ID, PROPOSE_CALLBACK_ID, REGISTER_VOTE_ID};
use crate::msg::InterchainGovQueryMsg;
use crate::msg::{InterchainGovIbcCallbackMsg, InterchainGovIbcMsg};
use crate::state::{
Governance, GovernanceVote, Members, Proposal, ProposalAction, ProposalId, ProposalMsg,
ProposalOutcome, TallyResult, Vote, ALLOW_JOINING_GOV, FINALIZED_PROPOSALS, GOV_VOTE_QUERIES,
MEMBERS, MEMBERS_STATE_SYNC, PENDING_REPLIES, PROPOSAL_STATE_SYNC,
TEMP_REMOTE_GOV_MODULE_ADDRS, VOTE, VOTE_RESULTS,
MEMBERS, MEMBERS_STATE_SYNC, PROPOSAL_STATE_SYNC, TEMP_REMOTE_GOV_MODULE_ADDRS, VOTE,
VOTE_RESULTS,
};
use crate::{
contract::{AdapterResult, InterchainGov},
Expand Down Expand Up @@ -197,7 +193,7 @@ fn execute_prop(
let ibc_client = app.ibc_client(deps.as_ref());
let exec_msg = InterchainGovIbcMsg::ProposalResult {
prop_hash: prop_id.clone(),
outcome: outcome,
outcome,
};
let mut msgs = vec![];
let target_module = this_module(&app)?;
Expand All @@ -218,11 +214,11 @@ fn execute_prop(
Some(callback.clone()),
)?);
}
return Ok(app
Ok(app
.response("propose_members")
.add_messages(msgs)
.add_messages(new_member_msgs)
.add_attribute("prop_id", prop_id));
.add_attribute("prop_id", prop_id))
}

/// Reach out to external members and request their local vote results
Expand All @@ -232,7 +228,7 @@ fn request_vote_results(
app: InterchainGov,
prop_id: ProposalId,
) -> AdapterResult {
let (prop, state) = load_proposal(deps.storage, &prop_id)?;
let (prop, _state) = load_proposal(deps.storage, &prop_id)?;

// We can only tally upon expiration
if !prop.expiration.is_expired(&env.block) {
Expand Down Expand Up @@ -304,7 +300,7 @@ fn request_vote_results(
/// REuest external members actual governance vote details
fn request_gov_vote_details(
deps: DepsMut,
env: Env,
_env: Env,
app: InterchainGov,
prop_id: ProposalId,
) -> AdapterResult {
Expand Down Expand Up @@ -385,9 +381,9 @@ fn request_gov_vote_details(
}

fn check_existing_votes<E: FnOnce() -> AdapterResult<()>>(
deps: &DepsMut,
prop_id: &ProposalId,
has_all_votes_handler: E,
_deps: &DepsMut,
_prop_id: &ProposalId,
_has_all_votes_handler: E,
) -> AdapterResult<()> {
// First, make sure that all votes are in by checking whether we have vote results

Expand Down
10 changes: 7 additions & 3 deletions contracts/interchain-gov/src/handlers/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use abstract_adapter::objects::chain_name::ChainName;
use crate::msg::{
MembersResponse, ProposalResponse, ProposalsResponse, VoteResponse, VoteResultsResponse,
};
use crate::state::{GovernanceVote, ProposalId, MEMBERS, VOTE, VOTE_RESULTS};
use crate::state::{GovernanceVote, ProposalId, VOTE, VOTE_RESULTS};
use cosmwasm_std::{to_json_binary, Binary, Deps, Env, Order, StdResult};
use ibc_sync_state::DataState;

Expand Down Expand Up @@ -47,7 +47,7 @@ fn query_proposals(deps: Deps, proposal_ids: Vec<String>) -> AdapterResult<Propo
let data_state = PROPOSAL_STATE_SYNC.data_state(deps.storage, proposal_id.clone());
proposals.push(ProposalResponse {
prop_id: proposal_id,
prop: prop,
prop,
state: data_state,
})
}
Expand Down Expand Up @@ -151,7 +151,11 @@ fn query_vote(deps: Deps, env: Env, prop_id: ProposalId) -> StdResult<VoteRespon
})
}

fn query_vote_results(deps: Deps, env: Env, prop_id: ProposalId) -> StdResult<VoteResultsResponse> {
fn query_vote_results(
deps: Deps,
_env: Env,
prop_id: ProposalId,
) -> StdResult<VoteResultsResponse> {
let results = VOTE_RESULTS
.prefix(prop_id.clone())
.range(deps.storage, None, None, Order::Ascending)
Expand Down
18 changes: 6 additions & 12 deletions contracts/interchain-gov/src/handlers/sudo.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
use abstract_adapter::sdk::AbstractResponse;
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{
to_json_binary, Binary, DepsMut, Env, MessageInfo, Order, StdError, StdResult, Storage, Uint128,
};
use cw_storage_plus::Item;

use cosmwasm_std::{Binary, DepsMut, Env, StdError, Storage};

use neutron_query::icq::IcqInterface;
use serde::de::DeserializeOwned;
use serde::Serialize;

use crate::msg::InterchainGovSudoMsg;
use crate::state::{StorageKey, TallyResult, GOV_VOTE_QUERIES, PENDING_QUERIES};
use crate::state::{TallyResult, GOV_VOTE_QUERIES, PENDING_QUERIES};
use crate::{
contract::{AdapterResult, InterchainGov},
msg::InterchainGovInstantiateMsg,
state::{Members, MEMBERS},
InterchainGovError,
};

pub fn sudo_handler(
deps: DepsMut,
env: Env,
_env: Env,
app: InterchainGov,
msg: InterchainGovSudoMsg,
) -> AdapterResult {
Expand Down Expand Up @@ -53,7 +47,7 @@ pub fn sudo_handler(

// check the first proposal
let prop = gov_props.proposals.first();
if let Some(prop) = prop.clone() {
if let Some(prop) = prop {
if prop.final_tally_result.is_none() {
return Err(StdError::generic_err("No final tally result found").into());
};
Expand Down
15 changes: 9 additions & 6 deletions contracts/interchain-gov/src/ibc_callbacks/vote_result.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use abstract_adapter::sdk::AbstractResponse;
use abstract_adapter::std::ibc::{CallbackResult, IbcResponseMsg};
use cosmwasm_std::{from_json, to_json_string, DepsMut, Env, MessageInfo, QueryRequest, WasmQuery};
use cosmwasm_std::{from_json, DepsMut, Env, MessageInfo, QueryRequest, WasmQuery};

use crate::contract::{AdapterResult, InterchainGov};
use crate::msg::{InterchainGovQueryMsg, QueryMsg, VoteResponse};
Expand All @@ -12,7 +12,7 @@ use crate::InterchainGovError;
pub fn vote_result_callback(
deps: DepsMut,
_env: Env,
info: MessageInfo,
_info: MessageInfo,
app: InterchainGov,
ibc_msg: IbcResponseMsg,
) -> AdapterResult {
Expand All @@ -29,7 +29,10 @@ pub fn vote_result_callback(
// Retrieve the prop id from the original message
let prop_id = match query {
QueryRequest::Wasm(wasm) => match wasm {
WasmQuery::Smart { contract_addr, msg } => {
WasmQuery::Smart {
contract_addr: _,
msg,
} => {
let msg: QueryMsg = from_json(msg)?;
match msg {
QueryMsg::Module(InterchainGovQueryMsg::Vote { prop_id }) => prop_id,
Expand Down Expand Up @@ -57,7 +60,7 @@ pub fn vote_result_callback(
|prev_res| -> Result<Option<GovernanceVote>, InterchainGovError> {
match prev_res {
Some(prev) => match prev {
Some(prev) => Err(InterchainGovError::ExistingVoteResult {
Some(_prev) => Err(InterchainGovError::ExistingVoteResult {
prop_id: prop_id.clone(),
chain: chain.clone(),
}),
Expand All @@ -78,8 +81,8 @@ pub fn vote_result_callback(
)?;
}
CallbackResult::Execute {
initiator_msg,
result,
initiator_msg: _,
result: _,
} => {
unreachable!("vote_result Execute callback")
}
Expand Down
6 changes: 2 additions & 4 deletions contracts/interchain-gov/src/replies/icq.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use crate::contract::{AdapterResult, InterchainGov};
use crate::state::{PENDING_QUERIES, PENDING_REPLIES};
use crate::InterchainGovError;

use abstract_adapter::sdk::AbstractResponse;
use cosmwasm_std::{
from_json, DepsMut, Env, Reply, StdError, StdResult, SubMsgResponse, SubMsgResult,
};
use cosmwasm_std::{from_json, DepsMut, Env, Reply, StdError, StdResult, SubMsgResult};
use neutron_query::neutron_sdk::bindings::msg::MsgRegisterInterchainQueryResponse;

pub fn icq_reply(deps: DepsMut, _env: Env, app: InterchainGov, reply: Reply) -> AdapterResult {
Expand Down
8 changes: 4 additions & 4 deletions contracts/interchain-gov/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt::Display;
use abstract_adapter::objects::chain_name::ChainName;
use base64::Engine;
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, Binary, Decimal, Env, Uint128};
use cosmwasm_std::{Addr, Decimal, Env, Uint128};
use cw_storage_plus::{Item, Map};
use cw_utils::Expiration;
use dao_voting::threshold::{PercentageThreshold, Threshold};
Expand All @@ -25,7 +25,7 @@ pub type Key = String;
// pub const PROPOSAL_STATE: Map<(ProposalId, ChainName), DataState> = Map::new("prop_state");

pub const MEMBERS_KEY: &'static str = "members";
pub const MEMBERS_KEY: &str = "members";
pub const MEMBERS: Item<Members> = Item::new(MEMBERS_KEY);
pub const MEMBERS_STATE_SYNC: MembersSyncState = MembersSyncState::new();
pub const OUTSTANDING_ACKS: Item<Vec<ChainName>> = Item::new("acks");
Expand Down Expand Up @@ -96,7 +96,7 @@ pub mod members_sync_state {
env: &Env,
) -> SyncStateResult<Members> {
let mut members = self.load_members(storage)?;
members.members.retain(|m| m != &ChainName::new(&env));
members.members.retain(|m| m != &ChainName::new(env));
Ok(members)
}

Expand Down Expand Up @@ -170,7 +170,7 @@ pub mod members_sync_state {
(members, true)
} else {
let members: Result<Members, _> = match self.load_state_change(storage)? {
StateChange::Proposal(members) => Ok(from_json(&members)?),
StateChange::Proposal(members) => Ok(from_json(members)?),
_ => Err(SyncStateError::DataNotFinalized {
key: MEMBERS_KEY.to_string(),
state: "Backup".to_string(),
Expand Down
14 changes: 6 additions & 8 deletions contracts/interchain-gov/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::str::FromStr;

use abstract_adapter::objects::chain_name::ChainName;
use ibc_sync_state::DataState;
use interchain_gov::{
Expand All @@ -10,7 +8,7 @@ use interchain_gov::{
};

use abstract_adapter::std::manager::ExecuteMsgFns;
use abstract_adapter::std::{adapter, adapter::AdapterRequestMsg, objects::namespace::Namespace};
use abstract_adapter::std::{adapter, objects::namespace::Namespace};
use abstract_client::{AbstractClient, Account, Application, Environment, Publisher};
use abstract_cw_orch_polytone::Polytone;
// Use prelude to get all the necessary imports
Expand All @@ -22,7 +20,7 @@ use cw_orch::{anyhow, prelude::*};
use speculoos::prelude::*;

use abstract_interchain_tests::setup::ibc_connect_polytone_and_abstract;
use cw_orch::mock::cw_multi_test::AppResponse;

use cw_orch::tokio::runtime::Runtime;
use cw_utils::Expiration;
use interchain_gov::state::{ProposalAction, ProposalId, ProposalMsg};
Expand Down Expand Up @@ -358,7 +356,7 @@ mod query_vote_results {
prop_id: prop_id.clone(),
})?;

let analysis = interchain.wait_ibc(A_CHAIN_ID, res)?;
let _analysis = interchain.wait_ibc(A_CHAIN_ID, res)?;

let vote_results = a_gov.vote_results(prop_id.clone())?;
println!("Vote results: {:?}", vote_results);
Expand Down Expand Up @@ -428,8 +426,8 @@ fn starship_test() -> anyhow::Result<()> {
b_env.enable_ibc()?;
ibc_connect_polytone_and_abstract(&interchain, A_CHAIN_ID, B_CHAIN_ID)?;

let a_gov = a_env.gov.clone();
let b_gov = b_env.gov.clone();
let _a_gov = a_env.gov.clone();
let _b_gov = b_env.gov.clone();

a_env.execute_gov(InterchainGovExecuteMsg::TestAddMembers {
members: vec![b_env.chain_name()].into(),
Expand All @@ -448,7 +446,7 @@ fn starship_test() -> anyhow::Result<()> {

// Finalize a proposal
let res = a_env.finalize_proposal(prop_id.clone())?;
let analysis = interchain.wait_ibc(A_CHAIN_ID, res)?;
let _analysis = interchain.wait_ibc(A_CHAIN_ID, res)?;

a_env.assert_prop_state(prop_id.clone(), None)?;
b_env.assert_prop_state(prop_id, None)?;
Expand Down
6 changes: 3 additions & 3 deletions packages/ibc-sync-state/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ impl ItemStateSyncController {
) -> SyncStateResult<()> {
let key = key.into();
// remove any of the states
if let Some(change) = self
if let Some(_change) = self
.state_status_map
.may_load(storage, (key.clone(), DataState::Initiated.to_num()))?
{
self.state_status_map
.remove(storage, (key.clone(), DataState::Initiated.to_num()));
return Ok(());
} else if let Some(change) = self
Ok(())
} else if let Some(_change) = self
.state_status_map
.may_load(storage, (key.clone(), DataState::Proposed.to_num()))?
{
Expand Down
8 changes: 2 additions & 6 deletions packages/ibc-sync-state/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,7 @@ where

self.state_status_map.save(
storage,
(
self.storage_key(),
key.into(),
DataState::Initiated.to_num(),
),
(self.storage_key(), key, DataState::Initiated.to_num()),
&StateChange::Proposal(to_json_binary(&initiated_value)?),
)?;
self.outstanding_acks.save(storage, &outstanding_acks)?;
Expand Down Expand Up @@ -236,7 +232,7 @@ where
(value, true)
} else {
let value: Result<V, _> = match self.load_state_change(storage, k.clone())? {
StateChange::Proposal(value) => Ok(from_json(&value)?),
StateChange::Proposal(value) => Ok(from_json(value)?),
_ => Err(SyncStateError::DataNotFinalized {
key: k.to_string(),
state: "Backup".to_string(),
Expand Down

0 comments on commit 8e3633c

Please sign in to comment.