Skip to content

Commit

Permalink
fix: next address order
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Nov 14, 2019
1 parent 1f3409c commit fffd2f0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/neuron-wallet/src/database/address/address-dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default class AddressDao {
&& value.txCount === 0
})
return addresses.sort((lhs, rhs) => {
return lhs.addressIndex < rhs.addressIndex ? 1 : -1
return lhs.addressIndex - rhs.addressIndex
})[0]
}

Expand Down Expand Up @@ -126,7 +126,7 @@ export default class AddressDao {
&& value.txCount === 0
})
return addresses.sort((lhs, rhs) => {
return lhs.addressIndex < rhs.addressIndex ? 1 : -1
return lhs.addressIndex - rhs.addressIndex
})[0]
}

Expand Down
23 changes: 23 additions & 0 deletions packages/neuron-wallet/tests/database/address/dao.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ describe('Address Dao tests', () => {
version: AddressVersion.Testnet,
}

const address2: Address = {
walletId: '1',
address: 'ckt1qyqrdsefa43s6m882pcj53m4gdnj4k440axqswmu83',
path: "m/44'/309'/0'/0/1",
addressType: AddressType.Receiving,
addressIndex: 1,
txCount: 0,
liveBalance: '0',
sentBalance: '0',
pendingBalance: '0',
balance: '0',
blake160: '0x36c329ed630d6ce750712a477543672adab57f4c',
version: AddressVersion.Testnet,
}

const usedAddress: Address = {
walletId: '2',
address: 'ckt1qyqrdsefa43s6m882pcj53m4gdnj4k440axqswmu83',
Expand Down Expand Up @@ -142,4 +157,12 @@ describe('Address Dao tests', () => {
const counts = AddressDao.unusedAddressesCount(address.walletId, AddressVersion.Testnet)
expect(counts).toEqual([1, 1])
})

it('nextUnusedAddress', () => {
AddressDao.create([address, address2])

const next = AddressDao.nextUnusedAddress('1', AddressVersion.Testnet)

expect(next!.address).toEqual(address.address)
})
})

0 comments on commit fffd2f0

Please sign in to comment.