Skip to content

Commit

Permalink
Merge pull request #7 from noislabs/bump-nois-v0.6.0
Browse files Browse the repository at this point in the history
bump-nois-v0.6.0
  • Loading branch information
kaisbaccour committed Jan 1, 2023
2 parents fc125b7 + 061fc9e commit e5f0edf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
26 changes: 13 additions & 13 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion contracts/double-dice-roll/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ backtraces = ["cosmwasm-std/backtraces"]
library = []

[dependencies]
nois = "0.5.1"
nois = "0.6.0"

cosmwasm-std = "1.0.0"
cw-storage-plus = "0.13.2"
Expand Down
20 changes: 10 additions & 10 deletions contracts/double-dice-roll/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ pub fn execute(
match msg {
//RollDice should be called by a player who wants to roll the dice
ExecuteMsg::RollDice { job_id } => execute_roll_dice(deps, env, info, job_id),
//Receive should be called by the proxy contract. The proxy is forwarding the randomness from the nois chain to this contract.
ExecuteMsg::Receive { callback } => execute_receive(deps, env, info, callback),
//NoisReceive should be called by the proxy contract. The proxy is forwarding the randomness from the nois chain to this contract.
ExecuteMsg::NoisReceive { callback } => execute_receive(deps, env, info, callback),
}
}

Expand Down Expand Up @@ -108,9 +108,9 @@ pub fn execute_receive(
.map_err(|_| ContractError::InvalidRandomness)?;
//ints_in_range provides a list of random numbers following a uniform distribution within a range.
//in this case it will provide uniformly randomized numbers between 1 and 6
let [dice_outcome_1, dice_outcome_2] = ints_in_range(randomness, 1..=6);
let double_dice_outcome = ints_in_range(randomness, 2, 1, 6);
//summing the dice to fit the real double dice probability distribution from 2 to 12
let double_dice_outcome = dice_outcome_1 + dice_outcome_2;
let double_dice_outcome = double_dice_outcome.iter().sum();

//Preserve the immutability of the previous rounds.
//So that the player cannot retry and change history.
Expand Down Expand Up @@ -209,7 +209,7 @@ mod tests {
fn proxy_cannot_bring_an_existing_job_id() {
let mut deps = instantiate_proxy();

let msg = ExecuteMsg::Receive {
let msg = ExecuteMsg::NoisReceive {
callback: NoisCallback {
job_id: "round_1".to_string(),
randomness: HexBinary::from_hex(
Expand All @@ -221,7 +221,7 @@ mod tests {
let info = mock_info(PROXY_ADDRESS, &[]);
execute(deps.as_mut(), mock_env(), info, msg).unwrap();

let msg = ExecuteMsg::Receive {
let msg = ExecuteMsg::NoisReceive {
callback: NoisCallback {
job_id: "round_1".to_string(),
randomness: HexBinary::from_hex(
Expand All @@ -242,7 +242,7 @@ mod tests {
fn execute_receive_fails_for_invalid_randomness() {
let mut deps = instantiate_proxy();

let msg = ExecuteMsg::Receive {
let msg = ExecuteMsg::NoisReceive {
callback: NoisCallback {
job_id: "round_1".to_string(),
randomness: HexBinary::from_hex("ffffffff").unwrap(),
Expand All @@ -258,7 +258,7 @@ mod tests {
fn players_cannot_request_an_existing_job_id() {
let mut deps = instantiate_proxy();

let msg = ExecuteMsg::Receive {
let msg = ExecuteMsg::NoisReceive {
callback: NoisCallback {
job_id: "111".to_string(),
randomness: HexBinary::from_hex(
Expand All @@ -284,7 +284,7 @@ mod tests {
fn execute_receive_fails_for_wrong_sender() {
let mut deps = instantiate_proxy();

let msg = ExecuteMsg::Receive {
let msg = ExecuteMsg::NoisReceive {
callback: NoisCallback {
job_id: "123".to_string(),
randomness: HexBinary::from_hex(
Expand All @@ -301,7 +301,7 @@ mod tests {
fn execute_receive_works() {
let mut deps = instantiate_proxy();

let msg = ExecuteMsg::Receive {
let msg = ExecuteMsg::NoisReceive {
callback: NoisCallback {
job_id: "123".to_string(),
randomness: HexBinary::from_hex(
Expand Down
2 changes: 1 addition & 1 deletion contracts/double-dice-roll/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum ExecuteMsg {
RollDice { job_id: String },
//callback contains the randomness from drand (HexBinary) and job_id
//callback should only be allowed to be called by the proxy contract
Receive { callback: NoisCallback },
NoisReceive { callback: NoisCallback },
}

#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
Expand Down

0 comments on commit e5f0edf

Please sign in to comment.