Skip to content

Commit

Permalink
✅ [client] Add virtual channel dispute test
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Geihs <matthias@perun.network>
  • Loading branch information
matthiasgeihs committed Jul 5, 2021
1 parent dc77aa4 commit 3c254ec
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions client/virtual_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,56 @@ func TestVirtualChannelsOptimistic(t *testing.T) {
assert.NoError(t, err, "Bob: invalid final balances")
}

func TestVirtualChannelsDispute(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), testDuration)
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")
}

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 and settles channel with Alice.
err = vct.registerAndSettle(ctx, vct.chIngridAlice)
assert.NoError(err, "ingrid-alice: register and settle")

// 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 Bob.
err = vct.registerAndSettle(ctx, vct.chIngridBob)
assert.NoError(err, "ingrid-bob: register and settle")

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

type virtualChannelTest struct {
chAliceIngrid *client.Channel
chIngridAlice *client.Channel
Expand Down Expand Up @@ -228,3 +278,13 @@ func setupVirtualChannelTest(t *testing.T, ctx context.Context) (vct virtualChan
require.NoError(err, "updating virtual channel")
return
}

func (vct virtualChannelTest) registerAndSettle(ctx context.Context, ch *client.Channel) (err error) {
err = ch.Register(ctx)
if err != nil {
return
}

err = ch.Settle(ctx, false)
return
}

0 comments on commit 3c254ec

Please sign in to comment.