From 4f538c3c31def83c0d8e71660ec38ce90708fc5c Mon Sep 17 00:00:00 2001 From: Jose Garcia Crosta Date: Wed, 20 Dec 2023 11:20:55 -0300 Subject: [PATCH] Update tests --- .../remediated-example/src/lib.rs | 10 +++++++--- .../vulnerable-example/src/lib.rs | 10 +++++++--- .../remediated-example/src/lib.rs | 10 +++++++--- .../vulnerable-example/src/lib.rs | 10 +++++++--- .../remediated-example/src/lib.rs | 10 +++++++--- .../vulnerable-example/src/lib.rs | 6 ++++-- 6 files changed, 39 insertions(+), 17 deletions(-) diff --git a/test-cases/dos-unbounded-operation/dos-unbounded-operation-1/remediated-example/src/lib.rs b/test-cases/dos-unbounded-operation/dos-unbounded-operation-1/remediated-example/src/lib.rs index 5693404d..99e91cbe 100644 --- a/test-cases/dos-unbounded-operation/dos-unbounded-operation-1/remediated-example/src/lib.rs +++ b/test-cases/dos-unbounded-operation/dos-unbounded-operation-1/remediated-example/src/lib.rs @@ -19,15 +19,19 @@ impl DosUnboundedOperation { #[cfg(test)] mod tests { - use crate::DosUnboundedOperation; + use soroban_sdk::Env; + + use crate::{DosUnboundedOperation, DosUnboundedOperationClient}; #[test] fn test_for_loop() { // Given - // .. + let env = Env::default(); + let contract_id = env.register_contract(None, DosUnboundedOperation); + let client = DosUnboundedOperationClient::new(&env, &contract_id); // When - let count = DosUnboundedOperation::restricted_loop_with_const(); + let count = client.restricted_loop_with_const(); // Then assert_eq!(count, 499500); diff --git a/test-cases/dos-unbounded-operation/dos-unbounded-operation-1/vulnerable-example/src/lib.rs b/test-cases/dos-unbounded-operation/dos-unbounded-operation-1/vulnerable-example/src/lib.rs index 3f4a8233..33c1c9d7 100644 --- a/test-cases/dos-unbounded-operation/dos-unbounded-operation-1/vulnerable-example/src/lib.rs +++ b/test-cases/dos-unbounded-operation/dos-unbounded-operation-1/vulnerable-example/src/lib.rs @@ -17,16 +17,20 @@ impl DosUnboundedOperation { #[cfg(test)] mod tests { - use crate::DosUnboundedOperation; + use soroban_sdk::Env; + + use crate::{DosUnboundedOperation, DosUnboundedOperationClient}; #[test] fn test_for_loop() { // Given - // .. + let env = Env::default(); + let contract_id = env.register_contract(None, DosUnboundedOperation); + let client = DosUnboundedOperationClient::new(&env, &contract_id); // When let for_loop_count = 1000; - let count = DosUnboundedOperation::unrestricted_loop(for_loop_count); + let count = client.unrestricted_loop(&for_loop_count); // Then assert_eq!(count, 499500); diff --git a/test-cases/dos-unbounded-operation/dos-unbounded-operation-2/remediated-example/src/lib.rs b/test-cases/dos-unbounded-operation/dos-unbounded-operation-2/remediated-example/src/lib.rs index 080c6a40..2427509a 100644 --- a/test-cases/dos-unbounded-operation/dos-unbounded-operation-2/remediated-example/src/lib.rs +++ b/test-cases/dos-unbounded-operation/dos-unbounded-operation-2/remediated-example/src/lib.rs @@ -24,15 +24,19 @@ impl DosUnboundedOperation { #[cfg(test)] mod tests { - use crate::DosUnboundedOperation; + use soroban_sdk::Env; + + use crate::{DosUnboundedOperation, DosUnboundedOperationClient}; #[test] fn test_for_loop() { // Given - // ... + let env = Env::default(); + let contract_id = env.register_contract(None, DosUnboundedOperation); + let client = DosUnboundedOperationClient::new(&env, &contract_id); // When - let count = DosUnboundedOperation::safe_loop_with_struct(); + let count = client.safe_loop_with_struct(); // Then assert_eq!(count, 499500); diff --git a/test-cases/dos-unbounded-operation/dos-unbounded-operation-2/vulnerable-example/src/lib.rs b/test-cases/dos-unbounded-operation/dos-unbounded-operation-2/vulnerable-example/src/lib.rs index d21a49d7..15876b18 100644 --- a/test-cases/dos-unbounded-operation/dos-unbounded-operation-2/vulnerable-example/src/lib.rs +++ b/test-cases/dos-unbounded-operation/dos-unbounded-operation-2/vulnerable-example/src/lib.rs @@ -23,16 +23,20 @@ impl DosUnboundedOperation { #[cfg(test)] mod tests { - use crate::{DosUnboundedOperation, KnownData}; + use soroban_sdk::Env; + + use crate::{DosUnboundedOperation, DosUnboundedOperationClient, KnownData}; #[test] fn test_for_loop() { // Given - // ... + let env = Env::default(); + let contract_id = env.register_contract(None, DosUnboundedOperation); + let client = DosUnboundedOperationClient::new(&env, &contract_id); // When let unknown_data = KnownData { fixed_value: 1000 }; - let count = DosUnboundedOperation::unsafe_loop_with_struct(unknown_data); + let count = client.unsafe_loop_with_struct(&unknown_data); // Then assert_eq!(count, 499500); diff --git a/test-cases/dos-unbounded-operation/dos-unbounded-operation-3/remediated-example/src/lib.rs b/test-cases/dos-unbounded-operation/dos-unbounded-operation-3/remediated-example/src/lib.rs index 12899788..b10e7675 100644 --- a/test-cases/dos-unbounded-operation/dos-unbounded-operation-3/remediated-example/src/lib.rs +++ b/test-cases/dos-unbounded-operation/dos-unbounded-operation-3/remediated-example/src/lib.rs @@ -19,15 +19,19 @@ impl DosUnboundedOperation { #[cfg(test)] mod tests { - use crate::DosUnboundedOperation; + use soroban_sdk::Env; + + use crate::{DosUnboundedOperation, DosUnboundedOperationClient}; #[test] fn test_for_loop() { // Given - // ... + let env = Env::default(); + let contract_id = env.register_contract(None, DosUnboundedOperation); + let client = DosUnboundedOperationClient::new(&env, &contract_id); // When - let count = DosUnboundedOperation::safe_loop_with_array(); + let count = client.safe_loop_with_array(); // Then assert_eq!(count, 28); diff --git a/test-cases/dos-unbounded-operation/dos-unbounded-operation-3/vulnerable-example/src/lib.rs b/test-cases/dos-unbounded-operation/dos-unbounded-operation-3/vulnerable-example/src/lib.rs index f4c77c35..7d6e4b20 100644 --- a/test-cases/dos-unbounded-operation/dos-unbounded-operation-3/vulnerable-example/src/lib.rs +++ b/test-cases/dos-unbounded-operation/dos-unbounded-operation-3/vulnerable-example/src/lib.rs @@ -20,16 +20,18 @@ mod tests { use soroban_sdk::{BytesN, Env}; - use crate::DosUnboundedOperation; + use crate::{DosUnboundedOperation, DosUnboundedOperationClient}; #[test] fn test_for_loop() { // Given let env = Env::default(); + let contract_id = env.register_contract(None, DosUnboundedOperation); + let client = DosUnboundedOperationClient::new(&env, &contract_id); // When let unknown_array = BytesN::from_array(&env, &[0; 8]); - let count = DosUnboundedOperation::unsafe_loop_with_array(unknown_array); + let count = client.unsafe_loop_with_array(&unknown_array); // Then assert_eq!(count, 28);