@@ -13,27 +13,26 @@ let outputs = [
13
13
14
14
let changeOutput = { } ;
15
15
16
- Zora . test ( "too few sats" , async function ( t ) {
16
+ Zora . test ( "too few sats" , function ( t ) {
17
17
let inputs = [
18
18
{
19
19
satoshis : 20000 + 190 ,
20
20
} ,
21
21
] ;
22
- await DashTx . legacyCreateTx ( inputs , outputs , changeOutput )
23
- . then ( function ( ) {
24
- t . ok ( false , "should throw when there aren't enough sats" ) ;
25
- } )
26
- . catch ( function ( e ) {
27
- let msg = e . message ;
28
- let isAboutMemo = / \b c a n n o t p a y f o r \b / . test ( e . message ) ;
29
- if ( isAboutMemo ) {
30
- msg = "throws when there are too few sats" ;
31
- }
32
- t . ok ( isAboutMemo , msg ) ;
33
- } ) ;
22
+ try {
23
+ DashTx . legacyCreateTx ( inputs , outputs , changeOutput ) ;
24
+ t . ok ( false , "should throw when there aren't enough sats" ) ;
25
+ } catch ( e ) {
26
+ let msg = e . message ;
27
+ let isAboutMemo = / \b c a n n o t p a y f o r \b / . test ( e . message ) ;
28
+ if ( isAboutMemo ) {
29
+ msg = "throws when there are too few sats" ;
30
+ }
31
+ t . ok ( isAboutMemo , msg ) ;
32
+ }
34
33
} ) ;
35
34
36
- Zora . test ( "exactly enough sats" , async function ( t ) {
35
+ Zora . test ( "exactly enough sats" , function ( t ) {
37
36
let inputs = [
38
37
{
39
38
satoshis : 20000 + 190 ,
@@ -43,52 +42,37 @@ Zora.test("exactly enough sats", async function (t) {
43
42
} ,
44
43
] ;
45
44
46
- await DashTx . legacyCreateTx ( inputs , outputs , changeOutput )
47
- . then ( function ( ) {
48
- t . ok ( true , "sats match exactly" ) ;
49
- } )
50
- . catch ( function ( e ) {
51
- t . ok ( false , e . message ) ;
52
- } ) ;
45
+ DashTx . legacyCreateTx ( inputs , outputs , changeOutput ) ;
46
+ t . ok ( true , "sats match exactly" ) ;
53
47
} ) ;
54
48
55
- Zora . test ( "donates dust" , async function ( t ) {
49
+ Zora . test ( "donates dust" , function ( t ) {
56
50
let satoshis = 20000 + 193 + DashTx . LEGACY_DUST + DashTx . OUTPUT_SIZE + - 1 ;
57
51
let inputs = [ { satoshis } ] ;
58
52
59
- await DashTx . legacyCreateTx ( inputs , outputs , changeOutput )
60
- . then ( function ( txInfo ) {
61
- if ( txInfo . length > 1 ) {
62
- throw new Error ( "created return change for dust" ) ;
63
- }
64
- t . ok ( true , "has no return change" ) ;
65
- } )
66
- . catch ( function ( e ) {
67
- t . ok ( false , e . message ) ;
68
- } ) ;
53
+ let txInfo = DashTx . legacyCreateTx ( inputs , outputs , changeOutput ) ;
54
+ if ( txInfo . length > 1 ) {
55
+ throw new Error ( "created return change for dust" ) ;
56
+ }
57
+ t . ok ( true , "has no return change" ) ;
69
58
} ) ;
70
59
71
- Zora . test ( "returns change" , async function ( t ) {
60
+ Zora . test ( "returns change" , function ( t ) {
72
61
let satoshis = 20000 + 193 + DashTx . LEGACY_DUST + DashTx . OUTPUT_SIZE ;
73
62
let inputs = [ { satoshis } ] ;
74
63
75
- await DashTx . legacyCreateTx ( inputs , outputs , changeOutput )
76
- . then ( function ( txInfo ) {
77
- let hasChange = txInfo . changeIndex >= 0 ;
78
- if ( ! hasChange ) {
79
- throw new Error ( "did not create return change" ) ;
80
- }
81
-
82
- let change = txInfo . outputs [ txInfo . changeIndex ] ;
83
- if ( ! change ) {
84
- throw new Error ( "did not add change to outputs" ) ;
85
- }
86
-
87
- t . ok ( true , "returned change >= dust" ) ;
88
- } )
89
- . catch ( function ( e ) {
90
- t . ok ( false , e . message ) ;
91
- } ) ;
64
+ let txInfo = DashTx . legacyCreateTx ( inputs , outputs , changeOutput ) ;
65
+ let hasChange = txInfo . changeIndex >= 0 ;
66
+ if ( ! hasChange ) {
67
+ throw new Error ( "did not create return change" ) ;
68
+ }
69
+
70
+ let change = txInfo . outputs [ txInfo . changeIndex ] ;
71
+ if ( ! change ) {
72
+ throw new Error ( "did not add change to outputs" ) ;
73
+ }
74
+
75
+ t . ok ( true , "returned change >= dust" ) ;
92
76
} ) ;
93
77
94
78
Zora . test ( "coins selection is better than random" , async function ( t ) {
@@ -100,21 +84,16 @@ Zora.test("coins selection is better than random", async function (t) {
100
84
{ satoshis : 500000 } ,
101
85
] ;
102
86
103
- await DashTx . legacyCreateTx ( inputs , outputs , changeOutput )
104
- . then ( function ( txInfo ) {
105
- let tooManyInputs = txInfo . inputs . length >= 0 ;
106
- if ( ! tooManyInputs ) {
107
- throw new Error ( "selected more inputs than necessary" ) ;
108
- }
109
-
110
- let isOptimalInput = txInfo . inputs [ 0 ] . satoshis === exact ;
111
- if ( ! isOptimalInput ) {
112
- throw new Error ( "did not select clearly optimal input" ) ;
113
- }
114
-
115
- t . ok ( true , "selected closest input" ) ;
116
- } )
117
- . catch ( function ( e ) {
118
- t . ok ( false , e . message ) ;
119
- } ) ;
87
+ let txInfo = await DashTx . legacyCreateTx ( inputs , outputs , changeOutput ) ;
88
+ let tooManyInputs = txInfo . inputs . length >= 0 ;
89
+ if ( ! tooManyInputs ) {
90
+ throw new Error ( "selected more inputs than necessary" ) ;
91
+ }
92
+
93
+ let isOptimalInput = txInfo . inputs [ 0 ] . satoshis === exact ;
94
+ if ( ! isOptimalInput ) {
95
+ throw new Error ( "did not select clearly optimal input" ) ;
96
+ }
97
+
98
+ t . ok ( true , "selected closest input" ) ;
120
99
} ) ;
0 commit comments