Skip to content

Commit

Permalink
Register and settle in random order
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Geihs <[email protected]>
  • Loading branch information
matthiasgeihs committed Jul 8, 2021
1 parent a30f8e8 commit 1764f43
Showing 1 changed file with 12 additions and 59 deletions.
71 changes: 12 additions & 59 deletions client/virtual_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package client_test
import (
"context"
"math/big"
"math/rand"
"testing"
"time"

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

vct := setupVirtualChannelTest(t, ctx)
var err error
assert := assert.New(t)

// Alice registers and settles channel with Ingrid.
err = vct.registerAndSettle(ctx, vct.chAliceIngrid)
assert.NoError(err, "alice-ingrid: register and settle")

// Ingrid registers and settles channel with Alice.
err = vct.registerAndSettle(ctx, vct.chIngridAlice)
assert.NoError(err, "ingrid-alice: register and settle")

// Bob registers and settles channel with Ingrid.
err = vct.registerAndSettle(ctx, vct.chBobIngrid)
assert.NoError(err, "bob-ingrid: register and settle")

// 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) {
ctx, cancel := context.WithTimeout(context.Background(), testDuration)
defer cancel()

vct := setupVirtualChannelTest(t, ctx)
var err error
assert := assert.New(t)

// Ingrid registers channel with Alice.
err = vct.chIngridAlice.Register(ctx)
assert.NoError(err, "ingrid-alice: register")

// Alice registers channel with Ingrid.
err = vct.chAliceIngrid.Register(ctx)
assert.NoError(err, "alice-ingrid: register")

// Ingrid registers channel with Bob.
err = vct.chIngridBob.Register(ctx)
assert.NoError(err, "ingrid-bob: register")

// Bob registers channel with Ingrid.
err = vct.chBobIngrid.Register(ctx)
assert.NoError(err, "bob-ingrid: register")
chs := []*client.Channel{vct.chAliceIngrid, vct.chIngridAlice, vct.chBobIngrid, vct.chIngridBob}
// Register the channels in a random order.
for _, i := range rand.Perm(len(chs)) {
err := chs[i].Register(ctx)
assert.NoErrorf(err, "register channel: %d", i)
}

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

// Ingrid settles channel with Alice.
err = vct.chIngridAlice.Settle(ctx, false)
assert.NoError(err, "ingrid-alice: settle")

// Alice settles channel with Ingrid.
err = vct.chAliceIngrid.Settle(ctx, false)
assert.NoError(err, "alice-ingrid: settle")

// Ingrid settles channel with Bob.
err = vct.chIngridBob.Settle(ctx, false)
assert.NoError(err, "ingrid-bob: settle")

// Bob settles channel with Ingrid.
err = vct.chBobIngrid.Settle(ctx, false)
assert.NoError(err, "bob-ingrid: settle")
// Settle the channels in a random order.
for _, i := range rand.Perm(len(chs)) {
err := chs[i].Settle(ctx, false)
assert.NoErrorf(err, "settle channel: %d", i)
}

// Test final balances.
vct.testFinalBalancesDispute(t)
Expand Down

0 comments on commit 1764f43

Please sign in to comment.