From d58082db908a57ea7a2b063af6af803e4925044f Mon Sep 17 00:00:00 2001 From: Iaroslav Gryshaiev Date: Sat, 28 Dec 2024 12:48:58 +0100 Subject: [PATCH] fix(billing): use specific endpoint to check managed wallet grants --- apps/api/mvm.lock | 2 +- apps/api/test/functional/start-trial.spec.ts | 22 +++++++++---------- packages/http-sdk/package.json | 2 +- .../http-sdk/src/authz/authz-http.service.ts | 10 +-------- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/apps/api/mvm.lock b/apps/api/mvm.lock index 646c06a7e..731146644 100644 --- a/apps/api/mvm.lock +++ b/apps/api/mvm.lock @@ -2,7 +2,7 @@ "dependencies": { "@akashnetwork/database": "1.0.0", "@akashnetwork/env-loader": "1.0.1", - "@akashnetwork/http-sdk": "1.1.1", + "@akashnetwork/http-sdk": "1.1.2", "@akashnetwork/logging": "2.0.2" } } diff --git a/apps/api/test/functional/start-trial.spec.ts b/apps/api/test/functional/start-trial.spec.ts index e7b3c0e06..0cf73c093 100644 --- a/apps/api/test/functional/start-trial.spec.ts +++ b/apps/api/test/functional/start-trial.spec.ts @@ -5,6 +5,7 @@ import { container } from "tsyringe"; import { app } from "@src/app"; import { BILLING_CONFIG, BillingConfig } from "@src/billing/providers"; +import { resolveWallet } from "@src/billing/providers/wallet.provider"; import { ApiPgDatabase, POSTGRES_DB, resolveTable } from "@src/core"; import { DbTestingService } from "@test/services/db-testing.service"; @@ -41,8 +42,9 @@ describe("start trial", () => { }); const getWalletsResponse = await app.request(`/v1/wallets?userId=${userId}`, { headers }); const userWallet = await userWalletsQuery.findFirst({ where: eq(userWalletsTable.userId, userId) }); + const masterWalletAddress = await resolveWallet("MANAGED").getFirstAddress(); const allowances = await Promise.all([ - authzHttpService.getDepositDeploymentGrantsForGrantee(userWallet.address), + authzHttpService.getDepositDeploymentGrantsForGranterAndGrantee(masterWalletAddress, userWallet.address), authzHttpService.getFeeAllowancesForGrantee(userWallet.address) ]); @@ -77,17 +79,13 @@ describe("start trial", () => { isTrialing: true }); expect(allowances).toMatchObject([ - [ - { - granter: expect.any(String), - grantee: userWallet.address, - authorization: { - "@type": "/akash.deployment.v1beta3.DepositDeploymentAuthorization", - spend_limit: { denom: config.DEPLOYMENT_GRANT_DENOM, amount: String(config.TRIAL_DEPLOYMENT_ALLOWANCE_AMOUNT) } - }, - expiration: expect.any(String) - } - ], + { + authorization: { + "@type": "/akash.deployment.v1beta3.DepositDeploymentAuthorization", + spend_limit: { denom: config.DEPLOYMENT_GRANT_DENOM, amount: String(config.TRIAL_DEPLOYMENT_ALLOWANCE_AMOUNT) } + }, + expiration: expect.any(String) + }, [ { granter: expect.any(String), diff --git a/packages/http-sdk/package.json b/packages/http-sdk/package.json index 68611ea34..67c161512 100644 --- a/packages/http-sdk/package.json +++ b/packages/http-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@akashnetwork/http-sdk", - "version": "1.1.1", + "version": "1.1.2", "description": "Package containing http layer for Akash Network", "keywords": [], "license": "Apache-2.0", diff --git a/packages/http-sdk/src/authz/authz-http.service.ts b/packages/http-sdk/src/authz/authz-http.service.ts index 2c15d81c3..444f5a8e9 100644 --- a/packages/http-sdk/src/authz/authz-http.service.ts +++ b/packages/http-sdk/src/authz/authz-http.service.ts @@ -74,13 +74,6 @@ export class AuthzHttpService extends HttpService { } } - // eslint-disable-next-line @typescript-eslint/no-unused-vars - async getDepositDeploymentGrantsForGrantee(address: string): Promise { - // const response = this.extractData(await this.get(`cosmos/authz/v1beta1/grants/grantee/${address}`)); - // return response.grants.filter(grant => this.isValidDepositDeploymentGrant(grant)); - return [] - } - async getDepositDeploymentGrantsForGranterAndGrantee(granter: string, grantee: string): Promise { const response = this.extractData( await this.get>("cosmos/authz/v1beta1/grants", { @@ -99,8 +92,7 @@ export class AuthzHttpService extends HttpService { } async hasValidDepositDeploymentGrant(granter: string, grantee: string) { - const depositDeploymentGrants = await this.getDepositDeploymentGrantsForGrantee(grantee); - return depositDeploymentGrants.some(allowance => allowance.granter === granter); + return !!(await this.getDepositDeploymentGrantsForGranterAndGrantee(granter, grantee)) } async paginateDepositDeploymentGrants(