unconditional event and post in withdraw#1959
Conversation
## Walkthrough
The `withdraw2` function in `OrderBook.sol` was updated to emit the `Withdraw` event after the token transfer, ensuring the event is always emitted regardless of the withdrawal amount. Formatting and indentation of the post-processing logic were also adjusted for clarity, without altering functionality. Test contracts were enhanced to check for event emission even on zero or empty withdrawals and to handle expected revert errors with improved assertion messages.
## Changes
| File(s) | Change Summary |
|---------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
| src/concrete/ob/OrderBook.sol | Moved `Withdraw` event emission to after token transfer and outside conditional; adjusted formatting and indentation of post-processing logic. |
| test/concrete/ob/OrderBook.withdraw.entask.t.sol | Enhanced `checkWithdraw` with revert error handling and descriptive assertions; updated calls to handle conditional revert expectations and event checks. |
| test/concrete/ob/OrderBook.withdraw.t.sol | Updated `testWithdrawEmptyVault` to expect `Withdraw` event emission even on empty vault withdrawal; adjusted log assertions accordingly. |
## Sequence Diagram(s)
```mermaid
sequenceDiagram
participant User
participant OrderBook
participant Token
User->>OrderBook: Call withdraw2(amount, ...)
OrderBook->>OrderBook: Update vault balance
alt amount > 0
OrderBook->>Token: Transfer tokens to User
end
OrderBook->>User: Emit Withdraw event (always)
OrderBook->>OrderBook: Process post array (if any)Learnt from: rouzwelt Learnt from: rouzwelt Learnt from: rouzwelt Learnt from: rouzwelt Learnt from: rouzwelt Learnt from: rouzwelt Learnt from: rouzwelt Learnt from: rouzwelt Learnt from: rouzwelt Learnt from: rouzwelt Learnt from: hardingjam Learnt from: thedavidmeister Learnt from: hardingjam Learnt from: thedavidmeister Learnt from: hardingjam Learnt from: findolor Learnt from: findolor Learnt from: findolor Learnt from: hardingjam Learnt from: findolor Learnt from: findolor Learnt from: findolor Learnt from: hardingjam Learnt from: thedavidmeister Learnt from: findolor Learnt from: hardingjam Learnt from: findolor Learnt from: hardingjam Learnt from: findolor Learnt from: hardingjam Learnt from: hardingjam Learnt from: thedavidmeister Learnt from: findolor Learnt from: thedavidmeister Learnt from: findolor Learnt from: thedavidmeister Learnt from: hardingjam Learnt from: findolor Learnt from: findolor Learnt from: hardingjam Learnt from: hardingjam Learnt from: hardingjam Learnt from: findolor Learnt from: findolor Learnt from: hardingjam Learnt from: hardingjam Learnt from: hardingjam Learnt from: findolor |
Motivation
Solution
Checks
By submitting this for review, I'm confirming I've done the following:
Summary by CodeRabbit