mirror of
https://github.com/pezkuwichain/pezkuwi-telegram-miniapp.git
synced 2026-11-24 19:39:57 +00:00
TronGrid's free plan allows 10,000 requests a day. Checking every user's TRC20 address on every five-minute run needs ~29,000 a day at 101 users, so the key ran out at 03:00 UTC and every later run was refused. get-deposit-info now records when a user opened the deposit screen. check-deposits checks users seen in the last 24 hours on every run and everyone in one run every six hours (00, 06, 12, 18 UTC): about 3,300 requests a day at 10 active users. A deposit made without opening the screen within the past day waits for the next full scan. The user-list query now reports its error instead of ending the TRC20 check as if there were no users.
33 lines
1.4 KiB
TypeScript
33 lines
1.4 KiB
TypeScript
import { assertEquals } from 'jsr:@std/assert@1';
|
|
import { isFullScanRun, selectTrc20Users } from './trc20.ts';
|
|
|
|
const at = (iso: string) => new Date(iso);
|
|
const users = [
|
|
{ id: 'recent', deposit_info_seen_at: '2026-10-19T09:00:00Z' },
|
|
{ id: 'stale', deposit_info_seen_at: '2026-10-17T09:00:00Z' },
|
|
{ id: 'never', deposit_info_seen_at: null },
|
|
{ id: 'garbled', deposit_info_seen_at: 'not a date' },
|
|
];
|
|
const ids = (list: { id: string }[]) => list.map((u) => u.id);
|
|
|
|
Deno.test('an ordinary run checks only users seen in the last 24 hours', () => {
|
|
assertEquals(ids(selectTrc20Users(users, at('2026-10-19T10:35:00Z'))), ['recent']);
|
|
});
|
|
|
|
Deno.test('a user seen exactly 24 hours ago is still checked', () => {
|
|
const edge = [{ id: 'edge', deposit_info_seen_at: '2026-10-18T10:35:00Z' }];
|
|
assertEquals(ids(selectTrc20Users(edge, at('2026-10-19T10:35:00Z'))), ['edge']);
|
|
});
|
|
|
|
Deno.test('the full-scan run checks everyone', () => {
|
|
assertEquals(ids(selectTrc20Users(users, at('2026-10-19T12:00:20Z'))), ids(users));
|
|
});
|
|
|
|
Deno.test('exactly one five-minute run per full-scan hour is a full scan', () => {
|
|
assertEquals(isFullScanRun(at('2026-10-19T00:00:15Z')), true);
|
|
assertEquals(isFullScanRun(at('2026-10-19T06:04:59Z')), true);
|
|
assertEquals(isFullScanRun(at('2026-10-19T06:05:00Z')), false);
|
|
assertEquals(isFullScanRun(at('2026-10-19T07:00:15Z')), false);
|
|
assertEquals(isFullScanRun(at('2026-10-19T18:00:15Z')), true);
|
|
});
|