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
22 changes: 22 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@ members = [
]
resolver = "2"

[workspace.lints.clippy]
# Pre-existing lint suppressions — these fire on code predating this PR.
len_zero = "allow"
unnecessary_cast = "allow"
useless_conversion = "allow"
question_mark = "allow"
manual_range_contains = "allow"
needless_range_loop = "allow"
bool_assert_comparison = "allow"
manual_is_multiple_of = "allow"
module_inception = "allow"
empty_line_after_outer_attr = "allow"
too_many_arguments = "allow"
upper_case_acronyms = "allow"
collapsible_if = "allow"
needless_borrows_for_generic_args = "allow"

[workspace.lints.rust]
dead_code = "allow"
unused_imports = "allow"
unused_variables = "allow"

[profile.release]
opt-level = "z"
overflow-checks = true
Expand Down
3 changes: 3 additions & 0 deletions contracts/atomic_swap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name = "atomic_swap"
version = "0.1.0"
edition = "2021"

[lints]
workspace = true

[lib]
crate-type = ["cdylib", "rlib"]

Expand Down
36 changes: 27 additions & 9 deletions contracts/atomic_swap/src/arbitration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ mod arbitration_tests {
}

fn setup_token(env: &Env, admin: &Address, recipient: &Address, amount: i128) -> Address {
let token_id = env.register_stellar_asset_contract_v2(admin.clone()).address();
let token_id = env
.register_stellar_asset_contract_v2(admin.clone())
.address();
StellarAssetClient::new(env, &token_id).mint(recipient, &amount);
token_id
}
Expand All @@ -39,7 +41,9 @@ mod arbitration_tests {
let client = AtomicSwapClient::new(env, &contract_id);
client.initialize(&registry_id);

let swap_id = client.initiate_swap(&token_id, &ip_id, &seller, &500_i128, &buyer, &0_u32, &None, &0_i128, &false);
let swap_id = client.initiate_swap(
&token_id, &ip_id, &seller, &500_i128, &buyer, &0_u32, &None, &0_i128, &false,
);
client.accept_swap(&swap_id);
client.raise_dispute(&swap_id);

Expand Down Expand Up @@ -95,7 +99,9 @@ mod arbitration_tests {
let client = AtomicSwapClient::new(&env, &contract_id);
client.initialize(&registry_id);

let swap_id = client.initiate_swap(&token_id, &ip_id, &seller, &500_i128, &buyer, &0_u32, &None, &0_i128, &false);
let swap_id = client.initiate_swap(
&token_id, &ip_id, &seller, &500_i128, &buyer, &0_u32, &None, &0_i128, &false,
);
// Swap is Pending, not Disputed — should panic
let admin = Address::generate(&env);
let arbitrator = Address::generate(&env);
Expand Down Expand Up @@ -253,7 +259,9 @@ mod arbitration_tests {
client.initialize(&registry_id);

// Initiate with flat price 500
let swap_id = client.initiate_swap(&token_id, &ip_id, &seller, &500_i128, &buyer, &0_u32, &None, &0_i128, &false);
let swap_id = client.initiate_swap(
&token_id, &ip_id, &seller, &500_i128, &buyer, &0_u32, &None, &0_i128, &false,
);

// Accept with quantity=1 (no tiers set, uses flat price)
client.accept_swap_with_quantity(&swap_id, &1_u32);
Expand All @@ -278,7 +286,9 @@ mod arbitration_tests {
let client = AtomicSwapClient::new(&env, &contract_id);
client.initialize(&registry_id);

let swap_id = client.initiate_swap(&token_id, &ip_id, &seller, &1000_i128, &buyer, &0_u32, &None, &0_i128, &false);
let swap_id = client.initiate_swap(
&token_id, &ip_id, &seller, &1000_i128, &buyer, &0_u32, &None, &0_i128, &false,
);
client.accept_swap_with_quantity(&swap_id, &5_u32);

let swap = client.get_swap(&swap_id).unwrap();
Expand Down Expand Up @@ -306,7 +316,9 @@ mod arbitration_tests {

// Initiate with price=1000, default quantity=1 — set quantity via initiate_swap
// then manually bump quantity to 10 by accepting partial
let swap_id = client.initiate_swap(&token_id, &ip_id, &seller, &1000_i128, &buyer, &0_u32, &None, &0_i128, &false);
let swap_id = client.initiate_swap(
&token_id, &ip_id, &seller, &1000_i128, &buyer, &0_u32, &None, &0_i128, &false,
);

// Patch quantity to 10 so partial acceptance makes sense
let mut swap = client.get_swap(&swap_id).unwrap();
Expand Down Expand Up @@ -342,7 +354,9 @@ mod arbitration_tests {
let client = AtomicSwapClient::new(&env, &contract_id);
client.initialize(&registry_id);

let swap_id = client.initiate_swap(&token_id, &ip_id, &seller, &500_i128, &buyer, &0_u32, &None, &0_i128, &false);
let swap_id = client.initiate_swap(
&token_id, &ip_id, &seller, &500_i128, &buyer, &0_u32, &None, &0_i128, &false,
);

// quantity=1 (default), accepting 1/1 = full price
client.accept_swap_partial(&swap_id, &1_u32);
Expand All @@ -368,7 +382,9 @@ mod arbitration_tests {
let client = AtomicSwapClient::new(&env, &contract_id);
client.initialize(&registry_id);

let swap_id = client.initiate_swap(&token_id, &ip_id, &seller, &500_i128, &buyer, &0_u32, &None, &0_i128, &false);
let swap_id = client.initiate_swap(
&token_id, &ip_id, &seller, &500_i128, &buyer, &0_u32, &None, &0_i128, &false,
);
client.accept_swap_partial(&swap_id, &0_u32);
}

Expand All @@ -388,7 +404,9 @@ mod arbitration_tests {
let client = AtomicSwapClient::new(&env, &contract_id);
client.initialize(&registry_id);

let swap_id = client.initiate_swap(&token_id, &ip_id, &seller, &500_i128, &buyer, &0_u32, &None, &0_i128, &false);
let swap_id = client.initiate_swap(
&token_id, &ip_id, &seller, &500_i128, &buyer, &0_u32, &None, &0_i128, &false,
);
// quantity=1 by default, requesting 2 should panic
client.accept_swap_partial(&swap_id, &2_u32);
}
Expand Down
60 changes: 29 additions & 31 deletions contracts/atomic_swap/src/batch_approval_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
mod batch_approval_tests {
use ip_registry::{IpRegistry, IpRegistryClient};
use soroban_sdk::{
testutils::Address as _,
token::StellarAssetClient,
Address, Bytes, BytesN, Env, Vec,
testutils::Address as _, token::StellarAssetClient, Address, Bytes, BytesN, Env, Vec,
};

use crate::{AtomicSwap, AtomicSwapClient, SwapStatus, ContractError, Error};
use crate::{AtomicSwap, AtomicSwapClient, ContractError, Error, SwapStatus};

fn setup_registry(env: &Env, owner: &Address) -> Address {
let registry_id = env.register(IpRegistry, ());
let _ = IpRegistryClient::new(env, &registry_id);
registry_id
}

fn commit_ip(env: &Env, registry_id: &Address, owner: &Address, seed: u8) -> (u64, BytesN<32>, BytesN<32>) {
fn commit_ip(
env: &Env,
registry_id: &Address,
owner: &Address,
seed: u8,
) -> (u64, BytesN<32>, BytesN<32>) {
let registry = IpRegistryClient::new(env, registry_id);
let secret = BytesN::from_array(env, &[seed; 32]);
let blinding = BytesN::from_array(env, &[seed.wrapping_add(0x80); 32]);
Expand All @@ -28,7 +31,9 @@ mod batch_approval_tests {
}

fn setup_token(env: &Env, admin: &Address, recipient: &Address, amount: i128) -> Address {
let token_id = env.register_stellar_asset_contract_v2(admin.clone()).address();
let token_id = env
.register_stellar_asset_contract_v2(admin.clone())
.address();
StellarAssetClient::new(env, &token_id).mint(recipient, &amount);
token_id
}
Expand Down Expand Up @@ -64,12 +69,11 @@ mod batch_approval_tests {
let mut prices = Vec::new(&env);
prices.push_back(1000i128);

let swap_ids = client.batch_initiate_swap(
&token_id, &ip_ids, &seller, &prices, &buyer, &1u32, &None,
);
let swap_ids =
client.batch_initiate_swap(&token_id, &ip_ids, &seller, &prices, &buyer, &1u32, &None);

let swap_id = swap_ids.get(0).unwrap();

// Approve with required approvals = 1
client.approve_swap(&swap_id, &approver1);

Expand Down Expand Up @@ -103,9 +107,8 @@ mod batch_approval_tests {
let mut prices = Vec::new(&env);
prices.push_back(1000i128);

let swap_ids = client.batch_initiate_swap(
&token_id, &ip_ids, &seller, &prices, &buyer, &3u32, &None,
);
let swap_ids =
client.batch_initiate_swap(&token_id, &ip_ids, &seller, &prices, &buyer, &3u32, &None);

let swap_id = swap_ids.get(0).unwrap();

Expand Down Expand Up @@ -143,19 +146,18 @@ mod batch_approval_tests {
let mut prices = Vec::new(&env);
prices.push_back(1000i128);

let swap_ids = client.batch_initiate_swap(
&token_id, &ip_ids, &seller, &prices, &buyer, &2u32, &None,
);
let swap_ids =
client.batch_initiate_swap(&token_id, &ip_ids, &seller, &prices, &buyer, &2u32, &None);

let swap_id = swap_ids.get(0).unwrap();

client.approve_swap(&swap_id, &approver);

// Second approval from same approver should fail
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
client.approve_swap(&swap_id, &approver);
}));

assert!(result.is_err());
}

Expand All @@ -182,9 +184,8 @@ mod batch_approval_tests {
let mut prices = Vec::new(&env);
prices.push_back(1000i128);

let swap_ids = client.batch_initiate_swap(
&token_id, &ip_ids, &seller, &prices, &buyer, &1u32, &None,
);
let swap_ids =
client.batch_initiate_swap(&token_id, &ip_ids, &seller, &prices, &buyer, &1u32, &None);

let swap_id = swap_ids.get(0).unwrap();

Expand All @@ -197,7 +198,7 @@ mod batch_approval_tests {
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
client.approve_swap(&swap_id, &approver);
}));

assert!(result.is_err());
}

Expand Down Expand Up @@ -230,9 +231,8 @@ mod batch_approval_tests {
prices.push_back(2000i128);
prices.push_back(3000i128);

let swap_ids = client.batch_initiate_swap(
&token_id, &ip_ids, &seller, &prices, &buyer, &1u32, &None,
);
let swap_ids =
client.batch_initiate_swap(&token_id, &ip_ids, &seller, &prices, &buyer, &1u32, &None);

// Approve each swap
for i in 0..swap_ids.len() {
Expand Down Expand Up @@ -272,9 +272,8 @@ mod batch_approval_tests {
let mut prices = Vec::new(&env);
prices.push_back(1000i128);

let swap_ids = client.batch_initiate_swap(
&token_id, &ip_ids, &seller, &prices, &buyer, &1u32, &None,
);
let swap_ids =
client.batch_initiate_swap(&token_id, &ip_ids, &seller, &prices, &buyer, &1u32, &None);

let swap_id = swap_ids.get(0).unwrap();

Expand Down Expand Up @@ -320,9 +319,8 @@ mod batch_approval_tests {
let mut prices = Vec::new(&env);
prices.push_back(1000i128);

let swap_ids = client.batch_initiate_swap(
&token_id, &ip_ids, &seller, &prices, &buyer, &1u32, &None,
);
let swap_ids =
client.batch_initiate_swap(&token_id, &ip_ids, &seller, &prices, &buyer, &1u32, &None);

let swap_id = swap_ids.get(0).unwrap();

Expand Down
Loading
Loading