import { ProposalQuota } from './proposal-quota.service'; import { RateLimitStore } from './ports/rate-limit.store'; class MemoryStore extends RateLimitStore { readonly counts = new Map(); async hit(key: string): Promise { const count = (this.counts.get(key) ?? 0) + 1; this.counts.set(key, count); return count; } } describe('ProposalQuota', () => { it('lets five proposals through per address, then says no', async () => { const quota = new ProposalQuota(new MemoryStore()); const answers = []; for (let i = 0; i < 6; i++) answers.push(await quota.take('1.2.3.4')); expect(answers).toEqual([true, true, true, true, true, false]); expect(await quota.take('5.6.7.8')).toBe(true); }); });