Skip to content

Commit

Permalink
Merge pull request #234 from Buckram123/empty-actions-test
Browse files Browse the repository at this point in the history
[TESTS] Empty actions test
  • Loading branch information
d3v3us authored Dec 21, 2022
2 parents c4e3594 + 3d9a68e commit a988931
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 4 deletions.
2 changes: 1 addition & 1 deletion checksum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
7e1411d78e92ac4ab2dbda9208b62f0b4cfffc926cfc61de10498fe4e40b7afd cw_croncat.wasm
853004395db1861f1f337925a76e31b9f8ed5fe158b807c647240ea71876e875 cw_croncat.wasm
de2d1a0c648e41760020dd261f818da085c358240059acf85128f60eb0e05db2 cw_rules.wasm
4 changes: 1 addition & 3 deletions contracts/cw-croncat/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
35 changes: 35 additions & 0 deletions contracts/cw-croncat/src/tests/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {}));
}
25 changes: 25 additions & 0 deletions packages/cw-croncat-core/src/tests/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions packages/cw-croncat-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a988931

Please sign in to comment.