@@ -18,7 +18,6 @@ package core_test
18
18
19
19
import (
20
20
"bytes"
21
- "context"
22
21
"fmt"
23
22
"math/big"
24
23
"os"
@@ -97,12 +96,12 @@ func (ui *headlessUi) ApproveNewAccount(request *core.NewAccountRequest) (core.N
97
96
}
98
97
99
98
func (ui * headlessUi ) ShowError (message string ) {
100
- //stdout is used by communication
99
+ // stdout is used by communication
101
100
fmt .Fprintln (os .Stderr , message )
102
101
}
103
102
104
103
func (ui * headlessUi ) ShowInfo (message string ) {
105
- //stdout is used by communication
104
+ // stdout is used by communication
106
105
fmt .Fprintln (os .Stderr , message )
107
106
}
108
107
@@ -128,7 +127,7 @@ func setup(t *testing.T) (*core.SignerAPI, *headlessUi) {
128
127
func createAccount (ui * headlessUi , api * core.SignerAPI , t * testing.T ) {
129
128
ui .approveCh <- "Y"
130
129
ui .inputCh <- "a_long_password"
131
- _ , err := api .New (context . Background ())
130
+ _ , err := api .New (t . Context ())
132
131
if err != nil {
133
132
t .Fatal (err )
134
133
}
@@ -143,7 +142,7 @@ func failCreateAccountWithPassword(ui *headlessUi, api *core.SignerAPI, password
143
142
ui .inputCh <- password
144
143
ui .inputCh <- password
145
144
146
- addr , err := api .New (context . Background ())
145
+ addr , err := api .New (t . Context ())
147
146
if err == nil {
148
147
t .Fatal ("Should have returned an error" )
149
148
}
@@ -154,7 +153,7 @@ func failCreateAccountWithPassword(ui *headlessUi, api *core.SignerAPI, password
154
153
155
154
func failCreateAccount (ui * headlessUi , api * core.SignerAPI , t * testing.T ) {
156
155
ui .approveCh <- "N"
157
- addr , err := api .New (context . Background ())
156
+ addr , err := api .New (t . Context ())
158
157
if err != core .ErrRequestDenied {
159
158
t .Fatal (err )
160
159
}
@@ -165,7 +164,7 @@ func failCreateAccount(ui *headlessUi, api *core.SignerAPI, t *testing.T) {
165
164
166
165
func list (ui * headlessUi , api * core.SignerAPI , t * testing.T ) ([]common.Address , error ) {
167
166
ui .approveCh <- "A"
168
- return api .List (context . Background ())
167
+ return api .List (t . Context ())
169
168
}
170
169
171
170
func TestNewAcc (t * testing.T ) {
@@ -199,7 +198,7 @@ func TestNewAcc(t *testing.T) {
199
198
// Testing listing:
200
199
// Listing one Account
201
200
control .approveCh <- "1"
202
- list , err := api .List (context . Background ())
201
+ list , err := api .List (t . Context ())
203
202
if err != nil {
204
203
t .Fatal (err )
205
204
}
@@ -208,7 +207,7 @@ func TestNewAcc(t *testing.T) {
208
207
}
209
208
// Listing denied
210
209
control .approveCh <- "Nope"
211
- list , err = api .List (context . Background ())
210
+ list , err = api .List (t . Context ())
212
211
if len (list ) != 0 {
213
212
t .Fatalf ("List should be empty" )
214
213
}
@@ -246,7 +245,7 @@ func TestSignTx(t *testing.T) {
246
245
api , control := setup (t )
247
246
createAccount (control , api , t )
248
247
control .approveCh <- "A"
249
- list , err = api .List (context . Background ())
248
+ list , err = api .List (t . Context ())
250
249
if err != nil {
251
250
t .Fatal (err )
252
251
}
@@ -260,15 +259,15 @@ func TestSignTx(t *testing.T) {
260
259
261
260
control .approveCh <- "Y"
262
261
control .inputCh <- "wrongpassword"
263
- res , err = api .SignTransaction (context . Background (), tx , & methodSig )
262
+ res , err = api .SignTransaction (t . Context (), tx , & methodSig )
264
263
if res != nil {
265
264
t .Errorf ("Expected nil-response, got %v" , res )
266
265
}
267
266
if err != keystore .ErrDecrypt {
268
267
t .Errorf ("Expected ErrLocked! %v" , err )
269
268
}
270
269
control .approveCh <- "No way"
271
- res , err = api .SignTransaction (context . Background (), tx , & methodSig )
270
+ res , err = api .SignTransaction (t . Context (), tx , & methodSig )
272
271
if res != nil {
273
272
t .Errorf ("Expected nil-response, got %v" , res )
274
273
}
@@ -278,43 +277,42 @@ func TestSignTx(t *testing.T) {
278
277
// Sign with correct password
279
278
control .approveCh <- "Y"
280
279
control .inputCh <- "a_long_password"
281
- res , err = api .SignTransaction (context .Background (), tx , & methodSig )
282
-
280
+ res , err = api .SignTransaction (t .Context (), tx , & methodSig )
283
281
if err != nil {
284
282
t .Fatal (err )
285
283
}
286
284
parsedTx := & types.Transaction {}
287
285
rlp .DecodeBytes (res .Raw , parsedTx )
288
286
289
- //The tx should NOT be modified by the UI
287
+ // The tx should NOT be modified by the UI
290
288
if parsedTx .Value ().Cmp (tx .Value .ToInt ()) != 0 {
291
289
t .Errorf ("Expected value to be unchanged, expected %v got %v" , tx .Value , parsedTx .Value ())
292
290
}
293
291
control .approveCh <- "Y"
294
292
control .inputCh <- "a_long_password"
295
293
296
- res2 , err = api .SignTransaction (context . Background (), tx , & methodSig )
294
+ res2 , err = api .SignTransaction (t . Context (), tx , & methodSig )
297
295
if err != nil {
298
296
t .Fatal (err )
299
297
}
300
298
if ! bytes .Equal (res .Raw , res2 .Raw ) {
301
299
t .Error ("Expected tx to be unmodified by UI" )
302
300
}
303
301
304
- //The tx is modified by the UI
302
+ // The tx is modified by the UI
305
303
control .approveCh <- "M"
306
304
control .inputCh <- "a_long_password"
307
305
308
- res2 , err = api .SignTransaction (context . Background (), tx , & methodSig )
306
+ res2 , err = api .SignTransaction (t . Context (), tx , & methodSig )
309
307
if err != nil {
310
308
t .Fatal (err )
311
309
}
312
310
parsedTx2 := & types.Transaction {}
313
- rlp .DecodeBytes (res .Raw , parsedTx2 )
311
+ rlp .DecodeBytes (res2 .Raw , parsedTx2 )
314
312
315
- //The tx should be modified by the UI
316
- if parsedTx2 .Value ().Cmp (tx .Value .ToInt ()) ! = 0 {
317
- t .Errorf ("Expected value to be unchanged , got %v" , parsedTx .Value ())
313
+ // The tx should be modified by the UI
314
+ if parsedTx2 .Value ().Cmp (tx .Value .ToInt ()) = = 0 {
315
+ t .Errorf ("Expected value to be changed , got %v" , parsedTx2 .Value ())
318
316
}
319
317
if bytes .Equal (res .Raw , res2 .Raw ) {
320
318
t .Error ("Expected tx to be modified by UI" )
0 commit comments