Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(): support whale test suite for defid ocean #2174

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b475a6b
wip
canonbrother Nov 30, 2023
41ac0c3
waitForIndexedHeight
canonbrother Dec 11, 2023
8115a1e
stub ctrls into DefidBin
canonbrother Dec 11, 2023
411fe85
unhide block.e2e
canonbrother Dec 13, 2023
99616ca
fix addr.ctrl func mapping
canonbrother Dec 13, 2023
11ba5ab
fix addr.ctrl func mapping
canonbrother Dec 13, 2023
a9859bd
return json
canonbrother Dec 13, 2023
1c59500
temp fix waitForAddressTxCount
canonbrother Dec 13, 2023
f1485f0
unhide address.e2e & update ctrl return mapping
canonbrother Dec 13, 2023
b5d08d9
map return type from addr -> rawtx
canonbrother Dec 13, 2023
29f861d
todo
canonbrother Dec 13, 2023
79d7d91
overload createTestingApp
canonbrother Dec 14, 2023
c009c3d
map return type from stats -> tx
canonbrother Dec 14, 2023
038474a
update stats e2e
canonbrother Dec 14, 2023
6199d96
typo
canonbrother Dec 14, 2023
b05021d
update fee e2e
canonbrother Dec 14, 2023
d7222a6
add governance defidbin api & update governance e2e
canonbrother Dec 14, 2023
fee0f70
update e2e to compact defid
canonbrother Dec 14, 2023
f6f1aa5
oceanarchive
canonbrother Jan 2, 2024
ae4febe
fix OceanProposalQuery
canonbrother Jan 2, 2024
277cc11
fix rawtx get
canonbrother Jan 3, 2024
7c17c0a
wait for ocean
canonbrother Jan 3, 2024
e593410
fix listProposalVotes
canonbrother Jan 3, 2024
e17804e
refine defid module from 2 objects ocean & blockchain -> 1 object (oc…
canonbrother Jan 25, 2024
b022c8e
add defid mod utils
canonbrother Jan 25, 2024
c7148fb
add defid utils
canonbrother Jan 25, 2024
601b8ba
refine token e2e
canonbrother Jan 25, 2024
dfcd165
fix block ctrl
canonbrother Jan 25, 2024
1819b10
add api blocks/highest
canonbrother Jan 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
687 changes: 687 additions & 0 deletions apps/whale-api/src/e2e.defid.module.ts

Large diffs are not rendered by default.

29 changes: 21 additions & 8 deletions apps/whale-api/src/e2e.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { addressToHid } from './module.api/address.controller'
import { ScriptAggregationMapper } from './module.model/script.aggregation'
import { TestingGroup } from '@defichain/jellyfish-testing'
import { DefidBin } from './e2e.defid.module'

/**
* Configures an end-to-end testing app integrated with all modules.
Expand Down Expand Up @@ -46,7 +47,7 @@
} finally {
await new Promise((resolve) => {
// Wait 2000ms between indexer cycle time to prevent database error
setTimeout(_ => resolve(0), 500)
setTimeout((_: any) => resolve(0), 500)
})

if (container instanceof MasterNodeRegTestContainer) {
Expand Down Expand Up @@ -82,12 +83,20 @@
* @param {number} height to wait for
* @param {number} [timeout=30000]
*/
export async function waitForIndexedHeight (app: NestFastifyApplication, height: number, timeout: number = 30000): Promise<void> {
const blockMapper = app.get(BlockMapper)
await waitForExpect(async () => {
const block = await blockMapper.getHighest()
await expect(block?.height).toBeGreaterThan(height)
}, timeout)
export async function waitForIndexedHeight (app: NestFastifyApplication | DefidBin, height: number, timeout: number = 30000): Promise<void> {
if (app instanceof DefidBin) {
await waitForExpect(async () => {
const block = await app.ocean.blockController.getHighest()
expect(block?.height).toBeGreaterThan(height)
await app.rpc.generate(1)

Check warning on line 91 in apps/whale-api/src/e2e.module.ts

View check run for this annotation

Codecov / codecov/patch

apps/whale-api/src/e2e.module.ts#L88-L91

Added lines #L88 - L91 were not covered by tests
}, timeout)
} else {
const blockMapper = app.get(BlockMapper)
await waitForExpect(async () => {
const block = await blockMapper.getHighest()
expect(block?.height).toBeGreaterThan(height)
}, timeout)
}
await new Promise((resolve) => setTimeout(resolve, 1000))
}

Expand All @@ -105,7 +114,11 @@
}, timeout)
}

export async function waitForAddressTxCount (app: NestFastifyApplication, address: string, txCount: number, timeout: number = 15000): Promise<void> {
// TODO(): handle DefidBin
export async function waitForAddressTxCount (app: NestFastifyApplication | DefidBin, address: string, txCount: number, timeout: number = 15000): Promise<void> {
if (app instanceof DefidBin) {
return

Check warning on line 120 in apps/whale-api/src/e2e.module.ts

View check run for this annotation

Codecov / codecov/patch

apps/whale-api/src/e2e.module.ts#L120

Added line #L120 was not covered by tests
}
const hid = addressToHid('regtest', address)
const aggregationMapper = app.get(ScriptAggregationMapper)
await waitForExpect(async () => {
Expand Down
47 changes: 38 additions & 9 deletions apps/whale-api/src/module.api/address.controller.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import { Testing } from '@defichain/jellyfish-testing'
import { ForbiddenException } from '@nestjs/common'
import BigNumber from 'bignumber.js'
import { RegTestFoundationKeys } from '@defichain/jellyfish-network'
import { DAddressController, DefidBin } from '../e2e.defid.module'

const container = new MasterNodeRegTestContainer()
let app: NestFastifyApplication
let controller: AddressController
let app: NestFastifyApplication | DefidBin
let controller: AddressController | DAddressController
const testing = Testing.create(container)
let colAddr: string
let usdcAddr: string
Expand Down Expand Up @@ -149,7 +150,11 @@ describe('listAccountHistory', () => {
await testing.generate(1)

app = await createTestingApp(container)
controller = app.get(AddressController)
if (app instanceof DefidBin) {
controller = app.addressController
} else {
controller = app.get(AddressController)
}

await testing.generate(1)

Expand Down Expand Up @@ -398,7 +403,11 @@ describe('getAccount', () => {
await testing.generate(1)

app = await createTestingApp(container)
controller = app.get(AddressController)
if (app instanceof DefidBin) {
controller = app.addressController
} else {
controller = app.get(AddressController)
}

await testing.generate(1)
})
Expand Down Expand Up @@ -474,7 +483,11 @@ describe('getBalance', () => {
await container.waitForWalletBalanceGTE(100)

app = await createTestingApp(container)
controller = app.get(AddressController)
if (app instanceof DefidBin) {
controller = app.addressController
} else {
controller = app.get(AddressController)
}

await waitForIndexedHeight(app, 100)
})
Expand Down Expand Up @@ -543,7 +556,11 @@ describe('getAggregation', () => {
await container.waitForWalletBalanceGTE(100)

app = await createTestingApp(container)
controller = app.get(AddressController)
if (app instanceof DefidBin) {
controller = app.addressController
} else {
controller = app.get(AddressController)
}

await waitForIndexedHeight(app, 100)
})
Expand Down Expand Up @@ -599,7 +616,11 @@ describe('listTransactions', () => {
await container.waitForWalletBalanceGTE(100)

app = await createTestingApp(container)
controller = app.get(AddressController)
if (app instanceof DefidBin) {
controller = app.addressController
} else {
controller = app.get(AddressController)
}

await waitForIndexedHeight(app, 100)

Expand Down Expand Up @@ -759,7 +780,11 @@ describe('listTransactionsUnspent', () => {
await container.waitForWalletBalanceGTE(100)

app = await createTestingApp(container)
controller = app.get(AddressController)
if (app instanceof DefidBin) {
controller = app.addressController
} else {
controller = app.get(AddressController)
}

await waitForIndexedHeight(app, 100)

Expand Down Expand Up @@ -988,7 +1013,11 @@ describe('listTokens', () => {
await container.waitForWalletBalanceGTE(100)

app = await createTestingApp(container)
controller = app.get(AddressController)
if (app instanceof DefidBin) {
controller = app.addressController
} else {
controller = app.get(AddressController)
}

await waitForIndexedHeight(app, 100)

Expand Down
40 changes: 28 additions & 12 deletions apps/whale-api/src/module.api/block.controller.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,33 @@ import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { NestFastifyApplication } from '@nestjs/platform-fastify'
import { createTestingApp, stopTestingApp, waitForIndexedHeight } from '../e2e.module'
import { JsonRpcClient } from '@defichain/jellyfish-api-jsonrpc'
import { DBlockController, DefidBin, DefidRpc } from '../e2e.defid.module'

const container = new MasterNodeRegTestContainer()
let app: NestFastifyApplication
let controller: BlockController
let app: NestFastifyApplication | DefidBin
let container: MasterNodeRegTestContainer | DefidRpc
let controller: BlockController | DBlockController
let client: JsonRpcClient

beforeAll(async () => {
await container.start()
await container.waitForBlockHeight(101)

app = await createTestingApp(container)

await waitForIndexedHeight(app, 100)
controller = app.get(BlockController)
client = new JsonRpcClient(await container.getCachedRpcUrl())
if (process.env.DEFID !== undefined) {
app = new DefidBin()
await app.start()
container = app.rpc
controller = app.ocean.blockController
await container.waitForBlockHeight(101)
// await waitForIndexedHeight(app, 100)
client = new JsonRpcClient(container.getCachedRpcUrl())
} else {
container = new MasterNodeRegTestContainer()
await container.start()
await container.waitForBlockHeight(101)

app = await createTestingApp(container)

await waitForIndexedHeight(app, 100)
controller = app.get(BlockController)
client = new JsonRpcClient(await container.getCachedRpcUrl())
}

const address = await container.getNewAddress()
for (let i = 0; i < 4; i += 1) {
Expand All @@ -29,7 +41,11 @@ beforeAll(async () => {
})

afterAll(async () => {
await stopTestingApp(container, app)
if (process.env.DEFID !== undefined) {
await (app as DefidBin).stop()
return
}
await stopTestingApp(container as MasterNodeRegTestContainer, app as NestFastifyApplication)
})

describe('get', () => {
Expand Down
33 changes: 24 additions & 9 deletions apps/whale-api/src/module.api/fee.controller.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,39 @@ import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { NestFastifyApplication } from '@nestjs/platform-fastify'
import { createTestingApp, stopTestingApp } from '../e2e.module'
import { FeeController } from './fee.controller'
import { DefidBin, DefidRpc, DFeeController } from '../e2e.defid.module'

const container = new MasterNodeRegTestContainer()
let app: NestFastifyApplication
let controller: FeeController
let container: MasterNodeRegTestContainer | DefidRpc
let app: NestFastifyApplication | DefidBin
let controller: FeeController | DFeeController
let client: JsonRpcClient

beforeAll(async () => {
await container.start()
await container.waitForWalletCoinbaseMaturity()
await container.waitForWalletBalanceGTE(100)
if (process.env.DEFID !== undefined) {
app = new DefidBin()
await app.start()
container = app.rpc
controller = app.ocean.feeController
await container.waitForWalletCoinbaseMaturity()
await container.waitForWalletBalanceGTE(100)
} else {
container = new MasterNodeRegTestContainer()
await container.start()
await container.waitForWalletCoinbaseMaturity()
await container.waitForWalletBalanceGTE(100)
app = await createTestingApp(container)
controller = app.get<FeeController>(FeeController)
}

app = await createTestingApp(container)
controller = app.get<FeeController>(FeeController)
client = new JsonRpcClient(await container.getCachedRpcUrl())
})

afterAll(async () => {
await stopTestingApp(container, app)
if (process.env.DEFID !== undefined) {
await (app as DefidBin).stop()
return
}
await stopTestingApp(container as MasterNodeRegTestContainer, app as NestFastifyApplication)
})

describe('fee/estimate', () => {
Expand Down
17 changes: 13 additions & 4 deletions apps/whale-api/src/module.api/governance.controller.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { NestFastifyApplication } from '@nestjs/platform-fastify'
import BigNumber from 'bignumber.js'
import { createTestingApp, stopTestingApp } from '../e2e.module'
import { GovernanceController } from './governance.controller'
import { DefidBin, DGovernanceController } from '../e2e.defid.module'

class MultiOperatorGovernanceMasterNodeRegTestContainer extends MasterNodeRegTestContainer {
protected getCmd (opts: StartOptions): string[] {
Expand All @@ -22,8 +23,8 @@ class MultiOperatorGovernanceMasterNodeRegTestContainer extends MasterNodeRegTes
}
}
const container = new MultiOperatorGovernanceMasterNodeRegTestContainer()
let app: NestFastifyApplication
let controller: GovernanceController
let app: NestFastifyApplication | DefidBin
let controller: GovernanceController | DGovernanceController
const testing = Testing.create(container)
let cfpProposalId: string
let vocProposalId: string
Expand All @@ -39,7 +40,11 @@ describe('governance - listProposals and getProposal', () => {
])
await testing.container.generate(1)
app = await createTestingApp(container)
controller = app.get(GovernanceController)
if (app instanceof DefidBin) {
controller = app.governanceController
} else {
controller = app.get(GovernanceController)
}

// Create 1 CFP + 1 VOC
payoutAddress = await testing.generateAddress()
Expand Down Expand Up @@ -259,7 +264,11 @@ describe('governance - listProposalVotes', () => {
])
await testing.container.generate(1)
app = await createTestingApp(container)
controller = app.get(GovernanceController)
if (app instanceof DefidBin) {
controller = app.governanceController
} else {
controller = app.get(GovernanceController)
}

/**
* Import the private keys of the masternode_operator in order to be able to mint blocks and vote on proposals.
Expand Down
Loading
Loading