Skip to content

Commit

Permalink
stub ctrls into DefidBin
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Dec 11, 2023
1 parent 41ac0c3 commit 8115a1e
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 97 deletions.
207 changes: 112 additions & 95 deletions apps/whale-api/src/e2e.defid.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,98 @@ class DefidOceanApi {

export class DefidOceanController {
protected readonly api: DefidOceanApi = new DefidOceanApi()
}

export class DAddressController extends DefidOceanController {
async getAccountHistory (address: string, height: number, txno: number) {
return await this.api.get(`/address/${address}/history/${height}/${txno}`)
}

async listAccountHistory (address: string, query: OceanListQuery = { size: 30 }) {
if (query.next !== undefined) {
return await this.api.get(`/address/${address}/history?size=${query.size}&next=${query.next}`)
}
return await this.api.get(`/address/${address}/history?size=${query.size}`)
}

async getBalance (address: string) {
return await this.api.get(`/address/${address}/balance`)
}

async getAggregation (address: string) {
return await this.api.get(`/address/${address}/aggregation`)
}

async listAddressTokens (address: string, query: OceanListQuery = { size: 30 }) {
if (query.next !== undefined) {
return await this.api.get(`/address/${address}/tokens?size=${query.size}&next=${query.next}`)
}
return await this.api.get(`/address/${address}/tokens?size=${query.size}`)
}

// ======== FeeController ========
async estimateFee () {
async listAddressVaults (address: string, query: OceanListQuery = { size: 30 }) {
if (query.next !== undefined) {
return await this.api.get(`/address/${address}/vaults?size=${query.size}&next=${query.next}`)
}
return await this.api.get(`/address/${address}/vaults?size=${query.size}`)
}

async listAddressTransactions (address: string, query: OceanListQuery = { size: 30 }) {
if (query.next !== undefined) {
return await this.api.get(`/address/${address}/transactions?size=${query.size}&next=${query.next}`)
}
return await this.api.get(`/address/${address}/transactions?size=${query.size}`)
}

async listAddressTransactionsUnspent (address: string, query: OceanListQuery = { size: 30 }) {
if (query.next !== undefined) {
return await this.api.get(`/address/${address}/transactions/unspent?size=${query.size}&next=${query.next}`)
}
return await this.api.get(`/address/${address}/transactions/unspent?size=${query.size}`)
}
}

export class DBlockController extends DefidOceanController {
async list (query: OceanListQuery = { size: 30 }): Promise<any> {
if (query.next !== undefined) {
return await this.api.get(`/blocks/transactions?size=${query.size}&next=${query.next}`)
}
return await this.api.get(`/blocks/transactions?size=${query.size}`)
}

async get (id: string): Promise<any> {
return await this.api.get(`/blocks/${id}`)
}

async getTransactions (hash: string, query: OceanListQuery = { size: 30 }): Promise<any> {
if (query.next !== undefined) {
return await this.api.get(`/blocks/${hash}/transactions?size=${query.size}&next=${query.next}`)
}
return await this.api.get(`/blocks/${hash}/transactions?size=${query.size}`)
}
}

export class DFeeController extends DefidOceanController {
async estimate () {
return await this.api.get('/fee/estimate')
}
}

// ======== MasternodeController ========
async listMasternodes (query: OceanListQuery = { size: 30 }) {
export class DMasternodeController extends DefidOceanController {
async list (query: OceanListQuery = { size: 30 }) {
if (query.next !== undefined) {
return await this.api.get(`/masternodes?size=${query.size}&next=${query.next}`)
}
return await this.api.get(`/masternodes?size=${query.size}`)
}

async getMasternode (id: string) {
async get (id: string) {
return await this.api.get(`/masternodes/${id}`)
}
}

// ======== OracleController ========
async listOracles (query: OceanListQuery = { size: 30 }) {
export class DOracleController extends DefidOceanController {
async list (query: OceanListQuery = { size: 30 }) {
if (query.next !== undefined) {
return await this.api.get(`/oracles?size=${query.size}&next=${query.next}`)
}
Expand All @@ -71,16 +143,17 @@ export class DefidOceanController {
async getOracleByAddress (address: string) {
return await this.api.get(`/oracles/${address}`)
}
}

// ======== PoolPairController ========
async listPoolPairs (query: OceanListQuery = { size: 30 }) {
export class DPoolPairController extends DefidOceanController {
async list (query: OceanListQuery = { size: 30 }) {
if (query.next !== undefined) {
return await this.api.get(`/poolpairs?size=${query.size}&next=${query.next}`)
}
return await this.api.get(`/poolpairs?size=${query.size}`)
}

async getPoolPair (id: string) {
async get (id: string) {
return await this.api.get(`/poolpairs/${id}`)
}

Expand Down Expand Up @@ -120,16 +193,17 @@ export class DefidOceanController {
async listDexPrices (denomination: string) {
return await this.api.get(`/poolpairs/dexprices?denomination=${denomination}`)
}
}

// ======== PriceController ========
async listPrices (query: OceanListQuery = { size: 30 }) {
export class DPriceController extends DefidOceanController {
async list (query: OceanListQuery = { size: 30 }) {
if (query.next !== undefined) {
return await this.api.get(`/prices?size=${query.size}&next=${query.next}`)
}
return await this.api.get(`/prices?size=${query.size}`)
}

async getPrice (id: string) {
async get (id: string) {
return await this.api.get(`/prices/${id}`)
}

Expand All @@ -145,24 +219,27 @@ export class DefidOceanController {
return await this.api.get(`/prices/${id}/feed/interval/${interval}`)
}

async get_oracles (id: string) {
async listPriceOracles (id: string) {
return await this.api.get(`/prices/${id}/oracles`)
}
}

export class DRawTxController extends DefidOceanController {
async sendRawtx () {
return await this.api.post('/rawtx/send')
}

// ======== RawTxController ========
// async sendRawtx() {
// return this.post(`/rawtx/send`)
// }
async testRawtx () {
return await this.api.get('/rawtx/test')
}

async getRawtx (id: string) {
return await this.api.get(`/rawtx/${id}`)
}
}

// ======== StatController ========
async getStats () {
export class DStateController extends DefidOceanController {
async get () {
return await this.api.get('/stats')
}

Expand All @@ -177,18 +254,20 @@ export class DefidOceanController {
async getBurn () {
return await this.api.get('/stats/burn')
}
}

// ======== TokenController ========
async listTokens () {
export class DTokenController extends DefidOceanController {
async list () {
return await this.api.get('/tokens')
}

async getToken (id: string) {
async get (id: string) {
return await this.api.get(`/tokens/${id}`)
}
}

// ======== TransactionController ========
async getTransaction (id: string) {
export class DTransactionController extends DefidOceanController {
async get (id: string) {
return await this.api.get(`/transactions/${id}`)
}

Expand All @@ -201,83 +280,21 @@ export class DefidOceanController {
}
}

export class DAddressController extends DefidOceanController {
async getAccountHistory (address: string, height: number, txno: number) {
return await this.api.get(`/address/${address}/history/${height}/${txno}`)
}

async listAccountHistory (address: string, query: OceanListQuery = { size: 30 }) {
if (query.next !== undefined) {
return await this.api.get(`/address/${address}/history?size=${query.size}&next=${query.next}`)
}
return await this.api.get(`/address/${address}/history?size=${query.size}`)
}

async getBalance (address: string) {
return await this.api.get(`/address/${address}/balance`)
}

async getAggregation (address: string) {
return await this.api.get(`/address/${address}/aggregation`)
}

async listAddressTokens (address: string, query: OceanListQuery = { size: 30 }) {
if (query.next !== undefined) {
return await this.api.get(`/address/${address}/tokens?size=${query.size}&next=${query.next}`)
}
return await this.api.get(`/address/${address}/tokens?size=${query.size}`)
}

async listAddressVaults (address: string, query: OceanListQuery = { size: 30 }) {
if (query.next !== undefined) {
return await this.api.get(`/address/${address}/vaults?size=${query.size}&next=${query.next}`)
}
return await this.api.get(`/address/${address}/vaults?size=${query.size}`)
}

async listAddressTransactions (address: string, query: OceanListQuery = { size: 30 }) {
if (query.next !== undefined) {
return await this.api.get(`/address/${address}/transactions?size=${query.size}&next=${query.next}`)
}
return await this.api.get(`/address/${address}/transactions?size=${query.size}`)
}

async listAddressTransactionsUnspent (address: string, query: OceanListQuery = { size: 30 }) {
if (query.next !== undefined) {
return await this.api.get(`/address/${address}/transactions/unspent?size=${query.size}&next=${query.next}`)
}
return await this.api.get(`/address/${address}/transactions/unspent?size=${query.size}`)
}
}

export class DBlockController extends DefidOceanController {
async list (query: OceanListQuery = { size: 30 }): Promise<any> {
if (query.next !== undefined) {
return await this.api.get(`/blocks/transactions?size=${query.size}&next=${query.next}`)
}
return await this.api.get(`/blocks/transactions?size=${query.size}`)
}

async get (id: string): Promise<any> {
return await this.api.get(`/blocks/${id}`)
}

async getTransactions (hash: string, query: OceanListQuery = { size: 30 }): Promise<any> {
if (query.next !== undefined) {
return await this.api.get(`/blocks/${hash}/transactions?size=${query.size}&next=${query.next}`)
}
return await this.api.get(`/blocks/${hash}/transactions?size=${query.size}`)
}
}

export class DefidBin {
tmpDir: string = `/tmp/${uuidv4()}`
binary: ChildProcess | null = null

public constructor (
readonly container: MasterNodeRegTestContainer,
readonly addressController: DAddressController,
readonly blockController: DBlockController
readonly blockController: DBlockController,
readonly feeController: DFeeController,
readonly masternodeController: DMasternodeController,
readonly oracleController: DOracleController,
readonly poolPairController: DPoolPairController,
readonly priceController: DPriceController,
readonly transactionController: DTransactionController,
readonly tokenController: DTokenController
) {
}

Expand Down
11 changes: 9 additions & 2 deletions apps/whale-api/src/e2e.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import waitForExpect from 'wait-for-expect'
import { addressToHid } from './module.api/address.controller'
import { ScriptAggregationMapper } from './module.model/script.aggregation'
import { TestingGroup } from '@defichain/jellyfish-testing'
import { DefidBin, DAddressController, DBlockController } from './e2e.defid.module'
import { DefidBin, DAddressController, DBlockController, DFeeController, DMasternodeController, DOracleController, DPoolPairController, DPriceController, DTransactionController, DTokenController } from './e2e.defid.module'

/**
* Configures an end-to-end testing app integrated with all modules.
Expand All @@ -26,7 +26,14 @@ export async function createTestingApp (container: MasterNodeRegTestContainer):
const defid = new DefidBin(
container,
new DAddressController(),
new DBlockController()
new DBlockController(),
new DFeeController(),
new DMasternodeController(),
new DOracleController(),
new DPoolPairController(),
new DPriceController(),
new DTransactionController(),
new DTokenController()
)
await defid.start()
return defid
Expand Down

0 comments on commit 8115a1e

Please sign in to comment.