Skip to content

Commit 1764f43

Browse files
committed
Register and settle in random order
Signed-off-by: Matthias Geihs <[email protected]>
1 parent a30f8e8 commit 1764f43

File tree

1 file changed

+12
-59
lines changed

1 file changed

+12
-59
lines changed

client/virtual_channel_test.go

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package client_test
1717
import (
1818
"context"
1919
"math/big"
20+
"math/rand"
2021
"testing"
2122
"time"
2223

@@ -74,70 +75,22 @@ func TestVirtualChannelsDispute(t *testing.T) {
7475
defer cancel()
7576

7677
vct := setupVirtualChannelTest(t, ctx)
77-
var err error
7878
assert := assert.New(t)
7979

80-
// Alice registers and settles channel with Ingrid.
81-
err = vct.registerAndSettle(ctx, vct.chAliceIngrid)
82-
assert.NoError(err, "alice-ingrid: register and settle")
83-
84-
// Ingrid registers and settles channel with Alice.
85-
err = vct.registerAndSettle(ctx, vct.chIngridAlice)
86-
assert.NoError(err, "ingrid-alice: register and settle")
87-
88-
// Bob registers and settles channel with Ingrid.
89-
err = vct.registerAndSettle(ctx, vct.chBobIngrid)
90-
assert.NoError(err, "bob-ingrid: register and settle")
91-
92-
// Ingrid registers and settles channel with Bob.
93-
err = vct.registerAndSettle(ctx, vct.chIngridBob)
94-
assert.NoError(err, "ingrid-bob: register and settle")
95-
96-
// Test final balances.
97-
vct.testFinalBalancesDispute(t)
98-
}
99-
100-
func TestVirtualChannelsDisputeHubFirst(t *testing.T) {
101-
ctx, cancel := context.WithTimeout(context.Background(), testDuration)
102-
defer cancel()
103-
104-
vct := setupVirtualChannelTest(t, ctx)
105-
var err error
106-
assert := assert.New(t)
107-
108-
// Ingrid registers channel with Alice.
109-
err = vct.chIngridAlice.Register(ctx)
110-
assert.NoError(err, "ingrid-alice: register")
111-
112-
// Alice registers channel with Ingrid.
113-
err = vct.chAliceIngrid.Register(ctx)
114-
assert.NoError(err, "alice-ingrid: register")
115-
116-
// Ingrid registers channel with Bob.
117-
err = vct.chIngridBob.Register(ctx)
118-
assert.NoError(err, "ingrid-bob: register")
119-
120-
// Bob registers channel with Ingrid.
121-
err = vct.chBobIngrid.Register(ctx)
122-
assert.NoError(err, "bob-ingrid: register")
80+
chs := []*client.Channel{vct.chAliceIngrid, vct.chIngridAlice, vct.chBobIngrid, vct.chIngridBob}
81+
// Register the channels in a random order.
82+
for _, i := range rand.Perm(len(chs)) {
83+
err := chs[i].Register(ctx)
84+
assert.NoErrorf(err, "register channel: %d", i)
85+
}
12386

12487
time.Sleep(100 * time.Millisecond) // Sleep to ensure that registered events have been processed.
12588

126-
// Ingrid settles channel with Alice.
127-
err = vct.chIngridAlice.Settle(ctx, false)
128-
assert.NoError(err, "ingrid-alice: settle")
129-
130-
// Alice settles channel with Ingrid.
131-
err = vct.chAliceIngrid.Settle(ctx, false)
132-
assert.NoError(err, "alice-ingrid: settle")
133-
134-
// Ingrid settles channel with Bob.
135-
err = vct.chIngridBob.Settle(ctx, false)
136-
assert.NoError(err, "ingrid-bob: settle")
137-
138-
// Bob settles channel with Ingrid.
139-
err = vct.chBobIngrid.Settle(ctx, false)
140-
assert.NoError(err, "bob-ingrid: settle")
89+
// Settle the channels in a random order.
90+
for _, i := range rand.Perm(len(chs)) {
91+
err := chs[i].Settle(ctx, false)
92+
assert.NoErrorf(err, "settle channel: %d", i)
93+
}
14194

14295
// Test final balances.
14396
vct.testFinalBalancesDispute(t)

0 commit comments

Comments
 (0)