Skip to content

Commit

Permalink
Add (failing) valset update test
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Aug 23, 2023
1 parent 2b6726a commit c0a0083
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
2 changes: 2 additions & 0 deletions contracts/consumer/virtual-staking/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub struct VirtualStakingContract<'a> {
#[contract]

Check failure on line 44 in contracts/consumer/virtual-staking/src/contract.rs

View workflow job for this annotation

GitHub Actions / Test Suite

mismatched types

Check failure on line 44 in contracts/consumer/virtual-staking/src/contract.rs

View workflow job for this annotation

GitHub Actions / Test Suite

mismatched types

Check failure on line 44 in contracts/consumer/virtual-staking/src/contract.rs

View workflow job for this annotation

GitHub Actions / Lints

mismatched types

Check failure on line 44 in contracts/consumer/virtual-staking/src/contract.rs

View workflow job for this annotation

GitHub Actions / Lints

mismatched types
#[error(ContractError)]
#[messages(virtual_staking_api as VirtualStakingApi)]
#[sv::override_entry_point(sudo=crate::contract::sudo(SudoMsg))]
impl VirtualStakingContract<'_> {
pub const fn new() -> Self {
Self {
Expand Down Expand Up @@ -285,6 +286,7 @@ fn withdraw_reward_msgs<T: CustomQuery>(

#[contract]
#[messages(virtual_staking_api as VirtualStakingApi)]
#[sv::override_entry_point(sudo=crate::contract::sudo(SudoMsg))]
impl VirtualStakingApi for VirtualStakingContract<'_> {
type Error = ContractError;

Expand Down
60 changes: 59 additions & 1 deletion contracts/consumer/virtual-staking/src/multitest.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cosmwasm_std::{Addr, Decimal};
use cosmwasm_std::{Addr, Decimal, Validator};
use cw_multi_test::App as MtApp;
use mesh_apis::virtual_staking_api::SudoMsg;
use sylvia::multitest::App;

use crate::contract;
Expand Down Expand Up @@ -106,3 +107,60 @@ fn instantiation() {
let vs_config = virtual_staking.config().unwrap();
assert_eq!(vs_config.converter, converter.contract_addr.to_string());
}

#[test]
fn valset_update_sudo() {
let app = App::default();

let owner = "sunny"; // Owner of the staking contract (i. e. the vault contract)
let admin = "theman";
let discount = Decimal::percent(40); // 1 OSMO worth of JUNO should give 0.6 OSMO of stake
let native_per_foreign = Decimal::percent(50); // 1 JUNO is worth 0.5 OSMO

let SetupResponse {
price_feed: _,
converter: _,
virtual_staking,
} = setup(
&app,
SetupArgs {
owner,
admin,
discount,
native_per_foreign,
},
);

// Send a valset update sudo message
let adds = vec![
Validator {
address: "cosmosval3".to_string(),
commission: Decimal::percent(3),
max_commission: Decimal::percent(30),
max_change_rate: Default::default(),
},
Validator {
address: "cosmosval1".to_string(),
commission: Decimal::percent(1),
max_commission: Decimal::percent(10),
max_change_rate: Default::default(),
},
];
let rems = vec![Validator {
address: "cosmosval2".to_string(),
commission: Decimal::percent(2),
max_commission: Decimal::percent(20),
max_change_rate: Default::default(),
}];
let msg = SudoMsg::ValsetUpdate {
additions: adds,
removals: rems,
};

let res = app
.app_mut()
.wasm_sudo(virtual_staking.contract_addr, &msg)
.unwrap();

println!("res: {:?}", res);
}

0 comments on commit c0a0083

Please sign in to comment.