Skip to content

Commit

Permalink
fix: Test clean up.
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Badiere <[email protected]>
  • Loading branch information
ebadiere committed Nov 13, 2024
1 parent 734ad20 commit 240a06c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
8 changes: 7 additions & 1 deletion packages/relay/src/lib/services/hbarLimitService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class HbarLimitService implements IHbarLimitService {
};

/**
* Disables the rate limiter.
* Flag to turn off the HBarRateLimitService.
* @private
*/
private readonly disableRateLimiter: boolean = false;
Expand Down Expand Up @@ -160,6 +160,12 @@ export class HbarLimitService implements IHbarLimitService {
return !this.disableRateLimiter;
}

public static getInstance(): HbarLimitService {
// if (!MyClass._instance) {
// MyClass._instance = new MyClass();
// }
return this;
}
/**
* Resets the {@link HbarSpendingPlan#amountSpent} field for all existing plans.
* @param {RequestDetails} requestDetails - The request details used for logging and tracking.
Expand Down
26 changes: 4 additions & 22 deletions packages/server/tests/acceptance/hbarLimiter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,24 +898,6 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () {
'HBAR_RATE_LIMIT_TINYBAR',
)}`,
);

const initialAccount: AliasAccount = global.accounts[0];

const neededAccounts: number = 1;
accounts.push(
...(await Utils.createMultipleAliasAccounts(
mirrorNode,
initialAccount,
neededAccounts,
initialBalance,
requestDetails,
)),
);
global.accounts.push(...accounts);
const basicPlans = await hbarSpendingPlanRepository.findAllActiveBySubscriptionTier(
[SubscriptionTier.BASIC],
requestDetails,
);
});

it('should eventually exhaust the hbar limit for a BASIC user after multiple deployments of large contracts, and not throw an error', async function () {
Expand All @@ -926,14 +908,14 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () {
let hbarSpendingPlan: IDetailedHbarSpendingPlan | null = null;

for (deploymentCounts = 0; deploymentCounts < 3; deploymentCounts++) {
const tx = await deployContract(largeContractJson, accounts[0].wallet);
const tx = await deployContract(largeContractJson, global.accounts[0].wallet);
await tx.waitForDeployment();

expectedTxCost ||= await getExpectedCostOfLastLargeTx(largeContractJson.bytecode);

if (!hbarSpendingPlan) {
const ethSpendingPlan = await ethAddressSpendingPlanRepository.findByAddress(
accounts[0].wallet.address,
global.accounts[0].wallet.address,
requestDetails,
);
hbarSpendingPlan = await hbarSpendingPlanRepository.findByIdWithDetails(
Expand All @@ -946,7 +928,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () {
}
if (!hbarSpendingPlan) {
const ethSpendingPlan = await ethAddressSpendingPlanRepository.findByAddress(
accounts[0].wallet.address,
global.accounts[0].wallet.address,
requestDetails,
);
hbarSpendingPlan = await hbarSpendingPlanRepository.findByIdWithDetails(
Expand All @@ -964,7 +946,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () {

// Confirm that deployments continued even after the limit was exhausted
expect(deploymentCounts).to.be.gte(1);
await expect(deployContract(largeContractJson, accounts[0].wallet)).to.be.fulfilled;
await expect(deployContract(largeContractJson, global.accounts[0].wallet)).to.be.fulfilled;
});
});
}
Expand Down

0 comments on commit 240a06c

Please sign in to comment.