
Bug hunt
Half a Transfer
The Guild's pay function moves coins between vaults. The vaults
table has CHECK (coins >= 0), so nobody can go below zero.
The bug report
- "Bram tried to pay me 50 coins with only 10 in his vault.
paysaidFalse, but I got the 50 coins anyway!", Wren - "Someone paid from a vault called
'Brahm'(typo). The coins appeared in my vault from nowhere.". Pip
The first UPDATE runs, then the second one fails or matches nothing, and the first change stays.
Assignment
Fix pay(conn, payer, payee, coins) so it is all or nothing:
- On success, both vaults change, the change is committed, and
payreturnsTrue. - If the payer can't afford it, or either vault doesn't exist,
nothing changes and
payreturnsFalse.
Use a with conn: block and check rowcount.
Fix pay(conn, payer, payee, coins) so it is all or nothing:
- On success, both vaults change, the change is committed, and
payreturnsTrue. - If the payer can't afford it, or either vault doesn't exist,
nothing changes and
payreturnsFalse.
Use a with conn: block and check rowcount.
main.py Python sleeping
Press Run to try your code, then Check to test it.