Skip to content

Feat/16/integration test 정산 버그 수정 및 매칭·정산 통합 테스트#17

Merged
ohhalim merged 2 commits into
developfrom
feat/16/integration-test
May 14, 2026
Merged

Feat/16/integration test 정산 버그 수정 및 매칭·정산 통합 테스트#17
ohhalim merged 2 commits into
developfrom
feat/16/integration-test

Conversation

@ohhalim
Copy link
Copy Markdown
Owner

@ohhalim ohhalim commented May 14, 2026

Summary

  • BUY 측 체결 정산 로직 버그 수정 (자산 이중 생성 문제)
  • 매칭·정산 시나리오 통합 테스트 7개 추가 (전체 통과)

변경 내용

버그 수정

기존 buyerQuoteWallet.unlock(quoteAmount) 호출이 매수자에게 quoteAmount를 반환하면서
동시에 매도자에도 deposit되어 자산이 이중 생성되는 문제를 수정

  • Wallet.consumeLocked() 추가 — locked만 차감, available 반환 없음
  • Order.fill() — 체결마다 lockedAmount 갱신 (amountScale 적용)
  • Order.releasableAmount() — lockedAmount 직접 반환으로 단순화
  • Order.cancel() — lockedAmount = ZERO 처리
  • OrderService.settle() — buyerReleased / buyerRefund 정확하게 계산

통합 테스트

테스트 검증 내용
SET-001 BUY taker 체결가 낮을 때 환불 검증
SET-001b 부분 체결 반복 시 환불 누적 검증
SET-002 SELL taker 정산 정확성
SET-005 self-trade mixed candidates 거절
CAN-002 부분 체결 후 취소 lockedAmount 정확성
MAT-001 가격 우선순위 체결
INVARIANT 체결 후 모든 지갑 잔고 음수 불가

Test plan

  • MatchingSettlementTest 7개 테스트 전체 통과
  • 기존 OrderApiTest 회귀 없음
  • [ ]

관련 이슈

closes #16

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved order settlement precision with enhanced amount scaling and rounding
    • Refined locked fund tracking and refund calculations during trades
  • Tests

    • Added comprehensive integration tests validating order matching, settlement scenarios, and wallet balance consistency across various trading conditions

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b3b6aa30-4eaa-4f22-80d5-fbac0ef7b40b

📥 Commits

Reviewing files that changed from the base of the PR and between 31902c7 and fa70a21.

📒 Files selected for processing (4)
  • src/main/java/com/coinflow/order/domain/Order.java
  • src/main/java/com/coinflow/order/service/OrderService.java
  • src/main/java/com/coinflow/wallet/domain/Wallet.java
  • src/test/java/com/coinflow/integration/MatchingSettlementTest.java

📝 Walkthrough

Walkthrough

This PR fixes a double-asset bug in buy-side settlement by refactoring locked-amount tracking: Order now recalculates locked amounts per side during fills with proper rounding; Wallet adds consumeLocked() to decouple locked consumption from refunds; OrderService computes buyer refunds from locked-amount deltas instead of quote amounts. Comprehensive integration tests validate settlement scenarios and invariants.

Changes

Settlement Logic Bug Fix

Layer / File(s) Summary
Order domain updates for locked-amount tracking
src/main/java/com/coinflow/order/domain/Order.java
fill() signature updated to accept amountScale; BUY-side recalculates lockedAmount from price * remainingQuantity with RoundingMode.CEILING; non-BUY side decrements lockedAmount by filled quantity; releasableAmount() simplified to return lockedAmount directly; cancel() zeroes lockedAmount.
Wallet locked-fund consumption method
src/main/java/com/coinflow/wallet/domain/Wallet.java
New consumeLocked(BigDecimal amount) method explicitly decrements lockedBalance without returning funds to availableBalance, enabling separation of locked consumption from refund deposits.
OrderService settlement refactor using computed buyer deltas
src/main/java/com/coinflow/order/service/OrderService.java
settle() captures buy order's pre-fill locked amount, fills both maker and taker using market's amountScale, computes buyerReleased from locked-amount delta, calculates buyerRefund as buyerReleased - result.quoteAmount(), updates buyer wallet via consumeLocked() and conditional deposit() for refunds, and records ledger with computed delta values instead of direct quoteAmount.
Integration tests for settlement scenarios and invariants
src/test/java/com/coinflow/integration/MatchingSettlementTest.java
Spring Boot integration test suite exercising seven settlement scenarios: buy-taker refund from execution below order price; accumulated rounding across partial fills; sell-taker settlement at matching prices; self-trade prevention; partial-fill-then-cancel locked-amount release; price-priority matching; wallet balance non-negativity invariant. Includes helpers for authentication, wallet operations, and order lifecycle.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • ohhalim/CoinFlow#9: Modifies core matching/settlement flow with Order.fill() and OrderService.settle() wallet accounting changes that directly build upon the initial match/settle implementation.

Poem

🐰 A locked amount's dance, now precise and serene,
No double-release coins, just consumption so clean!
With ceiling and delta, the balance rings true,
Integration tests prove: refunds work as they should do! 🪙✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/16/integration-test

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ohhalim ohhalim merged commit 9563e93 into develop May 14, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat]: 정산 로직 버그 수정 및 통합 테스트 작성

1 participant