From ffbf75f698e8c5d0a27db21ec718f14e1238407f Mon Sep 17 00:00:00 2001 From: Jose Garcia Crosta Date: Fri, 1 Dec 2023 11:49:46 -0300 Subject: [PATCH] Clean remediated test-case imports and move tests --- .../remediated-example/Cargo.toml | 2 +- .../remediated-example/src/lib.rs | 30 +++++++++++++++++-- .../remediated-example/src/test.rs | 24 --------------- 3 files changed, 29 insertions(+), 27 deletions(-) delete mode 100644 test-cases/insufficiently-random-values/insufficiently-random-values-1/remediated-example/src/test.rs diff --git a/test-cases/insufficiently-random-values/insufficiently-random-values-1/remediated-example/Cargo.toml b/test-cases/insufficiently-random-values/insufficiently-random-values-1/remediated-example/Cargo.toml index a0a63b5d..99e57ca8 100644 --- a/test-cases/insufficiently-random-values/insufficiently-random-values-1/remediated-example/Cargo.toml +++ b/test-cases/insufficiently-random-values/insufficiently-random-values-1/remediated-example/Cargo.toml @@ -28,4 +28,4 @@ lto = true [profile.release-with-logs] inherits = "release" -debug-assertions = true \ No newline at end of file +debug-assertions = true diff --git a/test-cases/insufficiently-random-values/insufficiently-random-values-1/remediated-example/src/lib.rs b/test-cases/insufficiently-random-values/insufficiently-random-values-1/remediated-example/src/lib.rs index 145e43bd..a05d3ed3 100644 --- a/test-cases/insufficiently-random-values/insufficiently-random-values-1/remediated-example/src/lib.rs +++ b/test-cases/insufficiently-random-values/insufficiently-random-values-1/remediated-example/src/lib.rs @@ -1,6 +1,6 @@ #![no_std] -use soroban_sdk::{contract, contracterror, contractimpl, symbol_short, vec, Env, Symbol, Vec}; +use soroban_sdk::{contract, contracterror, contractimpl, Env}; #[contracterror] #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] @@ -25,4 +25,30 @@ impl Contract { } #[cfg(test)] -mod test; +mod test { + use soroban_sdk::Env; + + use crate::{Contract, ContractClient}; + + #[test] + fn random_value_sequence() { + // Given + let env = Env::default(); + let contract_id = env.register_contract(None, Contract); + let client = ContractClient::new(&env, &contract_id); + + // When + let first_random_value = client.generate_random_value(&10); + let second_random_value = client.generate_random_value(&10); + let third_random_value = client.generate_random_value(&10); + let fourth_random_value = client.generate_random_value(&10); + let fifth_random_value = client.generate_random_value(&10); + + // Then + assert_eq!(first_random_value, 6); + assert_eq!(second_random_value, 5); + assert_eq!(third_random_value, 8); + assert_eq!(fourth_random_value, 8); + assert_eq!(fifth_random_value, 4); + } +} diff --git a/test-cases/insufficiently-random-values/insufficiently-random-values-1/remediated-example/src/test.rs b/test-cases/insufficiently-random-values/insufficiently-random-values-1/remediated-example/src/test.rs deleted file mode 100644 index 35f42f89..00000000 --- a/test-cases/insufficiently-random-values/insufficiently-random-values-1/remediated-example/src/test.rs +++ /dev/null @@ -1,24 +0,0 @@ -extern crate std; - -use std::dbg; - -use soroban_sdk::{ - symbol_short, - testutils::{Ledger, LedgerInfo}, - vec, Bytes, Env, -}; - -use crate::{Contract, ContractClient}; - -#[test] -fn random_value_sequence() { - let env = Env::default(); - let contract_id = env.register_contract(None, Contract); - let client = ContractClient::new(&env, &contract_id); - - assert_eq!(client.generate_random_value(&10), 6); - assert_eq!(client.generate_random_value(&10), 5); - assert_eq!(client.generate_random_value(&10), 8); - assert_eq!(client.generate_random_value(&10), 8); - assert_eq!(client.generate_random_value(&10), 4); -}