From 47e962443189fd1511352137bb5ae0fcad21ae2f Mon Sep 17 00:00:00 2001 From: Yaroslav Grishajev Date: Wed, 3 Apr 2024 13:34:40 +0200 Subject: [PATCH] refactor(api): uses akash-api protobuf generated files instead of local ones (#184) --- .gitignore | 1 + package-lock.json | 19 +++++++- package.json | 3 +- src/certificates/index.ts | 4 +- src/keplr/index.ts | 2 +- src/rpc/index.ts | 1 - src/sdl/index.ts | 4 +- src/stargate/index.ts | 2 +- .../tests/test_deployments.ts.test.cjs | 43 ------------------- tests/test_deployments.ts | 2 +- tests/util.ts | 18 -------- tsconfig.json | 6 +-- 12 files changed, 32 insertions(+), 73 deletions(-) diff --git a/.gitignore b/.gitignore index f2edf1c..e4c39d0 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,5 @@ yarn-error.log # Tests artifacts .coverage/ +coverage/ diff --git a/package-lock.json b/package-lock.json index 450d52e..77af5a5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.5.11", "license": "Apache-2.0", "dependencies": { + "@akashnetwork/akash-api": "^1.0.2", "@cosmjs/launchpad": "^0.27.0", "@cosmjs/proto-signing": "^0.28.11", "@cosmjs/stargate": "^0.28.0", @@ -49,7 +50,7 @@ "ts-loader": "^9.2.3", "ts-node": "^10.0.0", "ts-proto": "^1.104.0", - "typescript": "^4.3.4", + "typescript": "^4.7.4", "webpack": "^5.41.1", "webpack-cli": "^4.7.2" }, @@ -67,6 +68,22 @@ "node": ">=0.10.0" } }, + "node_modules/@akashnetwork/akash-api": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@akashnetwork/akash-api/-/akash-api-1.0.2.tgz", + "integrity": "sha512-QavBadf3efITPd4r1bECLoDmSoZJjCVHVoaeOnhh+pJX5K1dhsipVI5+QiBCCJ/4Os38WLD7EkgMlhQn6OWxrA==", + "dependencies": { + "rxjs": "^7.8.1" + } + }, + "node_modules/@akashnetwork/akash-api/node_modules/rxjs": { + "version": "7.8.1", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz", + "integrity": "sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==", + "dependencies": { + "tslib": "^2.1.0" + } + }, "node_modules/@ampproject/remapping": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.0.tgz", diff --git a/package.json b/package.json index e3ae8ca..790cc1a 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ ] }, "dependencies": { + "@akashnetwork/akash-api": "^1.0.2", "@cosmjs/launchpad": "^0.27.0", "@cosmjs/proto-signing": "^0.28.11", "@cosmjs/stargate": "^0.28.0", @@ -83,7 +84,7 @@ "ts-loader": "^9.2.3", "ts-node": "^10.0.0", "ts-proto": "^1.104.0", - "typescript": "^4.3.4", + "typescript": "^4.7.4", "webpack": "^5.41.1", "webpack-cli": "^4.7.2" }, diff --git a/src/certificates/index.ts b/src/certificates/index.ts index bc1c414..7611062 100644 --- a/src/certificates/index.ts +++ b/src/certificates/index.ts @@ -3,9 +3,9 @@ import { SigningStargateClient } from "@cosmjs/stargate"; import { messages as stargateMessages } from "../stargate"; import { createStarGateMessage } from "../pbclient/pbclient"; -import { QueryCertificatesRequest, QueryCertificatesResponse } from "../protobuf/akash/cert/v1beta3/query"; -import { CertificateFilter } from "../protobuf/akash/cert/v1beta1/cert"; +import { QueryCertificatesRequest, QueryCertificatesResponse, CertificateFilter } from "@akashnetwork/akash-api/akash/cert/v1beta3"; +// eslint-disable-next-line @typescript-eslint/no-var-requires const JsonRPC = require("simple-jsonrpc-js"); import { toBase64 } from "pvutils"; diff --git a/src/keplr/index.ts b/src/keplr/index.ts index f598e2d..4866af0 100644 --- a/src/keplr/index.ts +++ b/src/keplr/index.ts @@ -2,7 +2,7 @@ import { getAkashTypeRegistry } from "../stargate"; import { defaultRegistryTypes, SigningStargateClient } from "@cosmjs/stargate"; import { Registry } from "@cosmjs/proto-signing"; import { AminoTypes } from "@cosmjs/stargate"; -import { Certificate } from "../protobuf/akash/cert/v1beta2/cert"; +import { Certificate } from "@akashnetwork/akash-api/akash/cert/v1beta2"; export function getChains() { return { diff --git a/src/rpc/index.ts b/src/rpc/index.ts index 738c0f1..cd53e7d 100644 --- a/src/rpc/index.ts +++ b/src/rpc/index.ts @@ -2,7 +2,6 @@ import { Tendermint34Client } from "@cosmjs/tendermint-rpc"; import { createProtobufRpcClient, GasPrice, QueryClient, SigningStargateClient, SigningStargateClientOptions } from "@cosmjs/stargate"; import { getAkashTypeRegistry } from "../stargate"; import { OfflineSigner, Registry } from "@cosmjs/proto-signing"; -import { Decimal } from "cosmwasm"; export async function getRpc(endpoint: string) { return getQueryClient(endpoint); diff --git a/src/sdl/index.ts b/src/sdl/index.ts index 92d9456..8fe1ba0 100644 --- a/src/sdl/index.ts +++ b/src/sdl/index.ts @@ -110,7 +110,9 @@ export class SDL { if ( units > 0 && - Object.values(gpu.attributes?.vendor || {}).some(models => models?.some(model => model.interface && !GPU_SUPPORTED_INTERFACES.includes(model.interface))) + Object.values(gpu.attributes?.vendor || {}).some(models => + models?.some(model => model.interface && !GPU_SUPPORTED_INTERFACES.includes(model.interface)) + ) ) { throw new Error(`GPU interface must be one of the supported interfaces (${GPU_SUPPORTED_INTERFACES.join(",")}).`); } diff --git a/src/stargate/index.ts b/src/stargate/index.ts index 71e231e..ea3bbac 100644 --- a/src/stargate/index.ts +++ b/src/stargate/index.ts @@ -1,4 +1,4 @@ -import { MessageType, messageTypeRegistry, UnknownMessage } from "../protobuf/typeRegistry"; +import { MessageType, messageTypeRegistry, UnknownMessage } from "@akashnetwork/akash-api/typeRegistry"; export const getAkashTypeRegistry: () => [string, MessageType][] = () => Array.from(messageTypeRegistry).map(([path, type]) => [`/${path}`, type]); diff --git a/tap-snapshots/tests/test_deployments.ts.test.cjs b/tap-snapshots/tests/test_deployments.ts.test.cjs index 4c7a918..661d3e3 100644 --- a/tap-snapshots/tests/test_deployments.ts.test.cjs +++ b/tap-snapshots/tests/test_deployments.ts.test.cjs @@ -58,7 +58,6 @@ Object { }, ], "signedBy": Object { - "allOf": Array [], "anyOf": Array [ "akash1qqzwc5d7hynl67nsmn9jukvwqp3vzdl6j2t7lk", ], @@ -73,7 +72,6 @@ Object { }, "resource": Object { "cpu": Object { - "attributes": Array [], "units": Object { "val": "MTAwMA==", }, @@ -81,25 +79,21 @@ Object { "endpoints": Array [ Object { "kind": "RANDOM_PORT", - "sequenceNumber": 0, }, ], "gpu": Object { - "attributes": Array [], "units": Object { "val": "MA==", }, }, "id": 1, "memory": Object { - "attributes": Array [], "quantity": Object { "val": "NTM2ODcwOTEy", }, }, "storage": Array [ Object { - "attributes": Array [], "name": "default", "quantity": Object { "val": "MTA3Mzc0MTgyNA==", @@ -164,7 +158,6 @@ Object { }, ], "signedBy": Object { - "allOf": Array [], "anyOf": Array [ "akash1qqzwc5d7hynl67nsmn9jukvwqp3vzdl6j2t7lk", ], @@ -179,7 +172,6 @@ Object { }, "resource": Object { "cpu": Object { - "attributes": Array [], "units": Object { "val": "MTAwMA==", }, @@ -187,25 +179,21 @@ Object { "endpoints": Array [ Object { "kind": "RANDOM_PORT", - "sequenceNumber": 0, }, ], "gpu": Object { - "attributes": Array [], "units": Object { "val": "MA==", }, }, "id": 1, "memory": Object { - "attributes": Array [], "quantity": Object { "val": "NTM2ODcwOTEy", }, }, "storage": Array [ Object { - "attributes": Array [], "name": "default", "quantity": Object { "val": "MTA3Mzc0MTgyNA==", @@ -270,7 +258,6 @@ Object { }, ], "signedBy": Object { - "allOf": Array [], "anyOf": Array [ "akash1qqzwc5d7hynl67nsmn9jukvwqp3vzdl6j2t7lk", ], @@ -285,7 +272,6 @@ Object { }, "resource": Object { "cpu": Object { - "attributes": Array [], "units": Object { "val": "MTAwMA==", }, @@ -293,25 +279,21 @@ Object { "endpoints": Array [ Object { "kind": "RANDOM_PORT", - "sequenceNumber": 0, }, ], "gpu": Object { - "attributes": Array [], "units": Object { "val": "MA==", }, }, "id": 1, "memory": Object { - "attributes": Array [], "quantity": Object { "val": "NTM2ODcwOTEy", }, }, "storage": Array [ Object { - "attributes": Array [], "name": "default", "quantity": Object { "val": "MTA3Mzc0MTgyNA==", @@ -376,7 +358,6 @@ Object { }, ], "signedBy": Object { - "allOf": Array [], "anyOf": Array [ "akash1qqzwc5d7hynl67nsmn9jukvwqp3vzdl6j2t7lk", ], @@ -391,7 +372,6 @@ Object { }, "resource": Object { "cpu": Object { - "attributes": Array [], "units": Object { "val": "MTAw", }, @@ -399,25 +379,21 @@ Object { "endpoints": Array [ Object { "kind": "RANDOM_PORT", - "sequenceNumber": 0, }, ], "gpu": Object { - "attributes": Array [], "units": Object { "val": "MA==", }, }, "id": 1, "memory": Object { - "attributes": Array [], "quantity": Object { "val": "NTM2ODcwOTEy", }, }, "storage": Array [ Object { - "attributes": Array [], "name": "default", "quantity": Object { "val": "NTM2ODcwOTEy", @@ -482,7 +458,6 @@ Object { }, ], "signedBy": Object { - "allOf": Array [], "anyOf": Array [ "akash1qqzwc5d7hynl67nsmn9jukvwqp3vzdl6j2t7lk", ], @@ -497,7 +472,6 @@ Object { }, "resource": Object { "cpu": Object { - "attributes": Array [], "units": Object { "val": "MTAw", }, @@ -505,25 +479,21 @@ Object { "endpoints": Array [ Object { "kind": "RANDOM_PORT", - "sequenceNumber": 0, }, ], "gpu": Object { - "attributes": Array [], "units": Object { "val": "MA==", }, }, "id": 1, "memory": Object { - "attributes": Array [], "quantity": Object { "val": "MjY4NDM1NDU2", }, }, "storage": Array [ Object { - "attributes": Array [], "name": "default", "quantity": Object { "val": "NTM2ODcwOTEy", @@ -588,7 +558,6 @@ Object { }, ], "signedBy": Object { - "allOf": Array [], "anyOf": Array [ "akash1qqzwc5d7hynl67nsmn9jukvwqp3vzdl6j2t7lk", ], @@ -603,7 +572,6 @@ Object { }, "resource": Object { "cpu": Object { - "attributes": Array [], "units": Object { "val": "MTAw", }, @@ -611,25 +579,21 @@ Object { "endpoints": Array [ Object { "kind": "RANDOM_PORT", - "sequenceNumber": 0, }, ], "gpu": Object { - "attributes": Array [], "units": Object { "val": "MA==", }, }, "id": 1, "memory": Object { - "attributes": Array [], "quantity": Object { "val": "NTM2ODcwOTEy", }, }, "storage": Array [ Object { - "attributes": Array [], "name": "default", "quantity": Object { "val": "NTM2ODcwOTEy", @@ -646,7 +610,6 @@ Object { }, ], "pagination": Object { - "nextKey": "", "total": "6", }, } @@ -703,7 +666,6 @@ Object { }, ], "signedBy": Object { - "allOf": Array [], "anyOf": Array [ "akash1qqzwc5d7hynl67nsmn9jukvwqp3vzdl6j2t7lk", ], @@ -718,7 +680,6 @@ Object { }, "resource": Object { "cpu": Object { - "attributes": Array [], "units": Object { "val": "MTAwMA==", }, @@ -726,25 +687,21 @@ Object { "endpoints": Array [ Object { "kind": "RANDOM_PORT", - "sequenceNumber": 0, }, ], "gpu": Object { - "attributes": Array [], "units": Object { "val": "MA==", }, }, "id": 1, "memory": Object { - "attributes": Array [], "quantity": Object { "val": "NTM2ODcwOTEy", }, }, "storage": Array [ Object { - "attributes": Array [], "name": "default", "quantity": Object { "val": "MTA3Mzc0MTgyNA==", diff --git a/tests/test_deployments.ts b/tests/test_deployments.ts index 36d270f..f6f8179 100644 --- a/tests/test_deployments.ts +++ b/tests/test_deployments.ts @@ -9,7 +9,7 @@ import { QueryDeploymentResponse, QueryDeploymentsRequest, QueryDeploymentsResponse -} from "../src/protobuf/akash/deployment/v1beta3/query"; +} from "@akashnetwork/akash-api/akash/deployment/v1beta3/query"; tap.test("Deployments: query deployment list with owner filter", async t => { t.plan(1); diff --git a/tests/util.ts b/tests/util.ts index 0ba98fc..d8df4bc 100644 --- a/tests/util.ts +++ b/tests/util.ts @@ -1,19 +1 @@ -import sinon from "sinon"; - -export function testRpc(spy: sinon.SinonSpy, response = null) { - return { - request: spy - }; -} - export const testSnap = (test: Tap.Test) => (message: string) => (value: any) => test.matchSnapshot(value, message); - -export const testParams = (test: Tap.Test, spy: sinon.SinonSpy) => (params: any, message: string) => (result: any) => { - test.ok(spy.calledWith(...params), message); - return result; -}; - -export const wrapMockResponse = (value: string) => - Promise.resolve({ - json: () => ({ result: { response: { value } } }) - }); diff --git a/tsconfig.json b/tsconfig.json index 759daac..d3a070a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,7 @@ "target": "es2021" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */, "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, // "lib": [], /* Specify library files to be included in the compilation. */ - // "allowJs": true, /* Allow javascript files to be compiled. */ + "allowJs": true /* Allow javascript files to be compiled. */, // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ "declaration": true /* Generates corresponding '.d.ts' file. */, @@ -43,7 +43,7 @@ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ /* Module Resolution Options */ - // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + "moduleResolution": "Node16" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */, // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ @@ -68,6 +68,6 @@ "skipLibCheck": true /* Skip type checking of declaration files. */, "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ }, - "include": ["./src"], + "include": ["./src/**/*"], "exclude": ["./examples", "./tests"] }