@@ -6,44 +6,33 @@ import { getFixtureString } from '../fixtures';
6
6
import { getKeyTriple } from '../bip32.util' ;
7
7
import { captureConsole } from '../captureConsole' ;
8
8
9
- describe ( 'cmdDescriptor fromFixedScript' , function ( ) {
10
- it ( 'should be a yargs command' , function ( ) {
11
- assert . strictEqual ( typeof cmdFromFixedScript . command , 'string' ) ;
12
- assert . strictEqual ( typeof cmdFromFixedScript . describe , 'string' ) ;
13
- assert . strictEqual ( typeof cmdFromFixedScript . builder , 'function' ) ;
14
- assert . strictEqual ( typeof cmdFromFixedScript . handler , 'function' ) ;
15
- } ) ;
9
+ function keyArgs ( ) : string [ ] {
10
+ const [ userKey , backupKey , bitgoKey ] = getKeyTriple ( 'generateAddress' ) . map ( ( k ) => k . neutered ( ) . toBase58 ( ) ) ;
11
+ return [ '--userKey' , userKey , '--backupKey' , backupKey , '--bitgoKey' , bitgoKey , '--scriptType' , 'p2sh' ] ;
12
+ }
16
13
17
- it ( 'should output expected descriptor for valid keys' , async function ( ) {
18
- const [ userKey , backupKey , bitgoKey ] = getKeyTriple ( 'generateAddress' ) . map ( ( k ) => k . neutered ( ) . toBase58 ( ) ) ;
19
- const argv = [
20
- 'fromFixedScript' ,
21
- '--userKey' ,
22
- userKey ,
23
- '--backupKey' ,
24
- backupKey ,
25
- '--bitgoKey' ,
26
- bitgoKey ,
27
- '--scriptType' ,
28
- 'p2sh' ,
29
- '--network' ,
30
- 'testnet' ,
31
- ] ;
14
+ describe ( 'cmdDescriptor fromFixedScript' , function ( ) {
15
+ function runTest ( argv : string [ ] , fixtureName : string ) {
16
+ it ( `should output expected descriptor (${ fixtureName } )` , async function ( ) {
17
+ const y = yargs ( argv )
18
+ . command ( cmdFromFixedScript )
19
+ . exitProcess ( false )
20
+ . fail ( ( msg , err ) => {
21
+ throw err || new Error ( msg ) ;
22
+ } ) ;
32
23
33
- const y = yargs ( argv )
34
- . command ( cmdFromFixedScript )
35
- . exitProcess ( false )
36
- . fail ( ( msg , err ) => {
37
- throw err || new Error ( msg ) ;
24
+ const { stdout, stderr } = await captureConsole ( async ( ) => {
25
+ await y . parse ( ) ;
38
26
} ) ;
39
27
40
- const { stdout, stderr } = await captureConsole ( async ( ) => {
41
- await y . parse ( ) ;
28
+ // Compare output to fixture, or check for expected descriptor substring
29
+ const expected = await getFixtureString ( `test/fixtures/fromFixedScript/${ fixtureName } .txt` , stdout ) ;
30
+ assert . strictEqual ( stdout . trim ( ) , expected . trim ( ) ) ;
31
+ assert . strictEqual ( stderr , '' ) ;
42
32
} ) ;
33
+ }
34
+
35
+ runTest ( [ 'fromFixedScript' , ...keyArgs ( ) ] , 'default' ) ;
43
36
44
- // Compare output to fixture, or check for expected descriptor substring
45
- const expected = await getFixtureString ( 'test/fixtures/fromFixedScript/descriptors.txt' , stdout ) ;
46
- assert . strictEqual ( stdout . trim ( ) , expected . trim ( ) ) ;
47
- assert . strictEqual ( stderr , '' ) ;
48
- } ) ;
37
+ runTest ( [ 'fromFixedScript' , ...keyArgs ( ) , '--network' , 'testnet' ] , 'network-testnet' ) ;
49
38
} ) ;
0 commit comments