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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
36 changes: 32 additions & 4 deletions app/contract/contracts/quickex/src/bench_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,16 @@ fn bench_deposit() {

// --- Reset budget immediately before the hot path ---
env.cost_estimate().budget().reset_default();
let _ = client.deposit(&token, &amount, &owner, &salt, &0u64, &None);
let _ = client.deposit(
&token,
&amount,
&owner,
&salt,
&0u64,
&None,
&0u64,
&u64::MAX,
);
print_budget(&env, "deposit");
}

Expand All @@ -190,7 +199,16 @@ fn bench_deposit_with_commitment() {

// --- Reset budget immediately before the hot path ---
env.cost_estimate().budget().reset_default();
client.deposit_with_commitment(&from, &token, &amount, &commitment, &0u64, &None);
client.deposit_with_commitment(
&from,
&token,
&amount,
&commitment,
&0u64,
&None,
&0u64,
&u64::MAX,
);
print_budget(&env, "deposit_with_commitment");
}

Expand Down Expand Up @@ -219,7 +237,15 @@ fn bench_withdraw() {

// --- Reset budget immediately before the hot path ---
env.cost_estimate().budget().reset_default();
client.withdraw(&token, &amount, &commitment, &owner, &salt);
client.withdraw(
&token,
&amount,
&commitment,
&owner,
&salt,
&0u64,
&u64::MAX,
);
print_budget(&env, "withdraw");
}

Expand Down Expand Up @@ -372,12 +398,14 @@ fn bench_resolve_dispute_recipient() {
&salt,
&1000u64,
&Some(arbiter.clone()),
&0u64,
&u64::MAX,
);
client.dispute(&commitment);

// --- Reset budget immediately before the hot path ---
env.cost_estimate().budget().reset_default();
client.resolve_dispute(&arbiter, &commitment, &false, &recipient);
client.resolve_dispute(&arbiter, &commitment, &false, &recipient, &0u64, &u64::MAX);
print_budget(&env, "resolve_dispute_recipient");
}

Expand Down
32 changes: 22 additions & 10 deletions app/contract/contracts/quickex/src/coverage_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn test_deposit_with_commitment_duplicate_fails() {

// First deposit succeeds
ctx.client
.deposit_with_commitment(&ctx.alice, &ctx.token, &500, &commitment, &0, &None);
.deposit_with_commitment(&ctx.alice, &ctx.token, &500, &commitment, &0, &None, &0u64, &u64::MAX);

// Second deposit with the same commitment must fail
ctx.mint(&ctx.alice.clone(), 500);
Expand All @@ -115,6 +115,8 @@ fn test_deposit_with_commitment_duplicate_fails() {
&commitment,
&0,
&None,
&0u64,
&u64::MAX,
),
QuickexError::CommitmentAlreadyExists,
);
Expand All @@ -134,6 +136,8 @@ fn test_deposit_with_commitment_with_arbiter_stores_arbiter() {
&commitment,
&0,
&Some(ctx.arbiter.clone()),
&0u64,
&u64::MAX,
);

assert_escrow_pending(&ctx.client, &commitment);
Expand All @@ -153,7 +157,7 @@ fn test_deposit_with_commitment_zero_amount_fails() {
let commitment = BytesN::from_array(&ctx.env, &[0x01u8; 32]);
assert_qx_err(
ctx.client
.try_deposit_with_commitment(&ctx.alice, &ctx.token, &0, &commitment, &0, &None),
.try_deposit_with_commitment(&ctx.alice, &ctx.token, &0, &commitment, &0, &None, &0u64, &u64::MAX),
QuickexError::InvalidAmount,
);
}
Expand All @@ -177,6 +181,8 @@ fn test_deposit_with_commitment_paused_feature_fails() {
&commitment,
&0,
&None,
&0u64,
&u64::MAX,
),
QuickexError::OperationPaused,
);
Expand All @@ -194,7 +200,7 @@ fn test_refund_never_expiring_escrow_fails() {

// expires_at == 0 means the escrow never expires → refund must be rejected
assert_qx_err(
ctx.client.try_refund(&commitment, &ctx.alice),
ctx.client.try_refund(&commitment, &ctx.alice, &0u64, &u64::MAX),
QuickexError::EscrowNotExpired,
);
}
Expand All @@ -211,11 +217,13 @@ fn test_refund_before_timeout_window_fails() {
&ctx.salt(b"timed_refund"),
&3600,
&None,
&0u64,
&u64::MAX,
);

// Time has not advanced — refund is not yet available
assert_qx_err(
ctx.client.try_refund(&commitment, &ctx.alice),
ctx.client.try_refund(&commitment, &ctx.alice, &0u64, &u64::MAX),
QuickexError::EscrowNotExpired,
);
}
Expand All @@ -237,6 +245,8 @@ fn test_verify_proof_view_expired_returns_false() {
&ctx.salt(b"proof_exp"),
&timeout,
&None,
&0u64,
&u64::MAX,
);

// Advance past expiry
Expand Down Expand Up @@ -267,6 +277,8 @@ fn test_assert_helpers_pending_and_spent() {
&commitment,
&ctx.alice,
&ctx.salt(b"h_pending"),
&0u64,
&u64::MAX,
);
assert_escrow_spent(&ctx.client, &commitment);
}
Expand All @@ -281,7 +293,7 @@ fn test_assert_helpers_disputed_and_refunded() {
assert_escrow_disputed(&ctx.client, &commitment);

// Resolve for owner → Refunded
ctx.client.resolve_dispute(&commitment, &true, &ctx.bob);
ctx.client.resolve_dispute(&commitment, &true, &ctx.bob, &0u64, &u64::MAX);
assert_escrow_refunded(&ctx.client, &commitment);
}

Expand Down Expand Up @@ -312,7 +324,7 @@ fn test_demo_full_lifecycle_under_10_lines() {
let c = ctx.simple_deposit(&ctx.alice.clone(), 1_000, b"ten"); // 2
assert_escrow_pending(&ctx.client, &c); // 3
ctx.client
.withdraw(&ctx.token, &1_000, &c, &ctx.alice, &ctx.salt(b"ten")); // 4
.withdraw(&ctx.token, &1_000, &c, &ctx.alice, &ctx.salt(b"ten"), &0u64, &u64::MAX); // 4
assert_escrow_spent(&ctx.client, &c); // 5
assert_eq!(ctx.balance(&ctx.alice), 1_000); // 6
}
Expand All @@ -334,7 +346,7 @@ fn test_demo_fee_withdrawal_under_10_lines() {
let ctx = TestContext::with_fees(1000); // 1 (10%)
let c = ctx.simple_deposit(&ctx.alice.clone(), 1_000, b"fee_10"); // 2
ctx.client
.withdraw(&ctx.token, &1_000, &c, &ctx.alice, &ctx.salt(b"fee_10")); // 3
.withdraw(&ctx.token, &1_000, &c, &ctx.alice, &ctx.salt(b"fee_10"), &0u64, &u64::MAX); // 3
assert_eq!(ctx.balance(&ctx.alice), 900); // 4
assert_eq!(ctx.balance(&ctx.platform_wallet), 100); // 5
}
Expand All @@ -346,7 +358,7 @@ fn test_demo_dispute_flow_under_10_lines() {
let c = ctx.deposit_with_arbiter(&ctx.alice.clone(), 2_000, b"dp10", 3600); // 2
ctx.client.dispute(&c); // 3
assert_escrow_disputed(&ctx.client, &c); // 4
ctx.client.resolve_dispute(&c, &false, &ctx.bob); // 5 (pay bob)
ctx.client.resolve_dispute(&c, &false, &ctx.bob, &0u64, &u64::MAX); // 5 (pay bob)
assert_escrow_spent(&ctx.client, &c); // 6
assert_eq!(ctx.balance(&ctx.bob), 2_000); // 7
}
Expand All @@ -358,9 +370,9 @@ fn test_demo_expiry_and_refund_under_10_lines() {
ctx.mint(&ctx.alice.clone(), 500); // 2
let c = ctx
.client
.deposit(&ctx.token, &500, &ctx.alice, &ctx.salt(b"exp"), &100, &None); // 3
.deposit(&ctx.token, &500, &ctx.alice, &ctx.salt(b"exp"), &100, &None, &0u64, &u64::MAX); // 3
ctx.advance_time(101); // 4
ctx.client.refund(&c, &ctx.alice); // 5
ctx.client.refund(&c, &ctx.alice, &0u64, &u64::MAX); // 5
assert_escrow_refunded(&ctx.client, &c); // 6
assert_eq!(ctx.balance(&ctx.alice), 500); // 7
}
Expand Down
Loading
Loading