-
Notifications
You must be signed in to change notification settings - Fork 1
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
Auto return stake in tg4 contract #124
Changes from all commits
5579d66
938cd51
39d1089
f56bfed
2d0ac50
743302e
8adc5ec
2816079
17f5c4f
1f2e414
53db3ef
e7d7621
683aa39
598676f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
#[cfg(not(feature = "library"))] | ||
use cosmwasm_std::entry_point; | ||
use cosmwasm_std::{ | ||
to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Order, Response, StdResult, SubMsg, | ||
}; | ||
use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Order, StdResult}; | ||
use cw0::maybe_addr; | ||
use cw2::set_contract_version; | ||
use cw_storage_plus::{Bound, PrimaryKey, U64Key}; | ||
|
@@ -14,6 +12,10 @@ use tg4::{ | |
use crate::error::ContractError; | ||
use crate::msg::{ExecuteMsg, InstantiateMsg, PreauthResponse, QueryMsg, SudoMsg}; | ||
use crate::state::{members, ADMIN, HOOKS, PREAUTH, TOTAL}; | ||
use tg_bindings::TgradeMsg; | ||
|
||
pub type Response = cosmwasm_std::Response<TgradeMsg>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need to use these types here. |
||
pub type SubMsg = cosmwasm_std::SubMsg<TgradeMsg>; | ||
|
||
// version info for migration info | ||
const CONTRACT_NAME: &str = "crates.io:tg4-group"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
#[cfg(not(feature = "library"))] | ||
use cosmwasm_std::entry_point; | ||
use cosmwasm_std::{ | ||
to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Order, Response, StdResult, SubMsg, | ||
}; | ||
use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Order, StdResult}; | ||
use cw0::maybe_addr; | ||
use cw2::set_contract_version; | ||
use cw_storage_plus::{Bound, PrimaryKey, U64Key}; | ||
use integer_sqrt::IntegerSquareRoot; | ||
use tg_bindings::TgradeMsg; | ||
|
||
use tg4::{ | ||
HooksResponse, Member, MemberChangedHookMsg, MemberDiff, MemberListResponse, MemberResponse, | ||
|
@@ -17,6 +16,9 @@ use crate::error::ContractError; | |
use crate::msg::{ExecuteMsg, GroupsResponse, InstantiateMsg, PreauthResponse, QueryMsg}; | ||
use crate::state::{members, Groups, GROUPS, HOOKS, PREAUTH, TOTAL}; | ||
|
||
pub type Response = cosmwasm_std::Response<TgradeMsg>; | ||
pub type SubMsg = cosmwasm_std::SubMsg<TgradeMsg>; | ||
|
||
// version info for migration info | ||
const CONTRACT_NAME: &str = "crates.io:tg4-mixer"; | ||
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); | ||
|
@@ -325,11 +327,11 @@ fn list_members_by_weight( | |
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use cosmwasm_std::testing::{mock_env, MockApi, MockStorage}; | ||
use cosmwasm_std::{coins, Addr, Empty, Uint128}; | ||
use cosmwasm_std::{coins, Addr, Uint128}; | ||
use cw20::Denom; | ||
use cw_multi_test::{next_block, App, BankKeeper, Contract, ContractWrapper, Executor}; | ||
use cw_multi_test::{next_block, App, AppBuilder, Contract, ContractWrapper, Executor}; | ||
use tg4_stake::state::Duration; | ||
use tg_bindings::TgradeMsg; | ||
|
||
const STAKE_DENOM: &str = "utgd"; | ||
const OWNER: &str = "owner"; | ||
|
@@ -346,7 +348,7 @@ mod tests { | |
} | ||
} | ||
|
||
pub fn contract_mixer() -> Box<dyn Contract<Empty>> { | ||
pub fn contract_mixer() -> Box<dyn Contract<TgradeMsg>> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to change the contracts to make the types match. There is I'd prefer this over artificially adding the Tgrade Response types to tg4-group and tg4-mixer. But yeah, in the multitest that uses them all (this file), we need to use adaptors so the App supports TgradeMsg (as I describe on the first line). |
||
let contract = ContractWrapper::new( | ||
crate::contract::execute, | ||
crate::contract::instantiate, | ||
|
@@ -355,7 +357,7 @@ mod tests { | |
Box::new(contract) | ||
} | ||
|
||
pub fn contract_group() -> Box<dyn Contract<Empty>> { | ||
pub fn contract_group() -> Box<dyn Contract<TgradeMsg>> { | ||
let contract = ContractWrapper::new( | ||
tg4_group::contract::execute, | ||
tg4_group::contract::instantiate, | ||
|
@@ -364,7 +366,7 @@ mod tests { | |
Box::new(contract) | ||
} | ||
|
||
pub fn contract_staking() -> Box<dyn Contract<Empty>> { | ||
pub fn contract_staking() -> Box<dyn Contract<TgradeMsg>> { | ||
let contract = ContractWrapper::new( | ||
tg4_stake::contract::execute, | ||
tg4_stake::contract::instantiate, | ||
|
@@ -373,16 +375,8 @@ mod tests { | |
Box::new(contract) | ||
} | ||
|
||
fn mock_app() -> App { | ||
let env = mock_env(); | ||
let api = MockApi::default(); | ||
let bank = BankKeeper::new(); | ||
|
||
App::new(api, env.block, bank, MockStorage::new()) | ||
} | ||
|
||
// uploads code and returns address of group contract | ||
fn instantiate_group(app: &mut App, members: Vec<Member>) -> Addr { | ||
fn instantiate_group(app: &mut App<TgradeMsg>, members: Vec<Member>) -> Addr { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is needed. (and all App changes) |
||
let admin = Some(OWNER.into()); | ||
let group_id = app.store_code(contract_group()); | ||
let msg = tg4_group::msg::InstantiateMsg { | ||
|
@@ -395,7 +389,7 @@ mod tests { | |
} | ||
|
||
// uploads code and returns address of group contract | ||
fn instantiate_staking(app: &mut App, stakers: Vec<Member>) -> Addr { | ||
fn instantiate_staking(app: &mut App<TgradeMsg>, stakers: Vec<Member>) -> Addr { | ||
let admin = Some(OWNER.into()); | ||
let group_id = app.store_code(contract_staking()); | ||
let msg = tg4_stake::msg::InstantiateMsg { | ||
|
@@ -405,6 +399,7 @@ mod tests { | |
unbonding_period: Duration::new_from_seconds(3600), | ||
admin: admin.clone(), | ||
preauths: Some(1), | ||
auto_return_limit: 0, | ||
}; | ||
let contract = app | ||
.instantiate_contract( | ||
|
@@ -433,7 +428,7 @@ mod tests { | |
contract | ||
} | ||
|
||
fn instantiate_mixer(app: &mut App, left: &Addr, right: &Addr) -> Addr { | ||
fn instantiate_mixer(app: &mut App<TgradeMsg>, left: &Addr, right: &Addr) -> Addr { | ||
let flex_id = app.store_code(contract_mixer()); | ||
let msg = crate::msg::InstantiateMsg { | ||
left_group: left.to_string(), | ||
|
@@ -449,7 +444,7 @@ mod tests { | |
/// and connectioning them all to the mixer. | ||
/// | ||
/// Returns (mixer address, group address, staking address). | ||
fn setup_test_case(app: &mut App, stakers: Vec<Member>) -> (Addr, Addr, Addr) { | ||
fn setup_test_case(app: &mut App<TgradeMsg>, stakers: Vec<Member>) -> (Addr, Addr, Addr) { | ||
// 1. Instantiate group contract with members (and OWNER as admin) | ||
let members = vec![ | ||
member(OWNER, 0), | ||
|
@@ -475,7 +470,7 @@ mod tests { | |
|
||
#[allow(clippy::too_many_arguments)] | ||
fn check_membership( | ||
app: &App, | ||
app: &App<TgradeMsg>, | ||
mixer_addr: &Addr, | ||
owner: Option<u64>, | ||
voter1: Option<u64>, | ||
|
@@ -508,7 +503,7 @@ mod tests { | |
|
||
#[test] | ||
fn basic_init() { | ||
let mut app = mock_app(); | ||
let mut app = AppBuilder::new().build(); | ||
let stakers = vec![ | ||
member(OWNER, 88888888888), // 0 weight -> 0 mixed | ||
member(VOTER1, 10000), // 10000 stake, 100 weight -> 1000 mixed | ||
|
@@ -532,7 +527,7 @@ mod tests { | |
|
||
#[test] | ||
fn update_with_upstream_change() { | ||
let mut app = mock_app(); | ||
let mut app = AppBuilder::new().build(); | ||
let stakers = vec![ | ||
member(VOTER1, 10000), // 10000 stake, 100 weight -> 1000 mixed | ||
member(VOTER3, 7500), // 7500 stake, 300 weight -> 1500 mixed | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... this seems like a partial implementation of #142
I guess we merge main into #146 after this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: I merged this in, worked fine. Now everything is up to v0.9.0