mainnet-js 1.1.27 → 1.1.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.html +1 -1
- package/dist/{mainnet-1.1.27.js → mainnet-1.1.29.js} +9 -9
- package/dist/module/rate/ExchangeRate.js +1 -1
- package/dist/module/rate/ExchangeRate.js.map +1 -1
- package/dist/module/wallet/Bcmr.js +1 -1
- package/dist/module/wallet/Bcmr.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/network/Rpc.test.ts +91 -89
- package/src/rate/ExchangeRate.test.ts +58 -45
- package/src/rate/ExchangeRate.ts +1 -1
- package/src/transaction/allocateFee.test.ts +272 -262
- package/src/wallet/Bcmr.ts +1 -1
- package/src/wallet/Util.test.ts +71 -61
|
@@ -1,309 +1,319 @@
|
|
|
1
1
|
import { allocateFee, sortSendRequests } from "./allocateFee";
|
|
2
2
|
import { FeePaidByEnum } from "../wallet/enum";
|
|
3
3
|
import { asSendRequestObject } from "../util/asSendRequestObject";
|
|
4
|
-
import { SendRequest } from "..";
|
|
4
|
+
import { SendRequest, disconnectProviders, initProviders } from "..";
|
|
5
5
|
import { RegTestWallet } from "../wallet/Wif";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (!process.env.ADDRESS) {
|
|
10
|
-
throw Error("Attempted to pass an empty address");
|
|
11
|
-
} else {
|
|
12
|
-
const funder = await RegTestWallet.fromId(
|
|
13
|
-
`wif:regtest:${process.env.PRIVATE_WIF!}`
|
|
14
|
-
);
|
|
15
|
-
const alice = await RegTestWallet.newRandom();
|
|
16
|
-
const bob = await RegTestWallet.newRandom();
|
|
17
|
-
const charlie = await RegTestWallet.newRandom();
|
|
18
|
-
const dave = await RegTestWallet.newRandom();
|
|
19
|
-
const edward = await RegTestWallet.newRandom();
|
|
20
|
-
await funder.send([
|
|
21
|
-
{
|
|
22
|
-
cashaddr: alice.cashaddr!,
|
|
23
|
-
value: 4500,
|
|
24
|
-
unit: "satoshis",
|
|
25
|
-
},
|
|
26
|
-
]);
|
|
27
|
-
await alice.send(
|
|
28
|
-
[
|
|
29
|
-
{
|
|
30
|
-
cashaddr: bob.cashaddr!,
|
|
31
|
-
unit: "sat",
|
|
32
|
-
value: 549,
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
cashaddr: charlie.cashaddr!,
|
|
36
|
-
unit: "sat",
|
|
37
|
-
value: 550,
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
cashaddr: dave.cashaddr!,
|
|
41
|
-
unit: "sat",
|
|
42
|
-
value: 551,
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
cashaddr: edward.cashaddr!,
|
|
46
|
-
unit: "sat",
|
|
47
|
-
value: 2552,
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
{ feePaidBy: FeePaidByEnum.changeThenAny }
|
|
51
|
-
);
|
|
52
|
-
expect(await alice.getBalance("sat")).toBe(0);
|
|
53
|
-
expect(await bob.getBalance("sat")).toBe(0);
|
|
54
|
-
expect(await charlie.getBalance("sat")).toBe(550);
|
|
55
|
-
expect(await dave.getBalance("sat")).toBe(551);
|
|
56
|
-
expect(await edward.getBalance("sat")).toBe(2552);
|
|
57
|
-
}
|
|
7
|
+
beforeAll(async () => {
|
|
8
|
+
await initProviders();
|
|
58
9
|
});
|
|
59
10
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
["alice", 2000, "sat"],
|
|
63
|
-
["bob", 2000, "sat"],
|
|
64
|
-
];
|
|
65
|
-
let fee = 1;
|
|
66
|
-
let requests = asSendRequestObject(to) as SendRequest[];
|
|
67
|
-
let allocatedInputs = await allocateFee(
|
|
68
|
-
requests,
|
|
69
|
-
fee,
|
|
70
|
-
FeePaidByEnum.first,
|
|
71
|
-
BigInt(0)
|
|
72
|
-
);
|
|
73
|
-
expect(allocatedInputs[0].value).toBeLessThan(2000);
|
|
74
|
-
expect(allocatedInputs[1].value).toBe(2000);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test("Expect last to subtract fee from last", async () => {
|
|
78
|
-
let to = [
|
|
79
|
-
["alice", 2000, "sat"],
|
|
80
|
-
["bob", 2000, "sat"],
|
|
81
|
-
];
|
|
82
|
-
let fee = 1;
|
|
83
|
-
let requests = asSendRequestObject(to) as SendRequest[];
|
|
84
|
-
let allocatedInputs = allocateFee(
|
|
85
|
-
requests,
|
|
86
|
-
fee,
|
|
87
|
-
FeePaidByEnum.last,
|
|
88
|
-
BigInt(0)
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
expect(allocatedInputs[0].value).toBe(2000);
|
|
92
|
-
expect(allocatedInputs[1].value).toBeLessThan(2000);
|
|
11
|
+
afterAll(async () => {
|
|
12
|
+
await disconnectProviders();
|
|
93
13
|
});
|
|
94
14
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
15
|
+
describe("Fee tests", () => {
|
|
16
|
+
test("Should get the regtest wallet balance", async () => {
|
|
17
|
+
// Build Alice's wallet from Wallet Import Format string, send some sats
|
|
18
|
+
if (!process.env.ADDRESS) {
|
|
19
|
+
throw Error("Attempted to pass an empty address");
|
|
20
|
+
} else {
|
|
21
|
+
const funder = await RegTestWallet.fromId(
|
|
22
|
+
`wif:regtest:${process.env.PRIVATE_WIF!}`
|
|
23
|
+
);
|
|
24
|
+
const alice = await RegTestWallet.newRandom();
|
|
25
|
+
const bob = await RegTestWallet.newRandom();
|
|
26
|
+
const charlie = await RegTestWallet.newRandom();
|
|
27
|
+
const dave = await RegTestWallet.newRandom();
|
|
28
|
+
const edward = await RegTestWallet.newRandom();
|
|
29
|
+
await funder.send([
|
|
30
|
+
{
|
|
31
|
+
cashaddr: alice.cashaddr!,
|
|
32
|
+
value: 4500,
|
|
33
|
+
unit: "satoshis",
|
|
34
|
+
},
|
|
35
|
+
]);
|
|
36
|
+
await alice.send(
|
|
37
|
+
[
|
|
38
|
+
{
|
|
39
|
+
cashaddr: bob.cashaddr!,
|
|
40
|
+
unit: "sat",
|
|
41
|
+
value: 549,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
cashaddr: charlie.cashaddr!,
|
|
45
|
+
unit: "sat",
|
|
46
|
+
value: 550,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
cashaddr: dave.cashaddr!,
|
|
50
|
+
unit: "sat",
|
|
51
|
+
value: 551,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
cashaddr: edward.cashaddr!,
|
|
55
|
+
unit: "sat",
|
|
56
|
+
value: 2552,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
{ feePaidBy: FeePaidByEnum.changeThenAny }
|
|
60
|
+
);
|
|
61
|
+
expect(await alice.getBalance("sat")).toBe(0);
|
|
62
|
+
expect(await bob.getBalance("sat")).toBe(0);
|
|
63
|
+
expect(await charlie.getBalance("sat")).toBe(550);
|
|
64
|
+
expect(await dave.getBalance("sat")).toBe(551);
|
|
65
|
+
expect(await edward.getBalance("sat")).toBe(2552);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
115
68
|
|
|
116
|
-
test("Expect
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
69
|
+
test("Expect first in to subtract fee from first", async () => {
|
|
70
|
+
let to = [
|
|
71
|
+
["alice", 2000, "sat"],
|
|
72
|
+
["bob", 2000, "sat"],
|
|
73
|
+
];
|
|
74
|
+
let fee = 1;
|
|
75
|
+
let requests = asSendRequestObject(to) as SendRequest[];
|
|
76
|
+
let allocatedInputs = await allocateFee(
|
|
77
|
+
requests,
|
|
78
|
+
fee,
|
|
79
|
+
FeePaidByEnum.first,
|
|
80
|
+
BigInt(0)
|
|
81
|
+
);
|
|
82
|
+
expect(allocatedInputs[0].value).toBeLessThan(2000);
|
|
83
|
+
expect(allocatedInputs[1].value).toBe(2000);
|
|
84
|
+
});
|
|
124
85
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
86
|
+
test("Expect last to subtract fee from last", async () => {
|
|
87
|
+
let to = [
|
|
88
|
+
["alice", 2000, "sat"],
|
|
89
|
+
["bob", 2000, "sat"],
|
|
90
|
+
];
|
|
91
|
+
let fee = 1;
|
|
92
|
+
let requests = asSendRequestObject(to) as SendRequest[];
|
|
93
|
+
let allocatedInputs = allocateFee(
|
|
94
|
+
requests,
|
|
95
|
+
fee,
|
|
96
|
+
FeePaidByEnum.last,
|
|
97
|
+
BigInt(0)
|
|
98
|
+
);
|
|
131
99
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
});
|
|
100
|
+
expect(allocatedInputs[0].value).toBe(2000);
|
|
101
|
+
expect(allocatedInputs[1].value).toBeLessThan(2000);
|
|
102
|
+
});
|
|
136
103
|
|
|
137
|
-
test("Expect all to allocate fees equally
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
104
|
+
test("Expect all to allocate fees equally", async () => {
|
|
105
|
+
let to = [
|
|
106
|
+
["alice", 2000, "sat"],
|
|
107
|
+
["bob", 2000, "sat"],
|
|
108
|
+
["charlie", 2000, "sat"],
|
|
109
|
+
];
|
|
110
|
+
let fee = 3;
|
|
111
|
+
let requests = asSendRequestObject(to) as SendRequest[];
|
|
145
112
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
113
|
+
let allocatedInputs = allocateFee(
|
|
114
|
+
requests,
|
|
115
|
+
fee,
|
|
116
|
+
FeePaidByEnum.any,
|
|
117
|
+
BigInt(0)
|
|
118
|
+
);
|
|
152
119
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
});
|
|
120
|
+
expect(allocatedInputs[0].value).toBe(1999);
|
|
121
|
+
expect(allocatedInputs[1].value).toBe(1999);
|
|
122
|
+
expect(allocatedInputs[2].value).toBe(1999);
|
|
123
|
+
});
|
|
157
124
|
|
|
158
|
-
test("Expect
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
125
|
+
test("Expect all to allocate fees equally, taking dust result", async () => {
|
|
126
|
+
let to = [
|
|
127
|
+
["alice", 2000, "sat"],
|
|
128
|
+
["bob", 547, "sat"],
|
|
129
|
+
["charlie", 2000, "sat"],
|
|
130
|
+
];
|
|
131
|
+
let fee = 300;
|
|
132
|
+
let requests = asSendRequestObject(to) as SendRequest[];
|
|
166
133
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
134
|
+
let allocatedInputs = allocateFee(
|
|
135
|
+
requests,
|
|
136
|
+
fee,
|
|
137
|
+
FeePaidByEnum.any,
|
|
138
|
+
BigInt(0)
|
|
139
|
+
);
|
|
173
140
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
});
|
|
141
|
+
expect(allocatedInputs[0].value).toBe(2000);
|
|
142
|
+
expect(allocatedInputs[1].value).toBe(2000);
|
|
143
|
+
expect(allocatedInputs.length).toBe(2);
|
|
144
|
+
});
|
|
178
145
|
|
|
179
|
-
test("Expect
|
|
180
|
-
expect.assertions(1);
|
|
181
|
-
try {
|
|
146
|
+
test("Expect all to allocate fees equally, taking dust result output, dividing remainder", async () => {
|
|
182
147
|
let to = [
|
|
183
148
|
["alice", 2000, "sat"],
|
|
184
|
-
["bob",
|
|
149
|
+
["bob", 547, "sat"],
|
|
185
150
|
["charlie", 2000, "sat"],
|
|
186
151
|
];
|
|
187
|
-
let fee =
|
|
152
|
+
let fee = 647;
|
|
188
153
|
let requests = asSendRequestObject(to) as SendRequest[];
|
|
154
|
+
|
|
189
155
|
let allocatedInputs = allocateFee(
|
|
190
156
|
requests,
|
|
191
157
|
fee,
|
|
192
|
-
FeePaidByEnum.
|
|
193
|
-
BigInt(
|
|
158
|
+
FeePaidByEnum.any,
|
|
159
|
+
BigInt(0)
|
|
194
160
|
);
|
|
195
|
-
} catch (e: any) {
|
|
196
|
-
expect(e.message).toBe("Insufficient funds for transaction given fee");
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
161
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
162
|
+
expect(allocatedInputs[0].value).toBe(1950);
|
|
163
|
+
expect(allocatedInputs[1].value).toBe(1950);
|
|
164
|
+
expect(allocatedInputs.length).toBe(2);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("Expect an odd fee to be applied to have remainder applied to first receipt", async () => {
|
|
203
168
|
let to = [
|
|
204
169
|
["alice", 2000, "sat"],
|
|
205
170
|
["bob", 2000, "sat"],
|
|
206
171
|
["charlie", 2000, "sat"],
|
|
207
172
|
];
|
|
208
|
-
let fee =
|
|
173
|
+
let fee = 301;
|
|
209
174
|
let requests = asSendRequestObject(to) as SendRequest[];
|
|
175
|
+
|
|
210
176
|
let allocatedInputs = allocateFee(
|
|
211
177
|
requests,
|
|
212
178
|
fee,
|
|
213
|
-
FeePaidByEnum.
|
|
179
|
+
FeePaidByEnum.any,
|
|
214
180
|
BigInt(0)
|
|
215
181
|
);
|
|
216
|
-
} catch (e: any) {
|
|
217
|
-
expect(e.message).toBe("Fee strategy would result in dust output");
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
182
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
[
|
|
224
|
-
|
|
225
|
-
["charlie", 1000, "sat"],
|
|
226
|
-
];
|
|
227
|
-
let fee = 1362;
|
|
228
|
-
let requests = asSendRequestObject(to) as SendRequest[];
|
|
229
|
-
let result = allocateFee(requests, fee, FeePaidByEnum.any, BigInt(0));
|
|
230
|
-
expect(result[0].value).toBe(546);
|
|
231
|
-
expect(result[1].value).toBe(546);
|
|
232
|
-
expect(result[2].value).toBe(546);
|
|
233
|
-
});
|
|
183
|
+
expect(allocatedInputs[0].value).toBe(1899);
|
|
184
|
+
expect(allocatedInputs[1].value).toBe(1900);
|
|
185
|
+
expect(allocatedInputs[2].value).toBe(1900);
|
|
186
|
+
});
|
|
234
187
|
|
|
235
|
-
test("Expect
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
188
|
+
test("Expect insufficient funds to error", async () => {
|
|
189
|
+
expect.assertions(1);
|
|
190
|
+
try {
|
|
191
|
+
let to = [
|
|
192
|
+
["alice", 2000, "sat"],
|
|
193
|
+
["bob", 2000, "sat"],
|
|
194
|
+
["charlie", 2000, "sat"],
|
|
195
|
+
];
|
|
196
|
+
let fee = 7000;
|
|
197
|
+
let requests = asSendRequestObject(to) as SendRequest[];
|
|
198
|
+
let allocatedInputs = allocateFee(
|
|
199
|
+
requests,
|
|
200
|
+
fee,
|
|
201
|
+
FeePaidByEnum.changeThenAny,
|
|
202
|
+
BigInt(999)
|
|
203
|
+
);
|
|
204
|
+
} catch (e: any) {
|
|
205
|
+
expect(e.message).toBe("Insufficient funds for transaction given fee");
|
|
206
|
+
}
|
|
207
|
+
});
|
|
248
208
|
|
|
249
|
-
test("Expect
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
209
|
+
test("Expect dust amounts to error", async () => {
|
|
210
|
+
expect.assertions(1);
|
|
211
|
+
try {
|
|
212
|
+
let to = [
|
|
213
|
+
["alice", 2000, "sat"],
|
|
214
|
+
["bob", 2000, "sat"],
|
|
215
|
+
["charlie", 2000, "sat"],
|
|
216
|
+
];
|
|
217
|
+
let fee = 1500;
|
|
218
|
+
let requests = asSendRequestObject(to) as SendRequest[];
|
|
219
|
+
let allocatedInputs = allocateFee(
|
|
220
|
+
requests,
|
|
221
|
+
fee,
|
|
222
|
+
FeePaidByEnum.first,
|
|
223
|
+
BigInt(0)
|
|
224
|
+
);
|
|
225
|
+
} catch (e: any) {
|
|
226
|
+
expect(e.message).toBe("Fee strategy would result in dust output");
|
|
227
|
+
}
|
|
228
|
+
});
|
|
267
229
|
|
|
268
|
-
test("Expect
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
230
|
+
test("Expect near-dust amounts not to error", async () => {
|
|
231
|
+
let to = [
|
|
232
|
+
["alice", 1000, "sat"],
|
|
233
|
+
["bob", 1000, "sat"],
|
|
234
|
+
["charlie", 1000, "sat"],
|
|
235
|
+
];
|
|
236
|
+
let fee = 1362;
|
|
237
|
+
let requests = asSendRequestObject(to) as SendRequest[];
|
|
238
|
+
let result = allocateFee(requests, fee, FeePaidByEnum.any, BigInt(0));
|
|
239
|
+
expect(result[0].value).toBe(546);
|
|
240
|
+
expect(result[1].value).toBe(546);
|
|
241
|
+
expect(result[2].value).toBe(546);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test("Expect `any` to not consume change", async () => {
|
|
245
|
+
let to = [
|
|
246
|
+
["alice", 1000, "sat"],
|
|
247
|
+
["bob", 1000, "sat"],
|
|
248
|
+
["charlie", 1000, "sat"],
|
|
249
|
+
];
|
|
250
|
+
let fee = 1362;
|
|
251
|
+
let requests = asSendRequestObject(to) as SendRequest[];
|
|
252
|
+
let result = allocateFee(requests, fee, FeePaidByEnum.any, BigInt(1362));
|
|
253
|
+
expect(result[0].value).toBe(546);
|
|
254
|
+
expect(result[1].value).toBe(546);
|
|
255
|
+
expect(result[2].value).toBe(546);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test("Expect `change,any` to consume only change", async () => {
|
|
259
|
+
let to = [
|
|
260
|
+
["alice", 1000, "sat"],
|
|
261
|
+
["bob", 1000, "sat"],
|
|
262
|
+
["charlie", 1000, "sat"],
|
|
263
|
+
];
|
|
264
|
+
let fee = 1362;
|
|
265
|
+
let requests = asSendRequestObject(to) as SendRequest[];
|
|
266
|
+
let result = allocateFee(
|
|
267
|
+
requests,
|
|
268
|
+
fee,
|
|
269
|
+
FeePaidByEnum.changeThenAny,
|
|
270
|
+
BigInt(1362)
|
|
271
|
+
);
|
|
272
|
+
expect(result[0].value).toBe(1000);
|
|
273
|
+
expect(result[1].value).toBe(1000);
|
|
274
|
+
expect(result[2].value).toBe(1000);
|
|
275
|
+
});
|
|
286
276
|
|
|
287
|
-
test("Expect
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
277
|
+
test("Expect `change,any` to use both", async () => {
|
|
278
|
+
let to = [
|
|
279
|
+
["alice", 1000, "sat"],
|
|
280
|
+
["bob", 1000, "sat"],
|
|
281
|
+
["charlie", 1000, "sat"],
|
|
282
|
+
];
|
|
283
|
+
let fee = 1362 * 2;
|
|
284
|
+
let requests = asSendRequestObject(to) as SendRequest[];
|
|
285
|
+
let result = allocateFee(
|
|
286
|
+
requests,
|
|
287
|
+
fee,
|
|
288
|
+
FeePaidByEnum.changeThenAny,
|
|
289
|
+
BigInt(1362)
|
|
290
|
+
);
|
|
291
|
+
expect(result[0].value).toBe(546);
|
|
292
|
+
expect(result[1].value).toBe(546);
|
|
293
|
+
expect(result[2].value).toBe(546);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test("Expect sortSendRequests to sort by lowest value first", async () => {
|
|
297
|
+
let to = [
|
|
298
|
+
["alice", 2000, "sat"],
|
|
299
|
+
["bob", 547, "sat"],
|
|
300
|
+
["charlie", 1, "sat"],
|
|
301
|
+
["dave", 4, "sat"],
|
|
302
|
+
["edward", 6, "sat"],
|
|
303
|
+
["fred", 2000, "sat"],
|
|
304
|
+
["greg", 2000, "sat"],
|
|
305
|
+
["harry", 2000, "sat"],
|
|
306
|
+
];
|
|
307
|
+
let fee = 1;
|
|
308
|
+
let requests = asSendRequestObject(to) as SendRequest[];
|
|
300
309
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
310
|
+
let result = sortSendRequests(requests);
|
|
311
|
+
expect(result[0].value).toBe(1);
|
|
312
|
+
expect(result[1].value).toBe(4);
|
|
313
|
+
expect(result[2].value).toBe(6);
|
|
314
|
+
expect(result[3].value).toBe(547);
|
|
315
|
+
expect(result[4].value).toBe(2000);
|
|
316
|
+
expect(result[5].value).toBe(2000);
|
|
317
|
+
expect(result.length).toBe(8);
|
|
318
|
+
});
|
|
309
319
|
});
|