Skip to content

Commit

Permalink
fix: getDaoCells and its tests
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Nov 7, 2019
1 parent 41953bf commit 2460b0b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
13 changes: 5 additions & 8 deletions packages/neuron-wallet/src/services/cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,22 @@ export default class CellsService {
): Promise<PaginationResult<Cell>> => {
const skip = (page - 1) * perPage

const query = getConnection()
const outputsAndCount: [OutputEntity[], number] = await getConnection()
.getRepository(OutputEntity)
.createQueryBuilder('output')
.leftJoinAndSelect('output.transaction', 'tx')
.where(`output.daoData IS NOT NULL AND output.lockHash in (:...lockHashes)`, {
lockHashes,
})

const totalCount: number = await query.getCount()
const outputs: OutputEntity[] = await query
.orderBy(`CASE output.daoData WHEN '0x0000000000000000' THEN 1 ELSE 0 END`, 'ASC')
.addOrderBy('tx.timestamp', 'ASC')
.skip(skip)
.take(perPage)
.getMany()
.limit(perPage)
.getManyAndCount()

return {
totalCount,
items: outputs.map(o => o.toInterface()),
totalCount: outputsAndCount[1],
items: outputsAndCount[0].map(o => o.toInterface()),
}
}

Expand Down
9 changes: 6 additions & 3 deletions packages/neuron-wallet/tests/services/cells.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,18 @@ describe('CellsService', () => {
})

it('get all in correct order', async () => {
const cells = await CellsService.getDaoCells()
console.warn(cells.map(c => c.capacity))
const cells = await CellsService.getDaoCells(
[bob.lockHash],
1,
10
)
const expectedCapacitySort = [
'2000',
'4000',
'1000',
'3000',
].map(capacity => toShannon(capacity))
expect(cells.map(c => c.capacity)).toEqual(expectedCapacitySort)
expect(cells.items.map(c => c.capacity)).toEqual(expectedCapacitySort)
})
})
})
Expand Down

0 comments on commit 2460b0b

Please sign in to comment.