Skip to content

Commit c50c75f

Browse files
authored
🔀 Merge pull request #114 from perun-network/prepare-82-virtual-channels
Prepare 82 virtual channels
2 parents c7113e1 + c05d177 commit c50c75f

File tree

17 files changed

+113
-81
lines changed

17 files changed

+113
-81
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Lint
3535
uses: golangci/golangci-lint-action@v2
3636
with:
37-
version: v1.29
37+
version: v1.40.1
3838

3939
tests:
4040
name: Tests

backend/ethereum/channel/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func pwToCommonAddresses(addr []wallet.Address) []common.Address {
229229
func FromEthState(app channel.App, s *adjudicator.ChannelState) channel.State {
230230
locked := make([]channel.SubAlloc, len(s.Outcome.Locked))
231231
for i, sub := range s.Outcome.Locked {
232-
locked[i] = channel.SubAlloc{ID: sub.ID, Bals: sub.Balances}
232+
locked[i] = *channel.NewSubAlloc(sub.ID, sub.Balances)
233233
}
234234
alloc := channel.Allocation{
235235
Assets: fromEthAssets(s.Outcome.Assets),

backend/ethereum/channel/register_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
pkgtest "perun.network/go-perun/pkg/test"
3131
)
3232

33-
// nolint: dupl
3433
func TestAdjudicator_MultipleRegisters(t *testing.T) {
3534
t.Run("Register 1 party parallel", func(t *testing.T) { registerMultipleConcurrent(t, 1, true) })
3635
t.Run("Register 2 party parallel", func(t *testing.T) { registerMultipleConcurrent(t, 2, true) })

backend/ethereum/channel/withdraw_test.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package channel_test
1616

1717
import (
1818
"context"
19+
"fmt"
1920
"sync"
2021
"testing"
2122
"time"
@@ -31,15 +32,18 @@ import (
3132
pkgtest "perun.network/go-perun/pkg/test"
3233
)
3334

34-
// nolint: dupl
3535
func TestAdjudicator_MultipleWithdraws_FinalState(t *testing.T) {
36-
t.Run("Withdraw 1 party parallel", func(t *testing.T) { withdrawMultipleConcurrentFinal(t, 1, true) })
37-
t.Run("Withdraw 2 party parallel", func(t *testing.T) { withdrawMultipleConcurrentFinal(t, 2, true) })
38-
t.Run("Withdraw 5 party parallel", func(t *testing.T) { withdrawMultipleConcurrentFinal(t, 5, true) })
39-
t.Run("Withdraw 10 party parallel", func(t *testing.T) { withdrawMultipleConcurrentFinal(t, 10, true) })
40-
t.Run("Withdraw 1 party sequential", func(t *testing.T) { withdrawMultipleConcurrentFinal(t, 1, false) })
41-
t.Run("Withdraw 2 party sequential", func(t *testing.T) { withdrawMultipleConcurrentFinal(t, 2, false) })
42-
t.Run("Withdraw 5 party sequential", func(t *testing.T) { withdrawMultipleConcurrentFinal(t, 5, false) })
36+
testParallel := func(n int) {
37+
t.Run(fmt.Sprintf("Withdraw %d party parallel", n), func(t *testing.T) { withdrawMultipleConcurrentFinal(t, n, true) })
38+
}
39+
testSequential := func(n int) {
40+
t.Run(fmt.Sprintf("Withdraw %d party sequential", n), func(t *testing.T) { withdrawMultipleConcurrentFinal(t, n, false) })
41+
}
42+
43+
for _, n := range []int{1, 2, 5} {
44+
testParallel(n)
45+
testSequential(n)
46+
}
4347
}
4448

4549
func withdrawMultipleConcurrentFinal(t *testing.T, numParts int, parallel bool) {

channel/allocation_test.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,14 @@ func TestAllocationValidLimits(t *testing.T) {
282282
}
283283

284284
for i := range allocation.Locked {
285-
allocation.Locked[i] = channel.SubAlloc{
286-
ID: channel.ID{byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24)},
287-
Bals: make([]channel.Bal, x.numAssets)}
285+
allocation.Locked[i] = *channel.NewSubAlloc(
286+
channel.ID{byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24)},
287+
make([]channel.Bal, x.numAssets),
288+
)
289+
allocation.Locked[i] = *channel.NewSubAlloc(
290+
channel.ID{byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24)},
291+
make([]channel.Bal, x.numAssets),
292+
)
288293

289294
for j := range allocation.Locked[i].Bals {
290295
bal := big.NewInt(int64(x.numAssets)*int64(i) + int64(j) + 1)
@@ -372,7 +377,7 @@ func TestAllocation_Sum(t *testing.T) {
372377

373378
{
374379
"single asset/one participants/one locked",
375-
*test.NewRandomAllocation(rng, test.WithNumAssets(1), test.WithNumParts(1), test.WithLocked(channel.SubAlloc{Bals: []channel.Bal{big.NewInt(2)}}), test.WithBalancesInRange(big.NewInt(1), big.NewInt(1))),
380+
*test.NewRandomAllocation(rng, test.WithNumAssets(1), test.WithNumParts(1), test.WithLocked(*channel.NewSubAlloc(channel.ID{}, []channel.Bal{big.NewInt(2)})), test.WithBalancesInRange(big.NewInt(1), big.NewInt(1))),
376381
[]channel.Bal{big.NewInt(3)},
377382
},
378383

@@ -485,7 +490,7 @@ func TestAllocation_Valid(t *testing.T) {
485490
{big.NewInt(64), big.NewInt(128)},
486491
},
487492
Locked: []channel.SubAlloc{
488-
{channel.Zero, []channel.Bal{big.NewInt(4)}},
493+
*channel.NewSubAlloc(channel.Zero, []channel.Bal{big.NewInt(4)}),
489494
},
490495
},
491496
false,
@@ -501,7 +506,7 @@ func TestAllocation_Valid(t *testing.T) {
501506
{big.NewInt(64), big.NewInt(128)},
502507
},
503508
Locked: []channel.SubAlloc{
504-
{channel.Zero, []channel.Bal{big.NewInt(-1)}},
509+
*channel.NewSubAlloc(channel.Zero, []channel.Bal{big.NewInt(-1)}),
505510
},
506511
},
507512
false,
@@ -529,7 +534,7 @@ func TestAllocation_Valid(t *testing.T) {
529534
{big.NewInt(2), big.NewInt(16)},
530535
},
531536
Locked: []channel.SubAlloc{
532-
{channel.Zero, []channel.Bal{big.NewInt(4), big.NewInt(-1)}},
537+
*channel.NewSubAlloc(channel.Zero, []channel.Bal{big.NewInt(4), big.NewInt(-1)}),
533538
},
534539
},
535540
false,
@@ -549,9 +554,9 @@ func TestAllocation_Valid(t *testing.T) {
549554
// suballocation serialization.
550555
func TestSuballocSerialization(t *testing.T) {
551556
ss := []perunio.Serializer{
552-
&channel.SubAlloc{channel.ID{2}, []channel.Bal{}},
553-
&channel.SubAlloc{channel.ID{3}, []channel.Bal{big.NewInt(0)}},
554-
&channel.SubAlloc{channel.ID{4}, []channel.Bal{big.NewInt(5), big.NewInt(1 << 62)}},
557+
channel.NewSubAlloc(channel.ID{2}, []channel.Bal{}),
558+
channel.NewSubAlloc(channel.ID{3}, []channel.Bal{big.NewInt(0)}),
559+
channel.NewSubAlloc(channel.ID{4}, []channel.Bal{big.NewInt(5), big.NewInt(1 << 62)}),
555560
}
556561

557562
iotest.GenericSerializerTest(t, ss...)

channel/machine.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ const (
6868
Progressed
6969
Withdrawing
7070
Withdrawn
71-
LastPhase = Withdrawn
71+
// LastPhase contains the value of the last phase. This is useful for testing.
72+
LastPhase = int(Withdrawn)
7273
)
7374

7475
func (p Phase) String() string {

channel/persistence/keyvalue/cache.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type channelCache struct {
3838
peerChannels map[string]map[channel.ID]struct{} // Address -> Set<chID>
3939
}
4040

41+
// nolint: unused
4142
func (c *channelCache) addPeerChannel(addr wire.Address, chID channel.ID) {
4243
c.mutex.Lock()
4344
defer c.mutex.Unlock()
@@ -53,6 +54,7 @@ func (c *channelCache) addPeerChannel(addr wire.Address, chID channel.ID) {
5354
}
5455
}
5556

57+
// nolint: unused
5658
func (c *channelCache) deleteChannel(id channel.ID) []wire.Address {
5759
c.mutex.Lock()
5860
defer c.mutex.Unlock()
@@ -71,6 +73,7 @@ func (c *channelCache) deleteChannel(id channel.ID) []wire.Address {
7173
return peers
7274
}
7375

76+
// nolint: unused
7477
func (c *channelCache) clear() {
7578
c.mutex.Lock()
7679
defer c.mutex.Unlock()

channel/persistence/test/persistrestorertest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func GenericPersistRestorerTest(
119119
chIndex := iterIdx
120120
log.Error(subSeed)
121121
seed := pkgtest.Seed("", subSeed, numChans, numPeers, chIndex, ch.ID())
122-
rng := rand.New(rand.NewSource(seed))
122+
rng := rand.New(rand.NewSource(seed)) // nolint: gosec
123123

124124
ch.Init(t, rng)
125125
ch.SignAll(t)

channel/test/randomizer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func SetRandomizer(r Randomizer) {
4545

4646
// NewRandomPhase generates a random channel machine phase.
4747
func NewRandomPhase(rng *rand.Rand) channel.Phase {
48-
return channel.Phase(rng.Intn(int(channel.LastPhase) + 1))
48+
return channel.Phase(rng.Intn(channel.LastPhase + 1))
4949
}
5050

5151
// NewRandomAsset generates a new random `channel.Asset`.
@@ -134,7 +134,7 @@ func NewRandomSubAlloc(rng *rand.Rand, opts ...RandomOpt) *channel.SubAlloc {
134134
bals = NewRandomBals(rng, opt.NumAssets(rng), opt)
135135
}
136136

137-
return &channel.SubAlloc{ID: id, Bals: bals}
137+
return channel.NewSubAlloc(id, bals)
138138
}
139139

140140
// NewRandomParamsAndState generates a new random `channel.Params` and `channel.State`.
File renamed without changes.

0 commit comments

Comments
 (0)