@@ -40,6 +40,12 @@ describe('ICP transaction recovery', async () => {
40
40
broadcastResponse = Buffer . from ( testData . PublicNodeApiBroadcastResponse , 'hex' ) ;
41
41
} ) ;
42
42
43
+ beforeEach ( function ( ) {
44
+ // Common stubs for IcpAgent
45
+ sinon . stub ( IcpAgent . prototype , 'getBalance' ) . resolves ( BigNumber ( 1000000000 ) ) ;
46
+ sinon . stub ( IcpAgent . prototype , 'getFee' ) . resolves ( BigNumber ( 10000 ) ) ;
47
+ } ) ;
48
+
43
49
afterEach ( function ( ) {
44
50
recoveryParams = {
45
51
userKey : testData . WRWRecovery . userKey ,
@@ -66,8 +72,6 @@ describe('ICP transaction recovery', async () => {
66
72
} ) ;
67
73
68
74
const body = testData . RecoverySignedTransactionWithDefaultMemo ;
69
- sinon . stub ( IcpAgent . prototype , 'getBalance' ) . resolves ( BigNumber ( 1000000000 ) ) ;
70
- sinon . stub ( IcpAgent . prototype , 'getFee' ) . resolves ( BigNumber ( 10000 ) ) ;
71
75
nock ( nodeUrl ) . post ( broadcastEndpoint , body ) . reply ( 200 , broadcastResponse ) ;
72
76
const recoverTxn = await icp . recover ( recoveryParams ) ;
73
77
recoverTxn . id . should . be . a . String ( ) ;
@@ -88,8 +92,6 @@ describe('ICP transaction recovery', async () => {
88
92
} ) ;
89
93
90
94
const body = testData . RecoverySignedTransactionWithMemo ;
91
- sinon . stub ( IcpAgent . prototype , 'getBalance' ) . resolves ( BigNumber ( 1000000000 ) ) ;
92
- sinon . stub ( IcpAgent . prototype , 'getFee' ) . resolves ( BigNumber ( 10000 ) ) ;
93
95
nock ( nodeUrl ) . post ( broadcastEndpoint , body ) . reply ( 200 , broadcastResponse ) ;
94
96
recoveryParams . memo = testData . MetaDataWithMemo . memo ;
95
97
const recoverTxn = await icp . recover ( recoveryParams ) ;
@@ -109,8 +111,6 @@ describe('ICP transaction recovery', async () => {
109
111
ingressEndTime : testData . MetaDataWithMemo . ingress_end ,
110
112
} ) ;
111
113
112
- sinon . stub ( IcpAgent . prototype , 'getBalance' ) . resolves ( BigNumber ( 1000000000 ) ) ;
113
- sinon . stub ( IcpAgent . prototype , 'getFee' ) . resolves ( BigNumber ( 10000 ) ) ;
114
114
const unsignedSweepRecoveryParams = {
115
115
bitgoKey :
116
116
'0310768736a005ea5364e1b5b5288cf553224dd28b2df8ced63b72a8020478967f05ec5bce1f26cd7eb009a4bea445bb55c2f54a30f2706c1a3747e8df2d288829' ,
@@ -133,8 +133,6 @@ describe('ICP transaction recovery', async () => {
133
133
ingressEndTime : testData . MetaDataWithMemo . ingress_end ,
134
134
} ) ;
135
135
136
- sinon . stub ( IcpAgent . prototype , 'getBalance' ) . resolves ( BigNumber ( 1000000000 ) ) ;
137
- sinon . stub ( IcpAgent . prototype , 'getFee' ) . resolves ( BigNumber ( 10000 ) ) ;
138
136
const unsignedSweepRecoveryParams = {
139
137
bitgoKey : 'testKey' ,
140
138
recoveryDestination : testData . Accounts . account2 . address ,
@@ -156,17 +154,13 @@ describe('ICP transaction recovery', async () => {
156
154
ingressEndTime : testData . MetaDataWithMemo . ingress_end ,
157
155
} ) ;
158
156
159
- sinon . stub ( IcpAgent . prototype , 'getBalance' ) . resolves ( BigNumber ( 1000000000 ) ) ;
160
- sinon . stub ( IcpAgent . prototype , 'getFee' ) . resolves ( BigNumber ( 10000 ) ) ;
161
157
const unsignedSweepRecoveryParams = {
162
158
recoveryDestination : testData . Accounts . account2 . address ,
163
159
} ;
164
160
await icp . recover ( unsignedSweepRecoveryParams ) . should . rejectedWith ( 'Error during ICP recovery: missing bitgoKey' ) ;
165
161
} ) ;
166
162
167
163
it ( 'should fail to recover if broadcast API fails' , async ( ) => {
168
- sinon . stub ( IcpAgent . prototype , 'getBalance' ) . resolves ( BigNumber ( 1000000000 ) ) ;
169
- sinon . stub ( IcpAgent . prototype , 'getFee' ) . resolves ( BigNumber ( 10000 ) ) ;
170
164
nock ( nodeUrl ) . post ( broadcastEndpoint ) . reply ( 500 , 'Internal Server Error' ) ;
171
165
recoveryParams . memo = 0 ;
172
166
await icp
@@ -177,6 +171,8 @@ describe('ICP transaction recovery', async () => {
177
171
} ) ;
178
172
179
173
it ( 'should fail to recover txn if balance is low' , async ( ) => {
174
+ // Override the default balance stub for this specific test
175
+ sinon . restore ( ) ;
180
176
sinon . stub ( IcpAgent . prototype , 'getBalance' ) . resolves ( BigNumber ( 10 ) ) ;
181
177
sinon . stub ( IcpAgent . prototype , 'getFee' ) . resolves ( BigNumber ( 10000 ) ) ;
182
178
nock ( nodeUrl ) . post ( broadcastEndpoint ) . reply ( 200 , broadcastResponse ) ;
0 commit comments