Skip to content

Commit

Permalink
add rpc test
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Oct 10, 2024
1 parent e605196 commit 5c5599c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
14 changes: 14 additions & 0 deletions apps/whale-api/src/e2e.defid.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ interface RawTxDto {
maxFeeRate?: number
}

interface RpcDto {
method: string
params: any[]
}

class DefidOceanApiClient {
constructor (protected readonly options: WhaleApiClientOptions) {
this.options = {
Expand Down Expand Up @@ -467,6 +472,14 @@ export class DTransactionController {
}
}

export class DRpcController {
constructor (protected readonly client: DefidOceanApiClient) {}

async post (rpcDto: RpcDto): Promise<any> {
return await this.client.post('rpc', rpcDto)
}
}

export class DefidOcean {
readonly addressController = new DAddressController(this.api)
readonly blockController = new DBlockController(this.api)
Expand All @@ -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
Expand Down
32 changes: 32 additions & 0 deletions apps/whale-api/src/module.api/__defid__/rpc.controller.defid.ts
Original file line number Diff line number Diff line change
@@ -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')
})

0 comments on commit 5c5599c

Please sign in to comment.