From c43c41c88f3e062c6184e06acaf7c137092544b2 Mon Sep 17 00:00:00 2001 From: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> Date: Thu, 19 Jan 2023 15:27:16 +0800 Subject: [PATCH] chore(apps/ocean-api): removing ocean-api to save CI time (#1985) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What this PR does / why we need it: The high failure rate of docker images recently — to reduce CI time due to failure and having to retry them. I've removed `apps/ocean-api` , and `ocean-api-client` is kept intact as it provide the abstraction for both `playground-api-client` and `whale-api-client` (although not implemented yet for whale). --- .github/governance.yml | 1 - .github/labeler.yml | 5 - .github/labels.yml | 2 - .github/workflows/ci.yml | 2 +- .github/workflows/release-apps.yml | 4 +- .github/workflows/release-ecr.yml | 4 +- apps/ocean-api/README.md | 43 ----- .../controllers/ActuatorController.test.ts | 151 ------------------ .../controllers/RawTxController.test.ts | 40 ----- .../modules/PlaygroundModule.test.ts | 48 ------ .../src/controllers/RawTxController.ts | 25 --- apps/ocean-api/src/index.ts | 17 -- .../ocean-api/src/modules/ControllerModule.ts | 43 ----- .../ocean-api/src/modules/PlaygroundModule.ts | 65 -------- apps/ocean-api/src/modules/RootModule.ts | 33 ---- apps/ocean-api/testing/OceanApiTesting.ts | 90 ----------- apps/ocean-api/testing/OceanStubClient.ts | 34 ---- apps/ocean-api/testing/OceanStubServer.ts | 45 ------ apps/package.json | 2 - package-lock.json | 12 +- .../ocean-api-client/src/OceanApiClient.ts | 3 - packages/ocean-api-client/src/apis/RawTx.ts | 3 + 22 files changed, 14 insertions(+), 658 deletions(-) delete mode 100644 apps/ocean-api/README.md delete mode 100644 apps/ocean-api/__tests__/controllers/ActuatorController.test.ts delete mode 100644 apps/ocean-api/__tests__/controllers/RawTxController.test.ts delete mode 100644 apps/ocean-api/__tests__/modules/PlaygroundModule.test.ts delete mode 100644 apps/ocean-api/src/controllers/RawTxController.ts delete mode 100644 apps/ocean-api/src/index.ts delete mode 100644 apps/ocean-api/src/modules/ControllerModule.ts delete mode 100644 apps/ocean-api/src/modules/PlaygroundModule.ts delete mode 100644 apps/ocean-api/src/modules/RootModule.ts delete mode 100644 apps/ocean-api/testing/OceanApiTesting.ts delete mode 100644 apps/ocean-api/testing/OceanStubClient.ts delete mode 100644 apps/ocean-api/testing/OceanStubServer.ts diff --git a/.github/governance.yml b/.github/governance.yml index f76f57fb8f..d70e889888 100644 --- a/.github/governance.yml +++ b/.github/governance.yml @@ -58,7 +58,6 @@ issue: - legacy-api - ocean-api - playground-api - - rich-list-api - stats-api - whale-api - website diff --git a/.github/labeler.yml b/.github/labeler.yml index 8dca3021de..29976452d1 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -71,11 +71,6 @@ labels: matcher: files: "apps/playground-api/**" - - label: apps/rich-list-api - sync: true - matcher: - files: "apps/rich-list-api/**" - - label: apps/stats-api sync: true matcher: diff --git a/.github/labels.yml b/.github/labels.yml index a074f61c07..4173abe063 100644 --- a/.github/labels.yml +++ b/.github/labels.yml @@ -80,8 +80,6 @@ name: apps/ocean-api - color: 0581fa name: apps/playground-api -- color: 0581fa - name: apps/rich-list-api - color: 0581fa name: apps/stats-api - color: 0581fa diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 60078e194f..fa0ecc0b6e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,7 +86,7 @@ jobs: strategy: matrix: platform: [ linux/amd64 ] - app: [ legacy-api, ocean-api, playground-api, status-api, whale-api ] + app: [ legacy-api, playground-api, status-api, whale-api ] steps: - name: Set up QEMU uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # v2.1.0 diff --git a/.github/workflows/release-apps.yml b/.github/workflows/release-apps.yml index 61791bc19e..ca9cb7951f 100644 --- a/.github/workflows/release-apps.yml +++ b/.github/workflows/release-apps.yml @@ -13,7 +13,7 @@ concurrency: cancel-in-progress: true env: - APPS: 'legacy-api,ocean-api,playground-api,status-api,whale-api' + APPS: 'legacy-api,playground-api,status-api,whale-api' jobs: build: @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - app: [ legacy-api, ocean-api, playground-api, status-api, whale-api ] + app: [ legacy-api, playground-api, status-api, whale-api ] steps: - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 diff --git a/.github/workflows/release-ecr.yml b/.github/workflows/release-ecr.yml index 63880fa07c..beb9504a9d 100644 --- a/.github/workflows/release-ecr.yml +++ b/.github/workflows/release-ecr.yml @@ -9,7 +9,7 @@ concurrency: cancel-in-progress: true env: - APPS: 'legacy-api,ocean-api,playground-api,status-api,whale-api' + APPS: 'legacy-api,playground-api,status-api,whale-api' jobs: build: @@ -18,7 +18,7 @@ jobs: environment: ECR Release Publishing strategy: matrix: - app: [ legacy-api, ocean-api, playground-api, status-api, whale-api ] + app: [ legacy-api, playground-api, status-api, whale-api ] steps: - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 diff --git a/apps/ocean-api/README.md b/apps/ocean-api/README.md deleted file mode 100644 index fe428094f6..0000000000 --- a/apps/ocean-api/README.md +++ /dev/null @@ -1,43 +0,0 @@ -# DeFiChain Ocean API - -DeFiChain Ocean API, next^2 generation API for building scalable Native DeFi Apps. - -## Motivation - -> https://github.com/JellyfishSDK/jellyfish/issues/580 - -As part of [#580](https://github.com/JellyfishSDK/jellyfish/issues/580) consolidation efforts. We had multiple projects -that were extensions of the jellyfish project. The separated projects allowed us to move quickly initially but proves to -be a bottleneck when it comes to development. - -By including Ocean API development with jellyfish, it creates a better synergy of DeFiChain open source development -across concerns. Singular versioning, source of truth, documentation of entirety of defichain -via [jellyfishsdk.com](https://jellyfishsdk.com). - -## `/apps/ocean-api` - -The server for ocean-api, build with @nestjs it uses aspect-oriented programming methodology to allow the modular design -of `ocean-api`. Featuring 2 main directories `/controllers` and `/modules`. - -## Related Packages - -### `/packages/ocean-api-client` - -> Provides the protocol core for communicating between client and server. Within `ocean-api-client`, it contains a -> shared response and exception structure. - -The official JS client for ocean-api. As the development of ocean-api client and server are closely intertwined, this -allows the project to move iteratively together. With them packaged together within the same repo, the server and client -can be released together. This allows us to be the consumer of our own client implementation. Testing each server -endpoint directly with `ocean-api-client`, dogfooding at the maximum. - -### `/packages/playground` - -> This package is not published, for internal use within `@defichain-apps/ocean-api` only. - -`@defichain/playground` is a specialized testing blockchain isolated from MainNet for testing DeFi applications. Assets -are not real, they can be minted by anyone. Blocks are configured to generate every 3 seconds, the chain can reset -anytime. - -A bot-like design centers the playground as a mechanism that allows bootstrapping with an interval cycle. This allows -the developer to mock any behaviors they want with a simulated testing blockchain. diff --git a/apps/ocean-api/__tests__/controllers/ActuatorController.test.ts b/apps/ocean-api/__tests__/controllers/ActuatorController.test.ts deleted file mode 100644 index b14943ce1d..0000000000 --- a/apps/ocean-api/__tests__/controllers/ActuatorController.test.ts +++ /dev/null @@ -1,151 +0,0 @@ -import { OceanApiTesting } from '../../testing/OceanApiTesting' -import { TestingGroup } from '@defichain/jellyfish-testing' - -describe('no peers', () => { - const apiTesting = OceanApiTesting.create() - - beforeAll(async () => { - await apiTesting.start() - }) - - afterAll(async () => { - await apiTesting.stop() - }) - - it('/_actuator/probes/liveness healthy', async () => { - const res = await apiTesting.app.inject({ - method: 'GET', - url: '/_actuator/probes/liveness' - }) - - expect(res.json()).toStrictEqual({ - data: { - details: { - blockchain: { - status: 'up' - } - }, - error: {}, - info: { - blockchain: { - status: 'up' - } - }, - status: 'ok' - } - }) - expect(res.statusCode).toStrictEqual(200) - }) - - it('/_actuator/probes/readiness unhealthy', async () => { - const res = await apiTesting.app.inject({ - method: 'GET', - url: '/_actuator/probes/readiness' - }) - - expect(res.json()).toStrictEqual({ - data: { - details: { - blockchain: { - blocks: expect.any(Number), - headers: expect.any(Number), - initialBlockDownload: expect.any(Boolean), - peers: 0, - status: 'down' - } - }, - error: { - blockchain: { - blocks: expect.any(Number), - headers: expect.any(Number), - initialBlockDownload: expect.any(Boolean), - peers: 0, - status: 'down' - } - }, - info: {}, - status: 'error' - }, - error: { - at: expect.any(Number), - code: 503, - message: 'Service Unavailable Exception', - type: 'ServiceUnavailable', - url: '/_actuator/probes/readiness' - } - }) - expect(res.statusCode).toStrictEqual(503) - }) -}) - -describe('with peers', () => { - const apiTesting = OceanApiTesting.create(TestingGroup.create(2)) - - beforeAll(async () => { - await apiTesting.start() - await apiTesting.container.waitForWalletCoinbaseMaturity() - }) - - afterAll(async () => { - await apiTesting.stop() - }) - - it('/_actuator/probes/liveness healthy', async () => { - const res = await apiTesting.app.inject({ - method: 'GET', - url: '/_actuator/probes/liveness' - }) - - expect(res.json()).toStrictEqual({ - data: { - details: { - blockchain: { - status: 'up' - } - }, - error: {}, - info: { - blockchain: { - status: 'up' - } - }, - status: 'ok' - } - }) - expect(res.statusCode).toStrictEqual(200) - }) - - it('/_actuator/probes/readiness healthy', async () => { - const res = await apiTesting.app.inject({ - method: 'GET', - url: '/_actuator/probes/readiness' - }) - - expect(res.json()).toStrictEqual({ - data: { - details: { - blockchain: { - blocks: expect.any(Number), - headers: expect.any(Number), - initialBlockDownload: false, - peers: 1, - status: 'up' - } - - }, - error: {}, - info: { - blockchain: { - blocks: expect.any(Number), - headers: expect.any(Number), - initialBlockDownload: false, - peers: 1, - status: 'up' - } - }, - status: 'ok' - } - }) - expect(res.statusCode).toStrictEqual(200) - }) -}) diff --git a/apps/ocean-api/__tests__/controllers/RawTxController.test.ts b/apps/ocean-api/__tests__/controllers/RawTxController.test.ts deleted file mode 100644 index bfe0e07f90..0000000000 --- a/apps/ocean-api/__tests__/controllers/RawTxController.test.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { OceanApiTesting } from '../../testing/OceanApiTesting' - -const apiTesting = OceanApiTesting.create() - -beforeEach(async () => { - await apiTesting.start() -}) - -afterEach(async () => { - await apiTesting.stop() -}) - -it('should be fixed fee of 0.00005000 when there are no transactions', async () => { - const feeRate = await apiTesting.client.rawtx.feeEstimate() - - expect(feeRate).toStrictEqual(0.00005000) -}) - -it('should have fee of not 0.00005 with transactions activity', async () => { - await apiTesting.container.waitForWalletBalanceGTE(100) - - for (let i = 0; i < 10; i++) { - for (let x = 0; x < 20; x++) { - await apiTesting.rpc.wallet.sendToAddress('bcrt1qf5v8n3kfe6v5mharuvj0qnr7g74xnu9leut39r', 0.1, { - subtractFeeFromAmount: true, - avoidReuse: false - }) - } - await apiTesting.container.generate(1) - } - - const feeRate = await apiTesting.client.rawtx.feeEstimate() - expect(feeRate).not.toStrictEqual(0.00005000) -}) - -it('should be able to provide confirmation target', async () => { - const feeRate = await apiTesting.client.rawtx.feeEstimate(100) - - expect(feeRate).toBeDefined() -}) diff --git a/apps/ocean-api/__tests__/modules/PlaygroundModule.test.ts b/apps/ocean-api/__tests__/modules/PlaygroundModule.test.ts deleted file mode 100644 index 1fc7b22134..0000000000 --- a/apps/ocean-api/__tests__/modules/PlaygroundModule.test.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { OceanApiTesting } from '../../testing/OceanApiTesting' -import waitForExpect from 'wait-for-expect' - -describe('regtest', () => { - const apiTesting = OceanApiTesting.create() - - beforeEach(async () => { - apiTesting.playgroundEnable(false) - await apiTesting.start() - }) - - afterEach(async () => { - await apiTesting.stop() - }) - - it('should not increment block count', async () => { - const initial = await apiTesting.rpc.blockchain.getBlockCount() - - await new Promise((resolve) => { - setTimeout(_ => resolve(0), 5000) - }) - - const next = await apiTesting.rpc.blockchain.getBlockCount() - expect(next).toStrictEqual(initial) - }) -}) - -describe('playground', () => { - const apiTesting = OceanApiTesting.create() - - beforeEach(async () => { - apiTesting.playgroundEnable(true) - await apiTesting.start() - }) - - afterEach(async () => { - await apiTesting.stop() - }) - - it('should increment block count', async () => { - const initial = await apiTesting.rpc.blockchain.getBlockCount() - - await waitForExpect(async () => { - const next = await apiTesting.rpc.blockchain.getBlockCount() - expect(next).toBeGreaterThan(initial) - }) - }) -}) diff --git a/apps/ocean-api/src/controllers/RawTxController.ts b/apps/ocean-api/src/controllers/RawTxController.ts deleted file mode 100644 index 436c2c0ea2..0000000000 --- a/apps/ocean-api/src/controllers/RawTxController.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Controller, Get, ParseIntPipe, Query } from '@nestjs/common' -import { ApiClient, mining } from '@defichain/jellyfish-api-core' - -@Controller('/rawtx') -export class RawTxController { - constructor (private readonly client: ApiClient) { - } - - /** - * If fee rate cannot be estimated it will return a fixed rate of 0.00005000 - * That fee rate will max out at around 0.00001 DFI per average transaction (200vb). - * - * @param {number} confirmationTarget in blocks till fee get confirmed - * @return {Promise} fee rate per KB - */ - @Get('/fee/estimate') - async estimate (@Query('confirmationTarget', ParseIntPipe) confirmationTarget: number = 10): Promise { - const estimation = await this.client.mining.estimateSmartFee(confirmationTarget, mining.EstimateMode.CONSERVATIVE) - if (estimation.feerate !== undefined) { - return estimation.feerate - } - - return 0.00005000 - } -} diff --git a/apps/ocean-api/src/index.ts b/apps/ocean-api/src/index.ts deleted file mode 100644 index 7c96405831..0000000000 --- a/apps/ocean-api/src/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { RootModule } from './modules/RootModule' -import { NestFastifyApplication } from '@nestjs/platform-fastify' -import { NestFactory } from '@nestjs/core' -import { RootServer } from '@defichain-apps/libs/rootserver' - -export class OceanApiServer extends RootServer { - async create (): Promise { - return await NestFactory.create(RootModule, this.adapter) - } -} - -/** - * Bootstrap RootModule and start server - */ -if (require.main === module) { - void new OceanApiServer().start() -} diff --git a/apps/ocean-api/src/modules/ControllerModule.ts b/apps/ocean-api/src/modules/ControllerModule.ts deleted file mode 100644 index 450f1a4ee7..0000000000 --- a/apps/ocean-api/src/modules/ControllerModule.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { CacheModule, Module } from '@nestjs/common' -import { ActuatorController } from '@defichain-apps/libs/actuator' -import { APP_FILTER, APP_INTERCEPTOR, APP_PIPE } from '@nestjs/core' -import { GlobalValidationPipe, ResponseInterceptor, ErrorFilter } from '@defichain-apps/libs/filters' -import { ConfigService } from '@nestjs/config' -import { NetworkName } from '@defichain/jellyfish-network' -import { RawTxController } from '../controllers/RawTxController' - -/** - * Exposed ApiModule for public interfacing - */ -@Module({ - imports: [ - CacheModule.register() - ], - controllers: [ - ActuatorController, - RawTxController - ], - providers: [ - { - provide: APP_PIPE, - useClass: GlobalValidationPipe - }, - { - provide: APP_INTERCEPTOR, - useClass: ResponseInterceptor - }, - { - provide: APP_FILTER, - useClass: ErrorFilter - }, - { - provide: 'NETWORK_NAME', - useFactory: (configService: ConfigService): NetworkName => { - return configService.get('network') as NetworkName - }, - inject: [ConfigService] - } - ] -}) -export class ControllerModule { -} diff --git a/apps/ocean-api/src/modules/PlaygroundModule.ts b/apps/ocean-api/src/modules/PlaygroundModule.ts deleted file mode 100644 index 7ded526ee6..0000000000 --- a/apps/ocean-api/src/modules/PlaygroundModule.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { Injectable, Logger, Module } from '@nestjs/common' -import { ConfigService } from '@nestjs/config' -import { Interval, ScheduleModule } from '@nestjs/schedule' -import { BotLogger, Playground } from '@defichain/playground' -import { ApiClient } from '@defichain/jellyfish-api-core' - -/** - * Provide a PlaygroundRunner when PLAYGROUND_ENABLE is enabled. - */ -@Module({ - imports: [ - ScheduleModule.forRoot() - ], - providers: [ - { - provide: 'PLAYGROUND_RUNNER', - useFactory: (configService: ConfigService, apiClient: ApiClient): PlaygroundRunner | undefined => { - if (configService.get('PLAYGROUND_ENABLE') === false) { - return undefined - } - - if (configService.get('API_NETWORK') !== 'regtest') { - throw new Error('PLAYGROUND_ENABLE:true is only allowed on API_NETWORK:regtest') - } - - return new PlaygroundRunner(apiClient) - }, - inject: [ConfigService, ApiClient] - } - ] -}) -export class PlaygroundModule { -} - -/** - * Universal logger for playground using NestJS logger. - */ -class PlaygroundLogger implements BotLogger { - private readonly logger = new Logger(PlaygroundLogger.name) - - info (action: string, message: string): void { - this.logger.log(`${action} ${message}`) - } -} - -@Injectable() -class PlaygroundRunner { - constructor ( - private readonly apiClient: ApiClient, - private readonly logger: PlaygroundLogger = new PlaygroundLogger(), - private readonly playground: Playground = new Playground(apiClient, logger) - ) { - } - - async onApplicationBootstrap (): Promise { - this.logger.info('onApplicationBootstrap', 'Bootstrapping') - await this.playground.bootstrap() - this.logger.info('onApplicationBootstrap', 'Bootstrapped') - } - - @Interval(3000) - async cycle (): Promise { - await this.playground.cycle() - } -} diff --git a/apps/ocean-api/src/modules/RootModule.ts b/apps/ocean-api/src/modules/RootModule.ts deleted file mode 100644 index 0f89a5e7d2..0000000000 --- a/apps/ocean-api/src/modules/RootModule.ts +++ /dev/null @@ -1,33 +0,0 @@ -import * as Joi from 'joi' -import { Module } from '@nestjs/common' -import { ConfigModule } from '@nestjs/config' -import { ControllerModule } from './ControllerModule' -import { ActuatorModule } from '@defichain-apps/libs/actuator' -import { BlockchainCppModule } from '@defichain-apps/libs/blockchaincpp' -import { PlaygroundModule } from './PlaygroundModule' - -@Module({ - imports: [ - ConfigModule.forRoot({ - isGlobal: true, - cache: true, - validationSchema: ENV_VALIDATION_SCHEMA() - }), - ActuatorModule, - BlockchainCppModule, - ControllerModule, - PlaygroundModule - ] -}) -export class RootModule { -} - -function ENV_VALIDATION_SCHEMA (): any { - return Joi.object({ - NODE_ENV: Joi.string().valid('production', 'test').default('test'), - PORT: Joi.number().default(3000), - API_VERSION: Joi.string().regex(/^v[0-9]+(\.[0-9]+)?$/).default('v1'), - API_NETWORK: Joi.string().valid('regtest', 'testnet', 'mainnet').default('regtest'), - PLAYGROUND_ENABLE: Joi.boolean() - }) -} diff --git a/apps/ocean-api/testing/OceanApiTesting.ts b/apps/ocean-api/testing/OceanApiTesting.ts deleted file mode 100644 index e6cd5bdbc5..0000000000 --- a/apps/ocean-api/testing/OceanApiTesting.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { Testing, TestingGroup } from '@defichain/jellyfish-testing' -import { OceanApiClient } from '@defichain/ocean-api-client' -import { OceanStubServer } from './OceanStubServer' -import { OceanStubClient } from './OceanStubClient' -import { MasterNodeRegTestContainer } from '@defichain/testcontainers' -import { ApiClient } from '@defichain/jellyfish-api-core' -import { NestFastifyApplication } from '@nestjs/platform-fastify' - -/** - * OceanApi Testing framework. - */ -export class OceanApiTesting { - constructor ( - private readonly testingGroup: TestingGroup, - private readonly stubServer: OceanStubServer = new OceanStubServer(testingGroup.get(0).container), - private readonly stubApiClient: OceanStubClient = new OceanStubClient((stubServer)) - ) { - } - - static create (testingGroup: TestingGroup = TestingGroup.create(1)): OceanApiTesting { - return new OceanApiTesting(testingGroup) - } - - get group (): TestingGroup { - return this.testingGroup - } - - get testing (): Testing { - return this.testingGroup.get(0) - } - - get container (): MasterNodeRegTestContainer { - return this.testing.container - } - - get rpc (): ApiClient { - return this.testing.rpc - } - - get app (): NestFastifyApplication { - if (this.stubServer.app === undefined) { - throw new Error('not yet initialized') - } - return this.stubServer.app - } - - get client (): OceanApiClient { - return this.stubApiClient - } - - /** - * @param {boolean} bool to enable PlaygroundModule for OceanApiTest - * @see PlaygroundModule - */ - playgroundEnable (bool: boolean): void { - this.stubServer.playgroundEnable = bool - } - - /** - * Start connected services for testing. - * - * @see TestingGroup - * @see Testing - * @see OceanStubServer - */ - async start (): Promise { - await this.group.start() - await this.stubServer.start() - } - - /** - * Stop all connected services. - * - * @see TestingGroup - * @see Testing - * @see OceanStubServer - */ - async stop (): Promise { - try { - await this.stubServer.stop() - } catch (err) { - console.error(err) - } - try { - await this.group.stop() - } catch (err) { - console.error(err) - } - } -} diff --git a/apps/ocean-api/testing/OceanStubClient.ts b/apps/ocean-api/testing/OceanStubClient.ts deleted file mode 100644 index 5522313152..0000000000 --- a/apps/ocean-api/testing/OceanStubClient.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { ApiMethod, OceanApiClient, ResponseAsString } from '@defichain/ocean-api-client' -import { OceanStubServer } from './OceanStubServer' -import { ConfigService } from '@nestjs/config' - -/** - * Client stubs are simulations of a real client, which are used for functional testing. - * StubClient simulate a real OceanApiClient connected to an Ocean API. - */ -export class OceanStubClient extends OceanApiClient { - constructor (readonly service: OceanStubServer) { - super({ url: 'not required for stub service' }) - } - - async requestAsString (method: ApiMethod, path: string, body?: string): Promise { - if (this.service.app === undefined) { - throw new Error('StubService is not yet started.') - } - - const version = this.service.app.get(ConfigService).get('API_VERSION') as string - const network = this.service.app.get(ConfigService).get('API_NETWORK') as string - - const res = await this.service.app.inject({ - method: method, - url: `/${version}/${network}/${path}`, - payload: body, - headers: method !== 'GET' ? { 'Content-Type': 'application/json' } : {} - }) - - return { - body: res.body, - status: res.statusCode - } - } -} diff --git a/apps/ocean-api/testing/OceanStubServer.ts b/apps/ocean-api/testing/OceanStubServer.ts deleted file mode 100644 index 5b2150514a..0000000000 --- a/apps/ocean-api/testing/OceanStubServer.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { MasterNodeRegTestContainer } from '@defichain/testcontainers' -import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify' -import { Test } from '@nestjs/testing' -import { RootModule } from '../src/modules/RootModule' -import { OceanApiServer } from '../src' -import { ConfigModule, ConfigService } from '@nestjs/config' - -/** - * Service stubs are simulations of a real service, which are used for functional testing. - * Configures a TestingModule that is configured to connect to a provided @defichain/testcontainers. - */ -export class OceanStubServer extends OceanApiServer { - /** - * @see PlaygroundModule - */ - public playgroundEnable: boolean = false - - constructor (private readonly container: MasterNodeRegTestContainer) { - super() - } - - async create (): Promise { - const url = await this.container.getCachedRpcUrl() - const module = await Test.createTestingModule({ - imports: [ - RootModule, - ConfigModule.forFeature(() => { - return { - BLOCKCHAIN_CPP_URL: url, - PLAYGROUND_ENABLE: this.playgroundEnable - } - }) - ] - }).compile() - - const adapter = new FastifyAdapter({ - logger: false - }) - return module.createNestApplication(adapter) - } - - async init (app: NestFastifyApplication, config: ConfigService): Promise { - await app.init() - } -} diff --git a/apps/package.json b/apps/package.json index d7b0483b96..c545fcfa65 100644 --- a/apps/package.json +++ b/apps/package.json @@ -25,9 +25,7 @@ "@defichain/jellyfish-transaction": "^0.0.0", "@defichain/jellyfish-transaction-builder": "^0.0.0", "@defichain/jellyfish-wallet": "^0.0.0", - "@defichain/ocean-api-client": "^0.0.0", "@defichain/playground-api-client": "^0.0.0", - "@defichain/playground": "^0.0.0", "@defichain/testcontainers": "^0.0.0", "@defichain/testing": "^0.0.0", "@defichain/whale-api-client": "^0.0.0", diff --git a/package-lock.json b/package-lock.json index 4762674e24..432a1d313b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,8 +48,6 @@ "@defichain/jellyfish-transaction": "^0.0.0", "@defichain/jellyfish-transaction-builder": "^0.0.0", "@defichain/jellyfish-wallet": "^0.0.0", - "@defichain/ocean-api-client": "^0.0.0", - "@defichain/playground": "^0.0.0", "@defichain/playground-api-client": "^0.0.0", "@defichain/testcontainers": "^0.0.0", "@defichain/testing": "^0.0.0", @@ -25785,6 +25783,8 @@ "version": "0.0.0", "license": "MIT", "dependencies": { + "@defichain/jellyfish-transaction": "^0.0.0", + "@defichain/jellyfish-wallet": "^0.0.0", "bip32": "^2.0.6", "bip39": "^3.0.4", "create-hmac": "^1.1.7" @@ -27469,8 +27469,6 @@ "@defichain/jellyfish-transaction": "^0.0.0", "@defichain/jellyfish-transaction-builder": "^0.0.0", "@defichain/jellyfish-wallet": "^0.0.0", - "@defichain/ocean-api-client": "^0.0.0", - "@defichain/playground": "^0.0.0", "@defichain/playground-api-client": "^0.0.0", "@defichain/testcontainers": "^0.0.0", "@defichain/testing": "^0.0.0", @@ -27739,6 +27737,8 @@ "@defichain/jellyfish-wallet-mnemonic": { "version": "file:packages/jellyfish-wallet-mnemonic", "requires": { + "@defichain/jellyfish-transaction": "^0.0.0", + "@defichain/jellyfish-wallet": "^0.0.0", "@types/create-hmac": "1.1.0", "bip32": "^2.0.6", "bip39": "^3.0.4", @@ -35581,8 +35581,6 @@ "@defichain/jellyfish-transaction": "^0.0.0", "@defichain/jellyfish-transaction-builder": "^0.0.0", "@defichain/jellyfish-wallet": "^0.0.0", - "@defichain/ocean-api-client": "^0.0.0", - "@defichain/playground": "^0.0.0", "@defichain/playground-api-client": "^0.0.0", "@defichain/testcontainers": "^0.0.0", "@defichain/testing": "^0.0.0", @@ -35851,6 +35849,8 @@ "@defichain/jellyfish-wallet-mnemonic": { "version": "file:packages/jellyfish-wallet-mnemonic", "requires": { + "@defichain/jellyfish-transaction": "^0.0.0", + "@defichain/jellyfish-wallet": "^0.0.0", "@types/create-hmac": "1.1.0", "bip32": "^2.0.6", "bip39": "^3.0.4", diff --git a/packages/ocean-api-client/src/OceanApiClient.ts b/packages/ocean-api-client/src/OceanApiClient.ts index e4682f68e5..81248b2e13 100644 --- a/packages/ocean-api-client/src/OceanApiClient.ts +++ b/packages/ocean-api-client/src/OceanApiClient.ts @@ -2,7 +2,6 @@ import 'url-search-params-polyfill' import AbortController from 'abort-controller' import fetch from 'cross-fetch' import { ApiException, ApiMethod, ApiPagedResponse, ApiResponse, ClientException, TimeoutException } from './' -import { RawTx } from './apis/RawTx' /** * OceanApiClient configurable options @@ -32,8 +31,6 @@ export interface OceanApiClientOptions { * OceanApiClient */ export class OceanApiClient { - public readonly rawtx = new RawTx(this) - constructor ( protected readonly options: OceanApiClientOptions ) { diff --git a/packages/ocean-api-client/src/apis/RawTx.ts b/packages/ocean-api-client/src/apis/RawTx.ts index 086042d5a9..a81724fbfa 100644 --- a/packages/ocean-api-client/src/apis/RawTx.ts +++ b/packages/ocean-api-client/src/apis/RawTx.ts @@ -1,5 +1,8 @@ import { OceanApiClient } from '../' +/** + * @deprecated removing support very soon + */ export class RawTx { constructor (private readonly api: OceanApiClient) { }