Skip to content

Commit

Permalink
hotfix: pruning (#66)
Browse files Browse the repository at this point in the history
* add proposal payload maker

* fix & add tests
  • Loading branch information
byeongsu-hong authored Jan 23, 2024
1 parent d1f092c commit 60791e1
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
58 changes: 57 additions & 1 deletion contracts/core/src/execute/rebalance/finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn finalize(deps: DepsMut, env: Env, info: MessageInfo) -> StdResult<Respons
deps.storage,
&index_units
.into_iter()
.filter(|(_, current_unit)| current_unit.is_zero())
.filter(|(_, current_unit)| !current_unit.is_zero())
.collect::<Vec<_>>()
.into(),
)?;
Expand Down Expand Up @@ -232,4 +232,60 @@ mod tests {
.is_none());
}
}

#[rstest]
#[case(
"manager",
vec![("uatom", "0.0")].into(),
vec![("uatom", "0.0")].into(),
Some(Rebalance {
manager: Some(Addr::unchecked("manager")),
deflation: vec![("uatom", "0")].into(),
inflation: Units::default(),
}),
Units::default(),
)]
#[case(
"manager",
vec![("uatom", "0.89")].into(),
vec![("uatom", "0.0")].into(),
Some(Rebalance {
manager: Some(Addr::unchecked("manager")),
deflation: vec![("uatom", "0.90")].into(),
inflation: Units::default(),
}),
vec![("uatom", "0.89")].into(),
)]
fn test_pruning(
#[case] sender: &str,
#[case] index_units: Units,
#[case] reserve_units: Units,
#[case] rebalance: Option<Rebalance>,
#[case] after_index_units: Units,
) {
let env = mock_env();
let mut deps = mock_dependencies();

FEE.save(deps.as_mut().storage, &Fee::default()).unwrap();

INDEX_UNITS
.save(deps.as_mut().storage, &index_units)
.unwrap();

RESERVE_UNITS
.save(deps.as_mut().storage, &reserve_units)
.unwrap();

REBALANCE.remove(deps.as_mut().storage);
if let Some(rebalance) = rebalance {
REBALANCE.save(deps.as_mut().storage, &rebalance).unwrap();
}

finalize(deps.as_mut(), env.clone(), mock_info(sender, &[])).unwrap();

assert_eq!(
INDEX_UNITS.load(deps.as_ref().storage).unwrap(),
after_index_units
);
}
}
16 changes: 16 additions & 0 deletions integration-test/tests/proposal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use cosmwasm_std::{to_json_binary, CosmosMsg, WasmMsg};

use ibcx_interface::core;

#[test]
fn test_proposal() {
let msgs: Vec<CosmosMsg> = vec![WasmMsg::Migrate {
contract_addr: "osmo14klwqgkmackvx2tqa0trtg69dmy0nrg4ntq4gjgw2za4734r5seqjqm4gm"
.to_string(),
new_code_id: 455,
msg: to_json_binary(&core::MigrateMsg { force: None }).unwrap(),
}
.into()];

println!("{}", serde_json_wasm::to_string(&msgs).unwrap());
}

0 comments on commit 60791e1

Please sign in to comment.