Skip to content

Commit 3735a7d

Browse files
Merge pull request #5247 from BitGo/BTC-1450.move-outputdifference-test
refactor(abstract-utxo): move outputDifference test to abstract-utxo module
2 parents 714528b + 86bef95 commit 3735a7d

File tree

3 files changed

+97
-97
lines changed

3 files changed

+97
-97
lines changed

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
536536
* @param second
537537
* @returns {Array} All outputs that are in the first array but not in the second
538538
*/
539-
protected static outputDifference(first: Output[], second: Output[]): Output[] {
539+
public static outputDifference(first: Output[], second: Output[]): Output[] {
540540
const keyFunc = ({ address, amount }: Output): string => `${address}:${amount}`;
541541
const groupedOutputs = _.groupBy(first, keyFunc);
542542

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import 'should';
2+
3+
import { AbstractUtxoCoin } from '../src';
4+
5+
describe('Missing output detection', function () {
6+
it('should recognize count mismatch dupes', function () {
7+
const expectedOutputs = [
8+
{
9+
address: '2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ',
10+
amount: '300000',
11+
},
12+
{
13+
amount: '300000',
14+
address: '2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ',
15+
},
16+
];
17+
18+
const actualOutputs = [
19+
{
20+
address: '2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ',
21+
amount: 300000,
22+
},
23+
{
24+
address: '2N2womedYhTC3YCDtviFte5G7teQczpVcds',
25+
amount: 15349374,
26+
},
27+
];
28+
29+
// missing should be one entry of the two
30+
const missingOutputs = AbstractUtxoCoin.outputDifference(expectedOutputs, actualOutputs);
31+
32+
missingOutputs.length.should.equal(1);
33+
missingOutputs[0].address.should.equal('2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ');
34+
missingOutputs[0].amount.should.equal('300000');
35+
});
36+
37+
it('should be order-agnostic', function () {
38+
const expectedOutputs = [
39+
{
40+
address: '2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ',
41+
amount: '300000',
42+
},
43+
{
44+
amount: '300000',
45+
address: '2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ',
46+
},
47+
];
48+
49+
const actualOutputs = [
50+
{
51+
address: '2N2womedYhTC3YCDtviFte5G7teQczpVcds',
52+
amount: 15349374,
53+
},
54+
{
55+
address: '2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ',
56+
amount: 300000,
57+
},
58+
];
59+
// missing should be one entry of the two
60+
61+
const missingOutputs = AbstractUtxoCoin.outputDifference(expectedOutputs, actualOutputs);
62+
63+
missingOutputs.length.should.equal(1);
64+
missingOutputs[0].address.should.equal('2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ');
65+
missingOutputs[0].amount.should.equal('300000');
66+
});
67+
68+
it('should preserve all dupes', function () {
69+
const expectedOutputs = [
70+
{
71+
address: '2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ',
72+
amount: '300000',
73+
},
74+
{
75+
amount: '300000',
76+
address: '2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ',
77+
},
78+
];
79+
80+
const actualOutputs = [
81+
{
82+
address: '2N2womedYhTC3YCDtviFte5G7teQczpVcds',
83+
amount: 15349374,
84+
},
85+
];
86+
// missing should be one entry of the two
87+
88+
const missingOutputs = AbstractUtxoCoin.outputDifference(expectedOutputs, actualOutputs);
89+
90+
missingOutputs.length.should.equal(2);
91+
missingOutputs[0].address.should.equal('2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ');
92+
missingOutputs[1].address.should.equal('2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ');
93+
missingOutputs[0].amount.should.equal('300000');
94+
missingOutputs[1].amount.should.equal('300000');
95+
});
96+
});

modules/bitgo/test/v2/unit/baseCoin.ts

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -146,100 +146,4 @@ describe('V2 Base Coin:', function () {
146146
holeskyToken.getFamily().should.equal('eth');
147147
});
148148
});
149-
150-
describe('Missing output detection', function () {
151-
it('should recognize count mismatch dupes', function () {
152-
const expectedOutputs = [
153-
{
154-
address: '2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ',
155-
amount: '300000',
156-
},
157-
{
158-
amount: '300000',
159-
address: '2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ',
160-
},
161-
];
162-
163-
const actualOutputs = [
164-
{
165-
address: '2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ',
166-
amount: 300000,
167-
},
168-
{
169-
address: '2N2womedYhTC3YCDtviFte5G7teQczpVcds',
170-
amount: 15349374,
171-
},
172-
];
173-
// missing should be one entry of the two
174-
175-
const utxoBasecoin = bitgo.coin('tltc');
176-
const missingOutputs = utxoBasecoin.constructor.outputDifference(expectedOutputs, actualOutputs);
177-
178-
missingOutputs.length.should.equal(1);
179-
missingOutputs[0].address.should.equal('2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ');
180-
missingOutputs[0].amount.should.equal('300000');
181-
});
182-
183-
it('should be order-agnostic', function () {
184-
const expectedOutputs = [
185-
{
186-
address: '2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ',
187-
amount: '300000',
188-
},
189-
{
190-
amount: '300000',
191-
address: '2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ',
192-
},
193-
];
194-
195-
const actualOutputs = [
196-
{
197-
address: '2N2womedYhTC3YCDtviFte5G7teQczpVcds',
198-
amount: 15349374,
199-
},
200-
{
201-
address: '2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ',
202-
amount: 300000,
203-
},
204-
];
205-
// missing should be one entry of the two
206-
207-
const utxoBasecoin = bitgo.coin('tltc');
208-
const missingOutputs = utxoBasecoin.constructor.outputDifference(expectedOutputs, actualOutputs);
209-
210-
missingOutputs.length.should.equal(1);
211-
missingOutputs[0].address.should.equal('2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ');
212-
missingOutputs[0].amount.should.equal('300000');
213-
});
214-
215-
it('should preserve all dupes', function () {
216-
const expectedOutputs = [
217-
{
218-
address: '2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ',
219-
amount: '300000',
220-
},
221-
{
222-
amount: '300000',
223-
address: '2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ',
224-
},
225-
];
226-
227-
const actualOutputs = [
228-
{
229-
address: '2N2womedYhTC3YCDtviFte5G7teQczpVcds',
230-
amount: 15349374,
231-
},
232-
];
233-
// missing should be one entry of the two
234-
235-
const utxoBasecoin = bitgo.coin('tltc');
236-
const missingOutputs = utxoBasecoin.constructor.outputDifference(expectedOutputs, actualOutputs);
237-
238-
missingOutputs.length.should.equal(2);
239-
missingOutputs[0].address.should.equal('2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ');
240-
missingOutputs[1].address.should.equal('2N6eb6Gosm2jt4o3djFLjb4kuKyPgAj8teZ');
241-
missingOutputs[0].amount.should.equal('300000');
242-
missingOutputs[1].amount.should.equal('300000');
243-
});
244-
});
245149
});

0 commit comments

Comments
 (0)