Skip to content

Commit

Permalink
chore: revert unnecessary change
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Yanev <[email protected]>
  • Loading branch information
victor-yanev committed Dec 10, 2024
1 parent 0f4a4e7 commit 006de0f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
10 changes: 9 additions & 1 deletion packages/relay/src/lib/services/hbarLimitService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,15 @@ export class HbarLimitService implements IHbarLimitService {

let spendingPlan = await this.getSpendingPlan(evmAddress, requestDetails);
if (!spendingPlan) {
spendingPlan = await this.createSpendingPlanForAddress(evmAddress, requestDetails);
if (evmAddress) {
// Create a basic spending plan if none exists for the evm address
spendingPlan = await this.createSpendingPlanForAddress(evmAddress, requestDetails);
} else {
this.logger.warn(
`${requestDetails.formattedRequestId} Cannot add expense to a spending plan without an evm address`,
);
return;
}
}

if (this.logger.isLevelEnabled('trace')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -808,31 +808,28 @@ describe('HBAR Rate Limit Service', function () {
<any>'updateAverageAmountSpentPerSubscriptionTier',
);

const addExpensePromise = hbarLimitService.addExpense(
expense,
evmAddress,
new RequestDetails({
...requestDetails,
ipAddress,
}),
);

if (evmAddress) {
await hbarLimitService.addExpense(
expense,
evmAddress,
new RequestDetails({
...requestDetails,
ipAddress,
}),
);
await expect(addExpensePromise).to.eventually.be.fulfilled;
expect(hbarSpendingPlanRepositorySpy.addToAmountSpent.calledTwice).to.be.true; // once for operator and once for evm address
await Promise.all(updateAverageAmountSpentPerSubscriptionTierSpy.returnValues);
const expectedAverageUsage = Math.round((otherPlanOfTheSameTier.amountSpent + expense) / 2);
sinon.assert.calledOnceWithExactly(setAverageSpendingPlanAmountSpentGaugeSpy, expectedAverageUsage);
sinon.assert.calledOnceWithExactly(incUniqueSpendingPlansCounterSpy, 1);
} else {
await expect(
hbarLimitService.addExpense(
expense,
evmAddress,
new RequestDetails({
...requestDetails,
ipAddress,
}),
),
).to.eventually.be.rejectedWith('Cannot create a spending plan without an associated evm address');
await expect(addExpensePromise).to.eventually.be.fulfilled;
sinon.assert.calledWith(
loggerSpy.warn,
`${requestDetails.formattedRequestId} Cannot add expense to a spending plan without an evm address`,
);
expect(hbarSpendingPlanRepositorySpy.addToAmountSpent.calledOnce).to.be.true; // only once for the operator
}
expect(hbarSpendingPlanRepositorySpy.addToAmountSpent.calledWith(sinon.match.string, expense)).to.be.true;
Expand Down

0 comments on commit 006de0f

Please sign in to comment.