Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions quantara/soroban/contracts/Cargo.lock

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

1 change: 1 addition & 0 deletions quantara/soroban/contracts/looping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ soroban-sdk = { version = "22.0.0" }
common = { path = "../common", version = "0.1.0" }

[dev-dependencies]
proptest = "1.4.0"
soroban-sdk = { version = "22.0.0", features = ["testutils"] }
ed25519-dalek = "<3"
rand_core = "<0.7"
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! cargo-fuzz harness for LoopingContract::open_position entry-point.
//!
//! Invariants checked:
//! - Valid inputs (collateral > 0, leverage 100–500) must succeed.
//! - Valid inputs (collateral_amount > 0, debt_amount >= 0, leverage 100–500)
//! must succeed.
//! - Returned position IDs are >= 1.
//!
//! Run:
Expand All @@ -16,16 +17,19 @@ use soroban_sdk::{testutils::Address as _, Address, Env, IntoVal, Symbol};
use looping::LoopingContract;

fuzz_target!(|data: &[u8]| {
if data.len() < 12 {
if data.len() < 20 {
return;
}
let collateral = i64::from_le_bytes(data[..8].try_into().unwrap()) as i128;
let leverage = u32::from_le_bytes(data[8..12].try_into().unwrap());
let collateral_amount = i64::from_le_bytes(data[..8].try_into().unwrap()) as i128;
let debt_amount = i64::from_le_bytes(data[8..16].try_into().unwrap()) as i128;
let leverage = u32::from_le_bytes(data[16..20].try_into().unwrap());

let env = Env::default();
env.mock_all_auths();
let contract_id = env.register(LoopingContract, ());
let user = Address::generate(&env);
let collateral_asset = Address::generate(&env);
let debt_asset = Address::generate(&env);

// try_invoke_contract returns `Result<Result<u64, ContractError>, HostError>`;
// explicitly specify the host error type so type inference succeeds.
Expand All @@ -35,12 +39,15 @@ fuzz_target!(|data: &[u8]| {
soroban_sdk::vec![
&env,
user.to_val(),
collateral.into_val(&env),
collateral_asset.to_val(),
collateral_amount.into_val(&env),
debt_asset.to_val(),
debt_amount.into_val(&env),
leverage.into_val(&env),
],
);

if collateral > 0 && (100..=500).contains(&leverage) {
if collateral_amount > 0 && debt_amount >= 0 && (100..=500).contains(&leverage) {
// Unwrap the outer (host) Err first, then the inner (contract) Err.
let position_id = result
.expect("open_position returned a host error")
Expand Down
Loading
Loading