Skip to content

Commit

Permalink
unhide block.e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Dec 13, 2023
1 parent 8115a1e commit 411fe85
Showing 1 changed file with 91 additions and 91 deletions.
182 changes: 91 additions & 91 deletions apps/whale-api/src/module.api/block.controller.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { BlockController } from './block.controller'
import { BlockController, parseHeight } from './block.controller'
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 { JsonRpcClient } from '@defichain/jellyfish-api-jsonrpc'
import { DBlockController, DefidBin } from '../e2e.defid.module'

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

beforeAll(async () => {
await container.start()
Expand All @@ -22,7 +22,7 @@ beforeAll(async () => {
} else {
controller = app.get(BlockController)
}
// client = new JsonRpcClient(await container.getCachedRpcUrl())
client = new JsonRpcClient(await container.getCachedRpcUrl())

const address = await container.getNewAddress()
for (let i = 0; i < 4; i += 1) {
Expand All @@ -45,122 +45,122 @@ describe('get', () => {
expect(block?.hash).toStrictEqual(blockHash)
})

// it('get should get block with height', async () => {
// const block = await controller.get('100')
// expect(block?.height).toStrictEqual(100)
// })
it('get should get block with height', async () => {
const block = await controller.get('100')
expect(block?.height).toStrictEqual(100)
})

// it('should get undefined with invalid hash ', async () => {
// const block = await controller.get('lajsdl;kfjljklj12lk34j')
// expect(block).toStrictEqual(undefined)
// })
it('should get undefined with invalid hash ', async () => {
const block = await controller.get('lajsdl;kfjljklj12lk34j')
expect(block).toStrictEqual(undefined)
})
})

// describe('list', () => {
// it('should return paginated list of blocks', async () => {
// const firstPage = await controller.list({ size: 40 })
describe('list', () => {
it('should return paginated list of blocks', async () => {
const firstPage = await controller.list({ size: 40 })

// expect(firstPage.data.length).toStrictEqual(40)
expect(firstPage.data.length).toStrictEqual(40)

// expect(firstPage.data[0].height).toBeGreaterThanOrEqual(100)
expect(firstPage.data[0].height).toBeGreaterThanOrEqual(100)

// const secondPage = await controller.list({ size: 40, next: firstPage.page?.next })
const secondPage = await controller.list({ size: 40, next: firstPage.page?.next })

// expect(secondPage.data.length).toStrictEqual(40)
// expect(secondPage.data[0].height).toStrictEqual(firstPage.data[39].height - 1)
expect(secondPage.data.length).toStrictEqual(40)
expect(secondPage.data[0].height).toStrictEqual(firstPage.data[39].height - 1)

// const lastPage = await controller.list({ size: 40, next: secondPage.page?.next })
const lastPage = await controller.list({ size: 40, next: secondPage.page?.next })

// expect(lastPage.data[0].height).toStrictEqual(secondPage.data[39].height - 1)
// expect(lastPage.page?.next).toBeUndefined()
// })
expect(lastPage.data[0].height).toStrictEqual(secondPage.data[39].height - 1)
expect(lastPage.page?.next).toBeUndefined()
})

// it('should return all the blocks if the size is out of range', async () => {
// const paginatedBlocks = await controller.list({ size: 100000, next: '100' })
it('should return all the blocks if the size is out of range', async () => {
const paginatedBlocks = await controller.list({ size: 100000, next: '100' })

// expect(paginatedBlocks.data.length).toStrictEqual(100)
// expect(paginatedBlocks.data[0].height).toBeGreaterThanOrEqual(99)
// })
expect(paginatedBlocks.data.length).toStrictEqual(100)
expect(paginatedBlocks.data[0].height).toBeGreaterThanOrEqual(99)
})

// it('list would return the latest set if next is outside of range', async () => {
// const paginatedBlocks = await controller.list({ size: 30, next: '100000' })
it('list would return the latest set if next is outside of range', async () => {
const paginatedBlocks = await controller.list({ size: 30, next: '100000' })

// expect(paginatedBlocks.data.length).toStrictEqual(30)
// expect(paginatedBlocks.data[0].height).toBeGreaterThanOrEqual(100)
// })
expect(paginatedBlocks.data.length).toStrictEqual(30)
expect(paginatedBlocks.data[0].height).toBeGreaterThanOrEqual(100)
})

// it('list would return the latest set if next is 0', async () => {
// const paginatedBlocks = await controller.list({ size: 30, next: '0' })
it('list would return the latest set if next is 0', async () => {
const paginatedBlocks = await controller.list({ size: 30, next: '0' })

// expect(paginatedBlocks.data.length).toStrictEqual(0)
// expect(paginatedBlocks?.page).toBeUndefined()
// })
// })
expect(paginatedBlocks.data.length).toStrictEqual(0)
expect(paginatedBlocks?.page).toBeUndefined()
})
})

// describe('getTransactions', () => {
// it('should get transactions from a block by hash', async () => {
// const blockHash = await container.call('getblockhash', [100])
// const paginatedTransactions = await controller.getTransactions(blockHash, { size: 30 })
describe('getTransactions', () => {
it('should get transactions from a block by hash', async () => {
const blockHash = await container.call('getblockhash', [100])
const paginatedTransactions = await controller.getTransactions(blockHash, { size: 30 })

// expect(paginatedTransactions.data.length).toBeGreaterThanOrEqual(1)
// expect(paginatedTransactions.data[0].block.height).toStrictEqual(100)
// })
expect(paginatedTransactions.data.length).toBeGreaterThanOrEqual(1)
expect(paginatedTransactions.data[0].block.height).toStrictEqual(100)
})

// it('getTransactions should not get transactions by height', async () => {
// const paginatedTransactions = await controller.getTransactions('0', { size: 30 })
it('getTransactions should not get transactions by height', async () => {
const paginatedTransactions = await controller.getTransactions('0', { size: 30 })

// expect(paginatedTransactions.data.length).toStrictEqual(0)
// })
expect(paginatedTransactions.data.length).toStrictEqual(0)
})

// it('getTransactions should get empty array when hash is not valid', async () => {
// const paginatedTransactions = await controller.getTransactions('z1wadfsvq90qlkfalnklvm', { size: 30 })
it('getTransactions should get empty array when hash is not valid', async () => {
const paginatedTransactions = await controller.getTransactions('z1wadfsvq90qlkfalnklvm', { size: 30 })

// expect(paginatedTransactions.data.length).toStrictEqual(0)
// })
expect(paginatedTransactions.data.length).toStrictEqual(0)
})

// it('getTransactions should get empty array when height is not valid', async () => {
// const paginatedTransactions = await controller.getTransactions('999999999999', { size: 30 })
it('getTransactions should get empty array when height is not valid', async () => {
const paginatedTransactions = await controller.getTransactions('999999999999', { size: 30 })

// expect(paginatedTransactions.data.length).toStrictEqual(0)
// })
expect(paginatedTransactions.data.length).toStrictEqual(0)
})

// it('should list transactions in the right order', async () => {
// const blockHash = await container.call('getblockhash', [103])
// const paginatedTransactions = await controller.getTransactions(blockHash, { size: 30 })
it('should list transactions in the right order', async () => {
const blockHash = await container.call('getblockhash', [103])
const paginatedTransactions = await controller.getTransactions(blockHash, { size: 30 })

// expect(paginatedTransactions.data.length).toBeGreaterThanOrEqual(4)
// expect(paginatedTransactions.data[0].block.height).toStrictEqual(103)
expect(paginatedTransactions.data.length).toBeGreaterThanOrEqual(4)
expect(paginatedTransactions.data[0].block.height).toStrictEqual(103)

// const rpcBlock = await client.blockchain.getBlock(blockHash, 2)
// expect(paginatedTransactions.data[0].hash).toStrictEqual(rpcBlock.tx[0].hash)
// expect(paginatedTransactions.data[1].hash).toStrictEqual(rpcBlock.tx[1].hash)
// expect(paginatedTransactions.data[2].hash).toStrictEqual(rpcBlock.tx[2].hash)
// expect(paginatedTransactions.data[3].hash).toStrictEqual(rpcBlock.tx[3].hash)
// })
// })
const rpcBlock = await client.blockchain.getBlock(blockHash, 2)
expect(paginatedTransactions.data[0].hash).toStrictEqual(rpcBlock.tx[0].hash)
expect(paginatedTransactions.data[1].hash).toStrictEqual(rpcBlock.tx[1].hash)
expect(paginatedTransactions.data[2].hash).toStrictEqual(rpcBlock.tx[2].hash)
expect(paginatedTransactions.data[3].hash).toStrictEqual(rpcBlock.tx[3].hash)
})
})

// describe('parseHeight', () => {
// it('should return undefined for negative integer', () => {
// expect(parseHeight('-123')).toStrictEqual(undefined)
// })
describe('parseHeight', () => {
it('should return undefined for negative integer', () => {
expect(parseHeight('-123')).toStrictEqual(undefined)
})

// it('should return undefined for float', () => {
// expect(parseHeight('123.32')).toStrictEqual(undefined)
// })
it('should return undefined for float', () => {
expect(parseHeight('123.32')).toStrictEqual(undefined)
})

// it('should return number for positive integers', () => {
// expect(parseHeight('123')).toStrictEqual(123)
// })
it('should return number for positive integers', () => {
expect(parseHeight('123')).toStrictEqual(123)
})

// it('should return undefined for empty string', () => {
// expect(parseHeight('')).toStrictEqual(undefined)
// })
it('should return undefined for empty string', () => {
expect(parseHeight('')).toStrictEqual(undefined)
})

// it('should return undefined for undefined', () => {
// expect(parseHeight(undefined)).toStrictEqual(undefined)
// })
it('should return undefined for undefined', () => {
expect(parseHeight(undefined)).toStrictEqual(undefined)
})

// it('should return undefined for strings with characters', () => {
// expect(parseHeight('123a')).toStrictEqual(undefined)
// })
// })
it('should return undefined for strings with characters', () => {
expect(parseHeight('123a')).toStrictEqual(undefined)
})
})

0 comments on commit 411fe85

Please sign in to comment.