Fix the balance checks for a funds transfer test
Your task
An AI agent wrote a test for transferFunds(from, to, amount) in your payments service. It mocked the database and asserted only that the call returned { success: true }, so a transfer that debits twice or credits nothing still passed. Your team now checks both balances after every transfer instead.
An assistant wrote transfer_violations(from_before_cents, to_before_cents, from_after_cents, to_after_cents, amount_cents). It is in the editor. It has a bug. Find it and fix it.
Input and output:
from_before_centsandto_before_cents: the sender's and the receiver's balances before the transfer, as integer cents.from_after_centsandto_after_cents: the same two balances after the transfer, as integer cents. Any balance can be negative.amount_cents: the amount the transfer was asked to move, as integer cents. It can be 0 or negative.- Return the list of violations, empty when the transfer is correct.
Rules the tests check:
- Run every check below, in this order, and add each one that applies:
invalid_amountwhenamount_centsis 0 or less.source_debit_wrongwhenfrom_after_centsis not exactlyfrom_before_centsminusamount_cents.destination_credit_wrongwhento_after_centsis not exactlyto_before_centsplusamount_cents.total_not_conservedwhen the two balances after do not add up to the same sum as the two balances before.source_overdrawnwhenfrom_after_centsis below 0.
invalid_amountdoes not stop the other checks. They still useamount_centsas given.
Examples
transfer_violations(from_before_cents: int, to_before_cents: int, from_after_cents: int, to_after_cents: int, amount_cents: int) -> list[str]Example 1
Input
transfer_violations(10000, 5000, 7500, 7500, 2500)Output
[]Example 2
Input
transfer_violations(10000, 5000, 7500, 5000, 2500)Output
["destination_credit_wrong", "total_not_conserved"]Example 3
Input
transfer_violations(10000, 5000, 10000, 5000, 2500)Output
["source_debit_wrong", "destination_credit_wrong"]