From 5c5599cd8f7840e338e156ae1207aed25e5e18fe Mon Sep 17 00:00:00 2001 From: canonbrother Date: Thu, 10 Oct 2024 16:03:22 +0800 Subject: [PATCH] add rpc test --- apps/whale-api/src/e2e.defid.module.ts | 14 ++++++++ .../__defid__/rpc.controller.defid.ts | 32 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 apps/whale-api/src/module.api/__defid__/rpc.controller.defid.ts diff --git a/apps/whale-api/src/e2e.defid.module.ts b/apps/whale-api/src/e2e.defid.module.ts index ba0117794..03bb1e3ad 100644 --- a/apps/whale-api/src/e2e.defid.module.ts +++ b/apps/whale-api/src/e2e.defid.module.ts @@ -74,6 +74,11 @@ interface RawTxDto { maxFeeRate?: number } +interface RpcDto { + method: string + params: any[] +} + class DefidOceanApiClient { constructor (protected readonly options: WhaleApiClientOptions) { this.options = { @@ -467,6 +472,14 @@ export class DTransactionController { } } +export class DRpcController { + constructor (protected readonly client: DefidOceanApiClient) {} + + async post (rpcDto: RpcDto): Promise { + return await this.client.post('rpc', rpcDto) + } +} + export class DefidOcean { readonly addressController = new DAddressController(this.api) readonly blockController = new DBlockController(this.api) @@ -481,6 +494,7 @@ export class DefidOcean { readonly statsController = new DStatsController(this.api) readonly transactionController = new DTransactionController(this.api) readonly tokenController = new DTokenController(this.api) + readonly rpcController = new DRpcController(this.api) constructor ( readonly api: DefidOceanApiClient diff --git a/apps/whale-api/src/module.api/__defid__/rpc.controller.defid.ts b/apps/whale-api/src/module.api/__defid__/rpc.controller.defid.ts new file mode 100644 index 000000000..67dc26a90 --- /dev/null +++ b/apps/whale-api/src/module.api/__defid__/rpc.controller.defid.ts @@ -0,0 +1,32 @@ +import { DRpcController, DefidBin } from '../../e2e.defid.module' + +let app: DefidBin +let controller: DRpcController + +beforeAll(async () => { + app = new DefidBin() + await app.start() + controller = app.ocean.rpcController + await app.waitForWalletCoinbaseMaturity() + await app.waitForWalletBalanceGTE(100) + + await app.waitForBlockHeight(100) +}) + +afterAll(async () => { + await app.stop() +}) + +it('test whitelisted getblockcount rpc call', async () => { + const res = await controller.post({ method: 'getblockcount', params: [] }) + expect(res.data).toStrictEqual(101) +}) + +it('test **NOT** whitelisted listpoolpairs rpc call', async () => { + await expect( + controller.post({ + method: 'listpoolpairs', + params: [{ start: 0, including_start: true, limit: 3 }, true] + }) + ).rejects.toThrowError('403 - Unknown (/v0/regtest/rpc): Rpc listpoolpairs method is not whitelisted') +})