@@ -5,108 +5,112 @@ import { PaymentCreator, PaymentFactory } from '../src/payments';
55import * as u from './payments.utils' ;
66
77const payments = PaymentFactory ( ecc ) ;
8- [ 'embed' , 'p2ms' , 'p2pk' , 'p2pkh' , 'p2sh' , 'p2wpkh' , 'p2wsh' , 'p2tr' ] . forEach ( p => {
9- describe ( p , ( ) => {
10- //@ts -ignore
11- const fn : PaymentCreator = payments [ p ] ;
8+ [ 'embed' , 'p2ms' , 'p2pk' , 'p2pkh' , 'p2sh' , 'p2wpkh' , 'p2wsh' , 'p2tr' ] . forEach (
9+ p => {
10+ describe ( p , ( ) => {
11+ //@ts -ignore
12+ const fn : PaymentCreator = payments [ p ] ;
1213
13- const fixtures = require ( './fixtures/' + p ) ;
14+ const fixtures = require ( './fixtures/' + p ) ;
1415
15- fixtures . valid . forEach ( ( f : any ) => {
16- it ( f . description + ' as expected' , ( ) => {
17- const args = u . preform ( f . arguments ) ;
18- const actual = fn ( args , f . options ) ;
16+ fixtures . valid . forEach ( ( f : any ) => {
17+ it ( f . description + ' as expected' , ( ) => {
18+ const args = u . preform ( f . arguments ) ;
19+ const actual = fn ( args , f . options ) ;
1920
20- u . equate ( actual , f . expected , f . arguments ) ;
21- } ) ;
21+ u . equate ( actual , f . expected , f . arguments ) ;
22+ } ) ;
2223
23- it ( f . description + ' as expected (no validation)' , ( ) => {
24- const args = u . preform ( f . arguments ) ;
25- const actual = fn (
26- args ,
27- Object . assign ( { } , f . options , {
28- validate : false ,
29- } ) ,
30- ) ;
24+ it ( f . description + ' as expected (no validation)' , ( ) => {
25+ const args = u . preform ( f . arguments ) ;
26+ const actual = fn (
27+ args ,
28+ Object . assign ( { } , f . options , {
29+ validate : false ,
30+ } ) ,
31+ ) ;
3132
32- u . equate ( actual , f . expected , f . arguments ) ;
33+ u . equate ( actual , f . expected , f . arguments ) ;
34+ } ) ;
3335 } ) ;
34- } ) ;
3536
36- fixtures . invalid . forEach ( ( f : any ) => {
37- it (
38- 'throws ' + f . exception + ( f . description ? 'for ' + f . description : '' ) ,
39- ( ) => {
40- const args = u . preform ( f . arguments ) ;
37+ fixtures . invalid . forEach ( ( f : any ) => {
38+ it (
39+ 'throws ' +
40+ f . exception +
41+ ( f . description ? 'for ' + f . description : '' ) ,
42+ ( ) => {
43+ const args = u . preform ( f . arguments ) ;
4144
42- assert . throws ( ( ) => {
43- fn ( args , f . options ) ;
44- } , new RegExp ( f . exception ) ) ;
45- } ,
46- ) ;
47- } ) ;
45+ assert . throws ( ( ) => {
46+ fn ( args , f . options ) ;
47+ } , new RegExp ( f . exception ) ) ;
48+ } ,
49+ ) ;
50+ } ) ;
4851
49- if ( p === 'p2sh' ) {
50- const p2wsh = require ( '../src/payments/p2wsh' ) . p2wsh ;
51- const p2pk = require ( '../src/payments/p2pk' ) . p2pk ;
52- it ( 'properly assembles nested p2wsh with names' , ( ) => {
53- const actual = fn ( {
54- redeem : p2wsh ( {
55- redeem : p2pk ( {
56- pubkey : Buffer . from (
57- '03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058' ,
58- 'hex' ,
59- ) ,
52+ if ( p === 'p2sh' ) {
53+ const p2wsh = require ( '../src/payments/p2wsh' ) . p2wsh ;
54+ const p2pk = require ( '../src/payments/p2pk' ) . p2pk ;
55+ it ( 'properly assembles nested p2wsh with names' , ( ) => {
56+ const actual = fn ( {
57+ redeem : p2wsh ( {
58+ redeem : p2pk ( {
59+ pubkey : Buffer . from (
60+ '03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058' ,
61+ 'hex' ,
62+ ) ,
63+ } ) ,
6064 } ) ,
61- } ) ,
65+ } ) ;
66+ assert . strictEqual (
67+ actual . address ,
68+ '3MGbrbye4ttNUXM8WAvBFRKry4fkS9fjuw' ,
69+ ) ;
70+ assert . strictEqual ( actual . name , 'p2sh-p2wsh-p2pk' ) ;
71+ assert . strictEqual ( actual . redeem ! . name , 'p2wsh-p2pk' ) ;
72+ assert . strictEqual ( actual . redeem ! . redeem ! . name , 'p2pk' ) ;
6273 } ) ;
63- assert . strictEqual (
64- actual . address ,
65- '3MGbrbye4ttNUXM8WAvBFRKry4fkS9fjuw' ,
66- ) ;
67- assert . strictEqual ( actual . name , 'p2sh-p2wsh-p2pk' ) ;
68- assert . strictEqual ( actual . redeem ! . name , 'p2wsh-p2pk' ) ;
69- assert . strictEqual ( actual . redeem ! . redeem ! . name , 'p2pk' ) ;
70- } ) ;
71- }
74+ }
7275
73- // cross-verify dynamically too
74- if ( ! fixtures . dynamic ) return ;
75- const { depends, details } = fixtures . dynamic ;
76+ // cross-verify dynamically too
77+ if ( ! fixtures . dynamic ) return ;
78+ const { depends, details } = fixtures . dynamic ;
7679
77- details . forEach ( ( f : any ) => {
78- const detail = u . preform ( f ) ;
79- const disabled : any = { } ;
80- if ( f . disabled )
81- f . disabled . forEach ( ( k : string ) => {
82- disabled [ k ] = true ;
83- } ) ;
80+ details . forEach ( ( f : any ) => {
81+ const detail = u . preform ( f ) ;
82+ const disabled : any = { } ;
83+ if ( f . disabled )
84+ f . disabled . forEach ( ( k : string ) => {
85+ disabled [ k ] = true ;
86+ } ) ;
8487
85- for ( const key in depends ) {
86- if ( key in disabled ) continue ;
87- const dependencies = depends [ key ] ;
88+ for ( const key in depends ) {
89+ if ( key in disabled ) continue ;
90+ const dependencies = depends [ key ] ;
8891
89- dependencies . forEach ( ( dependency : any ) => {
90- if ( ! Array . isArray ( dependency ) ) dependency = [ dependency ] ;
92+ dependencies . forEach ( ( dependency : any ) => {
93+ if ( ! Array . isArray ( dependency ) ) dependency = [ dependency ] ;
9194
92- const args = { } ;
93- dependency . forEach ( ( d : any ) => {
94- u . from ( d , detail , args ) ;
95- } ) ;
96- const expected = u . from ( key , detail ) ;
95+ const args = { } ;
96+ dependency . forEach ( ( d : any ) => {
97+ u . from ( d , detail , args ) ;
98+ } ) ;
99+ const expected = u . from ( key , detail ) ;
97100
98- it (
99- f . description +
100- ', ' +
101- key +
102- ' derives from ' +
103- JSON . stringify ( dependency ) ,
104- ( ) => {
105- u . equate ( fn ( args ) , expected ) ;
106- } ,
107- ) ;
108- } ) ;
109- }
101+ it (
102+ f . description +
103+ ', ' +
104+ key +
105+ ' derives from ' +
106+ JSON . stringify ( dependency ) ,
107+ ( ) => {
108+ u . equate ( fn ( args ) , expected ) ;
109+ } ,
110+ ) ;
111+ } ) ;
112+ }
113+ } ) ;
110114 } ) ;
111- } ) ;
112- } ) ;
115+ } ,
116+ ) ;
0 commit comments