From a508332491dc32b98157cad1d7e32f5c475c9fc8 Mon Sep 17 00:00:00 2001 From: oldremez <83083413+oldremez@users.noreply.github.com> Date: Sun, 7 Jul 2024 14:22:59 +0200 Subject: [PATCH] tests --- contracts/core/src/contract.rs | 73 ++++++++++++++++++---------------- contracts/core/src/tests.rs | 52 ++++++++++++++---------- 2 files changed, 68 insertions(+), 57 deletions(-) diff --git a/contracts/core/src/contract.rs b/contracts/core/src/contract.rs index f3a56fbf..c6b4f77f 100644 --- a/contracts/core/src/contract.rs +++ b/contracts/core/src/contract.rs @@ -521,10 +521,7 @@ fn execute_tick_idle( info: MessageInfo, config: &Config, ) -> ContractResult> { - 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)?; @@ -608,9 +605,7 @@ fn execute_tick_idle( attrs.push(attr("knot", "007")); let transfer: Option = 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() @@ -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")); } @@ -814,11 +810,13 @@ fn execute_tick_claiming( config: &Config, ) -> ContractResult> { 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, @@ -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")); @@ -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")); @@ -940,22 +944,21 @@ fn execute_tick_staking_rewards( info: MessageInfo, config: &Config, ) -> ContractResult> { - 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")); @@ -969,10 +972,7 @@ fn execute_tick_unbonding( _info: MessageInfo, config: &Config, ) -> ContractResult> { - 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) => { @@ -1455,15 +1455,18 @@ fn get_unbonding_msg( 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)) } diff --git a/contracts/core/src/tests.rs b/contracts/core/src/tests.rs index 8b0f0011..f15e57f1 100644 --- a/contracts/core/src/tests.rs +++ b/contracts/core/src/tests.rs @@ -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"), @@ -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"), @@ -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"), @@ -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"), ] ) ) @@ -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"), @@ -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(), @@ -1694,13 +1688,12 @@ 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"), @@ -1708,7 +1701,6 @@ fn test_tick_idle_staking_bond() { ("knot", "016"), ("knot", "017"), ("state", "staking_bond"), - ("knot", "004"), ] ) ) @@ -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"), @@ -1875,7 +1866,6 @@ fn test_tick_idle_staking() { ("knot", "021"), ("knot", "022"), ("state", "staking_rewards"), - ("knot", "004"), ] ) ) @@ -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"), ] ) ) @@ -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"), @@ -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") @@ -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") ] @@ -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"), @@ -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"), ]