Skip to content

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

@ohhalim

Description

@ohhalim

Branch Keyword

integration-test

구현할 기능

매칭 체결 시 BUY 측 정산 로직에 버그가 있어 수정하고, 핵심 시나리오에 대한 통합 테스트를 작성한다.

버그 내용 (SET-001)

현재 OrderService.settle()에서 BUY 주문 정산 시 buyerQuoteWallet.unlock(quoteAmount)를 사용하고 있어,
매수자에게 quoteAmount가 available로 반환되면서 동시에 판매자에게도 deposit되어 자산이 이중으로 생성되는 문제.

수정 내용

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

통합 테스트 시나리오

  • SET-001: BUY taker 가격 차이 환불 (체결가 < 주문가, 잔여 locked 반환 검증)
  • SET-001b: 부분 체결 반복 시 rounding 누적 검증
  • SET-002: SELL taker 정산
  • SET-005: self-trade mixed candidates (user1 주문이 호가창에 있을 때 user1 반대 주문 거부)
  • CAN-002: 부분 체결 후 취소 — lockedAmount 정확성 검증
  • MAT-001: 가격 우선순위 (3명 매도, 가장 낮은 가격부터 체결)
  • 불변식 검증: wallet 잔고 음수 불가, 오더북에 OPEN/PARTIALLY_FILLED 주문만 존재

API 명세

No response

테스트 계획

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions