/
utxos-chart-steps.js
130 lines (118 loc) · 4.24 KB
/
utxos-chart-steps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { Given, When, Then } from 'cucumber';
import { expect } from 'chai';
import { isValidSpendingPassword } from '../../../../source/renderer/app/utils/validations';
import {
formattedAmountToLovelace,
formattedLovelaceToAmount,
} from '../../../../source/renderer/app/utils/formatters';
import {
getUtxoChartData,
getUtxoWalletPrettyAmount,
getWalletUtxosTotalAmount,
} from '../../../../source/renderer/app/utils/utxoUtils';
import { getHistogramFromTable } from '../setup/utxo-helpers';
Given('the `getUtxoChartData` function receives the following props:', function(
data
) {
const histogram = getHistogramFromTable(data);
const utxoChartData = getUtxoChartData(histogram);
this.context.histogram = histogram;
this.context.utxoChartData = utxoChartData;
this.context.response = utxoChartData;
this.context.sortedHistogram = Object.entries(histogram).sort();
});
Then('the wallet amounts should be sorted sorted ascending', function() {
const { utxoChartData: arr } = this.context;
const isSorted = arr.every(({ walletAmount }, i) =>
i < arr.length - 1 ? walletAmount <= arr[i + 1].walletAmount : true
);
expect(isSorted).to.be.true;
});
Then(
'the wallet amounts should be formatted into human-readable text',
function() {
const { utxoChartData, sortedHistogram } = this.context;
const isFormatted = utxoChartData.every(
({ walletAmount }, index) =>
walletAmount === formattedLovelaceToAmount(sortedHistogram[index][0])
);
expect(isFormatted).to.be.true;
}
);
Then('there should be no wallet amounts greater than 100K', function() {
return this.context.utxoChartData.every(
({ walletRawAmount }) => walletRawAmount <= 100000
);
});
Then(
'the wallet UTXO amounts for wallet amounts greater than {int} should be aggregated',
function(walletAmount) {
const walletAmountThreshold = formattedAmountToLovelace(
String(walletAmount)
);
const { histogram, utxoChartData, sortedHistogram } = this.context;
const expectedAggregatedUtxosAmount = sortedHistogram.reduce(
(sum, [walletAmount, walletUtxosAmount]) => {
if (walletAmount >= walletAmountThreshold)
sum += parseInt(walletUtxosAmount, 10);
return sum;
},
0
);
const {
walletUtxosAmount: calculatedAggregatedUtxosAmount,
} = utxoChartData.find(({ walletRawAmount }) => walletRawAmount === 100000);
expect(expectedAggregatedUtxosAmount).to.equal(
calculatedAggregatedUtxosAmount
);
}
);
function getUtxoChartDataReceivesAWalletAmount(walletAmount) {
this.context.walletRawAmount = walletAmount;
const walletPrettyAmount = getUtxoWalletPrettyAmount(walletAmount);
this.context.walletAmount = walletPrettyAmount;
this.context.response = walletPrettyAmount;
}
Given(
'the `getUtxoWalletPrettyAmount` function receives the following {float}',
getUtxoChartDataReceivesAWalletAmount
);
Given(
'the `getUtxoWalletPrettyAmount` function receives the following {int}',
getUtxoChartDataReceivesAWalletAmount
);
Then('the response should have type {string}', function(type) {
const { response } = this.context;
if (type === 'array') {
return expect(Array.isArray(response)).to.be.true;
}
expect(typeof response).to.equal(type);
});
Then('wallet amounts less than {int} should not be modified', function(amount) {
const { walletAmount, walletRawAmount } = this.context;
if (walletRawAmount < amount) {
expect(walletAmount).to.equal(String(walletRawAmount));
expect(/[a-zA-Z]/.test(walletAmount)).to.be.false;
}
});
Then(
'wallet amounts equal or greater than {int} should be formatted into human-readable text',
function(amount) {
const { walletAmount, walletRawAmount } = this.context;
if (walletRawAmount >= amount) {
expect(walletAmount).to.not.equal(String(walletRawAmount));
expect(/[a-zA-Z]/.test(walletAmount)).to.be.true;
}
}
);
Given(
'the `getWalletUtxosTotalAmount` function receives the following props:',
function(data) {
const histogram = getHistogramFromTable(data);
this.context.histogram = histogram;
this.context.response = getWalletUtxosTotalAmount(histogram);
}
);
Then('the response should be the number {int}', function(response) {
expect(response).to.equal(this.context.response);
});