|
1 | 1 | import assert from 'assert'; |
2 | 2 |
|
3 | | -import { Descriptor } from '@bitgo/wasm-miniscript'; |
4 | | - |
5 | | -import { isExternalOutput, isInternalOutput } from '../../src/descriptor'; |
| 3 | +import { isExternalOutput, isInternalOutput, toDerivedDescriptorWalletOutput } from '../../src/descriptor/Output'; |
| 4 | +import { getDescriptor } from '../../src/testutil/descriptor'; |
| 5 | +import { createScriptPubKeyFromDescriptor } from '../../src/descriptor'; |
6 | 6 |
|
7 | 7 | describe('decscriptor.Output', function () { |
8 | | - const mockDescriptor = {} as Descriptor; |
| 8 | + const descriptor = getDescriptor('Wsh2Of3'); |
9 | 9 |
|
10 | 10 | it('isInternalOutput correctly identifies internal outputs', function () { |
11 | | - const internalOutput = { value: 1n, descriptor: mockDescriptor }; |
| 11 | + const internalOutput = { value: 1n, descriptor }; |
12 | 12 | const externalOutput = { value: 1n }; |
13 | 13 |
|
14 | 14 | assert.strictEqual(isInternalOutput(internalOutput), true); |
15 | 15 | assert.strictEqual(isInternalOutput(externalOutput), false); |
16 | 16 | }); |
17 | 17 |
|
18 | 18 | it('isExternalOutput correctly identifies external outputs', function () { |
19 | | - const internalOutput = { value: 1n, descriptor: mockDescriptor }; |
| 19 | + const internalOutput = { value: 1n, descriptor }; |
20 | 20 | const externalOutput = { value: 1n }; |
21 | 21 |
|
22 | 22 | assert.strictEqual(isExternalOutput(internalOutput), false); |
23 | 23 | assert.strictEqual(isExternalOutput(externalOutput), true); |
24 | 24 | }); |
| 25 | + |
| 26 | + it('toDerivedDescriptorWalletOutput returns expected values', function () { |
| 27 | + const derivable = descriptor; |
| 28 | + const definite = derivable.atDerivationIndex(0); |
| 29 | + for (const descriptor of [derivable, definite]) { |
| 30 | + const descriptorIndex = descriptor === derivable ? 0 : undefined; |
| 31 | + const descriptorMap = new Map([['desc', descriptor]]); |
| 32 | + const descriptorWalletOutput = { |
| 33 | + hash: Buffer.alloc(32).toString('hex'), |
| 34 | + index: 0, |
| 35 | + witnessUtxo: { |
| 36 | + script: createScriptPubKeyFromDescriptor(descriptor, descriptorIndex), |
| 37 | + value: 1n, |
| 38 | + }, |
| 39 | + descriptorName: 'desc', |
| 40 | + descriptorIndex, |
| 41 | + }; |
| 42 | + assert.strictEqual( |
| 43 | + toDerivedDescriptorWalletOutput(descriptorWalletOutput, descriptorMap).descriptor.toString(), |
| 44 | + definite.toString() |
| 45 | + ); |
| 46 | + } |
| 47 | + }); |
25 | 48 | }); |
0 commit comments