Moved canonical transaction, NFT, and mempool reads into a separate read-only Ledger SQLite connection
This commit is contained in:
@@ -418,6 +418,34 @@ test('worker reads canonical facts from a separate read-only Ledger snapshot and
|
||||
} finally { verifyDb.close(); }
|
||||
});
|
||||
|
||||
test('worker reconciliation yields to event-loop timers during a large durable backlog', async t => {
|
||||
const f = await fixture(t, true, true, true), db = new DatabaseSync(join(f.dir, 'testnet', 'market.sqlite'));
|
||||
try {
|
||||
const insertListing = db.prepare('INSERT INTO listings VALUES(?,?,?,?)');
|
||||
const insertOrder = db.prepare('INSERT INTO orders VALUES(?,?)');
|
||||
db.exec('BEGIN IMMEDIATE');
|
||||
try {
|
||||
for (let i = 0; i < 3000; i++) {
|
||||
const id = `60000000-0000-4000-8000-${(i + 1).toString(16).padStart(12, '0')}`;
|
||||
const listingId = `70000000-0000-4000-8000-${(i + 1).toString(16).padStart(12, '0')}`;
|
||||
const cardHash = (i + 1).toString(16).padStart(64, '0');
|
||||
const listing = { id: listingId, cardHash, seller: alice.actor, sequence: 0, kind: 'fixed', status: 'cancelled' };
|
||||
insertListing.run(listingId, cardHash, 'cancelled', JSON.stringify(listing));
|
||||
insertOrder.run(id, JSON.stringify({ id, listingId, seller: alice.actor, buyer: bob.actor,
|
||||
cardHash, sequence: 0, status: 'refunded' }));
|
||||
}
|
||||
db.exec('COMMIT');
|
||||
} catch (error) { db.exec('ROLLBACK'); throw error; }
|
||||
} finally { db.close(); }
|
||||
f.market.browse();
|
||||
assert.equal(f.market.isReconciliationWorkerBusy(), true);
|
||||
let timerRan = false;
|
||||
await new Promise<void>(resolve => setTimeout(() => { timerRan = true; resolve(); }, 0));
|
||||
assert.equal(timerRan, true);
|
||||
assert.equal(f.market.isReconciliationWorkerBusy(), true,
|
||||
'large reconciliation should still be in flight while the main-loop timer has run');
|
||||
});
|
||||
|
||||
test('USD and mock XMR accounting use bounded integer amounts and exact fee splitting', () => {
|
||||
assert.equal(parseUsd('15.01'), 1501); assert.equal(parseUsd('0.01'), 1);
|
||||
for (const invalid of ['0', '-1', '1e3', '1.001', ' 1', 'NaN', '1000001', '01.00']) assert.throws(() => parseUsd(invalid));
|
||||
|
||||
Reference in New Issue
Block a user