Skip to content

Commit

Permalink
fix: hbarLimiter.spec.ts
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
  • Loading branch information
victor-yanev committed Dec 10, 2024
1 parent ab5e636 commit d30cec3
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/server/tests/acceptance/hbarLimiter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,37 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () {
)),
);
global.accounts.push(...accounts);

// Note: Reset all operator spending plans before running the tests
const operatorPlans = await hbarSpendingPlanRepository.findAllActiveBySubscriptionTier(
[SubscriptionTier.OPERATOR],
requestDetails,
);
for (const plan of operatorPlans) {
await cacheService.delete(`${HbarSpendingPlanRepository.collectionKey}:${plan.id}`, 'before', requestDetails);
await cacheService.delete(
`${HbarSpendingPlanRepository.collectionKey}:${plan.id}:amountSpent`,
'before',
requestDetails,
);
await evmAddressSpendingPlanRepository.deleteAllByPlanId(plan.id, 'before', requestDetails);
}
});

afterEach(async () => {
const operatorPlans = await hbarSpendingPlanRepository.findAllActiveBySubscriptionTier(
[SubscriptionTier.OPERATOR],
requestDetails,
);
expect(operatorPlans.length).to.be.eq(1); // sanity check

await hbarSpendingPlanRepository.resetAmountSpentOfAllPlans(requestDetails);

// we don't want to reset the operator account's spending, so we have to add the amount spent back
for (const plan of operatorPlans) {
await hbarSpendingPlanRepository.addToAmountSpent(plan.id, plan.amountSpent, requestDetails, mockTTL);
}

// Note: Since the total HBAR budget is shared across the entire Relay instance by multiple test cases,
// and expense updates occur asynchronously, the wait below ensures that the HBAR amount has sufficient time
// to update properly after each test.
Expand Down

0 comments on commit d30cec3

Please sign in to comment.