Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Jul 3, 2024
1 parent 8dd1e44 commit 8aae4e3
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 224 deletions.
16 changes: 7 additions & 9 deletions tests/integration/commands/open.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import { Bank } from 'oldschooljs';
import { beforeEach, describe, expect, test } from 'vitest';
import { describe, expect, test } from 'vitest';

import { openCommand } from '../../../src/mahoji/commands/open';
import { randomMock } from '../setup';
import { createTestUser, mockClient } from '../util';

describe('Open Command', async () => {
await mockClient();
const user = await createTestUser();

beforeEach(async () => {
test.concurrent('Open with no quantity', async () => {
randomMock();
await user.reset();
const user = await createTestUser();
await user.addItemsToBank({ items: new Bank().add('Reward casket (beginner)', 100) });
});

test('Open with no quantity', async () => {
const result = await user.runCommand(openCommand, { name: 'reward casket (beginner)' });
expect(result).toMatchObject({
content: `You have now opened a total of 1x Reward casket (beginner)
Expand All @@ -31,7 +26,10 @@ describe('Open Command', async () => {
await user.clMatch(new Bank().add('Fire rune', 34));
});

test('Open with quantity', async () => {
test.concurrent('Open with quantity', async () => {
randomMock();
const user = await createTestUser();
await user.addItemsToBank({ items: new Bank().add('Reward casket (beginner)', 100) });
await user.runCommand(openCommand, { name: 'reward casket (beginner)', quantity: 10 });
await user.bankAmountMatch('Reward casket (beginner)', 90);
await user.openedBankMatch(new Bank().add('Reward casket (beginner)', 10));
Expand Down
44 changes: 16 additions & 28 deletions tests/integration/grandExchange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,19 @@ import { describe, expect, test } from 'vitest';

import { usernameCache } from '../../src/lib/constants';
import { GrandExchange } from '../../src/lib/grandExchange';
import { prisma } from '../../src/lib/settings/prisma';
import { assert } from '../../src/lib/util';
import resolveItems from '../../src/lib/util/resolveItems';
import { geCommand } from '../../src/mahoji/commands/ge';
import { cancelUsersListings } from '../../src/mahoji/lib/abstracted_commands/cancelGEListingCommand';
import type { TestUser } from './util';
import { createTestUser, mockClient } from './util';
import { Stopwatch } from '@sapphire/stopwatch';


const TICKS_TO_RUN = 40;
const TICKS_TO_RUN = 100;
const AMOUNT_USERS = 20;

const quantities = [-1, 0, 100_000_000_000_000_000, 1, 2, 38, 1_000_000_000_000, 500, '5*5'];
const prices = [
-1,
0,
100_000_000_000_000_000,
1,
2,
1_000_000_000_000,
99,
100,
101,
1005,
4005,
5005,
100_000,
'5*9999999'
];
const quantities = [1, 2, 38, 500, '5*5'];
const prices = [1, 30, 33, 55];

const sampleBank = new Bank()
.add('Coins', 1_000_000_000)
Expand Down Expand Up @@ -68,11 +52,13 @@ describe('Grand Exchange', async () => {
let users: TestUser[] = [];

for (let i = 0; i < AMOUNT_USERS; i++) {
users.push((async () => {
const user = await createTestUser();
await user.addItemsToBank({ items: sampleBank });
return user;
})() as any)
users.push(
(async () => {
const user = await createTestUser();
await user.addItemsToBank({ items: sampleBank });
return user;
})() as any
);
}
users = await Promise.all(users);
console.log(`Finished initializing ${AMOUNT_USERS} users`);
Expand All @@ -81,7 +67,8 @@ describe('Grand Exchange', async () => {
const commandPromises = new PQueue({ concurrency: 20 });
for (const user of shuffleArr(users)) {
commandPromises.add(async () => {
const method = randArrItem(['buy', 'sell']);
for (let i = 0; i < 5;i++) {
const method = randArrItem(['buy', 'sell']);
const quantity = randArrItem(quantities);
const price = randArrItem(prices);
for (const item of itemPool) {
Expand All @@ -93,6 +80,7 @@ describe('Grand Exchange', async () => {
}
});
}
}
});
}
await commandPromises.onEmpty();
Expand All @@ -105,6 +93,8 @@ describe('Grand Exchange', async () => {
await GrandExchange.extensiveVerification();
}
await waitForGEToBeEmpty();
const count = await prisma.gETransaction.count();
console.log(`Finished ticking ${TICKS_TO_RUN} times, made ${count} transactions`);

// Cancel all remaining listings
const cancelPromises = [];
Expand Down Expand Up @@ -135,8 +125,6 @@ describe('Grand Exchange', async () => {

const data = await GrandExchange.fetchData();
expect(data.isLocked).toEqual(false);
expect(data.taxBank, '1MS').toBeGreaterThan(0);
expect(data.totalTax, 'L1M').toBeGreaterThan(0);

const totalTaxed = await global.prisma!.gETransaction.aggregate({
_sum: {
Expand Down
Loading

0 comments on commit 8aae4e3

Please sign in to comment.