From 87ea8e27bd35e73594d375f5cded2cec607a7870 Mon Sep 17 00:00:00 2001 From: Deveus Date: Wed, 21 Dec 2022 15:49:54 +0200 Subject: [PATCH 1/5] fix: Empty action bug --- contracts/cw-croncat/src/tasks.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contracts/cw-croncat/src/tasks.rs b/contracts/cw-croncat/src/tasks.rs index 9d2769ae..3b1b957d 100644 --- a/contracts/cw-croncat/src/tasks.rs +++ b/contracts/cw-croncat/src/tasks.rs @@ -254,7 +254,9 @@ impl<'a> CwCroncat<'a> { val: "Interval invalid".to_string(), }); } - + if task.actions.is_empty() { + return Err(ContractError::CoreError(CoreError::InvalidAction {})); + } let (mut amount_for_one_task, gas_amount) = task.is_valid_msg_calculate_usage( deps.api, &env.contract.address, From c4e3594db759e0ba4afa5fd4322f97aa2b12fba3 Mon Sep 17 00:00:00 2001 From: Deveus Date: Wed, 21 Dec 2022 16:40:50 +0200 Subject: [PATCH 2/5] fix: checksum --- checksum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checksum b/checksum index f311d653..7edbe48d 100644 --- a/checksum +++ b/checksum @@ -1,2 +1,2 @@ -e841b8f67c8209ade26674edd432bb1d7dc9dcaa470651ebf379c62d41c294c8 cw_croncat.wasm +7e1411d78e92ac4ab2dbda9208b62f0b4cfffc926cfc61de10498fe4e40b7afd cw_croncat.wasm de2d1a0c648e41760020dd261f818da085c358240059acf85128f60eb0e05db2 cw_rules.wasm From 3d9a68e145cc80ab6a74cc6f09b75dcbac06b970 Mon Sep 17 00:00:00 2001 From: Buckram Date: Wed, 21 Dec 2022 17:40:57 +0200 Subject: [PATCH 3/5] tests --- checksum | 2 +- contracts/cw-croncat/src/tasks.rs | 4 +-- contracts/cw-croncat/src/tests/manager.rs | 35 +++++++++++++++++++++ packages/cw-croncat-core/src/tests/types.rs | 25 +++++++++++++++ packages/cw-croncat-core/src/types.rs | 3 ++ 5 files changed, 65 insertions(+), 4 deletions(-) diff --git a/checksum b/checksum index 7edbe48d..97137749 100644 --- a/checksum +++ b/checksum @@ -1,2 +1,2 @@ -7e1411d78e92ac4ab2dbda9208b62f0b4cfffc926cfc61de10498fe4e40b7afd cw_croncat.wasm +853004395db1861f1f337925a76e31b9f8ed5fe158b807c647240ea71876e875 cw_croncat.wasm de2d1a0c648e41760020dd261f818da085c358240059acf85128f60eb0e05db2 cw_rules.wasm diff --git a/contracts/cw-croncat/src/tasks.rs b/contracts/cw-croncat/src/tasks.rs index 3b1b957d..9d2769ae 100644 --- a/contracts/cw-croncat/src/tasks.rs +++ b/contracts/cw-croncat/src/tasks.rs @@ -254,9 +254,7 @@ impl<'a> CwCroncat<'a> { val: "Interval invalid".to_string(), }); } - if task.actions.is_empty() { - return Err(ContractError::CoreError(CoreError::InvalidAction {})); - } + let (mut amount_for_one_task, gas_amount) = task.is_valid_msg_calculate_usage( deps.api, &env.contract.address, diff --git a/contracts/cw-croncat/src/tests/manager.rs b/contracts/cw-croncat/src/tests/manager.rs index 0a669587..f3d64ba9 100644 --- a/contracts/cw-croncat/src/tests/manager.rs +++ b/contracts/cw-croncat/src/tests/manager.rs @@ -8,6 +8,7 @@ use cosmwasm_std::{ coin, coins, to_binary, Addr, BankMsg, Coin, CosmosMsg, StakingMsg, StdResult, Uint128, WasmMsg, }; use cw20::Cw20Coin; +use cw_croncat_core::error::CoreError; use cw_croncat_core::msg::{ AgentResponse, AgentTaskResponse, ExecuteMsg, GetAgentIdsResponse, QueryMsg, TaskRequest, TaskResponse, TaskWithQueriesResponse, @@ -3026,3 +3027,37 @@ fn test_error_in_reply() { } assert!(without_failure); } + +#[test] +fn empty_actions_not_allowed() { + let (mut app, cw_template_contract, _) = proper_instantiate(); + let contract_addr = cw_template_contract.addr(); + + let empty_actions = ExecuteMsg::CreateTask { + task: TaskRequest { + interval: Interval::Once, + boundary: None, + stop_on_fail: false, + actions: vec![], + queries: None, + transforms: None, + cw20_coins: vec![], + }, + }; + + let total_gas = GAS_BASE_FEE_JUNO + GAS_ACTION_FEE_JUNO; + let attach_per_action = (total_gas + (total_gas * 5 / 100)) / GAS_DENOMINATOR_DEFAULT_JUNO; + let amount_for_three = (attach_per_action) as u128; + + let res: ContractError = app + .execute_contract( + Addr::unchecked(ADMIN), + contract_addr.clone(), + &empty_actions, + &coins(amount_for_three, NATIVE_DENOM), + ) + .unwrap_err() + .downcast() + .unwrap(); + assert_eq!(res, ContractError::CoreError(CoreError::InvalidAction {})); +} diff --git a/packages/cw-croncat-core/src/tests/types.rs b/packages/cw-croncat-core/src/tests/types.rs index 3bfaa88f..84db19db 100644 --- a/packages/cw-croncat-core/src/tests/types.rs +++ b/packages/cw-croncat-core/src/tests/types.rs @@ -316,6 +316,31 @@ fn is_valid_msg_send_should_success() { .is_ok()); } +#[test] +fn is_valid_empty_actions() { + let task = TaskRequest { + interval: Interval::Block(10), + boundary: None, + stop_on_fail: false, + actions: vec![], + queries: None, + transforms: None, + cw20_coins: Default::default(), + }; + assert_eq!( + task.is_valid_msg_calculate_usage( + &mock_dependencies().api, + &Addr::unchecked("alice2"), + &Addr::unchecked("bob"), + &Addr::unchecked("bob"), + 5, + 5, + ) + .unwrap_err(), + CoreError::InvalidAction {} + ); +} + #[test] fn test_add_tokens() { let mut coins: GenericBalance = GenericBalance::default(); diff --git a/packages/cw-croncat-core/src/types.rs b/packages/cw-croncat-core/src/types.rs index 25028c0d..790af8f9 100644 --- a/packages/cw-croncat-core/src/types.rs +++ b/packages/cw-croncat-core/src/types.rs @@ -239,6 +239,9 @@ impl TaskRequest { let mut gas_amount: u64 = base_gas; let mut amount_for_one_task = GenericBalance::default(); + if self.actions.is_empty() { + return Err(CoreError::InvalidAction {}); + } for action in self.actions.iter() { // checked for cases, where task creator intentionaly tries to overflow gas_amount = gas_amount From fb78dbb7f739c659b41fd7ec135cd2e32b384580 Mon Sep 17 00:00:00 2001 From: Deveus Date: Thu, 22 Dec 2022 01:23:00 +0200 Subject: [PATCH 4/5] fix: hooks --- .rusty-hook.toml | 3 +-- packages/cw-croncat-core/src/tests/types.rs | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.rusty-hook.toml b/.rusty-hook.toml index 6b5b6d2b..582f635e 100644 --- a/.rusty-hook.toml +++ b/.rusty-hook.toml @@ -1,6 +1,5 @@ [hooks] -pre-commit = "just lint test" -pre-push = "just all" +pre-commit = "just lint" [logging] verbose = true diff --git a/packages/cw-croncat-core/src/tests/types.rs b/packages/cw-croncat-core/src/tests/types.rs index cb13ea35..b792be09 100644 --- a/packages/cw-croncat-core/src/tests/types.rs +++ b/packages/cw-croncat-core/src/tests/types.rs @@ -353,6 +353,8 @@ fn is_valid_empty_actions() { &Addr::unchecked("bob"), 5, 5, + 5, + 5, ) .unwrap_err(), CoreError::InvalidAction {} From faaeb1bf379fa6cb148dfd3188109e0010b7a15d Mon Sep 17 00:00:00 2001 From: Deveus Date: Thu, 22 Dec 2022 01:58:03 +0200 Subject: [PATCH 5/5] fix: checksum --- checksum | 4 ++-- contracts/cw-croncat/src/tests/manager.rs | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/checksum b/checksum index 97137749..873e6b32 100644 --- a/checksum +++ b/checksum @@ -1,2 +1,2 @@ -853004395db1861f1f337925a76e31b9f8ed5fe158b807c647240ea71876e875 cw_croncat.wasm -de2d1a0c648e41760020dd261f818da085c358240059acf85128f60eb0e05db2 cw_rules.wasm +f02ba448d956da4cc508cafdf14dd010e3ac0d37f5d40fa3116d27093d3a6ce1 cw_croncat.wasm +348ce203ce7a18c2e28f001139c1f7a215f7a569c735825dc819dc79692aaffb cw_rules.wasm diff --git a/contracts/cw-croncat/src/tests/manager.rs b/contracts/cw-croncat/src/tests/manager.rs index 5ea8d706..faae7d3f 100644 --- a/contracts/cw-croncat/src/tests/manager.rs +++ b/contracts/cw-croncat/src/tests/manager.rs @@ -1,7 +1,8 @@ use crate::contract::{ GAS_ACTION_FEE, GAS_ADJUSTMENT_NUMERATOR_DEFAULT, GAS_BASE_FEE, GAS_DENOMINATOR, - GAS_NUMERATOR_DEFAULT, GAS_QUERY_FEE, GAS_WASM_QUERY_FEE, + GAS_NUMERATOR_DEFAULT, }; + use crate::tests::helpers::{ add_1000_blocks, add_little_time, add_one_duration_of_time, cw4_template, proper_instantiate, AGENT1, AGENT2, AGENT3, @@ -13,10 +14,10 @@ use cosmwasm_std::{ use cw20::Cw20Coin; use cw_croncat_core::error::CoreError; use cw_croncat_core::msg::{ - AgentResponse, AgentTaskResponse, ExecuteMsg, GetAgentIdsResponse, GetConfigResponse, QueryMsg, - TaskRequest, TaskResponse, TaskWithQueriesResponse, + AgentResponse, AgentTaskResponse, ExecuteMsg, GetAgentIdsResponse, QueryMsg, TaskRequest, + TaskResponse, TaskWithQueriesResponse, }; -use cw_croncat_core::types::{Action, Boundary, GasPrice, Interval, Transform}; +use cw_croncat_core::types::{Action, Boundary, Interval, Transform}; use cw_multi_test::Executor; use cw_rules_core::types::{CroncatQuery, HasBalanceGte}; use cwd_core::state::ProposalModule; @@ -3082,8 +3083,8 @@ fn empty_actions_not_allowed() { }, }; - let total_gas = GAS_BASE_FEE_JUNO + GAS_ACTION_FEE_JUNO; - let attach_per_action = (total_gas + (total_gas * 5 / 100)) / GAS_DENOMINATOR_DEFAULT_JUNO; + let total_gas = GAS_BASE_FEE + GAS_ACTION_FEE; + let attach_per_action = (total_gas + (total_gas * 5 / 100)) / GAS_NUMERATOR_DEFAULT; let amount_for_three = (attach_per_action) as u128; let res: ContractError = app