Skip to content

Commit

Permalink
Merge pull request #232 from Buckram123/task-hash-transforms-update
Browse files Browse the repository at this point in the history
[FIX] Task hash's, added transforms to the hashing
  • Loading branch information
Buckram123 authored Dec 21, 2022
2 parents 426c2c7 + f5a9a71 commit 3c9750a
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 32 deletions.
11 changes: 6 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions checksum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
0b779e7fbbab5d0d2e4b75a413351f41a7083cf410d6562cc9578baaaaf6d977 cw_croncat.wasm
66a4088ae10ba3a45653760543c8c52bad006a5fe79e896bb5f6c3aa26887277 cw_rules.wasm
c678d3d62965d9ba4982766fbd4bafcb8d7c0df2bdc089da0f975f3d78c84c0d cw_croncat.wasm
348ce203ce7a18c2e28f001139c1f7a215f7a569c735825dc819dc79692aaffb cw_rules.wasm
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!(
"7ea9a6d5ef5c78cb168afa96b43b5843b8f880627aa0580f4311403f907cbf93", task_hash,
"e078693103645f865278562ddb4301ec1f684c7ec4a0bd43907175b00ee8f562", task_hash,
"Unexpected task hash"
);

Expand Down
18 changes: 9 additions & 9 deletions contracts/cw-croncat/src/tests/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn proxy_call_fail_cases() -> StdResult<()> {
},
};
let task_id_str =
"95c916a53fa9d26deef094f7e1ee31c00a2d47b8bf474b2e06d39aebfb1fecc7".to_string();
"a78a89f0bbcba7d36c50d2b0ea8f3d3f6677b4b4ca76bd650eaf5836bed65b1c".to_string();

// Must attach funds
let res_err = app
Expand Down Expand Up @@ -257,7 +257,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 =
"1032a37c92801f73c75816bddb4f0db8516baeeeacd6a2c225f0a6a54c96732e".to_string();
"62c7a2dd020ace2169b3d61ac32a5e5fd98050d73584f121d424a9ebbf32e7a0".to_string();

// Doing this msg since its the easiest to guarantee success in reply
let msg = CosmosMsg::Wasm(WasmMsg::Execute {
Expand Down Expand Up @@ -514,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 =
"96003a7938c1ac9566fec1be9b0cfa97a56626a574940ef5968364ef4d30c15a".to_string();
"dc8759f300ac55b4d4f0e7fa0fc6727392f55e9f4d132745692eae1da7108cfc".to_string();

// Doing this msg since its the easiest to guarantee success in reply
let validator = String::from("you");
Expand Down Expand Up @@ -743,7 +743,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 =
"1032a37c92801f73c75816bddb4f0db8516baeeeacd6a2c225f0a6a54c96732e".to_string();
"62c7a2dd020ace2169b3d61ac32a5e5fd98050d73584f121d424a9ebbf32e7a0".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 +872,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 =
"164329dc48b4d81075f82c823108d1f1f435af952d4697583b99a9f35962e211".to_string();
"5a9fd1f1506e26cc78816f031ad251729fb2d6979f54639116611cd3d9df9191".to_string();

// Doing this msg since its the easiest to guarantee success in reply
let msg = CosmosMsg::Wasm(WasmMsg::Execute {
Expand Down Expand Up @@ -1551,7 +1551,7 @@ fn test_no_reschedule_if_lack_balance() {
.query_wasm_smart(
contract_addr.clone(),
&QueryMsg::GetTask {
task_hash: "65237042c224447b7d6d7cdfd6515af3e76cb3270ce6d5ed989a6babc12f1026"
task_hash: "8fad55a869f129ba363786bd7f0ec698f1a59e2553ba7fdec408f1cd82326cd3"
.to_string(),
},
)
Expand Down Expand Up @@ -1583,7 +1583,7 @@ fn test_no_reschedule_if_lack_balance() {
.query_wasm_smart(
contract_addr.clone(),
&QueryMsg::GetTask {
task_hash: "65237042c224447b7d6d7cdfd6515af3e76cb3270ce6d5ed989a6babc12f1026"
task_hash: "8fad55a869f129ba363786bd7f0ec698f1a59e2553ba7fdec408f1cd82326cd3"
.to_string(),
},
)
Expand All @@ -1608,7 +1608,7 @@ fn test_no_reschedule_if_lack_balance() {
fn test_complete_task_with_query() {
let (mut app, cw_template_contract, _) = proper_instantiate();
let contract_addr = cw_template_contract.addr();
let task_hash = "259f4b3122822233bee9bc6ec8d38184e4b6ce0908decd68d972639aa92199c7";
let task_hash = "c2772d2268fa9809f70bb36c15cb33c1f7c6ff458ca2f2a4707b8ae677d53c72";

let addr1 = String::from("addr1");
let amount = coins(3, NATIVE_DENOM);
Expand Down Expand Up @@ -1718,7 +1718,7 @@ fn test_complete_task_with_query() {
fn test_reschedule_task_with_queries() {
let (mut app, cw_template_contract, _) = proper_instantiate();
let contract_addr = cw_template_contract.addr();
let task_hash = "4e74864be3956efe77bafac50944995290a32507bbd4509dd8ff21d3fdfdfec3";
let task_hash = "672deeb057ad86ca6c16b7abee1b912b6f737b7eedd4f3fe319d5bd54dc1dbd6";

let addr1 = String::from("addr1");
let amount = coins(3, NATIVE_DENOM);
Expand Down
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 @@ -37,7 +37,7 @@ fn check_task_storage_structure() -> StdResult<()> {
transforms: None,
version: version.version,
};
let task_id_str = "69217dd2b6334abe2544a12fcb89588f9cc5c62a298b8720706d9befa3d736d3";
let task_id_str = "85a5729f478d96fbb12eec7886992a53635d22bba4d8d8ef2fde16dc7f1f1605";
let task_id = task_id_str.to_string().into_bytes();

// create a task
Expand Down
8 changes: 4 additions & 4 deletions contracts/cw-croncat/src/tests/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn query_task_hash_success() {
)
.unwrap();
assert_eq!(
"69217dd2b6334abe2544a12fcb89588f9cc5c62a298b8720706d9befa3d736d3",
"85a5729f478d96fbb12eec7886992a53635d22bba4d8d8ef2fde16dc7f1f1605",
task_hash
);
}
Expand Down Expand Up @@ -583,7 +583,7 @@ fn check_task_create_success() -> StdResult<()> {
},
};
let task_id_str =
"95c916a53fa9d26deef094f7e1ee31c00a2d47b8bf474b2e06d39aebfb1fecc7".to_string();
"a78a89f0bbcba7d36c50d2b0ea8f3d3f6677b4b4ca76bd650eaf5836bed65b1c".to_string();

// create a task
let res = app
Expand Down Expand Up @@ -856,7 +856,7 @@ fn check_remove_create() -> StdResult<()> {
},
};
let task_id_str =
"95c916a53fa9d26deef094f7e1ee31c00a2d47b8bf474b2e06d39aebfb1fecc7".to_string();
"a78a89f0bbcba7d36c50d2b0ea8f3d3f6677b4b4ca76bd650eaf5836bed65b1c".to_string();

// create a task
app.execute_contract(
Expand Down Expand Up @@ -966,7 +966,7 @@ fn check_refill_create() -> StdResult<()> {
},
};
let task_id_str =
"95c916a53fa9d26deef094f7e1ee31c00a2d47b8bf474b2e06d39aebfb1fecc7".to_string();
"a78a89f0bbcba7d36c50d2b0ea8f3d3f6677b4b4ca76bd650eaf5836bed65b1c".to_string();

// create a task
app.execute_contract(
Expand Down
3 changes: 1 addition & 2 deletions contracts/cw-rules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ thiserror = { version = "1.0.31" }
# This thing saved our lives thanks @hashedone for implementing it
serde-cw-value = "0.7.0"

# TODO: update when this feature is merged
serde-json-wasm = { version = "0.4.1", git = "https://github.com/CyberHoward/serde-json-wasm", rev = "cdc78130b25d65981b74a5e4a10a9f8667292d36" }
serde-json-wasm = { version = "0.5.0" }

[dev-dependencies]
cw721-base = "0.15.0"
Expand Down
7 changes: 3 additions & 4 deletions packages/cw-croncat-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ cw20 = { version = "0.13.4" }
schemars = "0.8"
serde = { version = "1.0", default-features = false, features = ["derive"] }
thiserror = { version = "1.0" }
hex = "0.4"
sha2 = "0.10.6"
hex = { version = "0.4", default-features = false }
sha2 = { version = "0.10.6", default-features = false }
serde-cw-value = "0.7.0"
# TODO: update when this feature is merged
serde-json-wasm = { version = "0.4.1", git = "https://github.com/CyberHoward/serde-json-wasm", rev = "cdc78130b25d65981b74a5e4a10a9f8667292d36" }
serde-json-wasm = { version = "0.5.0" }

[dev-dependencies]
cosmwasm-schema = { version = "1.0.0" }
Expand Down
4 changes: 2 additions & 2 deletions packages/cw-croncat-core/src/tests/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,8 @@ fn hashing() {
};

let message = format!(
"{:?}{:?}{:?}{:?}{:?}",
task.owner_id, task.interval, task.boundary, task.actions, task.queries
"{:?}{:?}{:?}{:?}{:?}{:?}",
task.owner_id, task.interval, task.boundary, task.actions, task.queries, task.transforms
);

let hash = Sha256::digest(message.as_bytes());
Expand Down
9 changes: 7 additions & 2 deletions packages/cw-croncat-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,13 @@ impl Task {
/// Get the hash of a task based on parameters
pub fn to_hash(&self) -> String {
let message = format!(
"{:?}{:?}{:?}{:?}{:?}",
self.owner_id, self.interval, self.boundary, self.actions, self.queries
"{:?}{:?}{:?}{:?}{:?}{:?}",
self.owner_id,
self.interval,
self.boundary,
self.actions,
self.queries,
self.transforms
);

let hash = Sha256::digest(message.as_bytes());
Expand Down

0 comments on commit 3c9750a

Please sign in to comment.