Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1320 from ArkEcosystem/develop
Browse files Browse the repository at this point in the history
chore: merge develop into master
  • Loading branch information
alexbarnsley committed Jul 12, 2019
2 parents c231579 + 8d64e18 commit cf930c7
Show file tree
Hide file tree
Showing 41 changed files with 762 additions and 499 deletions.
16 changes: 8 additions & 8 deletions __tests__/unit/__fixtures__/store/delegate.js
Expand Up @@ -2,35 +2,35 @@ const delegate1 = {
username: 'delegate1', username: 'delegate1',
address: 'AKdr5d9AMEnsKYxpDcoHdyyjSCKVx3r9Nj', address: 'AKdr5d9AMEnsKYxpDcoHdyyjSCKVx3r9Nj',
publicKey: '020431436cf94f3c6a6ba566fe9e42678db8486590c732ca6c3803a10a86f50b92', publicKey: '020431436cf94f3c6a6ba566fe9e42678db8486590c732ca6c3803a10a86f50b92',
voteWeight: 4202880284636, votes: '4202880284636',
blocks: { blocks: {
produced: 108940 produced: 108940
}, },
production: { production: {
approval: 0.03 approval: 0.03
}, },
forged: { forged: {
fees: 1173040419815, fees: '1173040419815',
rewards: 21788000000000, rewards: '21788000000000',
total: 22961040419815 total: '22961040419815'
}, },
rank: 59 rank: 59
} }
const delegate2 = { const delegate2 = {
username: 'delegate2', username: 'delegate2',
address: 'AU1TGCYoWzBnGMyMK9GTS8BG6EFbgc5xxC', address: 'AU1TGCYoWzBnGMyMK9GTS8BG6EFbgc5xxC',
publicKey: '02bf72c578a12c35a97ca1230b93017161ee42c3f0ab82f6fe7c95b3b43561a076', publicKey: '02bf72c578a12c35a97ca1230b93017161ee42c3f0ab82f6fe7c95b3b43561a076',
voteWeight: 2500294939144, votes: '2500294939144',
blocks: { blocks: {
produced: 2497 produced: 2497
}, },
production: { production: {
approval: 0.02 approval: 0.02
}, },
forged: { forged: {
fees: 3085620625, fees: '3085620625',
rewards: 499400000000, rewards: '499400000000',
total: 502485620625 total: '502485620625'
}, },
rank: 62 rank: 62
} }
Expand Down
17 changes: 10 additions & 7 deletions __tests__/unit/components/Input/InputCurrency.spec.js
Expand Up @@ -5,6 +5,7 @@ import { mount } from '@vue/test-utils'
import { useI18n } from '../../__utils__/i18n' import { useI18n } from '../../__utils__/i18n'
import { InputCurrency } from '@/components/Input' import { InputCurrency } from '@/components/Input'
import store from '@/store' import store from '@/store'
import BigNumber from '@/plugins/bignumber'


jest.mock('@/store', () => { jest.mock('@/store', () => {
return { return {
Expand Down Expand Up @@ -38,7 +39,9 @@ describe('InputCurrency', () => {
i18n, i18n,
propsData: { propsData: {
currency: mockNetwork.token, currency: mockNetwork.token,
value: '' value: '',
minimumAmount: new BigNumber(1e8),
maximumAmount: new BigNumber(1e8)
}, },
mocks: { mocks: {
currency_format: () => 'NET 9.9', currency_format: () => 'NET 9.9',
Expand Down Expand Up @@ -119,7 +122,7 @@ describe('InputCurrency', () => {
const wrapper = mountComponent() const wrapper = mountComponent()
wrapper.find('.InputCurrency input').setValue(99) wrapper.find('.InputCurrency input').setValue(99)


expect(wrapper.emitted('input')[0][0]).toEqual(99) expect(wrapper.emitted('input')[0][0]).toEqual('99')
}) })


it('should emit the `raw` event', () => { it('should emit the `raw` event', () => {
Expand All @@ -135,10 +138,10 @@ describe('InputCurrency', () => {
const wrapper = mountComponent() const wrapper = mountComponent()


wrapper.vm.emitInput('not') wrapper.vm.emitInput('not')
expect(wrapper.emitted('input')[0][0]).toEqual(0) expect(wrapper.emitted('input')[0][0]).toEqual('0')


wrapper.vm.emitInput(null) wrapper.vm.emitInput(null)
expect(wrapper.emitted('input')[1][0]).toEqual(0) expect(wrapper.emitted('input')[1][0]).toEqual('0')
}) })


it('should sanitize the values', () => { it('should sanitize the values', () => {
Expand All @@ -154,13 +157,13 @@ describe('InputCurrency', () => {
const wrapper = mountComponent() const wrapper = mountComponent()


wrapper.vm.emitInput('122,0122') wrapper.vm.emitInput('122,0122')
expect(wrapper.emitted('input')[0][0]).toEqual(122.0122) expect(wrapper.emitted('input')[0][0]).toEqual('122.0122')


wrapper.vm.emitInput('1,,23') wrapper.vm.emitInput('1,,23')
expect(wrapper.emitted('input')[1][0]).toEqual(1.23) expect(wrapper.emitted('input')[1][0]).toEqual('1.23')


wrapper.vm.emitInput('6,,97') wrapper.vm.emitInput('6,,97')
expect(wrapper.emitted('input')[2][0]).toEqual(6.97) expect(wrapper.emitted('input')[2][0]).toEqual('6.97')
}) })
}) })


Expand Down
55 changes: 31 additions & 24 deletions __tests__/unit/components/Input/InputFee.spec.js
Expand Up @@ -7,6 +7,7 @@ import CurrencyMixin from '@/mixins/currency'
import FormatterMixin from '@/mixins/formatter' import FormatterMixin from '@/mixins/formatter'
import { InputFee } from '@/components/Input' import { InputFee } from '@/components/Input'
import store from '@/store' import store from '@/store'
import BigNumber from '@/plugins/bignumber'


jest.mock('@/store', () => { jest.mock('@/store', () => {
return { return {
Expand Down Expand Up @@ -64,12 +65,14 @@ describe('InputFee', () => {
i18n, i18n,
propsData: { propsData: {
currency: mockNetwork.token, currency: mockNetwork.token,
transactionType: 0 transactionType: 0,
minimumAmount: new BigNumber(1e8),
maximumAmount: new BigNumber(1e8)
}, },
mixins: [CurrencyMixin, FormatterMixin], mixins: [CurrencyMixin, FormatterMixin],
mocks: { mocks: {
session_network: mockNetwork, session_network: mockNetwork,
wallet_fromRoute: { balance: 10 }, wallet_fromRoute: { balance: '10' },
$store: store, $store: store,
$synchronizer: { $synchronizer: {
focus: jest.fn(), focus: jest.fn(),
Expand Down Expand Up @@ -99,22 +102,21 @@ describe('InputFee', () => {
let wrapper = mountComponent({ let wrapper = mountComponent({
propsData: { transactionType: 0 } propsData: { transactionType: 0 }
}) })
expect(wrapper.vm.maxV1fee).toEqual(V1.fees[0] * 1e-8) expect(wrapper.vm.maxV1fee).toEqual(V1.fees[0])
expect(wrapper.vm.maxV1fee).toEqual(0.1)


wrapper = mountComponent({ wrapper = mountComponent({
propsData: { transactionType: 3 } propsData: { transactionType: 3 }
}) })
expect(wrapper.vm.maxV1fee).toEqual(V1.fees[3] * 1e-8) expect(wrapper.vm.maxV1fee).toEqual(V1.fees[3])
}) })
}) })


describe('rangePercentage', () => { describe('rangePercentage', () => {
const mockedComponent = (min, max) => { const mockedComponent = (min, max) => {
return mountComponent({ return mountComponent({
computed: { computed: {
feeChoiceMin: () => min, feeChoiceMin: () => new BigNumber(min),
feeChoiceMax: () => max feeChoiceMax: () => new BigNumber(max)
} }
}) })
} }
Expand Down Expand Up @@ -151,9 +153,9 @@ describe('InputFee', () => {
return mountComponent({ return mountComponent({
computed: { computed: {
feeChoices: () => ({ feeChoices: () => ({
MINIMUM: 1e-8, MINIMUM: new BigNumber(1e-8),
INPUT: 1e-8, INPUT: new BigNumber(1e-8),
ADVANCED: 1e-8, ADVANCED: new BigNumber(1e-8),
...fees ...fees
}) })
} }
Expand All @@ -162,31 +164,31 @@ describe('InputFee', () => {


it('should be `true` if the current fee matches, average and maximum fee are the same', () => { it('should be `true` if the current fee matches, average and maximum fee are the same', () => {
const wrapper = mockedComponent({ const wrapper = mockedComponent({
AVERAGE: 1, AVERAGE: new BigNumber(1),
MAXIMUM: 1 MAXIMUM: new BigNumber(1)
}) })
wrapper.vm.fee = 1 wrapper.vm.fee = 1
expect(wrapper.vm.isStaticFee).toBeTrue() expect(wrapper.vm.isStaticFee).toBeTrue()
}) })


it('should be `false` if the current fee matches, average and maximum fee are not the same', () => { it('should be `false` if the current fee matches, average and maximum fee are not the same', () => {
let wrapper = mockedComponent({ let wrapper = mockedComponent({
AVERAGE: 2, AVERAGE: new BigNumber(2),
MAXIMUM: 1 MAXIMUM: new BigNumber(1)
}) })
wrapper.vm.fee = 1 wrapper.vm.fee = 1
expect(wrapper.vm.isStaticFee).toBeFalse() expect(wrapper.vm.isStaticFee).toBeFalse()


wrapper = mockedComponent({ wrapper = mockedComponent({
AVERAGE: 1, AVERAGE: new BigNumber(1),
MAXIMUM: 2 MAXIMUM: new BigNumber(2)
}) })
wrapper.vm.fee = 1 wrapper.vm.fee = 1


expect(wrapper.vm.isStaticFee).toBeFalse() expect(wrapper.vm.isStaticFee).toBeFalse()
wrapper = mockedComponent({ wrapper = mockedComponent({
AVERAGE: 1, AVERAGE: new BigNumber(1),
MAXIMUM: 1 MAXIMUM: new BigNumber(1)
}) })
wrapper.vm.fee = 2 wrapper.vm.fee = 2
expect(wrapper.vm.isStaticFee).toBeFalse() expect(wrapper.vm.isStaticFee).toBeFalse()
Expand Down Expand Up @@ -224,7 +226,7 @@ describe('InputFee', () => {
const wrapper = mountComponent() const wrapper = mountComponent()


wrapper.vm.emitFee('97') wrapper.vm.emitFee('97')
expect(wrapper.emitted('input')[0][0]).toBeNumber() expect(wrapper.emitted('input')[0][0]).toBeString()
}) })
}) })


Expand All @@ -244,7 +246,8 @@ describe('InputFee', () => {
it('should use the V1 fee as average always', () => { it('should use the V1 fee as average always', () => {
const wrapper = mountComponent() const wrapper = mountComponent()


expect(wrapper.vm.feeChoices.AVERAGE).toEqual(0.1) expect(wrapper.vm.feeChoices.AVERAGE).toBeInstanceOf(BigNumber)
expect(wrapper.vm.feeChoices.AVERAGE.toString()).toEqual('0.1')
}) })
}) })


Expand All @@ -263,6 +266,7 @@ describe('InputFee', () => {
it('should use it as average', () => { it('should use it as average', () => {
const wrapper = mountComponent() const wrapper = mountComponent()


expect(wrapper.vm.feeChoices.AVERAGE).toBeInstanceOf(BigNumber)
expect(wrapper.vm.feeChoices.AVERAGE).toBeWithin(0.0048, 0.0048000001) expect(wrapper.vm.feeChoices.AVERAGE).toBeWithin(0.0048, 0.0048000001)
}) })
}) })
Expand All @@ -282,7 +286,8 @@ describe('InputFee', () => {
it('should use the V1 fee as maximum always', () => { it('should use the V1 fee as maximum always', () => {
const wrapper = mountComponent() const wrapper = mountComponent()


expect(wrapper.vm.feeChoices.MAXIMUM).toEqual(0.1) expect(wrapper.vm.feeChoices.MAXIMUM).toBeInstanceOf(BigNumber)
expect(wrapper.vm.feeChoices.MAXIMUM.toString()).toEqual('0.1')
}) })
}) })


Expand All @@ -301,6 +306,7 @@ describe('InputFee', () => {
it('should use it as maximum', () => { it('should use it as maximum', () => {
const wrapper = mountComponent() const wrapper = mountComponent()


expect(wrapper.vm.feeChoices.MAXIMUM).toBeInstanceOf(BigNumber)
expect(wrapper.vm.feeChoices.MAXIMUM).toBeWithin(0.03, 0.03000001) expect(wrapper.vm.feeChoices.MAXIMUM).toBeWithin(0.03, 0.03000001)
}) })
}) })
Expand All @@ -313,7 +319,8 @@ describe('InputFee', () => {
it('should use it as maximum', () => { it('should use it as maximum', () => {
const wrapper = mountComponent() const wrapper = mountComponent()


expect(wrapper.vm.feeChoices.MAXIMUM).toBe(0.1) expect(wrapper.vm.feeChoices.MAXIMUM).toBeInstanceOf(BigNumber)
expect(wrapper.vm.feeChoices.MAXIMUM.toString()).toBe('0.1')
}) })
}) })
}) })
Expand All @@ -328,7 +335,7 @@ describe('InputFee', () => {


describe('when the balance is smaller than the fee', () => { describe('when the balance is smaller than the fee', () => {
it('should return the message about funds', () => { it('should return the message about funds', () => {
wrapper.vm.wallet_fromRoute.balance = 50000 wrapper.vm.wallet_fromRoute.balance = '50000'
wrapper.vm.fee = 20e8 wrapper.vm.fee = 20e8
expect(wrapper.vm.insufficientFundsError).toEqual('TRANSACTION_FORM.ERROR.NOT_ENOUGH_BALANCE') expect(wrapper.vm.insufficientFundsError).toEqual('TRANSACTION_FORM.ERROR.NOT_ENOUGH_BALANCE')


Expand All @@ -341,7 +348,7 @@ describe('InputFee', () => {
describe('when the balance is bigger than the fee', () => { describe('when the balance is bigger than the fee', () => {
it('should return an empty message', () => { it('should return an empty message', () => {
// NOTE: Balance is in arktoshi, while fee is in ARK // NOTE: Balance is in arktoshi, while fee is in ARK
wrapper.vm.wallet_fromRoute.balance = 20e8 wrapper.vm.wallet_fromRoute.balance = '20e8'
wrapper.vm.fee = 1 wrapper.vm.fee = 1
expect(wrapper.vm.insufficientFundsError).toBeNull() expect(wrapper.vm.insufficientFundsError).toBeNull()


Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/components/Menu/MenuNavigation.spec.js
Expand Up @@ -32,7 +32,7 @@ describe('MenuNavigation', () => {
const slot = 'My MenuNavigationItem component' const slot = 'My MenuNavigationItem component'
const wrapper = mount(MenuNavigationItem, { const wrapper = mount(MenuNavigationItem, {
provide: { provide: {
switchToId: jest.fn() switchToItem: jest.fn()
}, },
slots: { slots: {
default: slot default: slot
Expand Down
15 changes: 11 additions & 4 deletions __tests__/unit/mixins/currency.spec.js
@@ -1,6 +1,7 @@
import { createLocalVue, shallowMount } from '@vue/test-utils' import { createLocalVue, shallowMount } from '@vue/test-utils'
import useI18n from '../__utils__/i18n' import useI18n from '../__utils__/i18n'
import CurrencyMixin from '@/mixins/currency' import CurrencyMixin from '@/mixins/currency'
import BigNumber from '@/plugins/bignumber'


describe('Mixins > Currency', () => { describe('Mixins > Currency', () => {
const network = { const network = {
Expand Down Expand Up @@ -182,10 +183,13 @@ describe('Mixins > Currency', () => {
describe('when not receiving a network', () => { describe('when not receiving a network', () => {
it('should use the session network to convert an amount from arktoshi to ARK', () => { it('should use the session network to convert an amount from arktoshi to ARK', () => {
let amount = Math.pow(10, 9) let amount = Math.pow(10, 9)
expect(subToUnit(amount)).toEqual('10') let unit = subToUnit(amount)
expect(unit).toBeInstanceOf(BigNumber)
expect(unit.toString()).toEqual('10')


amount = Math.pow(10, 12) + 9800 + 1 amount = Math.pow(10, 12) + 9800 + 1
expect(subToUnit(amount)).toEqual('10000.00009801') unit = subToUnit(amount)
expect(unit.toString()).toEqual('10000.00009801')
}) })
}) })


Expand All @@ -194,10 +198,13 @@ describe('Mixins > Currency', () => {
const network = { fractionDigits: 3 } const network = { fractionDigits: 3 }


let amount = Math.pow(10, 3) let amount = Math.pow(10, 3)
expect(subToUnit(amount, network)).toEqual('1') let unit = subToUnit(amount, network)
expect(unit).toBeInstanceOf(BigNumber)
expect(unit.toString()).toEqual('1')


amount = Math.pow(10, 9) + 9800 + 1 amount = Math.pow(10, 9) + 9800 + 1
expect(subToUnit(amount, network)).toEqual('1000009.801') unit = subToUnit(amount, network)
expect(unit.toString()).toEqual('1000009.801')
}) })
}) })
}) })
Expand Down
33 changes: 13 additions & 20 deletions __tests__/unit/pages/Profile/ProfileAll.spec.js
Expand Up @@ -4,6 +4,7 @@ import { useI18n } from '../../__utils__/i18n'
import router from '@/router' import router from '@/router'
import CurrencyMixin from '@/mixins/currency' import CurrencyMixin from '@/mixins/currency'
import ProfileAll from '@/pages/Profile/ProfileAll' import ProfileAll from '@/pages/Profile/ProfileAll'
import BigNumber from '@/plugins/bignumber.js'


const localVue = createLocalVue() const localVue = createLocalVue()
const i18n = useI18n(localVue) const i18n = useI18n(localVue)
Expand Down Expand Up @@ -88,11 +89,9 @@ describe('pages > ProfileAll', () => {
describe('aggregatedBalances', () => { describe('aggregatedBalances', () => {
it('should aggregate the sum of the balances of all profiles by network', () => { it('should aggregate the sum of the balances of all profiles by network', () => {
wrapper = mountPage() wrapper = mountPage()
expect(wrapper.vm.aggregatedBalances).toEqual({ expect(wrapper.vm.aggregatedBalances).toHaveProperty('main', new BigNumber(50015090900))
main: 50015090900, expect(wrapper.vm.aggregatedBalances).toHaveProperty('other', new BigNumber(12190000))
other: 12190000, expect(wrapper.vm.aggregatedBalances).toHaveProperty('dev', new BigNumber(52010000))
dev: 52010000
})
}) })


describe('when there are profiles with the same wallets', () => { describe('when there are profiles with the same wallets', () => {
Expand All @@ -102,11 +101,9 @@ describe('pages > ProfileAll', () => {


it('should include those wallets only 1 time', () => { it('should include those wallets only 1 time', () => {
wrapper = mountPage() wrapper = mountPage()
expect(wrapper.vm.aggregatedBalances).toEqual({ expect(wrapper.vm.aggregatedBalances).toHaveProperty('main', new BigNumber(15090900))
main: 15090900, expect(wrapper.vm.aggregatedBalances).toHaveProperty('other', new BigNumber(12190000))
other: 12190000, expect(wrapper.vm.aggregatedBalances).toHaveProperty('dev', new BigNumber(52010000))
dev: 52010000
})
}) })
}) })


Expand All @@ -120,11 +117,9 @@ describe('pages > ProfileAll', () => {


it('should include their balances', () => { it('should include their balances', () => {
wrapper = mountPage() wrapper = mountPage()
expect(wrapper.vm.aggregatedBalances).toEqual({ expect(wrapper.vm.aggregatedBalances).toHaveProperty('main', new BigNumber(66622093608))
main: 66622093608, expect(wrapper.vm.aggregatedBalances).toHaveProperty('other', new BigNumber(12190000))
other: 12190000, expect(wrapper.vm.aggregatedBalances).toHaveProperty('dev', new BigNumber(52010000))
dev: 52010000
})
}) })


describe('when they are included as non-Ledger wallets', () => { describe('when they are included as non-Ledger wallets', () => {
Expand All @@ -134,11 +129,9 @@ describe('pages > ProfileAll', () => {


it('should include those wallets only 1 time', () => { it('should include those wallets only 1 time', () => {
wrapper = mountPage() wrapper = mountPage()
expect(wrapper.vm.aggregatedBalances).toEqual({ expect(wrapper.vm.aggregatedBalances).toHaveProperty('main', new BigNumber(59898192907))
main: 59898192907, expect(wrapper.vm.aggregatedBalances).toHaveProperty('other', new BigNumber(12190000))
other: 12190000, expect(wrapper.vm.aggregatedBalances).toHaveProperty('dev', new BigNumber(52010000))
dev: 52010000
})
}) })
}) })
}) })
Expand Down

0 comments on commit cf930c7

Please sign in to comment.