diff --git a/client/virtual_channel_test.go b/client/virtual_channel_test.go index 4d337c3cb..563b45782 100644 --- a/client/virtual_channel_test.go +++ b/client/virtual_channel_test.go @@ -26,6 +26,7 @@ import ( "perun.network/go-perun/channel" chtest "perun.network/go-perun/channel/test" "perun.network/go-perun/client" + ctest "perun.network/go-perun/client/test" "perun.network/go-perun/pkg/sync" "perun.network/go-perun/pkg/test" "perun.network/go-perun/wire" @@ -91,6 +92,9 @@ func TestVirtualChannelsDispute(t *testing.T) { // Ingrid registers and settles channel with Bob. err = vct.registerAndSettle(ctx, vct.chIngridBob) assert.NoError(err, "ingrid-bob: register and settle") + + // Test final balances. + vct.testFinalBalancesDispute(t) } func TestVirtualChannelsDisputeHubFirst(t *testing.T) { @@ -134,9 +138,26 @@ func TestVirtualChannelsDisputeHubFirst(t *testing.T) { // Bob settles channel with Ingrid. err = vct.chBobIngrid.Settle(ctx, false) assert.NoError(err, "bob-ingrid: settle") + + // Test final balances. + vct.testFinalBalancesDispute(t) +} + +func (vct *virtualChannelTest) testFinalBalancesDispute(t *testing.T) { + assert := assert.New(t) + backend, asset := vct.backend, vct.asset + got, expected := backend.GetBalance(vct.alice.Identity.Address(), asset), vct.finalBalsAlice[0] + assert.Truef(got.Cmp(expected) == 0, "alice: wrong final balance: got %v, expected %v", got, expected) + got, expected = backend.GetBalance(vct.bob.Identity.Address(), asset), vct.finalBalsBob[0] + assert.Truef(got.Cmp(expected) == 0, "bob: wrong final balance: got %v, expected %v", got, expected) + got, expected = backend.GetBalance(vct.ingrid.Identity.Address(), asset), vct.finalBalIngrid + assert.Truef(got.Cmp(expected) == 0, "ingrid: wrong final balance: got %v, expected %v", got, expected) } type virtualChannelTest struct { + alice *Client + bob *Client + ingrid *Client chAliceIngrid *client.Channel chIngridAlice *client.Channel chBobIngrid *client.Channel @@ -146,7 +167,10 @@ type virtualChannelTest struct { virtualBalsUpdated []*big.Int finalBalsAlice []*big.Int finalBalsBob []*big.Int + finalBalIngrid *big.Int errs chan error + backend *ctest.MockBackend + asset channel.Asset } func setupVirtualChannelTest(t *testing.T, ctx context.Context) (vct virtualChannelTest) { @@ -155,12 +179,14 @@ func setupVirtualChannelTest(t *testing.T, ctx context.Context) (vct virtualChan // Set test values. asset := chtest.NewRandomAsset(rng) + vct.asset = asset initBalsAlice := []*big.Int{big.NewInt(10), big.NewInt(10)} // with Ingrid initBalsBob := []*big.Int{big.NewInt(10), big.NewInt(10)} // with Ingrid initBalsVirtual := []*big.Int{big.NewInt(5), big.NewInt(5)} // Alice proposes vct.virtualBalsUpdated = []*big.Int{big.NewInt(2), big.NewInt(8)} // Send 3. vct.finalBalsAlice = []*big.Int{big.NewInt(7), big.NewInt(13)} vct.finalBalsBob = []*big.Int{big.NewInt(13), big.NewInt(7)} + vct.finalBalIngrid = new(big.Int).Add(vct.finalBalsAlice[1], vct.finalBalsBob[1]) vct.errs = make(chan error, 10) // Setup clients. @@ -170,6 +196,8 @@ func setupVirtualChannelTest(t *testing.T, ctx context.Context) (vct virtualChan t, ) alice, bob, ingrid := clients[0], clients[1], clients[2] + vct.alice, vct.bob, vct.ingrid = alice, bob, ingrid + vct.backend = alice.Backend // Assumes all clients have same backend. _channelsIngrid := make(chan *client.Channel, 1) var openingProposalHandlerIngrid client.ProposalHandlerFunc = func(cp client.ChannelProposal, pr *client.ProposalResponder) {