From d25da746c5d9cb413ddf379a888600f70e012240 Mon Sep 17 00:00:00 2001 From: Kais Date: Mon, 24 Apr 2023 12:41:05 -0300 Subject: [PATCH] bump-nois-crate-to-v0.7.0 --- Cargo.lock | 4 ++-- contracts/double-dice-roll/Cargo.toml | 2 +- contracts/double-dice-roll/src/contract.rs | 21 ++++++++++++++++----- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e07eddd..0d2f3c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -404,9 +404,9 @@ checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" [[package]] name = "nois" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92b4f3482c5e189a5a51eb2ae3e54ddd58e7f5f63a3cb176b2d6f8709a875ce2" +checksum = "3f2f7aff53bda03e2f301e6a53aa4e76bb992b599c3163a3f18c1d3169e6341a" dependencies = [ "cosmwasm-schema", "cosmwasm-std", diff --git a/contracts/double-dice-roll/Cargo.toml b/contracts/double-dice-roll/Cargo.toml index b8b0d67..9b9972a 100644 --- a/contracts/double-dice-roll/Cargo.toml +++ b/contracts/double-dice-roll/Cargo.toml @@ -27,7 +27,7 @@ backtraces = ["cosmwasm-std/backtraces"] library = [] [dependencies] -nois = "0.6.0" +nois = "0.7.0" cosmwasm-std = "1.2.3" cosmwasm-schema = "1.2.3" diff --git a/contracts/double-dice-roll/src/contract.rs b/contracts/double-dice-roll/src/contract.rs index 26000aa..e514173 100644 --- a/contracts/double-dice-roll/src/contract.rs +++ b/contracts/double-dice-roll/src/contract.rs @@ -102,8 +102,13 @@ pub fn execute_receive( //callback should only be allowed to be called by the proxy contract //otherwise anyone can cut the randomness workflow and cheat the randomness by sending the randomness directly to this contract ensure_eq!(info.sender, proxy, ContractError::UnauthorizedReceive); - let randomness: [u8; 32] = callback - .randomness + + // In this Dapp we don't need the drand publish time. so we skip it with .. + let NoisCallback { + job_id, randomness, .. + } = callback; + + let randomness: [u8; 32] = randomness .to_array() .map_err(|_| ContractError::InvalidRandomness)?; //ints_in_range provides a list of random numbers following a uniform distribution within a range. @@ -114,11 +119,11 @@ pub fn execute_receive( //Preserve the immutability of the previous rounds. //So that the player cannot retry and change history. - let response = match DOUBLE_DICE_OUTCOME.may_load(deps.storage, &callback.job_id)? { + let response = match DOUBLE_DICE_OUTCOME.may_load(deps.storage, &job_id)? { None => Response::default(), Some(_randomness) => return Err(ContractError::JobIdAlreadyPresent), }; - DOUBLE_DICE_OUTCOME.save(deps.storage, &callback.job_id, &double_dice_outcome)?; + DOUBLE_DICE_OUTCOME.save(deps.storage, &job_id, &double_dice_outcome)?; Ok(response) } @@ -149,10 +154,10 @@ fn query_history(deps: Deps) -> StdResult> { #[cfg(test)] mod tests { use super::*; - use cosmwasm_std::coins; use cosmwasm_std::testing::{ mock_dependencies, mock_env, mock_info, MockApi, MockQuerier, MockStorage, }; + use cosmwasm_std::{coins, Timestamp}; use cosmwasm_std::{Empty, HexBinary, OwnedDeps}; const CREATOR: &str = "creator"; @@ -216,6 +221,7 @@ mod tests { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", ) .unwrap(), + published: Timestamp::from_seconds(1111111111), }, }; let info = mock_info(PROXY_ADDRESS, &[]); @@ -228,6 +234,7 @@ mod tests { "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", ) .unwrap(), + published: Timestamp::from_seconds(1111111111), }, }; let info = mock_info(PROXY_ADDRESS, &[]); @@ -246,6 +253,7 @@ mod tests { callback: NoisCallback { job_id: "round_1".to_string(), randomness: HexBinary::from_hex("ffffffff").unwrap(), + published: Timestamp::from_seconds(1111111111), }, }; let info = mock_info(PROXY_ADDRESS, &[]); @@ -265,6 +273,7 @@ mod tests { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", ) .unwrap(), + published: Timestamp::from_seconds(1111111111), }, }; let info = mock_info(PROXY_ADDRESS, &[]); @@ -291,6 +300,7 @@ mod tests { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", ) .unwrap(), + published: Timestamp::from_seconds(1111111111), }, }; let info = mock_info("guest", &[]); @@ -308,6 +318,7 @@ mod tests { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", ) .unwrap(), + published: Timestamp::from_seconds(1111111111), }, }; let info = mock_info(PROXY_ADDRESS, &[]);