From 880b1812ebd3e42d94036d5ba4e16f0a4cdfc521 Mon Sep 17 00:00:00 2001 From: gc <30398469+gc@users.noreply.github.com> Date: Mon, 26 Feb 2024 00:28:29 +1100 Subject: [PATCH] improve error message --- src/lib/grandExchange.ts | 11 ++++++++--- tests/integration/grandExchange.test.ts | 18 +++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/lib/grandExchange.ts b/src/lib/grandExchange.ts index 418df03f1e..20e8b78fce 100644 --- a/src/lib/grandExchange.ts +++ b/src/lib/grandExchange.ts @@ -766,9 +766,14 @@ ${type} ${toKMB(quantity)} ${item.name} for ${toKMB(price)} each, for a total of debugLog(`Expected G.E Bank: ${shouldHave}`); if (!currentBank.equals(shouldHave)) { - throw new Error( - `GE either has extra or insufficient items. Difference: ${shouldHave.difference(currentBank)}` - ); + if (!currentBank.has(shouldHave)) { + throw new Error( + `GE is MISSING items to cover the ${ + [...buyListings, ...sellListings].length + }x active listings. Difference: ${shouldHave.difference(currentBank)}` + ); + } + throw new Error(`GE has EXTRA items. Difference: ${shouldHave.difference(currentBank)}`); } else { debugLog( `GE has ${currentBank}, which is enough to cover the ${ diff --git a/tests/integration/grandExchange.test.ts b/tests/integration/grandExchange.test.ts index c55487d3d2..7bbcdfd66c 100644 --- a/tests/integration/grandExchange.test.ts +++ b/tests/integration/grandExchange.test.ts @@ -62,6 +62,12 @@ describe('Grand Exchange', async () => { GrandExchange.calculateSlotsOfUser = async () => ({ slots: 500 } as any); await mockClient(); + async function waitForGEToBeEmpty() { + await GrandExchange.queue.onEmpty(); + assert(GrandExchange.queue.size === 0, 'G.E Queue should be empty'); + assert(!GrandExchange.locked, 'G.E should not be locked'); + } + test( 'Fuzz', async () => { @@ -84,6 +90,7 @@ describe('Grand Exchange', async () => { } console.log(`Finished initializing ${amountOfUsers} users`); + // Run a bunch of commands to buy/sell const commandPromises = new PQueue({ concurrency: 10 }); for (const user of shuffleArr(users)) { const method = randArrItem(['buy', 'sell']); @@ -101,12 +108,12 @@ describe('Grand Exchange', async () => { } }); } - await commandPromises.onEmpty(); - await GrandExchange.queue.onEmpty(); + await waitForGEToBeEmpty(); console.log('Finished running all commands'); + // Tick the g.e to make some transactions for (let i = 0; i < 100; i++) { await GrandExchange.tick(); await Promise.all([ @@ -114,20 +121,21 @@ describe('Grand Exchange', async () => { GrandExchange.extensiveVerification() ]); } + await waitForGEToBeEmpty(); console.log('Finished ticking 100 times'); - const testBank = new Bank(); + // Cancel all remaining listings const cancelPromises = []; for (const user of users) { cancelPromises.push(cancelAllListings(user)); } - await Promise.all(cancelPromises); - await GrandExchange.queue.onEmpty(); + await waitForGEToBeEmpty(); console.log('Finished cancelling'); await Promise.all(users.map(u => u.sync())); + const testBank = new Bank(); for (const user of users) { testBank.add(user.bankWithGP); }