@@ -26,6 +26,7 @@ import (
26
26
"perun.network/go-perun/channel"
27
27
chtest "perun.network/go-perun/channel/test"
28
28
"perun.network/go-perun/client"
29
+ ctest "perun.network/go-perun/client/test"
29
30
"perun.network/go-perun/pkg/sync"
30
31
"perun.network/go-perun/pkg/test"
31
32
"perun.network/go-perun/wire"
@@ -91,6 +92,9 @@ func TestVirtualChannelsDispute(t *testing.T) {
91
92
// Ingrid registers and settles channel with Bob.
92
93
err = vct .registerAndSettle (ctx , vct .chIngridBob )
93
94
assert .NoError (err , "ingrid-bob: register and settle" )
95
+
96
+ // Test final balances.
97
+ vct .testFinalBalancesDispute (t )
94
98
}
95
99
96
100
func TestVirtualChannelsDisputeHubFirst (t * testing.T ) {
@@ -134,9 +138,26 @@ func TestVirtualChannelsDisputeHubFirst(t *testing.T) {
134
138
// Bob settles channel with Ingrid.
135
139
err = vct .chBobIngrid .Settle (ctx , false )
136
140
assert .NoError (err , "bob-ingrid: settle" )
141
+
142
+ // Test final balances.
143
+ vct .testFinalBalancesDispute (t )
144
+ }
145
+
146
+ func (vct * virtualChannelTest ) testFinalBalancesDispute (t * testing.T ) {
147
+ assert := assert .New (t )
148
+ backend , asset := vct .backend , vct .asset
149
+ got , expected := backend .GetBalance (vct .alice .Identity .Address (), asset ), vct .finalBalsAlice [0 ]
150
+ assert .Truef (got .Cmp (expected ) == 0 , "alice: wrong final balance: got %v, expected %v" , got , expected )
151
+ got , expected = backend .GetBalance (vct .bob .Identity .Address (), asset ), vct .finalBalsBob [0 ]
152
+ assert .Truef (got .Cmp (expected ) == 0 , "bob: wrong final balance: got %v, expected %v" , got , expected )
153
+ got , expected = backend .GetBalance (vct .ingrid .Identity .Address (), asset ), vct .finalBalIngrid
154
+ assert .Truef (got .Cmp (expected ) == 0 , "ingrid: wrong final balance: got %v, expected %v" , got , expected )
137
155
}
138
156
139
157
type virtualChannelTest struct {
158
+ alice * Client
159
+ bob * Client
160
+ ingrid * Client
140
161
chAliceIngrid * client.Channel
141
162
chIngridAlice * client.Channel
142
163
chBobIngrid * client.Channel
@@ -146,7 +167,10 @@ type virtualChannelTest struct {
146
167
virtualBalsUpdated []* big.Int
147
168
finalBalsAlice []* big.Int
148
169
finalBalsBob []* big.Int
170
+ finalBalIngrid * big.Int
149
171
errs chan error
172
+ backend * ctest.MockBackend
173
+ asset channel.Asset
150
174
}
151
175
152
176
func setupVirtualChannelTest (t * testing.T , ctx context.Context ) (vct virtualChannelTest ) {
@@ -155,12 +179,14 @@ func setupVirtualChannelTest(t *testing.T, ctx context.Context) (vct virtualChan
155
179
156
180
// Set test values.
157
181
asset := chtest .NewRandomAsset (rng )
182
+ vct .asset = asset
158
183
initBalsAlice := []* big.Int {big .NewInt (10 ), big .NewInt (10 )} // with Ingrid
159
184
initBalsBob := []* big.Int {big .NewInt (10 ), big .NewInt (10 )} // with Ingrid
160
185
initBalsVirtual := []* big.Int {big .NewInt (5 ), big .NewInt (5 )} // Alice proposes
161
186
vct .virtualBalsUpdated = []* big.Int {big .NewInt (2 ), big .NewInt (8 )} // Send 3.
162
187
vct .finalBalsAlice = []* big.Int {big .NewInt (7 ), big .NewInt (13 )}
163
188
vct .finalBalsBob = []* big.Int {big .NewInt (13 ), big .NewInt (7 )}
189
+ vct .finalBalIngrid = new (big.Int ).Add (vct .finalBalsAlice [1 ], vct .finalBalsBob [1 ])
164
190
vct .errs = make (chan error , 10 )
165
191
166
192
// Setup clients.
@@ -170,6 +196,8 @@ func setupVirtualChannelTest(t *testing.T, ctx context.Context) (vct virtualChan
170
196
t ,
171
197
)
172
198
alice , bob , ingrid := clients [0 ], clients [1 ], clients [2 ]
199
+ vct .alice , vct .bob , vct .ingrid = alice , bob , ingrid
200
+ vct .backend = alice .Backend // Assumes all clients have same backend.
173
201
174
202
_channelsIngrid := make (chan * client.Channel , 1 )
175
203
var openingProposalHandlerIngrid client.ProposalHandlerFunc = func (cp client.ChannelProposal , pr * client.ProposalResponder ) {
0 commit comments