Skip to content

Commit da6ccfd

Browse files
ralph-pichlernonsense
authored andcommitted
swap: fix rpc test to use peer balance (ethersphere#1743)
1 parent 537e386 commit da6ccfd

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

swap/protocol_test.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ func TestSwapRPC(t *testing.T) {
358358
// query a first time, should give error
359359
var balance int64
360360
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
362362
if err == nil {
363363
t.Fatal("Expected error but no error received")
364364
}
@@ -369,9 +369,23 @@ func TestSwapRPC(t *testing.T) {
369369
t.Fatalf("Expected balance to be 0 but it is %d", balance)
370370
}
371371

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+
}
375389

376390
// query them, values should coincide
377391
err = rpcclient.Call(&balance, "swap_balance", id1)
@@ -410,7 +424,12 @@ func TestSwapRPC(t *testing.T) {
410424
t.Fatalf("Expected total balance to be %d, but it %d", fakeSum, sum)
411425
}
412426

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) {
414433
t.Fatal("Balances are not deep equal")
415434
}
416435
}

0 commit comments

Comments
 (0)