@@ -17,6 +17,7 @@ package client_test
17
17
import (
18
18
"context"
19
19
"math/big"
20
+ "math/rand"
20
21
"testing"
21
22
"time"
22
23
@@ -74,70 +75,22 @@ func TestVirtualChannelsDispute(t *testing.T) {
74
75
defer cancel ()
75
76
76
77
vct := setupVirtualChannelTest (t , ctx )
77
- var err error
78
78
assert := assert .New (t )
79
79
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
+ }
123
86
124
87
time .Sleep (100 * time .Millisecond ) // Sleep to ensure that registered events have been processed.
125
88
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
+ }
141
94
142
95
// Test final balances.
143
96
vct .testFinalBalancesDispute (t )
0 commit comments