From 97d125122c3306e5725176c6f8b56224a2a0d5c0 Mon Sep 17 00:00:00 2001 From: reform Date: Sat, 31 Oct 2026 03:19:14 +0300 Subject: [PATCH] Fix duel double refund on expiry; idempotent weekly top-referrer prizes Co-Authored-By: Claude Opus 5.5 --- bot/grok_bot.py | 4 ++-- tests/test_econ_refund_refs.py | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tests/test_econ_refund_refs.py diff --git a/bot/grok_bot.py b/bot/grok_bot.py index 7e55d6b5..1d93d49a 100644 --- a/bot/grok_bot.py +++ b/bot/grok_bot.py @@ -5662,7 +5662,7 @@ async def econ_worker(bot): for r in con.execute("SELECT id,challenger,units FROM duels WHERE status='expired' AND created>=? AND created= 3 and isinstance(node.args[2], ast.Constant) + and node.args[2].value == type_): + yield node + + +class RefundRefTest(unittest.TestCase): + def test_duel_expire_refunds_are_idempotent(self): + calls = list(_calls("duel:expire")) + self.assertGreaterEqual(len(calls), 3) + for c in calls: + self.assertIn("ref", [k.arg for k in c.keywords], "line %d" % c.lineno) + + def test_tax_burn_is_idempotent(self): + calls = list(_calls("tax")) + self.assertTrue(calls) + for c in calls: + self.assertIn("ref", [k.arg for k in c.keywords], "line %d" % c.lineno) + + def test_weekly_top_referrer_prize_is_idempotent(self): + src = SRC.read_text(encoding="utf-8") + self.assertIn('"top3week:" + wk, ref=', src) + + +if __name__ == "__main__": + unittest.main()