Skip to content

Commit 3c254ec

Browse files
committed
✅ [client] Add virtual channel dispute test
Signed-off-by: Matthias Geihs <[email protected]>
1 parent dc77aa4 commit 3c254ec

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

client/virtual_channel_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,56 @@ func TestVirtualChannelsOptimistic(t *testing.T) {
6868
assert.NoError(t, err, "Bob: invalid final balances")
6969
}
7070

71+
func TestVirtualChannelsDispute(t *testing.T) {
72+
ctx, cancel := context.WithTimeout(context.Background(), testDuration)
73+
defer cancel()
74+
75+
vct := setupVirtualChannelTest(t, ctx)
76+
var err error
77+
assert := assert.New(t)
78+
79+
// Alice registers and settles channel with Ingrid.
80+
err = vct.registerAndSettle(ctx, vct.chAliceIngrid)
81+
assert.NoError(err, "alice-ingrid: register and settle")
82+
83+
// Ingrid registers and settles channel with Alice.
84+
err = vct.registerAndSettle(ctx, vct.chIngridAlice)
85+
assert.NoError(err, "ingrid-alice: register and settle")
86+
87+
// Bob registers and settles channel with Ingrid.
88+
err = vct.registerAndSettle(ctx, vct.chBobIngrid)
89+
assert.NoError(err, "bob-ingrid: register and settle")
90+
91+
// Ingrid registers and settles channel with Bob.
92+
err = vct.registerAndSettle(ctx, vct.chIngridBob)
93+
assert.NoError(err, "ingrid-bob: register and settle")
94+
}
95+
96+
func TestVirtualChannelsDisputeHubFirst(t *testing.T) {
97+
ctx, cancel := context.WithTimeout(context.Background(), testDuration)
98+
defer cancel()
99+
100+
vct := setupVirtualChannelTest(t, ctx)
101+
var err error
102+
assert := assert.New(t)
103+
104+
// Ingrid registers and settles channel with Alice.
105+
err = vct.registerAndSettle(ctx, vct.chIngridAlice)
106+
assert.NoError(err, "ingrid-alice: register and settle")
107+
108+
// Alice registers and settles channel with Ingrid.
109+
err = vct.registerAndSettle(ctx, vct.chAliceIngrid)
110+
assert.NoError(err, "alice-ingrid: register and settle")
111+
112+
// Ingrid registers and settles channel with Bob.
113+
err = vct.registerAndSettle(ctx, vct.chIngridBob)
114+
assert.NoError(err, "ingrid-bob: register and settle")
115+
116+
// Bob registers and settles channel with Ingrid.
117+
err = vct.registerAndSettle(ctx, vct.chBobIngrid)
118+
assert.NoError(err, "bob-ingrid: register and settle")
119+
}
120+
71121
type virtualChannelTest struct {
72122
chAliceIngrid *client.Channel
73123
chIngridAlice *client.Channel
@@ -228,3 +278,13 @@ func setupVirtualChannelTest(t *testing.T, ctx context.Context) (vct virtualChan
228278
require.NoError(err, "updating virtual channel")
229279
return
230280
}
281+
282+
func (vct virtualChannelTest) registerAndSettle(ctx context.Context, ch *client.Channel) (err error) {
283+
err = ch.Register(ctx)
284+
if err != nil {
285+
return
286+
}
287+
288+
err = ch.Settle(ctx, false)
289+
return
290+
}

0 commit comments

Comments
 (0)