@@ -358,7 +358,7 @@ func TestSwapRPC(t *testing.T) {
358
358
// query a first time, should give error
359
359
var balance int64
360
360
err = rpcclient .Call (& balance , "swap_balance" , id1 )
361
- // at this point no balance should be there: no peer at address in map...
361
+ // at this point no balance should be there: no peer registered with Swap
362
362
if err == nil {
363
363
t .Fatal ("Expected error but no error received" )
364
364
}
@@ -369,9 +369,23 @@ func TestSwapRPC(t *testing.T) {
369
369
t .Fatalf ("Expected balance to be 0 but it is %d" , balance )
370
370
}
371
371
372
- // now artificially assign some balances
373
- swap .balances [id1 ] = fakeBalance1
374
- swap .balances [id2 ] = fakeBalance2
372
+ peer1 , err := swap .addPeer (dummyPeer1 .Peer , common.Address {}, common.Address {})
373
+ if err != nil {
374
+ t .Fatal (err )
375
+ }
376
+
377
+ if err := peer1 .setBalance (fakeBalance1 ); err != nil {
378
+ t .Fatal (err )
379
+ }
380
+
381
+ peer2 , err := swap .addPeer (dummyPeer2 .Peer , common.Address {}, common.Address {})
382
+ if err != nil {
383
+ t .Fatal (err )
384
+ }
385
+
386
+ if err := peer2 .setBalance (fakeBalance2 ); err != nil {
387
+ t .Fatal (err )
388
+ }
375
389
376
390
// query them, values should coincide
377
391
err = rpcclient .Call (& balance , "swap_balance" , id1 )
@@ -410,7 +424,12 @@ func TestSwapRPC(t *testing.T) {
410
424
t .Fatalf ("Expected total balance to be %d, but it %d" , fakeSum , sum )
411
425
}
412
426
413
- if ! reflect .DeepEqual (allBalances , swap .balances ) {
427
+ balances , err := swap .Balances ()
428
+ if err != nil {
429
+ t .Fatal (err )
430
+ }
431
+
432
+ if ! reflect .DeepEqual (allBalances , balances ) {
414
433
t .Fatal ("Balances are not deep equal" )
415
434
}
416
435
}
0 commit comments