Skip to content

Commit

Permalink
Merge pull request #41 from blockpool-io/bpl_develop
Browse files Browse the repository at this point in the history
v3.6.2 release
  • Loading branch information
toucansam-bpl committed Sep 15, 2019
2 parents fe26120 + f05727c commit da175ed
Show file tree
Hide file tree
Showing 23 changed files with 12,781 additions and 145 deletions.
4 changes: 2 additions & 2 deletions README.md
@@ -1,6 +1,6 @@
# BPL Desktop Wallet
# Blockpool Desktop Wallet

![BPL Desktop Wallet](./banner.png)
![Blockpool Desktop Wallet](./banner.png)

[![Build Status](https://badgen.now.sh/circleci/github/blockpool-io/desktop-wallet)](https://circleci.com/gh/ArkEcosystem/desktop-wallet)
[![Latest Version](https://badgen.now.sh/github/release/blockpool-io/desktop-wallet)](https://github.com/ArkEcosystem/desktop-wallet/releases)
Expand Down
52 changes: 48 additions & 4 deletions __tests__/unit/components/Modal/ModalWindow.spec.js
Expand Up @@ -2,14 +2,14 @@ import { mount } from '@vue/test-utils'
import ModalWindow from '@/components/Modal'

const stubs = {
Portal: true
Portal: '<div><slot/></div>'
}

describe('ModalWindow', () => {
describe('render popup', () => {
it('should render the popup', () => {
const wrapper = mount(ModalWindow, { stubs })
expect(wrapper.contains('.modal-backdrop')).toBe(true)
expect(wrapper.contains('.ModalWindow')).toBe(true)
})

it('should render with content', () => {
Expand Down Expand Up @@ -66,14 +66,14 @@ describe('ModalWindow', () => {
describe('close popup', () => {
it('should emit a close event when clicks the close button', () => {
const wrapper = mount(ModalWindow, { stubs })
const mask = wrapper.find('button')
const mask = wrapper.find('.ModalWindow__close-button')
mask.trigger('click')
expect(wrapper.emitted('close')).toBeTruthy()
})

it('should emit a close event when clicks the mask', () => {
const wrapper = mount(ModalWindow, { stubs })
const mask = wrapper.find('.modal-backdrop')
const mask = wrapper.find('.ModalWindow')
mask.trigger('click')
expect(wrapper.emitted('close')).toBeTruthy()
})
Expand All @@ -85,4 +85,48 @@ describe('ModalWindow', () => {
expect(wrapper.emitted('close')).toBeFalsy()
})
})

describe('resize popup', () => {
it('should start maximized', () => {
const wrapper = mount(ModalWindow, { stubs })
expect(wrapper.contains('.ModalWindow--maximized')).toBe(true)
})

it('should not display the resize button by default', () => {
const wrapper = mount(ModalWindow, { stubs })
expect(wrapper.contains('.ModalWindow__resize-button')).toBe(false)
})

it('should display the resize button', () => {
const wrapper = mount(ModalWindow, { stubs, propsData: { canResize: true } })
expect(wrapper.contains('.ModalWindow__resize-button')).toBe(true)
})

it('should minimize modal when clicks the resize button', () => {
const wrapper = mount(ModalWindow, { stubs, propsData: { canResize: true } })
const button = wrapper.find('.ModalWindow__resize-button')
button.trigger('click')
expect(wrapper.contains('.ModalWindow--minimized')).toBe(true)
})

it('should not close when pressing on the backdrop while minimized', () => {
const wrapper = mount(ModalWindow, { stubs, propsData: { canResize: true } })
const button = wrapper.find('.ModalWindow__resize-button')
button.trigger('click')
expect(wrapper.contains('.ModalWindow--minimized')).toBe(true)

const modal = wrapper.find('.ModalWindow')
modal.trigger('click')
expect(wrapper.emitted('close')).toBeFalsy()
})

it('should maximize modal when clicks the resize button', () => {
const wrapper = mount(ModalWindow, { stubs, propsData: { canResize: true } })
const button = wrapper.find('.ModalWindow__resize-button')
button.trigger('click')
expect(wrapper.contains('.ModalWindow--minimized')).toBe(true)
button.trigger('click')
expect(wrapper.contains('.ModalWindow--maximized')).toBe(true)
})
})
})
143 changes: 90 additions & 53 deletions __tests__/unit/services/client.spec.js
@@ -1,7 +1,6 @@
import { cloneDeep } from 'lodash'
import nock from 'nock'
import errorCapturer from '../__utils__/error-capturer'
import { V1 } from '@config'
import fixtures from '../__fixtures__/services/client'
import ClientService from '@/services/client'
import BigNumber from '@/plugins/bignumber'
Expand Down Expand Up @@ -48,6 +47,41 @@ beforeEach(() => {
describe('Services > Client', () => {
let client

const wallets = [
{
address: 'address1',
balance: '1202',
publicKey: 'public key',
vote: 'voted delegate'
},
{
address: 'address2',
balance: '300',
publicKey: 'public key'
}
]

const generateWalletResponse = (address) => {
return {
body: {
data: {
...wallets.find(wallet => wallet.address === address),
isDelegate: true,
username: 'test'
}
}
}
}

const getWalletEndpoint = jest.fn(generateWalletResponse)

const fees = [
0.1 * 1e8,
5 * 1e8,
10 * 1e8,
1 * 1e8
]

beforeEach(() => {
client = new ClientService()
client.host = `http://127.0.0.1:4003`
Expand Down Expand Up @@ -108,26 +142,14 @@ describe('Services > Client', () => {
it('should return almost all properties from the wallet endpoint', async () => {
const wallet = await client.fetchWallet('address')
expect(wallet).toHaveProperty('address', data.address)
expect(wallet).toHaveProperty('balance', parseInt(data.balance))
expect(wallet).toHaveProperty('balance', data.balance)
expect(wallet).toHaveProperty('publicKey', data.publicKey)
expect(wallet).toHaveProperty('isDelegate', true)
})
})
})

describe('fetchWallets', () => {
const wallets = [
{
address: 'address1',
balance: '1202',
publicKey: 'public key'
},
{
address: 'address2',
balance: '300',
publicKey: 'public key'
}
]
const walletAddresses = ['address1', 'address2']
const walletsResponse = {
body: {
Expand All @@ -145,19 +167,6 @@ describe('Services > Client', () => {
]
}
}
const generateWalletResponse = (address) => {
return {
body: {
data: {
...wallets.find(wallet => wallet.address === address),
isDelegate: true,
username: 'test'
}
}
}
}

const getWalletEndpoint = jest.fn(generateWalletResponse)
const searchWalletEndpoint = jest.fn(() => walletsResponse)
beforeEach(() => {
const resource = resource => {
Expand Down Expand Up @@ -201,17 +210,45 @@ describe('Services > Client', () => {
expect(fetchedWallets).toEqual([
generateWalletResponse('address1').body.data,
generateWalletResponse('address2').body.data
].map(wallet => ({ ...wallet, balance: +wallet.balance })))
])
})
})
})

describe('fetchWalletVote', () => {
const publicKey = 'public key'
const voteDelegate = 'voted delegate'

beforeEach(() => {
const resource = resource => {
if (resource === 'wallets') {
return {
get: generateWalletResponse
}
}
}

client.client.api = resource
})

it('should return delegate public key if wallet is voting', async () => {
const response = await client.fetchWalletVote('address1')
expect(response).toBe(voteDelegate)
})

it('should return null if wallet is not voting', async () => {
const response = await client.fetchWalletVote('address2')
expect(response).toBeNull()
})
})

describe('fetchWalletVotes', () => {
const transactions = [{
asset: {
votes: ['+' + publicKey]
votes: ['+test']
}
}, {
asset: {
votes: ['+test2']
}
}]

Expand All @@ -227,9 +264,9 @@ describe('Services > Client', () => {
client.client.api = resource
})

it('should return delegate public key', async () => {
const response = await client.fetchWalletVote()
expect(response).toBe(publicKey)
it('should return vote transactions', async () => {
const response = await client.fetchWalletVotes()
expect(response).toBe(transactions)
})
})

Expand Down Expand Up @@ -483,65 +520,65 @@ describe('Services > Client', () => {
})

describe('buildDelegateRegistration', () => {
describe('when the fee is bigger than V1 fee', () => {
describe('when the fee is bigger than the static fee', () => {
it('should throw an Error', async () => {
const fee = V1.fees[2] + 0.1
const fee = new BigNumber(fees[2] + 1)
expect(await errorCapturer(client.buildDelegateRegistration({ fee }))).toThrow(/fee/)
})
})

describe('when the fee is smaller or equal to V1 fee (10)', () => {
describe('when the fee is smaller or equal to the static fee (10)', () => {
it('should not throw an Error', async () => {
expect(await errorCapturer(client.buildDelegateRegistration({ fee: 10 * 1e8 }))).not.toThrow(/fee/)
expect(await errorCapturer(client.buildDelegateRegistration({ fee: 8.09 * 1e8 }))).not.toThrow(/fee/)
expect(await errorCapturer(client.buildDelegateRegistration({ fee: new BigNumber(fees[2]) }))).not.toThrow(/fee/)
expect(await errorCapturer(client.buildDelegateRegistration({ fee: new BigNumber(fees[2] - 1) }))).not.toThrow(/fee/)
})
})
})

describe('buildSecondSignatureRegistration', () => {
describe('when the fee is bigger than V1 fee', () => {
describe('when the fee is bigger than the static fee', () => {
it('should throw an Error', async () => {
const fee = V1.fees[1] + 0.01
const fee = new BigNumber(fees[1] + 1)
expect(await errorCapturer(client.buildSecondSignatureRegistration({ fee }))).toThrow(/fee/)
})
})

describe('when the fee is smaller or equal to V1 fee (5)', () => {
describe('when the fee is smaller or equal to the static fee (5)', () => {
it('should not throw an Error', async () => {
expect(await errorCapturer(client.buildSecondSignatureRegistration({ fee: 5 * 1e8 }))).not.toThrow(/fee/)
expect(await errorCapturer(client.buildSecondSignatureRegistration({ fee: 3.09 * 1e8 }))).not.toThrow(/fee/)
expect(await errorCapturer(client.buildSecondSignatureRegistration({ fee: new BigNumber(fees[1]) }))).not.toThrow(/fee/)
expect(await errorCapturer(client.buildSecondSignatureRegistration({ fee: new BigNumber(fees[1] - 1) }))).not.toThrow(/fee/)
})
})
})

describe('buildTransfer', () => {
describe('when the fee is bigger than V1 fee', () => {
describe('when the fee is bigger than the static fee', () => {
it('should throw an Error', async () => {
const fee = V1.fees[0] + 0.00001
const fee = new BigNumber(fees[0] + 1)
expect(await errorCapturer(client.buildTransfer({ fee }))).toThrow(/fee/)
})
})

describe('when the fee is smaller or equal to V1 fee (0.1)', () => {
describe('when the fee is smaller or equal to the static fee (0.1)', () => {
it('should not throw an Error', async () => {
expect(await errorCapturer(client.buildTransfer({ fee: 0.1 * 1e8 }))).not.toThrow(/fee/)
expect(await errorCapturer(client.buildTransfer({ fee: 0.09 * 1e8 }))).not.toThrow(/fee/)
expect(await errorCapturer(client.buildTransfer({ fee: new BigNumber(fees[0]) }))).not.toThrow(/fee/)
expect(await errorCapturer(client.buildTransfer({ fee: new BigNumber(fees[0] - 1) }))).not.toThrow(/fee/)
})
})
})

describe('buildVote', () => {
describe('when the fee is bigger than V1 fee', () => {
describe('when the fee is bigger than the static fee', () => {
it('should throw an Error', async () => {
const fee = V1.fees[3] + 0.0000001
const fee = new BigNumber(fees[3] + 1)
expect(await errorCapturer(client.buildVote({ fee }))).toThrow(/fee/)
})
})

describe('when the fee is smaller or equal to V1 fee (0.1)', () => {
describe('when the fee is smaller or equal to the static fee fee (0.1)', () => {
it('should not throw an Error', async () => {
expect(await errorCapturer(client.buildVote({ fee: 1 * 1e8 }))).not.toThrow(/fee/)
expect(await errorCapturer(client.buildVote({ fee: 0.9 * 1e8 }))).not.toThrow(/fee/)
expect(await errorCapturer(client.buildVote({ fee: new BigNumber(fees[3]) }))).not.toThrow(/fee/)
expect(await errorCapturer(client.buildVote({ fee: new BigNumber(fees[3] - 1) }))).not.toThrow(/fee/)
})
})
})
Expand Down
32 changes: 31 additions & 1 deletion __tests__/unit/services/synchronizer/wallets.spec.js
Expand Up @@ -10,9 +10,11 @@ describe('Services > Synchronizer > Wallets', () => {
let transactions

let transactionDeleteBulk
let transactionProcessVotes

beforeEach(() => {
transactionDeleteBulk = jest.fn()
transactionProcessVotes = jest.fn()

const synchronizer = {
$client: {},
Expand All @@ -28,11 +30,14 @@ describe('Services > Synchronizer > Wallets', () => {
'ledger/wallets': [],
'session/backgroundUpdateLedger': true,
'wallet/byProfileId': jest.fn(),
'wallet/contactsByProfileId': jest.fn()
'wallet/contactsByProfileId': jest.fn(),
'session/unconfirmedVotes': []
},
dispatch: (action, data) => {
if (action === 'transaction/deleteBulk') {
return transactionDeleteBulk(action, data)
} else if (action === 'transaction/processVotes') {
return transactionProcessVotes(action, data)
} else if (action === 'transaction/clearExpired') {
return []
}
Expand Down Expand Up @@ -592,6 +597,31 @@ describe('Services > Synchronizer > Wallets', () => {
})
})

describe('processUnconfirmedVotes', () => {
let votes
beforeEach(() => {
votes = [{
address: 'test'
}, {
address: 'test'
}]

action.$client.fetchWalletVotes = jest.fn(() => votes)
action.$getters['session/unconfirmedVotes'] = [{
address: 'test'
}, {
address: 'test-2'
}]
})

it('should fetch votes for wallets with unconfirmed vote transactions', async () => {
await action.processUnconfirmedVotes()
expect(action.$client.fetchWalletVotes).toHaveBeenNthCalledWith(1, 'test')
expect(action.$client.fetchWalletVotes).toHaveBeenNthCalledWith(2, 'test-2')
expect(transactionProcessVotes).toHaveBeenCalledWith('transaction/processVotes', votes)
})
})

describe('when at least 1 of them is new', () => {
let latestTransaction

Expand Down

0 comments on commit da175ed

Please sign in to comment.