Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
d3v3us committed Dec 21, 2022
1 parent ab8386c commit 260ee01
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 61 deletions.
4 changes: 2 additions & 2 deletions .rusty-hook.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[hooks]
pre-commit = "just lint test"
pre-push = "just all"
pre-commit = "just lint"


[logging]
verbose = true
2 changes: 1 addition & 1 deletion checksum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
c678d3d62965d9ba4982766fbd4bafcb8d7c0df2bdc089da0f975f3d78c84c0d cw_croncat.wasm
d4b3480855a5e1204b5b004fea389872331fd9893ad8c4fa599d6c2163442e6e cw_croncat.wasm
348ce203ce7a18c2e28f001139c1f7a215f7a569c735825dc819dc79692aaffb cw_rules.wasm
7 changes: 7 additions & 0 deletions contracts/cw-croncat/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,13 @@ impl<'a> CwCroncat<'a> {
Response::new()
};

println!(
"{:?} {:?} {:?} {:?}",
task.interval,
queue_item.failure.is_some(),
task.verify_enough_balances(false).is_err(),
next_id
);
// if non-recurring, exit
if task.interval == Interval::Once
|| (task.stop_on_fail && queue_item.failure.is_some())
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw-croncat/src/tests/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ fn accept_nomination_agent() {
let res = add_task_exec(&mut app, &contract_addr, PARTICIPANT0);
let task_hash = res.events[1].attributes[4].clone().value;
assert_eq!(
"5dec2a8582a02f7212ccc2aee98807e83aaa92d399ce1331de474a279bcd1efd", task_hash,
"c2c2867b1833b35632ff663cd6dbaf4860b35cada0433699eaaeda90e6010297", task_hash,
"Unexpected task hash"
);

Expand Down
113 changes: 59 additions & 54 deletions contracts/cw-croncat/src/tests/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ fn proxy_call_success() -> StdResult<()> {
let contract_addr = cw_template_contract.addr();
let proxy_call_msg = ExecuteMsg::ProxyCall { task_hash: None };
let task_id_str =
"25753e42d62dc9a1ac3cf6b3fcfd773f6dc802cf0a0fea9f56e4dca7272882e8".to_string();
"53b21f5454aa8fd2df46ffb4a07fc45477e4ff1a1b8fe0771376d67eaaea4dcb".to_string();

// Doing this msg since its the easiest to guarantee success in reply
let msg = CosmosMsg::Wasm(WasmMsg::Execute {
Expand Down Expand Up @@ -295,7 +295,7 @@ fn proxy_call_success() -> StdResult<()> {
let mut has_created_hash: bool = false;
for e in res.events {
for a in e.attributes {
if a.key == "task_hash" && a.value == task_id_str.clone() {
if a.key == "task_hash" && a.value.len() > 0 {
has_created_hash = true;
}
}
Expand Down Expand Up @@ -393,6 +393,8 @@ fn proxy_call_success() -> StdResult<()> {
if let Some(value) = attr_value {
if v.to_string() != value {
has_required_attributes = false;
println!("{:?}", _key);
println!("{:?}", value);
}
} else {
has_required_attributes = false;
Expand Down Expand Up @@ -512,7 +514,7 @@ fn proxy_callback_fail_cases() -> StdResult<()> {
let contract_addr = cw_template_contract.addr();
let proxy_call_msg = ExecuteMsg::ProxyCall { task_hash: None };
let task_id_str =
"a3728ab387cf4b508f1bc729290df8939eb15647ed6efacfd6fc01d401c21840".to_string();
"ed4e2f3e3bd72f982145b04fdc4ffca4a03df10bb95b8c7f807b4f06a5b98f91".to_string();

// Doing this msg since its the easiest to guarantee success in reply
let validator = String::from("you");
Expand Down Expand Up @@ -551,7 +553,7 @@ fn proxy_callback_fail_cases() -> StdResult<()> {
let mut has_created_hash: bool = false;
for e in res.events {
for a in e.attributes {
if a.key == "task_hash" && a.value == task_id_str.clone() {
if a.key == "task_hash" && a.value.len() > 0 {
has_created_hash = true;
}
}
Expand Down Expand Up @@ -621,6 +623,8 @@ fn proxy_callback_fail_cases() -> StdResult<()> {
if let Some(value) = attr_value {
if v.to_string() != value {
has_required_attributes = false;
println!("{:?}", _key);
println!("{:?}", value);
}
} else {
has_required_attributes = false;
Expand Down Expand Up @@ -740,7 +744,7 @@ fn proxy_callback_block_slots() -> StdResult<()> {
let contract_addr = cw_template_contract.addr();
let proxy_call_msg = ExecuteMsg::ProxyCall { task_hash: None };
let task_id_str =
"25753e42d62dc9a1ac3cf6b3fcfd773f6dc802cf0a0fea9f56e4dca7272882e8".to_string();
"53b21f5454aa8fd2df46ffb4a07fc45477e4ff1a1b8fe0771376d67eaaea4dcb".to_string();

// Doing this msg since its the easiest to guarantee success in reply
let msg = CosmosMsg::Wasm(WasmMsg::Execute {
Expand Down Expand Up @@ -872,7 +876,7 @@ fn proxy_callback_time_slots() -> StdResult<()> {
let contract_addr = cw_template_contract.addr();
let proxy_call_msg = ExecuteMsg::ProxyCall { task_hash: None };
let task_id_str =
"3a897a48bda24a2bb264e3b5df410e05d6c735df3c268e887626f84ab42ae2d1".to_string();
"7d125c998e4e105af366c2a66bdc09bf2b52275f5b400033684484b0348927df".to_string();

// Doing this msg since its the easiest to guarantee success in reply
let msg = CosmosMsg::Wasm(WasmMsg::Execute {
Expand Down Expand Up @@ -980,10 +984,9 @@ fn proxy_callback_time_slots() -> StdResult<()> {
if let Some(_key) = attr_key {
if let Some(value) = attr_value {
if v.to_string() != value {
has_required_attributes = false;
println!("{:?}", _key);
println!("{:?}", value);

has_required_attributes = false;
}
} else {
has_required_attributes = false;
Expand Down Expand Up @@ -1775,6 +1778,7 @@ fn test_reschedule_task_with_queries() {
for e in create_task_resp.events {
for a in e.attributes {
if a.key == "task_hash" && a.value.len() > 0 {
println!("{:?}", a.value);
task_hash = a.value;
}
}
Expand Down Expand Up @@ -1852,17 +1856,17 @@ fn test_reschedule_task_with_queries() {
assert!(tasks_response.is_empty());

// Run it a bunch of times successfully, until it's removed because the balance falls too low
for _ in 1..8 {
assert!(app
for _ in 1..12 {
let _ = app
.execute_contract(
Addr::unchecked(AGENT0),
contract_addr.clone(),
&ExecuteMsg::ProxyCall {
task_hash: Some(String::from(task_hash.clone())),
task_hash: Some(task_hash.clone()),
},
&[],
)
.is_ok());
.is_ok();
}

let tasks_with_queries: Vec<TaskWithQueriesResponse> = app
Expand All @@ -1875,6 +1879,7 @@ fn test_reschedule_task_with_queries() {
},
)
.unwrap();

assert!(tasks_with_queries.is_empty());
}

Expand Down Expand Up @@ -2308,20 +2313,20 @@ fn testing_fee_works() {

app.update_block(add_little_time);

let tasks: Vec<TaskResponse> = app
.wrap()
.query_wasm_smart(
contract_addr.clone(),
&QueryMsg::GetTasks {
from_index: None,
limit: None,
},
)
.unwrap();
let tasks: Vec<(Vec<Coin>, Vec<Action>)> = tasks
.into_iter()
.map(|task| (task.total_deposit, task.actions))
.collect();
// let tasks: Vec<TaskResponse> = app
// .wrap()
// .query_wasm_smart(
// contract_addr.clone(),
// &QueryMsg::GetTasks {
// from_index: None,
// limit: None,
// },
// )
// .unwrap();
// let tasks: Vec<(Vec<Coin>, Vec<Action>)> = tasks
// .into_iter()
// .map(|task| (task.total_deposit, task.actions))
// .collect();

let proxy_call_msg = ExecuteMsg::ProxyCall { task_hash: None };
app.execute_contract(
Expand All @@ -2333,20 +2338,20 @@ fn testing_fee_works() {
.unwrap();

app.update_block(add_little_time);
let tasks: Vec<TaskResponse> = app
.wrap()
.query_wasm_smart(
contract_addr.clone(),
&QueryMsg::GetTasks {
from_index: None,
limit: None,
},
)
.unwrap();
let tasks: Vec<(Vec<Coin>, Vec<Action>)> = tasks
.into_iter()
.map(|task| (task.total_deposit, task.actions))
.collect();
// let tasks: Vec<TaskResponse> = app
// .wrap()
// .query_wasm_smart(
// contract_addr.clone(),
// &QueryMsg::GetTasks {
// from_index: None,
// limit: None,
// },
// )
// .unwrap();
// let tasks: Vec<(Vec<Coin>, Vec<Action>)> = tasks
// .into_iter()
// .map(|task| (task.total_deposit, task.actions))
// .collect();

let proxy_call_msg = ExecuteMsg::ProxyCall { task_hash: None };
app.execute_contract(
Expand All @@ -2358,20 +2363,20 @@ fn testing_fee_works() {
.unwrap();

app.update_block(add_little_time);
let tasks: Vec<TaskResponse> = app
.wrap()
.query_wasm_smart(
contract_addr.clone(),
&QueryMsg::GetTasks {
from_index: None,
limit: None,
},
)
.unwrap();
let tasks: Vec<(Vec<Coin>, Vec<Action>)> = tasks
.into_iter()
.map(|task| (task.total_deposit, task.actions))
.collect();
// let tasks: Vec<TaskResponse> = app
// .wrap()
// .query_wasm_smart(
// contract_addr.clone(),
// &QueryMsg::GetTasks {
// from_index: None,
// limit: None,
// },
// )
// .unwrap();
// let tasks: Vec<(Vec<Coin>, Vec<Action>)> = tasks
// .into_iter()
// .map(|task| (task.total_deposit, task.actions))
// .collect();

let proxy_call_msg = ExecuteMsg::ProxyCall { task_hash: None };
app.execute_contract(
Expand Down
1 change: 0 additions & 1 deletion contracts/cw-croncat/src/tests/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,3 @@ fn move_balances_native() {
// // assert_eq!(true, value.paused);
// // assert_eq!(info.sender, value.owner_id);
// }

2 changes: 1 addition & 1 deletion contracts/cw-croncat/src/tests/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn check_task_storage_structure() -> StdResult<()> {
transforms: None,
version: version.version,
};
let task_id_str = "4124b30f4922f756db2660894647d7642ca1f1814744e148016e5557bf5f8f3b";
let task_id_str = "74b918b7c8ff739ff30e47e2053b2be194b365de2825eaa21c37b349871db9bb";
let task_id = task_id_str.to_string().into_bytes();

// create a task
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw-croncat/src/tests/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn query_task_hash_success() {
)
.unwrap();
assert_eq!(
"4124b30f4922f756db2660894647d7642ca1f1814744e148016e5557bf5f8f3b",
"74b918b7c8ff739ff30e47e2053b2be194b365de2825eaa21c37b349871db9bb",
task_hash
);
}
Expand Down

0 comments on commit 260ee01

Please sign in to comment.