Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oldremez committed Jul 7, 2024
1 parent 030de73 commit a508332
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 57 deletions.
73 changes: 38 additions & 35 deletions contracts/core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,7 @@ fn execute_tick_idle(
info: MessageInfo,
config: &Config,
) -> ContractResult<Response<NeutronMsg>> {
let mut attrs = vec![
attr("action", "tick_idle"),
attr("knot", "000"),
];
let mut attrs = vec![attr("action", "tick_idle"), attr("knot", "000")];
let last_idle_call = LAST_IDLE_CALL.load(deps.storage)?;
let mut messages = vec![];
cache_exchange_rate(deps.branch(), env.clone(), config)?;
Expand Down Expand Up @@ -608,9 +605,7 @@ fn execute_tick_idle(

attrs.push(attr("knot", "007"));
let transfer: Option<TransferReadyBatchesMsg> = match unbonded_batches.len() {
0 => {
None
} // we have nothing to do
0 => None, // we have nothing to do
1 => {
let (id, mut unbonding_batch) = unbonded_batches
.into_iter()
Expand Down Expand Up @@ -739,16 +734,17 @@ fn execute_tick_idle(
attrs.push(attr("knot", "022"));
attrs.push(attr("state", "staking_rewards"));
} else {
attrs.push(attr("knot", "024"));
if let Some(unbond_message) =
get_unbonding_msg(deps.branch(), &env, config, &info)?
{
let (unbond_message_relut, unbond_attrs) =
get_unbonding_msg(deps.branch(), &env, config, &info)?;
if let Some(unbond_message) = unbond_message_relut {
attrs.extend(unbond_attrs);
messages.push(unbond_message);
attrs.push(attr("knot", "028"));
FSM.go_to(deps.storage, ContractState::Unbonding)?;
attrs.push(attr("knot", "029"));
attrs.push(attr("state", "unbonding"));
} else {
attrs.extend(unbond_attrs);
attrs.push(attr("state", "idle"));
attrs.push(attr("knot", "000"));
}
Expand Down Expand Up @@ -814,11 +810,13 @@ fn execute_tick_claiming(
config: &Config,
) -> ContractResult<Response<NeutronMsg>> {
let mut attrs = vec![attr("action", "tick_claiming")];
attrs.push(attr("knot", "012"));
let response_msg = get_received_puppeteer_response(deps.as_ref())?;
LAST_PUPPETEER_RESPONSE.remove(deps.storage);
let mut messages = vec![];
match response_msg {
drop_puppeteer_base::msg::ResponseHookMsg::Success(success_msg) => {
attrs.push(attr("knot", "047"));
match success_msg.transaction {
drop_puppeteer_base::msg::Transaction::ClaimRewardsAndOptionalyTransfer {
transfer,
Expand Down Expand Up @@ -867,14 +865,17 @@ fn execute_tick_claiming(
attrs.push(attr("knot", "022"));
attrs.push(attr("state", "staking_rewards"));
} else {
attrs.push(attr("knot", "024"));
if let Some(unbond_message) = get_unbonding_msg(deps.branch(), &env, config, &info)? {
let (unbond_message_relut, unbond_attrs) =
get_unbonding_msg(deps.branch(), &env, config, &info)?;
if let Some(unbond_message) = unbond_message_relut {
attrs.extend(unbond_attrs);
messages.push(unbond_message);
attrs.push(attr("knot", "028"));
FSM.go_to(deps.storage, ContractState::Unbonding)?;
attrs.push(attr("knot", "029"));
attrs.push(attr("state", "unbonding"));
} else {
attrs.extend(unbond_attrs);
FSM.go_to(deps.storage, ContractState::Idle)?;
attrs.push(attr("knot", "000"));
attrs.push(attr("state", "idle"));
Expand Down Expand Up @@ -918,14 +919,17 @@ fn execute_tick_staking_bond(
attrs.push(attr("knot", "022"));
attrs.push(attr("state", "staking_rewards"));
} else {
attrs.push(attr("knot", "024"));
if let Some(unbond_message) = get_unbonding_msg(deps.branch(), &env, config, &info)? {
let (unbond_message_relut, unbond_attrs) =
get_unbonding_msg(deps.branch(), &env, config, &info)?;
if let Some(unbond_message) = unbond_message_relut {
attrs.extend(unbond_attrs);
messages.push(unbond_message);
attrs.push(attr("knot", "028"));
FSM.go_to(deps.storage, ContractState::Unbonding)?;
attrs.push(attr("knot", "029"));
attrs.push(attr("state", "unbonding"));
} else {
attrs.extend(unbond_attrs);
FSM.go_to(deps.storage, ContractState::Idle)?;
attrs.push(attr("knot", "000"));
attrs.push(attr("state", "idle"));
Expand All @@ -940,22 +944,21 @@ fn execute_tick_staking_rewards(
info: MessageInfo,
config: &Config,
) -> ContractResult<Response<NeutronMsg>> {
let mut attrs = vec![
attr("action", "tick_staking"),
attr("knot", "022"),
];
let mut attrs = vec![attr("action", "tick_staking"), attr("knot", "022")];
let _response_msg = get_received_puppeteer_response(deps.as_ref())?;
LAST_PUPPETEER_RESPONSE.remove(deps.storage);
let mut messages = vec![];
attrs.push(attr("knot", "024"));
let unbond_message = get_unbonding_msg(deps.branch(), &env, config, &info)?;
if let Some(unbond_message) = unbond_message {
let (unbond_message_relut, unbond_attrs) =
get_unbonding_msg(deps.branch(), &env, config, &info)?;
if let Some(unbond_message) = unbond_message_relut {
attrs.extend(unbond_attrs);
messages.push(unbond_message);
attrs.push(attr("knot", "028"));
FSM.go_to(deps.storage, ContractState::Unbonding)?;
attrs.push(attr("knot", "029"));
attrs.push(attr("state", "unbonding"));
} else {
attrs.extend(unbond_attrs);
FSM.go_to(deps.storage, ContractState::Idle)?;
attrs.push(attr("knot", "000"));
attrs.push(attr("state", "idle"));
Expand All @@ -969,10 +972,7 @@ fn execute_tick_unbonding(
_info: MessageInfo,
config: &Config,
) -> ContractResult<Response<NeutronMsg>> {
let mut attrs = vec![
attr("action", "tick_unbonding"),
attr("knot", "029"),
];
let mut attrs = vec![attr("action", "tick_unbonding"), attr("knot", "029")];
let res = get_received_puppeteer_response(deps.as_ref())?;
match res {
drop_puppeteer_base::msg::ResponseHookMsg::Success(response) => {
Expand Down Expand Up @@ -1455,15 +1455,18 @@ fn get_unbonding_msg<T>(
batch_id + 1,
&new_unbond(env.block.time.seconds()),
)?;
Ok((Some(CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: config.puppeteer_contract.to_string(),
msg: to_json_binary(&drop_staking_base::msg::puppeteer::ExecuteMsg::Undelegate {
items: undelegations,
batch_id,
reply_to: env.contract.address.to_string(),
})?,
funds,
})), attrs))
Ok((
Some(CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: config.puppeteer_contract.to_string(),
msg: to_json_binary(&drop_staking_base::msg::puppeteer::ExecuteMsg::Undelegate {
items: undelegations,
batch_id,
reply_to: env.contract.address.to_string(),
})?,
funds,
})),
attrs,
))
} else {
Ok((None, attrs))
}
Expand Down
52 changes: 30 additions & 22 deletions contracts/core/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,6 @@ fn test_execute_tick_idle_non_native_rewards() {
Event::new("crates.io:drop-staking__drop-core-execute-tick_idle").add_attributes(
vec![
("action", "tick_idle"),
("knot", "001"),
("knot", "000"),
("knot", "002"),
("knot", "003"),
Expand Down Expand Up @@ -939,7 +938,6 @@ fn test_execute_tick_idle_get_pending_lsm_shares_transfer() {
Event::new("crates.io:drop-staking__drop-core-execute-tick_idle").add_attributes(
vec![
("action", "tick_idle"),
("knot", "001"),
("knot", "000"),
("knot", "002"),
("knot", "003"),
Expand Down Expand Up @@ -1084,7 +1082,6 @@ fn test_idle_tick_pending_lsm_redeem() {
Event::new("crates.io:drop-staking__drop-core-execute-tick_idle").add_attributes(
vec![
("action", "tick_idle"),
("knot", "001"),
("knot", "000"),
("knot", "002"),
("knot", "003"),
Expand Down Expand Up @@ -1380,20 +1377,18 @@ fn test_tick_idle_claim_wo_unbond() {
Event::new("crates.io:drop-staking__drop-core-execute-tick_idle").add_attributes(
vec![
("action", "tick_idle"),
("knot", "001"),
("knot", "000"),
("knot", "002"),
("knot", "003"),
("knot", "004"),
("knot", "005"),
("knot", "007"),
("knot", "045"),
("knot", "009"),
("knot", "010"),
("validators_to_claim", "valoper_address"),
("knot", "011"),
("knot", "012"),
("state", "claiming"),
("knot", "004"),
]
)
)
Expand Down Expand Up @@ -1544,10 +1539,10 @@ fn test_tick_idle_claim_with_unbond_transfer() {
Response::new()
.add_event(Event::new("crates.io:drop-staking__drop-core-execute-tick_idle").add_attributes(vec![
("action", "tick_idle" ),
("knot", "001"),
("knot", "000"),
("knot", "002"),
("knot", "003"),
("knot", "004"),
("knot", "005"),
("knot", "007"),
("knot", "008"),
Expand All @@ -1557,7 +1552,6 @@ fn test_tick_idle_claim_with_unbond_transfer() {
("knot", "011"),
("knot", "012"),
("state", "claiming"),
("knot", "004"),
]))
.add_submessage(SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: "puppeteer_contract".to_string(),
Expand Down Expand Up @@ -1694,21 +1688,19 @@ fn test_tick_idle_staking_bond() {
Event::new("crates.io:drop-staking__drop-core-execute-tick_idle").add_attributes(
vec![
("action", "tick_idle"),
("knot", "001"),
("knot", "000"),
("knot", "002"),
("knot", "003"),
("knot", "004"),
("knot", "005"),
("knot", "007"),
("knot", "045"),
("knot", "009"),
("knot", "010"),
("validators_to_claim", "empty"),
("knot", "015"),
("knot", "016"),
("knot", "017"),
("state", "staking_bond"),
("knot", "004"),
]
)
)
Expand Down Expand Up @@ -1860,13 +1852,12 @@ fn test_tick_idle_staking() {
Event::new("crates.io:drop-staking__drop-core-execute-tick_idle").add_attributes(
vec![
("action", "tick_idle"),
("knot", "001"),
("knot", "000"),
("knot", "002"),
("knot", "003"),
("knot", "004"),
("knot", "005"),
("knot", "007"),
("knot", "045"),
("knot", "009"),
("knot", "010"),
("validators_to_claim", "empty"),
Expand All @@ -1875,7 +1866,6 @@ fn test_tick_idle_staking() {
("knot", "021"),
("knot", "022"),
("state", "staking_rewards"),
("knot", "004"),
]
)
)
Expand Down Expand Up @@ -2057,23 +2047,25 @@ fn test_tick_idle_unbonding() {
Event::new("crates.io:drop-staking__drop-core-execute-tick_idle").add_attributes(
vec![
("action", "tick_idle"),
("knot", "001"),
("knot", "000"),
("knot", "002"),
("knot", "003"),
("knot", "004"),
("knot", "005"),
("knot", "007"),
("knot", "045"),
("knot", "009"),
("knot", "010"),
("validators_to_claim", "empty"),
("knot", "015"),
("knot", "020"),
("knot", "024"),
("knot", "026"),
("knot", "027"),
("knot", "045"),
("knot", "046"),
("knot", "028"),
("knot", "029"),
("state", "unbonding"),
("knot", "004"),
]
)
)
Expand Down Expand Up @@ -2243,7 +2235,9 @@ fn test_tick_claiming_wo_transfer_stake() {
Event::new("crates.io:drop-staking__drop-core-execute-tick_claiming")
.add_attributes(vec![
("action", "tick_claiming"),
("knot", "001"),
("knot", "012"),
("knot", "047"),
("knot", "013"),
("knot", "015"),
("knot", "020"),
("knot", "021"),
Expand Down Expand Up @@ -2415,10 +2409,16 @@ fn test_tick_claiming_wo_transfer_unbonding() {
Event::new("crates.io:drop-staking__drop-core-execute-tick_claiming")
.add_attributes(vec![
("action", "tick_claiming"),
("knot", "001"),
("knot", "012"),
("knot", "047"),
("knot", "013"),
("knot", "015"),
("knot", "020"),
("knot", "024"),
("knot", "026"),
("knot", "027"),
("knot", "045"),
("knot", "046"),
("knot", "028"),
("knot", "029"),
("state", "unbonding")
Expand Down Expand Up @@ -2584,10 +2584,14 @@ fn test_tick_claiming_wo_idle() {
Event::new("crates.io:drop-staking__drop-core-execute-tick_claiming").add_attributes(
vec![
("action", "tick_claiming"),
("knot", "001"),
("knot", "012"),
("knot", "047"),
("knot", "013"),
("knot", "015"),
("knot", "020"),
("knot", "024"),
("knot", "026"),
("knot", "027"),
("knot", "000"),
("state", "idle")
]
Expand Down Expand Up @@ -2949,9 +2953,12 @@ fn test_tick_staking_to_unbonding() {
Event::new("crates.io:drop-staking__drop-core-execute-tick_staking")
.add_attributes(vec![
("action", "tick_staking"),
("knot", "001"),
("knot", "022"),
("knot", "024"),
("knot", "026"),
("knot", "027"),
("knot", "045"),
("knot", "046"),
("knot", "028"),
("knot", "029"),
("state", "unbonding"),
Expand Down Expand Up @@ -3089,9 +3096,10 @@ fn test_tick_staking_to_idle() {
Event::new("crates.io:drop-staking__drop-core-execute-tick_staking").add_attributes(
vec![
("action", "tick_staking"),
("knot", "001"),
("knot", "022"),
("knot", "024"),
("knot", "026"),
("knot", "027"),
("knot", "000"),
("state", "idle"),
]
Expand Down

0 comments on commit a508332

Please sign in to comment.